Skip to content

Commit

Permalink
fix: monster target list erasing after player died (opentibiabr#839)
Browse files Browse the repository at this point in the history
When dying, the spectator's list of players was cleared, that is, if a player died, the target of all others was cleared.
Also fixed the bug that when a player dies near the temple and a creature is in his sight, the creature will not target the player.
  • Loading branch information
dudantas authored Feb 4, 2023
1 parent 3f6c671 commit d52581f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 12 additions & 6 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,18 @@ void Creature::onCreatureAppear(Creature* creature, bool isLogin)

void Creature::onRemoveCreature(Creature* creature, bool)
{
onCreatureDisappear(creature, true);
if (creature != this && isMapLoaded) {
if (creature->getPosition().z == getPosition().z) {
updateTileCache(creature->getTile(), creature->getPosition());
}
}
onCreatureDisappear(creature, true);
if (creature != this && isMapLoaded) {
if (creature->getPosition().z == getPosition().z) {
updateTileCache(creature->getTile(), creature->getPosition());
}
}

// Update player from monster target list (avoid memory usage after clean)
if (auto monster = getMonster(); monster && monster->getAttackedCreature() == creature) {
monster->setAttackedCreature(creature);
monster->setFollowCreature(creature);
}
}

void Creature::onCreatureDisappear(const Creature* creature, bool isLogout)
Expand Down
5 changes: 1 addition & 4 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@ bool Player::spawn()
}

SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, position, false, true);
g_game().map.getSpectators(spectators, position);
for (Creature* spectator : spectators) {
if (!spectator) {
continue;
Expand Down Expand Up @@ -2767,9 +2767,6 @@ void Player::despawn()
}

spectator->onRemoveCreature(this, false);
// Remove player from spectator target list
spectator->setAttackedCreature(nullptr);
spectator->setFollowCreature(nullptr);
}

tile->removeCreature(this);
Expand Down

0 comments on commit d52581f

Please sign in to comment.