Skip to content

Commit

Permalink
fix: creature attacked by monster (opentibiabr#1793)
Browse files Browse the repository at this point in the history
It is necessary to remove the attacked creature if a path cannot be found.
  • Loading branch information
mehah authored Nov 11, 2023
1 parent 483b32b commit fa0e120
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
8 changes: 5 additions & 3 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,16 @@ void Creature::goToFollowCreature() {
}
}

if (listDir.empty()) {
hasFollowPath = getPathTo(getFollowCreature()->getPosition(), listDir, fpp);
if (followCreature->getPlayer() && followCreature->getPlayer()->isDisconnected()) {
hasFollowPath = false;
} else if (listDir.empty()) {
hasFollowPath = getPathTo(followCreature->getPosition(), listDir, fpp);
}

startAutoWalk(listDir.data());

if (executeOnFollow) {
onFollowCreatureComplete(getFollowCreature());
onFollowCreatureComplete(followCreature);
}
}

Expand Down
32 changes: 20 additions & 12 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,20 +601,28 @@ void Monster::onFollowCreatureComplete(const std::shared_ptr<Creature> &creature
return;
}

auto it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID());
if (it == targetIDList.end()) {
return;
}
const auto &it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID());
if (it != targetIDList.end()) {
if (const auto &target = targetListMap[*it].lock()) {
targetIDList.erase(it);

if (const auto &target = targetListMap[*it].lock()) {
targetIDList.erase(it);
if (hasFollowPath) {
targetIDList.push_front(target->getID());
} else if (!isSummon()) {
targetIDList.push_back(target->getID());
} else {
targetListMap.erase(target->getID());
}
}
}

if (hasFollowPath) {
targetIDList.push_front(target->getID());
} else if (!isSummon()) {
targetIDList.push_back(target->getID());
} else {
targetListMap.erase(target->getID());
// Change the target if necessary
if (!hasFollowPath && !isSummon() && !targetIDList.empty() && targetIDList.front() != creature->getID()) {
const auto &itMap = targetListMap.find(targetIDList.front());
if (itMap != targetListMap.end()) {
if (const auto &target = itMap->second.lock()) {
selectTarget(target);
}
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2548,14 +2548,6 @@ BlockType_t Player::blockHit(std::shared_ptr<Creature> attacker, CombatType_t co
return blockType;
}

uint32_t Player::getIP() const {
if (client) {
return client->getIP();
}

return 0;
}

void Player::death(std::shared_ptr<Creature> lastHitCreature) {
loginPosition = town->getTemplePosition();

Expand Down
9 changes: 8 additions & 1 deletion src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,14 @@ class Player final : public Creature, public Cylinder, public Bankable {
client->disconnect();
}
}
uint32_t getIP() const;

uint32_t getIP() const {
return client ? client->getIP() : 0;
}

bool isDisconnected() const {
return getIP() == 0;
}

void addContainer(uint8_t cid, std::shared_ptr<Container> container);
void closeContainer(uint8_t cid);
Expand Down

0 comments on commit fa0e120

Please sign in to comment.