From 5de09a5046629239daf04dd1d9502f6a9112d296 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 24 Dec 2021 20:41:51 -0500 Subject: [PATCH] Core/BattlePets: Added default cooldown to revive battle pets Port From (https://github.com/TrinityCore/TrinityCore/commit/1a846415493289fc3852e56c82514d85c421267c) --- Source/Framework/Constants/SharedConst.cs | 1 + Source/Game/Entities/Player/Player.Spells.cs | 19 +++++++ Source/Game/Handlers/CharacterHandler.cs | 2 + Source/Game/Spells/SpellHistory.cs | 53 ++++++++++++++++---- Source/Scripts/Spells/Priest.cs | 2 +- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Source/Framework/Constants/SharedConst.cs b/Source/Framework/Constants/SharedConst.cs index a2fa46433..909be05fa 100644 --- a/Source/Framework/Constants/SharedConst.cs +++ b/Source/Framework/Constants/SharedConst.cs @@ -57,6 +57,7 @@ namespace Framework.Constants public const int SpellBattlePetTraining = 125610; public const int SpellReviveBattlePets = 125439; public const int SpellSummonBattlePet = 118301; + public static TimeSpan ReviveBattlePetsCooldown = TimeSpan.FromSeconds(180); /// /// Lfg Const diff --git a/Source/Game/Entities/Player/Player.Spells.cs b/Source/Game/Entities/Player/Player.Spells.cs index e0b075f5e..ae3dd98ff 100644 --- a/Source/Game/Entities/Player/Player.Spells.cs +++ b/Source/Game/Entities/Player/Player.Spells.cs @@ -1015,6 +1015,25 @@ namespace Game.Entities m_lastPotionId = 0; } + public void UpdateReviveBattlePetCooldown() + { + SpellInfo reviveBattlePetSpellInfo = Global.SpellMgr.GetSpellInfo(SharedConst.SpellReviveBattlePets, Difficulty.None); + + if (reviveBattlePetSpellInfo != null && HasSpell(SharedConst.SpellReviveBattlePets)) + { + var remainingCooldown = GetSpellHistory().GetRemainingCategoryCooldown(reviveBattlePetSpellInfo); + if (remainingCooldown > TimeSpan.Zero) + { + if (remainingCooldown < SharedConst.ReviveBattlePetsCooldown) + GetSpellHistory().ModifyCooldown(reviveBattlePetSpellInfo, SharedConst.ReviveBattlePetsCooldown - remainingCooldown); + } + else + { + GetSpellHistory().StartCooldown(reviveBattlePetSpellInfo, 0, null, false, SharedConst.ReviveBattlePetsCooldown); + } + } + } + public bool CanUseMastery() { ChrSpecializationRecord chrSpec = CliDB.ChrSpecializationStorage.LookupByKey(GetPrimarySpecialization()); diff --git a/Source/Game/Handlers/CharacterHandler.cs b/Source/Game/Handlers/CharacterHandler.cs index 8fa2620f8..8003bc733 100644 --- a/Source/Game/Handlers/CharacterHandler.cs +++ b/Source/Game/Handlers/CharacterHandler.cs @@ -845,6 +845,8 @@ namespace Game pCurrChar.SendInitialPacketsAfterAddToMap(); + pCurrChar.UpdateReviveBattlePetCooldown(); + PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHAR_ONLINE); stmt.AddValue(0, pCurrChar.GetGUID().GetCounter()); DB.Characters.Execute(stmt); diff --git a/Source/Game/Spells/SpellHistory.cs b/Source/Game/Spells/SpellHistory.cs index f10c2c55d..f8f8448cf 100644 --- a/Source/Game/Spells/SpellHistory.cs +++ b/Source/Game/Spells/SpellHistory.cs @@ -255,13 +255,15 @@ namespace Game.Spells if (cooldownDuration.TotalMilliseconds <= 0) continue; - historyEntry.RecoveryTime = (int)cooldownDuration.TotalMilliseconds; TimeSpan categoryDuration = p.Value.CategoryEnd - now; if (categoryDuration.TotalMilliseconds > 0) { historyEntry.Category = p.Value.CategoryId; historyEntry.CategoryRecoveryTime = (int)categoryDuration.TotalMilliseconds; } + + if (cooldownDuration > categoryDuration) + historyEntry.RecoveryTime = (int)cooldownDuration.TotalMilliseconds; } sendSpellHistory.Entries.Add(historyEntry); @@ -517,7 +519,7 @@ namespace Game.Spells } } - public void ModifySpellCooldown(uint spellId, TimeSpan offset) + public void ModifySpellCooldown(uint spellId, TimeSpan offset, bool withoutCategoryCooldown = false) { var cooldownEntry = _spellCooldowns.LookupByKey(spellId); if (offset.TotalMilliseconds == 0 || cooldownEntry == null) @@ -525,9 +527,19 @@ namespace Game.Spells DateTime now = GameTime.GetGameTimeSystemPoint(); - if (cooldownEntry.CooldownEnd + offset > now) - cooldownEntry.CooldownEnd += offset; - else + cooldownEntry.CooldownEnd += offset; + + if (cooldownEntry.CategoryId != 0) + { + if (!withoutCategoryCooldown) + cooldownEntry.CategoryEnd += offset; + + // Because category cooldown existence is tied to regular cooldown, we cannot allow a situation where regular cooldown is shorter than category + if (cooldownEntry.CooldownEnd < cooldownEntry.CategoryEnd) + cooldownEntry.CooldownEnd = cooldownEntry.CategoryEnd; + } + + if (cooldownEntry.CooldownEnd <= now) { _categoryCooldowns.Remove(cooldownEntry.CategoryId); _spellCooldowns.Remove(spellId); @@ -540,18 +552,19 @@ namespace Game.Spells modifyCooldown.IsPet = _owner != playerOwner; modifyCooldown.SpellID = spellId; modifyCooldown.DeltaTime = (int)offset.TotalMilliseconds; + modifyCooldown.WithoutCategoryCooldown = withoutCategoryCooldown; playerOwner.SendPacket(modifyCooldown); } } - public void ModifyCooldown(uint spellId, TimeSpan cooldownMod) + public void ModifyCooldown(uint spellId, TimeSpan cooldownMod, bool withoutCategoryCooldown = false) { SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, _owner.GetMap().GetDifficultyID()); if (spellInfo != null) - ModifyCooldown(spellInfo, cooldownMod); + ModifyCooldown(spellInfo, cooldownMod, withoutCategoryCooldown); } - public void ModifyCooldown(SpellInfo spellInfo, TimeSpan cooldownMod) + public void ModifyCooldown(SpellInfo spellInfo, TimeSpan cooldownMod, bool withoutCategoryCooldown = false) { if (cooldownMod == TimeSpan.Zero) return; @@ -559,7 +572,7 @@ namespace Game.Spells if (GetChargeRecoveryTime(spellInfo.ChargeCategoryId) > 0 && GetMaxCharges(spellInfo.ChargeCategoryId) > 0) ModifyChargeRecoveryTime(spellInfo.ChargeCategoryId, cooldownMod); else - ModifySpellCooldown(spellInfo.Id, cooldownMod); + ModifySpellCooldown(spellInfo.Id, cooldownMod, withoutCategoryCooldown); } public void ResetCooldown(uint spellId, bool update = false) @@ -665,6 +678,28 @@ namespace Game.Spells return remaining; } + public TimeSpan GetRemainingCategoryCooldown(uint categoryId) + { + DateTime end; + var cooldownEntry = _categoryCooldowns.LookupByKey(categoryId); + if (cooldownEntry == null) + return TimeSpan.Zero; + + end = cooldownEntry.CategoryEnd; + + DateTime now = GameTime.GetGameTimeSystemPoint(); + if (end < now) + return TimeSpan.Zero; + + TimeSpan remaining = end - now; + return remaining; + } + + public TimeSpan GetRemainingCategoryCooldown(SpellInfo spellInfo) + { + return GetRemainingCategoryCooldown(spellInfo.GetCategory()); + } + public void LockSpellSchool(SpellSchoolMask schoolMask, TimeSpan lockoutTime) { DateTime now = GameTime.GetGameTimeSystemPoint(); diff --git a/Source/Scripts/Spells/Priest.cs b/Source/Scripts/Spells/Priest.cs index fa76fb03e..58db11744 100644 --- a/Source/Scripts/Spells/Priest.cs +++ b/Source/Scripts/Spells/Priest.cs @@ -324,7 +324,7 @@ namespace Scripts.Spells.Priest SpellInfo targetSpellInfo = Global.SpellMgr.GetSpellInfo(targetSpellId, GetCastDifficulty()); int cdReduction = targetSpellInfo.GetEffect(cdReductionEffIndex).CalcValue(GetTarget()); - GetTarget().GetSpellHistory().ModifyCooldown(targetSpellInfo, TimeSpan.FromSeconds(-cdReduction)); + GetTarget().GetSpellHistory().ModifyCooldown(targetSpellInfo, TimeSpan.FromSeconds(-cdReduction), true); } public override void Register()