From a303ba3da33e58bda77fc027a6cc30f925fcb992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viste=28=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=29?= Date: Sat, 16 Jun 2018 19:28:44 +0300 Subject: [PATCH] Core/Arena: fix auto distribute arena points and config option. (#927) --- .../game/Battlegrounds/BattlegroundMgr.cpp | 29 ++++++++++++++----- .../game/Battlegrounds/BattlegroundMgr.h | 3 ++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index fdbbcf4c5..b495597d4 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -43,7 +43,7 @@ /*********************************************************/ BattlegroundMgr::BattlegroundMgr() : randomBgDifficultyEntry(999, 0, 80, 80, 0), m_ArenaTesting(false), m_Testing(false), - m_lastClientVisibleInstanceId(0), m_NextAutoDistributionTime(0), m_NextPeriodicQueueUpdateTime(5*IN_MILLISECONDS) + m_lastClientVisibleInstanceId(0), m_NextAutoDistributionTime(0), m_AutoDistributionTimeChecker(0), m_NextPeriodicQueueUpdateTime(5*IN_MILLISECONDS) { for (uint32 qtype = BATTLEGROUND_QUEUE_NONE; qtype < MAX_BATTLEGROUND_QUEUE_TYPES; ++qtype) m_BattlegroundQueues[qtype].SetBgTypeIdAndArenaType(BGTemplateId(BattlegroundQueueTypeId(qtype)), BGArenaType(BattlegroundQueueTypeId(qtype))); @@ -126,12 +126,18 @@ void BattlegroundMgr::Update(uint32 diff) // arena points auto-distribution if (sWorld->getBoolConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_POINTS)) { - if (sWorld->GetGameTime() > m_NextAutoDistributionTime) + if (m_AutoDistributionTimeChecker < diff) { - sArenaTeamMgr->DistributeArenaPoints(); - m_NextAutoDistributionTime = sWorld->GetNextTimeWithDayAndHour(5, 18); - sWorld->setWorldState(WS_ARENA_DISTRIBUTION_TIME, uint64(m_NextAutoDistributionTime)); + if (time(NULL) > m_NextAutoDistributionTime) + { + sArenaTeamMgr->DistributeArenaPoints(); + m_NextAutoDistributionTime = m_NextAutoDistributionTime + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld->getIntConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS); + sWorld->setWorldState(WS_ARENA_DISTRIBUTION_TIME, uint64(m_NextAutoDistributionTime)); + } + m_AutoDistributionTimeChecker = 600000; // 10 minutes check } + else + m_AutoDistributionTimeChecker -= diff; } } @@ -687,9 +693,16 @@ void BattlegroundMgr::InitAutomaticArenaPointDistribution() return; time_t wstime = time_t(sWorld->getWorldState(WS_ARENA_DISTRIBUTION_TIME)); - m_NextAutoDistributionTime = wstime ? wstime : sWorld->GetNextTimeWithDayAndHour(5, 18); - if (!wstime) - sWorld->setWorldState(WS_ARENA_DISTRIBUTION_TIME, uint64(m_NextAutoDistributionTime)); + time_t curtime = time(NULL); + sLog->outString("AzerothCore Battleground: Initializing Automatic Arena Point Distribution"); + if (wstime < curtime) + { + m_NextAutoDistributionTime = curtime; // reset will be called in the next update + sLog->outString("AzerothCore Battleground: Battleground: Next arena point distribution time in the past, reseting it now."); + } + else + m_NextAutoDistributionTime = wstime; + sLog->outString("AzerothCore Battleground: Automatic Arena Point Distribution initialized."); } void BattlegroundMgr::BuildBattlegroundListPacket(WorldPacket* data, uint64 guid, Player* player, BattlegroundTypeId bgTypeId, uint8 fromWhere) diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.h b/src/server/game/Battlegrounds/BattlegroundMgr.h index b8c5448f1..7f6b58e25 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.h +++ b/src/server/game/Battlegrounds/BattlegroundMgr.h @@ -17,6 +17,8 @@ typedef std::map BattlegroundContainer; typedef UNORDERED_MAP BattleMastersMap; +#define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // how many seconds in day + struct CreateBattlegroundData { BattlegroundTypeId bgTypeId; @@ -146,6 +148,7 @@ class BattlegroundMgr bool m_Testing; uint32 m_lastClientVisibleInstanceId; time_t m_NextAutoDistributionTime; + uint32 m_AutoDistributionTimeChecker; uint32 m_NextPeriodicQueueUpdateTime; BattleMastersMap mBattleMastersMap; };