Skip to content

Commit

Permalink
use a trigger to leave BG
Browse files Browse the repository at this point in the history
  • Loading branch information
celguar committed Mar 23, 2024
1 parent e92cb38 commit fe609ef
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions playerbot/strategy/actions/BattleGroundJoinAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,6 @@ bool BGLeaveAction::Execute(Event& event)
if (!(bot->InBattleGroundQueue() || bot->InBattleGround()))
return false;

//ai->ChangeStrategy("-bg", BotState::BOT_STATE_NON_COMBAT);

BattleGroundQueueTypeId queueTypeId = bot->GetBattleGroundQueueTypeId(0);
BattleGroundTypeId _bgTypeId = sServerFacade.BgTemplateId(queueTypeId);
uint8 type = false;
Expand Down Expand Up @@ -1034,6 +1032,10 @@ bool BGLeaveAction::Execute(Event& event)
ai->GetAiObjectContext()->GetValue<uint32>("bg type")->Set(0);
ai->GetAiObjectContext()->GetValue<uint32>("bg role")->Set(0);
ai->GetAiObjectContext()->GetValue<uint32>("arena type")->Set(0);
ai::PositionMap& posMap = context->GetValue<ai::PositionMap&>("position")->Get();
ai::PositionEntry pos = context->GetValue<ai::PositionMap&>("position")->Get()["bg objective"];
pos.Reset();
posMap["bg objective"] = pos;
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions playerbot/strategy/generic/BattlegroundStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ void BattlegroundStrategy::InitNonCombatTriggers(std::list<TriggerNode*> &trigge
"very often",
NextAction::array(0, new NextAction("bg check objective", 10.0f), NULL)));

triggers.push_back(new TriggerNode(
"bg ended",
NextAction::array(0, new NextAction("bg leave", ACTION_HIGH), NULL)));

/*triggers.push_back(new TriggerNode(
"enemy flagcarrier near",
NextAction::array(0, new NextAction("attack enemy flag carrier", 80.0f), NULL)));*/
Expand Down
10 changes: 10 additions & 0 deletions playerbot/strategy/triggers/PvpTriggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ bool BgActiveTrigger::IsActive()
return false;
}

bool BgEndedTrigger::IsActive()
{
if (bot->InBattleGround())
{
if (bot->GetBattleGround() && bot->GetBattleGround()->GetStatus() == STATUS_WAIT_LEAVE)
return true;
}
return false;
}

bool BgInviteActiveTrigger::IsActive()
{
if (bot->InBattleGround() || !bot->InBattleGroundQueue())
Expand Down
9 changes: 9 additions & 0 deletions playerbot/strategy/triggers/PvpTriggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ namespace ai
virtual bool IsActive();
};

class BgEndedTrigger : public Trigger
{
public:
BgEndedTrigger(PlayerbotAI* ai) : Trigger(ai, "bg ended", 10) {}

public:
virtual bool IsActive();
};

class BgInviteActiveTrigger : public Trigger
{
public:
Expand Down
2 changes: 2 additions & 0 deletions playerbot/strategy/triggers/TriggerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ namespace ai

creators["bg waiting"] = &TriggerContext::bg_waiting;
creators["bg active"] = &TriggerContext::bg_active;
creators["bg ended"] = &TriggerContext::bg_ended;
creators["bg invite active"] = &TriggerContext::bg_invite_active;
creators["player has no flag"] = &TriggerContext::player_has_no_flag;
creators["player has flag"] = &TriggerContext::player_has_flag;
Expand Down Expand Up @@ -321,6 +322,7 @@ namespace ai
static Trigger* player_has_no_flag(PlayerbotAI* ai) { return new PlayerHasNoFlag(ai); }
static Trigger* bg_waiting(PlayerbotAI* ai) { return new BgWaitingTrigger(ai); }
static Trigger* bg_active(PlayerbotAI* ai) { return new BgActiveTrigger(ai); }
static Trigger* bg_ended(PlayerbotAI* ai) { return new BgEndedTrigger(ai); }
static Trigger* bg_invite_active(PlayerbotAI* ai) { return new BgInviteActiveTrigger(ai); }
static Trigger* player_has_flag(PlayerbotAI* ai) { return new PlayerHasFlag(ai); }
static Trigger* team_has_flag(PlayerbotAI* ai) { return new TeamHasFlag(ai); }
Expand Down

0 comments on commit fe609ef

Please sign in to comment.