Fixed bot level reset/init to work inline with the PlayerBotFactory randomize function.

This commit is contained in:
Dustin Hendrickson
2025-02-19 14:42:51 -08:00
parent f483a838ff
commit 36cd9dc23e

View File

@@ -16,9 +16,7 @@
void RemoveAllEquippedItems(Player* bot);
void RemoveAllTradeSkills(Player* bot);
void RemoveAllLearnedSpells(Player* bot);
void RemoveAllQuests(Player* bot);
void RemoveAllActiveAuras(Player* bot);
static bool IsAlliancePlayerBot(Player* bot);
static bool IsHordePlayerBot(Player* bot);
@@ -113,23 +111,14 @@ static void AdjustBotToRange(Player* bot, int targetRangeIndex, const LevelRange
if (!bot || targetRangeIndex < 0 || targetRangeIndex >= NUM_RANGES)
return;
PlayerbotFactory factory(bot, bot->GetLevel());
if (bot->IsMounted())
{
bot->Dismount();
bot->resetTalents(true);
RemoveAllEquippedItems(bot);
RemoveAllTradeSkills(bot);
RemoveAllLearnedSpells(bot);
RemoveAllQuests(bot);
RemoveAllActiveAuras(bot);
if (bot->GetPet())
bot->RemovePet(bot->GetPet(), PET_SAVE_NOT_IN_SLOT, false);
}
uint8 botOriginalLevel = bot->GetLevel();
uint8 newLevel = 0;
// For Death Knight bots, enforce a minimum level of 55.
if (bot->getClass() == CLASS_DEATH_KNIGHT)
{
@@ -155,9 +144,9 @@ static void AdjustBotToRange(Player* bot, int targetRangeIndex, const LevelRange
newLevel = GetRandomLevelInRange(factionRanges[targetRangeIndex]);
}
bot->SetLevel(newLevel);
bot->SetUInt32Value(PLAYER_XP, 0);
ChatHandler(bot->GetSession()).SendSysMessage("[mod-bot-level-brackets] Your level has been reset.");
PlayerbotFactory newFactory(bot, newLevel);
newFactory.Randomize(false);
if (g_BotDistDebugMode)
{
@@ -170,42 +159,13 @@ static void AdjustBotToRange(Player* bot, int targetRangeIndex, const LevelRange
factionRanges[targetRangeIndex].lower, factionRanges[targetRangeIndex].upper);
}
bot->InitStatsForLevel();
ChatHandler(bot->GetSession()).SendSysMessage("[mod-bot-level-brackets] Your level has been reset.");
PlayerbotAI* botAI = sPlayerbotsMgr->GetPlayerbotAI(bot);
if (botAI)
{
AutoMaintenanceOnLevelupAction maintenanceAction(botAI);
maintenanceAction.Execute(Event());
if (g_BotDistDebugMode)
LOG_INFO("server.loading",
"[BotLevelBrackets] AdjustBotToRange: AutoMaintenanceOnLevelupAction executed for bot '{}'.", bot->GetName());
}
else
{
LOG_ERROR("server.loading",
"[BotLevelBrackets] AdjustBotToRange: Failed to retrieve PlayerbotAI for bot '{}'.", bot->GetName());
}
}
// -----------------------------------------------------------------------------
// BOT INTERFACE HELPERS
// -----------------------------------------------------------------------------
void RemoveAllLearnedSpells(Player* bot)
{
bot->RemoveAllSpellCooldown();
std::vector<uint32> spellsToRemove;
for (const auto& spellPair : bot->GetSpellMap())
{
const uint32 spellId = spellPair.first;
const PlayerSpellState state = spellPair.second->State;
if (state != PLAYERSPELL_REMOVED)
spellsToRemove.push_back(spellId);
}
for (uint32 spellId : spellsToRemove)
bot->removeSpell(spellId, SPEC_MASK_ALL, false);
}
void RemoveAllQuests(Player* bot)
{
@@ -218,11 +178,6 @@ void RemoveAllQuests(Player* bot)
CharacterDatabase.Execute("DELETE FROM character_queststatus WHERE guid = {}", bot->GetGUID().GetCounter());
}
void RemoveAllActiveAuras(Player* bot)
{
bot->RemoveAllAuras();
}
void RemoveAllEquippedItems(Player* bot)
{
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)