Core/Script: Implement CalcCritChance hooks for spell and aura scripts

Port From (https://github.com/TrinityCore/TrinityCore/commit/f8255b15419cd1efdd2ccaf77298c8598322288f)
This commit is contained in:
hondacrx
2021-03-29 16:04:29 -04:00
parent 487aad55df
commit 3d40c868f6
6 changed files with 86 additions and 11 deletions
+16 -3
View File
@@ -882,7 +882,7 @@ namespace Game.Spells
}
return maxStackAmount;
}
public bool ModStackAmount(int num, AuraRemoveMode removeMode = AuraRemoveMode.Default, bool resetPeriodicTimer = true)
{
int stackAmount = m_stackAmount + num;
@@ -1449,7 +1449,7 @@ namespace Game.Spells
effect.SetDonePct(caster.SpellDamagePctDone(target, m_spellInfo, DamageEffectType.DOT)); // Calculate done percentage first!
effect.SetDamage((int)(caster.SpellDamageBonusDone(target, m_spellInfo, damage, DamageEffectType.DOT, effect.GetSpellEffectInfo(), GetStackAmount()) * effect.GetDonePct()));
effect.SetCritChance(caster.GetUnitSpellCriticalChance(target, m_spellInfo, m_spellInfo.GetSchoolMask()));
effect.SetCritChance(caster.GetUnitSpellCriticalChance(target, null, effect, m_spellInfo.GetSchoolMask()));
break;
}
case AuraType.PeriodicHeal:
@@ -1463,7 +1463,7 @@ namespace Game.Spells
effect.SetDonePct(caster.SpellHealingPctDone(target, m_spellInfo)); // Calculate done percentage first!
effect.SetDamage((int)(caster.SpellHealingBonusDone(target, m_spellInfo, damage, DamageEffectType.DOT, effect.GetSpellEffectInfo(), GetStackAmount()) * effect.GetDonePct()));
effect.SetCritChance(caster.GetUnitSpellCriticalChance(target, m_spellInfo, m_spellInfo.GetSchoolMask()));
effect.SetCritChance(caster.GetUnitSpellCriticalChance(target, null, effect, m_spellInfo.GetSchoolMask()));
break;
}
default:
@@ -2074,6 +2074,19 @@ namespace Game.Spells
}
}
public void CallScriptEffectCalcCritChanceHandlers(AuraEffect aurEff, AuraApplication aurApp, Unit victim, ref float critChance)
{
foreach (AuraScript loadedScript in m_loadedScripts)
{
loadedScript._PrepareScriptCall(AuraScriptHookType.EffectCalcCritChance, aurApp);
foreach (var hook in loadedScript.DoEffectCalcCritChance)
if (hook.IsEffectAffected(m_spellInfo, aurEff.GetEffIndex()))
hook.Call(aurEff, victim, ref critChance);
loadedScript._FinishScriptCall();
}
}
public void CallScriptEffectAbsorbHandlers(AuraEffect aurEff, AuraApplication aurApp, DamageInfo dmgInfo, ref uint absorbAmount, ref bool defaultPrevented)
{
foreach (var auraScript in m_loadedScripts)
+3 -3
View File
@@ -4923,7 +4923,7 @@ namespace Game.Spells
}
}
bool crit = RandomHelper.randChance(isAreaAura ? caster.GetUnitSpellCriticalChance(target, m_spellInfo, m_spellInfo.GetSchoolMask()) : m_critChance);
bool crit = RandomHelper.randChance(isAreaAura ? caster.GetUnitSpellCriticalChance(target, null, this, m_spellInfo.GetSchoolMask()) : m_critChance);
if (crit)
damage = caster.SpellCriticalDamageBonus(m_spellInfo, damage, target);
@@ -5010,7 +5010,7 @@ namespace Game.Spells
}
}
bool crit = RandomHelper.randChance(isAreaAura ? caster.GetUnitSpellCriticalChance(target, m_spellInfo, m_spellInfo.GetSchoolMask()) : m_critChance);
bool crit = RandomHelper.randChance(isAreaAura ? caster.GetUnitSpellCriticalChance(target, null, this, m_spellInfo.GetSchoolMask()) : m_critChance);
if (crit)
damage = caster.SpellCriticalDamageBonus(m_spellInfo, damage, target);
@@ -5150,7 +5150,7 @@ namespace Game.Spells
damage = (int)target.SpellHealingBonusTaken(caster, GetSpellInfo(), (uint)damage, DamageEffectType.DOT, GetSpellEffectInfo(), GetBase().GetStackAmount());
}
bool crit = RandomHelper.randChance(isAreaAura ? caster.GetUnitSpellCriticalChance(target, m_spellInfo, m_spellInfo.GetSchoolMask()) : m_critChance);
bool crit = RandomHelper.randChance(isAreaAura ? caster.GetUnitSpellCriticalChance(target, null, this, m_spellInfo.GetSchoolMask()) : m_critChance);
if (crit)
damage = caster.SpellCriticalHealingBonus(m_spellInfo, damage, target);
+13 -1
View File
@@ -6814,7 +6814,7 @@ namespace Game.Spells
}
}
targetInfo.crit = m_caster.IsSpellCrit(unit, m_spellInfo, m_spellSchoolMask, m_attackType);
targetInfo.crit = m_caster.IsSpellCrit(unit, this, null, m_spellSchoolMask, m_attackType);
}
SpellCastResult CanOpenLock(uint effIndex, uint lockId, ref SkillType skillId, ref int reqSkillValue, ref int skillValue)
@@ -7092,6 +7092,18 @@ namespace Game.Spells
}
}
public void CallScriptCalcCritChanceHandlers(Unit victim, ref float critChance)
{
foreach (var loadedScript in m_loadedScripts)
{
loadedScript._PrepareScriptCall(SpellScriptHookType.CalcCritChance);
foreach (var hook in loadedScript.OnCalcCritChance)
hook.Call(victim, ref critChance);
loadedScript._FinishScriptCall();
}
}
void CallScriptObjectAreaTargetSelectHandlers(List<WorldObject> targets, uint effIndex, SpellImplicitTargetInfo targetType)
{
foreach (var script in m_loadedScripts)