fixes for arena I've been working on with Dave (most credit belongs to him I feel)

This commit is contained in:
Fuzz
2024-07-04 14:08:21 +10:00
parent 6dddab7c1a
commit 08cbe2f4ec
3 changed files with 40 additions and 9 deletions

View File

@@ -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<uint32>();
}
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;

View File

@@ -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<uint32>("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<uint32>("bg role")->Set(urand(0, 9));
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
PositionInfo pos = context->GetValue<PositionMap&>("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<uint32>("bg role")->Set(urand(0, 9));
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
PositionInfo pos = context->GetValue<PositionMap&>("position")->Get()["bg objective"];

View File

@@ -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);