Skip to content

Commit

Permalink
fix: Fixes monster ability firing after dying
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Nov 5, 2024
1 parent b475e17 commit b721e03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Projects/UOContent/Mobiles/Abilities/MonsterAbility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// 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.
/// </summary>
/// <returns>Boolean indicating the ability can trigger.</returns>
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;
Expand All @@ -54,11 +56,11 @@ public virtual bool CanTrigger(BaseCreature source, MonsterAbilityTrigger trigge
/// <summary>
/// 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)
/// </summary>
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;
}
Expand Down
5 changes: 5 additions & 0 deletions Projects/UOContent/Spells/Base/SpellHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,11 @@ public SpellDamageTimerAOS(

protected override void OnTick()
{
if (m_Target.Deleted || !m_Target.Alive)
{
return;
}

Damage(
m_Spell,
TimeSpan.Zero,
Expand Down

0 comments on commit b721e03

Please sign in to comment.