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;
}

View File

@@ -141,7 +141,7 @@ typedef std::map<ObjectGuid::LowType /*spawnId*/, uint8 /*state*/> ObjectStateMa
class InstanceScript : public ZoneScript
{
public:
explicit InstanceScript(Map* map) : instance(map), completedEncounters(0) {}
explicit InstanceScript(Map* map) : instance(map), completedEncounters(0), _teamIdInInstance(TEAM_NEUTRAL) {}
~InstanceScript() override {}
@@ -182,10 +182,10 @@ public:
GameObject* GetGameObject(uint32 type);
//Called when a player successfully enters the instance.
virtual void OnPlayerEnter(Player* /*player*/) {}
virtual void OnPlayerEnter(Player* /*player*/);
//Called when a player successfully leaves the instance.
virtual void OnPlayerLeave(Player* /*player*/) {}
virtual void OnPlayerLeave(Player* /*player*/);
virtual void OnPlayerAreaUpdate(Player* /*player*/, uint32 /*oldArea*/, uint32 /*newArea*/) {}
@@ -322,6 +322,9 @@ protected:
void WritePersistentData(std::ostringstream& data);
virtual void WriteSaveDataMore(std::ostringstream& /*data*/) { }
TeamId GetTeamIdInInstance() const { return _teamIdInInstance; }
bool IsTwoFactionInstance() const;
private:
static void LoadObjectData(ObjectData const* creatureData, ObjectInfoMap& objectInfo);
@@ -336,6 +339,7 @@ private:
ObjectGuidMap _objectGuids;
ObjectStateMap _objectStateMap;
uint32 completedEncounters; // completed encounter mask, bit indexes are DungeonEncounter.dbc boss numbers, used for packets
TeamId _teamIdInInstance;
std::unordered_set<uint32> _activatedAreaTriggers;
};