From 038db403aa68f5279f4b77025ebfa25116d3e2be Mon Sep 17 00:00:00 2001 From: trickerer Date: Mon, 16 Dec 2024 21:05:40 +0700 Subject: [PATCH] NPCBots: Fix default faction for extra classes --- src/server/game/AI/NpcBots/bot_ai.cpp | 2 +- src/server/game/AI/NpcBots/botcommands.cpp | 2 +- src/server/game/AI/NpcBots/botdatamgr.cpp | 13 ++++++++----- src/server/game/AI/NpcBots/botdatamgr.h | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/server/game/AI/NpcBots/bot_ai.cpp b/src/server/game/AI/NpcBots/bot_ai.cpp index cba9d27a6872a..8ac4cdc602e20 100644 --- a/src/server/game/AI/NpcBots/bot_ai.cpp +++ b/src/server/game/AI/NpcBots/bot_ai.cpp @@ -3817,7 +3817,7 @@ bool bot_ai::CanBotAttack(Unit const* target, int8 byspell, bool secondary) cons //do not attack friendly targets in FFAPvP mode if (me->IsFFAPvP() && me->GetFaction() == FACTION_TEMPLATE_NEUTRAL_HOSTILE) { - uint32 base_faction = BotDataMgr::GetDefaultFactionForBotRace(me->GetRace()); + uint32 base_faction = BotDataMgr::GetDefaultFactionForBotRaceClass(GetBotClass(), me->GetRace()); if (me->GetFaction() != base_faction && Unit::GetFactionReactionTo(sFactionTemplateStore.LookupEntry(base_faction), target) >= REP_FRIENDLY) return false; } diff --git a/src/server/game/AI/NpcBots/botcommands.cpp b/src/server/game/AI/NpcBots/botcommands.cpp index 802a9a32906d4..9c8740df8ca86 100644 --- a/src/server/game/AI/NpcBots/botcommands.cpp +++ b/src/server/game/AI/NpcBots/botcommands.cpp @@ -3342,7 +3342,7 @@ class script_bot_commands : public CommandScript if (teamid) { - uint32 faction = BotDataMgr::GetDefaultFactionForBotRace(race); + uint32 faction = BotDataMgr::GetDefaultFactionForBotRaceClass(_botExtras->bclass, race); TeamId team = BotDataMgr::GetTeamIdForFaction(faction); if (*teamid != uint8(team)) diff --git a/src/server/game/AI/NpcBots/botdatamgr.cpp b/src/server/game/AI/NpcBots/botdatamgr.cpp index 4a5272a4e1f6b..d64ebd7b70a2a 100644 --- a/src/server/game/AI/NpcBots/botdatamgr.cpp +++ b/src/server/game/AI/NpcBots/botdatamgr.cpp @@ -298,7 +298,7 @@ struct WanderingBotsGenerator const uint32 orig_entry = spareBotPair.second; CreatureTemplate const* orig_template = ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(orig_entry)); NpcBotExtras const* orig_extras = ASSERT_NOTNULL(BotDataMgr::SelectNpcBotExtras(orig_entry)); - uint32 bot_faction = BotDataMgr::GetDefaultFactionForBotRace(orig_extras->race); + uint32 bot_faction = BotDataMgr::GetDefaultFactionForBotRaceClass(bot_class, orig_extras->race); NodeVec const* bot_spawn_nodes; TeamId bot_team = BotDataMgr::GetTeamIdForFaction(bot_faction); @@ -429,7 +429,7 @@ struct WanderingBotsGenerator for (uint32 entry : kv.second) { NpcBotExtras const* extras = ASSERT_NOTNULL(BotDataMgr::SelectNpcBotExtras(entry)); - uint32 bot_faction = BotDataMgr::GetDefaultFactionForBotRace(extras->race); + uint32 bot_faction = BotDataMgr::GetDefaultFactionForBotRaceClass(extras->bclass, extras->race); TeamId bot_team = BotDataMgr::GetTeamIdForFaction(bot_faction); if (teamId == bot_team) ++count; @@ -542,7 +542,7 @@ struct WanderingBotsGenerator for (uint32 spareBotId : kv.second) { NpcBotExtras const* orig_extras = ASSERT_NOTNULL(BotDataMgr::SelectNpcBotExtras(spareBotId)); - uint32 bot_faction = BotDataMgr::GetDefaultFactionForBotRace(orig_extras->race); + uint32 bot_faction = BotDataMgr::GetDefaultFactionForBotRaceClass(orig_extras->bclass, orig_extras->race); uint32 botTeam = BotDataMgr::GetTeamForFaction(bot_faction); if (int32(botTeam) != team) @@ -3191,7 +3191,7 @@ int32 BotDataMgr::GetBotBaseReputation(Creature const* bot, FactionEntry const* if (bot->IsNPCBotPet()) bot = bot->GetBotPetAI()->GetPetsOwner(); - uint32 raceMask = GetDefaultFactionForBotRace(bot->GetRace()) == FACTION_TEMPLATE_NEUTRAL_HOSTILE ? 0 : bot->GetRaceMask(); + uint32 raceMask = GetDefaultFactionForBotRaceClass(bot->GetBotClass(), bot->GetRace()) == FACTION_TEMPLATE_NEUTRAL_HOSTILE ? 0 : bot->GetRaceMask(); uint32 classMask = bot->GetClassMask(); int32 minRep = 42999; @@ -3209,8 +3209,11 @@ int32 BotDataMgr::GetBotBaseReputation(Creature const* bot, FactionEntry const* return std::min(minRep, 0); } -uint32 BotDataMgr::GetDefaultFactionForBotRace(uint8 bot_race) +uint32 BotDataMgr::GetDefaultFactionForBotRaceClass(uint8 bot_class, uint8 bot_race) { + if (bot_class >= BOT_CLASS_EX_START) + return uint32(FACTION_TEMPLATE_NEUTRAL_HOSTILE); + ChrRacesEntry const* rentry = sChrRacesStore.LookupEntry(bot_race); return rentry ? rentry->FactionID : uint32(FACTION_TEMPLATE_NEUTRAL_HOSTILE); } diff --git a/src/server/game/AI/NpcBots/botdatamgr.h b/src/server/game/AI/NpcBots/botdatamgr.h index eb9ab68cf0b35..69c34e71d08e9 100644 --- a/src/server/game/AI/NpcBots/botdatamgr.h +++ b/src/server/game/AI/NpcBots/botdatamgr.h @@ -260,7 +260,7 @@ class BotDataMgr static uint8 GetMaxLevelForMapId(uint32 mapId); static uint8 GetMinLevelForBotClass(uint8 m_class); static int32 GetBotBaseReputation(Creature const* bot, FactionEntry const* factionEntry); - static uint32 GetDefaultFactionForBotRace(uint8 bot_race); + static uint32 GetDefaultFactionForBotRaceClass(uint8 bot_class, uint8 bot_race); static TeamId GetTeamIdForFaction(uint32 factionTemplateId); static uint32 GetTeamForFaction(uint32 factionTemplateId);