Skip to content
16 changes: 11 additions & 5 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void Creature::onThink(uint32_t interval)

void Creature::forceUpdatePath()
{
if (attackedCreature.expired() && followCreature.expired()) {
if (followCreature.expired()) {
return;
}

Expand Down Expand Up @@ -688,15 +688,12 @@ void Creature::setAttackedCreature(const std::shared_ptr<Creature>& creature)
}

attackedCreature = creature;
creature->addFollower(asCreature());
onAttackedCreature(creature);

if (const auto& player = creature->asPlayer()) {
player->addInFightTicks();
}

forceUpdatePath();

for (const auto& summon : summons | tfs::views::lock_weak_ptrs) {
summon->setAttackedCreature(creature);
}
Expand Down Expand Up @@ -740,15 +737,24 @@ void Creature::setFollowCreature(const std::shared_ptr<Creature>& creature)
return;
}

followCreature = creature;
if (const auto& oldFollow = getFollowCreature()) {
oldFollow->removeFollower(asCreature());
}
creature->addFollower(asCreature());

followCreature = creature;
hasFollowPath = false;
onFollowCreature(creature);

forceUpdatePath();
}

void Creature::removeFollowCreature()
{
if (const auto& oldFollow = getFollowCreature()) {
oldFollow->removeFollower(asCreature());
}

followCreature.reset();
onUnfollowCreature();
}
Expand Down
Loading