Core/Spells: Implemented pausing spell cooldowns

Port From (https://github.com/TrinityCore/TrinityCore/commit/a814eb65b15c4fcef6a37adc1b13905d4c13b2a5)
This commit is contained in:
hondacrx
2024-02-29 22:25:59 -05:00
parent 784f34beed
commit 2a4a2d1fdb
2 changed files with 35 additions and 2 deletions
+2 -1
View File
@@ -199,7 +199,8 @@ namespace Game.Entities
void _UpdateSpells(uint diff) void _UpdateSpells(uint diff)
{ {
_spellHistory.Update(); if (!_spellHistory.IsPaused())
_spellHistory.Update();
if (GetCurrentSpell(CurrentSpellTypes.AutoRepeat) != null) if (GetCurrentSpell(CurrentSpellTypes.AutoRepeat) != null)
_UpdateAutoRepeatSpell(); _UpdateAutoRepeatSpell();
+33 -1
View File
@@ -926,13 +926,44 @@ namespace Game.Spells
if (!_globalCooldowns.TryGetValue(spellInfo.StartRecoveryCategory, out DateTime end)) if (!_globalCooldowns.TryGetValue(spellInfo.StartRecoveryCategory, out DateTime end))
return TimeSpan.Zero; return TimeSpan.Zero;
DateTime now = GameTime.GetDateAndTime(); DateTime now = GameTime.GetSystemTime();
if (end < now) if (end < now)
return TimeSpan.Zero; return TimeSpan.Zero;
return end - now; return end - now;
} }
public bool IsPaused() { return _pauseTime.HasValue; }
public void PauseCooldowns()
{
_pauseTime = GameTime.GetSystemTime().TimeOfDay;
}
public void ResumeCooldowns()
{
if (!_pauseTime.HasValue)
return;
TimeSpan pausedDuration = GameTime.GetSystemTime().TimeOfDay - _pauseTime.Value;
foreach (var itr in _spellCooldowns)
itr.Value.CooldownEnd += pausedDuration;
foreach (var itr in _categoryCharges.Keys)
{
for (var i = 0; i < _categoryCharges[itr].Count; ++i)
{
var entry = _categoryCharges[itr][i];
entry.RechargeEnd += pausedDuration;
}
}
_pauseTime = null;
Update();
}
public Player GetPlayerOwner() public Player GetPlayerOwner()
{ {
return _owner.GetCharmerOrOwnerPlayerOrPlayerItself(); return _owner.GetCharmerOrOwnerPlayerOrPlayerItself();
@@ -1063,6 +1094,7 @@ namespace Game.Spells
DateTime[] _schoolLockouts = new DateTime[(int)SpellSchools.Max]; DateTime[] _schoolLockouts = new DateTime[(int)SpellSchools.Max];
MultiMap<uint, ChargeEntry> _categoryCharges = new(); MultiMap<uint, ChargeEntry> _categoryCharges = new();
Dictionary<uint, DateTime> _globalCooldowns = new(); Dictionary<uint, DateTime> _globalCooldowns = new();
TimeSpan? _pauseTime;
public class CooldownEntry public class CooldownEntry
{ {