From cc5263099ce2e52937a0c9f1f97894480e7cf359 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 4 Oct 2017 18:13:04 -0400 Subject: [PATCH] compute aura diminishing return info at startup and cache it some changes in default proc generation. Fix an issue of stealth breaking with positive and/or healing spells --- Game/Entities/Unit/Unit.Spells.cs | 20 +++++++++--------- Game/Spells/Spell.cs | 9 ++++---- Game/Spells/SpellInfo.cs | 4 ++-- Game/Spells/SpellManager.cs | 34 +++++++++++++++++++++++-------- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/Game/Entities/Unit/Unit.Spells.cs b/Game/Entities/Unit/Unit.Spells.cs index 2a427f27e..790fe3c0b 100644 --- a/Game/Entities/Unit/Unit.Spells.cs +++ b/Game/Entities/Unit/Unit.Spells.cs @@ -2677,10 +2677,10 @@ namespace Game.Entities return diminish.HitCount; } - public void IncrDiminishing(SpellInfo auraSpellInfo, bool triggered) + public void IncrDiminishing(SpellInfo auraSpellInfo) { - DiminishingGroup group = auraSpellInfo.GetDiminishingReturnsGroupForSpell(triggered); - DiminishingLevels maxLevel = auraSpellInfo.GetDiminishingReturnsMaxLevel(triggered); + DiminishingGroup group = auraSpellInfo.GetDiminishingReturnsGroupForSpell(); + DiminishingLevels maxLevel = auraSpellInfo.GetDiminishingReturnsMaxLevel(); // Checking for existing in the table DiminishingReturn diminish = m_Diminishing[(int)group]; @@ -2688,13 +2688,13 @@ namespace Game.Entities ++diminish.HitCount; } - public float ApplyDiminishingToDuration(SpellInfo auraSpellInfo, bool triggered, ref int duration, Unit caster, DiminishingLevels previousLevel) + public float ApplyDiminishingToDuration(SpellInfo auraSpellInfo, ref int duration, Unit caster, DiminishingLevels previousLevel) { - DiminishingGroup group = auraSpellInfo.GetDiminishingReturnsGroupForSpell(triggered); + DiminishingGroup group = auraSpellInfo.GetDiminishingReturnsGroupForSpell(); if (duration == -1 || group == DiminishingGroup.None) return 1.0f; - int limitDuration = auraSpellInfo.GetDiminishingReturnsLimitDuration(triggered); + int limitDuration = auraSpellInfo.GetDiminishingReturnsLimitDuration(); // test pet/charm masters instead pets/charmeds Unit targetOwner = GetCharmerOrOwner(); @@ -2740,9 +2740,9 @@ namespace Game.Entities } break; case DiminishingGroup.AOEKnockback: - if ((auraSpellInfo.GetDiminishingReturnsGroupType(triggered) == DiminishingReturnsType.Player && (((targetOwner ? targetOwner : this).ToPlayer()) + if ((auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.Player && (((targetOwner ? targetOwner : this).ToPlayer()) || IsCreature() && ToCreature().GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish))) - || auraSpellInfo.GetDiminishingReturnsGroupType(triggered) == DiminishingReturnsType.All) + || auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.All) { DiminishingLevels diminish = previousLevel; switch (diminish) @@ -2758,9 +2758,9 @@ namespace Game.Entities } break; default: - if ((auraSpellInfo.GetDiminishingReturnsGroupType(triggered) == DiminishingReturnsType.Player && (((targetOwner ? targetOwner : this).ToPlayer()) + if ((auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.Player && (((targetOwner ? targetOwner : this).ToPlayer()) || IsCreature() && ToCreature().GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish))) - || auraSpellInfo.GetDiminishingReturnsGroupType(triggered) == DiminishingReturnsType.All) + || auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.All) { DiminishingLevels diminish = previousLevel; switch (diminish) diff --git a/Game/Spells/Spell.cs b/Game/Spells/Spell.cs index df3f7fd09..90c5baa18 100644 --- a/Game/Spells/Spell.cs +++ b/Game/Spells/Spell.cs @@ -2111,19 +2111,18 @@ namespace Game.Spells aura_effmask |= (1u << (int)effect.EffectIndex); // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add - bool triggered = m_triggeredByAuraSpell != null; - DiminishingGroup diminishGroup = m_spellInfo.GetDiminishingReturnsGroupForSpell(triggered); + DiminishingGroup diminishGroup = m_spellInfo.GetDiminishingReturnsGroupForSpell(); DiminishingLevels diminishLevel = DiminishingLevels.Level1; if (diminishGroup != 0 && aura_effmask != 0) { diminishLevel = unit.GetDiminishing(diminishGroup); - DiminishingReturnsType type = m_spellInfo.GetDiminishingReturnsGroupType(triggered); + DiminishingReturnsType type = m_spellInfo.GetDiminishingReturnsGroupType(); // Increase Diminishing on unit, current informations for actually casts will use values above if ((type == DiminishingReturnsType.Player && (unit.GetCharmerOrOwnerPlayerOrPlayerItself() || (unit.IsCreature() && unit.ToCreature().GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish)))) || type == DiminishingReturnsType.All) - unit.IncrDiminishing(m_spellInfo, triggered); + unit.IncrDiminishing(m_spellInfo); } if (aura_effmask != 0) @@ -2170,7 +2169,7 @@ namespace Game.Spells // Now Reduce spell duration using data received at spell hit int duration = m_spellAura.GetMaxDuration(); - float diminishMod = unit.ApplyDiminishingToDuration(aurSpellInfo, triggered, ref duration, m_originalCaster, diminishLevel); + float diminishMod = unit.ApplyDiminishingToDuration(aurSpellInfo, ref duration, m_originalCaster, diminishLevel); // unit is immune to aura if it was diminished to 0 duration if (diminishMod == 0.0f) diff --git a/Game/Spells/SpellInfo.cs b/Game/Spells/SpellInfo.cs index 21e09f485..5407709ed 100644 --- a/Game/Spells/SpellInfo.cs +++ b/Game/Spells/SpellInfo.cs @@ -1558,12 +1558,12 @@ namespace Game.Spells return _diminishInfo.DiminishReturnType; } - public DiminishingLevels GetDiminishingReturnsMaxLevel(bool triggered) + public DiminishingLevels GetDiminishingReturnsMaxLevel() { return _diminishInfo.DiminishMaxLevel; } - public int GetDiminishingReturnsLimitDuration(bool triggered) + public int GetDiminishingReturnsLimitDuration() { return _diminishInfo.DiminishDurationLimit; } diff --git a/Game/Spells/SpellManager.cs b/Game/Spells/SpellManager.cs index c645b0642..4b88cbe7e 100644 --- a/Game/Spells/SpellManager.cs +++ b/Game/Spells/SpellManager.cs @@ -1280,7 +1280,8 @@ namespace Game.Entities if (mSpellProcMap.ContainsKey(spellInfo.Id)) continue; - bool found = false, addTriggerFlag = false; + bool addTriggerFlag = false; + ProcFlagsSpellType procSpellTypeMask = ProcFlagsSpellType.None; foreach (SpellEffectInfo effect in spellInfo.GetEffectsForDifficulty(Difficulty.None)) { if (effect == null || !effect.IsEffect()) @@ -1293,14 +1294,13 @@ namespace Game.Entities if (!isTriggerAura(auraName)) continue; - found = true; - - if (!addTriggerFlag && isAlwaysTriggeredAura(auraName)) + procSpellTypeMask |= getSpellTypeMask(auraName); + if (isAlwaysTriggeredAura(auraName)) addTriggerFlag = true; break; } - if (!found) + if (procSpellTypeMask == 0) continue; if (spellInfo.ProcFlags == 0) @@ -1317,7 +1317,7 @@ namespace Game.Entities if (procEntry.SpellFamilyMask) procEntry.SpellFamilyName = spellInfo.SpellFamilyName; - procEntry.SpellTypeMask = ProcFlagsSpellType.MaskAll; + procEntry.SpellTypeMask = procSpellTypeMask; procEntry.SpellPhaseMask = ProcFlagsSpellPhase.Hit; procEntry.HitMask = ProcFlagsHit.None; // uses default proc @see SpellMgr::CanSpellTriggerProcOnEvent @@ -2790,7 +2790,7 @@ namespace Game.Entities } #endregion - public bool isTriggerAura(AuraType type) + bool isTriggerAura(AuraType type) { switch (type) { @@ -2834,7 +2834,7 @@ namespace Game.Entities } return false; } - public bool isAlwaysTriggeredAura(AuraType type) + bool isAlwaysTriggeredAura(AuraType type) { switch (type) { @@ -2851,6 +2851,24 @@ namespace Game.Entities } return false; } + ProcFlagsSpellType getSpellTypeMask(AuraType type) + { + switch (type) + { + case AuraType.ModStealth: + return ProcFlagsSpellType.Damage | ProcFlagsSpellType.NoDmgHeal; + case AuraType.ModConfuse: + case AuraType.ModFear: + case AuraType.ModRoot: + case AuraType.ModRoot2: + case AuraType.ModStun: + case AuraType.Transform: + return ProcFlagsSpellType.Damage; + default: + return ProcFlagsSpellType.MaskAll; + } + } + // SpellInfo object management public SpellInfo GetSpellInfo(uint spellId)