Fixing some stuff related to attacks

This commit is contained in:
Vladislav Khorev committed 2026-07-12 16:55:23 +03:00
1 parent 9d03b52c2a
commit 92929118d5
7 files changed
+32 -7

No files matched your search

+18 -1
View File
@@ -744,8 +744,25 @@ namespace ZL
// Wire HP-change callbacks so all player instances update the health bar HUD.
for (auto& [name, loc] : gameState.locations) {
if (loc->player) {
loc->player->state.onHpChanged = [this](float hp, float maxHp) {
loc->player->state.onHpChanged = [this, loc](float hp, float maxHp, int attackerIndex) {
menuManager.updateHealthBar(hp, maxHp);
if (attackerIndex != CharacterState::kNoTarget) {
//Someone attacked, cancel dialogue and agro the player
if (loc->dialogueSystem.isDialogueActive()) {
loc->dialogueSystem.stopDialogue();
}
if ((loc->player->state.attackTargetIndex == CharacterState::kNoTarget ||
((loc->player->state.attackTargetIndex >= 0) &&
(loc->npcs[loc->player->state.attackTargetIndex]->state.hp <= 0)))
&&
loc->player->isMoving() == false) {
loc->player->state.attackTargetIndex = attackerIndex;
}
}
};
}
}