Skip to content

Commit 3d539ca

Browse files
authored
Bot follow state survives teleport and instances (#236)
1 parent d96f240 commit 3d539ca

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/modules/Bots/playerbot/PlayerbotAI.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ void PlayerbotAI::HandleTeleportAck()
229229
{
230230
bot->GetSession()->HandleMoveWorldportAckOpcode();
231231
}
232+
233+
LastMovement& movement = aiObjectContext->GetValue<LastMovement&>("last movement")->Get();
234+
if (movement.lastFollowState)
235+
{
236+
ChangeStrategy("+follow master,-stay", BOT_STATE_NON_COMBAT);
237+
movement.lastFollowState = false;
238+
}
232239
}
233240

234241
/**

src/modules/Bots/playerbot/strategy/actions/AreaTriggerAction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ bool ReachAreaTriggerAction::Execute(Event event)
4242
return true;
4343
}
4444

45-
ai->ChangeStrategy("-follow,+stay", BOT_STATE_NON_COMBAT);
45+
bool wasFollowing = ai->HasStrategy("follow master", BOT_STATE_NON_COMBAT);
46+
ai->ChangeStrategy("-follow master,+stay", BOT_STATE_NON_COMBAT);
4647

4748
MotionMaster &mm = *bot->GetMotionMaster();
4849
mm.Clear();
@@ -52,7 +53,7 @@ bool ReachAreaTriggerAction::Execute(Event event)
5253
ai->TellMaster("Wait for me");
5354
ai->SetNextCheckDelay(delay);
5455
context->GetValue<LastMovement&>("last movement")->Get().lastAreaTrigger = triggerId;
55-
56+
context->GetValue<LastMovement&>("last movement")->Get().lastFollowState = wasFollowing;
5657
return true;
5758
}
5859

@@ -77,7 +78,7 @@ bool AreaTriggerAction::Execute(Event event)
7778
return true;
7879
}
7980

80-
ai->ChangeStrategy("-follow,+stay", BOT_STATE_NON_COMBAT);
81+
ai->ChangeStrategy("-follow master,+stay", BOT_STATE_NON_COMBAT);
8182

8283
MotionMaster &mm = *bot->GetMotionMaster();
8384
mm.Clear();
@@ -86,7 +87,6 @@ bool AreaTriggerAction::Execute(Event event)
8687
p << triggerId;
8788
p.rpos(0);
8889
bot->GetSession()->HandleAreaTriggerOpcode(p);
89-
9090
ai->TellMaster("Hello");
9191
return true;
9292
}

src/modules/Bots/playerbot/strategy/actions/TeleportAction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ bool TeleportAction::Execute(Event event)
2929
continue;
3030
}
3131

32+
LastMovement& movement = context->GetValue<LastMovement&>("last movement")->Get();
33+
movement.lastFollowState = ai->HasStrategy("follow master", BOT_STATE_NON_COMBAT);
3234
ostringstream out; out << "Teleporting using " << goInfo->name;
3335
ai->TellMasterNoFacing(out.str());
3436

35-
ai->ChangeStrategy("-follow,+stay", BOT_STATE_NON_COMBAT);
37+
ai->ChangeStrategy("-follow master,+stay", BOT_STATE_NON_COMBAT);
3638

3739
Spell *spell = new Spell(bot, pSpellInfo, false);
3840
SpellCastTargets targets;

src/modules/Bots/playerbot/strategy/values/LastMovementValue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ai
1616
lastMoveToOri = 0;
1717
lastFollow = NULL;
1818
lastAreaTrigger = 0; // Initialize lastAreaTrigger
19+
lastFollowState = false;
1920
}
2021

2122
// Copy constructor to copy movement details from another LastMovement object
@@ -29,6 +30,7 @@ namespace ai
2930
lastMoveToY = other.lastMoveToY;
3031
lastMoveToZ = other.lastMoveToZ;
3132
lastMoveToOri = other.lastMoveToOri;
33+
lastFollowState = other.lastFollowState;
3234
}
3335

3436
// Set the last follow unit and reset movement coordinates
@@ -53,6 +55,7 @@ namespace ai
5355
ObjectGuid taxiMaster; // GUID of the taxi master
5456
Unit* lastFollow; // Pointer to the last followed unit
5557
uint32 lastAreaTrigger; // ID of the last area trigger
58+
bool lastFollowState; // whether follow was removed temprarily
5659
float lastMoveToX, lastMoveToY, lastMoveToZ, lastMoveToOri; // Last movement coordinates and orientation
5760
};
5861

0 commit comments

Comments
 (0)