Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions src/CFBG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,18 @@ void CFBG::ValidatePlayerForBG(Battleground* bg, Player* player)

BalanceTeamsOnEntry(bg, player);

TeamId teamId{ player->GetBgTeamId() };
TeamId const assigned = player->GetBgTeamId();

if (player->GetTeamId(true) == teamId)
return;

BGData& bgdata = player->GetBGData();

if (bgdata.bgTeamId != teamId)
bgdata.bgTeamId = teamId;
// Keep bgTeamId authoritative (also covers the TEAM_NEUTRAL bootstrap where GetBgTeamId() falls back to m_team)
player->GetBGData().bgTeamId = assigned;

SetFakeRaceAndMorph(player);
EnforceBGTeamConsistency(player);

if (bg->GetMapId() == MapAlteracValley)
// AV forced reactions apply only to a cross-faction (faked) player;
// a native player already holds the correct Frostwolf/Stormpike standings.
if (!IsPlayingNative(player) && bg->GetMapId() == MapAlteracValley)
{
if (teamId == TEAM_HORDE)
if (assigned == TEAM_HORDE)
{
player->GetReputationMgr().ApplyForceReaction(FACTION_FROSTWOLF_CLAN, REP_FRIENDLY, true);
player->GetReputationMgr().ApplyForceReaction(FACTION_STORMPIKE_GUARD, REP_HOSTILE, true);
Expand All @@ -303,6 +300,38 @@ void CFBG::ValidatePlayerForBG(Battleground* bg, Player* player)
}
}

void CFBG::EnforceBGTeamConsistency(Player* player)
{
if (!player || !player->InBattleground())
return;

Battleground* bg = player->GetBattleground();
if (!bg || bg->isArena())
return;

TeamId const assigned = player->GetBgTeamId();

// Native: must not carry a fake.
if (player->GetTeamId(true) == assigned)
{
if (IsPlayerFake(player))
ClearFakePlayer(player);
return;
}

// Cross-faction: must be faked to `assigned`.
FakePlayer const* info = GetFakePlayer(player);
if (!info)
SetFakeRaceAndMorph(player); // not faked yet -> apply
else if (info->FakeTeamID != assigned)
{
ClearFakePlayer(player); // stale wrong-team fake -> redo
SetFakeRaceAndMorph(player);
}
else
ReapplyFakePlayer(player); // correct side -> re-push reset values
}

void CFBG::BalanceTeamsOnEntry(Battleground* bg, Player* player)
{
// The invite-time team was chosen using level/ilvl, but declined invites can
Expand Down
3 changes: 3 additions & 0 deletions src/CFBG.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class CFBG
bool IsPlayingNative(Player* player);

void ValidatePlayerForBG(Battleground* bg, Player* player);
// Forces race/faction/m_team/fake-store into agreement with the player's
// assigned BG team (GetBgTeamId()); idempotent and self-correcting.
void EnforceBGTeamConsistency(Player* player);
void SetFakeRaceAndMorph(Player* player);
void SetFakeRaceAndMorphForBF(Player* player, TeamId assignedTeam);
void SetFactionForRace(Player* player, uint8 Race, TeamId teamId);
Expand Down
13 changes: 12 additions & 1 deletion src/CFBG_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,18 @@ class CFBG_Player : public PlayerScript

void OnPlayerResurrect(Player* player, float /*restorePercent*/, bool& /*applySickness*/) override
{
if (!sCFBG->IsEnableSystem() || !sCFBG->IsEnableWGSystem() || !sCFBG->IsEnableWGReapplyOnResurrect())
if (!sCFBG->IsEnableSystem())
return;

// Battleground fakes are not re-pushed elsewhere on resurrect;
// re-assert assigned-team consistency after the ghost->alive transition.
if (player->InBattleground())
{
sCFBG->EnforceBGTeamConsistency(player);
return;
}

if (!sCFBG->IsEnableWGSystem() || !sCFBG->IsEnableWGReapplyOnResurrect())
return;

if (!sCFBG->IsPlayerFake(player))
Expand Down
Loading