mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 17:09:08 +00:00
Fix. Leave group actions (#1774)
Fix for issue #1768 where the bot master was not getting reset. I also cleaned up leave group action to focus up function scope. I moved the resets from #612 to the actual leaving function. Disclosure: LLMs were NOT used in authoring this PR. Test cases to consider for testers. 1. Master disbands group with random bots. Bots should go about their business. 2. If you can dual box, create a raid where two real player both invite random bots. One player leaves group, their bots should also leave. (edge case, if a random bot that is supposed to leave the group becomes leader they may disband the whole group.
This commit is contained in:
@@ -11,8 +11,11 @@
|
||||
|
||||
bool LeaveGroupAction::Execute(Event event)
|
||||
{
|
||||
Player* master = event.getOwner();
|
||||
return Leave(master);
|
||||
Player* player = event.getOwner();
|
||||
if (player == botAI->GetMaster())
|
||||
return Leave();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PartyCommandAction::Execute(Event event)
|
||||
@@ -26,13 +29,21 @@ bool PartyCommandAction::Execute(Event event)
|
||||
|
||||
if (operation != PARTY_OP_LEAVE)
|
||||
return false;
|
||||
|
||||
// Only leave if master has left the party, and randombot cannot set new master.
|
||||
Player* master = GetMaster();
|
||||
if (master && member == master->GetName())
|
||||
return Leave(bot);
|
||||
|
||||
botAI->Reset();
|
||||
|
||||
{
|
||||
if (sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||
{
|
||||
Player* newMaster = botAI->FindNewMaster();
|
||||
if (newMaster || bot->InBattleground())
|
||||
{
|
||||
botAI->SetMaster(newMaster);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return Leave();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,17 +53,17 @@ bool UninviteAction::Execute(Event event)
|
||||
if (p.GetOpcode() == CMSG_GROUP_UNINVITE)
|
||||
{
|
||||
p.rpos(0);
|
||||
std::string membername;
|
||||
p >> membername;
|
||||
std::string memberName;
|
||||
p >> memberName;
|
||||
|
||||
// player not found
|
||||
if (!normalizePlayerName(membername))
|
||||
if (!normalizePlayerName(memberName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bot->GetName() == membername)
|
||||
return Leave(bot);
|
||||
if (bot->GetName() == memberName)
|
||||
return Leave();
|
||||
}
|
||||
|
||||
if (p.GetOpcode() == CMSG_GROUP_UNINVITE_GUID)
|
||||
@@ -62,50 +73,29 @@ bool UninviteAction::Execute(Event event)
|
||||
p >> guid;
|
||||
|
||||
if (bot->GetGUID() == guid)
|
||||
return Leave(bot);
|
||||
return Leave();
|
||||
}
|
||||
|
||||
botAI->Reset();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LeaveGroupAction::Leave(Player* player)
|
||||
bool LeaveGroupAction::Leave()
|
||||
{
|
||||
if (player &&
|
||||
!botAI &&
|
||||
!botAI->GetSecurity()->CheckLevelFor(PLAYERBOT_SECURITY_INVITE, false, player))
|
||||
|
||||
if (!botAI)
|
||||
return false;
|
||||
|
||||
bool aiMaster = GET_PLAYERBOT_AI(botAI->GetMaster()) != nullptr;
|
||||
|
||||
botAI->TellMaster("Goodbye!", PLAYERBOT_SECURITY_TALK);
|
||||
|
||||
bool randomBot = sRandomPlayerbotMgr->IsRandomBot(bot);
|
||||
bool shouldStay = randomBot && bot->GetGroup() && player == bot;
|
||||
if (!shouldStay)
|
||||
{
|
||||
botAI->LeaveOrDisbandGroup();
|
||||
}
|
||||
|
||||
if (randomBot)
|
||||
{
|
||||
GET_PLAYERBOT_AI(bot)->SetMaster(nullptr);
|
||||
}
|
||||
|
||||
if (!aiMaster)
|
||||
botAI->ResetStrategies(!randomBot);
|
||||
|
||||
botAI->Reset();
|
||||
Player* master = botAI -> GetMaster();
|
||||
if (master)
|
||||
botAI->TellMaster("Goodbye!", PLAYERBOT_SECURITY_TALK);
|
||||
|
||||
botAI->LeaveOrDisbandGroup();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LeaveFarAwayAction::Execute(Event event)
|
||||
{
|
||||
// allow bot to leave party when they want
|
||||
return Leave(botAI->GetGroupMaster());
|
||||
return Leave();
|
||||
}
|
||||
|
||||
bool LeaveFarAwayAction::isUseful()
|
||||
@@ -165,7 +155,5 @@ bool LeaveFarAwayAction::isUseful()
|
||||
return true;
|
||||
}
|
||||
|
||||
botAI->Reset();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user