AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Arena Class Reference

#include "Arena.h"

Inheritance diagram for Arena:
Battleground BattlegroundBE BattlegroundDS BattlegroundNA BattlegroundRL BattlegroundRV

Protected Member Functions

 Arena ()
 
void AddPlayer (Player *player) override
 
void RemovePlayer (Player *) override
 
void FillInitialWorldStates (WorldPackets::WorldState::InitWorldStates &packet) override
 
void UpdateArenaWorldState ()
 
void HandleKillPlayer (Player *player, Player *killer) override
 
- Protected Member Functions inherited from Battleground
void EndNow ()
 
void PlayerAddedToBGCheckIfBGIsRunning (Player *player)
 
void _ProcessResurrect (uint32 diff)
 
void _ProcessProgress (uint32 diff)
 
void _ProcessLeave (uint32 diff)
 
void _ProcessJoin (uint32 diff)
 
void _CheckSafePositions (uint32 diff)
 

Private Member Functions

void RemovePlayerAtLeave (Player *player) override
 
void CheckWinConditions () override
 
void EndBattleground (TeamId winnerTeamId) override
 

Additional Inherited Members

- Public Types inherited from Battleground
typedef std::set< Player * > SpectatorList
 
typedef std::map< ObjectGuid, ObjectGuidToBeTeleportedMap
 
typedef std::map< ObjectGuid, Player * > BattlegroundPlayerMap
 
typedef std::unordered_map< ObjectGuid::LowType, BattlegroundScore * > BattlegroundScoreMap
 
typedef std::unordered_map< ObjectGuid, ArenaLogEntryDataArenaLogEntryDataMap
 
typedef GuidVector BGObjects
 
typedef GuidVector BGCreatures
 
- Public Member Functions inherited from Battleground
 Battleground ()
 
virtual ~Battleground ()
 
void Update (uint32 diff)
 
virtual bool SetupBattleground ()
 
virtual void Init ()
 
virtual void StartingEventCloseDoors ()
 
virtual void StartingEventOpenDoors ()
 
virtual void ResetBGSubclass ()
 
virtual void DestroyGate (Player *, GameObject *)
 
virtual bool AllNodesConrolledByTeam (TeamId) const
 
void StartTimedAchievement (AchievementCriteriaTimedTypes type, uint32 entry)
 
std::string GetName () const
 
BattlegroundTypeId GetBgTypeID (bool GetRandom=false) const
 
BattlegroundBracketId GetBracketId () const
 
uint32 GetInstanceID () const
 
BattlegroundStatus GetStatus () const
 
uint32 GetClientInstanceID () const
 
uint32 GetStartTime () const
 
uint32 GetEndTime () const
 
uint32 GetLastResurrectTime () const
 
uint32 GetMinLevel () const
 
uint32 GetMaxLevel () const
 
bool isTemplate () const
 
bool isMaxLevel () const
 
uint32 GetMaxPlayersPerTeam () const
 
uint32 GetMinPlayersPerTeam () const
 
int32 GetStartDelayTime () const
 
uint8 GetArenaType () const
 
PvPTeamId GetWinner () const
 
uint32 GetScriptId () const
 
uint32 GetBonusHonorFromKill (uint32 kills) const
 
void SpiritOfCompetitionEvent (PvPTeamId winnerTeamId) const
 
bool IsRandom ()
 
void SetName (std::string_view name)
 
void SetBgTypeID (BattlegroundTypeId TypeID)
 
void SetRandomTypeID (BattlegroundTypeId TypeID)
 
void SetBracket (PvPDifficultyEntry const *bracketEntry)
 
void SetInstanceID (uint32 InstanceID)
 
void SetStatus (BattlegroundStatus Status)
 
void SetClientInstanceID (uint32 InstanceID)
 
void SetStartTime (uint32 Time)
 
void SetEndTime (uint32 Time)
 
void SetLastResurrectTime (uint32 Time)
 
void SetLevelRange (uint32 min, uint32 max)
 
void SetRated (bool state)
 
void SetArenaType (uint8 type)
 
void SetArenaorBGType (bool _isArena)
 
void SetWinner (PvPTeamId winner)
 
void SetScriptId (uint32 scriptId)
 
void SetRandom (bool isRandom)
 
void ModifyStartDelayTime (int32 diff)
 
void SetStartDelayTime (int32 Time)
 
void SetMaxPlayersPerTeam (uint32 MaxPlayers)
 
void SetMinPlayersPerTeam (uint32 MinPlayers)
 
void AddToBGFreeSlotQueue ()
 
void RemoveFromBGFreeSlotQueue ()
 
void DecreaseInvitedCount (TeamId teamId)
 
void IncreaseInvitedCount (TeamId teamId)
 
uint32 GetInvitedCount (TeamId teamId) const
 
bool HasFreeSlots () const
 
uint32 GetFreeSlotsForTeam (TeamId teamId) const
 
uint32 GetMaxFreeSlots () const
 
void AddSpectator (Player *p)
 
void RemoveSpectator (Player *p)
 
bool HaveSpectators ()
 
const SpectatorListGetSpectators () const
 
void AddToBeTeleported (ObjectGuid spectator, ObjectGuid participant)
 
void RemoveToBeTeleported (ObjectGuid spectator)
 
void SpectatorsSendPacket (WorldPacket &data)
 
bool isArena () const
 
bool isBattleground () const
 
bool isRated () const
 
BattlegroundPlayerMap const & GetPlayers () const
 
uint32 GetPlayersSize () const
 
void ReadyMarkerClicked (Player *p)
 
BattlegroundScoreMap const * GetPlayerScores () const
 
std::size_t GetPlayerScoresSize () const
 
uint32 GetReviveQueueSize () const
 
void AddPlayerToResurrectQueue (ObjectGuid npc_guid, ObjectGuid player_guid)
 
void RemovePlayerFromResurrectQueue (Player *player)
 
void RelocateDeadPlayers (ObjectGuid queueIndex)
 Relocate all players in ReviveQueue to the closest graveyard.
 
void StartBattleground ()
 
GameObjectGetBGObject (uint32 type)
 
CreatureGetBGCreature (uint32 type)
 
void SetMapId (uint32 MapID)
 
uint32 GetMapId () const
 
void SetBgMap (BattlegroundMap *map)
 
BattlegroundMapGetBgMap () const
 
BattlegroundMapFindBgMap () const
 
void SetTeamStartPosition (TeamId teamId, Position const &pos)
 
Position const * GetTeamStartPosition (TeamId teamId) const
 
void SetStartMaxDist (float startMaxDist)
 
float GetStartMaxDist () const
 
void SendPacketToTeam (TeamId teamId, WorldPacket const *packet, Player *sender=nullptr, bool self=true)
 
void SendPacketToAll (WorldPacket const *packet)
 
void YellToAll (Creature *creature, const char *text, uint32 language)
 
void SendChatMessage (Creature *source, uint8 textId, WorldObject *target=nullptr)
 
void SendBroadcastText (uint32 id, ChatMsg msgType, WorldObject const *target=nullptr)
 
template<class Do >
void BroadcastWorker (Do &_do)
 
void PlaySoundToAll (uint32 soundId)
 
void CastSpellOnTeam (uint32 spellId, TeamId teamId)
 
void RemoveAuraOnTeam (uint32 spellId, TeamId teamId)
 
void RewardHonorToTeam (uint32 honor, TeamId teamId)
 
void RewardReputationToTeam (uint32 factionId, uint32 reputation, TeamId teamId)
 
uint32 GetRealRepFactionForPlayer (uint32 factionId, Player *player)
 
void UpdateWorldState (uint32 variable, uint32 value)
 
void EndBattleground (PvPTeamId winnerTeamId)
 
void BlockMovement (Player *player)
 
GroupGetBgRaid (TeamId teamId) const
 
void SetBgRaid (TeamId teamId, Group *bg_raid)
 
void BuildPvPLogDataPacket (WorldPacket &data)
 
virtual bool UpdatePlayerScore (Player *player, uint32 type, uint32 value, bool doAddHonor=true)
 
uint32 GetPlayersCountByTeam (TeamId teamId) const
 
uint32 GetAlivePlayersCountByTeam (TeamId teamId) const
 
void UpdatePlayersCountByTeam (TeamId teamId, bool remove)
 
void SetArenaTeamIdForTeam (TeamId teamId, uint32 ArenaTeamId)
 
uint32 GetArenaTeamIdForTeam (TeamId teamId) const
 
void SetArenaMatchmakerRating (TeamId teamId, uint32 MMR)
 
uint32 GetArenaMatchmakerRating (TeamId teamId) const
 
virtual void HandleAreaTrigger (Player *, uint32)
 
virtual void HandleKillUnit (Creature *, Player *)
 
virtual void EventPlayerDroppedFlag (Player *)
 
virtual void EventPlayerClickedOnFlag (Player *, GameObject *)
 
virtual void EventPlayerDamagedGO (Player *, GameObject *, uint32)
 
virtual void EventPlayerUsedGO (Player *, GameObject *)
 
virtual void DoAction (uint32, ObjectGuid)
 
virtual void HandlePlayerResurrect (Player *)
 
virtual GraveyardStruct const * GetClosestGraveyard (Player *player)
 
void AddOrSetPlayerToCorrectBgGroup (Player *player, TeamId teamId)
 
void HandleTriggerBuff (GameObject *gameObject)
 
void SetHoliday (bool is_holiday)
 
void SpawnBGObject (uint32 type, uint32 respawntime, uint32 forceRespawnDelay=0)
 
bool AddObject (uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime=0, GOState goState=GO_STATE_READY)
 
CreatureAddCreature (uint32 entry, uint32 type, float x, float y, float z, float o, uint32 respawntime=0, MotionTransport *transport=nullptr)
 
bool DelCreature (uint32 type)
 
bool DelObject (uint32 type)
 
bool AddSpiritGuide (uint32 type, float x, float y, float z, float o, TeamId teamId)
 
int32 GetObjectType (ObjectGuid guid)
 
void DoorOpen (uint32 type)
 
void DoorClose (uint32 type)
 
virtual bool HandlePlayerUnderMap (Player *)
 
bool IsPlayerInBattleground (ObjectGuid guid) const
 
bool ToBeDeleted () const
 
void RewardXPAtKill (Player *killer, Player *victim)
 
virtual ObjectGuid GetFlagPickerGUID (TeamId=TEAM_NEUTRAL) const
 
virtual void SetDroppedFlagGUID (ObjectGuid, TeamId=TEAM_NEUTRAL)
 
uint32 GetTeamScore (TeamId teamId) const
 
virtual TeamId GetPrematureWinner ()
 
uint8 GetUniqueBracketId () const
 
BattlegroundAVToBattlegroundAV ()
 
BattlegroundAV const * ToBattlegroundAV () const
 
BattlegroundWSToBattlegroundWS ()
 
BattlegroundWS const * ToBattlegroundWS () const
 
BattlegroundABToBattlegroundAB ()
 
BattlegroundAB const * ToBattlegroundAB () const
 
BattlegroundNAToBattlegroundNA ()
 
BattlegroundNA const * ToBattlegroundNA () const
 
BattlegroundBEToBattlegroundBE ()
 
BattlegroundBE const * ToBattlegroundBE () const
 
BattlegroundEYToBattlegroundEY ()
 
BattlegroundEY const * ToBattlegroundEY () const
 
BattlegroundRLToBattlegroundRL ()
 
BattlegroundRL const * ToBattlegroundRL () const
 
BattlegroundSAToBattlegroundSA ()
 
BattlegroundSA const * ToBattlegroundSA () const
 
BattlegroundDSToBattlegroundDS ()
 
BattlegroundDS const * ToBattlegroundDS () const
 
BattlegroundRVToBattlegroundRV ()
 
BattlegroundRV const * ToBattlegroundRV () const
 
BattlegroundICToBattlegroundIC ()
 
BattlegroundIC const * ToBattlegroundIC () const
 
- Static Public Member Functions inherited from Battleground
static TeamId GetOtherTeamId (TeamId teamId)
 
- Public Attributes inherited from Battleground
GuidSet readyMarkerClickedSet
 
ArenaLogEntryDataMap ArenaLogEntries
 
BGObjects BgObjects
 
BGCreatures BgCreatures
 
- Protected Attributes inherited from Battleground
bool m_SetupCompleted
 
BattlegroundScoreMap PlayerScores
 
BattlegroundPlayerMap m_Players
 
std::map< ObjectGuid, GuidVectorm_ReviveQueue
 
uint8 m_Events
 
BattlegroundStartTimeIntervals StartDelayTimes [BG_STARTING_EVENT_COUNT]
 
uint32 StartMessageIds [BG_STARTING_EVENT_COUNT]
 
bool m_BuffChange
 
bool m_IsRandom
 
BGHonorMode m_HonorMode
 
int32 m_TeamScores [PVP_TEAMS_COUNT]
 
ArenaTeamScore _arenaTeamScores [PVP_TEAMS_COUNT]
 
uint32 m_UpdateTimer
 
EventProcessor _reviveEvents
 

Detailed Description

Constructor & Destructor Documentation

◆ Arena()

Arena::Arena ( )
protected
66{
71
76}
@ ARENA_TEXT_START_ONE_MINUTE
Definition Arena.h:25
@ ARENA_TEXT_START_THIRTY_SECONDS
Definition Arena.h:26
@ ARENA_TEXT_START_BATTLE_HAS_BEGUN
Definition Arena.h:28
@ ARENA_TEXT_START_FIFTEEN_SECONDS
Definition Arena.h:27
@ BG_START_DELAY_1M
Definition Battleground.h:171
@ BG_START_DELAY_30S
Definition Battleground.h:172
@ BG_START_DELAY_NONE
Definition Battleground.h:174
@ BG_START_DELAY_15S
Definition Battleground.h:173
@ BG_STARTING_EVENT_THIRD
Definition Battleground.h:232
@ BG_STARTING_EVENT_SECOND
Definition Battleground.h:231
@ BG_STARTING_EVENT_FIRST
Definition Battleground.h:230
@ BG_STARTING_EVENT_FOURTH
Definition Battleground.h:233
BattlegroundStartTimeIntervals StartDelayTimes[BG_STARTING_EVENT_COUNT]
Definition Battleground.h:642
uint32 StartMessageIds[BG_STARTING_EVENT_COUNT]
Definition Battleground.h:644

References ARENA_TEXT_START_BATTLE_HAS_BEGUN, ARENA_TEXT_START_FIFTEEN_SECONDS, ARENA_TEXT_START_ONE_MINUTE, ARENA_TEXT_START_THIRTY_SECONDS, BG_START_DELAY_15S, BG_START_DELAY_1M, BG_START_DELAY_30S, BG_START_DELAY_NONE, BG_STARTING_EVENT_FIRST, BG_STARTING_EVENT_FOURTH, BG_STARTING_EVENT_SECOND, BG_STARTING_EVENT_THIRD, Battleground::StartDelayTimes, and Battleground::StartMessageIds.

Member Function Documentation

◆ AddPlayer()

void Arena::AddPlayer ( Player player)
overrideprotectedvirtual

Reimplemented from Battleground.

79{
81 PlayerScores.emplace(player->GetGUID().GetCounter(), new ArenaScore(player->GetGUID(), player->GetBgTeamId()));
82
83 if (player->GetBgTeamId() == TEAM_ALLIANCE) // gold
84 {
85 if (player->GetTeamId() == TEAM_HORDE)
86 player->CastSpell(player, SPELL_HORDE_GOLD_FLAG, true);
87 else
88 player->CastSpell(player, SPELL_ALLIANCE_GOLD_FLAG, true);
89 }
90 else // green
91 {
92 if (player->GetTeamId() == TEAM_HORDE)
93 player->CastSpell(player, SPELL_HORDE_GREEN_FLAG, true);
94 else
95 player->CastSpell(player, SPELL_ALLIANCE_GREEN_FLAG, true);
96 }
97
99
100 Group* group = player->GetGroup();
101 if (group)
102 {
103 // Hackfix for crossfaction arenas, recreate group when joining
104 // Without this, players in a crossfaction arena group would not be able to cast beneficial spells on their teammates
105
106 std::vector<Player*> members;
107 bool isCrossfaction = false;
108 for (Group::member_citerator mitr = group->GetMemberSlots().begin(); mitr != group->GetMemberSlots().end(); ++mitr)
109 {
110 Player* member = ObjectAccessor::FindPlayer(mitr->guid);
111 if (!member || member->GetGUID() == player->GetGUID())
112 {
113 continue;
114 }
115 members.push_back(member);
116 if (member->GetTeamId(true) != player->GetTeamId(true))
117 {
118 isCrossfaction = true;
119 }
120 }
121
122 if (isCrossfaction)
123 {
124 for (Player* member : members)
125 {
126 member->RemoveFromGroup();
127 }
128 group->Disband();
129
130 group = new Group();
131 SetBgRaid(player->GetBgTeamId(), group);
132 group->Create(player);
133 sGroupMgr->AddGroup(group);
134 for (Player* member : members)
135 {
136 group->AddMember(member);
137 }
138 }
139 }
140}
@ SPELL_ALLIANCE_GOLD_FLAG
Definition Arena.h:33
@ SPELL_HORDE_GOLD_FLAG
Definition Arena.h:35
@ SPELL_HORDE_GREEN_FLAG
Definition Arena.h:36
@ SPELL_ALLIANCE_GREEN_FLAG
Definition Arena.h:34
#define sGroupMgr
Definition GroupMgr.h:51
@ TEAM_ALLIANCE
Definition SharedDefines.h:748
@ TEAM_HORDE
Definition SharedDefines.h:749
void UpdateArenaWorldState()
Definition Arena.cpp:158
virtual void AddPlayer(Player *player)
Definition Battleground.cpp:1195
BattlegroundScoreMap PlayerScores
Definition Battleground.h:631
void SetBgRaid(TeamId teamId, Group *bg_raid)
Definition Battleground.cpp:1884
Definition Group.h:176
MemberSlotList const & GetMemberSlots() const
Definition Group.h:249
void Disband(bool hideDestroy=false)
Definition Group.cpp:759
bool AddMember(Player *player, uint8 roles=0)
Definition Group.cpp:424
MemberSlotList::const_iterator member_citerator
Definition Group.h:187
bool Create(Player *leader)
Definition Group.cpp:142
LowType GetCounter() const
Definition ObjectGuid.h:145
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
Definition Player.h:1084
static void RemoveFromGroup(Group *group, ObjectGuid guid, RemoveMethod method=GROUP_REMOVEMETHOD_DEFAULT, ObjectGuid kicker=ObjectGuid::Empty, const char *reason=nullptr)
Definition Player.cpp:2328
TeamId GetTeamId(bool original=false) const
Definition Player.h:2131
Group * GetGroup()
Definition Player.h:2509
TeamId GetBgTeamId() const
Definition Player.h:2318
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition Unit.cpp:1389
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245
Definition ArenaScore.h:26

References Group::AddMember(), Battleground::AddPlayer(), Unit::CastSpell(), Group::Create(), Group::Disband(), ObjectAccessor::FindPlayer(), Player::GetBgTeamId(), ObjectGuid::GetCounter(), Player::GetGroup(), Object::GetGUID(), Group::GetMemberSlots(), Player::GetTeamId(), Battleground::PlayerScores, Battleground::SetBgRaid(), sGroupMgr, SPELL_ALLIANCE_GOLD_FLAG, SPELL_ALLIANCE_GREEN_FLAG, SPELL_HORDE_GOLD_FLAG, SPELL_HORDE_GREEN_FLAG, TEAM_ALLIANCE, TEAM_HORDE, and UpdateArenaWorldState().

◆ CheckWinConditions()

void Arena::CheckWinConditions ( )
overrideprivatevirtual

Reimplemented from Battleground.

197{
198 if (!sScriptMgr->OnBeforeArenaCheckWinConditions(this))
199 return;
200
205}
#define sScriptMgr
Definition ScriptMgr.h:740
void EndBattleground(TeamId winnerTeamId) override
Definition Arena.cpp:207
uint32 GetAlivePlayersCountByTeam(TeamId teamId) const
Definition Battleground.cpp:1857
uint32 GetPlayersCountByTeam(TeamId teamId) const
Definition Battleground.h:498

References EndBattleground(), Battleground::GetAlivePlayersCountByTeam(), Battleground::GetPlayersCountByTeam(), sScriptMgr, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by HandleKillPlayer(), and RemovePlayer().

◆ EndBattleground()

void Arena::EndBattleground ( TeamId  winnerTeamId)
overrideprivatevirtual
Deprecated:
need delete

Reimplemented from Battleground.

208{
209 if (isRated())
210 {
211 uint32 startDelay = GetStartDelayTime();
212 bool bValidArena = GetStatus() == STATUS_IN_PROGRESS && GetStartTime() >= startDelay + 15000; // pussywizard: only if arena lasted at least 15 secs
213
214 uint32 loserTeamRating = 0;
215 uint32 loserMatchmakerRating = 0;
216 int32 loserChange = 0;
217 int32 loserMatchmakerChange = 0;
218 uint32 winnerTeamRating = 0;
219 uint32 winnerMatchmakerRating = 0;
220 int32 winnerChange = 0;
221 int32 winnerMatchmakerChange = 0;
222
223 ArenaTeam* winnerArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(winnerTeamId == TEAM_NEUTRAL ? TEAM_HORDE : winnerTeamId));
224 ArenaTeam* loserArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(winnerTeamId == TEAM_NEUTRAL ? TEAM_ALLIANCE : GetOtherTeamId(winnerTeamId)));
225
226 auto SaveArenaLogs = [&]()
227 {
228 // pussywizard: arena logs in database
229 uint32 fightId = sArenaTeamMgr->GetNextArenaLogId();
230 uint32 currOnline = sWorldSessionMgr->GetActiveSessionCount();
231
232 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
234 stmt2->SetData(0, fightId);
235 stmt2->SetData(1, GetArenaType());
236 stmt2->SetData(2, ((GetStartTime() <= startDelay ? 0 : GetStartTime() - startDelay) / 1000));
237 stmt2->SetData(3, winnerArenaTeam->GetId());
238 stmt2->SetData(4, loserArenaTeam->GetId());
239 stmt2->SetData(5, (uint16)winnerTeamRating);
240 stmt2->SetData(6, (uint16)winnerMatchmakerRating);
241 stmt2->SetData(7, (int16)winnerChange);
242 stmt2->SetData(8, (uint16)loserTeamRating);
243 stmt2->SetData(9, (uint16)loserMatchmakerRating);
244 stmt2->SetData(10, (int16)loserChange);
245 stmt2->SetData(11, currOnline);
246 trans->Append(stmt2);
247
248 uint8 memberId = 0;
249 for (auto& [playerGuid, arenaLogEntryData] : ArenaLogEntries)
250 {
251 auto const& score = PlayerScores.find(playerGuid.GetCounter());
252 // Update stats from PlayerScores if player is still in arena
253 if (score != PlayerScores.end())
254 arenaLogEntryData.SaveStats(score->second->GetDamageDone(), score->second->GetHealingDone(), score->second->GetKillingBlows());
255
256 stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_INS_ARENA_LOG_MEMBERSTATS);
257 stmt2->SetData(0, fightId);
258 stmt2->SetData(1, ++memberId);
259 stmt2->SetData(2, arenaLogEntryData.Name);
260 stmt2->SetData(3, arenaLogEntryData.Guid);
261 stmt2->SetData(4, arenaLogEntryData.ArenaTeamId);
262 stmt2->SetData(5, arenaLogEntryData.Acc);
263 stmt2->SetData(6, arenaLogEntryData.IP);
264 stmt2->SetData(7, arenaLogEntryData.DamageDone);
265 stmt2->SetData(8, arenaLogEntryData.HealingDone);
266 stmt2->SetData(9, arenaLogEntryData.KillingBlows);
267 trans->Append(stmt2);
268 }
269
270 CharacterDatabase.CommitTransaction(trans);
271 };
272
273 if (winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam)
274 {
275 loserTeamRating = loserArenaTeam->GetRating();
276 loserMatchmakerRating = GetArenaMatchmakerRating(GetOtherTeamId(winnerTeamId));
277 winnerTeamRating = winnerArenaTeam->GetRating();
278 winnerMatchmakerRating = GetArenaMatchmakerRating(winnerTeamId);
279
280 if (winnerTeamId != TEAM_NEUTRAL)
281 {
282 winnerMatchmakerChange = bValidArena ? winnerArenaTeam->WonAgainst(winnerMatchmakerRating, loserMatchmakerRating, winnerChange, GetBgMap()) : 0;
283 loserMatchmakerChange = loserArenaTeam->LostAgainst(loserMatchmakerRating, winnerMatchmakerRating, loserChange, GetBgMap());
284
285 sScriptMgr->OnAfterArenaRatingCalculation(this, winnerMatchmakerChange, loserMatchmakerChange, winnerChange, loserChange);
286
287 LOG_DEBUG("bg.arena", "match Type: {} --- Winner: old rating: {}, rating gain: {}, old MMR: {}, MMR gain: {} --- Loser: old rating: {}, rating loss: {}, old MMR: {}, MMR loss: {} ---",
288 GetArenaType(), winnerTeamRating, winnerChange, winnerMatchmakerRating, winnerMatchmakerChange,
289 loserTeamRating, loserChange, loserMatchmakerRating, loserMatchmakerChange);
290
291 SetArenaMatchmakerRating(winnerTeamId, winnerMatchmakerRating + winnerMatchmakerChange);
292 SetArenaMatchmakerRating(GetOtherTeamId(winnerTeamId), loserMatchmakerRating + loserMatchmakerChange);
293
294 // bg team that the client expects is different to TeamId
295 // alliance 1, horde 0
296 uint8 winnerTeam = winnerTeamId == TEAM_ALLIANCE ? PVP_TEAM_ALLIANCE : PVP_TEAM_HORDE;
297 uint8 loserTeam = winnerTeamId == TEAM_ALLIANCE ? PVP_TEAM_HORDE : PVP_TEAM_ALLIANCE;
298
299 _arenaTeamScores[winnerTeam].Assign(winnerChange, winnerMatchmakerRating, winnerArenaTeam->GetName());
300 _arenaTeamScores[loserTeam].Assign(loserChange, loserMatchmakerRating, loserArenaTeam->GetName());
301
302 LOG_DEBUG("bg.arena", "Arena match Type: {} for Team1Id: {} - Team2Id: {} ended. WinnerTeamId: {}. Winner rating: +{}, Loser rating: {}",
303 GetArenaType(), GetArenaTeamIdForTeam(TEAM_ALLIANCE), GetArenaTeamIdForTeam(TEAM_HORDE), winnerArenaTeam->GetId(), winnerChange, loserChange);
304 }
305 else // Deduct 16 points from each teams arena-rating if there are no winners after 45+2 minutes
306 {
307 // pussywizard: in case of a draw, the following is always true:
308 // winnerArenaTeam => TEAM_HORDE, loserArenaTeam => TEAM_ALLIANCE
309
310 winnerTeamRating = winnerArenaTeam->GetRating();
311 winnerMatchmakerRating = GetArenaMatchmakerRating(TEAM_HORDE);
312 loserTeamRating = loserArenaTeam->GetRating();
313 loserMatchmakerRating = GetArenaMatchmakerRating(TEAM_ALLIANCE);
314 winnerMatchmakerChange = 0;
315 loserMatchmakerChange = 0;
316 winnerChange = ARENA_TIMELIMIT_POINTS_LOSS;
317 loserChange = ARENA_TIMELIMIT_POINTS_LOSS;
318
319 _arenaTeamScores[PVP_TEAM_ALLIANCE].Assign(ARENA_TIMELIMIT_POINTS_LOSS, winnerMatchmakerRating, winnerArenaTeam->GetName());
320 _arenaTeamScores[PVP_TEAM_HORDE].Assign(ARENA_TIMELIMIT_POINTS_LOSS, loserMatchmakerRating, loserArenaTeam->GetName());
321
324 }
325 }
326
327 SaveArenaLogs();
328
329 uint8 aliveWinners = GetAlivePlayersCountByTeam(winnerTeamId);
330
331 for (auto const& [playerGuid, player] : GetPlayers())
332 {
333 auto const& bgTeamId = player->GetBgTeamId();
334
335 // per player calculation
336 if (winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam)
337 {
338 if (bgTeamId == winnerTeamId)
339 {
340 if (bValidArena)
341 {
342 // update achievement BEFORE personal rating update
343 uint32 rating = player->GetArenaPersonalRating(winnerArenaTeam->GetSlot());
344 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA, rating ? rating : 1);
345 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA, GetMapId());
346
347 // Last standing - Rated 5v5 arena & be solely alive player
348 if (GetArenaType() == ARENA_TYPE_5v5 && aliveWinners == 1 && player->IsAlive())
349 player->CastSpell(player, SPELL_LAST_MAN_STANDING, true);
350
351 if (sScriptMgr->OnBeforeArenaTeamMemberUpdate(winnerArenaTeam, player, true, loserMatchmakerRating, winnerMatchmakerChange))
352 winnerArenaTeam->MemberWon(player, loserMatchmakerRating, winnerMatchmakerChange);
353 }
354 }
355 else
356 {
357 if (sScriptMgr->OnBeforeArenaTeamMemberUpdate(loserArenaTeam, player, false, winnerMatchmakerRating, loserMatchmakerChange))
358 loserArenaTeam->MemberLost(player, winnerMatchmakerRating, loserMatchmakerChange);
359
360 // Arena lost => reset the win_rated_arena having the "no_lose" condition
361 player->ResetAchievementCriteria(ACHIEVEMENT_CRITERIA_CONDITION_NO_LOSE, 0);
362 }
363
364 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_PLAY_ARENA, GetMapId());
365 }
366 }
367
368 // update previous opponents for arena queue
369 winnerArenaTeam->SetPreviousOpponents(loserArenaTeam->GetId());
370 loserArenaTeam->SetPreviousOpponents(winnerArenaTeam->GetId());
371
372 // save the stat changes
373 if (bValidArena)
374 {
375 winnerArenaTeam->SaveToDB();
376 winnerArenaTeam->NotifyStatsChanged();
377 }
378
379 loserArenaTeam->SaveToDB();
380 loserArenaTeam->NotifyStatsChanged();
381 }
382
383 // end battleground
384 Battleground::EndBattleground(winnerTeamId);
385}
#define sArenaTeamMgr
Definition ArenaTeamMgr.h:69
@ SPELL_LAST_MAN_STANDING
Definition Arena.h:38
#define ARENA_TIMELIMIT_POINTS_LOSS
Definition Battleground.h:285
@ STATUS_IN_PROGRESS
Definition Battleground.h:193
@ ARENA_TYPE_5v5
Definition Battleground.h:210
@ CHAR_INS_ARENA_LOG_MEMBERSTATS
Definition CharacterDatabase.h:317
@ CHAR_INS_ARENA_LOG_FIGHT
Definition CharacterDatabase.h:316
@ ACHIEVEMENT_CRITERIA_CONDITION_NO_LOSE
Definition DBCEnums.h:91
@ ACHIEVEMENT_CRITERIA_TYPE_PLAY_ARENA
Definition DBCEnums.h:147
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA
Definition DBCEnums.h:151
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA
Definition DBCEnums.h:146
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition DatabaseEnvFwd.h:69
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::int32_t int32
Definition Define.h:103
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
std::uint16_t uint16
Definition Define.h:108
std::int16_t int16
Definition Define.h:104
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157
@ PVP_TEAM_HORDE
Definition SharedDefines.h:3689
@ PVP_TEAM_ALLIANCE
Definition SharedDefines.h:3690
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
#define sWorldSessionMgr
Definition WorldSessionMgr.h:108
Definition ArenaTeam.h:137
void SaveToDB(bool forceMemberSave=false)
Definition ArenaTeam.cpp:936
uint32 GetRating() const
Definition ArenaTeam.h:158
void MemberLost(Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange=-12)
Definition ArenaTeam.cpp:847
void SetPreviousOpponents(uint32 arenaTeamId)
Definition ArenaTeam.h:211
int32 WonAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32 &rating_change, const Map *bgMap)
Definition ArenaTeam.cpp:811
uint8 GetSlot() const
Definition ArenaTeam.h:150
void NotifyStatsChanged()
Definition ArenaTeam.cpp:510
int32 LostAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32 &rating_change, const Map *bgMap)
Definition ArenaTeam.cpp:831
std::string const & GetName() const
Definition ArenaTeam.h:154
void FinishGame(int32 mod, const Map *bgMap)
Definition ArenaTeam.cpp:781
uint32 GetId() const
Definition ArenaTeam.h:148
void MemberWon(Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange)
Definition ArenaTeam.cpp:873
uint32 GetMapId() const
Definition Battleground.h:446
ArenaTeamScore _arenaTeamScores[PVP_TEAMS_COUNT]
Definition Battleground.h:652
uint8 GetArenaType() const
Definition Battleground.h:358
uint32 GetArenaMatchmakerRating(TeamId teamId) const
Definition Battleground.h:514
ArenaLogEntryDataMap ArenaLogEntries
Definition Battleground.h:427
static TeamId GetOtherTeamId(TeamId teamId)
Definition Battleground.cpp:1829
bool isRated() const
Definition Battleground.h:416
BattlegroundMap * GetBgMap() const
Definition Battleground.h:450
void EndBattleground(PvPTeamId winnerTeamId)
Definition Battleground.cpp:835
uint32 GetStartTime() const
Definition Battleground.h:335
BattlegroundPlayerMap const & GetPlayers() const
Definition Battleground.h:419
int32 GetStartDelayTime() const
Definition Battleground.h:357
BattlegroundStatus GetStatus() const
Definition Battleground.h:333
void SetArenaMatchmakerRating(TeamId teamId, uint32 MMR)
Definition Battleground.h:513
uint32 GetArenaTeamIdForTeam(TeamId teamId) const
Definition Battleground.h:512
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
void Assign(int32 ratingChange, uint32 matchMakerRating, std::string_view teamName)
Definition ArenaScore.h:61

References Battleground::_arenaTeamScores, ACHIEVEMENT_CRITERIA_CONDITION_NO_LOSE, ACHIEVEMENT_CRITERIA_TYPE_PLAY_ARENA, ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA, ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA, ARENA_TIMELIMIT_POINTS_LOSS, ARENA_TYPE_5v5, Battleground::ArenaLogEntries, ArenaTeamScore::Assign(), CHAR_INS_ARENA_LOG_FIGHT, CHAR_INS_ARENA_LOG_MEMBERSTATS, CharacterDatabase, Battleground::EndBattleground(), ArenaTeam::FinishGame(), Battleground::GetAlivePlayersCountByTeam(), Battleground::GetArenaMatchmakerRating(), Battleground::GetArenaTeamIdForTeam(), Battleground::GetArenaType(), Battleground::GetBgMap(), ArenaTeam::GetId(), Battleground::GetMapId(), ArenaTeam::GetName(), Battleground::GetOtherTeamId(), Battleground::GetPlayers(), ArenaTeam::GetRating(), ArenaTeam::GetSlot(), Battleground::GetStartDelayTime(), Battleground::GetStartTime(), Battleground::GetStatus(), Battleground::isRated(), LOG_DEBUG, ArenaTeam::LostAgainst(), ArenaTeam::MemberLost(), ArenaTeam::MemberWon(), ArenaTeam::NotifyStatsChanged(), Battleground::PlayerScores, PVP_TEAM_ALLIANCE, PVP_TEAM_HORDE, sArenaTeamMgr, ArenaTeam::SaveToDB(), Battleground::SetArenaMatchmakerRating(), PreparedStatementBase::SetData(), ArenaTeam::SetPreviousOpponents(), SPELL_LAST_MAN_STANDING, sScriptMgr, STATUS_IN_PROGRESS, sWorldSessionMgr, TEAM_ALLIANCE, TEAM_HORDE, TEAM_NEUTRAL, and ArenaTeam::WonAgainst().

Referenced by CheckWinConditions().

◆ FillInitialWorldStates()

◆ HandleKillPlayer()

void Arena::HandleKillPlayer ( Player player,
Player killer 
)
overrideprotectedvirtual

Reimplemented from Battleground.

165{
167 return;
168
169 Battleground::HandleKillPlayer(player, killer);
170
173}
void CheckWinConditions() override
Definition Arena.cpp:196
virtual void HandleKillPlayer(Player *player, Player *killer)
Definition Battleground.cpp:1794

References CheckWinConditions(), Battleground::GetStatus(), Battleground::HandleKillPlayer(), STATUS_IN_PROGRESS, and UpdateArenaWorldState().

◆ RemovePlayer()

void Arena::RemovePlayer ( Player )
overrideprotectedvirtual

Reimplemented from Battleground.

143{
145 return;
146
149}
@ STATUS_WAIT_LEAVE
Definition Battleground.h:194

References CheckWinConditions(), Battleground::GetStatus(), STATUS_WAIT_LEAVE, and UpdateArenaWorldState().

◆ RemovePlayerAtLeave()

void Arena::RemovePlayerAtLeave ( Player player)
overrideprivatevirtual

Reimplemented from Battleground.

176{
178 {
179 if (auto const& member = Acore::Containers::MapGetValuePtr(m_Players, player->GetGUID()))
180 {
181 // if the player was a match participant, calculate rating
182 auto teamId = member->GetBgTeamId();
183
184 ArenaTeam* winnerArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(GetOtherTeamId(teamId)));
185 ArenaTeam* loserArenaTeam = sArenaTeamMgr->GetArenaTeamById(GetArenaTeamIdForTeam(teamId));
186
187 if (winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam)
188 loserArenaTeam->MemberLost(player, GetArenaMatchmakerRating(GetOtherTeamId(teamId)));
189 }
190 }
191
192 // remove player
194}
virtual void RemovePlayerAtLeave(Player *player)
Definition Battleground.cpp:1046
BattlegroundPlayerMap m_Players
Definition Battleground.h:636
auto MapGetValuePtr(M &map, typename M::key_type const &key) -> decltype(AddressOrSelf(map.find(key) ->second))
Definition Containers.h:216

References Battleground::GetArenaMatchmakerRating(), Battleground::GetArenaTeamIdForTeam(), Object::GetGUID(), Battleground::GetOtherTeamId(), Battleground::GetStatus(), Battleground::isRated(), Battleground::m_Players, Acore::Containers::MapGetValuePtr(), ArenaTeam::MemberLost(), Battleground::RemovePlayerAtLeave(), sArenaTeamMgr, and STATUS_IN_PROGRESS.

◆ UpdateArenaWorldState()


The documentation for this class was generated from the following files: