removeFromGroup replaced with worldpackets

This commit is contained in:
bash
2025-10-05 20:05:56 +02:00
parent 377ac199a7
commit 1faf20f567
5 changed files with 69 additions and 58 deletions

View File

@@ -378,10 +378,7 @@ void PlayerbotAI::UpdateAIGroupMembership()
PlayerbotAI* leaderAI = GET_PLAYERBOT_AI(leader); PlayerbotAI* leaderAI = GET_PLAYERBOT_AI(leader);
if (leaderAI && !leaderAI->IsRealPlayer()) if (leaderAI && !leaderAI->IsRealPlayer())
{ {
WorldPacket* packet = new WorldPacket(CMSG_GROUP_DISBAND); RemoveFromGroup();
bot->GetSession()->QueuePacket(packet);
// bot->RemoveFromGroup();
ResetStrategies();
} }
} }
} }
@@ -405,10 +402,7 @@ void PlayerbotAI::UpdateAIGroupMembership()
} }
if (!hasRealPlayer) if (!hasRealPlayer)
{ {
WorldPacket* packet = new WorldPacket(CMSG_GROUP_DISBAND); RemoveFromGroup();
bot->GetSession()->QueuePacket(packet);
// bot->RemoveFromGroup();
ResetStrategies();
} }
} }
} }
@@ -791,6 +785,16 @@ void PlayerbotAI::Reset(bool full)
} }
} }
void PlayerbotAI::RemoveFromGroup()
{
if (!bot || !bot->GetGroup() || bot->IsRealPlayer())
return;
WorldPacket* packet = new WorldPacket(CMSG_GROUP_DISBAND);
bot->GetSession()->QueuePacket(packet);
ResetStrategies();
}
bool PlayerbotAI::IsAllowedCommand(std::string const text) bool PlayerbotAI::IsAllowedCommand(std::string const text)
{ {
if (unsecuredCommands.empty()) if (unsecuredCommands.empty())

View File

@@ -415,6 +415,7 @@ public:
void ResetStrategies(bool load = false); void ResetStrategies(bool load = false);
void ReInitCurrentEngine(); void ReInitCurrentEngine();
void Reset(bool full = false); void Reset(bool full = false);
void PlayerbotAI::RemoveFromGroup()
static bool IsTank(Player* player, bool bySpec = false); static bool IsTank(Player* player, bool bySpec = false);
static bool IsHeal(Player* player, bool bySpec = false); static bool IsHeal(Player* player, bool bySpec = false);
static bool IsDps(Player* player, bool bySpec = false); static bool IsDps(Player* player, bool bySpec = false);

View File

@@ -514,12 +514,12 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
if (!groupValid) if (!groupValid)
{ {
bot->RemoveFromGroup(); botAI->RemoveFromGroup();
} }
} }
group = bot->GetGroup(); group = bot->GetGroup();
if (group) if (!group)
{ {
botAI->ResetStrategies(); botAI->ResetStrategies();
} }

View File

@@ -1517,33 +1517,38 @@ bool RandomPlayerbotMgr::ProcessBot(uint32 bot)
return false; return false;
} }
bool RandomPlayerbotMgr::ProcessBot(Player* player) bool RandomPlayerbotMgr::ProcessBot(Player* bot)
{ {
uint32 bot = player->GetGUID().GetCounter();
if (player->InBattleground()) PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (botAI)
return false; return false;
if (player->InBattlegroundQueue()) if (bot->InBattleground())
return false; return false;
if (bot->InBattlegroundQueue())
return false;
uint32 botId = bot->GetGUID().GetCounter();
// if death revive // if death revive
if (player->isDead()) if (bot->isDead())
{ {
if (!GetEventValue(bot, "dead")) if (!GetEventValue(botId, "dead"))
{ {
uint32 randomTime = uint32 randomTime =
urand(sPlayerbotAIConfig->minRandomBotReviveTime, sPlayerbotAIConfig->maxRandomBotReviveTime); urand(sPlayerbotAIConfig->minRandomBotReviveTime, sPlayerbotAIConfig->maxRandomBotReviveTime);
LOG_DEBUG("playerbots", "Mark bot {} as dead, will be revived in {}s.", player->GetName().c_str(), LOG_DEBUG("playerbots", "Mark bot {} as dead, will be revived in {}s.", bot->GetName().c_str(),
randomTime); randomTime);
SetEventValue(bot, "dead", 1, sPlayerbotAIConfig->maxRandomBotInWorldTime); SetEventValue(botId, "dead", 1, sPlayerbotAIConfig->maxRandomBotInWorldTime);
SetEventValue(bot, "revive", 1, randomTime); SetEventValue(botId, "revive", 1, randomTime);
return false; return false;
} }
if (!GetEventValue(bot, "revive")) if (!GetEventValue(botId, "revive"))
{ {
Revive(player); Revive(bot);
return true; return true;
} }
@@ -1551,34 +1556,31 @@ bool RandomPlayerbotMgr::ProcessBot(Player* player)
} }
// leave group if leader is rndbot // leave group if leader is rndbot
Group* group = player->GetGroup(); Group* group = bot->GetGroup();
if (group && !group->isLFGGroup() && IsRandomBot(group->GetLeader())) if (group && !group->isLFGGroup() && IsRandomBot(group->GetLeader()))
{ {
player->RemoveFromGroup(); botAI->RemoveFromGroup();
LOG_INFO("playerbots", "Bot {} remove from group since leader is random bot.", player->GetName().c_str()); LOG_INFO("playerbots", "Bot {} remove from group since leader is random bot.", bot->GetName().c_str());
} }
// only randomize and teleport idle bots // only randomize and teleport idle bots
bool idleBot = false; bool idleBot = false;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player); if (TravelTarget* target = botAI->GetAiObjectContext()->GetValue<TravelTarget*>("travel target")->Get())
if (botAI)
{ {
if (TravelTarget* target = botAI->GetAiObjectContext()->GetValue<TravelTarget*>("travel target")->Get()) if (target->getTravelState() == TravelState::TRAVEL_STATE_IDLE)
{
if (target->getTravelState() == TravelState::TRAVEL_STATE_IDLE)
{
idleBot = true;
}
}
else
{ {
idleBot = true; idleBot = true;
} }
} }
else
{
idleBot = true;
}
if (idleBot) if (idleBot)
{ {
// randomize // randomize
uint32 randomize = GetEventValue(bot, "randomize"); uint32 randomize = GetEventValue(botId, "randomize");
if (!randomize) if (!randomize)
{ {
// bool randomiser = true; // bool randomiser = true;
@@ -1602,12 +1604,12 @@ bool RandomPlayerbotMgr::ProcessBot(Player* player)
// } // }
// if (randomiser) // if (randomiser)
// { // {
Randomize(player); Randomize(bot);
LOG_DEBUG("playerbots", "Bot #{} {}:{} <{}>: randomized", bot, LOG_DEBUG("playerbots", "Bot #{} {}:{} <{}>: randomized", botId,
player->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", player->GetLevel(), player->GetName()); bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName());
uint32 randomTime = uint32 randomTime =
urand(sPlayerbotAIConfig->minRandomBotRandomizeTime, sPlayerbotAIConfig->maxRandomBotRandomizeTime); urand(sPlayerbotAIConfig->minRandomBotRandomizeTime, sPlayerbotAIConfig->maxRandomBotRandomizeTime);
ScheduleRandomize(bot, randomTime); ScheduleRandomize(botId, randomTime);
return true; return true;
} }
@@ -1619,15 +1621,15 @@ bool RandomPlayerbotMgr::ProcessBot(Player* player)
// return true; // return true;
// } // }
uint32 teleport = GetEventValue(bot, "teleport"); uint32 teleport = GetEventValue(botId, "teleport");
if (!teleport) if (!teleport)
{ {
LOG_DEBUG("playerbots", "Bot #{} <{}>: teleport for level and refresh", bot, player->GetName()); LOG_DEBUG("playerbots", "Bot #{} <{}>: teleport for level and refresh", botId, bot->GetName());
Refresh(player); Refresh(bot);
RandomTeleportForLevel(player); RandomTeleportForLevel(bot);
uint32 time = urand(sPlayerbotAIConfig->minRandomBotTeleportInterval, uint32 time = urand(sPlayerbotAIConfig->minRandomBotTeleportInterval,
sPlayerbotAIConfig->maxRandomBotTeleportInterval); sPlayerbotAIConfig->maxRandomBotTeleportInterval);
ScheduleTeleport(bot, time); ScheduleTeleport(botId, time);
return true; return true;
} }
} }
@@ -2376,6 +2378,10 @@ void RandomPlayerbotMgr::IncreaseLevel(Player* bot)
void RandomPlayerbotMgr::RandomizeFirst(Player* bot) void RandomPlayerbotMgr::RandomizeFirst(Player* bot)
{ {
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
if (botAI)
return;
uint32 maxLevel = sPlayerbotAIConfig->randomBotMaxLevel; uint32 maxLevel = sPlayerbotAIConfig->randomBotMaxLevel;
if (maxLevel > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) if (maxLevel > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
maxLevel = sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL); maxLevel = sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL);
@@ -2433,7 +2439,6 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot)
} }
SetValue(bot, "level", level); SetValue(bot, "level", level);
PlayerbotFactory factory(bot, level); PlayerbotFactory factory(bot, level);
factory.Randomize(false); factory.Randomize(false);
@@ -2455,11 +2460,10 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot)
PlayerbotsDatabase.Execute(stmt); PlayerbotsDatabase.Execute(stmt);
// teleport to a random inn for bot level // teleport to a random inn for bot level
if (GET_PLAYERBOT_AI(bot)) botAI->Reset(true);
GET_PLAYERBOT_AI(bot)->Reset(true);
if (bot->GetGroup()) if (bot->GetGroup())
bot->RemoveFromGroup(); botAI->RemoveFromGroup();
if (pmo) if (pmo)
pmo->finish(); pmo->finish();
@@ -2469,12 +2473,13 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot)
void RandomPlayerbotMgr::RandomizeMin(Player* bot) void RandomPlayerbotMgr::RandomizeMin(Player* bot)
{ {
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
if (botAI)
return;
PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "RandomizeMin"); PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "RandomizeMin");
uint32 level = sPlayerbotAIConfig->randomBotMinLevel; uint32 level = sPlayerbotAIConfig->randomBotMinLevel;
SetValue(bot, "level", level); SetValue(bot, "level", level);
PlayerbotFactory factory(bot, level); PlayerbotFactory factory(bot, level);
factory.Randomize(false); factory.Randomize(false);
@@ -2496,11 +2501,10 @@ void RandomPlayerbotMgr::RandomizeMin(Player* bot)
PlayerbotsDatabase.Execute(stmt); PlayerbotsDatabase.Execute(stmt);
// teleport to a random inn for bot level // teleport to a random inn for bot level
if (GET_PLAYERBOT_AI(bot)) botAI->Reset(true);
GET_PLAYERBOT_AI(bot)->Reset(true);
if (bot->GetGroup()) if (bot->GetGroup())
bot->RemoveFromGroup(); botAI->RemoveFromGroup();
if (pmo) if (pmo)
pmo->finish(); pmo->finish();
@@ -2582,7 +2586,7 @@ void RandomPlayerbotMgr::Refresh(Player* bot)
bot->SetMoney(money + 500 * sqrt(urand(1, bot->GetLevel() * 5))); bot->SetMoney(money + 500 * sqrt(urand(1, bot->GetLevel() * 5)));
if (bot->GetGroup()) if (bot->GetGroup())
bot->RemoveFromGroup(); botAI->RemoveFromGroup();
if (pmo) if (pmo)
pmo->finish(); pmo->finish();

View File

@@ -70,10 +70,12 @@ bool UninviteAction::Execute(Event event)
return false; return false;
} }
bool LeaveGroupAction::Leave(Player* player) static bool LeaveGroupAction::Leave(Player* player)
{ {
if (player && !GET_PLAYERBOT_AI(player) && if (player &&
!botAI &&
!botAI->GetSecurity()->CheckLevelFor(PLAYERBOT_SECURITY_INVITE, false, player)) !botAI->GetSecurity()->CheckLevelFor(PLAYERBOT_SECURITY_INVITE, false, player))
return false; return false;
bool aiMaster = GET_PLAYERBOT_AI(botAI->GetMaster()) != nullptr; bool aiMaster = GET_PLAYERBOT_AI(botAI->GetMaster()) != nullptr;
@@ -84,7 +86,7 @@ bool LeaveGroupAction::Leave(Player* player)
bool shouldStay = randomBot && bot->GetGroup() && player == bot; bool shouldStay = randomBot && bot->GetGroup() && player == bot;
if (!shouldStay) if (!shouldStay)
{ {
bot->RemoveFromGroup(); botAI->RemoveFromGroup();
} }
if (randomBot) if (randomBot)