From b721e038d65dcc3d77f20b1b6ea0990a16477675 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:23:33 -0800 Subject: [PATCH] fix: Fixes monster ability firing after dying --- .../UOContent/Mobiles/Abilities/MonsterAbility.cs | 14 ++++++++------ Projects/UOContent/Spells/Base/SpellHelper.cs | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Projects/UOContent/Mobiles/Abilities/MonsterAbility.cs b/Projects/UOContent/Mobiles/Abilities/MonsterAbility.cs index abe9597ac4..72fb61ec3a 100644 --- a/Projects/UOContent/Mobiles/Abilities/MonsterAbility.cs +++ b/Projects/UOContent/Mobiles/Abilities/MonsterAbility.cs @@ -18,17 +18,19 @@ public abstract partial class MonsterAbility public virtual TimeSpan MinTriggerCooldown => TimeSpan.Zero; public virtual TimeSpan MaxTriggerCooldown => TimeSpan.Zero; - // To prevent reflect from harming the monster - public virtual bool CanTriggerAgainstSelf => false; - public bool WillTrigger(MonsterAbilityTrigger trigger) => (AbilityTrigger & trigger) != 0; /// - /// Returns true if ability is not on cooldown, and the change to trigger succeeds. + /// Returns true if ability is not on cooldown, and the chance to trigger succeeds. /// /// Boolean indicating the ability can trigger. public virtual bool CanTrigger(BaseCreature source, MonsterAbilityTrigger trigger) { + if (source is not { Alive: true, Deleted: false }) + { + return false; + } + if (_nextTriggerTicks?.TryGetValue(source, out var nextTrigger) == true && nextTrigger - Core.TickCount > 0) { return false; @@ -54,11 +56,11 @@ public virtual bool CanTrigger(BaseCreature source, MonsterAbilityTrigger trigge /// /// Triggers the monster's ability. Override this and call `base.Trigger(source);` to make sure /// the cooldown is tracked. + /// Note: This can fire after a monster is killed/deleted (map is null) /// public virtual void Trigger(MonsterAbilityTrigger trigger, BaseCreature source, Mobile target) { - if (!CanTriggerAgainstSelf && target == source || - MinTriggerCooldown <= TimeSpan.Zero && MaxTriggerCooldown <= TimeSpan.Zero) + if (MinTriggerCooldown <= TimeSpan.Zero && MaxTriggerCooldown <= TimeSpan.Zero) { return; } diff --git a/Projects/UOContent/Spells/Base/SpellHelper.cs b/Projects/UOContent/Spells/Base/SpellHelper.cs index 14eb566a28..396e64fdbc 100644 --- a/Projects/UOContent/Spells/Base/SpellHelper.cs +++ b/Projects/UOContent/Spells/Base/SpellHelper.cs @@ -1140,6 +1140,11 @@ public SpellDamageTimerAOS( protected override void OnTick() { + if (m_Target.Deleted || !m_Target.Alive) + { + return; + } + Damage( m_Spell, TimeSpan.Zero,