From d5781441500cf99d24d1e3eed02aa29e06c28ea3 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 6 Sep 2017 11:24:12 -0400 Subject: [PATCH] Added missing null checks for DamageInfo struct Misc spell fixes --- Framework/Constants/Spells/SpellConst.cs | 2 +- Game/Spells/SpellInfo.cs | 2 +- .../AzjolNerub/BossKrikthirTheGatewatcher.cs | 11 ++---- Scripts/Spells/Generic.cs | 4 +-- Scripts/Spells/Hunter.cs | 13 +++++-- Scripts/Spells/Items.cs | 6 +++- Scripts/Spells/Paladin.cs | 6 +++- Scripts/Spells/Warlock.cs | 36 +++++++++++++++++-- Scripts/Spells/Warrior.cs | 28 ++++++++++----- 9 files changed, 78 insertions(+), 30 deletions(-) diff --git a/Framework/Constants/Spells/SpellConst.cs b/Framework/Constants/Spells/SpellConst.cs index 27922b82b..33c4d2e12 100644 --- a/Framework/Constants/Spells/SpellConst.cs +++ b/Framework/Constants/Spells/SpellConst.cs @@ -1657,7 +1657,7 @@ namespace Framework.Constants ScalesWithItemLevel = 0x04, // 2 Unk3 = 0x08, // 3 Unk4 = 0x10, // 4 - AbsorbFallDamage = 0x20, // 5 + AbsorbEnvironmentalDamage = 0x20, // 5 Unk6 = 0x40, // 6 RankIgnoresCasterLevel = 0x80, // 7 Spell_C_GetSpellRank returns SpellLevels->MaxLevel * 5 instead of std::min(SpellLevels->MaxLevel, caster->Level) * 5 Unk8 = 0x100, // 8 diff --git a/Game/Spells/SpellInfo.cs b/Game/Spells/SpellInfo.cs index ccd2f00f9..dc4b69fbf 100644 --- a/Game/Spells/SpellInfo.cs +++ b/Game/Spells/SpellInfo.cs @@ -2801,7 +2801,7 @@ namespace Game.Spells else if (caster) level = caster.getLevel(); - if (!_spellInfo.HasAttribute(SpellAttr11.ScalesWithItemLevel) && _spellInfo.HasAttribute(SpellAttr10.UseSpellBaseLevelForScaling)) + if (_spellInfo.BaseLevel != 0 && !_spellInfo.HasAttribute(SpellAttr11.ScalesWithItemLevel) && _spellInfo.HasAttribute(SpellAttr10.UseSpellBaseLevelForScaling)) level = _spellInfo.BaseLevel; if (_spellInfo.Scaling.MinScalingLevel != 0 && _spellInfo.Scaling.MinScalingLevel > level) diff --git a/Scripts/Northrend/AzjolNerub/AzjolNerub/BossKrikthirTheGatewatcher.cs b/Scripts/Northrend/AzjolNerub/AzjolNerub/BossKrikthirTheGatewatcher.cs index 375942333..a6d410014 100644 --- a/Scripts/Northrend/AzjolNerub/AzjolNerub/BossKrikthirTheGatewatcher.cs +++ b/Scripts/Northrend/AzjolNerub/AzjolNerub/BossKrikthirTheGatewatcher.cs @@ -393,7 +393,6 @@ namespace Scripts.Northrend.AzjolNerub.AzjolNerub.KrikthirTheGatewatcher { public npc_watcher_gashra(Creature creature) : base(creature, true) { - _instance = creature.GetInstanceScript(); me.SetReactState(ReactStates.Passive); } @@ -451,10 +450,7 @@ namespace Scripts.Northrend.AzjolNerub.AzjolNerub.KrikthirTheGatewatcher [Script] class npc_watcher_narjil : npc_gatewatcher_petAI { - public npc_watcher_narjil(Creature creature) : base(creature, true) - { - _instance = creature.GetInstanceScript(); - } + public npc_watcher_narjil(Creature creature) : base(creature, true) { } public override void Reset() { @@ -510,10 +506,7 @@ namespace Scripts.Northrend.AzjolNerub.AzjolNerub.KrikthirTheGatewatcher [Script] class npc_watcher_silthik : npc_gatewatcher_petAI { - public npc_watcher_silthik(Creature creature) : base(creature, true) - { - _instance = creature.GetInstanceScript(); - } + public npc_watcher_silthik(Creature creature) : base(creature, true) { } public override void Reset() { diff --git a/Scripts/Spells/Generic.cs b/Scripts/Spells/Generic.cs index 6eee76bb8..bbb08a37f 100644 --- a/Scripts/Spells/Generic.cs +++ b/Scripts/Spells/Generic.cs @@ -391,7 +391,7 @@ namespace Scripts.Spells.Generic bool CheckProc(ProcEventInfo eventInfo) { - if (eventInfo.GetDamageInfo().GetSpellInfo() != null) // eventInfo.GetSpellInfo() + if (eventInfo.GetSpellInfo() == null) return false; // find Mage Armor @@ -1705,7 +1705,7 @@ namespace Scripts.Spells.Generic bool CheckProc(ProcEventInfo eventInfo) { - if (eventInfo.GetDamageInfo().GetSpellInfo() != null) // eventInfo.GetSpellInfo() + if (eventInfo.GetSpellInfo() == null) return false; if (SharedConst.GetFirstSchoolInMask(eventInfo.GetSchoolMask()) == SpellSchools.Normal) diff --git a/Scripts/Spells/Hunter.cs b/Scripts/Spells/Hunter.cs index 183f9bec2..f7a3247a8 100644 --- a/Scripts/Spells/Hunter.cs +++ b/Scripts/Spells/Hunter.cs @@ -483,9 +483,16 @@ namespace Scripts.Spells.Hunter return ValidateSpellInfo(SpellIds.RoarOfSacrificeTriggered); } - bool CheckProc(ProcEventInfo eventInfo) + bool CheckProc(AuraEffect aurEff, ProcEventInfo eventInfo) { - return GetCaster() && ((uint)eventInfo.GetDamageInfo().GetSchoolMask() & GetEffect(1).GetMiscValue()) != 0; + DamageInfo damageInfo = eventInfo.GetDamageInfo(); + if (damageInfo == null || !Convert.ToBoolean((int)damageInfo.GetSchoolMask() & aurEff.GetMiscValue())) + return false; + + if (!GetCaster()) + return false; + + return true; } void HandleProc(AuraEffect aurEff, ProcEventInfo eventInfo) @@ -498,7 +505,7 @@ namespace Scripts.Spells.Hunter public override void Register() { - DoCheckProc.Add(new CheckProcHandler(CheckProc)); + DoCheckEffectProc.Add(new CheckEffectProcHandler(CheckProc, 1, AuraType.Dummy)); OnEffectProc.Add(new EffectProcHandler(HandleProc, 1, AuraType.Dummy)); } } diff --git a/Scripts/Spells/Items.cs b/Scripts/Spells/Items.cs index 344d348e3..b5f0cfd22 100644 --- a/Scripts/Spells/Items.cs +++ b/Scripts/Spells/Items.cs @@ -1360,7 +1360,11 @@ namespace Scripts.Spells.Items void HandleProc(AuraEffect aurEff, ProcEventInfo eventInfo) { PreventDefaultAction(); - int bp = (int)MathFunctions.CalculatePct(eventInfo.GetDamageInfo().GetDamage(), aurEff.GetAmount()); + DamageInfo damageInfo = eventInfo.GetDamageInfo(); + if (damageInfo == null || damageInfo.GetDamage() == 0) + return; + + int bp = (int)MathFunctions.CalculatePct(damageInfo.GetDamage(), aurEff.GetAmount()); GetTarget().CastCustomSpell(SpellIds.ItemNecroticTouchProc, SpellValueMod.BasePoint0, bp, eventInfo.GetProcTarget(), true, null, aurEff); } diff --git a/Scripts/Spells/Paladin.cs b/Scripts/Spells/Paladin.cs index 92f0d9ff8..20a10beb4 100644 --- a/Scripts/Spells/Paladin.cs +++ b/Scripts/Spells/Paladin.cs @@ -258,7 +258,11 @@ namespace Scripts.Spells.Paladin void HandleEffectProc(AuraEffect aurEff, ProcEventInfo eventInfo) { PreventDefaultAction(); - int damage = (int)MathFunctions.CalculatePct(eventInfo.GetDamageInfo().GetDamage(), aurEff.GetAmount()); + DamageInfo damageInfo = eventInfo.GetDamageInfo(); + if (damageInfo == null || damageInfo.GetDamage() == 0) + return; + + int damage = (int)MathFunctions.CalculatePct(damageInfo.GetDamage(), aurEff.GetAmount()); GetTarget().CastCustomSpell(SpellIds.EyeForAnEyeDamage, SpellValueMod.BasePoint0, damage, eventInfo.GetProcTarget(), true, null, aurEff); } diff --git a/Scripts/Spells/Warlock.cs b/Scripts/Spells/Warlock.cs index 4a8435bf7..17fa73e28 100644 --- a/Scripts/Spells/Warlock.cs +++ b/Scripts/Spells/Warlock.cs @@ -123,6 +123,32 @@ namespace Scripts.Spells.Warlock } } + [Script] // 77220 - Mastery: Chaotic Energies + class spell_warl_chaotic_energies : AuraScript + { + void HandleAbsorb(AuraEffect aurEff, DamageInfo dmgInfo, ref uint absorbAmount) + { + AuraEffect effect1 = GetEffect(1); + if (effect1 == null || !GetTargetApplication().HasEffect(1)) + { + PreventDefaultAction(); + return; + } + + // You take ${$s2/3}% reduced damage + float damageReductionPct = effect1.GetAmount() / 3; + // plus a random amount of up to ${$s2/3}% additional reduced damage + damageReductionPct += RandomHelper.FRand(0.0f, damageReductionPct); + + absorbAmount = MathFunctions.CalculatePct(dmgInfo.GetDamage(), damageReductionPct); + } + + public override void Register() + { + OnEffectAbsorb.Add(new EffectAbsorbHandler(HandleAbsorb, 2)); + } + } + [Script] // 6201 - Create Healthstone class spell_warl_create_healthstone : SpellScript { @@ -409,7 +435,11 @@ namespace Scripts.Spells.Warlock bool CheckProc(ProcEventInfo eventInfo) { - return GetTarget().GetGuardianPet() && eventInfo.GetDamageInfo().GetDamage() != 0; + DamageInfo damageInfo = eventInfo.GetDamageInfo(); + if (damageInfo == null || damageInfo.GetDamage() == 0) + return false; + + return GetTarget().GetGuardianPet(); } void onProc(AuraEffect aurEff, ProcEventInfo eventInfo) @@ -656,7 +686,7 @@ namespace Scripts.Spells.Warlock { PreventDefaultAction(); DamageInfo damageInfo = eventInfo.GetDamageInfo(); - if (damageInfo == null) + if (damageInfo == null || damageInfo.GetDamage() == 0) return; int amount = (int)(aurEff.GetAmount() - damageInfo.GetDamage()); @@ -700,7 +730,7 @@ namespace Scripts.Spells.Warlock { PreventDefaultAction(); DamageInfo damageInfo = eventInfo.GetDamageInfo(); - if (damageInfo == null) + if (damageInfo == null || damageInfo.GetDamage() == 0) return; int amount = aurEff.GetAmount() - (int)damageInfo.GetDamage(); diff --git a/Scripts/Spells/Warrior.cs b/Scripts/Spells/Warrior.cs index f7cd8e608..38227a2e2 100644 --- a/Scripts/Spells/Warrior.cs +++ b/Scripts/Spells/Warrior.cs @@ -28,6 +28,7 @@ namespace Scripts.Spells.Warrior { struct SpellIds { + public const uint BladestormPeriodicWhirlwind = 50622; public const uint BloodthirstHeal = 117313; public const uint Charge = 34846; public const uint ChargeEffect = 218104; @@ -61,7 +62,8 @@ namespace Scripts.Spells.Warrior public const uint Slam = 50782; public const uint Stoicism = 70845; public const uint StormBoltStun = 132169; - public const uint SweepingStrikesExtraAttack = 26654; + public const uint SweepingStrikesExtraAttack1 = 12723; + public const uint SweepingStrikesExtraAttack2 = 26654; public const uint Taunt = 355; public const uint TraumaEffect = 215537; public const uint UnrelentingAssaultRank1 = 46859; @@ -703,13 +705,7 @@ namespace Scripts.Spells.Warrior { public override bool Validate(SpellInfo spellInfo) { - return ValidateSpellInfo(SpellIds.SweepingStrikesExtraAttack); - } - - public override bool Load() - { - _procTarget = null; - return true; + return ValidateSpellInfo(SpellIds.SweepingStrikesExtraAttack1, SpellIds.SweepingStrikesExtraAttack2); } bool CheckProc(ProcEventInfo eventInfo) @@ -721,7 +717,21 @@ namespace Scripts.Spells.Warrior void HandleProc(AuraEffect aurEff, ProcEventInfo eventInfo) { PreventDefaultAction(); - GetTarget().CastSpell(_procTarget, SpellIds.SweepingStrikesExtraAttack, true, null, aurEff); + DamageInfo damageInfo = eventInfo.GetDamageInfo(); + if (damageInfo != null) + { + SpellInfo spellInfo = damageInfo.GetSpellInfo(); + if (spellInfo != null && (spellInfo.Id == SpellIds.BladestormPeriodicWhirlwind || (spellInfo.Id == SpellIds.Execute && !_procTarget.HasAuraState(AuraStateType.HealthLess20Percent)))) + { + // If triggered by Execute (while target is not under 20% hp) or Bladestorm deals normalized weapon damage + GetTarget().CastSpell(_procTarget, SpellIds.SweepingStrikesExtraAttack2, true, null, aurEff); + } + else + { + int damage = (int)damageInfo.GetDamage(); + GetTarget().CastCustomSpell(SpellIds.SweepingStrikesExtraAttack1, SpellValueMod.BasePoint0, damage, _procTarget, true, null, aurEff); + } + } } public override void Register()