|
| 1 | +/* |
| 2 | + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify it |
| 5 | + * under the terms of the GNU General Public License as published by the |
| 6 | + * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | + * option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | + * more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License along |
| 15 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | + |
| 19 | +#include "ScriptMgr.h" |
| 20 | +#include "Player.h" |
| 21 | +#include "Group.h" |
| 22 | +#include "ObjectAccessor.h" |
| 23 | + |
| 24 | +enum MiscCrossFactionPVE |
| 25 | +{ |
| 26 | + ZONE_ICECROWN_CITADEL = 4812, |
| 27 | + ICC_MAP_ID = 631, |
| 28 | + ZONE_TRIAL_OF_THE_CHAMPION = 4723, |
| 29 | + TOCHAMPION_MAP_ID = 650, |
| 30 | + ZONE_TRIAL_OF_THE_CRUSADER = 4722, |
| 31 | + TOCRUSADER_MAP_ID = 649, |
| 32 | + ZONE_PIT_OF_SARON = 4813, |
| 33 | + POS_MAP_ID = 658, |
| 34 | + ZONE_HALLS_OF_REFLECTION = 4820, |
| 35 | + HOR_MAP_ID = 668, |
| 36 | + ZONE_FORGE_OF_SOULS = 4809, |
| 37 | + FOS_MAP_ID = 632, |
| 38 | + ZONE_HALLS_OF_STONE = 4264, |
| 39 | + HOS_MAP_ID = 599, |
| 40 | + ZONE_THE_NEXUS = 4265, |
| 41 | + TN_MAP_ID = 576, |
| 42 | + ZONE_WARSONG_GULCH = 3277, |
| 43 | + WSG_MAP_ID = 489, |
| 44 | + ZONE_ARATHI_BASIN = 3358, |
| 45 | + AB_MAP_ID = 529 |
| 46 | +}; |
| 47 | + |
| 48 | +class CfPlayerScript : public PlayerScript |
| 49 | +{ |
| 50 | +public: |
| 51 | + CfPlayerScript() : PlayerScript("CfPlayerScript") {} |
| 52 | + |
| 53 | + // Called when a player enters the world (logs in or teleports) |
| 54 | + void OnLogin(Player* player, bool /* firstLogin */) override |
| 55 | + { |
| 56 | + HandleFactionChange(player, player->GetMapId()); |
| 57 | + } |
| 58 | + |
| 59 | + // Called when a player changes zones |
| 60 | + void OnUpdateZone(Player* player, uint32 newZone, uint32 /*newArea*/) override |
| 61 | + { |
| 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 |
| 93 | + { |
| 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 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +}; |
| 104 | + |
| 105 | +void AddSC_cfpve() |
| 106 | +{ |
| 107 | + new CfPlayerScript(); |
| 108 | +} |
0 commit comments