Skip to content

Commit

Permalink
Handle path on follow events
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-bernardo committed Nov 5, 2024
1 parent de13332 commit ea23035
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
25 changes: 14 additions & 11 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,23 +1030,12 @@ void Creature::setFollowCreature(Creature* creature)
return;
}

if (!listWalkDir.empty()) {
listWalkDir.clear();
onWalkAborted();
}

hasFollowPath = false;
forceUpdateFollowPath = false;
isUpdatingPath = true;

followCreature = creature;
onFollowCreature(creature);
}

void Creature::removeFollowCreature()
{
isUpdatingPath = false;

followCreature = nullptr;
onUnfollowCreature();
}
Expand All @@ -1060,6 +1049,20 @@ bool Creature::canFollowCreature(Creature* creature)
return canSee(creaturePos);
}

void Creature::onFollowCreature(const Creature*)
{
if (!listWalkDir.empty()) {
listWalkDir.clear();
onWalkAborted();
}

hasFollowPath = false;
forceUpdateFollowPath = false;
isUpdatingPath = true;
}

void Creature::onUnfollowCreature() { isUpdatingPath = false; }

double Creature::getDamageRatio(Creature* attacker) const
{
uint32_t totalDamage = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class Creature : virtual public Thing
virtual bool hasFollowingCreature(Creature* creature) { return followCreature == creature; }

// follow events
virtual void onFollowCreature(const Creature*) {}
virtual void onUnfollowCreature() {}
virtual void onFollowCreature(const Creature*);
virtual void onUnfollowCreature();
virtual void onFollowCreatureComplete(const Creature*) {}

// combat functions
Expand Down
7 changes: 6 additions & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,12 @@ uint64_t Player::getGainedExperience(Creature* attacker) const
return 0;
}

void Player::onUnfollowCreature() { stopWalk(); }
void Player::onUnfollowCreature()
{
Creature::onUnfollowCreature();

stopWalk();
}

void Player::setChaseMode(bool mode)
{
Expand Down

0 comments on commit ea23035

Please sign in to comment.