Skip to content

Commit

Permalink
fix: death call several times (#3186)
Browse files Browse the repository at this point in the history
fix #3177
  • Loading branch information
mehah authored Dec 21, 2024
1 parent 13ae9e5 commit ba2c41f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,10 @@ std::shared_ptr<Item> Creature::getCorpse(const std::shared_ptr<Creature> &, con
}

void Creature::changeHealth(int32_t healthChange, bool sendHealthChange /* = true*/) {
if (isLifeless()) {
return;
}

int32_t oldHealth = health;

if (healthChange > 0) {
Expand Down
6 changes: 5 additions & 1 deletion src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ class Creature : virtual public Thing, public SharedObject {
}

bool isAlive() const {
return !isDead();
return !isLifeless();
}

bool isLifeless() const {
return health <= 0;
}

virtual int32_t getMaxHealth() const {
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ void Monster::onThink_async() {

void Monster::doAttacking(uint32_t interval) {
const auto &attackedCreature = getAttackedCreature();
if (!attackedCreature || (isSummon() && attackedCreature.get() == this)) {
if (!attackedCreature || attackedCreature->isLifeless() || (isSummon() && attackedCreature.get() == this)) {
return;
}

Expand Down

0 comments on commit ba2c41f

Please sign in to comment.