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 (WorldPacket &data) 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)
 
virtual void RemovePlayer (Player *)
 

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. More...
 
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
 
virtual void FillInitialWorldStates (WorldPacket &)
 
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)
 
virtual void EndBattleground (TeamId 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)
 
virtual void CheckWinConditions ()
 
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 HandleKillPlayer (Player *player, Player *killer)
 
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)
 
virtual void AddPlayer (Player *player)
 
void AddOrSetPlayerToCorrectBgGroup (Player *player, TeamId teamId)
 
virtual void RemovePlayerAtLeave (Player *player)
 
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)
 
const char * GetAcoreString (int32 entry)
 
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
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
64{
69
74}
@ BG_START_DELAY_1M
Definition: Battleground.h:180
@ BG_START_DELAY_30S
Definition: Battleground.h:181
@ BG_START_DELAY_NONE
Definition: Battleground.h:183
@ BG_START_DELAY_15S
Definition: Battleground.h:182
@ BG_STARTING_EVENT_THIRD
Definition: Battleground.h:241
@ BG_STARTING_EVENT_SECOND
Definition: Battleground.h:240
@ BG_STARTING_EVENT_FIRST
Definition: Battleground.h:239
@ BG_STARTING_EVENT_FOURTH
Definition: Battleground.h:242
@ 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
BattlegroundStartTimeIntervals StartDelayTimes[BG_STARTING_EVENT_COUNT]
Definition: Battleground.h:640
uint32 StartMessageIds[BG_STARTING_EVENT_COUNT]
Definition: Battleground.h:642

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.

77{
79 PlayerScores.emplace(player->GetGUID().GetCounter(), new ArenaScore(player->GetGUID(), player->GetBgTeamId()));
80
81 if (player->GetBgTeamId() == TEAM_ALLIANCE) // gold
82 {
83 if (player->GetTeamId() == TEAM_HORDE)
84 player->CastSpell(player, SPELL_HORDE_GOLD_FLAG, true);
85 else
86 player->CastSpell(player, SPELL_ALLIANCE_GOLD_FLAG, true);
87 }
88 else // green
89 {
90 if (player->GetTeamId() == TEAM_HORDE)
91 player->CastSpell(player, SPELL_HORDE_GREEN_FLAG, true);
92 else
93 player->CastSpell(player, SPELL_ALLIANCE_GREEN_FLAG, true);
94 }
95
97
98 Group* group = player->GetGroup();
99 if (group)
100 {
101 // Hackfix for crossfaction arenas, recreate group when joining
102 // Without this, players in a crossfaction arena group would not be able to cast beneficial spells on their teammates
103
104 std::vector<Player*> members;
105 bool isCrossfaction = false;
106 for (Group::member_citerator mitr = group->GetMemberSlots().begin(); mitr != group->GetMemberSlots().end(); ++mitr)
107 {
108 Player* member = ObjectAccessor::FindPlayer(mitr->guid);
109 if (!member || member->GetGUID() == player->GetGUID())
110 {
111 continue;
112 }
113 members.push_back(member);
114 if (member->GetTeamId(true) != player->GetTeamId(true))
115 {
116 isCrossfaction = true;
117 }
118 }
119
120 if (isCrossfaction)
121 {
122 for (Player* member : members)
123 {
124 member->RemoveFromGroup();
125 }
126 group->Disband();
127
128 group = new Group();
129 SetBgRaid(player->GetBgTeamId(), group);
130 group->Create(player);
131 sGroupMgr->AddGroup(group);
132 for (Player* member : members)
133 {
134 group->AddMember(member);
135 }
136 }
137 }
138}
@ TEAM_ALLIANCE
Definition: SharedDefines.h:760
@ TEAM_HORDE
Definition: SharedDefines.h:761
#define sGroupMgr
Definition: GroupMgr.h:51
@ 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
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:245
void UpdateArenaWorldState()
Definition: Arena.cpp:155
Definition: ArenaScore.h:26
virtual void AddPlayer(Player *player)
Definition: Battleground.cpp:1115
BattlegroundScoreMap PlayerScores
Definition: Battleground.h:629
void SetBgRaid(TeamId teamId, Group *bg_raid)
Definition: Battleground.cpp:1809
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
LowType GetCounter() const
Definition: ObjectGuid.h:145
Definition: Player.h:1081
static void RemoveFromGroup(Group *group, ObjectGuid guid, RemoveMethod method=GROUP_REMOVEMETHOD_DEFAULT, ObjectGuid kicker=ObjectGuid::Empty, const char *reason=nullptr)
Definition: Player.cpp:2367
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2108
Group * GetGroup()
Definition: Player.h:2468
TeamId GetBgTeamId() const
Definition: Player.h:2278
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:1167
Definition: Group.h:169
MemberSlotList const & GetMemberSlots() const
Definition: Group.h:242
void Disband(bool hideDestroy=false)
Definition: Group.cpp:751
bool AddMember(Player *player)
Definition: Group.cpp:388
MemberSlotList::const_iterator member_citerator
Definition: Group.h:180
bool Create(Player *leader)
Definition: Group.cpp:106

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.

194{
195 if (!sScriptMgr->OnBeforeArenaCheckWinConditions(this))
196 return;
197
202}
#define sScriptMgr
Definition: ScriptMgr.h:709
void EndBattleground(TeamId winnerTeamId) override
Definition: Arena.cpp:204
uint32 GetAlivePlayersCountByTeam(TeamId teamId) const
Definition: Battleground.cpp:1782
uint32 GetPlayersCountByTeam(TeamId teamId) const
Definition: Battleground.h:497

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.

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

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, sWorld, 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.

162{
164 return;
165
166 Battleground::HandleKillPlayer(player, killer);
167
170}
void CheckWinConditions() override
Definition: Arena.cpp:193
virtual void HandleKillPlayer(Player *player, Player *killer)
Definition: Battleground.cpp:1719

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

◆ RemovePlayer()

void Arena::RemovePlayer ( Player )
overrideprotectedvirtual

Reimplemented from Battleground.

141{
143 return;
144
147}
@ STATUS_WAIT_LEAVE
Definition: Battleground.h:203

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

◆ RemovePlayerAtLeave()

void Arena::RemovePlayerAtLeave ( Player player)
overrideprivatevirtual

Reimplemented from Battleground.

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

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()