diff --git a/Source/Framework/Constants/SharedConst.cs b/Source/Framework/Constants/SharedConst.cs index 80cf3c04c..1bd411eef 100644 --- a/Source/Framework/Constants/SharedConst.cs +++ b/Source/Framework/Constants/SharedConst.cs @@ -1170,7 +1170,6 @@ namespace Framework.Constants IntervalChangeweather, IntervalDisconnectTolerance, IntervalGridclean, - IntervalLogUpdate, IntervalMapupdate, IntervalSave, IpBasedActionLogging, @@ -1194,7 +1193,6 @@ namespace Framework.Constants MinCharterName, MinDualspecLevel, MinLevelStatSave, - MinLogUpdate, MinPetName, MinPetitionSigns, MinPlayerName, diff --git a/Source/Game/AuctionHouse/AuctionManager.cs b/Source/Game/AuctionHouse/AuctionManager.cs index 071339893..088bb01bd 100644 --- a/Source/Game/AuctionHouse/AuctionManager.cs +++ b/Source/Game/AuctionHouse/AuctionManager.cs @@ -438,7 +438,7 @@ namespace Game public void Update() { - long curTime = Global.WorldMgr.GetGameTime(); + long curTime = GameTime.GetGameTime(); // Handle expired auctions // If storage is empty, no need to update. next == NULL in this case. @@ -507,7 +507,7 @@ namespace Game public void BuildListAuctionItems(AuctionListItemsResult packet, Player player, string searchedname, uint listfrom, byte levelmin, byte levelmax, bool usable, Optional filters, uint quality) { - long curTime = Global.WorldMgr.GetGameTime(); + long curTime = GameTime.GetGameTime(); foreach (var Aentry in AuctionsMap.Values) { diff --git a/Source/Game/BattleGrounds/BattleGround.cs b/Source/Game/BattleGrounds/BattleGround.cs index 0368c8aa2..964bdd876 100644 --- a/Source/Game/BattleGrounds/BattleGround.cs +++ b/Source/Game/BattleGrounds/BattleGround.cs @@ -206,7 +206,7 @@ namespace Game.BattleGrounds var bgPlayer = m_Players.LookupByKey(guid); if (bgPlayer != null) { - if (bgPlayer.OfflineRemoveTime <= Global.WorldMgr.GetGameTime()) + if (bgPlayer.OfflineRemoveTime <= GameTime.GetGameTime()) { RemovePlayerAtLeave(guid, true, true);// remove player from BG m_OfflineQueue.RemoveAt(0); // remove from offline queue @@ -1113,7 +1113,7 @@ namespace Game.BattleGrounds // player is correct pointer, it is checked in WorldSession.LogoutPlayer() m_OfflineQueue.Add(player.GetGUID()); - m_Players[guid].OfflineRemoveTime = Global.WorldMgr.GetGameTime() + BattlegroundConst.MaxOfflineTime; + m_Players[guid].OfflineRemoveTime = GameTime.GetGameTime() + BattlegroundConst.MaxOfflineTime; if (GetStatus() == BattlegroundStatus.InProgress) { // drop flag and handle other cleanups diff --git a/Source/Game/BattleGrounds/BattleGroundQueue.cs b/Source/Game/BattleGrounds/BattleGroundQueue.cs index 48cb06d5e..9e122249e 100644 --- a/Source/Game/BattleGrounds/BattleGroundQueue.cs +++ b/Source/Game/BattleGrounds/BattleGroundQueue.cs @@ -66,7 +66,7 @@ namespace Game.BattleGrounds ginfo.ArenaTeamId = arenateamid; ginfo.IsRated = isRated; ginfo.IsInvitedToBGInstanceGUID = 0; - ginfo.JoinTime = Time.GetMSTime(); + ginfo.JoinTime = GameTime.GetGameTimeMS(); ginfo.RemoveInviteTime = 0; ginfo.Team = leader.GetTeam(); ginfo.ArenaTeamRating = ArenaRating; @@ -84,7 +84,7 @@ namespace Game.BattleGrounds index++; Log.outDebug(LogFilter.Battleground, "Adding Group to BattlegroundQueue bgTypeId : {0}, bracket_id : {1}, index : {2}", BgTypeId, bracketId, index); - uint lastOnlineTime = Time.GetMSTime(); + uint lastOnlineTime = GameTime.GetGameTimeMS(); //announce world (this don't need mutex) if (isRated && WorldConfig.GetBoolValue(WorldCfg.ArenaQueueAnnouncerEnable)) @@ -169,7 +169,7 @@ namespace Game.BattleGrounds void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo ginfo, BattlegroundBracketId bracket_id) { - uint timeInQueue = Time.GetMSTimeDiff(ginfo.JoinTime, Time.GetMSTime()); + uint timeInQueue = Time.GetMSTimeDiff(ginfo.JoinTime, GameTime.GetGameTimeMS()); uint team_index = TeamId.Alliance; //default set to TeamIndex.Alliance - or non rated arenas! if (ginfo.ArenaType == 0) { @@ -388,7 +388,7 @@ namespace Game.BattleGrounds if (bg.isArena() && bg.isRated()) bg.SetArenaTeamIdForTeam(ginfo.Team, ginfo.ArenaTeamId); - ginfo.RemoveInviteTime = Time.GetMSTime() + BattlegroundConst.InviteAcceptWaitTime; + ginfo.RemoveInviteTime = GameTime.GetGameTimeMS() + BattlegroundConst.InviteAcceptWaitTime; // loop through the players foreach (var guid in ginfo.Players.Keys) @@ -586,7 +586,7 @@ namespace Game.BattleGrounds // this could be 2 cycles but i'm checking only first team in queue - it can cause problem - // if first is invited to BG and seconds timer expired, but we can ignore it, because players have only 80 seconds to click to enter bg // and when they click or after 80 seconds the queue info is removed from queue - uint time_before = (uint)(Time.GetMSTime() - WorldConfig.GetIntValue(WorldCfg.BattlegroundPremadeGroupWaitForMatch)); + uint time_before = (uint)(GameTime.GetGameTimeMS() - WorldConfig.GetIntValue(WorldCfg.BattlegroundPremadeGroupWaitForMatch)); for (uint i = 0; i < SharedConst.BGTeamsCount; i++) { if (!m_QueuedGroups[(int)bracket_id][BattlegroundConst.BgQueuePremadeAlliance + i].Empty()) @@ -881,7 +881,7 @@ namespace Game.BattleGrounds // (after what time the ratings aren't taken into account when making teams) then // the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account // else leave the discard time on 0, this way all ratings will be discarded - int discardTime = (int)(Time.GetMSTime() - Global.BattlegroundMgr.GetRatingDiscardTimer()); + int discardTime = (int)(GameTime.GetGameTimeMS() - Global.BattlegroundMgr.GetRatingDiscardTimer()); // we need to find 2 teams which will play next game GroupQueueInfo[] queueArray = new GroupQueueInfo[SharedConst.BGTeamsCount]; diff --git a/Source/Game/BattleGrounds/Zones/StrandofAncients.cs b/Source/Game/BattleGrounds/Zones/StrandofAncients.cs index ead79249e..3fff51033 100644 --- a/Source/Game/BattleGrounds/Zones/StrandofAncients.cs +++ b/Source/Game/BattleGrounds/Zones/StrandofAncients.cs @@ -1008,11 +1008,11 @@ namespace Game.BattleGrounds.Zones // Demolisher is not in list if (!DemoliserRespawnList.ContainsKey(i)) { - DemoliserRespawnList[i] = Time.GetMSTime() + 30000; + DemoliserRespawnList[i] = GameTime.GetGameTimeMS() + 30000; } else { - if (DemoliserRespawnList[i] < Time.GetMSTime()) + if (DemoliserRespawnList[i] < GameTime.GetGameTimeMS()) { Demolisher.Relocate(SAMiscConst.NpcSpawnlocs[i]); Demolisher.Respawn(); diff --git a/Source/Game/Chat/Commands/ServerCommands.cs b/Source/Game/Chat/Commands/ServerCommands.cs index 744041611..905d416ab 100644 --- a/Source/Game/Chat/Commands/ServerCommands.cs +++ b/Source/Game/Chat/Commands/ServerCommands.cs @@ -49,8 +49,8 @@ namespace Game.Chat int queuedClientsNum = Global.WorldMgr.GetQueuedSessionCount(); uint maxActiveClientsNum = Global.WorldMgr.GetMaxActiveSessionCount(); uint maxQueuedClientsNum = Global.WorldMgr.GetMaxQueuedSessionCount(); - string uptime = Time.secsToTimeString(Global.WorldMgr.GetUptime()); - uint updateTime = Global.WorldMgr.GetUpdateTime(); + string uptime = Time.secsToTimeString(GameTime.GetUptime()); + uint updateTime = Global.WorldMgr.GetWorldUpdateTime().GetLastUpdateTime(); handler.SendSysMessage(CypherStrings.ConnectedPlayers, playersNum, maxPlayersNum); handler.SendSysMessage(CypherStrings.ConnectedUsers, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum); diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index db82597c1..9195d0aed 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -2082,7 +2082,7 @@ namespace Game.Entities return true; // don't check distance to home position if recently damaged, this should include taunt auras - if (!isWorldBoss() && (GetLastDamagedTime() > Global.WorldMgr.GetGameTime() || HasAuraType(AuraType.ModTaunt))) + if (!isWorldBoss() && (GetLastDamagedTime() > GameTime.GetGameTime() || HasAuraType(AuraType.ModTaunt))) return true; } @@ -2824,7 +2824,7 @@ namespace Game.Entities ClearUnitState(UnitState.CannotTurn); _focusSpell = null; - _focusDelay = (!IsPet() && withDelay) ? Time.GetMSTime() : 0; // don't allow re-target right away to prevent visual bugs + _focusDelay = (!IsPet() && withDelay) ? GameTime.GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs } public void MustReacquireTarget() { m_shouldReacquireTarget = true; } // flags the Creature for forced (client displayed) target reacquisition in the next Update call diff --git a/Source/Game/Entities/DynamicObject.cs b/Source/Game/Entities/DynamicObject.cs index 461cc552a..95dda4e01 100644 --- a/Source/Game/Entities/DynamicObject.cs +++ b/Source/Game/Entities/DynamicObject.cs @@ -97,7 +97,7 @@ namespace Game.Entities SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.SpellXSpellVisualID), spellXSpellVisualId); SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.SpellID), spell.Id); SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.Radius), radius); - SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.CastTime), Time.GetMSTime()); + SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.CastTime), GameTime.GetGameTimeMS()); if (IsWorldObject()) setActive(true); //must before add to map to be put in world container diff --git a/Source/Game/Entities/GameObject/GameObject.cs b/Source/Game/Entities/GameObject/GameObject.cs index 5ce3026e1..543b4dceb 100644 --- a/Source/Game/Entities/GameObject/GameObject.cs +++ b/Source/Game/Entities/GameObject/GameObject.cs @@ -422,11 +422,11 @@ namespace Game.Entities // Bombs Unit owner = GetOwner(); if (goInfo.Trap.charges == 2) - m_cooldownTime = (uint)Time.UnixTime + 10; // Hardcoded tooltip value + m_cooldownTime = GameTime.GetGameTimeMS() + 10 * Time.InMilliseconds; // Hardcoded tooltip value else if (owner) { if (owner.IsInCombat()) - m_cooldownTime = (uint)Time.UnixTime + goInfo.Trap.startDelay; + m_cooldownTime = GameTime.GetGameTimeMS() + goInfo.Trap.startDelay * Time.InMilliseconds; } m_lootState = LootState.Ready; break; @@ -589,7 +589,7 @@ namespace Game.Entities uint max_charges; if (goInfo.type == GameObjectTypes.Trap) { - if (m_cooldownTime >= Time.UnixTime) + if (GameTime.GetGameTimeMS() < m_cooldownTime) break; // Type 2 (bomb) does not need to be triggered by a unit and despawns after casting its spell. @@ -654,11 +654,11 @@ namespace Game.Entities { case GameObjectTypes.Door: case GameObjectTypes.Button: - if (GetGoInfo().GetAutoCloseTime() != 0 && (m_cooldownTime < Time.UnixTime)) + if (m_cooldownTime != 0 && GameTime.GetGameTimeMS() >= m_cooldownTime) ResetDoorOrButton(); break; case GameObjectTypes.Goober: - if (m_cooldownTime < Time.UnixTime) + if (GameTime.GetGameTimeMS() >= m_cooldownTime) { RemoveFlag(GameObjectFlags.InUse); @@ -699,7 +699,7 @@ namespace Game.Entities CastSpell(target, goInfo.Trap.spell); // Template value or 4 seconds - m_cooldownTime = (uint)(Time.UnixTime + (goInfo.Trap.cooldown != 0 ? goInfo.Trap.cooldown : 4u)); + m_cooldownTime = (GameTime.GetGameTimeMS() + (goInfo.Trap.cooldown != 0 ? goInfo.Trap.cooldown : 4u)) * Time.InMilliseconds; if (goInfo.Trap.charges == 1) SetLootState(LootState.JustDeactivated); @@ -1258,7 +1258,7 @@ namespace Game.Entities SwitchDoorOrButton(true, alternative); SetLootState(LootState.Activated, user); - m_cooldownTime = time_to_restore != 0 ? (uint)Time.UnixTime + time_to_restore : 0; + m_cooldownTime = time_to_restore != 0 ? GameTime.GetGameTimeMS() + time_to_restore : 0; } public void SetGoArtKit(byte kit) @@ -1318,10 +1318,10 @@ namespace Game.Entities uint cooldown = GetGoInfo().GetCooldown(); if (cooldown != 0) { - if (m_cooldownTime > Global.WorldMgr.GetGameTime()) + if (m_cooldownTime > GameTime.GetGameTime()) return; - m_cooldownTime = (uint)(Global.WorldMgr.GetGameTime() + cooldown); + m_cooldownTime = GameTime.GetGameTimeMS() + cooldown * Time.InMilliseconds; } switch (GetGoType()) @@ -1348,7 +1348,7 @@ namespace Game.Entities if (goInfo.Trap.spell != 0) CastSpell(user, goInfo.Trap.spell); - m_cooldownTime = (uint)Time.UnixTime + (goInfo.Trap.cooldown != 0 ? goInfo.Trap.cooldown : 4); // template or 4 seconds + m_cooldownTime = GameTime.GetGameTimeMS() + (goInfo.Trap.cooldown != 0 ? goInfo.Trap.cooldown : 4) * Time.InMilliseconds; // template or 4 seconds if (goInfo.Trap.charges == 1) // Deactivate after trigger SetLootState(LootState.JustDeactivated); @@ -1505,7 +1505,7 @@ namespace Game.Entities else SetGoState(GameObjectState.Active); - m_cooldownTime = (uint)Time.UnixTime + info.GetAutoCloseTime(); + m_cooldownTime = GameTime.GetGameTimeMS() + info.GetAutoCloseTime(); // cast this spell later if provided spellId = info.Goober.spell; diff --git a/Source/Game/Entities/GameObject/GameObjectData.cs b/Source/Game/Entities/GameObject/GameObjectData.cs index 86c6aeffb..810958919 100644 --- a/Source/Game/Entities/GameObject/GameObjectData.cs +++ b/Source/Game/Entities/GameObject/GameObjectData.cs @@ -373,7 +373,7 @@ namespace Game.Entities default: break; } - return autoCloseTime / Time.InMilliseconds; // prior to 3.0.3, conversion was / 0x10000; + return autoCloseTime; // prior to 3.0.3, conversion was / 0x10000; } public uint GetLootId() diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 08a9c53ed..65a6a6920 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -382,7 +382,7 @@ namespace Game.Entities if (go1 && go1.ToTransport()) // ServerTime data.WriteUInt32(go1.GetGoValue().Transport.PathProgress); else - data.WriteUInt32(Time.GetMSTime()); + data.WriteUInt32(GameTime.GetGameTimeMS()); } if (flags.Vehicle) diff --git a/Source/Game/Entities/Player/Player.DB.cs b/Source/Game/Entities/Player/Player.DB.cs index ad1a76970..75c7cb9b6 100644 --- a/Source/Game/Entities/Player/Player.DB.cs +++ b/Source/Game/Entities/Player/Player.DB.cs @@ -694,10 +694,10 @@ namespace Game.Entities { AddTimedQuest(quest_id); - if (quest_time <= Global.WorldMgr.GetGameTime()) + if (quest_time <= GameTime.GetGameTime()) questStatusData.Timer = 1; else - questStatusData.Timer = (uint)((quest_time - Global.WorldMgr.GetGameTime()) * Time.InMilliseconds); + questStatusData.Timer = (uint)((quest_time - GameTime.GetGameTime()) * Time.InMilliseconds); } else quest_time = 0; @@ -1824,7 +1824,7 @@ namespace Game.Entities stmt.AddValue(0, GetGUID().GetCounter()); stmt.AddValue(1, save.Key); stmt.AddValue(2, data.Status); - stmt.AddValue(3, data.Timer / Time.InMilliseconds + Global.WorldMgr.GetGameTime()); + stmt.AddValue(3, data.Timer / Time.InMilliseconds + GameTime.GetGameTime()); trans.Append(stmt); // Save objectives diff --git a/Source/Game/Entities/Player/Player.Items.cs b/Source/Game/Entities/Player/Player.Items.cs index b3871ce88..5418379e7 100644 --- a/Source/Game/Entities/Player/Player.Items.cs +++ b/Source/Game/Entities/Player/Player.Items.cs @@ -4309,7 +4309,7 @@ namespace Game.Entities if (proto.GetFlags().HasAnyFlag(ItemFlags.NoEquipCooldown)) return; - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSteadyPoint(); for (byte i = 0; i < proto.Effects.Count; ++i) { var effectData = proto.Effects[i]; diff --git a/Source/Game/Entities/Player/Player.Talents.cs b/Source/Game/Entities/Player/Player.Talents.cs index fb7a1e475..afa992eb0 100644 --- a/Source/Game/Entities/Player/Player.Talents.cs +++ b/Source/Game/Entities/Player/Player.Talents.cs @@ -446,7 +446,7 @@ namespace Game.Entities return 10 * MoneyConstants.Gold; else { - ulong months = (ulong)(Global.WorldMgr.GetGameTime() - GetTalentResetTime()) / Time.Month; + ulong months = (ulong)(GameTime.GetGameTime() - GetTalentResetTime()) / Time.Month; if (months > 0) { // This cost will be reduced by a rate of 5 gold per month diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 37bfeaac9..e468d4258 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -72,6 +72,8 @@ namespace Game.Entities m_logintime = Time.UnixTime; m_Last_tick = m_logintime; + m_timeSyncServer = GameTime.GetGameTimeMS(); + m_dungeonDifficulty = Difficulty.Normal; m_raidDifficulty = Difficulty.NormalRaid; m_legacyRaidDifficulty = Difficulty.Raid10N; @@ -451,7 +453,7 @@ namespace Game.Entities _cinematicMgr.m_cinematicDiff += diff; if (_cinematicMgr.m_activeCinematicCameraId != 0 && Time.GetMSTimeDiffToNow(_cinematicMgr.m_lastCinematicCheck) > 500) { - _cinematicMgr.m_lastCinematicCheck = Time.GetMSTime(); + _cinematicMgr.m_lastCinematicCheck = GameTime.GetGameTimeMS(); _cinematicMgr.UpdateCinematicLocation(diff); } @@ -951,7 +953,7 @@ namespace Game.Entities { m_timeSyncTimer = 0; m_timeSyncClient = 0; - m_timeSyncServer = Time.GetMSTime(); + m_timeSyncServer = GameTime.GetGameTimeMS(); } void SendTimeSync() { @@ -963,7 +965,7 @@ namespace Game.Entities // Schedule next sync in 10 sec m_timeSyncTimer = 10000; - m_timeSyncServer = Time.GetMSTime(); + m_timeSyncServer = GameTime.GetGameTimeMS(); if (m_timeSyncQueue.Count > 3) Log.outError(LogFilter.Network, "Not received CMSG_TIME_SYNC_RESP for over 30 seconds from player {0} ({1}), possible cheater", GetGUID().ToString(), GetName()); @@ -5640,8 +5642,8 @@ namespace Game.Entities float TimeSpeed = 0.01666667f; LoginSetTimeSpeed loginSetTimeSpeed = new LoginSetTimeSpeed(); loginSetTimeSpeed.NewSpeed = TimeSpeed; - loginSetTimeSpeed.GameTime = (uint)Global.WorldMgr.GetGameTime(); - loginSetTimeSpeed.ServerTime = (uint)Global.WorldMgr.GetGameTime(); + loginSetTimeSpeed.GameTime = (uint)GameTime.GetGameTime(); + loginSetTimeSpeed.ServerTime = (uint)GameTime.GetGameTime(); loginSetTimeSpeed.GameTimeHolidayOffset = 0; // @todo loginSetTimeSpeed.ServerTimeHolidayOffset = 0; // @todo SendPacket(loginSetTimeSpeed); diff --git a/Source/Game/Entities/Unit/Unit.Combat.cs b/Source/Game/Entities/Unit/Unit.Combat.cs index 829586355..161b7badc 100644 --- a/Source/Game/Entities/Unit/Unit.Combat.cs +++ b/Source/Game/Entities/Unit/Unit.Combat.cs @@ -1104,7 +1104,7 @@ namespace Game.Entities { // Part of Evade mechanics. DoT's and Thorns / Retribution Aura do not contribute to this if (damagetype != DamageEffectType.DOT && damage > 0 && !victim.GetOwnerGUID().IsPlayer() && (spellProto == null || !spellProto.HasAura(GetMap().GetDifficultyID(), AuraType.DamageShield))) - victim.ToCreature().SetLastDamagedTime(Global.WorldMgr.GetGameTime() + SharedConst.MaxAggroResetTime); + victim.ToCreature().SetLastDamagedTime(GameTime.GetGameTime() + SharedConst.MaxAggroResetTime); victim.AddThreat(this, damage, damageSchoolMask, spellProto); } diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index 8a6a044a6..f5c4c5f31 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -1809,7 +1809,7 @@ namespace Game.Entities void GetProcAurasTriggeredOnEvent(List> aurasTriggeringProc, List procAuras, ProcEventInfo eventInfo) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSteadyPoint(); // use provided list of auras which can proc if (procAuras != null) @@ -2788,7 +2788,7 @@ namespace Game.Entities // Remember time after last aura from group removed if (diminish.Stack == 0) - diminish.HitTime = Time.GetMSTime(); + diminish.HitTime = GameTime.GetGameTimeMS(); } } diff --git a/Source/Game/Handlers/CharacterHandler.cs b/Source/Game/Handlers/CharacterHandler.cs index cc94b613c..c52c20663 100644 --- a/Source/Game/Handlers/CharacterHandler.cs +++ b/Source/Game/Handlers/CharacterHandler.cs @@ -663,7 +663,7 @@ namespace Game AccountDataTimes accountDataTimes = new AccountDataTimes(); accountDataTimes.PlayerGuid = playerGuid; - accountDataTimes.ServerTime = (uint)Global.WorldMgr.GetGameTime(); + accountDataTimes.ServerTime = (uint)GameTime.GetGameTime(); for (AccountDataTypes i = 0; i < AccountDataTypes.Max; ++i) accountDataTimes.AccountTimes[(int)i] = (uint)GetAccountData(i).Time; @@ -759,7 +759,7 @@ namespace Game stmt.AddValue(0, GetAccountId()); DB.Login.Execute(stmt); - pCurrChar.SetInGameTime(Time.GetMSTime()); + pCurrChar.SetInGameTime(GameTime.GetGameTimeMS()); // announce group about member online (must be after add to player list to receive announce to self) Group group = pCurrChar.GetGroup(); diff --git a/Source/Game/Handlers/HotfixHandler.cs b/Source/Game/Handlers/HotfixHandler.cs index 5e6332906..63c8e2d2d 100644 --- a/Source/Game/Handlers/HotfixHandler.cs +++ b/Source/Game/Handlers/HotfixHandler.cs @@ -44,7 +44,7 @@ namespace Game if (store.HasRecord(record.RecordID)) { dbReply.Allow = true; - dbReply.Timestamp = (uint)Global.WorldMgr.GetGameTime(); + dbReply.Timestamp = (uint)GameTime.GetGameTime(); store.WriteRecord(record.RecordID, GetSessionDbcLocale(), dbReply.Data); } else diff --git a/Source/Game/Handlers/MovementHandler.cs b/Source/Game/Handlers/MovementHandler.cs index 02efc40a1..fa8d83721 100644 --- a/Source/Game/Handlers/MovementHandler.cs +++ b/Source/Game/Handlers/MovementHandler.cs @@ -146,7 +146,7 @@ namespace Game plrMover.SetInWater(!plrMover.IsInWater() || plrMover.GetMap().IsUnderWater(plrMover.GetPhaseShift(), movementInfo.Pos.posX, movementInfo.Pos.posY, movementInfo.Pos.posZ)); } - uint mstime = Time.GetMSTime(); + uint mstime = GameTime.GetGameTimeMS(); if (m_clientTimeDelay == 0) m_clientTimeDelay = mstime - movementInfo.Time; diff --git a/Source/Game/Handlers/TimeHandler.cs b/Source/Game/Handlers/TimeHandler.cs index d77da5db5..98a956e04 100644 --- a/Source/Game/Handlers/TimeHandler.cs +++ b/Source/Game/Handlers/TimeHandler.cs @@ -42,7 +42,7 @@ namespace Game Log.outDebug(LogFilter.Network, "Time sync received: counter {0}, client ticks {1}, time since last sync {2}", packet.SequenceIndex, packet.ClientTime, packet.ClientTime - _player.m_timeSyncClient); - uint ourTicks = packet.ClientTime + (Time.GetMSTime() - _player.m_timeSyncServer); + uint ourTicks = packet.ClientTime + (GameTime.GetGameTimeMS() - _player.m_timeSyncServer); // diff should be small Log.outDebug(LogFilter.Network, "Our ticks: {0}, diff {1}, latency {2}", ourTicks, ourTicks - packet.ClientTime, GetLatency()); diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index 4219d4d60..8e113c901 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -3446,7 +3446,7 @@ namespace Game.Maps sa.ownerGUID = ownerGUID; sa.script = script.Value; - m_scriptSchedule.Add(Global.WorldMgr.GetGameTime() + script.Key, sa); + m_scriptSchedule.Add(GameTime.GetGameTime() + script.Key, sa); if (script.Key == 0) immedScript = true; @@ -3476,7 +3476,7 @@ namespace Game.Maps sa.ownerGUID = ownerGUID; sa.script = script; - m_scriptSchedule.Add(Global.WorldMgr.GetGameTime() + delay, sa); + m_scriptSchedule.Add(GameTime.GetGameTime() + delay, sa); Global.MapMgr.IncreaseScheduledScriptsCount(); @@ -3674,7 +3674,7 @@ namespace Game.Maps // Process overdue queued scripts KeyValuePair iter = m_scriptSchedule.First(); - while (!m_scriptSchedule.Empty() && (iter.Key <= Global.WorldMgr.GetGameTime())) + while (!m_scriptSchedule.Empty() && (iter.Key <= GameTime.GetGameTime())) { ScriptAction step = iter.Value; diff --git a/Source/Game/Server/WorldConfig.cs b/Source/Game/Server/WorldConfig.cs index d0353ad90..5df96f04b 100644 --- a/Source/Game/Server/WorldConfig.cs +++ b/Source/Game/Server/WorldConfig.cs @@ -806,8 +806,6 @@ namespace Game Values[WorldCfg.ShowKickInWorld] = GetDefaultValue("ShowKickInWorld", false); Values[WorldCfg.ShowMuteInWorld] = GetDefaultValue("ShowMuteInWorld", false); Values[WorldCfg.ShowBanInWorld] = GetDefaultValue("ShowBanInWorld", false); - Values[WorldCfg.IntervalLogUpdate] = GetDefaultValue("RecordUpdateTimeDiffInterval", 60000); - Values[WorldCfg.MinLogUpdate] = GetDefaultValue("MinRecordUpdateTimeDiff", 100); Values[WorldCfg.Numthreads] = GetDefaultValue("MapUpdate.Threads", 1); Values[WorldCfg.MaxResultsLookupCommands] = GetDefaultValue("Command.LookupMaxResults", 0); diff --git a/Source/Game/Server/WorldManager.cs b/Source/Game/Server/WorldManager.cs index 91564375a..aa5817fb2 100644 --- a/Source/Game/Server/WorldManager.cs +++ b/Source/Game/Server/WorldManager.cs @@ -43,10 +43,10 @@ namespace Game m_timers[timer] = new IntervalTimer(); m_allowedSecurityLevel = AccountTypes.Player; - m_gameTime = Time.UnixTime; - m_startTime = m_gameTime; _realm = new Realm(); + + _worldUpdateTime = new WorldUpdateTime(); } public Player FindPlayerInZone(uint zone) @@ -841,10 +841,9 @@ namespace Game // Initialize game time and timers Log.outInfo(LogFilter.ServerLoading, "Initialize game time and timers"); - m_gameTime = Time.UnixTime; - m_startTime = m_gameTime; + GameTime.UpdateGameTimers(); - DB.Login.Execute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES({0}, {1}, 0, '{2}')", _realm.Id.Realm, m_startTime, ""); // One-time query + DB.Login.Execute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES({0}, {1}, 0, '{2}')", _realm.Id.Realm, GameTime.GetStartTime(), ""); // One-time query m_timers[WorldTimers.Auctions].SetInterval(Time.Minute * Time.InMilliseconds); m_timers[WorldTimers.AuctionsPending].SetInterval(250); @@ -871,7 +870,7 @@ namespace Game //mailtimer is increased when updating auctions //one second is 1000 -(tested on win system) // @todo Get rid of magic numbers - var localTime = Time.UnixTimeToDateTime(m_gameTime).ToLocalTime(); + var localTime = Time.UnixTimeToDateTime(GameTime.GetGameTime()).ToLocalTime(); mail_timer = ((((localTime.Hour + 20) % 24) * Time.Hour * Time.InMilliseconds) / m_timers[WorldTimers.Auctions].GetInterval()); //1440 mail_timer_expires = ((Time.Day * Time.InMilliseconds) / (m_timers[(int)WorldTimers.Auctions].GetInterval())); @@ -1091,28 +1090,6 @@ namespace Game Log.outInfo(LogFilter.ServerLoading, @"VMap data directory is: {0}\vmaps", GetDataPath()); } - void ResetTimeDiffRecord() - { - if (m_updateTimeCount != 1) - return; - - m_currentTime = Time.GetMSTime(); - } - - void RecordTimeDiff(string text) - { - if (m_updateTimeCount != 1) - return; - - uint thisTime = Time.GetMSTime(); - uint diff = Time.GetMSTimeDiff(m_currentTime, thisTime); - - if (diff > WorldConfig.GetIntValue(WorldCfg.MinLogUpdate)) - Log.outInfo(LogFilter.Server, "Difftime {0}: {1}.", text, diff); - - m_currentTime = thisTime; - } - public void LoadAutobroadcasts() { uint oldMSTime = Time.GetMSTime(); @@ -1142,22 +1119,14 @@ namespace Game public void Update(uint diff) { - m_updateTime = diff; + ///- Update the game time and check for shutdown time + _UpdateGameTime(); + long currentGameTime = GameTime.GetGameTime(); - if (diff > 100) - { - if (m_updateTimeSum > 60000) - { - Log.outDebug(LogFilter.Server, "Update time diff: {0}. Players online: {1}.", m_updateTimeSum / m_updateTimeCount, GetActiveSessionCount()); - m_updateTimeSum = m_updateTime; - m_updateTimeCount = 1; - } - else - { - m_updateTimeSum += m_updateTime; - ++m_updateTimeCount; - } - } + _worldUpdateTime.UpdateWithDiff(diff); + + // Record update if recording set in log and diff is greater then minimum set in log + _worldUpdateTime.RecordUpdateTime(GameTime.GetGameTimeMS(), diff, (uint)GetActiveSessionCount()); // Update the different timers for (WorldTimers i = 0; i < WorldTimers.Max; ++i) @@ -1175,31 +1144,28 @@ namespace Game Global.WhoListStorageMgr.Update(); } - // Update the game time and check for shutdown time - _UpdateGameTime(); - // Handle daily quests reset time - if (m_gameTime > m_NextDailyQuestReset) + if (currentGameTime > m_NextDailyQuestReset) { DailyReset(); InitDailyQuestResetTime(false); } // Handle weekly quests reset time - if (m_gameTime > m_NextWeeklyQuestReset) + if (currentGameTime > m_NextWeeklyQuestReset) ResetWeeklyQuests(); // Handle monthly quests reset time - if (m_gameTime > m_NextMonthlyQuestReset) + if (currentGameTime > m_NextMonthlyQuestReset) ResetMonthlyQuests(); - if (m_gameTime > m_NextRandomBGReset) + if (currentGameTime > m_NextRandomBGReset) ResetRandomBG(); - if (m_gameTime > m_NextGuildReset) + if (currentGameTime > m_NextGuildReset) ResetGuildCap(); - if (m_gameTime > m_NextCurrencyReset) + if (currentGameTime > m_NextCurrencyReset) ResetCurrencyWeekCap(); //Handle auctions when the timer has passed @@ -1243,14 +1209,14 @@ namespace Game } //Handle session updates when the timer has passed - ResetTimeDiffRecord(); + _worldUpdateTime.RecordUpdateTimeReset(); UpdateSessions(diff); - RecordTimeDiff("UpdateSessions"); + _worldUpdateTime.RecordUpdateTimeDuration("UpdateSessions"); //
  • Update uptime table if (m_timers[WorldTimers.UpTime].Passed()) { - uint tmpDiff = (uint)(m_gameTime - m_startTime); + uint tmpDiff = GameTime.GetUptime(); uint maxOnlinePlayers = GetMaxPlayerCount(); m_timers[WorldTimers.UpTime].Reset(); @@ -1260,7 +1226,7 @@ namespace Game stmt.AddValue(0, tmpDiff); stmt.AddValue(1, maxOnlinePlayers); stmt.AddValue(2, _realm.Id.Realm); - stmt.AddValue(3, m_startTime); + stmt.AddValue(3, (uint)GameTime.GetStartTime()); DB.Login.Execute(stmt); } @@ -1281,9 +1247,9 @@ namespace Game } } - ResetTimeDiffRecord(); + _worldUpdateTime.RecordUpdateTimeReset(); Global.MapMgr.Update(diff); - RecordTimeDiff("UpdateMapMgr"); + _worldUpdateTime.RecordUpdateTimeDuration("UpdateMapMgr"); if (WorldConfig.GetBoolValue(WorldCfg.AutoBroadcast)) { @@ -1295,13 +1261,13 @@ namespace Game } Global.BattlegroundMgr.Update(diff); - RecordTimeDiff("UpdateBattlegroundMgr"); + _worldUpdateTime.RecordUpdateTimeDuration("UpdateBattlegroundMgr"); Global.OutdoorPvPMgr.Update(diff); - RecordTimeDiff("UpdateOutdoorPvPMgr"); + _worldUpdateTime.RecordUpdateTimeDuration("UpdateOutdoorPvPMgr"); Global.BattleFieldMgr.Update(diff); - RecordTimeDiff("BattlefieldMgr"); + _worldUpdateTime.RecordUpdateTimeDuration("BattlefieldMgr"); //- Delete all characters which have been deleted X days before if (m_timers[WorldTimers.DeleteChars].Passed()) @@ -1311,14 +1277,14 @@ namespace Game } Global.LFGMgr.Update(diff); - RecordTimeDiff("UpdateLFGMgr"); + _worldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr"); Global.GroupMgr.Update(diff); - RecordTimeDiff("GroupMgr"); + _worldUpdateTime.RecordUpdateTimeDuration("GroupMgr"); // execute callbacks from sql queries that were queued recently ProcessQueryCallbacks(); - RecordTimeDiff("ProcessQueryCallbacks"); + _worldUpdateTime.RecordUpdateTimeDuration("ProcessQueryCallbacks"); // Erase corpses once every 20 minutes if (m_timers[WorldTimers.Corpses].Passed()) @@ -1647,9 +1613,10 @@ namespace Game void _UpdateGameTime() { // update the time - long thisTime = Time.UnixTime; - uint elapsed = (uint)(thisTime - m_gameTime); - m_gameTime = thisTime; + long lastGameTime = GameTime.GetGameTime(); + GameTime.UpdateGameTimers(); + + uint elapsed = (uint)(GameTime.GetGameTime() - lastGameTime); //- if there is a shutdown timer if (!IsStopped && m_ShutdownTimer > 0 && elapsed > 0) @@ -2218,15 +2185,6 @@ namespace Game public void SetDataPath(string path) { _dataPath = path; } - // When server started? - long GetStartTime() { return m_startTime; } - // What time is it? - public long GetGameTime() { return m_gameTime; } - // Uptime (in secs) - public uint GetUptime() { return (uint)(m_gameTime - m_startTime); } - // Update time - public uint GetUpdateTime() { return m_updateTime; } - public long GetNextDailyQuestsResetTime() { return m_NextDailyQuestReset; } public long GetNextWeeklyQuestsResetTime() { return m_NextWeeklyQuestReset; } long GetNextRandomBGResetTime() { return m_NextRandomBGReset; } @@ -2310,6 +2268,8 @@ namespace Game public CleaningFlags GetCleaningFlags() { return m_CleaningFlags; } public void SetCleaningFlags(CleaningFlags flags) { m_CleaningFlags = flags; } + public WorldUpdateTime GetWorldUpdateTime() { return _worldUpdateTime; } + #region Fields uint m_ShutdownTimer; ShutdownMask m_ShutdownMask; @@ -2330,15 +2290,10 @@ namespace Game bool m_isClosed; - long m_startTime; - long m_gameTime; Dictionary m_timers = new Dictionary(); long mail_timer; long mail_timer_expires; long blackmarket_timer; - uint m_updateTime, m_updateTimeSum; - uint m_updateTimeCount; - uint m_currentTime; ConcurrentDictionary m_sessions = new ConcurrentDictionary(); Dictionary m_disconnects = new Dictionary(); @@ -2371,6 +2326,8 @@ namespace Game Realm _realm; string _dataPath; + + WorldUpdateTime _worldUpdateTime; #endregion } diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index 7f301fb5a..90288aeb5 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -1835,7 +1835,7 @@ namespace Game.Spells float ppm = m_spellInfo.CalcProcPPM(actor, m_castItemLevel); float averageProcInterval = 60.0f / ppm; - var currentTime = DateTime.Now; + var currentTime = GameTime.GetGameTimeSteadyPoint(); float secondsSinceLastAttempt = Math.Min((float)(currentTime - m_lastProcAttemptTime).TotalSeconds, 10.0f); float secondsSinceLastProc = Math.Min((float)(currentTime - m_lastProcSuccessTime).TotalSeconds, 1000.0f); diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index fc7cc3756..3ce2a3ce6 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -1729,7 +1729,7 @@ namespace Game.Spells if (unit.IsAlive() != target.alive) return; - if (getState() == SpellState.Delayed && !m_spellInfo.IsPositive() && (Time.GetMSTime() - target.timeDelay) <= unit.m_lastSanctuaryTime) + if (getState() == SpellState.Delayed && !m_spellInfo.IsPositive() && (GameTime.GetGameTimeMS() - target.timeDelay) <= unit.m_lastSanctuaryTime) return; // No missinfo in that case // Get original caster (if exist) and calculate damage/healing from him data diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 89bdfbfde..c2bdf3055 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -3400,7 +3400,7 @@ namespace Game.Spells unit.AttackStop(); } - unitTarget.m_lastSanctuaryTime = Time.GetMSTime(); + unitTarget.m_lastSanctuaryTime = GameTime.GetGameTimeMS(); // Vanish allows to remove all threat and cast regular stealth so other spells can be used if (m_caster.IsTypeId(TypeId.Player) diff --git a/Source/Game/Spells/SpellHistory.cs b/Source/Game/Spells/SpellHistory.cs index 608a6ae02..c4b736241 100644 --- a/Source/Game/Spells/SpellHistory.cs +++ b/Source/Game/Spells/SpellHistory.cs @@ -159,7 +159,7 @@ namespace Game.Spells public void Update() { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); foreach (var pair in _categoryCooldowns.ToList()) { if (pair.Value.CategoryEnd < now) @@ -233,7 +233,7 @@ namespace Game.Spells public void WritePacket(SendSpellHistory sendSpellHistory) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); foreach (var p in _spellCooldowns) { SpellHistoryEntry historyEntry = new SpellHistoryEntry(); @@ -263,7 +263,7 @@ namespace Game.Spells public void WritePacket(SendSpellCharges sendSpellCharges) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); foreach (var key in _categoryCharges.Keys) { var list = _categoryCharges[key]; @@ -284,7 +284,7 @@ namespace Game.Spells public void WritePacket(PetSpells petSpells) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); foreach (var pair in _spellCooldowns) { @@ -337,7 +337,7 @@ namespace Game.Spells GetCooldownDurations(spellInfo, itemId, ref cooldown, ref categoryId, ref categoryCooldown); - DateTime curTime = DateTime.Now; + DateTime curTime = GameTime.GetGameTimeSystemPoint(); DateTime catrecTime; DateTime recTime; bool needsCooldownPacket = false; @@ -407,7 +407,7 @@ namespace Game.Spells SpellCategoryRecord categoryEntry = CliDB.SpellCategoryStorage.LookupByKey(categoryId); if (categoryEntry.Flags.HasAnyFlag(SpellCategoryFlags.CooldownExpiresAtDailyReset)) - categoryCooldown = (int)(Time.UnixTimeToDateTime(Global.WorldMgr.GetNextDailyQuestsResetTime()) - DateTime.Now).TotalMilliseconds; + categoryCooldown = (int)(Time.UnixTimeToDateTime(Global.WorldMgr.GetNextDailyQuestsResetTime()) - GameTime.GetGameTimeSystemPoint()).TotalMilliseconds; } // replace negative cooldowns by 0 @@ -472,7 +472,7 @@ namespace Game.Spells public void AddCooldown(uint spellId, uint itemId, TimeSpan cooldownDuration) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); AddCooldown(spellId, itemId, now + cooldownDuration, 0, now); } @@ -503,7 +503,7 @@ namespace Game.Spells if (offset.TotalMilliseconds == 0 || cooldownEntry == null) return; - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); if (cooldownEntry.CooldownEnd + offset > now) cooldownEntry.CooldownEnd += offset; @@ -619,7 +619,7 @@ namespace Game.Spells end = cooldownEntry.CategoryEnd; } - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); if (end < now) return 0; @@ -629,7 +629,7 @@ namespace Game.Spells public void LockSpellSchool(SpellSchoolMask schoolMask, uint lockoutTime) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); DateTime lockoutEnd = now + TimeSpan.FromMilliseconds(lockoutTime); for (int i = 0; i < (int)SpellSchools.Max; ++i) if (Convert.ToBoolean((SpellSchoolMask)(1 << i) & schoolMask)) @@ -685,7 +685,7 @@ namespace Game.Spells public bool IsSchoolLocked(SpellSchoolMask schoolMask) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); for (int i = 0; i < (int)SpellSchools.Max; ++i) if (Convert.ToBoolean((SpellSchoolMask)(1 << i) & schoolMask)) if (_schoolLockouts[i] > now) @@ -705,7 +705,7 @@ namespace Game.Spells DateTime recoveryStart; var charges = _categoryCharges.LookupByKey(chargeCategoryId); if (charges.Empty()) - recoveryStart = DateTime.Now; + recoveryStart = GameTime.GetGameTimeSystemPoint(); else recoveryStart = charges.Last().RechargeEnd; @@ -729,7 +729,7 @@ namespace Game.Spells SetSpellCharges setSpellCharges = new SetSpellCharges(); setSpellCharges.Category = chargeCategoryId; if (!chargeList.Empty()) - setSpellCharges.NextRecoveryTime = (uint)(chargeList.FirstOrDefault().RechargeEnd - DateTime.Now).TotalMilliseconds; + setSpellCharges.NextRecoveryTime = (uint)(chargeList.FirstOrDefault().RechargeEnd - GameTime.GetGameTimeSystemPoint()).TotalMilliseconds; setSpellCharges.ConsumedCharges = (byte)chargeList.Count; setSpellCharges.IsPet = player != _owner; @@ -817,12 +817,12 @@ namespace Game.Spells public bool HasGlobalCooldown(SpellInfo spellInfo) { - return _globalCooldowns.ContainsKey(spellInfo.StartRecoveryCategory) && _globalCooldowns[spellInfo.StartRecoveryCategory] > DateTime.Now; + return _globalCooldowns.ContainsKey(spellInfo.StartRecoveryCategory) && _globalCooldowns[spellInfo.StartRecoveryCategory] > GameTime.GetGameTimeSystemPoint(); } public void AddGlobalCooldown(SpellInfo spellInfo, uint duration) { - _globalCooldowns[spellInfo.StartRecoveryCategory] = DateTime.Now + TimeSpan.FromMilliseconds(duration); + _globalCooldowns[spellInfo.StartRecoveryCategory] = GameTime.GetGameTimeSystemPoint() + TimeSpan.FromMilliseconds(duration); } public void CancelGlobalCooldown(SpellInfo spellInfo) @@ -924,7 +924,7 @@ namespace Game.Spells foreach (var c in _spellCooldowns) { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); uint cooldownDuration = c.Value.CooldownEnd > now ? (uint)(c.Value.CooldownEnd - now).TotalMilliseconds : 0; // cooldownDuration must be between 0 and 10 minutes in order to avoid any visual bugs diff --git a/Source/Game/Time/GameTime.cs b/Source/Game/Time/GameTime.cs new file mode 100644 index 000000000..4653e3df7 --- /dev/null +++ b/Source/Game/Time/GameTime.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; + +public class GameTime +{ + static long StartTime = Time.UnixTime; + + static long _gameTime = 0; + static uint _gameMSTime = 0; + + static DateTime _gameTimeSystemPoint = DateTime.MinValue; + static DateTime _gameTimeSteadyPoint = DateTime.MinValue; + + public static long GetStartTime() + { + return StartTime; + } + + public static long GetGameTime() + { + return _gameTime; + } + + public static uint GetGameTimeMS() + { + return _gameMSTime; + } + + public static DateTime GetGameTimeSystemPoint() + { + return _gameTimeSystemPoint; + } + + public static DateTime GetGameTimeSteadyPoint() + { + return _gameTimeSteadyPoint; + } + + public static uint GetUptime() + { + return (uint)(_gameTime - StartTime); + } + + public static void UpdateGameTimers() + { + _gameTime = Time.UnixTime; + _gameMSTime = Time.GetMSTime(); + _gameTimeSystemPoint = DateTime.Now; + _gameTimeSteadyPoint = DateTime.Now; + } +} diff --git a/Source/Game/Time/Updatetime.cs b/Source/Game/Time/Updatetime.cs new file mode 100644 index 000000000..40ba9f5d3 --- /dev/null +++ b/Source/Game/Time/Updatetime.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Framework; + +namespace Game +{ + public class UpdateTime + { + uint[] _updateTimeDataTable = new uint[500]; + uint _averageUpdateTime; + uint _totalUpdateTime; + uint _updateTimeTableIndex; + uint _maxUpdateTime; + uint _maxUpdateTimeOfLastTable; + uint _maxUpdateTimeOfCurrentTable; + + uint _recordedTime; + + public uint GetAverageUpdateTime() + { + return _averageUpdateTime; + } + + public uint GetTimeWeightedAverageUpdateTime() + { + uint sum = 0, weightsum = 0; + foreach (uint diff in _updateTimeDataTable) + { + sum += diff * diff; + weightsum += diff; + } + return sum / weightsum; + } + + public uint GetMaxUpdateTime() + { + return _maxUpdateTime; + } + + public uint GetMaxUpdateTimeOfCurrentTable() + { + return Math.Max(_maxUpdateTimeOfCurrentTable, _maxUpdateTimeOfLastTable); + } + + public uint GetLastUpdateTime() + { + return _updateTimeDataTable[_updateTimeTableIndex != 0 ? _updateTimeTableIndex - 1 : _updateTimeDataTable.Length - 1u]; + } + + public void UpdateWithDiff(uint diff) + { + _totalUpdateTime = _totalUpdateTime - _updateTimeDataTable[_updateTimeTableIndex] + diff; + _updateTimeDataTable[_updateTimeTableIndex] = diff; + + if (diff > _maxUpdateTime) + _maxUpdateTime = diff; + + if (diff > _maxUpdateTimeOfCurrentTable) + _maxUpdateTimeOfCurrentTable = diff; + + if (++_updateTimeTableIndex >= _updateTimeDataTable.Length) + { + _updateTimeTableIndex = 0; + _maxUpdateTimeOfLastTable = _maxUpdateTimeOfCurrentTable; + _maxUpdateTimeOfCurrentTable = 0; + } + + if (_updateTimeDataTable[_updateTimeDataTable.Length - 1] != 0) + _averageUpdateTime = (uint)(_totalUpdateTime / _updateTimeDataTable.Length); + else if (_updateTimeTableIndex != 0) + _averageUpdateTime = _totalUpdateTime / _updateTimeTableIndex; + } + + public void RecordUpdateTimeReset() + { + _recordedTime = Time.GetMSTime(); + } + + public void RecordUpdateTimeDuration(string text, uint minUpdateTime) + { + uint thisTime = Time.GetMSTime(); + uint diff = Time.GetMSTimeDiff(_recordedTime, thisTime); + + if (diff > minUpdateTime) + Log.outInfo(LogFilter.Misc, $"Recored Update Time of {text}: {diff}."); + + _recordedTime = thisTime; + } + } + + public class WorldUpdateTime : UpdateTime + { + uint _recordUpdateTimeInverval; + uint _recordUpdateTimeMin; + uint _lastRecordTime; + + public void LoadFromConfig() + { + _recordUpdateTimeInverval = WorldConfig.GetDefaultValue("RecordUpdateTimeDiffInterval", 60000u); + _recordUpdateTimeMin = WorldConfig.GetDefaultValue("MinRecordUpdateTimeDiff", 100u); + } + + public void SetRecordUpdateTimeInterval(uint t) + { + _recordUpdateTimeInverval = t; + } + + public void RecordUpdateTime(uint gameTimeMs, uint diff, uint sessionCount) + { + if (_recordUpdateTimeInverval > 0 && diff > _recordUpdateTimeMin) + { + if (Time.GetMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval) + { + Log.outDebug(LogFilter.Misc, $"Update time diff: {GetAverageUpdateTime()}. Players online: {sessionCount}."); + _lastRecordTime = gameTimeMs; + } + } + } + + public void RecordUpdateTimeDuration(string text) + { + RecordUpdateTimeDuration(text, _recordUpdateTimeMin); + } + } +} diff --git a/Source/Game/Warden/Warden.cs b/Source/Game/Warden/Warden.cs index 716aed949..0653dd3c5 100644 --- a/Source/Game/Warden/Warden.cs +++ b/Source/Game/Warden/Warden.cs @@ -87,7 +87,7 @@ namespace Game { if (_initialized) { - uint currentTimestamp = Time.GetMSTime(); + uint currentTimestamp = GameTime.GetGameTimeMS(); uint diff = currentTimestamp - _previousTimestamp; _previousTimestamp = currentTimestamp; diff --git a/Source/Game/Warden/WardenWin.cs b/Source/Game/Warden/WardenWin.cs index 4336e3a65..2f5ac8270 100644 --- a/Source/Game/Warden/WardenWin.cs +++ b/Source/Game/Warden/WardenWin.cs @@ -148,7 +148,7 @@ namespace Game _initialized = true; - _previousTimestamp = Time.GetMSTime(); + _previousTimestamp = GameTime.GetGameTimeMS(); } public override void RequestData() @@ -162,7 +162,7 @@ namespace Game if (_otherChecksTodo.Empty()) _otherChecksTodo.AddRange(Global.WardenCheckMgr.OtherChecksIdPool); - _serverTicks = Time.GetMSTime(); + _serverTicks = GameTime.GetGameTimeMS(); ushort id; WardenCheckType type; @@ -323,7 +323,7 @@ namespace Game uint newClientTicks = buff.ReadUInt32(); - uint ticksNow = Time.GetMSTime(); + uint ticksNow = GameTime.GetGameTimeMS(); uint ourTicks = newClientTicks + (ticksNow - _serverTicks); Log.outDebug(LogFilter.Warden, "ServerTicks {0}", ticksNow); // Now diff --git a/Source/Game/Weather/WeatherManager.cs b/Source/Game/Weather/WeatherManager.cs index 71ff7b34c..590fe8d39 100644 --- a/Source/Game/Weather/WeatherManager.cs +++ b/Source/Game/Weather/WeatherManager.cs @@ -150,7 +150,7 @@ namespace Game WeatherType old_type = m_type; float old_grade = m_grade; - long gtime = Global.WorldMgr.GetGameTime(); + long gtime = GameTime.GetGameTime(); var ltime = Time.UnixTimeToDateTime(gtime).ToLocalTime(); uint season = (uint)((ltime.DayOfYear - 78 + 365) / 91) % 4; diff --git a/Source/Scripts/Northrend/IcecrownCitadel/IcecrownCitadel.cs b/Source/Scripts/Northrend/IcecrownCitadel/IcecrownCitadel.cs index 149c14cc2..35687600a 100644 --- a/Source/Scripts/Northrend/IcecrownCitadel/IcecrownCitadel.cs +++ b/Source/Scripts/Northrend/IcecrownCitadel/IcecrownCitadel.cs @@ -1449,7 +1449,7 @@ namespace Scripts.Northrend.IcecrownCitadel GameObject trap = GetCaster().FindNearestGameObject(trapId, 5.0f); if (trap) - trap.SetRespawnTime((int)trap.GetGoInfo().GetAutoCloseTime()); + trap.SetRespawnTime((int)trap.GetGoInfo().GetAutoCloseTime() / Time.InMilliseconds); List wards = new List(); GetCaster().GetCreatureListWithEntryInGrid(wards, CreatureIds.DeathboundWard, 150.0f); diff --git a/Source/Scripts/Northrend/Nexus/Nexus/BossMagusTelestra.cs b/Source/Scripts/Northrend/Nexus/Nexus/BossMagusTelestra.cs index a5f81847e..e28d9ed8c 100644 --- a/Source/Scripts/Northrend/Nexus/Nexus/BossMagusTelestra.cs +++ b/Source/Scripts/Northrend/Nexus/Nexus/BossMagusTelestra.cs @@ -269,7 +269,7 @@ namespace Scripts.Northrend.Nexus.Nexus while (time[i] != 0) ++i; - time[i] = Global.WorldMgr.GetGameTime(); + time[i] = GameTime.GetGameTime(); if (i == 2 && (time[2] - time[1] < 5) && (time[1] - time[0] < 5)) ++splitPersonality; } diff --git a/Source/Scripts/Spells/Generic.cs b/Source/Scripts/Spells/Generic.cs index 712b2b6ca..5c357b10c 100644 --- a/Source/Scripts/Spells/Generic.cs +++ b/Source/Scripts/Spells/Generic.cs @@ -2661,7 +2661,7 @@ namespace Scripts.Spells.Generic void OnApply(AuraEffect aurEff, AuraEffectHandleModes mode) { // store stack apply times, so we can pop them while they expire - _applyTimes.Add(Time.GetMSTime()); + _applyTimes.Add(GameTime.GetGameTimeMS()); Unit target = GetTarget(); // on stack 15 cast the achievement crediting spell @@ -2675,7 +2675,7 @@ namespace Scripts.Spells.Generic return; // pop stack if it expired for us - if (_applyTimes.First() + GetMaxDuration() < Time.GetMSTime()) + if (_applyTimes.First() + GetMaxDuration() < GameTime.GetGameTimeMS()) ModStackAmount(-1, AuraRemoveMode.Expire); } diff --git a/Source/Scripts/World/AreaTrigger.cs b/Source/Scripts/World/AreaTrigger.cs index f60102d40..11ed84763 100644 --- a/Source/Scripts/World/AreaTrigger.cs +++ b/Source/Scripts/World/AreaTrigger.cs @@ -276,7 +276,7 @@ namespace Scripts.World { uint triggerId = trigger.Id; // Second trigger happened too early after first, skip for now - if (Global.WorldMgr.GetGameTime() - _triggerTimes[triggerId] < AreaTriggerConst.AreatriggerTalkCooldown) + if (GameTime.GetGameTime() - _triggerTimes[triggerId] < AreaTriggerConst.AreatriggerTalkCooldown) return false; switch (triggerId) @@ -295,7 +295,7 @@ namespace Scripts.World break; } - _triggerTimes[triggerId] = Global.WorldMgr.GetGameTime(); + _triggerTimes[triggerId] = GameTime.GetGameTime(); return false; } @@ -318,7 +318,7 @@ namespace Scripts.World return false; uint triggerId = trigger.Id; - if (Global.WorldMgr.GetGameTime() - _triggerTimes[trigger.Id] < AreaTriggerConst.SummonCooldown) + if (GameTime.GetGameTime() - _triggerTimes[trigger.Id] < AreaTriggerConst.SummonCooldown) return false; switch (triggerId) @@ -347,7 +347,7 @@ namespace Scripts.World player.SummonCreature(AreaTriggerConst.NpcSpotlight, x, y, z, 0.0f, TempSummonType.TimedDespawn, 5000); player.AddAura(AreaTriggerConst.SpellA52Neuralyzer, player); - _triggerTimes[trigger.Id] = Global.WorldMgr.GetGameTime(); + _triggerTimes[trigger.Id] = GameTime.GetGameTime(); return false; } diff --git a/Source/Scripts/World/DuelReset.cs b/Source/Scripts/World/DuelReset.cs index e99841529..ef1286411 100644 --- a/Source/Scripts/World/DuelReset.cs +++ b/Source/Scripts/World/DuelReset.cs @@ -97,7 +97,7 @@ namespace Scripts.World // remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold player.GetSpellHistory().ResetCooldowns(pair => { - DateTime now = DateTime.Now; + DateTime now = GameTime.GetGameTimeSystemPoint(); uint cooldownDuration = pair.Value.CooldownEnd > now ? (uint)(pair.Value.CooldownEnd - now).TotalMilliseconds : 0; SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(pair.Key); return spellInfo.RecoveryTime < 10 * Time.Minute * Time.InMilliseconds