aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/framework/GameSystem/NGrid.h2
-rw-r--r--src/game/AchievementMgr.cpp12
-rw-r--r--src/game/AuctionHouseBot.cpp13
-rw-r--r--src/game/AuctionHouseHandler.cpp3
-rw-r--r--src/game/AuctionHouseMgr.cpp7
-rw-r--r--src/game/BattleGround.cpp5
-rw-r--r--src/game/BattleGroundMgr.cpp7
-rw-r--r--src/game/CMakeLists.txt2
-rw-r--r--src/game/CalendarHandler.cpp3
-rw-r--r--src/game/CharacterHandler.cpp3
-rw-r--r--src/game/ChatHandler.cpp5
-rw-r--r--src/game/Corpse.cpp3
-rw-r--r--src/game/Corpse.h3
-rw-r--r--src/game/Creature.cpp96
-rw-r--r--src/game/Creature.h26
-rw-r--r--src/game/DestinationHolder.h2
-rw-r--r--src/game/DuelHandler.cpp3
-rw-r--r--src/game/GameEventMgr.cpp15
-rw-r--r--src/game/GameObject.cpp38
-rw-r--r--src/game/GameObject.h17
-rw-r--r--src/game/GuardAI.h2
-rw-r--r--src/game/Guild.cpp21
-rw-r--r--src/game/InstanceSaveMgr.cpp12
-rw-r--r--src/game/Level0.cpp15
-rw-r--r--src/game/Level2.cpp10
-rw-r--r--src/game/Level3.cpp11
-rw-r--r--src/game/Mail.cpp19
-rw-r--r--src/game/Map.cpp6
-rw-r--r--src/game/Map.h2
-rw-r--r--src/game/MiscHandler.cpp11
-rw-r--r--src/game/MovementHandler.cpp3
-rw-r--r--src/game/ObjectMgr.cpp10
-rw-r--r--src/game/Pet.cpp15
-rw-r--r--src/game/PetAI.h2
-rw-r--r--src/game/PetHandler.cpp3
-rw-r--r--src/game/Player.cpp101
-rw-r--r--src/game/Player.h23
-rw-r--r--src/game/QueryHandler.cpp3
-rw-r--r--src/game/RandomMovementGenerator.cpp2
-rw-r--r--src/game/SpellAuras.cpp5
-rw-r--r--src/game/SpellEffects.cpp3
-rw-r--r--src/game/TicketHandler.cpp9
-rw-r--r--src/game/TotemAI.h2
-rw-r--r--src/game/Unit.cpp27
-rw-r--r--src/game/Weather.cpp2
-rw-r--r--src/game/Weather.h2
-rw-r--r--src/game/World.cpp28
-rw-r--r--src/game/World.h8
-rw-r--r--src/game/WorldSession.cpp9
-rw-r--r--src/shared/Timer.h79
-rw-r--r--win/VC90/game.vcproj8
51 files changed, 353 insertions, 365 deletions
diff --git a/src/framework/GameSystem/NGrid.h b/src/framework/GameSystem/NGrid.h
index ecb00e6d6f4..c5e6cb5133d 100644
--- a/src/framework/GameSystem/NGrid.h
+++ b/src/framework/GameSystem/NGrid.h
@@ -26,7 +26,7 @@
#include "GameSystem/Grid.h"
#include "GameSystem/GridReference.h"
-#include "Timer.h"
+#include "TimeMgr.h"
class GridInfo
{
diff --git a/src/game/AchievementMgr.cpp b/src/game/AchievementMgr.cpp
index b7175a09af3..aaacee695fd 100644
--- a/src/game/AchievementMgr.cpp
+++ b/src/game/AchievementMgr.cpp
@@ -34,7 +34,7 @@
#include "Player.h"
#include "ProgressBar.h"
#include "SpellMgr.h"
-
+#include "TimeMgr.h"
#include "MapManager.h"
#include "BattleGround.h"
#include "BattleGroundAB.h"
@@ -552,7 +552,7 @@ void AchievementMgr::LoadFromDB(QueryResult *achievementResult, QueryResult *cri
continue;
}
- if (criteria->timeLimit && time_t(date + criteria->timeLimit) < time(NULL))
+ if (criteria->timeLimit && time_t(date + criteria->timeLimit) < sGameTime.GetGameTime())
continue;
CriteriaProgress& progress = m_criteriaProgress[id];
@@ -612,7 +612,7 @@ void AchievementMgr::SendAchievementEarned(AchievementEntry const* achievement)
WorldPacket data(SMSG_ACHIEVEMENT_EARNED, 8+4+8);
data.append(GetPlayer()->GetPackGUID());
data << uint32(achievement->ID);
- data << uint32(secsToTimeBitFields(time(NULL)));
+ data << uint32(secsToTimeBitFields(sGameTime.GetGameTime()));
data << uint32(0);
GetPlayer()->SendMessageToSetInRange(&data, sWorld.getConfig(CONFIG_LISTEN_RANGE_SAY), true);
}
@@ -1623,7 +1623,7 @@ void AchievementMgr::SetCriteriaProgress(AchievementCriteriaEntry const* entry,
progress = &m_criteriaProgress[entry->ID];
progress->counter = changeValue;
- progress->date = time(NULL);
+ progress->date = sGameTime.GetGameTime();
}
else
{
@@ -1658,7 +1658,7 @@ void AchievementMgr::SetCriteriaProgress(AchievementCriteriaEntry const* entry,
if(entry->timeLimit)
{
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
if(time_t(progress->date + entry->timeLimit) < now)
progress->counter = 1;
@@ -1680,7 +1680,7 @@ void AchievementMgr::CompletedAchievement(AchievementEntry const* achievement)
SendAchievementEarned(achievement);
CompletedAchievementData& ca = m_completedAchievements[achievement->ID];
- ca.date = time(NULL);
+ ca.date = sGameTime.GetGameTime();
ca.changed = true;
// don't insert for ACHIEVEMENT_FLAG_REALM_FIRST_KILL since otherwise only the first group member would reach that achievement
diff --git a/src/game/AuctionHouseBot.cpp b/src/game/AuctionHouseBot.cpp
index 6b86f9de306..556fb88a88f 100644
--- a/src/game/AuctionHouseBot.cpp
+++ b/src/game/AuctionHouseBot.cpp
@@ -1,6 +1,7 @@
#include "ObjectMgr.h"
#include "AuctionHouseMgr.h"
#include "AuctionHouseBot.h"
+#include "TimeMgr.h"
#include <vector>
#include "Policies/SingletonImp.h"
@@ -89,9 +90,9 @@ AuctionHouseBot::AuctionHouseBot()
//End Filters
- _lastrun_a = time(NULL);
- _lastrun_h = time(NULL);
- _lastrun_n = time(NULL);
+ _lastrun_a = sGameTime.GetGameTime();
+ _lastrun_h = sGameTime.GetGameTime();
+ _lastrun_n = sGameTime.GetGameTime();
AllianceConfig = AHBConfig(2);
HordeConfig = AHBConfig(6);
@@ -419,7 +420,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
auctionEntry->bidder = 0;
auctionEntry->bid = 0;
auctionEntry->deposit = dep;
- auctionEntry->expire_time = (time_t) etime + time(NULL);
+ auctionEntry->expire_time = (time_t) etime + sGameTime.GetGameTime();
auctionEntry->auctionHouseEntry = ahEntry;
item->SaveToDB();
item->RemoveFromUpdateQueueOf(AHBplayer);
@@ -695,7 +696,7 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
void AuctionHouseBot::Update()
{
- time_t _newrun = time(NULL);
+ time_t _newrun = sGameTime.GetGameTime();
if ((!AHBSeller) && (!AHBBuyer))
return;
@@ -1506,7 +1507,7 @@ void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char*
{
if (itr->second->owner == AHBplayerGUID)
{
- itr->second->expire_time = sWorld.GetGameTime();
+ itr->second->expire_time = sGameTime.GetGameTime();
uint32 id = itr->second->Id;
uint32 expire_time = itr->second->expire_time;
CharacterDatabase.PExecute("UPDATE auctionhouse SET time = '%u' WHERE id = '%u'", expire_time, id);
diff --git a/src/game/AuctionHouseHandler.cpp b/src/game/AuctionHouseHandler.cpp
index fdfea922c4f..6ff9d7d5f8d 100644
--- a/src/game/AuctionHouseHandler.cpp
+++ b/src/game/AuctionHouseHandler.cpp
@@ -30,6 +30,7 @@
#include "Opcodes.h"
#include "UpdateMask.h"
#include "Util.h"
+#include "TimeMgr.h"
//please DO NOT use iterator++, because it is slower than ++iterator!!!
//post-incrementation is always slower than pre-incrementation !
@@ -271,7 +272,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket & recv_data)
AH->bidder = 0;
AH->bid = 0;
AH->buyout = buyout;
- AH->expire_time = time(NULL) + auction_time;
+ AH->expire_time = sGameTime.GetGameTime() + auction_time;
AH->deposit = deposit;
AH->auctionHouseEntry = auctionHouseEntry;
diff --git a/src/game/AuctionHouseMgr.cpp b/src/game/AuctionHouseMgr.cpp
index b2b5d250b28..129089fd892 100644
--- a/src/game/AuctionHouseMgr.cpp
+++ b/src/game/AuctionHouseMgr.cpp
@@ -32,6 +32,7 @@
#include "Item.h"
#include "Language.h"
#include "Log.h"
+#include "TimeMgr.h"
#include "ProgressBar.h"
#include <vector>
@@ -183,7 +184,7 @@ void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry * auction)
std::ostringstream msgAuctionSalePendingBody;
uint32 auctionCut = auction->GetAuctionCut();
- time_t distrTime = time(NULL) + sWorld.getConfig(CONFIG_MAIL_DELIVERY_DELAY);
+ time_t distrTime = sGameTime.GetGameTime() + sWorld.getConfig(CONFIG_MAIL_DELIVERY_DELAY);
msgAuctionSalePendingBody.width(16);
msgAuctionSalePendingBody << std::right << std::hex << auction->bidder;
@@ -499,7 +500,7 @@ AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTem
void AuctionHouseObject::Update()
{
- time_t curTime = sWorld.GetGameTime();
+ time_t curTime = sGameTime.GetGameTime();
///- Handle expired auctions
// If storage is empty, no need to update. next == NULL in this case.
@@ -683,7 +684,7 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const
data << uint32(bid ? GetAuctionOutBid() : 0);
//minimal outbid
data << uint32(buyout); //auction->buyout
- data << uint32((expire_time-time(NULL))*IN_MILISECONDS);//time left
+ data << uint32((expire_time-sGameTime.GetGameTime())*IN_MILISECONDS);//time left
data << uint64(bidder) ; //auction->bidder current
data << uint32(bid); //current bid
return true;
diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp
index 554f8555627..ec8bccd535f 100644
--- a/src/game/BattleGround.cpp
+++ b/src/game/BattleGround.cpp
@@ -35,6 +35,7 @@
#include "Object.h"
#include "SpellAuras.h"
#include "Util.h"
+#include "TimeMgr.h"
namespace Trinity
{
@@ -259,7 +260,7 @@ void BattleGround::Update(uint32 diff)
BattleGroundPlayerMap::iterator itr = m_Players.find(*(m_OfflineQueue.begin()));
if (itr != m_Players.end())
{
- if (itr->second.OfflineRemoveTime <= sWorld.GetGameTime())
+ if (itr->second.OfflineRemoveTime <= sGameTime.GetGameTime())
{
RemovePlayerAtLeave(itr->first, true, true);// remove player from BG
m_OfflineQueue.pop_front(); // remove from offline queue
@@ -1266,7 +1267,7 @@ void BattleGround::EventPlayerLoggedOut(Player* player)
{
// player is correct pointer, it is checked in WorldSession::LogoutPlayer()
m_OfflineQueue.push_back(player->GetGUID());
- m_Players[player->GetGUID()].OfflineRemoveTime = sWorld.GetGameTime() + MAX_OFFLINE_TIME;
+ m_Players[player->GetGUID()].OfflineRemoveTime = sGameTime.GetGameTime() + MAX_OFFLINE_TIME;
if (GetStatus() == STATUS_IN_PROGRESS)
{
if (isBattleGround())
diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp
index 0853148362f..249243a78f1 100644
--- a/src/game/BattleGroundMgr.cpp
+++ b/src/game/BattleGroundMgr.cpp
@@ -47,6 +47,7 @@
#include "GameEventMgr.h"
#include "ProgressBar.h"
#include "SharedDefines.h"
+#include "TimeMgr.h"
INSTANTIATE_SINGLETON_1( BattleGroundMgr );
@@ -1224,10 +1225,10 @@ void BattleGroundMgr::Update(uint32 diff)
{
if (m_AutoDistributionTimeChecker < diff)
{
- if(time(NULL) > m_NextAutoDistributionTime)
+ if(sGameTime.GetGameTime() > m_NextAutoDistributionTime)
{
DistributeArenaPoints();
- m_NextAutoDistributionTime = time(NULL) + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
+ m_NextAutoDistributionTime = sGameTime.GetGameTime() + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
CharacterDatabase.PExecute("UPDATE saved_variables SET NextArenaPointDistributionTime = '"UI64FMTD"'", m_NextAutoDistributionTime);
}
m_AutoDistributionTimeChecker = 600000; // check 10 minutes
@@ -1805,7 +1806,7 @@ void BattleGroundMgr::InitAutomaticArenaPointDistribution()
if (!result)
{
sLog.outDebug("Battleground: Next arena point distribution time not found in SavedVariables, reseting it now.");
- m_NextAutoDistributionTime = time(NULL) + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
+ m_NextAutoDistributionTime = sGameTime.GetGameTime() + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
CharacterDatabase.PExecute("INSERT INTO saved_variables (NextArenaPointDistributionTime) VALUES ('"UI64FMTD"')", m_NextAutoDistributionTime);
}
else
diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt
index a4d656cf7f6..a4e1e75a330 100644
--- a/src/game/CMakeLists.txt
+++ b/src/game/CMakeLists.txt
@@ -250,6 +250,8 @@ SET(game_STAT_SRCS
TaxiHandler.cpp
TemporarySummon.cpp
TemporarySummon.h
+ TimeMgr.cpp
+ TimeMgr.h
TicketHandler.cpp
Tools.cpp
Tools.h
diff --git a/src/game/CalendarHandler.cpp b/src/game/CalendarHandler.cpp
index 5860f4acaec..1dbf86d69a9 100644
--- a/src/game/CalendarHandler.cpp
+++ b/src/game/CalendarHandler.cpp
@@ -24,12 +24,13 @@
#include "Log.h"
#include "Opcodes.h"
#include "Player.h"
+#include "TimeMgr.h"
void WorldSession::HandleCalendarGetCalendar(WorldPacket &recv_data)
{
sLog.outDebug("WORLD: CMSG_CALENDAR_GET_CALENDAR"); // empty
- time_t cur_time = time(NULL);
+ time_t cur_time = sGameTime.GetGameTime();
WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR,4+4*0+4+4*0+4+4);
diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp
index 3ef302c2f79..4dde49c4ee0 100644
--- a/src/game/CharacterHandler.cpp
+++ b/src/game/CharacterHandler.cpp
@@ -43,6 +43,7 @@
#include "UpdateMask.h"
#include "Util.h"
#include "ScriptCalls.h"
+#include "TimeMgr.h"
class LoginQueryHolder : public SqlQueryHolder
{
@@ -75,7 +76,7 @@ bool LoginQueryHolder::Initialize()
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS, "SELECT a.button,a.action,a.type FROM character_action as a, characters as c WHERE a.guid = c.guid AND a.spec = c.activespec AND a.guid = '%u' ORDER BY button", GUID_LOPART(m_guid));
- res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILCOUNT, "SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD "'", GUID_LOPART(m_guid),(uint64)time(NULL));
+ res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILCOUNT, "SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD "'", GUID_LOPART(m_guid),(uint64)sGameTime.GetGameTime());
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADHOMEBIND, "SELECT map,zone,position_x,position_y,position_z FROM character_homebind WHERE guid = '%u'", GUID_LOPART(m_guid));
diff --git a/src/game/ChatHandler.cpp b/src/game/ChatHandler.cpp
index dd39dd72190..7616394134a 100644
--- a/src/game/ChatHandler.cpp
+++ b/src/game/ChatHandler.cpp
@@ -39,6 +39,7 @@
#include "ScriptCalls.h"
#include "SpellAuras.h"
#include "Util.h"
+#include "TimeMgr.h"
bool WorldSession::processChatmessageFurtherAfterSecurityChecks(std::string& msg, uint32 lang)
{
@@ -166,7 +167,7 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
if (!_player->CanSpeak())
{
- std::string timeStr = secsToTimeString(m_muteTime - time(NULL));
+ std::string timeStr = secsToTimeString(m_muteTime - sGameTime.GetGameTime());
SendNotification(GetTrinityString(LANG_WAIT_BEFORE_SPEAKING),timeStr.c_str());
return;
}
@@ -627,7 +628,7 @@ void WorldSession::HandleTextEmoteOpcode( WorldPacket & recv_data )
if (!GetPlayer()->CanSpeak())
{
- std::string timeStr = secsToTimeString(m_muteTime - time(NULL));
+ std::string timeStr = secsToTimeString(m_muteTime - sGameTime.GetGameTime());
SendNotification(GetTrinityString(LANG_WAIT_BEFORE_SPEAKING),timeStr.c_str());
return;
}
diff --git a/src/game/Corpse.cpp b/src/game/Corpse.cpp
index 1edb478872f..2a8eb0f6795 100644
--- a/src/game/Corpse.cpp
+++ b/src/game/Corpse.cpp
@@ -27,6 +27,7 @@
#include "Opcodes.h"
#include "GossipDef.h"
#include "World.h"
+#include "TimeMgr.h"
Corpse::Corpse(CorpseType type) : WorldObject()
, m_type(type)
@@ -38,7 +39,7 @@ Corpse::Corpse(CorpseType type) : WorldObject()
m_valuesCount = CORPSE_END;
- m_time = time(NULL);
+ m_time = sGameTime.GetGameTime();
lootForBody = false;
diff --git a/src/game/Corpse.h b/src/game/Corpse.h
index e0374a03470..eb0d788ae35 100644
--- a/src/game/Corpse.h
+++ b/src/game/Corpse.h
@@ -25,6 +25,7 @@
#include "Database/DatabaseEnv.h"
#include "GridDefines.h"
#include "LootMgr.h"
+#include "TimeMgr.h"
enum CorpseType
{
@@ -70,7 +71,7 @@ class Corpse : public WorldObject
uint64 const& GetOwnerGUID() const { return GetUInt64Value(CORPSE_FIELD_OWNER); }
time_t const& GetGhostTime() const { return m_time; }
- void ResetGhostTime() { m_time = time(NULL); }
+ void ResetGhostTime() { m_time = sGameTime.GetGameTime(); }
CorpseType GetType() const { return m_type; }
GridPair const& GetGrid() const { return m_grid; }
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 05f2c7e1ec6..98639a97018 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -47,6 +47,7 @@
#include "GameEventMgr.h"
#include "CreatureGroups.h"
#include "Vehicle.h"
+#include "TimeMgr.h"
// apply implementation of the singletons
#include "Policies/SingletonImp.h"
@@ -59,32 +60,40 @@ TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
return NULL;
}
-bool VendorItemData::RemoveItem( uint32 item_id )
+bool VendorItemData::RemoveItem(uint32 item_id)
{
- for (VendorItemList::iterator i = m_items.begin(); i != m_items.end(); ++i )
+ ItemToSlotMap::iterator i = m_itemtoslot.find(item_id);
+ if (i != m_itemtoslot.end())
{
- if((*i)->item==item_id)
- {
- m_items.erase(i);
- return true;
- }
+ m_items.erase(m_items.begin() + i->second);
+
+ //need to recount vendorslot
+ ItemToSlotMap::iterator itr;
+ for (itr = i; itr != m_itemtoslot.end();++itr)
+ itr->second -= 1;
+ //and delete
+ m_itemtoslot.erase(i);
+
+ return true;
}
+
return false;
}
-size_t VendorItemData::FindItemSlot(uint32 item_id) const
+uint8 VendorItemData::FindItemSlot(uint32 item_id) const
{
- for (size_t i = 0; i < m_items.size(); ++i)
- if (m_items[i]->item==item_id)
- return i;
- return m_items.size();
+ ItemToSlotMap::const_iterator i = m_itemtoslot.find(item_id);
+ if (i != m_itemtoslot.end())
+ return i->second;
+
+ return uint8(m_items.size());
}
VendorItem const* VendorItemData::FindItem(uint32 item_id) const
{
- for (VendorItemList::const_iterator i = m_items.begin(); i != m_items.end(); ++i )
- if((*i)->item==item_id)
- return *i;
+ ItemToSlotMap::const_iterator i = m_itemtoslot.find(item_id);
+ if (i != m_itemtoslot.end())
+ return m_items[i->second];
return NULL;
}
@@ -162,6 +171,8 @@ m_creatureInfo(NULL), m_reactState(REACT_AGGRESSIVE), m_formation(NULL)
Creature::~Creature()
{
+ for (VendorItemCounts::iterator itr = m_vendorItemCounts.begin(); itr != m_vendorItemCounts.end(); ++itr)
+ delete itr->second;
m_vendorItemCounts.clear();
if(i_AI)
@@ -240,7 +251,7 @@ void Creature::RemoveCorpse()
if (IsAIEnabled)
AI()->CorpseRemoved(respawnDelay);
- m_respawnTime = time(NULL) + m_respawnDelay;
+ m_respawnTime = sGameTime.GetGameTime() + m_respawnDelay;
float x,y,z,o;
GetRespawnCoord(x, y, z, &o);
@@ -440,7 +451,7 @@ void Creature::Update(uint32 diff)
break;
case DEAD:
{
- if( m_respawnTime <= time(NULL) )
+ if( m_respawnTime <= sGameTime.GetGameTime() )
{
if(!GetLinkedCreatureRespawnTime()) // Can respawn
Respawn();
@@ -451,7 +462,7 @@ void Creature::Update(uint32 diff)
if(targetGuid == m_DBTableGuid) // if linking self, never respawn (check delayed to next day)
SetRespawnTime(DAY);
else
- m_respawnTime = (time(NULL)>GetLinkedCreatureRespawnTime()? time(NULL):GetLinkedCreatureRespawnTime())+urand(5,MINUTE); // else copy time from master and add a little
+ m_respawnTime = (sGameTime.GetGameTime()>GetLinkedCreatureRespawnTime()? sGameTime.GetGameTime():GetLinkedCreatureRespawnTime())+urand(5,MINUTE); // else copy time from master and add a little
SaveRespawnTime(); // also save to DB immediately
}
else
@@ -584,6 +595,11 @@ void Creature::Update(uint32 diff)
}
}
+void Creature::SetRespawnTime(uint32 respawn)
+{
+ m_respawnTime = respawn ? sGameTime.GetGameTime() + respawn : 0;
+}
+
void Creature::RegenerateMana()
{
uint32 curValue = GetPower(POWER_MANA);
@@ -1870,10 +1886,10 @@ void Creature::SaveRespawnTime()
if(isSummon() || !m_DBTableGuid || m_creatureData && !m_creatureData->dbData)
return;
- if(m_respawnTime > time(NULL)) // dead (no corpse)
+ if(m_respawnTime > sGameTime.GetGameTime()) // dead (no corpse)
objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),m_respawnTime);
else if(m_deathTimer > 0) // dead (corpse)
- objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),time(NULL)+m_respawnDelay+m_deathTimer/IN_MILISECONDS);
+ objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),sGameTime.GetGameTime()+m_respawnDelay+m_deathTimer/IN_MILISECONDS);
}
// this should not be called by petAI or
@@ -2062,10 +2078,10 @@ void Creature::AddCreatureSpellCooldown(uint32 spellid)
modOwner->ApplySpellMod(spellid, SPELLMOD_COOLDOWN, cooldown);
if(cooldown)
- _AddCreatureSpellCooldown(spellid, time(NULL) + cooldown/IN_MILISECONDS);
+ _AddCreatureSpellCooldown(spellid, sGameTime.GetGameTime() + cooldown/IN_MILISECONDS);
if(spellInfo->Category)
- _AddCreatureCategoryCooldown(spellInfo->Category, time(NULL));
+ _AddCreatureCategoryCooldown(spellInfo->Category, sGameTime.GetGameTime());
m_GlobalCooldown = spellInfo->StartRecoveryTime;
}
@@ -2081,13 +2097,13 @@ bool Creature::HasCategoryCooldown(uint32 spell_id) const
return true;
CreatureSpellCooldowns::const_iterator itr = m_CreatureCategoryCooldowns.find(spellInfo->Category);
- return(itr != m_CreatureCategoryCooldowns.end() && time_t(itr->second + (spellInfo->CategoryRecoveryTime / IN_MILISECONDS)) > time(NULL));
+ return(itr != m_CreatureCategoryCooldowns.end() && time_t(itr->second + (spellInfo->CategoryRecoveryTime / IN_MILISECONDS)) > sGameTime.GetGameTime());
}
bool Creature::HasSpellCooldown(uint32 spell_id) const
{
CreatureSpellCooldowns::const_iterator itr = m_CreatureSpellCooldowns.find(spell_id);
- return (itr != m_CreatureSpellCooldowns.end() && itr->second > time(NULL)) || HasCategoryCooldown(spell_id);
+ return (itr != m_CreatureSpellCooldowns.end() && itr->second > sGameTime.GetGameTime()) || HasCategoryCooldown(spell_id);
}
bool Creature::HasSpell(uint32 spellID) const
@@ -2101,7 +2117,7 @@ bool Creature::HasSpell(uint32 spellID) const
time_t Creature::GetRespawnTimeEx() const
{
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
if(m_respawnTime > now) // dead (no corpse)
return m_respawnTime;
else if(m_deathTimer > 0) // dead (corpse)
@@ -2196,17 +2212,13 @@ uint32 Creature::GetVendorItemCurrentCount(VendorItem const* vItem)
if(!vItem->maxcount)
return vItem->maxcount;
- VendorItemCounts::iterator itr = m_vendorItemCounts.begin();
- for (; itr != m_vendorItemCounts.end(); ++itr)
- if(itr->itemId==vItem->item)
- break;
-
+ VendorItemCounts::iterator itr = m_vendorItemCounts.find(vItem->item);
if(itr == m_vendorItemCounts.end())
return vItem->maxcount;
- VendorItemCount* vCount = &*itr;
+ VendorItemCount* vCount = itr->second;
- time_t ptime = time(NULL);
+ time_t ptime = sGameTime.GetGameTime();
if( vCount->lastIncrementTime + vItem->incrtime <= ptime )
{
@@ -2215,6 +2227,7 @@ uint32 Creature::GetVendorItemCurrentCount(VendorItem const* vItem)
uint32 diff = uint32((ptime - vCount->lastIncrementTime)/vItem->incrtime);
if((vCount->count + diff * pProto->BuyCount) >= vItem->maxcount )
{
+ delete itr->second;
m_vendorItemCounts.erase(itr);
return vItem->maxcount;
}
@@ -2231,21 +2244,17 @@ uint32 Creature::UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 us
if(!vItem->maxcount)
return 0;
- VendorItemCounts::iterator itr = m_vendorItemCounts.begin();
- for (; itr != m_vendorItemCounts.end(); ++itr)
- if(itr->itemId==vItem->item)
- break;
-
+ VendorItemCounts::iterator itr = m_vendorItemCounts.find(vItem->item);
if(itr == m_vendorItemCounts.end())
{
- int32 new_count = vItem->maxcount > used_count ? vItem->maxcount-used_count : 0;
- m_vendorItemCounts.push_back(VendorItemCount(vItem->item,new_count));
+ uint32 new_count = vItem->maxcount > used_count ? vItem->maxcount-used_count : 0;
+ m_vendorItemCounts[vItem->item] = new VendorItemCount(new_count);
return new_count;
}
- VendorItemCount* vCount = &*itr;
+ VendorItemCount* vCount = itr->second;
- time_t ptime = time(NULL);
+ time_t ptime = sGameTime.GetGameTime();
if( vCount->lastIncrementTime + vItem->incrtime <= ptime )
{
@@ -2258,7 +2267,7 @@ uint32 Creature::UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 us
vCount->count = vItem->maxcount;
}
- vCount->count = vCount->count > used_count ? vCount->count-used_count : 0;
+ vCount->count = vCount->count > used_count ? vCount->count - used_count : 0;
vCount->lastIncrementTime = ptime;
return vCount->count;
}
@@ -2322,3 +2331,6 @@ BaseHealthManaPair Creature::GenerateHealthMana()
{
return objmgr.GenerateCreatureStats(getLevel(), GetCreatureInfo());
}
+
+VendorItemCount::VendorItemCount() : count(0), lastIncrementTime(sGameTime.GetGameTime()) {}
+VendorItemCount::VendorItemCount(uint32 _count) : count(_count), lastIncrementTime(sGameTime.GetGameTime()) {}
diff --git a/src/game/Creature.h b/src/game/Creature.h
index 6470af4bb71..7209388c032 100644
--- a/src/game/Creature.h
+++ b/src/game/Creature.h
@@ -28,6 +28,7 @@
#include "LootMgr.h"
#include "Database/DatabaseEnv.h"
#include "Cell.h"
+#include "TimeMgr.h"
#include <list>
@@ -318,45 +319,50 @@ struct VendorItem
uint32 ExtendedCost;
};
typedef std::vector<VendorItem*> VendorItemList;
+typedef std::map<uint32, uint8> ItemToSlotMap;
struct VendorItemData
{
VendorItemList m_items;
+ ItemToSlotMap m_itemtoslot;
- VendorItem* GetItem(uint32 slot) const
+ VendorItem* GetItem(uint8 slot) const
{
- if(slot>=m_items.size()) return NULL;
+ if(slot >= uint8(m_items.size()))
+ return NULL;
return m_items[slot];
}
+
bool Empty() const { return m_items.empty(); }
- uint8 GetItemCount() const { return m_items.size(); }
- void AddItem( uint32 item, int32 maxcount, uint32 ptime, uint32 ExtendedCost)
+ uint8 GetItemCount() const { return uint8(m_items.size()); }
+ void AddItem(uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, uint8 vendorslot)
{
m_items.push_back(new VendorItem(item, maxcount, ptime, ExtendedCost));
+ m_itemtoslot[item] = vendorslot;
}
bool RemoveItem( uint32 item_id );
VendorItem const* FindItem(uint32 item_id) const;
- size_t FindItemSlot(uint32 item_id) const;
+ uint8 FindItemSlot(uint32 item_id) const;
void Clear()
{
for (VendorItemList::const_iterator itr = m_items.begin(); itr != m_items.end(); ++itr)
delete (*itr);
m_items.clear();
+ m_itemtoslot.clear();
}
};
struct VendorItemCount
{
- explicit VendorItemCount(uint32 _item, uint32 _count)
- : itemId(_item), count(_count), lastIncrementTime(time(NULL)) {}
+ VendorItemCount();
+ VendorItemCount(uint32 _count);
- uint32 itemId;
uint32 count;
time_t lastIncrementTime;
};
-typedef std::list<VendorItemCount> VendorItemCounts;
+typedef std::map<uint32, VendorItemCount*> VendorItemCounts;
struct TrainerSpell
{
@@ -583,7 +589,7 @@ class TRINITY_DLL_SPEC Creature : public Unit
time_t const& GetRespawnTime() const { return m_respawnTime; }
time_t GetRespawnTimeEx() const;
- void SetRespawnTime(uint32 respawn) { m_respawnTime = respawn ? time(NULL) + respawn : 0; }
+ void SetRespawnTime(uint32 respawn);
void Respawn(bool force = false);
void SaveRespawnTime();
diff --git a/src/game/DestinationHolder.h b/src/game/DestinationHolder.h
index e41ced5980a..4e93d1a2754 100644
--- a/src/game/DestinationHolder.h
+++ b/src/game/DestinationHolder.h
@@ -22,7 +22,7 @@
#define TRINITY_DESTINATION_HOLDER_H
#include "Platform/Define.h"
-#include "Timer.h"
+#include "TimeMgr.h"
class WorldObject;
class Map;
diff --git a/src/game/DuelHandler.cpp b/src/game/DuelHandler.cpp
index d9854d900c8..8da8787ab8b 100644
--- a/src/game/DuelHandler.cpp
+++ b/src/game/DuelHandler.cpp
@@ -25,6 +25,7 @@
#include "Opcodes.h"
#include "UpdateData.h"
#include "Player.h"
+#include "TimeMgr.h"
void WorldSession::HandleDuelAcceptedOpcode(WorldPacket& recvPacket)
{
@@ -47,7 +48,7 @@ void WorldSession::HandleDuelAcceptedOpcode(WorldPacket& recvPacket)
DEBUG_LOG("Player 1 is: %u (%s)", pl->GetGUIDLow(),pl->GetName());
DEBUG_LOG("Player 2 is: %u (%s)", plTarget->GetGUIDLow(),plTarget->GetName());
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
pl->duel->startTimer = now;
plTarget->duel->startTimer = now;
diff --git a/src/game/GameEventMgr.cpp b/src/game/GameEventMgr.cpp
index c48a0f3f892..735ee67ae01 100644
--- a/src/game/GameEventMgr.cpp
+++ b/src/game/GameEventMgr.cpp
@@ -30,6 +30,7 @@
#include "GossipDef.h"
#include "Player.h"
#include "BattleGroundMgr.h"
+#include "TimeMgr.h"
INSTANTIATE_SINGLETON_1(GameEventMgr);
@@ -40,7 +41,7 @@ bool GameEventMgr::CheckOneGameEvent(uint16 entry) const
default:
case GAMEEVENT_NORMAL:
{
- time_t currenttime = time(NULL);
+ time_t currenttime = sGameTime.GetGameTime();
// Get the event information
return mGameEvent[entry].start < currenttime
&& currenttime < mGameEvent[entry].end
@@ -57,7 +58,7 @@ bool GameEventMgr::CheckOneGameEvent(uint16 entry) const
// if inactive world event, check the prerequisite events
case GAMEEVENT_WORLD_INACTIVE:
{
- time_t currenttime = time(NULL);
+ time_t currenttime = sGameTime.GetGameTime();
for (std::set<uint16>::const_iterator itr = mGameEvent[entry].prerequisite_events.begin(); itr != mGameEvent[entry].prerequisite_events.end(); ++itr)
{
if( (mGameEvent[*itr].state != GAMEEVENT_WORLD_NEXTPHASE && mGameEvent[*itr].state != GAMEEVENT_WORLD_FINISHED) || // if prereq not in nextphase or finished state, then can't start this one
@@ -73,7 +74,7 @@ bool GameEventMgr::CheckOneGameEvent(uint16 entry) const
uint32 GameEventMgr::NextCheck(uint16 entry) const
{
- time_t currenttime = time(NULL);
+ time_t currenttime = sGameTime.GetGameTime();
// for NEXTPHASE state world events, return the delay to start the next event, so the followup event will be checked correctly
if ((mGameEvent[entry].state == GAMEEVENT_WORLD_NEXTPHASE || mGameEvent[entry].state == GAMEEVENT_WORLD_FINISHED) && mGameEvent[entry].nextstart >= currenttime)
@@ -128,7 +129,7 @@ bool GameEventMgr::StartEvent( uint16 event_id, bool overwrite )
ApplyNewEvent(event_id);
if(overwrite)
{
- mGameEvent[event_id].start = time(NULL);
+ mGameEvent[event_id].start = sGameTime.GetGameTime();
if(mGameEvent[event_id].end <= mGameEvent[event_id].start)
mGameEvent[event_id].end = mGameEvent[event_id].start+mGameEvent[event_id].length;
}
@@ -168,7 +169,7 @@ void GameEventMgr::StopEvent( uint16 event_id, bool overwrite )
if(overwrite && !serverwide_evt)
{
- mGameEvent[event_id].start = time(NULL) - mGameEvent[event_id].length * MINUTE;
+ mGameEvent[event_id].start = sGameTime.GetGameTime() - mGameEvent[event_id].length * MINUTE;
if(mGameEvent[event_id].end <= mGameEvent[event_id].start)
mGameEvent[event_id].end = mGameEvent[event_id].start+mGameEvent[event_id].length;
}
@@ -1045,7 +1046,7 @@ uint32 GameEventMgr::Initialize() // return the next e
uint32 GameEventMgr::Update() // return the next event delay in ms
{
- time_t currenttime = time(NULL);
+ time_t currenttime = sGameTime.GetGameTime();
uint32 nextEventDelay = max_ge_check_delay; // 1 day
uint32 calcDelay;
std::set<uint16> activate, deactivate;
@@ -1598,7 +1599,7 @@ bool GameEventMgr::CheckOneGameEventConditions(uint16 event_id)
// set the followup events' start time
if(!mGameEvent[event_id].nextstart)
{
- time_t currenttime = time(NULL);
+ time_t currenttime = sGameTime.GetGameTime();
mGameEvent[event_id].nextstart = currenttime + mGameEvent[event_id].length * 60;
}
return true;
diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp
index e3794de8a8e..1c9e80ee84d 100644
--- a/src/game/GameObject.cpp
+++ b/src/game/GameObject.cpp
@@ -39,6 +39,7 @@
#include "Util.h"
#include "OutdoorPvPMgr.h"
#include "BattleGroundAV.h"
+#include "TimeMgr.h"
GameObject::GameObject() : WorldObject(), m_goValue(new GameObjectValue)
{
@@ -225,14 +226,14 @@ void GameObject::Update(uint32 /*p_time*/)
// Arming Time for GAMEOBJECT_TYPE_TRAP (6)
Unit* owner = GetOwner();
if (owner && owner->isInCombat())
- m_cooldownTime = time(NULL) + GetGOInfo()->trap.startDelay;
+ m_cooldownTime = sGameTime.GetGameTime() + GetGOInfo()->trap.startDelay;
m_lootState = GO_READY;
break;
}
case GAMEOBJECT_TYPE_FISHINGNODE:
{
// fishing code (bobber ready)
- if( time(NULL) > m_respawnTime - FISHING_BOBBER_READY_TIME )
+ if( sGameTime.GetGameTime() > m_respawnTime - FISHING_BOBBER_READY_TIME )
{
// splash bobber (bobber ready now)
Unit* caster = GetOwner();
@@ -264,7 +265,7 @@ void GameObject::Update(uint32 /*p_time*/)
{
if (m_respawnTime > 0) // timer on
{
- if (m_respawnTime <= time(NULL)) // timer expired
+ if (m_respawnTime <= sGameTime.GetGameTime()) // timer expired
{
m_respawnTime = 0;
m_SkillupList.clear();
@@ -316,7 +317,7 @@ void GameObject::Update(uint32 /*p_time*/)
GameObjectInfo const* goInfo = GetGOInfo();
if(goInfo->type == GAMEOBJECT_TYPE_TRAP)
{
- if(m_cooldownTime >= time(NULL))
+ if(m_cooldownTime >= sGameTime.GetGameTime())
return;
// traps
@@ -370,7 +371,7 @@ void GameObject::Update(uint32 /*p_time*/)
if(goInfo->trap.spellId)
CastSpell(ok, goInfo->trap.spellId);
- m_cooldownTime = time(NULL) + 4; // 4 seconds
+ m_cooldownTime = sGameTime.GetGameTime() + 4; // 4 seconds
// count charges
//if(goInfo->trap.charges > 0)
@@ -406,7 +407,7 @@ void GameObject::Update(uint32 /*p_time*/)
{
case GAMEOBJECT_TYPE_DOOR:
case GAMEOBJECT_TYPE_BUTTON:
- if (GetGOInfo()->GetAutoCloseTime() && (m_cooldownTime < time(NULL)))
+ if (GetGOInfo()->GetAutoCloseTime() && (m_cooldownTime < sGameTime.GetGameTime()))
ResetDoorOrButton();
break;
default: break;
@@ -470,7 +471,7 @@ void GameObject::Update(uint32 /*p_time*/)
return;
}
- m_respawnTime = time(NULL) + m_respawnDelayTime;
+ m_respawnTime = sGameTime.GetGameTime() + m_respawnDelayTime;
// if option not set then object will be saved at grid unload
if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY))
@@ -651,7 +652,7 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
m_respawnTime = objmgr.GetGORespawnTime(m_DBTableGuid, map->GetInstanceId());
// ready to respawn
- if(m_respawnTime && m_respawnTime <= time(NULL))
+ if(m_respawnTime && m_respawnTime <= sGameTime.GetGameTime())
{
m_respawnTime = 0;
objmgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
@@ -735,7 +736,7 @@ Unit* GameObject::GetOwner(bool inWorld) const
void GameObject::SaveRespawnTime()
{
- if(m_goData && m_goData->dbData && m_respawnTime > time(NULL) && m_spawnedByDefault)
+ if(m_goData && m_goData->dbData && m_respawnTime > sGameTime.GetGameTime() && m_spawnedByDefault)
objmgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),m_respawnTime);
}
@@ -791,11 +792,26 @@ bool GameObject::canDetectTrap(Player const* u, float distance) const
return distance < visibleDistance;
}
+time_t GameObject::GetRespawnTimeEx() const
+{
+ time_t now = sGameTime.GetGameTime();
+ if(m_respawnTime > now)
+ return m_respawnTime;
+ else
+ return now;
+}
+
+void GameObject::SetRespawnTime(int32 respawn)
+{
+ m_respawnTime = respawn > 0 ? sGameTime.GetGameTime() + respawn : 0;
+ m_respawnDelayTime = respawn > 0 ? respawn : 0;
+}
+
void GameObject::Respawn()
{
if(m_spawnedByDefault && m_respawnTime > 0)
{
- m_respawnTime = time(NULL);
+ m_respawnTime = sGameTime.GetGameTime();
objmgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
}
}
@@ -920,7 +936,7 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f
SwitchDoorOrButton(true,alternative);
SetLootState(GO_ACTIVATED);
- m_cooldownTime = time(NULL) + time_to_restore;
+ m_cooldownTime = sGameTime.GetGameTime() + time_to_restore;
}
void GameObject::SetGoArtKit(uint8 kit)
diff --git a/src/game/GameObject.h b/src/game/GameObject.h
index 358af95a9be..b6efbecd690 100644
--- a/src/game/GameObject.h
+++ b/src/game/GameObject.h
@@ -25,6 +25,7 @@
#include "SharedDefines.h"
#include "Object.h"
#include "LootMgr.h"
+#include "TimeMgr.h"
#include "Database/DatabaseEnv.h"
// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform
@@ -640,20 +641,10 @@ class TRINITY_DLL_SPEC GameObject : public WorldObject
uint32 GetSpellId() const { return m_spellId;}
time_t GetRespawnTime() const { return m_respawnTime; }
- time_t GetRespawnTimeEx() const
- {
- time_t now = time(NULL);
- if(m_respawnTime > now)
- return m_respawnTime;
- else
- return now;
- }
+ time_t GetRespawnTimeEx() const;
+
+ void SetRespawnTime(int32 respawn);
- void SetRespawnTime(int32 respawn)
- {
- m_respawnTime = respawn > 0 ? time(NULL) + respawn : 0;
- m_respawnDelayTime = respawn > 0 ? respawn : 0;
- }
void Respawn();
bool isSpawned() const
{
diff --git a/src/game/GuardAI.h b/src/game/GuardAI.h
index db1bfe0229d..70b5c5bf3de 100644
--- a/src/game/GuardAI.h
+++ b/src/game/GuardAI.h
@@ -22,7 +22,7 @@
#define TRINITY_GUARDAI_H
#include "CreatureAI.h"
-#include "Timer.h"
+#include "TimeMgr.h"
class Creature;
diff --git a/src/game/Guild.cpp b/src/game/Guild.cpp
index 9359fbf5487..b0d09627c17 100644
--- a/src/game/Guild.cpp
+++ b/src/game/Guild.cpp
@@ -30,6 +30,7 @@
#include "Util.h"
#include "Language.h"
#include "World.h"
+#include "TimeMgr.h"
#include "Config/ConfigEnv.h"
Guild::Guild()
@@ -168,7 +169,7 @@ bool Guild::AddMember(uint64 plGuid, uint32 plRank)
newmember.RankId = plRank;
newmember.OFFnote = (std::string)"";
newmember.Pnote = (std::string)"";
- newmember.LogoutTime = time(NULL);
+ newmember.LogoutTime = sGameTime.GetGameTime();
newmember.BankResetTimeMoney = 0; // this will force update at first query
for (uint8 i = 0; i < GUILD_BANK_MAX_TABS; ++i)
newmember.BankResetTimeTab[i] = 0;
@@ -772,7 +773,7 @@ void Guild::Roster(WorldSession *session /*= NULL*/)
data << uint8(itr->second.Class);
data << uint8(0); // new 2.4.0
data << uint32(itr->second.ZoneId);
- data << float(float(time(NULL)-itr->second.LogoutTime) / DAY);
+ data << float(float(sGameTime.GetGameTime()-itr->second.LogoutTime) / DAY);
data << itr->second.Pnote;
data << itr->second.OFFnote;
}
@@ -827,7 +828,7 @@ void Guild::UpdateLogoutTime(uint64 guid)
if (itr == members.end())
return;
- itr->second.LogoutTime = time(NULL);
+ itr->second.LogoutTime = sGameTime.GetGameTime();
if (m_OnlineMembers > 0)
--m_OnlineMembers;
@@ -865,7 +866,7 @@ void Guild::DisplayGuildEventLog(WorldSession *session)
if (itr->EventType == GUILD_EVENT_LOG_PROMOTE_PLAYER || itr->EventType == GUILD_EVENT_LOG_DEMOTE_PLAYER)
data << uint8(itr->NewRank);
// Event timestamp
- data << uint32(time(NULL)-itr->TimeStamp);
+ data << uint32(sGameTime.GetGameTime()-itr->TimeStamp);
}
session->SendPacket(&data);
sLog.outDebug("WORLD: Sent (MSG_GUILD_EVENT_LOG_QUERY)");
@@ -933,7 +934,7 @@ void Guild::LogGuildEvent(uint8 EventType, uint32 PlayerGuid1, uint32 PlayerGuid
NewEvent.PlayerGuid1 = PlayerGuid1;
NewEvent.PlayerGuid2 = PlayerGuid2;
NewEvent.NewRank = NewRank;
- NewEvent.TimeStamp = uint32(time(NULL));
+ NewEvent.TimeStamp = uint32(sGameTime.GetGameTime());
// Count new LogGuid
m_GuildEventLogNextGuid = (m_GuildEventLogNextGuid + 1) % sWorld.getConfig(CONFIG_GUILD_EVENT_LOG_COUNT);
// Check max records limit
@@ -1346,7 +1347,7 @@ uint32 Guild::GetMemberSlotWithdrawRem(uint32 LowGuid, uint8 TabId)
if ((GetBankRights(itr->second.RankId,TabId) & GUILD_BANK_RIGHT_VIEW_TAB) != GUILD_BANK_RIGHT_VIEW_TAB)
return 0;
- uint32 curTime = uint32(time(NULL)/MINUTE);
+ uint32 curTime = uint32(sGameTime.GetGameTime()/MINUTE);
if (curTime - itr->second.BankResetTimeTab[TabId] >= 24*HOUR/MINUTE)
{
itr->second.BankResetTimeTab[TabId] = curTime;
@@ -1366,7 +1367,7 @@ uint32 Guild::GetMemberMoneyWithdrawRem(uint32 LowGuid)
if (itr->second.RankId == GR_GUILDMASTER)
return WITHDRAW_MONEY_UNLIMITED;
- uint32 curTime = uint32(time(NULL)/MINUTE); // minutes
+ uint32 curTime = uint32(sGameTime.GetGameTime()/MINUTE); // minutes
// 24 hours
if (curTime > itr->second.BankResetTimeMoney + 24*HOUR/MINUTE)
{
@@ -1600,7 +1601,7 @@ void Guild::DisplayGuildBankLogs(WorldSession *session, uint8 TabId)
if (itr->EventType == GUILD_BANK_LOG_MOVE_ITEM || itr->EventType == GUILD_BANK_LOG_MOVE_ITEM2)
data << uint8(itr->DestTabId); // moved tab
}
- data << uint32(time(NULL) - itr->TimeStamp);
+ data << uint32(sGameTime.GetGameTime() - itr->TimeStamp);
}
session->SendPacket(&data);
}
@@ -1630,7 +1631,7 @@ void Guild::DisplayGuildBankLogs(WorldSession *session, uint8 TabId)
if (itr->EventType == GUILD_BANK_LOG_MOVE_ITEM || itr->EventType == GUILD_BANK_LOG_MOVE_ITEM2)
data << uint8(itr->DestTabId); // moved tab
}
- data << uint32(time(NULL) - itr->TimeStamp);
+ data << uint32(sGameTime.GetGameTime() - itr->TimeStamp);
}
session->SendPacket(&data);
}
@@ -1646,7 +1647,7 @@ void Guild::LogBankEvent(uint8 EventType, uint8 TabId, uint32 PlayerGuidLow, uin
NewEvent.ItemOrMoney = ItemOrMoney;
NewEvent.ItemStackCount = ItemStackCount;
NewEvent.DestTabId = DestTabId;
- NewEvent.TimeStamp = uint32(time(NULL));
+ NewEvent.TimeStamp = uint32(sGameTime.GetGameTime());
//add new event to the end of event list
uint32 currentTabId = TabId;
diff --git a/src/game/InstanceSaveMgr.cpp b/src/game/InstanceSaveMgr.cpp
index a60df7c4f91..3c432d6cba6 100644
--- a/src/game/InstanceSaveMgr.cpp
+++ b/src/game/InstanceSaveMgr.cpp
@@ -31,7 +31,6 @@
#include "MapManager.h"
#include "MapInstanced.h"
#include "InstanceSaveMgr.h"
-#include "Timer.h"
#include "GridNotifiersImpl.h"
#include "Config/ConfigEnv.h"
#include "Transports.h"
@@ -39,6 +38,7 @@
#include "World.h"
#include "Group.h"
#include "InstanceData.h"
+#include "TimeMgr.h"
#include "ProgressBar.h"
#include "Policies/Singleton.h"
#include "Policies/SingletonImp.h"
@@ -109,7 +109,7 @@ InstanceSave* InstanceSaveManager::AddInstanceSave(uint32 mapId, uint32 instance
resetTime = GetResetTimeFor(mapId,difficulty);
else
{
- resetTime = time(NULL) + 2 * HOUR;
+ resetTime = sGameTime.GetGameTime() + 2 * HOUR;
// normally this will be removed soon after in InstanceMap::Add, prevent error
ScheduleReset(true, resetTime, InstResetEvent(0, mapId, difficulty, instanceId));
}
@@ -259,7 +259,7 @@ void InstanceSaveManager::_DelHelper(DatabaseType &db, const char *fields, const
void InstanceSaveManager::CleanupInstances()
{
- uint64 now = (uint64)time(NULL);
+ uint64 now = (uint64)sGameTime.GetGameTime();
barGoLink bar(2);
bar.step();
@@ -406,7 +406,7 @@ void InstanceSaveManager::PackInstances()
void InstanceSaveManager::LoadResetTimes()
{
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
time_t today = (now / DAY) * DAY;
// NOTE: Use DirectPExecute for tables that will be queried later
@@ -571,7 +571,7 @@ void InstanceSaveManager::ScheduleReset(bool add, time_t time, InstResetEvent ev
void InstanceSaveManager::Update()
{
- time_t now = time(NULL), t;
+ time_t now = sGameTime.GetGameTime(), t;
while(!m_resetTimeQueue.empty() && (t = m_resetTimeQueue.begin()->first) < now)
{
InstResetEvent &event = m_resetTimeQueue.begin()->second;
@@ -643,7 +643,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b
if (!mapEntry->Instanceable())
return;
- uint64 now = (uint64)time(NULL);
+ uint64 now = (uint64)sGameTime.GetGameTime();
if(!warn)
{
diff --git a/src/game/Level0.cpp b/src/game/Level0.cpp
index cdfa3517bfa..820478bee8e 100644
--- a/src/game/Level0.cpp
+++ b/src/game/Level0.cpp
@@ -30,6 +30,7 @@
#include "SystemConfig.h"
#include "revision.h"
#include "Util.h"
+#include "TimeMgr.h"
bool ChatHandler::HandleHelpCommand(const char* args)
{
@@ -99,22 +100,14 @@ bool ChatHandler::HandleServerInfoCommand(const char* /*args*/)
uint32 queuedClientsNum = sWorld.GetQueuedSessionCount();
uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount();
uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount();
- std::string uptime = secsToTimeString(sWorld.GetUptime());
+ std::string str = secsToTimeString(sGameTime.GetUptime());
uint32 updateTime = sWorld.GetUpdateTime();
PSendSysMessage(_FULLVERSION);
- //if(m_session)
- // full = _FULLVERSION(REVISION_DATE,REVISION_TIME,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
- //else
- // full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_ID);
-
- //SendSysMessage(full);
- //PSendSysMessage(LANG_USING_SCRIPT_LIB,sWorld.GetScriptsVersion());
- //PSendSysMessage(LANG_USING_WORLD_DB,sWorld.GetDBVersion());
- //PSendSysMessage(LANG_USING_EVENT_AI,sWorld.GetCreatureEventAIVersion());
+
PSendSysMessage(LANG_CONNECTED_PLAYERS, PlayersNum, MaxPlayersNum);
PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
- PSendSysMessage(LANG_UPTIME, uptime.c_str());
+ PSendSysMessage(LANG_UPTIME, str.c_str());
PSendSysMessage("Update time diff: %u.", updateTime);
return true;
diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp
index dc9d84bf4c8..106c573dc35 100644
--- a/src/game/Level2.cpp
+++ b/src/game/Level2.cpp
@@ -42,7 +42,7 @@
#include "GlobalEvents.h"
#include "OutdoorPvPWG.h"
#include "OutdoorPvPMgr.h"
-
+#include "TimeMgr.h"
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
#include "CreatureGroups.h"
@@ -79,7 +79,7 @@ bool ChatHandler::HandleMuteCommand(const char* args)
if(HasLowerSecurity (target,target_guid,true))
return false;
- time_t mutetime = time(NULL) + notspeaktime*60;
+ time_t mutetime = sGameTime.GetGameTime() + notspeaktime*60;
if (target)
target->GetSession()->m_muteTime = mutetime;
@@ -536,7 +536,7 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args)
if(target)
{
- int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
+ int32 curRespawnDelay = target->GetRespawnTimeEx()-sGameTime.GetGameTime();
if(curRespawnDelay < 0)
curRespawnDelay = 0;
@@ -3502,8 +3502,8 @@ bool ChatHandler::HandleEventInfoCommand(const char* args)
std::string endTimeStr = TimeToTimestampStr(eventData.end);
uint32 delay = gameeventmgr.NextCheck(event_id);
- time_t nextTime = time(NULL)+delay;
- std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(NULL)+delay) : "-";
+ time_t nextTime = sGameTime.GetGameTime()+delay;
+ std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(sGameTime.GetGameTime()+delay) : "-";
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE);
std::string lengthStr = secsToTimeString(eventData.length * MINUTE);
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp
index 540bd0d8586..854ccc7e67a 100644
--- a/src/game/Level3.cpp
+++ b/src/game/Level3.cpp
@@ -55,6 +55,7 @@
#include "AuctionHouseBot.h"
#include "CreatureEventAIMgr.h"
#include "DBCEnums.h"
+#include "TimeMgr.h"
bool ChatHandler::HandleAHBotOptionsCommand(const char *args)
{
@@ -4614,7 +4615,7 @@ bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
uint32 Entry = target->GetEntry();
CreatureInfo const* cInfo = target->GetCreatureInfo();
- int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
+ int32 curRespawnDelay = target->GetRespawnTimeEx()-sGameTime.GetGameTime();
if(curRespawnDelay < 0)
curRespawnDelay = 0;
std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
@@ -5974,7 +5975,7 @@ bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
time_t unbandate = time_t(fields[3].GetUInt64());
bool active = false;
- if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
+ if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= sGameTime.GetGameTime()) )
active = true;
bool permanent = (fields[1].GetUInt64() == (uint64)0);
std::string bantime = permanent?GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
@@ -6824,7 +6825,7 @@ bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
for (Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
{
InstanceSave *save = itr->second.save;
- std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
+ std::string timeleft = GetTimeString(save->GetResetTime() - sGameTime.GetGameTime());
PSendSysMessage("map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
counter++;
}
@@ -6840,7 +6841,7 @@ bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
for (Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
{
InstanceSave *save = itr->second.save;
- std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
+ std::string timeleft = GetTimeString(save->GetResetTime() - sGameTime.GetGameTime());
PSendSysMessage("map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str()); counter++;
}
}
@@ -6869,7 +6870,7 @@ bool ChatHandler::HandleInstanceUnbindCommand(const char *args)
if(itr->first != player->GetMapId())
{
InstanceSave *save = itr->second.save;
- std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
+ std::string timeleft = GetTimeString(save->GetResetTime() - sGameTime.GetGameTime());
PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
player->UnbindInstance(itr, Difficulty(i));
counter++;
diff --git a/src/game/Mail.cpp b/src/game/Mail.cpp
index 961a12332e9..d4c4d574591 100644
--- a/src/game/Mail.cpp
+++ b/src/game/Mail.cpp
@@ -34,6 +34,7 @@
#include "BattleGroundMgr.h"
#include "Item.h"
#include "AuctionHouseMgr.h"
+#include "TimeMgr.h"
enum MailShowFlags
{
@@ -283,7 +284,7 @@ void WorldSession::HandleMailMarkAsRead(WorldPacket & recv_data )
if (pl->unReadMails)
--pl->unReadMails;
m->checked = m->checked | MAIL_CHECK_MASK_READ;
- // m->expire_time = time(NULL) + (30 * DAY); // Expire time do not change at reading mail
+ // m->expire_time = sGameTime.GetGameTime() + (30 * DAY); // Expire time do not change at reading mail
pl->m_mailsUpdated = true;
m->state = MAIL_STATE_CHANGED;
}
@@ -331,7 +332,7 @@ void WorldSession::HandleMailReturnToSender(WorldPacket & recv_data )
Player *pl = _player;
Mail *m = pl->GetMail(mailId);
- if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
+ if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > sGameTime.GetGameTime())
{
pl->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR);
return;
@@ -393,7 +394,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket & recv_data )
Player* pl = _player;
Mail* m = pl->GetMail(mailId);
- if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
+ if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > sGameTime.GetGameTime())
{
pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR);
return;
@@ -486,7 +487,7 @@ void WorldSession::HandleMailTakeMoney(WorldPacket & recv_data )
Player *pl = _player;
Mail* m = pl->GetMail(mailId);
- if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
+ if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > sGameTime.GetGameTime())
{
pl->SendMailResult(mailId, MAIL_MONEY_TAKEN, MAIL_ERR_INTERNAL_ERROR);
return;
@@ -530,7 +531,7 @@ void WorldSession::HandleGetMailList(WorldPacket & recv_data )
WorldPacket data(SMSG_MAIL_LIST_RESULT, (200)); // guess size
data << uint32(0); // real mail's count
data << uint8(0); // mail's count
- time_t cur_time = time(NULL);
+ time_t cur_time = sGameTime.GetGameTime();
for (PlayerMails::iterator itr = pl->GetMailBegin(); itr != pl->GetMailEnd(); ++itr)
{
@@ -588,7 +589,7 @@ void WorldSession::HandleGetMailList(WorldPacket & recv_data )
data << uint32((*itr)->stationery); // stationery (Stationery.dbc)
data << uint32((*itr)->money); // Gold
data << uint32(show_flags); // unknown, 0x4 - auction, 0x10 - normal
- data << float(((*itr)->expire_time-time(NULL))/DAY); // Time
+ data << float(((*itr)->expire_time-sGameTime.GetGameTime())/DAY); // Time
data << uint32((*itr)->mailTemplateId); // mail template (MailTemplate.dbc)
data << (*itr)->subject; // Subject string - once 00, when mail type = 3
data << uint8(item_count); // client limit is 0x10
@@ -674,7 +675,7 @@ void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data )
Player *pl = _player;
Mail* m = pl->GetMail(mailId);
- if (!m || !m->itemTextId && !m->mailTemplateId || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
+ if (!m || !m->itemTextId && !m->mailTemplateId || m->state == MAIL_STATE_DELETED || m->deliver_time > sGameTime.GetGameTime())
{
pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
return;
@@ -740,7 +741,7 @@ void WorldSession::HandleQueryNextMailTime(WorldPacket & /*recv_data*/ )
data << uint32(0); // count
uint32 count = 0;
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
for (PlayerMails::iterator itr = _player->GetMailBegin(); itr != _player->GetMailEnd(); ++itr)
{
Mail *m = (*itr);
@@ -929,7 +930,7 @@ void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sende
return;
}
- time_t deliver_time = time(NULL) + deliver_delay;
+ time_t deliver_time = sGameTime.GetGameTime() + deliver_delay;
//expire time if COD 3 days, if no COD 30 days, if auction sale pending 1 hour
uint32 expire_delay;
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 8e72be7ad5e..f419e21364a 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -3135,7 +3135,7 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O
sa.ownerGUID = ownerGUID;
sa.script = &iter->second;
- m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sWorld.GetGameTime() + iter->first), sa));
+ m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sGameTime.GetGameTime() + iter->first), sa));
if (iter->first == 0)
immedScript = true;
@@ -3165,7 +3165,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
sa.ownerGUID = ownerGUID;
sa.script = &script;
- m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sWorld.GetGameTime() + delay), sa));
+ m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sGameTime.GetGameTime() + delay), sa));
sWorld.IncreaseScheduledScriptsCount();
@@ -3187,7 +3187,7 @@ void Map::ScriptsProcess()
///- Process overdue queued scripts
std::multimap<time_t, ScriptAction>::iterator iter = m_scriptSchedule.begin();
// ok as multimap is a *sorted* associative container
- while (!m_scriptSchedule.empty() && (iter->first <= sWorld.GetGameTime()))
+ while (!m_scriptSchedule.empty() && (iter->first <= sGameTime.GetGameTime()))
{
ScriptAction const& step = iter->second;
diff --git a/src/game/Map.h b/src/game/Map.h
index 494618baa8e..4e2309768cb 100644
--- a/src/game/Map.h
+++ b/src/game/Map.h
@@ -29,7 +29,7 @@
#include "DBCStructure.h"
#include "GridDefines.h"
#include "Cell.h"
-#include "Timer.h"
+#include "TimeMgr.h"
#include "SharedDefines.h"
#include "GameSystem/GridRefManager.h"
#include "MapRefManager.h"
diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp
index c9692b2ebef..2608f60dcb8 100644
--- a/src/game/MiscHandler.cpp
+++ b/src/game/MiscHandler.cpp
@@ -48,6 +48,7 @@
#include "Vehicle.h"
#include "CreatureAI.h"
#include "DBCEnums.h"
+#include "TimeMgr.h"
void WorldSession::HandleRepopRequestOpcode( WorldPacket & recv_data )
{
@@ -382,7 +383,7 @@ void WorldSession::HandleLogoutRequestOpcode( WorldPacket & /*recv_data*/ )
data << uint32(0);
data << uint8(0);
SendPacket( &data );
- LogoutRequest(time(NULL));
+ LogoutRequest(sGameTime.GetGameTime());
}
void WorldSession::HandlePlayerLogoutOpcode( WorldPacket & /*recv_data*/ )
@@ -442,7 +443,7 @@ void WorldSession::HandleTogglePvP( WorldPacket & recv_data )
else
{
if(!GetPlayer()->pvpInfo.inHostileArea && GetPlayer()->IsPvP())
- GetPlayer()->pvpInfo.endTimer = time(NULL); // start toggle-off
+ GetPlayer()->pvpInfo.endTimer = sGameTime.GetGameTime(); // start toggle-off
}
//if(OutdoorPvP * pvp = _player->GetOutdoorPvP())
@@ -733,7 +734,7 @@ void WorldSession::HandleReclaimCorpseOpcode(WorldPacket &recv_data)
return;
// prevent resurrect before 30-sec delay after body release not finished
- if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > time(NULL))
+ if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > sGameTime.GetGameTime())
return;
if (!corpse->IsWithinDistInMap(GetPlayer(), CORPSE_RECLAIM_RADIUS, true))
@@ -867,7 +868,7 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data)
{
// set resting flag we are in the inn
GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
- GetPlayer()->InnEnter(time(NULL), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
+ GetPlayer()->InnEnter(sGameTime.GetGameTime(), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN);
if(sWorld.IsFFAPvPRealm())
@@ -1621,6 +1622,6 @@ void WorldSession::HandleWorldStateUITimerUpdate(WorldPacket& recv_data)
sLog.outDebug("WORLD: CMSG_WORLD_STATE_UI_TIMER_UPDATE");
WorldPacket data(SMSG_WORLD_STATE_UI_TIMER_UPDATE, 4);
- data << uint32(time(NULL));
+ data << uint32(sGameTime.GetGameTime());
SendPacket(&data);
}
diff --git a/src/game/MovementHandler.cpp b/src/game/MovementHandler.cpp
index 2fc1e5a9125..7942d0800ca 100644
--- a/src/game/MovementHandler.cpp
+++ b/src/game/MovementHandler.cpp
@@ -33,6 +33,7 @@
#include "WaypointMovementGenerator.h"
#include "InstanceSaveMgr.h"
#include "ObjectMgr.h"
+#include "TimeMgr.h"
void WorldSession::HandleMoveWorldportAckOpcode( WorldPacket & /*recv_data*/ )
{
@@ -154,7 +155,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
Difficulty diff = GetPlayer()->GetDifficulty(mEntry->IsRaid());
if (uint32 timeReset = sInstanceSaveManager.GetResetTimeFor(GetPlayer()->GetMapId(),diff))
{
- uint32 timeleft = timeReset - time(NULL);
+ uint32 timeleft = timeReset - sGameTime.GetGameTime();
GetPlayer()->SendInstanceResetWarning(GetPlayer()->GetMapId(), diff, timeleft);
}
}
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index 01867c7cffc..ba52e8ff85c 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -46,6 +46,7 @@
#include "WaypointManager.h"
#include "InstanceData.h" //for condition_instance_data
#include "GossipDef.h"
+#include "TimeMgr.h"
INSTANTIATE_SINGLETON_1(ObjectMgr);
@@ -5024,7 +5025,7 @@ void ObjectMgr::LoadNpcTextLocales()
//not very fast function but it is called only once a day, or on starting-up
void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
{
- time_t basetime = time(NULL);
+ time_t basetime = sGameTime.GetGameTime();
sLog.outDebug("Returning mails current time: hour: %d, minute: %d, second: %d ", localtime(&basetime)->tm_hour, localtime(&basetime)->tm_min, localtime(&basetime)->tm_sec);
//delete all old mails without item and without body immediately, if starting server
if (!serverUp)
@@ -8249,7 +8250,9 @@ void ObjectMgr::LoadVendors()
VendorItemData& vList = m_mCacheVendorItemMap[entry];
- vList.AddItem(item_id,maxcount,incrtime,ExtendedCost);
+ uint8 vendorslot = vList.GetItemCount();
+
+ vList.AddItem(item_id,maxcount,incrtime,ExtendedCost,vendorslot);
++count;
} while (result->NextRow());
@@ -8520,7 +8523,8 @@ void ObjectMgr::LoadGossipMenuItems()
void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, int32 maxcount, uint32 incrtime, uint32 extendedcost, bool savetodb)
{
VendorItemData& vList = m_mCacheVendorItemMap[entry];
- vList.AddItem(item,maxcount,incrtime,extendedcost);
+ uint8 vendorslot = vList.GetItemCount();
+ vList.AddItem(item,maxcount,incrtime,extendedcost,vendorslot);
if(savetodb) WorldDatabase.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%u')",entry, item, maxcount,incrtime,extendedcost);
}
diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp
index 58a561c3a6f..3c8a3b3510f 100644
--- a/src/game/Pet.cpp
+++ b/src/game/Pet.cpp
@@ -30,6 +30,7 @@
#include "CreatureAI.h"
#include "Unit.h"
#include "Util.h"
+#include "TimeMgr.h"
char const* petTypeSuffix[MAX_PET_TYPE] =
{
@@ -243,7 +244,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
break;
}
- SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
+ SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, sGameTime.GetGameTime());
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32());
SetCreatorGUID(owner->GetGUID());
@@ -301,7 +302,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
m_resetTalentsTime = fields[16].GetUInt64();
InitTalentForLevel(); // set original talents points before spell loading
- uint32 timediff = (time(NULL) - fields[14].GetUInt32());
+ uint32 timediff = (sGameTime.GetGameTime() - fields[14].GetUInt32());
_LoadAuras(timediff);
// load action bar, if data broken will fill later by default spells.
@@ -442,7 +443,7 @@ void Pet::SavePetToDB(PetSaveMode mode)
};
ss << "', "
- << time(NULL) << ", "
+ << sGameTime.GetGameTime() << ", "
<< uint32(m_resetTalentsCost) << ", "
<< uint64(m_resetTalentsTime) << ", "
<< GetUInt32Value(UNIT_CREATED_BY_SPELL) << ", "
@@ -1034,7 +1035,7 @@ void Pet::_LoadSpellCooldowns()
if(result)
{
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
WorldPacket data(SMSG_SPELL_COOLDOWN, (8+1+result->GetRowCount()*8));
data << GetGUID();
@@ -1077,7 +1078,7 @@ void Pet::_SaveSpellCooldowns()
{
CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", m_charmInfo->GetPetNumber());
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
// remove oudated and save active
for (CreatureSpellCooldowns::iterator itr = m_CreatureSpellCooldowns.begin(); itr != m_CreatureSpellCooldowns.end();)
@@ -1592,7 +1593,7 @@ bool Pet::resetTalents(bool no_cost)
player->ModifyMoney(-(int32)cost);
m_resetTalentsCost = cost;
- m_resetTalentsTime = time(NULL);
+ m_resetTalentsTime = sGameTime.GetGameTime();
}
if (!m_loading)
player->PetSpellInitialize();
@@ -1703,7 +1704,7 @@ void Pet::InitTalentForLevel()
uint32 Pet::resetTalentsCost() const
{
- uint32 days = (sWorld.GetGameTime() - m_resetTalentsTime)/DAY;
+ uint32 days = (sGameTime.GetGameTime() - m_resetTalentsTime)/DAY;
// The first time reset costs 10 silver; after 1 day cost is reset to 10 silver
if (m_resetTalentsCost < 10*SILVER || days > 0)
diff --git a/src/game/PetAI.h b/src/game/PetAI.h
index 226aa493202..4e47cd9dffe 100644
--- a/src/game/PetAI.h
+++ b/src/game/PetAI.h
@@ -22,7 +22,7 @@
#define TRINITY_PETAI_H
#include "CreatureAI.h"
-#include "Timer.h"
+#include "TimeMgr.h"
class Creature;
class Spell;
diff --git a/src/game/PetHandler.cpp b/src/game/PetHandler.cpp
index ee8c02dfb43..05c5c35bda5 100644
--- a/src/game/PetHandler.cpp
+++ b/src/game/PetHandler.cpp
@@ -31,6 +31,7 @@
#include "Util.h"
#include "Pet.h"
#include "World.h"
+#include "TimeMgr.h"
void WorldSession::HandlePetAction( WorldPacket & recv_data )
{
@@ -557,7 +558,7 @@ void WorldSession::HandlePetRename( WorldPacket & recv_data )
CharacterDatabase.PExecute("UPDATE character_pet SET name = '%s', renamed = '1' WHERE owner = '%u' AND id = '%u'", name.c_str(), _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber());
CharacterDatabase.CommitTransaction();
- pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
+ pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, sGameTime.GetGameTime());
}
void WorldSession::HandlePetAbandon( WorldPacket & recv_data )
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index d578a243a01..32ea3eb8374 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -65,6 +65,7 @@
#include "GameEventMgr.h"
#include "AchievementMgr.h"
#include "SpellAuras.h"
+#include "TimeMgr.h"
#include <cmath>
@@ -385,7 +386,7 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
m_bgBattleGroundQueueID[j].invitedToInstance = 0;
}
- m_logintime = time(NULL);
+ m_logintime = sGameTime.GetGameTime();
m_Last_tick = m_logintime;
m_WeaponProficiency = 0;
m_ArmorProficiency = 0;
@@ -461,7 +462,7 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
m_baseHealthRegen = 0;
// Honor System
- m_lastHonorUpdateTime = time(NULL);
+ m_lastHonorUpdateTime = sGameTime.GetGameTime();
// Player summoning
m_summon_expire = 0;
@@ -696,7 +697,7 @@ bool Player::Create( uint32 guidlow, const std::string& name, uint8 race, uint8
}
// Played time
- m_Last_tick = time(NULL);
+ m_Last_tick = sGameTime.GetGameTime();
m_Played_time[PLAYED_TIME_TOTAL] = 0;
m_Played_time[PLAYED_TIME_LEVEL] = 0;
@@ -1135,7 +1136,7 @@ void Player::Update( uint32 p_time )
return;
// undelivered mail
- if (m_nextMailDelivereTime && m_nextMailDelivereTime <= time(NULL))
+ if (m_nextMailDelivereTime && m_nextMailDelivereTime <= sGameTime.GetGameTime())
{
SendNewMail();
++unReadMails;
@@ -1161,7 +1162,7 @@ void Player::Update( uint32 p_time )
Unit::Update(p_time);
SetCanDelayTeleport(false);
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
UpdatePvPFlag(now);
@@ -1279,13 +1280,13 @@ void Player::Update( uint32 p_time )
{
if (roll_chance_i(3) && GetTimeInnEnter() > 0) // freeze update
{
- int time_inn = time(NULL)-GetTimeInnEnter();
+ int time_inn = sGameTime.GetGameTime()-GetTimeInnEnter();
if (time_inn >= 10) // freeze update
{
float bubble = 0.125*sWorld.getRate(RATE_REST_INGAME);
// speed collect rest bonus (section/in hour)
SetRestBonus(GetRestBonus()+ time_inn*((float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP)/72000)*bubble);
- UpdateInnerTime(time(NULL));
+ UpdateInnerTime(sGameTime.GetGameTime());
}
}
}
@@ -2780,7 +2781,7 @@ void Player::InitStatsForLevel(bool reapplyMods)
void Player::SendInitialSpells()
{
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
time_t infTime = curTime + infinityCooldownDelayCheck;
uint16 spellCount = 0;
@@ -2888,7 +2889,7 @@ void Player::UpdateNextMailTimeAndUnreads()
{
// calculate next delivery time (min. from non-delivered mails
// and recalculate unReadMail
- time_t cTime = time(NULL);
+ time_t cTime = sGameTime.GetGameTime();
m_nextMailDelivereTime = 0;
unReadMails = 0;
for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
@@ -2905,7 +2906,7 @@ void Player::UpdateNextMailTimeAndUnreads()
void Player::AddNewMailDeliverTime(time_t deliver_time)
{
- if(deliver_time <= time(NULL)) // ready now
+ if(deliver_time <= sGameTime.GetGameTime()) // ready now
{
++unReadMails;
SendNewMail();
@@ -3673,7 +3674,7 @@ void Player::_LoadSpellCooldowns(QueryResult *result)
if (result)
{
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
do
{
@@ -3707,7 +3708,7 @@ void Player::_SaveSpellCooldowns()
{
CharacterDatabase.PExecute("DELETE FROM character_spell_cooldown WHERE guid = '%u'", GetGUIDLow());
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
time_t infTime = curTime + infinityCooldownDelayCheck;
bool first_round = true;
@@ -3753,7 +3754,7 @@ uint32 Player::resetTalentsCost() const
return 10*GOLD;
else
{
- uint32 months = (sWorld.GetGameTime() - m_resetTalentsTime)/MONTH;
+ uint32 months = (sGameTime.GetGameTime() - m_resetTalentsTime)/MONTH;
if(months > 0)
{
// This cost will be reduced by a rate of 5 gold per month
@@ -3846,7 +3847,7 @@ bool Player::resetTalents(bool no_cost)
GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_NUMBER_OF_TALENT_RESETS, 1);
m_resetTalentsCost = cost;
- m_resetTalentsTime = time(NULL);
+ m_resetTalentsTime = sGameTime.GetGameTime();
}
//FIXME: remove pet before or after unlearn spells? for now after unlearn to allow removing of talent related, pet affecting auras
@@ -4380,7 +4381,7 @@ void Player::SendDelayResponse(const uint32 ml_seconds)
{
//FIXME: is this delay time arg really need? 50msec by default in code
WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 );
- data << (uint32)time(NULL);
+ data << (uint32)sGameTime.GetGameTime();
data << (uint32)0;
GetSession()->SendPacket( &data );
}
@@ -6286,8 +6287,8 @@ void Player::RewardReputation(Quest const *pQuest)
void Player::UpdateHonorFields()
{
/// called when rewarding honor and at each save
- uint64 now = time(NULL);
- uint64 today = uint64(time(NULL) / DAY) * DAY;
+ uint64 now = sGameTime.GetGameTime();
+ uint64 today = uint64(sGameTime.GetGameTime() / DAY) * DAY;
if(m_lastHonorUpdateTime < today)
{
@@ -6339,7 +6340,7 @@ bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, float honor, bool pvpt
uint64 victim_guid = 0;
uint32 victim_rank = 0;
uint32 rank_diff = 0;
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
// need call before fields update to have chance move yesterday data to appropriate fields before today data change.
UpdateHonorFields();
@@ -12052,7 +12053,7 @@ void Player::AddItemToBuyBackSlot( Item *pItem )
sLog.outDebug( "STORAGE: AddItemToBuyBackSlot item = %u, slot = %u", pItem->GetEntry(), slot);
m_items[slot] = pItem;
- time_t base = time(NULL);
+ time_t base = sGameTime.GetGameTime();
uint32 etime = uint32(base - m_logintime + (30 * 3600));
uint32 eslot = slot - BUYBACK_SLOT_START;
@@ -13575,7 +13576,7 @@ void Player::AddQuest( Quest const *pQuest, Object *questGiver )
AddTimedQuest( quest_id );
questStatusData.m_timer = limittime * IN_MILISECONDS;
- qtime = static_cast<uint32>(time(NULL)) + limittime;
+ qtime = static_cast<uint32>(sGameTime.GetGameTime()) + limittime;
}
else
questStatusData.m_timer = 0;
@@ -15546,7 +15547,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
SaveRecallPosition();
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
time_t logoutTime = time_t(fields[23].GetUInt64());
// since last logout (in seconds)
@@ -16287,10 +16288,10 @@ void Player::_LoadQuestStatus(QueryResult *result)
{
AddTimedQuest(quest_id);
- if (quest_time <= sWorld.GetGameTime())
+ if (quest_time <= sGameTime.GetGameTime())
questStatusData.m_timer = 1;
else
- questStatusData.m_timer = (quest_time - sWorld.GetGameTime()) * IN_MILISECONDS;
+ questStatusData.m_timer = (quest_time - sGameTime.GetGameTime()) * IN_MILISECONDS;
}
else
quest_time = 0;
@@ -16588,7 +16589,7 @@ void Player::SendRaidInfo()
size_t p_counter = data.wpos();
data << uint32(counter); // placeholder
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
{
@@ -16911,7 +16912,7 @@ void Player::SaveToDB()
ss << m_Played_time[PLAYED_TIME_LEVEL] << ", ";
ss << finiteAlways(m_rest_bonus) << ", ";
- ss << (uint64)time(NULL) << ", ";
+ ss << (uint64)sGameTime.GetGameTime() << ", ";
ss << (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ? 1 : 0) << ", ";
//save, far from tavern/city
//save, but in tavern/city
@@ -17180,11 +17181,11 @@ void Player::_SaveQuestStatus()
case QUEST_NEW :
CharacterDatabase.PExecute("INSERT INTO character_queststatus (guid,quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4) "
"VALUES ('%u', '%u', '%u', '%u', '%u', '" UI64FMTD "', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u')",
- GetGUIDLow(), i->first, i->second.m_status, i->second.m_rewarded, i->second.m_explored, uint64(i->second.m_timer / IN_MILISECONDS+ sWorld.GetGameTime()), i->second.m_creatureOrGOcount[0], i->second.m_creatureOrGOcount[1], i->second.m_creatureOrGOcount[2], i->second.m_creatureOrGOcount[3], i->second.m_itemcount[0], i->second.m_itemcount[1], i->second.m_itemcount[2], i->second.m_itemcount[3]);
+ GetGUIDLow(), i->first, i->second.m_status, i->second.m_rewarded, i->second.m_explored, uint64(i->second.m_timer / IN_MILISECONDS+ sGameTime.GetGameTime()), i->second.m_creatureOrGOcount[0], i->second.m_creatureOrGOcount[1], i->second.m_creatureOrGOcount[2], i->second.m_creatureOrGOcount[3], i->second.m_itemcount[0], i->second.m_itemcount[1], i->second.m_itemcount[2], i->second.m_itemcount[3]);
break;
case QUEST_CHANGED :
CharacterDatabase.PExecute("UPDATE character_queststatus SET status = '%u',rewarded = '%u',explored = '%u',timer = '" UI64FMTD "',mobcount1 = '%u',mobcount2 = '%u',mobcount3 = '%u',mobcount4 = '%u',itemcount1 = '%u',itemcount2 = '%u',itemcount3 = '%u',itemcount4 = '%u' WHERE guid = '%u' AND quest = '%u' ",
- i->second.m_status, i->second.m_rewarded, i->second.m_explored, uint64(i->second.m_timer / IN_MILISECONDS + sWorld.GetGameTime()), i->second.m_creatureOrGOcount[0], i->second.m_creatureOrGOcount[1], i->second.m_creatureOrGOcount[2], i->second.m_creatureOrGOcount[3], i->second.m_itemcount[0], i->second.m_itemcount[1], i->second.m_itemcount[2], i->second.m_itemcount[3], GetGUIDLow(), i->first );
+ i->second.m_status, i->second.m_rewarded, i->second.m_explored, uint64(i->second.m_timer / IN_MILISECONDS + sGameTime.GetGameTime()), i->second.m_creatureOrGOcount[0], i->second.m_creatureOrGOcount[1], i->second.m_creatureOrGOcount[2], i->second.m_creatureOrGOcount[3], i->second.m_itemcount[0], i->second.m_itemcount[1], i->second.m_itemcount[2], i->second.m_itemcount[3], GetGUIDLow(), i->first );
break;
case QUEST_UNCHANGED:
break;
@@ -17879,7 +17880,7 @@ void Player::PetSpellInitialize()
uint8 cooldownsCount = pet->m_CreatureSpellCooldowns.size() + pet->m_CreatureCategoryCooldowns.size();
data << uint8(cooldownsCount);
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
for (CreatureSpellCooldowns::const_iterator itr = pet->m_CreatureSpellCooldowns.begin(); itr != pet->m_CreatureSpellCooldowns.end(); ++itr)
{
@@ -18645,7 +18646,7 @@ void Player::ProhibitSpellScholl(SpellSchoolMask idSchoolMask, uint32 unTimeMs )
WorldPacket data(SMSG_SPELL_COOLDOWN, 8+1+m_spells.size()*8);
data << GetGUID();
data << uint8(0x0); // flags (0x1, 0x2)
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
for (PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
{
if (itr->second->state == PLAYERSPELL_REMOVED)
@@ -18924,7 +18925,7 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
{
it->SetPaidArenaPoints(arenaPoints);
it->SetPaidHonorPoints(honorPoints);
- it->SetRefundExpiryTime( time(NULL)+(HOUR*2) );
+ it->SetRefundExpiryTime( sGameTime.GetGameTime()+(HOUR*2) );
for (uint8 i = 0; i < 5; ++i)
it->SetPaidExtendedCost(i, extendedCost[i], extendedCostCount[i]);
}
@@ -19090,12 +19091,25 @@ void Player::UpdatePvP(bool state, bool override)
else
{
if(pvpInfo.endTimer != 0)
- pvpInfo.endTimer = time(NULL);
+ pvpInfo.endTimer = sGameTime.GetGameTime();
else
SetPvP(state);
}
}
+bool Player::HasSpellCooldown(uint32 spell_id) const
+{
+ SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
+ return itr != m_spellCooldowns.end() && itr->second.end > sGameTime.GetGameTime();
+}
+
+uint32 Player::GetSpellCooldownDelay(uint32 spell_id) const
+{
+ SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
+ time_t t = sGameTime.GetGameTime();
+ return itr != m_spellCooldowns.end() && itr->second.end > t ? itr->second.end - t : 0;
+}
+
void Player::AddSpellAndCategoryCooldowns(SpellEntry const* spellInfo, uint32 itemId, Spell* spell, bool infinityCooldown)
{
// init cooldown values
@@ -19132,7 +19146,7 @@ void Player::AddSpellAndCategoryCooldowns(SpellEntry const* spellInfo, uint32 it
catrec = spellInfo->CategoryRecoveryTime;
}
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
time_t catrecTime;
time_t recTime;
@@ -19993,7 +20007,7 @@ void Player::SendInitialPacketsBeforeAddToMap()
SendEquipmentSetList();
data.Initialize(SMSG_LOGIN_SETTIMESPEED, 4 + 4 + 4);
- data << uint32(secsToTimeBitFields(sWorld.GetGameTime()));
+ data << uint32(secsToTimeBitFields(sGameTime.GetGameTime()));
data << (float)0.01666667f; // game speed
data << uint32(0); // added in 3.1.2
GetSession()->SendPacket( &data );
@@ -20124,7 +20138,7 @@ void Player::ApplyEquipCooldown( Item * pItem )
if( spellData.SpellTrigger != ITEM_SPELLTRIGGER_ON_USE )
continue;
- AddSpellCooldown(spellData.SpellId, pItem->GetEntry(), time(NULL) + 30);
+ AddSpellCooldown(spellData.SpellId, pItem->GetEntry(), sGameTime.GetGameTime() + 30);
WorldPacket data(SMSG_ITEM_COOLDOWN, 12);
data << pItem->GetGUID();
@@ -20375,7 +20389,7 @@ void Player::SetDailyQuestStatus( uint32 quest_id )
if(!GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1+quest_daily_idx))
{
SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1+quest_daily_idx,quest_id);
- m_lastDailyQuestTime = time(NULL); // last daily quest time
+ m_lastDailyQuestTime = sGameTime.GetGameTime(); // last daily quest time
m_DailyQuestChanged = true;
break;
}
@@ -20545,6 +20559,15 @@ void Player::UpdateForQuestWorldObjects()
GetSession()->SendPacket(&packet);
}
+void Player::SetSummonPoint(uint32 mapid, float x, float y, float z)
+{
+ m_summon_expire = sGameTime.GetGameTime() + MAX_PLAYER_SUMMON_DELAY;
+ m_summon_mapid = mapid;
+ m_summon_x = x;
+ m_summon_y = y;
+ m_summon_z = z;
+}
+
void Player::SummonIfPossible(bool agree)
{
if (!agree)
@@ -20554,7 +20577,7 @@ void Player::SummonIfPossible(bool agree)
}
// expire and auto declined
- if (m_summon_expire < time(NULL))
+ if (m_summon_expire < sGameTime.GetGameTime())
return;
// stop taxi flight at summon
@@ -21047,7 +21070,7 @@ uint32 Player::GetCorpseReclaimDelay(bool pvp) const
else if(!sWorld.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE) )
return 0;
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
// 0..2 full period
// should be ceil(x)-1 but not floor(x)
uint32 count = (now < m_deathExpireTime - 1) ? (m_deathExpireTime - 1 - now)/DEATH_EXPIRE_STEP : 0;
@@ -21062,7 +21085,7 @@ void Player::UpdateCorpseReclaimDelay()
(!pvp && !sWorld.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE) ))
return;
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
if(now < m_deathExpireTime)
{
// full and partly periods 1..3
@@ -21107,7 +21130,7 @@ void Player::SendCorpseReclaimDelay(bool load)
time_t expected_time = corpse->GetGhostTime()+copseReclaimDelay[count];
- time_t now = time(NULL);
+ time_t now = sGameTime.GetGameTime();
if(now >= expected_time)
return;
diff --git a/src/game/Player.h b/src/game/Player.h
index db6e72b5768..8d1af04e72d 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -39,6 +39,7 @@
#include "ReputationMgr.h"
#include "BattleGround.h"
#include "DBCEnums.h"
+#include "TimeMgr.h"
#include<string>
#include<vector>
@@ -987,14 +988,7 @@ class TRINITY_DLL_SPEC Player : public Unit
bool TeleportToBGEntryPoint();
- void SetSummonPoint(uint32 mapid, float x, float y, float z)
- {
- m_summon_expire = time(NULL) + MAX_PLAYER_SUMMON_DELAY;
- m_summon_mapid = mapid;
- m_summon_x = x;
- m_summon_y = y;
- m_summon_z = z;
- }
+ void SetSummonPoint(uint32 mapid, float x, float y, float z);
void SummonIfPossible(bool agree);
bool Create( uint32 guidlow, const std::string& name, uint8 race, uint8 class_, uint8 gender, uint8 skin, uint8 face, uint8 hairStyle, uint8 hairColor, uint8 facialHair, uint8 outfitId );
@@ -1571,17 +1565,8 @@ class TRINITY_DLL_SPEC Player : public Unit
static uint32 const infinityCooldownDelay = MONTH; // used for set "infinity cooldowns" for spells and check
static uint32 const infinityCooldownDelayCheck = MONTH/2;
- bool HasSpellCooldown(uint32 spell_id) const
- {
- SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
- return itr != m_spellCooldowns.end() && itr->second.end > time(NULL);
- }
- uint32 GetSpellCooldownDelay(uint32 spell_id) const
- {
- SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
- time_t t = time(NULL);
- return itr != m_spellCooldowns.end() && itr->second.end > t ? itr->second.end - t : 0;
- }
+ bool HasSpellCooldown(uint32 spell_id) const;
+ uint32 GetSpellCooldownDelay(uint32 spell_id) const;
void AddSpellAndCategoryCooldowns(SpellEntry const* spellInfo, uint32 itemId, Spell* spell = NULL, bool infinityCooldown = false );
void AddSpellCooldown(uint32 spell_id, uint32 itemid, time_t end_time);
void SendCooldownEvent(SpellEntry const *spellInfo, uint32 itemId = 0, Spell* spell = NULL);
diff --git a/src/game/QueryHandler.cpp b/src/game/QueryHandler.cpp
index 4ce59eef384..f0f70fde55c 100644
--- a/src/game/QueryHandler.cpp
+++ b/src/game/QueryHandler.cpp
@@ -33,6 +33,7 @@
#include "NPCHandler.h"
#include "Pet.h"
#include "MapManager.h"
+#include "TimeMgr.h"
void WorldSession::SendNameQueryOpcode(Player *p)
{
@@ -142,7 +143,7 @@ void WorldSession::HandleNameQueryOpcode( WorldPacket & recv_data )
void WorldSession::HandleQueryTimeOpcode( WorldPacket & /*recv_data*/ )
{
WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 );
- data << (uint32)time(NULL);
+ data << (uint32)sGameTime.GetGameTime();
data << (uint32)0;
SendPacket( &data );
}
diff --git a/src/game/RandomMovementGenerator.cpp b/src/game/RandomMovementGenerator.cpp
index c8872c6fef6..5e23648660c 100644
--- a/src/game/RandomMovementGenerator.cpp
+++ b/src/game/RandomMovementGenerator.cpp
@@ -170,7 +170,7 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff
{
if(creature.hasUnitState(UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED))
{
- i_nextMoveTime.Update(i_nextMoveTime.GetExpiry()); // Expire the timer
+ i_nextMoveTime.Update(i_nextMoveTime.GetExpireTime()); // Expire the timer
creature.clearUnitState(UNIT_STAT_ROAMING);
return true;
}
diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp
index e7295fd7e74..446065607c6 100644
--- a/src/game/SpellAuras.cpp
+++ b/src/game/SpellAuras.cpp
@@ -49,6 +49,7 @@
#include "GridNotifiersImpl.h"
#include "Vehicle.h"
#include "CellImpl.h"
+#include "TimeMgr.h"
#define Aura AuraEffect
pAuraHandler AuraHandler[TOTAL_AURAS]=
@@ -366,7 +367,7 @@ pAuraHandler AuraHandler[TOTAL_AURAS]=
Aura::Aura(SpellEntry const* spellproto, uint32 effMask, Unit *target, WorldObject *source, Unit *caster, int32 *currentBasePoints, Item* castItem) :
m_spellProto(spellproto),
m_target(target), m_sourceGuid(source->GetGUID()), m_casterGuid(caster->GetGUID()), m_castItemGuid(castItem ? castItem->GetGUID() : 0),
- m_applyTime(time(NULL)),
+ m_applyTime(sGameTime.GetGameTime()),
m_timeCla(0), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_AuraDRGroup(DIMINISHING_NONE),
m_auraSlot(MAX_AURAS), m_auraLevel(1), m_procCharges(0), m_stackAmount(1), m_isRemoved(false)
{
@@ -1330,7 +1331,7 @@ void Aura::HandleAuraSpecificMods(bool apply)
return;
player->RemoveSpellCooldown(m_spellProto->Id, true);
- player->AddSpellCooldown(m_spellProto->Id, 0, uint32(time(NULL) + aurEff->GetAmount()));
+ player->AddSpellCooldown(m_spellProto->Id, 0, uint32(sGameTime.GetGameTime() + aurEff->GetAmount()));
WorldPacket data(SMSG_SPELL_COOLDOWN, 8+1+4+4);
data << uint64(player->GetGUID());
diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp
index f535033b0e6..72a6ad32bb9 100644
--- a/src/game/SpellEffects.cpp
+++ b/src/game/SpellEffects.cpp
@@ -61,6 +61,7 @@
#include "SkillDiscovery.h"
#include "Formulas.h"
#include "Vehicle.h"
+#include "TimeMgr.h"
pEffect SpellEffects[TOTAL_SPELL_EFFECTS]=
{
@@ -998,7 +999,7 @@ void Spell::EffectDummy(uint32 i)
Creature* creatureTarget = (Creature*)unitTarget;
- GameObject* Crystal_Prison = m_caster->SummonGameObject(179644, creatureTarget->GetPositionX(), creatureTarget->GetPositionY(), creatureTarget->GetPositionZ(), creatureTarget->GetOrientation(), 0, 0, 0, 0, creatureTarget->GetRespawnTime()-time(NULL));
+ GameObject* Crystal_Prison = m_caster->SummonGameObject(179644, creatureTarget->GetPositionX(), creatureTarget->GetPositionY(), creatureTarget->GetPositionZ(), creatureTarget->GetOrientation(), 0, 0, 0, 0, creatureTarget->GetRespawnTime()-sGameTime.GetGameTime());
sLog.outDebug("SummonGameObject at SpellEfects.cpp EffectDummy for Spell 23019");
creatureTarget->ForcedDespawn();
diff --git a/src/game/TicketHandler.cpp b/src/game/TicketHandler.cpp
index ac6675beba0..b0158963ae0 100644
--- a/src/game/TicketHandler.cpp
+++ b/src/game/TicketHandler.cpp
@@ -24,6 +24,7 @@
#include "ObjectMgr.h"
#include "Player.h"
#include "World.h"
+#include "TimeMgr.h"
void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data )
{
@@ -52,12 +53,12 @@ void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data )
ticket->guid = objmgr.GenerateGMTicketId();
ticket->playerGuid = GetPlayer()->GetGUID();
ticket->message = ticketText;
- ticket->createtime = time(NULL);
+ ticket->createtime = sGameTime.GetGameTime();
ticket->map = map;
ticket->pos_x = x;
ticket->pos_y = y;
ticket->pos_z = z;
- ticket->timestamp = time(NULL);
+ ticket->timestamp = sGameTime.GetGameTime();
ticket->closed = 0;
ticket->assignedToGM = 0;
ticket->comment = "";
@@ -87,7 +88,7 @@ void WorldSession::HandleGMTicketUpdateOpcode( WorldPacket & recv_data)
}
ticket->message = message;
- ticket->timestamp = time(NULL);
+ ticket->timestamp = sGameTime.GetGameTime();
objmgr.AddOrUpdateGMTicket(*ticket);
@@ -117,7 +118,7 @@ void WorldSession::HandleGMTicketDeleteOpcode( WorldPacket & /*recv_data*/)
void WorldSession::HandleGMTicketGetTicketOpcode( WorldPacket & /*recv_data*/)
{
WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 );
- data << (uint32)time(NULL);
+ data << (uint32)sGameTime.GetGameTime();
data << (uint32)0;
SendPacket( &data );
diff --git a/src/game/TotemAI.h b/src/game/TotemAI.h
index 003f5d5ca13..68e44e04c4c 100644
--- a/src/game/TotemAI.h
+++ b/src/game/TotemAI.h
@@ -22,7 +22,7 @@
#define TRINITY_TOTEMAI_H
#include "CreatureAI.h"
-#include "Timer.h"
+#include "TimeMgr.h"
class Creature;
class Totem;
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 230478dd9ec..30fee0eeb45 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -54,6 +54,7 @@
#include "Vehicle.h"
#include "Transports.h"
#include "ScriptCalls.h"
+#include "TimeMgr.h"
#include <math.h>
@@ -2007,7 +2008,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff
int32 healAmount = pVictim->GetMaxHealth() * (*i)->GetAmount() / 100.0f * pctFromDefense;
pVictim->CastCustomSpell(pVictim, 66235, &healAmount, NULL, NULL, true);
- ((Player*)pVictim)->AddSpellCooldown(66235,0,time(NULL) + 120);
+ ((Player*)pVictim)->AddSpellCooldown(66235,0,sGameTime.GetGameTime() + 120);
}
else if (remainingHealth < allowedHealth)
{
@@ -2254,7 +2255,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff
if (preventDeathSpell->SpellIconID == 2109)
{
pVictim->CastSpell(pVictim,31231,true);
- ((Player*)pVictim)->AddSpellCooldown(31231,0,time(NULL)+60);
+ ((Player*)pVictim)->AddSpellCooldown(31231,0,sGameTime.GetGameTime()+60);
// with health > 10% lost health until health==10%, in other case no losses
uint32 health10 = pVictim->GetMaxHealth()/10;
RemainingDamage = pVictim->GetHealth() > health10 ? pVictim->GetHealth() - health10 : 0;
@@ -4898,7 +4899,7 @@ bool Unit::HandleHasteAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura);
if (cooldown && GetTypeId() == TYPEID_PLAYER)
- ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
@@ -4960,7 +4961,7 @@ bool Unit::HandleSpellCritChanceAuraProc(Unit *pVictim, uint32 /*damage*/, AuraE
CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
@@ -6717,7 +6718,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
// apply cooldown before cast to prevent processing itself
if( cooldown )
- ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,sGameTime.GetGameTime() + cooldown);
// Attack Twice
for (uint32 i = 0; i<2; ++i )
@@ -6957,7 +6958,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
((Player*)this)->AddSpellMod(mod, false);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
@@ -7240,7 +7241,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura, originalCaster);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
@@ -7298,7 +7299,7 @@ bool Unit::HandleObsModEnergyAuraProc(Unit *pVictim, uint32 damage, AuraEffect*
CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
bool Unit::HandleModDamagePctTakenAuraProc(Unit *pVictim, uint32 damage, AuraEffect* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown)
@@ -7356,7 +7357,7 @@ bool Unit::HandleModDamagePctTakenAuraProc(Unit *pVictim, uint32 damage, AuraEff
CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
@@ -7994,7 +7995,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
target->CastSpell(target,trigger_spell_id,true,castItem,triggeredByAura);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(trigger_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(trigger_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
// Cast positive spell on enemy target
@@ -8166,7 +8167,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
CastSpell(target,trigger_spell_id,true,castItem,triggeredByAura);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(trigger_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(trigger_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
@@ -8264,7 +8265,7 @@ bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, AuraE
CastSpell(pVictim, triggered_spell_id, true, castItem, triggeredByAura);
if( cooldown && GetTypeId() == TYPEID_PLAYER )
- ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown);
+ ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,sGameTime.GetGameTime() + cooldown);
return true;
}
@@ -14595,7 +14596,7 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type)
GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true);
//if charmed two demons the same session, the 2nd gets the 1st one's name
- SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
+ SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, sGameTime.GetGameTime());
}
}
((Player*)charmer)->CharmSpellInitialize();
diff --git a/src/game/Weather.cpp b/src/game/Weather.cpp
index 5d8d1fbd9ba..62c2532a3cd 100644
--- a/src/game/Weather.cpp
+++ b/src/game/Weather.cpp
@@ -88,7 +88,7 @@ bool Weather::ReGenerate()
//78 days between January 1st and March 20nd; 365/4=91 days by season
// season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
- time_t gtime = sWorld.GetGameTime();
+ time_t gtime = sGameTime.GetGameTime();
struct tm * ltime = localtime(&gtime);
uint32 season = ((ltime->tm_yday - 78 + 365)/91)%4;
diff --git a/src/game/Weather.h b/src/game/Weather.h
index e312f004060..9b824f9df21 100644
--- a/src/game/Weather.h
+++ b/src/game/Weather.h
@@ -27,7 +27,7 @@
#include "Common.h"
#include "SharedDefines.h"
-#include "Timer.h"
+#include "TimeMgr.h"
class Player;
diff --git a/src/game/World.cpp b/src/game/World.cpp
index 21b1372f1af..9fe7f77fd5c 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -68,6 +68,7 @@
#include "CreatureGroups.h"
#include "Transports.h"
#include "ProgressBar.h"
+#include "TimeMgr.h"
INSTANTIATE_SINGLETON_1(World);
@@ -96,7 +97,7 @@ World::World()
m_allowMovement = true;
m_ShutdownMask = 0;
m_ShutdownTimer = 0;
- m_gameTime=time(NULL);
+ m_gameTime=sGameTime.GetGameTime();
m_startTime=m_gameTime;
m_maxActiveSessionCount = 0;
m_maxQueuedSessionCount = 0;
@@ -287,7 +288,7 @@ bool World::HasRecentlyDisconnected(WorldSession* session)
{
for (DisconnectMap::iterator i = m_disconnects.begin(); i != m_disconnects.end();)
{
- if (difftime(i->second, time(NULL)) < tolerance)
+ if (difftime(i->second, sGameTime.GetGameTime()) < tolerance)
{
if (i->first == session->GetAccountId())
return true;
@@ -1234,7 +1235,7 @@ void World::LoadConfigSettings(bool reload)
void World::SetInitialWorldSettings()
{
///- Initialize the random number generator
- srand((unsigned int)time(NULL));
+ srand((unsigned int)sGameTime.GetGameTime());
///- Initialize config settings
LoadConfigSettings();
@@ -1625,7 +1626,7 @@ void World::SetInitialWorldSettings()
///- Initialize game time and timers
sLog.outDebug("DEBUG:: Initialize game time and timers");
- m_gameTime = time(NULL);
+ m_gameTime=sGameTime.GetGameTime();
m_startTime=m_gameTime;
tm local;
@@ -1637,7 +1638,7 @@ void World::SetInitialWorldSettings()
local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
loginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, startstring, uptime, revision) VALUES('%u', " UI64FMTD ", '%s', 0, '%s')",
- realmID, uint64(m_startTime), isoDate, _FULLVERSION);
+ realmID, sGameTime, isoDate, _FULLVERSION);
static uint32 abtimer = 0;
abtimer = sConfig.GetIntDefault("AutoBroadcast.Timer", 60000);
@@ -1656,7 +1657,7 @@ void World::SetInitialWorldSettings()
//to set mailtimer to return mails every day between 4 and 5 am
//mailtimer is increased when updating auctions
//one second is 1000 -(tested on win system)
- mail_timer = ((((localtime(&m_gameTime)->tm_hour + 20) % 24)* HOUR * IN_MILISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval());
+ mail_timer = ((((localtime(&sGameTime.GetGameTime())->tm_hour + 20) % 24)* HOUR * IN_MILISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval());
//1440
mail_timer_expires = ((DAY * IN_MILISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
sLog.outDebug("Mail timer set to: %u, mail return is called every %u minutes", mail_timer, mail_timer_expires);
@@ -1857,7 +1858,7 @@ void World::Update(uint32 diff)
_UpdateGameTime();
/// Handle daily quests reset time
- if (m_gameTime > m_NextDailyQuestReset)
+ if (sGameTime.GetGameTime() > m_NextDailyQuestReset)
{
ResetDailyQuests();
m_NextDailyQuestReset += DAY;
@@ -1914,7 +1915,7 @@ void World::Update(uint32 diff)
uint32 maxClientsNum = GetMaxActiveSessionCount();
m_timers[WUPDATE_UPTIME].Reset();
- loginDatabase.PExecute("UPDATE uptime SET uptime = %u, maxplayers = %u WHERE realmid = %u AND starttime = " UI64FMTD, tmpDiff, maxClientsNum, realmID, uint64(m_startTime));
+ loginDatabase.PExecute("UPDATE uptime SET uptime = %u, maxplayers = %u WHERE realmid = %u AND starttime = " UI64FMTD, tmpDiff, maxClientsNum, realmID, sGameTime);
}
/// <li> Clean logs table
@@ -1922,7 +1923,6 @@ void World::Update(uint32 diff)
{
if (m_timers[WUPDATE_CLEANDB].Passed())
{
- uint32 tmpDiff = (m_gameTime - m_startTime);
uint32 maxClientsNum = sWorld.GetMaxActiveSessionCount();
m_timers[WUPDATE_CLEANDB].Reset();
@@ -2281,9 +2281,9 @@ bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
void World::_UpdateGameTime()
{
///- update the time
- time_t thisTime = time(NULL);
- uint32 elapsed = uint32(thisTime - m_gameTime);
- m_gameTime = thisTime;
+ time_t thisTime = sGameTime.GetGameTime();
+ uint32 elapsed = uint32(thisTime - sGameTime.GetGameTime());
+ sGameTime.SetGameTime();
///- if there is a shutdown timer
if (!m_stopEvent && m_ShutdownTimer > 0 && elapsed > 0)
@@ -2412,7 +2412,7 @@ void World::UpdateSessions(uint32 diff)
if (!itr->second->Update(diff)) // As interval = 0
{
if (!RemoveQueuedPlayer(itr->second) && itr->second && getConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
- m_disconnects[itr->second->GetAccountId()] = time(NULL);
+ m_disconnects[itr->second->GetAccountId()] = sGameTime.GetGameTime();
delete itr->second;
m_sessions.erase(itr);
}
@@ -2523,7 +2523,7 @@ void World::InitDailyQuestResetTime()
// client built-in time for reset is 6:00 AM
// FIX ME: client not show day start time
- time_t curTime = time(NULL);
+ time_t curTime = sGameTime.GetGameTime();
tm localTm = *localtime(&curTime);
localTm.tm_hour = 6;
localTm.tm_min = 0;
diff --git a/src/game/World.h b/src/game/World.h
index ed16d03307a..a1e01b55b2b 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -26,7 +26,7 @@
#define __WORLD_H
#include "Common.h"
-#include "Timer.h"
+#include "TimeMgr.h"
#include "Policies/Singleton.h"
#include "SharedDefines.h"
#include "ace/Atomic_Op.h"
@@ -516,12 +516,6 @@ class World
/// Get the path where data (dbc, maps) are stored on disk
std::string GetDataPath() const { return m_dataPath; }
- /// When server started?
- time_t const& GetStartTime() const { return m_startTime; }
- /// What time is it?
- time_t const& GetGameTime() const { return m_gameTime; }
- /// Uptime (in secs)
- uint32 GetUptime() const { return uint32(m_gameTime - m_startTime); }
/// Update time
uint32 GetUpdateTime() const { return m_updateTime; }
void SetRecordDiffInterval(int32 t) { if(t >= 0) m_configs[CONFIG_INTERVAL_LOG_UPDATE] = (uint32)t; }
diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp
index 569c8fade62..bb7950de222 100644
--- a/src/game/WorldSession.cpp
+++ b/src/game/WorldSession.cpp
@@ -39,6 +39,7 @@
#include "OutdoorPvPMgr.h"
#include "MapManager.h"
#include "SocialMgr.h"
+#include "TimeMgr.h"
#include "zlib/zlib.h"
#include "ScriptCalls.h"
@@ -106,13 +107,13 @@ void WorldSession::SendPacket(WorldPacket const* packet)
static uint64 sendPacketCount = 0;
static uint64 sendPacketBytes = 0;
- static time_t firstTime = time(NULL);
+ static time_t firstTime = sGameTime.GetGameTime();
static time_t lastTime = firstTime; // next 60 secs start time
static uint64 sendLastPacketCount = 0;
static uint64 sendLastPacketBytes = 0;
- time_t cur_time = time(NULL);
+ time_t cur_time = sGameTime.GetGameTime();
if((cur_time - lastTime) < 60)
{
@@ -281,7 +282,7 @@ bool WorldSession::Update(uint32 /*diff*/)
}
///- If necessary, log the player out
- time_t currTime = time(NULL);
+ time_t currTime = sGameTime.GetGameTime();
if (!m_Socket || (ShouldLogOut(currTime) && !m_playerLoading))
LogoutPlayer(true);
@@ -658,7 +659,7 @@ void WorldSession::SetAccountData(AccountDataType type, time_t time_, std::strin
void WorldSession::SendAccountDataTimes(uint32 mask)
{
WorldPacket data( SMSG_ACCOUNT_DATA_TIMES, 4+1+4+8*4 ); // changed in WotLK
- data << uint32(time(NULL)); // unix time of something
+ data << uint32(sGameTime.GetGameTime()); // unix time of something
data << uint8(1);
data << uint32(mask); // type mask
for(uint32 i = 0; i < NUM_ACCOUNT_DATA_TYPES; ++i)
diff --git a/src/shared/Timer.h b/src/shared/Timer.h
index 46bba5475bc..d21407b8e42 100644
--- a/src/shared/Timer.h
+++ b/src/shared/Timer.h
@@ -18,21 +18,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef TRINITY_TIMER_H
-#define TRINITY_TIMER_H
+#ifndef _TIMER_H
+#define _TIMER_H
-#include "Platform/CompilerDefs.h"
+#include "Platform/Define.h"
-#if PLATFORM == PLATFORM_WINDOWS
-# include <ace/config-all.h>
-# include <mmsystem.h>
-# include <time.h>
-#else
-# if defined(__APPLE_CC__)
-# include <time.h>
-# endif
+#if (PLATFORM != PLATFORM_WINDOWS)
# include <sys/time.h>
-# include <sys/timeb.h>
#endif
#if PLATFORM == PLATFORM_WINDOWS
@@ -56,67 +48,4 @@ inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
return newMSTime - oldMSTime;
}
-class IntervalTimer
-{
- public:
- IntervalTimer() : _interval(0), _current(0) {}
-
- void Update(time_t diff) { _current += diff; if(_current<0) _current=0;}
- bool Passed() { return _current >= _interval; }
- void Reset() { if(_current >= _interval) _current -= _interval; }
-
- void SetCurrent(time_t current) { _current = current; }
- void SetInterval(time_t interval) { _interval = interval; }
- time_t GetInterval() const { return _interval; }
- time_t GetCurrent() const { return _current; }
-
- private:
- time_t _interval;
- time_t _current;
-};
-
-struct TimeTracker
-{
- TimeTracker(time_t expiry) : i_expiryTime(expiry) {}
- void Update(time_t diff) { i_expiryTime -= diff; }
- bool Passed(void) const { return (i_expiryTime <= 0); }
- void Reset(time_t interval) { i_expiryTime = interval; }
- time_t GetExpiry(void) const { return i_expiryTime; }
- time_t i_expiryTime;
-};
-
-struct TimeTrackerSmall
-{
- TimeTrackerSmall(int32 expiry) : i_expiryTime(expiry) {}
- void Update(int32 diff) { i_expiryTime -= diff; }
- bool Passed(void) const { return (i_expiryTime <= 0); }
- void Reset(int32 interval) { i_expiryTime = interval; }
- int32 GetExpiry(void) const { return i_expiryTime; }
- int32 i_expiryTime;
-};
-
-struct PeriodicTimer
-{
- PeriodicTimer(int32 period, int32 start_time) :
- i_expireTime(start_time), i_period(period) {}
-
- bool Update(const uint32 &diff)
- {
- if((i_expireTime -= diff) > 0)
- return false;
-
- i_expireTime += i_period > diff ? i_period : diff;
- return true;
- }
-
- void SetPeriodic(int32 period, int32 start_time)
- {
- i_expireTime=start_time, i_period=period;
- }
-
- int32 i_period;
- int32 i_expireTime;
-};
-
#endif
-
diff --git a/win/VC90/game.vcproj b/win/VC90/game.vcproj
index 41888f323e2..58e2a7f21bb 100644
--- a/win/VC90/game.vcproj
+++ b/win/VC90/game.vcproj
@@ -1219,6 +1219,14 @@
>
</File>
<File
+ RelativePath="..\..\src\game\TimeMgr.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\game\TimeMgr.h"
+ >
+ </File>
+ <File
RelativePath="..\..\src\game\Totem.cpp"
>
</File>