Skip to content

Commit

Permalink
NPCBots: Fix default faction for extra classes
Browse files Browse the repository at this point in the history
  • Loading branch information
trickerer committed Dec 16, 2024
1 parent 219dc43 commit 038db40
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/NpcBots/botcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 8 additions & 5 deletions src/server/game/AI/NpcBots/botdatamgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -3209,8 +3209,11 @@ int32 BotDataMgr::GetBotBaseReputation(Creature const* bot, FactionEntry const*
return std::min<int32>(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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/NpcBots/botdatamgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 038db40

Please sign in to comment.