try fix bg playerbots

This commit is contained in:
luis
2026-03-12 20:12:13 -03:00
parent 5badcaaf3c
commit 5d670be3c8
3 changed files with 85 additions and 10 deletions
+61 -10
View File
@@ -17,6 +17,7 @@
#include "../AI/Coordination/Battleground/BattlegroundCoordinatorManager.h"
#include "../AI/Coordination/Battleground/BattlegroundCoordinator.h"
#include "../AI/Coordination/Battleground/Scripts/IBGScript.h"
#include "../Movement/BotMovementUtil.h" // for fallback roaming
namespace Playerbot
{
@@ -98,6 +99,12 @@ void BattlegroundAI::Update(::Player* player, uint32 /*diff*/)
BGRole assignedRole = coordinator->GetBotRole(player->GetGUID());
if (assignedRole == BGRole::UNASSIGNED)
coordinator->AddBot(player);
// If coordinator exists but script hasn't been loaded yet (race during startup)
// queue another creation/update request. This _should_ be rare, but ensures a
// bot won't be left untracked if the initial coordinator was empty.
if (!coordinator->GetScript())
sBGCoordinatorMgr->UpdateBot(player, 0);
}
else
{
@@ -158,6 +165,10 @@ void BattlegroundAI::Update(::Player* player, uint32 /*diff*/)
break;
default:
// Unknown battleground type - fall back to minimal behavior so bots at least move
TC_LOG_WARN("playerbots.bg", "BattlegroundAI: Unknown BGType %u for bot %s, using fallback",
static_cast<uint32>(bgType), player->GetName());
FallbackBehavior(player);
break;
}
}
@@ -181,8 +192,9 @@ void BattlegroundAI::ExecuteWSGStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[WSG/TP] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[WSG/TP] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteABStrategy(::Player* player)
@@ -198,8 +210,9 @@ void BattlegroundAI::ExecuteABStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[AB/BFG] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[AB/BFG] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteAVStrategy(::Player* player)
@@ -215,8 +228,9 @@ void BattlegroundAI::ExecuteAVStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[AV] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[AV] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteEOTSStrategy(::Player* player)
@@ -232,8 +246,9 @@ void BattlegroundAI::ExecuteEOTSStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[EOTS] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[EOTS] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteSiegeStrategy(::Player* player)
@@ -249,8 +264,9 @@ void BattlegroundAI::ExecuteSiegeStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[Siege] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[Siege] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteKotmoguStrategy(::Player* player)
@@ -266,8 +282,9 @@ void BattlegroundAI::ExecuteKotmoguStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[TOK] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[TOK] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteSilvershardStrategy(::Player* player)
@@ -283,8 +300,9 @@ void BattlegroundAI::ExecuteSilvershardStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[SSM] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[SSM] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteDeepwindStrategy(::Player* player)
@@ -300,8 +318,9 @@ void BattlegroundAI::ExecuteDeepwindStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[DWG] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[DWG] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteSeethingShoreStrategy(::Player* player)
@@ -317,8 +336,9 @@ void BattlegroundAI::ExecuteSeethingShoreStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[SS] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[SS] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
void BattlegroundAI::ExecuteAshranStrategy(::Player* player)
@@ -334,8 +354,39 @@ void BattlegroundAI::ExecuteAshranStrategy(::Player* player)
return;
}
TC_LOG_DEBUG("playerbots.bg", "[Ashran] {} no coordinator/script available, idle",
TC_LOG_DEBUG("playerbots.bg", "[Ashran] {} no coordinator/script available or script failed, falling back",
player->GetName());
FallbackBehavior(player);
}
// ============================================================================
// FALLBACK UTILITIES
// ============================================================================
// Simple behavior used when the coordinator or script isn't available. This
// ensures bots don't sit idle at spawn when the BG subsystem hasn't initialized
// yet (common during early development or in bot-only matches). The fallback
// will attack the nearest enemy player if one is nearby, otherwise it will
// wander randomly so the bot at least moves.
void BattlegroundAI::FallbackBehavior(::Player* player)
{
if (!player || !player->IsInWorld() || !player->IsAlive())
return;
// If already engaged, let the combat system handle it
if (player->getVictim())
return;
// Try to find a nearby enemy player
if (Player* enemy = player->SelectNearestPlayer(30.0f))
{
player->AI()->AttackStart(enemy);
return;
}
// No enemies nearby - just wander a bit to avoid looking frozen
BotMovementUtil::MoveRandomAround(player, 10.0f);
}
// ============================================================================
@@ -102,6 +102,10 @@ public:
void Initialize();
void Update(::Player* player, uint32 diff);
// Fallback routine used when no coordinator/script is ready. Ensures bots
// still wander or engage nearby enemies instead of sitting frozen.
static void FallbackBehavior(::Player* player);
// ============================================================================
// PROFILES
// ============================================================================
@@ -33,6 +33,7 @@ namespace Creatures
{
static constexpr uint32 VereesaWindrunnerOztanIsle = 231042;
static constexpr uint32 AratorOztanIsle = 231039;
static constexpr uint32 SummonedSilverHandAvenger = 233329;
}
namespace Mounts
@@ -77,6 +78,7 @@ namespace Conversations
{
static constexpr uint32 VereesaActorOztanIsle = 102984;
static constexpr uint32 AratorActorOztanIsle = 102985;
static constexpr uint32 SummonedSilverHandAvenger = 103060;
}
namespace Lines
@@ -257,6 +259,23 @@ public:
}, conversation->GetLastLineEndTime(privateOwnerLocale) + 2s);
}
};
// 28287 - Conversation: After Vereesas Ceremony
class conversation_after_vereesas_ceremony : public ConversationAI
{
public:
using ConversationAI::ConversationAI;
void OnCreate(Unit* creator) override
{
Creature* summonedAvenger = creator->FindNearestCreatureWithOptions(20.0f, { .CreatureId = Creatures::SummonedSilverHandAvenger, .IgnorePhases = true, .OwnerGuid = creator->GetGUID() });
if (!summonedAvenger)
return;
conversation->AddActor(Conversations::Actors::SummonedSilverHandAvenger, 1, summonedAvenger->GetGUID());
conversation->Start();
}
};
}
void AddSC_campaign_visions_of_a_shadowed_sun()
@@ -268,4 +287,5 @@ void AddSC_campaign_visions_of_a_shadowed_sun()
// Conversation
RegisterConversationAI(conversation_vereesas_tale);
RegisterConversationAI(conversation_after_vereesas_ceremony);
}