mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Merge pull request #298 from fuzzdeveloper/master
Fixes to make bots work in arena (big shoutout to Dave on the discord who worked alongside me on this)
This commit is contained in:
@@ -637,7 +637,7 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
|
||||
if (bgType == BATTLEGROUND_RB)
|
||||
bgType = player->GetBattleground()->GetBgTypeID(true);
|
||||
|
||||
if (bgType <= BATTLEGROUND_EY || bgType == BATTLEGROUND_IC) // do not add for not supported bg
|
||||
if ((bgType <= BATTLEGROUND_EY || bgType == BATTLEGROUND_IC) && !player->InArena()) // do not add for not supported bg or arena
|
||||
nonCombatEngine->addStrategy("battleground");
|
||||
|
||||
if (bgType == BATTLEGROUND_WS)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,10 @@ bool BGStatusAction::Execute(Event event)
|
||||
bot->GetSession()->HandleBattleFieldPortOpcode(packet);
|
||||
|
||||
botAI->ResetStrategies(false);
|
||||
if (!bot->GetBattleground()) {
|
||||
// first bot to join wont have battleground and PlayerbotAI::ResetStrategies() wont set them up properly, set bg for "bg strategy check" to fix that
|
||||
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 +1058,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 +1087,10 @@ bool BGStatusAction::Execute(Event event)
|
||||
bot->GetSession()->HandleBattleFieldPortOpcode(packet);
|
||||
|
||||
botAI->ResetStrategies(false);
|
||||
if (!bot->GetBattleground()) {
|
||||
// first bot to join wont have battleground and PlayerbotAI::ResetStrategies() wont set them up properly, set bg for "bg strategy check" to fix that
|
||||
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"];
|
||||
|
||||
@@ -474,6 +474,48 @@ BattleBotPath vPath_AB_AllianceBase_to_Stables =
|
||||
{ 1167.98f, 1202.9f, -56.4743f, nullptr },
|
||||
};
|
||||
|
||||
// Blacksmith to Lumber Mill
|
||||
BattleBotPath vPath_AB_Blacksmith_to_LumberMill =
|
||||
{
|
||||
{ 967.04f, 1039.03f, -45.091f, nullptr },
|
||||
{ 933.67f, 1016.49f, -50.5154f, nullptr },
|
||||
{ 904.02f, 996.63f, -62.3461f, nullptr },
|
||||
{ 841.74f, 985.23f, -58.8920f, nullptr },
|
||||
{ 796.25f, 1009.93f, -44.3286f, nullptr },
|
||||
{ 781.29f, 1034.49f, -32.887f, nullptr },
|
||||
{ 793.17f, 1107.21f, 5.5663f, nullptr },
|
||||
{ 848.98f, 1155.9f, 11.3453f, nullptr },
|
||||
};
|
||||
|
||||
// Blacksmith to GoldMine
|
||||
BattleBotPath vPath_AB_Blacksmith_to_GoldMine =
|
||||
{
|
||||
{ 1035.98f, 1015.66f, -46.0278f, nullptr },
|
||||
{ 1096.86f, 1002.05f, -60.8013f, nullptr },
|
||||
{ 1159.93f, 1003.69f, -63.8378f, nullptr },
|
||||
{ 1198.03f, 1064.09f, -65.8385f, nullptr },
|
||||
{ 1218.58f, 1016.96f, -76.9848f, nullptr },
|
||||
{ 1192.83f, 956.25f, -93.6974f, nullptr },
|
||||
{ 1162.93f, 908.92f, -108.6703f, nullptr },
|
||||
{ 1144.94f, 860.09f, -111.2100f, nullptr },
|
||||
};
|
||||
|
||||
// Farm to Stables
|
||||
BattleBotPath vPath_AB_Farm_to_Stable =
|
||||
{
|
||||
{ 749.88f, 878.23f, -55.1523f, nullptr },
|
||||
{ 819.77f, 931.13f, -57.5882f, nullptr },
|
||||
{ 842.34f, 984.76f, -59.0333f, nullptr },
|
||||
{ 863.03f, 1051.47f, -58.0495f, nullptr },
|
||||
{ 899.28f, 1098.27f, -57.4149f, nullptr },
|
||||
{ 949.22f, 1153.27f, -54.4464f, nullptr },
|
||||
{ 999.07f, 1189.47f, -49.9125f, nullptr },
|
||||
{ 1063.11f, 1211.55f, -53.4164f, nullptr },
|
||||
{ 1098.45f, 1225.47f, -53.1301f, nullptr },
|
||||
{ 1146.02f, 1226.34f, -53.8979f, nullptr },
|
||||
{ 1167.10f, 1204.31f, -56.55f, nullptr },
|
||||
};
|
||||
|
||||
// Alliance Base to Gold Mine
|
||||
BattleBotPath vPath_AB_AllianceBase_to_GoldMine =
|
||||
{
|
||||
@@ -2070,6 +2112,9 @@ std::vector<BattleBotPath*> const vPaths_AB =
|
||||
&vPath_AB_Stables_to_LumberMill,
|
||||
&vPath_AB_Farm_to_GoldMine,
|
||||
&vPath_AB_Farm_to_LumberMill,
|
||||
&vPath_AB_Blacksmith_to_LumberMill,
|
||||
&vPath_AB_Blacksmith_to_GoldMine,
|
||||
&vPath_AB_Farm_to_Stable,
|
||||
};
|
||||
|
||||
std::vector<BattleBotPath*> const vPaths_AV =
|
||||
@@ -2607,6 +2652,13 @@ bool BGTactics::Execute(Event event)
|
||||
if (bg->GetStatus() == STATUS_WAIT_LEAVE)
|
||||
return false;
|
||||
|
||||
if (bg->isArena())
|
||||
{
|
||||
// can't use this in arena - no vPaths/vFlagIds (will crash server)
|
||||
botAI->ResetStrategies();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bg->GetStatus() == STATUS_IN_PROGRESS)
|
||||
botAI->ChangeStrategy("-buff", BOT_STATE_NON_COMBAT);
|
||||
|
||||
@@ -2649,7 +2701,9 @@ bool BGTactics::Execute(Event event)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
// can't use this in this BG - no vPaths/vFlagIds (will crash server)
|
||||
botAI->ResetStrategies();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getName() == "move to start")
|
||||
@@ -3324,7 +3378,7 @@ bool BGTactics::selectObjective(bool reset)
|
||||
((!defender || !objectives.size()) && arathiBasinBG->GetCapturePointInfo(objective)._state == BG_AB_NODE_STATE_ALLY_OCCUPIED) ||
|
||||
((defender || !objectives.size()) && arathiBasinBG->GetCapturePointInfo(objective)._state == BG_AB_NODE_STATE_ALLY_CONTESTED))
|
||||
{
|
||||
if (GameObject* pGO = bg->GetBGObject(objective))
|
||||
if (GameObject* pGO = bg->GetBGObject(objective * BG_AB_OBJECTS_PER_NODE))
|
||||
{
|
||||
float const distance = sqrt(bot->GetDistance(pGO));
|
||||
if (attackObjectiveDistance > distance)
|
||||
@@ -3366,11 +3420,11 @@ bool BGTactics::selectObjective(bool reset)
|
||||
|
||||
for (const auto& objective : AB_AttackObjectives)
|
||||
{
|
||||
if (arathiBasinBG->GetCapturePointInfo(objective)._ownerTeamId == BG_AB_NODE_STATE_NEUTRAL ||
|
||||
((!defender || !objectives.size()) && arathiBasinBG->GetCapturePointInfo(objective)._ownerTeamId == BG_AB_NODE_STATE_HORDE_OCCUPIED) ||
|
||||
((defender || !objectives.size()) && arathiBasinBG->GetCapturePointInfo(objective)._ownerTeamId == BG_AB_NODE_STATE_HORDE_CONTESTED))
|
||||
if (arathiBasinBG->GetCapturePointInfo(objective)._state == BG_AB_NODE_STATE_NEUTRAL ||
|
||||
((!defender || !objectives.size()) && arathiBasinBG->GetCapturePointInfo(objective)._state == BG_AB_NODE_STATE_HORDE_OCCUPIED) ||
|
||||
((defender || !objectives.size()) && arathiBasinBG->GetCapturePointInfo(objective)._state == BG_AB_NODE_STATE_HORDE_CONTESTED))
|
||||
{
|
||||
if (GameObject* pGO = bg->GetBGObject(objective))
|
||||
if (GameObject* pGO = bg->GetBGObject(objective * BG_AB_OBJECTS_PER_NODE))
|
||||
{
|
||||
float const distance = sqrt(bot->GetDistance(pGO));
|
||||
if (attackObjectiveDistance > distance)
|
||||
@@ -4866,11 +4920,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);
|
||||
@@ -4903,6 +4958,18 @@ bool ArenaTactics::moveToCenter(Battleground* bg)
|
||||
case BATTLEGROUND_NA:
|
||||
MoveTo(bg->GetMapId(), 4055.0f + frand(-5, +5), 2921.0f + frand(-5, +5), 15.1f, false, true);
|
||||
break;
|
||||
case BATTLEGROUND_DS:
|
||||
if (!MoveTo(bg->GetMapId(), 1291.58f + frand(-5, +5), 790.87f + frand(-5, +5), 7.8f, false, true)) {
|
||||
// they like to hang around at the tip of the pipes doing nothing, so we just teleport them down
|
||||
if (bot->GetDistance(1333.07f, 817.18f, 13.35f) < 2)
|
||||
bot->TeleportTo(bg->GetMapId(), 1330.96f, 816.75f, 3.2f, bot->GetOrientation());
|
||||
if (bot->GetDistance(1250.13f, 764.79f, 13.34f) < 2)
|
||||
bot->TeleportTo(bg->GetMapId(), 1252.19f, 765.41f, 3.2f, bot->GetOrientation());
|
||||
}
|
||||
break;
|
||||
case BATTLEGROUND_RV:
|
||||
MoveTo(bg->GetMapId(), 764.65f + frand(-2, +2), -283.85f + frand(-2, +2), 28.28f, false, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user