mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-28 14:25:56 +00:00
# Pull Request
This is the first in a series of PRs intended to eliminate warnings in
the module. The design intent is to eliminate the calling event when not
needed in the body of the function. Based off of SmashingQuasars work.
---
## How to Test the Changes
- Step-by-step instructions to test the change
- Any required setup (e.g. multiple players, bots, specific
configuration)
- Expected behavior and how to verify it
## Complexity & Impact
- Does this change add new decision branches?
- [x] No
- [ ] Yes (**explain below**)
- Does this change increase per-bot or per-tick processing?
- [x] No
- [ ] Yes (**describe and justify impact**)
- Could this logic scale poorly under load?
- [x] No
- [ ] Yes (**explain why**)
---
## Defaults & Configuration
- Does this change modify default bot behavior?
- [x] No
- [ ] Yes (**explain why**)
If this introduces more advanced or AI-heavy logic:
- [ ] Lightweight mode remains the default
- [ ] More complex behavior is optional and thereby configurable
---
## AI Assistance
- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
- [x] No
- [ ] Yes (**explain below**)
---
## Final Checklist
- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed
---
## Notes for Reviewers
Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.
---------
Co-authored-by: bashermens <31279994+hermensbas@users.noreply.github.com>
160 lines
3.7 KiB
C++
160 lines
3.7 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
|
|
* and/or modify it under version 3 of the License, or (at your option), any later version.
|
|
*/
|
|
|
|
#include "LeaveGroupAction.h"
|
|
|
|
#include "Event.h"
|
|
#include "PlayerbotAIConfig.h"
|
|
#include "Playerbots.h"
|
|
|
|
bool LeaveGroupAction::Execute(Event event)
|
|
{
|
|
Player* player = event.getOwner();
|
|
if (player == botAI->GetMaster())
|
|
return Leave();
|
|
|
|
return false;
|
|
}
|
|
|
|
bool PartyCommandAction::Execute(Event event)
|
|
{
|
|
WorldPacket& p = event.getPacket();
|
|
p.rpos(0);
|
|
uint32 operation;
|
|
std::string member;
|
|
|
|
p >> operation >> member;
|
|
|
|
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())
|
|
{
|
|
if (sRandomPlayerbotMgr.IsRandomBot(bot))
|
|
{
|
|
Player* newMaster = botAI->FindNewMaster();
|
|
if (newMaster || bot->InBattleground())
|
|
{
|
|
botAI->SetMaster(newMaster);
|
|
return false;
|
|
}
|
|
}
|
|
return Leave();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool UninviteAction::Execute(Event event)
|
|
{
|
|
WorldPacket& p = event.getPacket();
|
|
if (p.GetOpcode() == CMSG_GROUP_UNINVITE)
|
|
{
|
|
p.rpos(0);
|
|
std::string memberName;
|
|
p >> memberName;
|
|
|
|
// player not found
|
|
if (!normalizePlayerName(memberName))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (bot->GetName() == memberName)
|
|
return Leave();
|
|
}
|
|
|
|
if (p.GetOpcode() == CMSG_GROUP_UNINVITE_GUID)
|
|
{
|
|
p.rpos(0);
|
|
ObjectGuid guid;
|
|
p >> guid;
|
|
|
|
if (bot->GetGUID() == guid)
|
|
return Leave();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool LeaveGroupAction::Leave()
|
|
{
|
|
if (!botAI)
|
|
return false;
|
|
|
|
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();
|
|
}
|
|
|
|
bool LeaveFarAwayAction::isUseful()
|
|
{
|
|
if (bot->InBattleground())
|
|
return false;
|
|
|
|
if (bot->InBattlegroundQueue())
|
|
return false;
|
|
|
|
if (!bot->GetGroup())
|
|
return false;
|
|
|
|
Player* groupLeader = botAI->GetGroupLeader();
|
|
Player* trueMaster = botAI->GetMaster();
|
|
if (!groupLeader || (bot == groupLeader && !botAI->IsRealPlayer()))
|
|
return false;
|
|
|
|
PlayerbotAI* groupLeaderBotAI = nullptr;
|
|
if (groupLeader)
|
|
groupLeaderBotAI = GET_PLAYERBOT_AI(groupLeader);
|
|
if (groupLeader && !groupLeaderBotAI)
|
|
return false;
|
|
|
|
if (trueMaster && !GET_PLAYERBOT_AI(trueMaster))
|
|
return false;
|
|
|
|
if (botAI->IsAlt() &&
|
|
(!groupLeaderBotAI || groupLeaderBotAI->IsRealPlayer())) // Don't leave group when alt grouped with player groupLeader.
|
|
return false;
|
|
|
|
if (botAI->GetGrouperType() == GrouperType::SOLO)
|
|
return true;
|
|
|
|
uint32 dCount = AI_VALUE(uint32, "death count");
|
|
|
|
if (dCount > 9)
|
|
return true;
|
|
|
|
if (dCount > 4 && !botAI->HasRealPlayerMaster())
|
|
return true;
|
|
|
|
if (bot->GetGuildId() == groupLeader->GetGuildId())
|
|
{
|
|
if (bot->GetLevel() > groupLeader->GetLevel() + 5)
|
|
{
|
|
if (AI_VALUE(bool, "should get money"))
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (abs(int32(groupLeader->GetLevel() - bot->GetLevel())) > 4)
|
|
return true;
|
|
|
|
if (bot->GetMapId() != groupLeader->GetMapId() || bot->GetDistance2d(groupLeader) >= 2 * sPlayerbotAIConfig.rpgDistance)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|