Skip to content

Commit 9da4cf6

Browse files
fix: enforce assigned-team consistency in BGs (#168)
1 parent 702df19 commit 9da4cf6

3 files changed

Lines changed: 55 additions & 12 deletions

File tree

src/CFBG.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,18 @@ void CFBG::ValidatePlayerForBG(Battleground* bg, Player* player)
274274

275275
BalanceTeamsOnEntry(bg, player);
276276

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

279-
if (player->GetTeamId(true) == teamId)
280-
return;
281-
282-
BGData& bgdata = player->GetBGData();
283-
284-
if (bgdata.bgTeamId != teamId)
285-
bgdata.bgTeamId = teamId;
279+
// Keep bgTeamId authoritative (also covers the TEAM_NEUTRAL bootstrap where GetBgTeamId() falls back to m_team)
280+
player->GetBGData().bgTeamId = assigned;
286281

287-
SetFakeRaceAndMorph(player);
282+
EnforceBGTeamConsistency(player);
288283

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

303+
void CFBG::EnforceBGTeamConsistency(Player* player)
304+
{
305+
if (!player || !player->InBattleground())
306+
return;
307+
308+
Battleground* bg = player->GetBattleground();
309+
if (!bg || bg->isArena())
310+
return;
311+
312+
TeamId const assigned = player->GetBgTeamId();
313+
314+
// Native: must not carry a fake.
315+
if (player->GetTeamId(true) == assigned)
316+
{
317+
if (IsPlayerFake(player))
318+
ClearFakePlayer(player);
319+
return;
320+
}
321+
322+
// Cross-faction: must be faked to `assigned`.
323+
FakePlayer const* info = GetFakePlayer(player);
324+
if (!info)
325+
SetFakeRaceAndMorph(player); // not faked yet -> apply
326+
else if (info->FakeTeamID != assigned)
327+
{
328+
ClearFakePlayer(player); // stale wrong-team fake -> redo
329+
SetFakeRaceAndMorph(player);
330+
}
331+
else
332+
ReapplyFakePlayer(player); // correct side -> re-push reset values
333+
}
334+
306335
void CFBG::BalanceTeamsOnEntry(Battleground* bg, Player* player)
307336
{
308337
// The invite-time team was chosen using level/ilvl, but declined invites can

src/CFBG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ class CFBG
160160
bool IsPlayingNative(Player* player);
161161

162162
void ValidatePlayerForBG(Battleground* bg, Player* player);
163+
// Forces race/faction/m_team/fake-store into agreement with the player's
164+
// assigned BG team (GetBgTeamId()); idempotent and self-correcting.
165+
void EnforceBGTeamConsistency(Player* player);
163166
void SetFakeRaceAndMorph(Player* player);
164167
void SetFakeRaceAndMorphForBF(Player* player, TeamId assignedTeam);
165168
void SetFactionForRace(Player* player, uint8 Race, TeamId teamId);

src/CFBG_SC.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,18 @@ class CFBG_Player : public PlayerScript
218218

219219
void OnPlayerResurrect(Player* player, float /*restorePercent*/, bool& /*applySickness*/) override
220220
{
221-
if (!sCFBG->IsEnableSystem() || !sCFBG->IsEnableWGSystem() || !sCFBG->IsEnableWGReapplyOnResurrect())
221+
if (!sCFBG->IsEnableSystem())
222+
return;
223+
224+
// Battleground fakes are not re-pushed elsewhere on resurrect;
225+
// re-assert assigned-team consistency after the ghost->alive transition.
226+
if (player->InBattleground())
227+
{
228+
sCFBG->EnforceBGTeamConsistency(player);
229+
return;
230+
}
231+
232+
if (!sCFBG->IsEnableWGSystem() || !sCFBG->IsEnableWGReapplyOnResurrect())
222233
return;
223234

224235
if (!sCFBG->IsPlayerFake(player))

0 commit comments

Comments
 (0)