56 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
129 bgRaid->SetBattlegroundGroup(
nullptr);
214 for (BattlegroundPlayerMap::const_iterator itr =
GetPlayers().begin(); itr !=
GetPlayers().end(); ++itr)
218 if (player->IsGameMaster())
225 TC_LOG_DEBUG(
"bg.battleground",
"BATTLEGROUND: Sending {} back to start location (map: {}) (possible exploit)", player->GetName(),
GetMapId());
226 player->TeleportTo(startPos->
Loc);
246 playerPosition.Pos = player->GetPosition();
290 bool broadcastStatusUpdate =
false;
297 broadcastStatusUpdate =
true;
310 broadcastStatusUpdate =
true;
313 if (broadcastStatusUpdate)
315 for (
auto const& [guid, playerData] :
m_Players)
321 player->GetBattlegroundQueueIndex(playerData.queueTypeId),
322 player->GetBattlegroundQueueJoinTime(playerData.queueTypeId), playerData.queueTypeId);
323 player->SendDirectMessage(battlefieldStatus.
Write());
339 for (BattlegroundPlayerMap::const_iterator itr =
GetPlayers().begin(); itr !=
GetPlayers().end(); ++itr)
341 player->ResetAllPowers();
409 for (BattlegroundPlayerMap::const_iterator itr =
GetPlayers().begin(); itr !=
GetPlayers().end(); ++itr)
414 player->SetArenaFaction(player->GetBGTeam());
417 player->ResetAllPowers();
418 if (!player->IsGameMaster())
440 for (BattlegroundPlayerMap::const_iterator itr =
GetPlayers().begin(); itr !=
GetPlayers().end(); ++itr)
445 player->ResetAllPowers();
465 BattlegroundPlayerMap::iterator itr, next;
485 TC_LOG_ERROR(
"bg.battleground",
"Battleground::{}: player ({}) not found for BG (map: {}, instance id: {})!",
496 Team playerTeam = itr->second.Team;
499 if (playerTeam != team)
524 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
526 player->SendDirectMessage(packet);
531 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
534 if (player != except)
535 player->SendDirectMessage(packet);
548 TC_LOG_ERROR(
"bg.battleground",
"Battleground::SendBroadcastText: `broadcast_text` (ID: {}) was not found",
id);
569 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
571 player->CastSpell(player, SpellID,
true);
576 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
578 player->RemoveAura(SpellID);
583 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
594 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
603 uint32 repGain = Reputation;
619 bool guildAwarded =
false;
630 else if (winner ==
HORDE)
645 uint64 battlegroundId = 1;
653 Field* fields = result->Fetch();
654 battlegroundId = fields[0].
GetUInt64() + 1;
673 pvpMatchComplete.
Write();
675 for (BattlegroundPlayerMap::iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
677 Team team = itr->second.Team;
710 stmt->
setBool (2, team == winner);
711 stmt->
setUInt32(3, score->second->GetKillingBlows());
712 stmt->
setUInt32(4, score->second->GetDeaths());
713 stmt->
setUInt32(5, score->second->GetHonorableKills());
714 stmt->
setUInt32(6, score->second->GetBonusHonor());
715 stmt->
setUInt32(7, score->second->GetDamageDone());
716 stmt->
setUInt32(8, score->second->GetHealingDone());
717 stmt->
setUInt32(9, score->second->GetAttr(0));
718 stmt->
setUInt32(10, score->second->GetAttr(1));
719 stmt->
setUInt32(11, score->second->GetAttr(2));
720 stmt->
setUInt32(12, score->second->GetAttr(3));
721 stmt->
setUInt32(13, score->second->GetAttr(4));
806 bool participant =
false;
808 BattlegroundPlayerMap::iterator itr =
m_Players.find(guid);
812 bgQueueTypeId = itr->second.queueTypeId;
819 BattlegroundScoreMap::iterator itr2 =
PlayerScores.find(guid);
874 if (SendPacket && bgQueueTypeId)
889 if (!group->RemoveMember(guid))
903 playerLeft.
Guid = guid;
920 TC_LOG_DEBUG(
"bg.battleground",
"Removed player {} from Battleground.", player->
GetName());
936 TC_LOG_ERROR(
"bg.battleground",
"Battleground::Reset: one of the counters is not 0 (alliance: {}, horde: {}) for BG (map: {}, instance id: {})!",
993 if (!isInBattleground)
1027 pvpMatchInitialize.
Duration = std::chrono::duration_cast<Seconds>(duration);
1110 if (originalGroup->IsLeader(playerGuid))
1189 uint32 otherTeamInvitedCount;
1190 uint32 thisTeamInvitedCount;
1191 uint32 otherTeamPlayersCount;
1192 uint32 thisTeamPlayersCount;
1215 if (otherTeamInvitedCount == thisTeamInvitedCount)
1218 else if (otherTeamInvitedCount > thisTeamInvitedCount)
1219 diff = otherTeamInvitedCount - thisTeamInvitedCount;
1228 if (otherTeamPlayersCount == thisTeamPlayersCount)
1231 else if (otherTeamPlayersCount > thisTeamPlayersCount)
1232 diff3 = otherTeamPlayersCount - thisTeamPlayersCount;
1240 diff = std::min(diff, diff2);
1242 return std::min(diff, diff3);
1270 score.second->BuildPvPLogPlayerDataPacket(playerData);
1274 playerData.
Sex = player->GetGender();
1275 playerData.
Race = player->GetRace();
1276 playerData.
Class = player->GetClass();
1277 playerData.
HonorLevel = player->GetHonorLevel();
1301 itr->second->UpdateScore(type, value);
1309 score->UpdatePvpStat(pvpStatId, value);
1364 if (killer == victim)
1373 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
1376 if (!creditedPlayer || creditedPlayer == killer)
1395 script->OnPlayerKilled(victim, killer);
1401 script->OnUnitKilled(victim, killer);
1408 BattlegroundPlayerMap::const_iterator itr =
m_Players.find(guid);
1410 return itr->second.Team;
1416 BattlegroundPlayerMap::const_iterator itr =
m_Players.find(guid);
1426 return itr->second.Mercenary;
1445 for (BattlegroundPlayerMap::const_iterator itr =
m_Players.begin(); itr !=
m_Players.end(); ++itr)
1447 if (itr->second.Team == team)
1450 if (player && player->
IsAlive())
1476 Player* killers[] = { killer };
@ BG_QUEUE_INVITATION_TYPE_NO_BALANCE
@ PLAYER_POSITION_UPDATE_INTERVAL
@ TIME_AUTOCLOSE_BATTLEGROUND
@ CHECK_PLAYER_POSITION_INVERVAL
@ BG_TEXT_START_TWO_MINUTES
@ BG_TEXT_BATTLE_HAS_BEGUN
@ BG_TEXT_START_ONE_MINUTE
@ BG_TEXT_START_HALF_MINUTE
@ SPELL_MERCENARY_SHAPESHIFT
@ SPELL_MERCENARY_ALLIANCE_REACTIONS
@ SPELL_MERCENARY_HORDE_REACTIONS
@ SPELL_MERCENARY_HORDE_1
@ SPELL_ARENA_PREPARATION
@ SPELL_HONORABLE_DEFENDER_25Y
@ SPELL_MERCENARY_ALLIANCE_1
@ SPELL_HONORABLE_DEFENDER_60Y
@ BG_STARTING_EVENT_THIRD
@ BG_STARTING_EVENT_SECOND
@ BG_STARTING_EVENT_FIRST
@ BG_STARTING_EVENT_FOURTH
@ CHAR_SEL_PVPSTATS_MAXID
@ CHAR_INS_PVPSTATS_PLAYER
@ CHAR_INS_PVPSTATS_BATTLEGROUND
DB2Storage< BroadcastTextEntry > sBroadcastTextStore("BroadcastText.db2", &BroadcastTextLoadInfo::Instance)
DB2Storage< FactionEntry > sFactionStore("Faction.db2", &FactionLoadInfo::Instance)
@ ParticipateInBattleground
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
std::chrono::seconds Seconds
Seconds shorthand typedef.
@ LANG_BG_STARTED_ANNOUNCE_WORLD
#define TC_LOG_DEBUG(filterType__, message__,...)
#define TC_LOG_ERROR(filterType__, message__,...)
std::optional< T > Optional
Optional helper class to wrap optional values within.
@ PLAYER_FLAGS_EX_MERCENARY_MODE
constexpr BattlegroundQueueTypeId BATTLEGROUND_QUEUE_NONE
constexpr TeamId GetOtherTeam(TeamId team)
@ SPELL_ATTR0_NO_IMMUNITIES
@ CHAT_MSG_BG_SYSTEM_NEUTRAL
@ SPELL_AURA_MOD_SHAPESHIFT
@ SPELL_AURA_SPIRIT_OF_REDEMPTION
@ SPELL_AURA_MOD_INVISIBILITY
@ SPELL_AURA_MOD_REPUTATION_GAIN
@ SPELL_AURA_MOD_FACTION_REPUTATION_GAIN
@ LeaveArenaOrBattleground
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
int32 GetDuration() const
bool HasEffectType(AuraType type) const
SpellInfo const * GetSpellInfo() const
ObjectGuid const & GetGUID() const
void SetBG(Battleground *bg)
BattlegroundScript * GetBattlegroundScript()
static void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive *battlefieldStatus, Battleground const *bg, Player const *player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId)
static void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone *battlefieldStatus, Player const *player, uint32 ticketId, uint32 joinTime)
static bool IsRandomBattleground(uint32 battlemasterListId)
static bool IsBGWeekend(BattlegroundTypeId bgTypeId)
virtual void OnPrepareStage1()
virtual void OnEnd(Team winner)
virtual void OnPrepareStage2()
virtual void OnPrepareStage3()
virtual void OnPlayerJoined(Player *player, bool inBattleground)
void UpdatePlayersCountByTeam(Team team, bool remove)
void SetRemainingTime(uint32 Time)
uint32 m_ArenaTeamMMR[PVP_TEAMS_COUNT]
WorldSafeLocsEntry const * GetTeamStartPosition(TeamId teamId) const
Team GetPrematureWinner()
void SendPacketToTeam(Team team, WorldPacket const *packet, Player *except=nullptr) const
char const * GetName() const
PVPDifficultyEntry const * _pvpDifficultyEntry
void SendPacketToAll(WorldPacket const *packet) const
void RemovePlayerPosition(ObjectGuid guid)
uint32 GetMinLevel() const
void ModifyStartDelayTime(int diff)
void SetElapsedTime(uint32 Time)
virtual void HandleKillPlayer(Player *player, Player *killer)
void _ProcessPlayerPositionBroadcast(uint32 diff)
void AddOrSetPlayerToCorrectBgGroup(Player *player, Team team)
std::deque< ObjectGuid > m_OfflineQueue
uint32 GetMinPlayersPerTeam() const
void PlayerAddedToBGCheckIfBGIsRunning(Player *player)
uint8 GetArenaType() const
BattlegroundPlayerMap m_Players
Player * _GetPlayerForTeam(Team team, BattlegroundPlayerMap::const_iterator itr, char const *context) const
uint32 GetMaxPlayersPerTeam() const
time_t _preparationStartTime
uint32 m_ValidStartPositionTimer
Group * GetBgRaid(Team team) const
BattlegroundTemplate const * _battlegroundTemplate
uint32 GetInvitedCount(Team team) const
void SetWinner(PvPTeamId winnerTeamId)
uint8 GetUniqueBracketId() const
void PlaySoundToAll(uint32 SoundID)
uint32 m_ClientInstanceID
void AddToBGFreeSlotQueue()
uint32 GetTeamScore(TeamId teamId) const
uint32 GetPlayerScoresSize() const
void DecreaseInvitedCount(Team team)
void RewardHonorToTeam(uint32 Honor, Team team)
void SetBgMap(BattlegroundMap *map)
virtual void HandleKillUnit(Creature *, Unit *)
uint32 GetMaxPlayers() const
BattlegroundMap * GetBgMap() const
virtual void PostUpdateImpl(uint32)
Post-update hook.
PvPTeamId GetWinner() const
Battleground(BattlegroundTemplate const *battlegroundTemplate)
virtual void RemovePlayer(Player *, ObjectGuid, uint32)
BattlegroundMap * FindBgMap() const
void BlockMovement(Player *player)
uint32 GetRemainingTime() const
Player * _GetPlayer(ObjectGuid guid, bool offlineRemove, char const *context) const
BattlegroundTypeId GetTypeID() const
bool m_PrematureCountDown
uint32 m_PlayersCount[PVP_TEAMS_COUNT]
Group * m_BgRaids[PVP_TEAMS_COUNT]
void RemoveAuraOnTeam(uint32 SpellID, Team team)
virtual WorldSafeLocsEntry const * GetExploitTeleportLocation(Team)
int32 m_TeamScores[PVP_TEAMS_COUNT]
void SendMessageToAll(uint32 entry, ChatMsg type, Player const *source=nullptr)
void EventPlayerLoggedOut(Player *player)
void SendChatMessage(Creature *source, uint8 textId, WorldObject *target=nullptr)
BattlegroundPlayer const * GetBattlegroundPlayerData(ObjectGuid const &playerGuid) const
void RewardXPAtKill(Player *killer, Player *victim)
static TeamId GetTeamIndexByTeamId(Team team)
void UpdateWorldState(int32 worldStateId, int32 value, bool hidden=false)
void SetStatus(BattlegroundStatus Status)
bool IsPlayerMercenaryInBattleground(ObjectGuid guid) const
void BroadcastWorker(Do &_do)
virtual void EndBattleground(Team winner)
bool IsPlayerInBattleground(ObjectGuid guid) const
BattlegroundStartTimeIntervals StartDelayTimes[BG_STARTING_EVENT_COUNT]
uint32 m_LastPlayerPositionBroadcast
void SendBroadcastText(uint32 id, ChatMsg msgType, WorldObject const *target=nullptr)
BattlegroundScore const * GetBattlegroundScore(Player *player) const
void AddPlayerPosition(WorldPackets::Battleground::BattlegroundPlayerPosition const &position)
void PlaySoundToTeam(uint32 SoundID, Team team)
void RewardReputationToTeam(uint32 faction_id, uint32 Reputation, Team team)
BattlegroundPlayerMap const & GetPlayers() const
int32 GetStartDelayTime() const
BattlegroundScoreMap PlayerScores
float GetStartMaxDist() const
bool isBattleground() const
bool UpdatePlayerScore(Player *player, uint32 type, uint32 value, bool doAddHonor=true, Optional< HonorGainSource > source={})
std::vector< WorldPackets::Battleground::BattlegroundPlayerPosition > _playerPositions
virtual void AddPlayer(Player *player, BattlegroundQueueTypeId queueId)
BattlegroundStatus GetStatus() const
bool HasFreeSlots() const
uint32 GetPlayersCountByTeam(Team team) const
void _ProcessOfflineQueue()
uint32 GetAlivePlayersCountByTeam(Team team) const
void RemoveFromBGFreeSlotQueue()
void TeleportPlayerToExploitLocation(Player *player)
void _ProcessProgress(uint32 diff)
uint32 GetFreeSlotsForTeam(Team team) const
virtual bool PreUpdateImpl(uint32)
Pre-update hook.
uint32 GetScriptId() const
virtual void CheckWinConditions()
void EventPlayerLoggedIn(Player *player)
void _CheckSafePositions(uint32 diff)
void _ProcessJoin(uint32 diff)
BattlegroundBracketId GetBracketId() const
std::unordered_set< uint32 > const * _pvpStatIds
Team GetPlayerTeam(ObjectGuid guid) const
uint32 GetBonusHonorFromKill(uint32 kills) const
void UpdatePvpStat(Player *player, uint32 pvpStatId, uint32 value)
uint32 GetMaxLevel() const
uint32 GetElapsedTime() const
void CastSpellOnTeam(uint32 SpellID, Team team)
void SetBracket(PVPDifficultyEntry const *bracketEntry)
uint32 GetPlayersSize() const
void SetBgRaid(Team team, Group *bg_raid)
void SetStartDelayTime(int Time)
virtual void BuildPvPLogDataPacket(WorldPackets::Battleground::PVPMatchStatistics &pvpLogData) const
virtual void RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool SendPacket)
uint32 GetMinPlayers() const
void _ProcessLeave(uint32 diff)
BattlegroundStatus m_Status
uint32 StartMessageIds[BG_STARTING_EVENT_COUNT]
Class used to access individual fields of database query result.
uint64 GetUInt64() const noexcept
uint8 GetMemberGroup(ObjectGuid guid) const
bool AddMember(Player *player)
void ChangeLeader(ObjectGuid guid)
void SetBattlegroundGroup(Battleground *bg)
bool IsMember(ObjectGuid guid) const
bool Create(Player *leader)
void StartCountdown(CountdownTimerType timerType, Seconds duration, Optional< time_t > startTime={ })
LowType GetCounter() const
static ObjectGuid const Empty
std::string ToString() const
bool RewardHonor(Unit *victim, uint32 groupsize, int32 honor=-1, HonorGainSource source=HonorGainSource::Kill)
void SetClientControl(Unit *target, bool allowMove)
void SetBGTeam(Team team)
void SetPlayerFlagEx(PlayerFlagsEx flags)
bool HasPlayerFlagEx(PlayerFlagsEx flags) const
void SetBattlegroundId(uint32 val, BattlegroundTypeId bgTypeId, BattlegroundQueueTypeId queueId)
void SendDirectMessage(WorldPacket const *data) const
static void OfflineResurrect(ObjectGuid const &guid, CharacterDatabaseTransaction trans)
void RemovePlayerFlagEx(PlayerFlagsEx flags)
void SpawnCorpseBones(bool triggerSave=true)
Group * GetOriginalGroup() const
uint32 GetBattlegroundQueueJoinTime(BattlegroundQueueTypeId bgQueueTypeId) const
bool IsMercenaryForBattlegroundQueueType(BattlegroundQueueTypeId bgQueueTypeId) const
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
void DestroyConjuredItems(bool update)
void UnsummonPetTemporaryIfAny()
void RemoveBattlegroundQueueId(BattlegroundQueueTypeId val)
bool GetRandomWinner() const
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
void RemovePet(Pet *pet, PetSaveMode mode, bool returnreagent=false)
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, TeleportToOptions options=TELE_TO_NONE, Optional< uint32 > instanceId={}, uint32 teleportSpellId=0)
bool TeleportToBGEntryPoint()
uint32 GetBattlegroundQueueIndex(BattlegroundQueueTypeId bgQueueTypeId) const
Team GetEffectiveTeam() const
void FailCriteria(CriteriaFailEvent condition, int32 failAsset)
void ResummonPetTemporaryUnSummonedIfAny()
void SetBattlegroundOrBattlefieldRaid(Group *group, int8 subgroup=-1)
ReputationMgr & GetReputationMgr()
void RemoveArenaEnchantments(EnchantmentSlot slot)
void SetRandomWinner(bool isWinner)
void ResurrectPlayer(float restore_percent, bool applySickness=false)
void setUInt32(uint8 index, uint32 value)
void setBool(uint8 index, bool value)
void setUInt64(uint8 index, uint64 value)
void setUInt8(uint8 index, uint8 value)
bool ModifyReputation(FactionEntry const *factionEntry, int32 standing, bool spillOverOnly=false, bool noSpillover=false)
bool HasAttribute(SpellAttr0 attribute) const
Utility class to enable range for loop syntax for multimap.equal_range uses.
void RemoveAurasByType(AuraType auraType, std::function< bool(AuraApplication const *)> const &check, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
void CombatStop(bool includingCast=false, bool mutualPvP=true, bool(*unitFilter)(Unit const *otherUnit)=nullptr)
void RemoveAura(AuraApplicationMap::iterator &i, AuraRemoveMode mode=AURA_REMOVE_BY_DEFAULT)
void AtEndOfEncounter(EncounterType type)
float GetTotalAuraModifier(AuraType auraType) const
bool HasAuraType(AuraType auraType) const
void RemoveAurasWithInterruptFlags(InterruptFlags flag, SpellInfo const *source=nullptr)
float GetTotalAuraModifierByMiscValue(AuraType auraType, int32 misc_value) const
void SetUnitFlag(UnitFlags flags)
void CombatStopWithPets(bool includingCast=false)
constexpr uint32 GetMapId() const
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
std::string const & GetName() const
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
std::vector< BattlegroundPlayerPosition > FlagCarriers
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPackets::Duration< Seconds > Duration
Optional< PVPMatchStatistics > LogData
uint32 BattlemasterListID
WorldPackets::Duration< Seconds > Duration
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * GetRawPacket() const
@ CONFIG_BG_REWARD_LOSER_HONOR_LAST
@ CONFIG_BATTLEGROUND_INVITATION_TYPE
@ CONFIG_BG_REWARD_WINNER_HONOR_FIRST
@ CONFIG_BG_REWARD_LOSER_HONOR_FIRST
@ CONFIG_BG_REWARD_WINNER_HONOR_LAST
@ CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
TC_GAME_API Player * GetPlayer(Map const *, ObjectGuid const &guid)
auto MapGetValuePtr(M &map, typename M::key_type const &key)
uint32 hk_honor_at_level(uint8 level, float multiplier=1.0f)
TC_GAME_API void SetValue(int32 worldStateId, int32 value, bool hidden, Map *map)
BattlegroundQueueTypeId queueTypeId
uint16 BattlemasterListId
uint8 GetMinLevel() const
BattlemasterListEntry const * BattlemasterEntry
uint16 GetMaxPlayersPerTeam() const
std::vector< int32 > MapIDs
WorldSafeLocsEntry const * StartLocation[PVP_TEAMS_COUNT]
uint16 GetMinPlayersPerTeam() const
uint8 GetMaxLevel() const
BattlegroundBracketId GetBracketId() const
constexpr void GetPosition(float &x, float &y) const
constexpr float GetExactDistSq(float x, float y, float z) const
std::vector< PVPMatchPlayerStatistics > Statistics
std::array< int8, 2 > PlayerCount