Updating scripts
This commit is contained in:
1 parent
21bf3f0710
commit
27b4b19df4
13 files changed
+903
-127
No files matched your search
@@ -7,6 +7,7 @@
|
||||
#include "GameConstants.h"
|
||||
#include "Environment.h"
|
||||
|
||||
|
||||
namespace ZL {
|
||||
|
||||
const float ATTACK_COOLDOWN_TIME = 1.6f;
|
||||
|
||||
@@ -188,7 +188,6 @@ namespace ZL
|
||||
|
||||
ItemRegistry::instance().loadFromJson("resources/config2/items.json", CONST_ZIP_FILE);
|
||||
|
||||
|
||||
globalFloats["player_hp"] = 200;
|
||||
|
||||
LocationSetup uniInteriorParams;
|
||||
|
||||
@@ -78,7 +78,6 @@ namespace ZL
|
||||
player->loadBinaryAnimation(AnimationState::DEATH_IDLE, "resources/w/gg/new/gg_die_idle001.anim", CONST_ZIP_FILE);
|
||||
|
||||
|
||||
|
||||
player->weaponTexture = renderer.textureManager.LoadFromPng("resources/w/white.png", CONST_ZIP_FILE);
|
||||
player->weaponMesh.data = LoadFromTextFile02("resources/w/gg/knife002.txt", CONST_ZIP_FILE);
|
||||
player->weaponMesh.data.Scale(0.1f);
|
||||
|
||||
@@ -101,6 +101,28 @@ namespace ZL {
|
||||
std::cerr << "[script] activate_interactive_object: not found: " << objectName << std::endl;
|
||||
});
|
||||
|
||||
api.set_function("set_object_rotation", [game](const std::string& objectName, float value) {
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.loadedObject.name == objectName) {
|
||||
intObj.rotationY = value;
|
||||
std::cout << "[script] set_object_rotation: " << objectName << " " << value << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::cerr << "[script] set_object_rotation: not found: " << objectName << std::endl;
|
||||
});
|
||||
|
||||
api.set_function("set_object_alpha", [game](const std::string& objectName, float value) {
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.loadedObject.name == objectName) {
|
||||
intObj.alpha = value;
|
||||
std::cout << "[script] set_object_alpha: " <<objectName << " " << value << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::cerr << "[script] set_object_alpha: not found: " << objectName << std::endl;
|
||||
});
|
||||
|
||||
// get_inventory_count()
|
||||
api.set_function("get_inventory_count", [inventory]() {
|
||||
return inventory->getCount();
|
||||
@@ -209,7 +231,14 @@ namespace ZL {
|
||||
api.set_function("set_player_hp",
|
||||
[game](float value) {
|
||||
if (game->player)
|
||||
{
|
||||
game->player->hp = value;
|
||||
if (game->player->currentState == AnimationState::ACTION_TO_DEATH || game->player->currentState == AnimationState::DEATH_IDLE)
|
||||
{
|
||||
game->player->currentState = AnimationState::STAND;
|
||||
game->player->resetAnim = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
// get_player_hp() → float (0 if no player)
|
||||
api.set_function("get_player_hp",
|
||||
@@ -254,6 +283,42 @@ namespace ZL {
|
||||
});
|
||||
|
||||
|
||||
// npc_set_hp(index, value) — sets an NPC's current HP directly.
|
||||
api.set_function("npc_set_hp",
|
||||
[game](int index, float value) {
|
||||
auto& npcs = game->npcs;
|
||||
if (index < 0 || index >= static_cast<int>(npcs.size())) {
|
||||
std::cerr << "[script] npc_set_hp: index " << index << " out of range\n";
|
||||
return;
|
||||
}
|
||||
npcs[index]->hp = value;
|
||||
});
|
||||
|
||||
// npc_set_position(index, x, y, z) — teleports an NPC instantly, no walking.
|
||||
api.set_function("npc_set_position",
|
||||
[game](int index, float x, float y, float z) {
|
||||
auto& npcs = game->npcs;
|
||||
if (index < 0 || index >= static_cast<int>(npcs.size())) {
|
||||
std::cerr << "[script] npc_set_position: index " << index << " out of range\n";
|
||||
return;
|
||||
}
|
||||
Eigen::Vector3f pos(x, y, z);
|
||||
npcs[index]->position = pos;
|
||||
npcs[index]->setTarget(pos);
|
||||
});
|
||||
|
||||
// npc_set_rotation(index, angle) — sets NPC facing angle around Y axis (radians).
|
||||
api.set_function("npc_set_rotation",
|
||||
[game](int index, float angle) {
|
||||
auto& npcs = game->npcs;
|
||||
if (index < 0 || index >= static_cast<int>(npcs.size())) {
|
||||
std::cerr << "[script] npc_set_rotation: index " << index << " out of range\n";
|
||||
return;
|
||||
}
|
||||
npcs[index]->facingAngle = angle;
|
||||
npcs[index]->targetFacingAngle = angle;
|
||||
});
|
||||
|
||||
// set_npc_enabled(index, enabled)
|
||||
api.set_function("set_npc_enabled",
|
||||
[game](int index, bool value) {
|
||||
@@ -263,6 +328,14 @@ namespace ZL {
|
||||
return;
|
||||
}
|
||||
npcs[index]->enabled = value;
|
||||
npcs[index]->attack = 0;
|
||||
npcs[index]->attack_cooldown = 0;
|
||||
npcs[index]->currentState = AnimationState::STAND;
|
||||
if (npcs[index]->canAttack)
|
||||
{
|
||||
npcs[index]->attackTarget = game->player.get();
|
||||
}
|
||||
npcs[index]->battle_state = 0;
|
||||
});
|
||||
|
||||
// move_object(name, x, y, z, duration_sec [, on_complete])
|
||||
|
||||
@@ -107,7 +107,10 @@ namespace ZL {
|
||||
// Snap to exact target
|
||||
position = task.targetPos;
|
||||
rotationY = task.targetRotY;
|
||||
scale = task.targetScale;
|
||||
if (task.type == AnimTask::Type::Fade)
|
||||
alpha = task.targetScale; // targetScale reused to hold targetAlpha for Fade
|
||||
else
|
||||
scale = task.targetScale;
|
||||
|
||||
std::function<void()> cb = std::move(task.onComplete);
|
||||
animTask.reset();
|
||||
|
||||
Reference in new issue
Block a user