diff --git a/conf/CFBG.conf.dist b/conf/CFBG.conf.dist index f7bb597..7b74cb0 100644 --- a/conf/CFBG.conf.dist +++ b/conf/CFBG.conf.dist @@ -32,6 +32,14 @@ # Default: 1 - (Enabled) # 0 - (Disabled) # +# CFBG.Battlefield.ReapplyOnResurrect.Enable +# Description: Re-apply a cross-faction player's assigned race/faction/morph +# when they resurrect inside Wintergrasp, so the ghost->alive +# transition does not revert them to their native faction. +# Requires CFBG.Battlefield.Enable = 1. +# Default: 1 - (Enabled) +# 0 - (Disabled) +# # CFBG.Include.Avg.Ilvl.Enable # Description: Enable check average item level for bg # Default: 0 @@ -90,6 +98,7 @@ CFBG.Enable = 1 CFBG.Battlefield.Enable = 1 CFBG.Battlefield.TeamLock.Enable = 1 +CFBG.Battlefield.ReapplyOnResurrect.Enable = 1 CFBG.BalancedTeams = 1 CFBG.BalancedTeams.Class.LowLevel = 0 CFBG.BalancedTeams.Class.MinLevel = 10 diff --git a/src/CFBG.cpp b/src/CFBG.cpp index 760c1e5..75d165b 100644 --- a/src/CFBG.cpp +++ b/src/CFBG.cpp @@ -152,6 +152,7 @@ void CFBG::LoadConfig() _IsEnableWGSystem = sConfigMgr->GetOption("CFBG.Battlefield.Enable", true); _IsEnableWGTeamLock = sConfigMgr->GetOption("CFBG.Battlefield.TeamLock.Enable", true); + _IsEnableWGReapplyOnResurrect = sConfigMgr->GetOption("CFBG.Battlefield.ReapplyOnResurrect.Enable", true); _IsEnableAvgIlvl = sConfigMgr->GetOption("CFBG.Include.Avg.Ilvl.Enable", false); _IsEnableBalancedTeams = sConfigMgr->GetOption("CFBG.BalancedTeams", false); _IsEnableEvenTeams = sConfigMgr->GetOption("CFBG.EvenTeams.Enabled", false); @@ -594,6 +595,20 @@ void CFBG::ClearFakePlayer(Player* player) _fakePlayerStore.erase(player); } +void CFBG::ReapplyFakePlayer(Player* player) +{ + FakePlayer const* info = GetFakePlayer(player); + if (!info) + return; + + // Re-push the stored fake values after a resurrect so the assigned faction + // and morph survive the ghost->alive transition. + player->setRace(info->FakeRace); + SetFactionForRace(player, info->FakeRace, info->FakeTeamID); + player->SetDisplayId(info->FakeMorph); + player->SetNativeDisplayId(info->FakeMorph); +} + bool CFBG::IsPlayerFake(Player* player) { return _fakePlayerStore.contains(player); diff --git a/src/CFBG.h b/src/CFBG.h index f429059..2610fc5 100644 --- a/src/CFBG.h +++ b/src/CFBG.h @@ -137,6 +137,7 @@ class CFBG inline bool IsEnableSystem() const { return _IsEnableSystem; } inline bool IsEnableWGSystem() const { return _IsEnableWGSystem; } inline bool IsEnableWGTeamLock() const { return _IsEnableWGTeamLock; } + inline bool IsEnableWGReapplyOnResurrect() const { return _IsEnableWGReapplyOnResurrect; } inline bool IsEnableAvgIlvl() const { return _IsEnableAvgIlvl; } inline bool IsEnableBalancedTeams() const { return _IsEnableBalancedTeams; } inline bool IsEnableBalanceClassLowLevel() const { return _IsEnableBalanceClassLowLevel; } @@ -174,6 +175,7 @@ class CFBG void SetFakeRaceAndMorphForBF(Player* player, TeamId assignedTeam); void SetFactionForRace(Player* player, uint8 Race, TeamId teamId); void ClearFakePlayer(Player* player); + void ReapplyFakePlayer(Player* player); void DoForgetPlayersInList(Player* player); void FitPlayerInTeam(Player* player, bool action, Battleground* bg); void DoForgetPlayersInBG(Player* player, Battleground* bg); @@ -223,6 +225,7 @@ class CFBG bool _IsEnableSystem; bool _IsEnableWGSystem; bool _IsEnableWGTeamLock; + bool _IsEnableWGReapplyOnResurrect; bool _IsEnableAvgIlvl; bool _IsEnableBalancedTeams; bool _IsEnableBalanceClassLowLevel; diff --git a/src/CFBG_SC.cpp b/src/CFBG_SC.cpp index 808aa8a..6a0c0bd 100644 --- a/src/CFBG_SC.cpp +++ b/src/CFBG_SC.cpp @@ -108,7 +108,8 @@ class CFBG_Player : public PlayerScript PLAYERHOOK_CAN_JOIN_IN_BATTLEGROUND_QUEUE, PLAYERHOOK_ON_BEFORE_UPDATE, PLAYERHOOK_ON_BEFORE_SEND_CHAT_MESSAGE, - PLAYERHOOK_ON_REPUTATION_CHANGE + PLAYERHOOK_ON_REPUTATION_CHANGE, + PLAYERHOOK_ON_PLAYER_RESURRECT }) { } void OnPlayerLogin(Player* player) override @@ -215,6 +216,23 @@ class CFBG_Player : public PlayerScript lang = LANG_UNIVERSAL; } + void OnPlayerResurrect(Player* player, float /*restorePercent*/, bool& /*applySickness*/) override + { + if (!sCFBG->IsEnableSystem() || !sCFBG->IsEnableWGSystem() || !sCFBG->IsEnableWGReapplyOnResurrect()) + return; + + if (!sCFBG->IsPlayerFake(player)) + return; + + // Only re-apply for WG fakes. Battleground fakes are owned by the BG + // hooks and must not be touched here. + Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId()); + if (!bf || bf->GetTypeId() != BATTLEFIELD_WG) + return; + + sCFBG->ReapplyFakePlayer(player); + } + bool OnPlayerReputationChange(Player* player, uint32 factionID, int32& standing, bool /*incremental*/) override { uint32 repGain = player->GetReputation(factionID);