refactor(Core/Instances): Implement GetTeamIdInInstance() for two-fac… (#21168)

This commit is contained in:
Andrew
2025-01-17 23:51:25 -03:00
committed by GitHub
parent 30a9c87d7d
commit 4a3fab424c
10 changed files with 156 additions and 514 deletions

View File

@@ -55,6 +55,34 @@ void InstanceScript::SaveToDB()
CharacterDatabase.Execute(stmt);
}
void InstanceScript::OnPlayerEnter(Player* player)
{
if (!IsTwoFactionInstance())
return;
if (GetTeamIdInInstance() == TEAM_NEUTRAL)
{
if (Group* group = player->GetGroup())
{
if (Player* leader = ObjectAccessor::FindConnectedPlayer(group->GetLeaderGUID()))
_teamIdInInstance = leader->GetTeamId();
else
_teamIdInInstance = player->GetTeamId();
}
else
_teamIdInInstance = player->GetTeamId();
}
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFaction((_teamIdInInstance == TEAM_HORDE) ? 1610 /*FACTION_HORDE*/ : 1 /*FACTION_ALLIANCE*/);
}
void InstanceScript::OnPlayerLeave(Player* player)
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP) && IsTwoFactionInstance())
player->SetFactionForRace(player->getRace());
}
void InstanceScript::OnCreatureCreate(Creature* creature)
{
AddObject(creature);
@@ -848,3 +876,21 @@ bool InstanceHasScript(WorldObject const* obj, char const* scriptName)
return false;
}
bool InstanceScript::IsTwoFactionInstance() const
{
switch (instance->GetId())
{
case 540: // Shattered Halls
case 576: // Nexus
case 631: // Icecrown Citadel
case 632: // Forge of Souls
case 649: // Trial of the Champion
case 650: // Trial of the Crusader
case 658: // Pit of Saron
case 668: // Halls of Reflection
return true;
}
return false;
}