Minor dialogue and UI bug fixing

This commit is contained in:
Vladislav Khorev committed 2026-06-13 20:58:44 +03:00
1 parent fff5a9d4aa
commit db456bde09
11 files changed
+2350 -21

No files matched your search

+12 -1
View File
@@ -117,8 +117,19 @@ public:
std::string npcId;
std::string npcName;
float hp = 200.f;
float initialHp = 200.f;
protected:
float hp = 200.f;
public:
float getHp() const {
return hp;
}
void setHp(float newHp) {
hp = newHp;
if (onHpChanged) onHpChanged(hp, initialHp);
}
// The position the NPC should return to if pushed too far away.
// Initialised to the spawn position; updated whenever a script walk command is issued.
+2 -2
View File
@@ -204,6 +204,7 @@ namespace ZL
#endif
std::cout << "Load resurces step 4" << std::endl;
ItemRegistry::instance().loadFromJson("resources/config2/items.json", CONST_ZIP_FILE);
@@ -213,8 +214,7 @@ namespace ZL
LocationSetup uniInteriorParams;
uniInteriorParams.gameObjectsJsonPath = "resources/config2/gameobjects_uni_interior_x.json";
uniInteriorParams.npcsJsonPath = "resources/config2/npcs_uni_interior.json";
uniInteriorParams.dialoguesJsonPath = "resources/dialogue/uni_interior_dialogues_005.json";
uniInteriorParams.dialoguesJsonPath = "resources/dialogue/uni_interior_dialogues_006.json";
uniInteriorParams.navigationJsonPaths = {
"resources/navigation/uni_interior4_unlocked_n2.txt", //0
+19 -4
View File
@@ -379,7 +379,7 @@ namespace ZL
const auto addCharacter = [&](const Character* other) {
if (!other || other == self) return;
if (other->hp <= 0.f || !other->enabled) return;
if (other->getHp() <= 0.f || !other->enabled) return;
if (other->isMoving()) return;
if (distancePointToSegmentXZ(other->position, start, end) > kDynamicObstacleInfluenceDist) {
@@ -533,7 +533,7 @@ namespace ZL
//std::cout << "[RAYCAST_NPC] Starting raycast with " << npcs.size() << " npcs" << std::endl;
for (auto& npc : npcs) {
if (npc->hp <= 0.f) {
if (npc->getHp() <= 0.f) {
//std::cout << "[RAYCAST_NPC] " << npc->npcId << " is dead, skipping" << std::endl;
continue;
}
@@ -1248,7 +1248,7 @@ namespace ZL
Character* a = characters[i];
Character* b = characters[j];
if (!a || !b) continue;
if (a->hp <= 0.f || b->hp <= 0.f || !a->enabled || !b->enabled) continue;
if (a->getHp() <= 0.f || b->getHp() <= 0.f || !a->enabled || !b->enabled) continue;
const float minDist = a->collisionRadius + b->collisionRadius;
if (minDist <= 0.f) continue;
@@ -1322,6 +1322,8 @@ namespace ZL
static constexpr float kMovedEps = 0.05f;
static constexpr float kReplanTriggerDist = 1.8f;
static constexpr int64_t kReplanCooldownMs = 500;
static constexpr float kStuckMovementThreshold = 0.02f;
static constexpr int kStuckFrameThreshold = 4;
for (auto it = replanCooldownRemainingMs.begin(); it != replanCooldownRemainingMs.end();) {
it->second -= deltaMs;
@@ -1355,6 +1357,19 @@ namespace ZL
if (moved > kMovedEps) {
movers.push_back(c);
}
if (c->isMoving()) {
if (moved < kStuckMovementThreshold) {
if (++stuckFrameCounts[c] >= kStuckFrameThreshold) {
c->forceReplan();
stuckFrameCounts[c] = 0;
}
} else {
stuckFrameCounts[c] = 0;
}
} else {
stuckFrameCounts[c] = 0;
}
}
if (movers.empty()) {
@@ -1366,7 +1381,7 @@ namespace ZL
for (Character* walker : characters) {
if (!walker || walker == mover) continue;
if (walker->hp <= 0.f || !walker->enabled) continue;
if (walker->getHp() <= 0.f || !walker->enabled) continue;
if (!walker->isMoving()) continue;
if (replanCooldownRemainingMs.find(walker) != replanCooldownRemainingMs.end()) {
+1
View File
@@ -182,6 +182,7 @@ namespace ZL
std::unordered_map<Character*, Eigen::Vector3f> lastCharacterPositions;
std::unordered_map<Character*, int64_t> replanCooldownRemainingMs;
std::unordered_map<Character*, int> stuckFrameCounts;
static constexpr float NPC_BUMP_CALLBACK_COOLDOWN = 5.0f;
std::unordered_map<int, float> npcBumpedByPlayerCooldown;
+7
View File
@@ -1059,6 +1059,7 @@ namespace ZL {
void MenuManager::setDarklandsMode(bool enabled)
{
std::cout << "MenuManager::setDarklandsMode called" << std::endl;
currentIsDarklands_ = enabled;
if (currentLocationName_ == "uni_interior") {
@@ -1149,8 +1150,14 @@ namespace ZL {
}
void MenuManager::applyCurrentHealthBar() {
std::cout << "MenuManager::applyCurrentHealthBar called step 1" << std::endl;
std::cout << "currentPlayerMaxHp_ is " << currentPlayerMaxHp_ << std::endl;
if (currentPlayerMaxHp_ <= 0.f) return;
std::cout << "MenuManager::applyCurrentHealthBar called step 2" << std::endl;
std::cout << "currentPlayerHp_ is " << currentPlayerHp_ << std::endl;
const float fraction = std::clamp(currentPlayerHp_ / currentPlayerMaxHp_, 0.f, 1.f);
uiManager.setSliderValue("healthBarFill", fraction);
std::string hpText = std::to_string(static_cast<int>(currentPlayerHp_)) + "/" +
std::to_string(static_cast<int>(currentPlayerMaxHp_));
+3 -3
View File
@@ -324,7 +324,7 @@ namespace ZL {
[loc](float value) {
if (loc->player)
{
loc->player->hp = value;
loc->player->setHp(value);
if (loc->player->currentState == AnimationState::ACTION_TO_DEATH || loc->player->currentState == AnimationState::DEATH_IDLE)
{
loc->player->currentState = AnimationState::STAND;
@@ -335,7 +335,7 @@ namespace ZL {
// get_player_hp() → float (0 if no player)
api.set_function("get_player_hp",
[loc]() -> float {
return loc->player ? loc->player->hp : 0.0f;
return loc->player ? loc->player->getHp() : 0.0f;
});
// Global integer store — shared across all location scripts.
@@ -453,7 +453,7 @@ namespace ZL {
std::cerr << "[script] npc_set_hp: index " << index << " out of range\n";
return;
}
npcs[index]->hp = value;
npcs[index]->setHp(value);
});
// npc_set_position(index, x, y, z) — teleports an NPC instantly, no walking.
+1 -1
View File
@@ -391,7 +391,7 @@ namespace ZL {
npc->modelScale = npcData.modelScale;
npc->position = Eigen::Vector3f(npcData.positionX, npcData.positionY, npcData.positionZ);
npc->facingAngle = npcData.facingAngle;
npc->hp = npcData.hp;
npc->setHp(npcData.hp);
npc->initialHp = npcData.hp;
npc->canAttack = npcData.canAttack;
npc->enabled = npcData.enabled;