@@ -45,17 +45,6 @@ enum MiscCrossFactionPVE
4545 AB_MAP_ID = 529
4646};
4747
48- void TemporaryFactionChange (Player* player)
49- {
50- if (Group* group = player->GetGroup ())
51- {
52- if (Player* leader = ObjectAccessor::FindPlayer (group->GetLeaderGUID ()))
53- {
54- player->SetFaction (leader->GetFaction ());
55- }
56- }
57- }
58-
5948class CfPlayerScript : public PlayerScript
6049{
6150public:
@@ -64,40 +53,51 @@ class CfPlayerScript : public PlayerScript
6453 // Called when a player enters the world (logs in or teleports)
6554 void OnLogin (Player* player, bool firstLogin) override
6655 {
67- switch (player->GetMapId ())
68- {
69- case ICC_MAP_ID:
70- case TOCHAMPION_MAP_ID:
71- case TOCRUSADER_MAP_ID:
72- case POS_MAP_ID:
73- case HOR_MAP_ID:
74- case FOS_MAP_ID:
75- case HOS_MAP_ID:
76- case TN_MAP_ID:
77- case WSG_MAP_ID:
78- case AB_MAP_ID:
79- TemporaryFactionChange (player);
80- break ;
81- }
56+ HandleFactionChange (player, player->GetMapId ());
8257 }
8358
8459 // Called when a player changes zones
8560 void OnUpdateZone (Player* player, uint32 newZone, uint32 /* newArea*/ ) override
8661 {
87- switch (newZone)
62+ HandleFactionChange (player, newZone);
63+ }
64+
65+ private:
66+ // Store the original faction in a map
67+ std::unordered_map<uint64, uint32> originalFactionMap;
68+
69+ void HandleFactionChange (Player* player, uint32 zoneOrMapId)
70+ {
71+ static const std::set<uint32> zoneSet = {
72+ ICC_MAP_ID, TOCHAMPION_MAP_ID, TOCRUSADER_MAP_ID, POS_MAP_ID,
73+ HOR_MAP_ID, FOS_MAP_ID, HOS_MAP_ID, TN_MAP_ID, WSG_MAP_ID, AB_MAP_ID
74+ };
75+
76+ if (zoneSet.count (zoneOrMapId))
77+ {
78+ // Change faction to match the group leader
79+ if (Group* group = player->GetGroup ())
80+ {
81+ if (Player* leader = ObjectAccessor::FindPlayer (group->GetLeaderGUID ()))
82+ {
83+ if (originalFactionMap.find (player->GetGUID ()) == originalFactionMap.end ())
84+ {
85+ // Store the original faction
86+ originalFactionMap[player->GetGUID ()] = player->GetFaction ();
87+ }
88+ player->SetFaction (leader->GetFaction ());
89+ }
90+ }
91+ }
92+ else
8893 {
89- case ZONE_ICECROWN_CITADEL:
90- case ZONE_TRIAL_OF_THE_CHAMPION:
91- case ZONE_TRIAL_OF_THE_CRUSADER:
92- case ZONE_PIT_OF_SARON:
93- case ZONE_HALLS_OF_REFLECTION:
94- case ZONE_FORGE_OF_SOULS:
95- case ZONE_HALLS_OF_STONE:
96- case ZONE_THE_NEXUS:
97- case ZONE_WARSONG_GULCH:
98- case ZONE_ARATHI_BASIN:
99- TemporaryFactionChange (player);
100- break ;
94+ // Restore player's original faction
95+ auto it = originalFactionMap.find (player->GetGUID ());
96+ if (it != originalFactionMap.end ())
97+ {
98+ player->SetFaction (it->second );
99+ originalFactionMap.erase (it); // Clean up the map after restoring
100+ }
101101 }
102102 }
103103};
0 commit comments