From 08cbe2f4ecdd4b06a6be6523d329c58a8ea4d6a3 Mon Sep 17 00:00:00 2001 From: Fuzz Date: Thu, 4 Jul 2024 14:08:21 +1000 Subject: [PATCH] fixes for arena I've been working on with Dave (most credit belongs to him I feel) --- src/PlayerbotAI.cpp | 15 ++++++++++++++- .../actions/BattleGroundJoinAction.cpp | 16 +++++++++++++--- src/strategy/actions/BattleGroundTactics.cpp | 18 +++++++++++++----- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index f3e865d6..25d92a1d 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -1808,6 +1808,16 @@ Player* PlayerbotAI::GetPlayer(ObjectGuid guid) return unit ? unit->ToPlayer() : nullptr; } +uint32 GetCreatureIdForCreatureTemplateId(uint32 creatureTemplateId) +{ + QueryResult results = WorldDatabase.Query("SELECT guid FROM `acore_world`.`creature` WHERE id1 = {} LIMIT 1;", creatureTemplateId); + if (results) { + Field* fields = results->Fetch(); + return fields[0].Get(); + } + return 0; +} + Unit* PlayerbotAI::GetUnit(CreatureData const* creatureData) { if (!creatureData) @@ -1817,7 +1827,10 @@ Unit* PlayerbotAI::GetUnit(CreatureData const* creatureData) if (!map) return nullptr; - auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(creatureData->spawnId); + uint32 spawnId = creatureData->spawnId; + if (!spawnId) // workaround for CreatureData with missing spawnId (this just uses first matching creatureId in DB, but thats ok this method is only used for battlemasters and theres only 1 of each type) + spawnId = GetCreatureIdForCreatureTemplateId(creatureData->id1); + auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(spawnId); if (creatureBounds.first == creatureBounds.second) return nullptr; diff --git a/src/strategy/actions/BattleGroundJoinAction.cpp b/src/strategy/actions/BattleGroundJoinAction.cpp index 05ca2796..6ab94f7c 100644 --- a/src/strategy/actions/BattleGroundJoinAction.cpp +++ b/src/strategy/actions/BattleGroundJoinAction.cpp @@ -252,6 +252,9 @@ bool BGJoinAction::shouldJoinBg(BattlegroundQueueTypeId queueTypeId, Battlegroun if (!sPlayerbotAIConfig->randomBotAutoJoinBG && !hasPlayers) return false; + if (!hasPlayers && isArena) // avoid many arena's being created when 1 player queues a skirmish + return false; + if (!(hasPlayers || hasBots)) return false; @@ -471,7 +474,8 @@ bool BGJoinAction::JoinQueue(uint32 type) isArena = true; // get battlemaster - Unit* unit = botAI->GetUnit(AI_VALUE2(CreatureData const*, "bg master", bgTypeId)); + //Unit* unit = botAI->GetUnit(AI_VALUE2(CreatureData const*, "bg master", bgTypeId)); + Unit* unit = botAI->GetUnit(sRandomPlayerbotMgr->GetBattleMasterGUID(bot, bgTypeId)); if (!unit && isArena) { botAI->GetAiObjectContext()->GetValue("bg type")->Set(0); @@ -950,7 +954,8 @@ bool BGStatusAction::Execute(Event event) { if (ginfo.IsInvitedToBGInstanceGUID && !bot->InBattleground()) { - Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, _bgTypeId); + // BattlegroundMgr::GetBattleground() does not return battleground if bgTypeId==BATTLEGROUND_AA + Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, _bgTypeId == BATTLEGROUND_AA ? BATTLEGROUND_TYPE_NONE : _bgTypeId); if (bg) { if (isArena) @@ -972,6 +977,8 @@ bool BGStatusAction::Execute(Event event) bot->GetSession()->HandleBattleFieldPortOpcode(packet); botAI->ResetStrategies(false); + // if this is first bot into BG they can lose bg strat + botAI->ChangeStrategy("+bg", BOT_STATE_NON_COMBAT); context->GetValue("bg role")->Set(urand(0, 9)); PositionMap& posMap = context->GetValue("position")->Get(); PositionInfo pos = context->GetValue("position")->Get()["bg objective"]; @@ -1049,7 +1056,8 @@ bool BGStatusAction::Execute(Event event) if (ginfo.IsInvitedToBGInstanceGUID) { - Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, _bgTypeId); + // BattlegroundMgr::GetBattleground() does not return battleground if bgTypeId==BATTLEGROUND_AA + Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, _bgTypeId == BATTLEGROUND_AA ? BATTLEGROUND_TYPE_NONE : _bgTypeId); if (!bg) { LOG_ERROR("playerbots", "Bot {} {}:{} <{}>: Missing QueueInfo for {} {}", @@ -1077,6 +1085,8 @@ bool BGStatusAction::Execute(Event event) bot->GetSession()->HandleBattleFieldPortOpcode(packet); botAI->ResetStrategies(false); + // if this is first bot into BG they can lose bg strat + botAI->ChangeStrategy("+bg", BOT_STATE_NON_COMBAT); context->GetValue("bg role")->Set(urand(0, 9)); PositionMap& posMap = context->GetValue("position")->Get(); PositionInfo pos = context->GetValue("position")->Get()["bg objective"]; diff --git a/src/strategy/actions/BattleGroundTactics.cpp b/src/strategy/actions/BattleGroundTactics.cpp index 3dabc821..c7dadfc4 100644 --- a/src/strategy/actions/BattleGroundTactics.cpp +++ b/src/strategy/actions/BattleGroundTactics.cpp @@ -2607,6 +2607,13 @@ bool BGTactics::Execute(Event event) if (bg->GetStatus() == STATUS_WAIT_LEAVE) return false; + if (bg->isArena()) + { + // can't use this in arena - it will crash server wehen vPaths/vFlagIds are used uninitialized + botAI->ResetStrategies(); + return false; + } + if (bg->GetStatus() == STATUS_IN_PROGRESS) botAI->ChangeStrategy("-buff", BOT_STATE_NON_COMBAT); @@ -4866,11 +4873,12 @@ bool ArenaTactics::Execute(Event event) if (botAI->HasStrategy("buff", BOT_STATE_NON_COMBAT)) botAI->ChangeStrategy("-buff", BOT_STATE_NON_COMBAT); - if (sBattlegroundMgr->IsArenaType(bg->GetBgTypeID())) - { - botAI->ResetStrategies(false); - botAI->SetMaster(nullptr); - } +// this causes bot to reset constantly in arena +// if (sBattlegroundMgr->IsArenaType(bg->GetBgTypeID())) +// { +// botAI->ResetStrategies(false); +// botAI->SetMaster(nullptr); +// } if (!bot->IsInCombat()) return moveToCenter(bg);