fix: tighten Spell Focusing Sash cleanup

This commit is contained in:
Crome696 2026-07-10 15:50:23 +02:00
parent f040f1b69c
commit dfee8f09c5
3 changed files with 55 additions and 8 deletions

View file

@ -25,11 +25,13 @@ public class SpellFocusingSashTests
public void SpellFocusingSash_HasArtifactStatsAndPropertyOrder()
{
var previousExpansion = Core.Expansion;
var caster = CreateMobile(player: true);
var sash = new SpellFocusingSash();
try
{
Core.Expansion = Expansion.SA;
caster.AddItem(sash);
var list = new RecordingPropertyList();
sash.GetProperties(list);
@ -39,6 +41,8 @@ public class SpellFocusingSashTests
Assert.Equal(10, sash.StrRequirement);
Assert.Equal(255, sash.HitPoints);
Assert.Equal(255, sash.MaxHitPoints);
Assert.Equal(1, AosAttributes.GetValue(caster, AosAttribute.BonusMana));
Assert.Equal(5, AosAttributes.GetValue(caster, AosAttribute.DefendChance));
Assert.True(NegativeAttributes.IsBrittle(sash));
var spellFocusingIndex = list.Entries.FindIndex(entry => entry.Number == SpellFocusingCliloc);
@ -58,14 +62,17 @@ public class SpellFocusingSashTests
var preStygianAbyss = new RecordingPropertyList();
sash.GetProperties(preStygianAbyss);
Assert.DoesNotContain(preStygianAbyss.Entries, entry => entry.Number == SpellFocusingCliloc);
Assert.Contains(preStygianAbyss.Entries, entry => entry.Number == ManaIncreaseCliloc && entry.Argument == "1");
Assert.Contains(preStygianAbyss.Entries, entry => entry.Number == DefendChanceCliloc && entry.Argument == "5");
Assert.DoesNotContain(preStygianAbyss.Entries, entry => entry.Number == ManaIncreaseCliloc);
Assert.DoesNotContain(preStygianAbyss.Entries, entry => entry.Number == DefendChanceCliloc);
Assert.Equal(0, AosAttributes.GetValue(caster, AosAttribute.BonusMana));
Assert.Equal(0, AosAttributes.GetValue(caster, AosAttribute.DefendChance));
Assert.False(NegativeAttributes.IsBrittle(sash));
}
finally
{
Core.Expansion = previousExpansion;
sash.Delete();
caster.Delete();
}
}
@ -229,10 +236,15 @@ public class SpellFocusingSashTests
Assert.True(SpellFocusing.TryGetDamageOffset(spell, caster, target, out var secondOffset));
Assert.Equal(-24, secondOffset);
SpellFocusingSash.Clear(target);
Assert.True(SpellFocusing.TryGetDamageOffset(spell, caster, target, out var targetResetOffset));
Assert.Equal(-30, targetResetOffset);
SpellFocusingSash.Clear(caster);
Assert.True(SpellFocusing.TryGetDamageOffset(spell, caster, target, out var resetOffset));
Assert.Equal(-30, resetOffset);
Assert.True(SpellFocusing.TryGetDamageOffset(spell, caster, target, out var casterResetOffset));
Assert.Equal(-30, casterResetOffset);
target.Delete();
Assert.False(SpellFocusing.TryGetDamageOffset(spell, caster, target, out _));
@ -269,8 +281,12 @@ public class SpellFocusingSashTests
{
caster.AddItem(sash);
var spell = new NonQualifyingSpell(caster);
var qualifyingSpell = new TestSpell(caster);
Core.Expansion = Expansion.ML;
Assert.False(SpellFocusing.TryGetDamageOffset(qualifyingSpell, caster, target, out _));
Assert.Equal(0, AosAttributes.GetValue(caster, AosAttribute.BonusMana));
Assert.Equal(0, AosAttributes.GetValue(caster, AosAttribute.DefendChance));
Assert.False(SpellFocusing.TryGetDamageOffset(spell, caster, target, out _));
Core.Expansion = Expansion.SA;

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using ModernUO.Serialization;
using Server.Collections;
@ -21,6 +22,8 @@ public partial class SpellFocusingSash : BaseMiddleTorso
private const int BuffSecondaryCliloc = 1151392;
private const int SequenceLength = 21;
private static readonly HashSet<SpellFocusingSash> ActiveSashes = [];
private Mobile _spellCastTarget;
private int _spellCastCount;
private bool _enabled = true;
@ -149,10 +152,36 @@ public partial class SpellFocusingSash : BaseMiddleTorso
[OnEvent(nameof(BaseCreature.CreatureDeletedEvent))]
public static void Clear(Mobile mobile)
{
if (mobile?.FindItemOnLayer(Layer.MiddleTorso) is SpellFocusingSash sash)
if (mobile == null)
{
return;
}
if (mobile.FindItemOnLayer(Layer.MiddleTorso) is SpellFocusingSash sash)
{
sash.ResetSequence(mobile);
}
if (ActiveSashes.Count == 0)
{
return;
}
using var sashes = PooledRefList<SpellFocusingSash>.Create();
foreach (var activeSash in ActiveSashes)
{
if (activeSash._spellCastTarget == mobile)
{
sashes.Add(activeSash);
}
}
for (var i = 0; i < sashes.Count; i++)
{
var activeSash = sashes[i];
activeSash.ResetSequence(activeSash.Parent as Mobile);
}
}
private bool TryGetDamageOffset(Mobile caster, Mobile target, out int offset)
@ -173,6 +202,7 @@ public partial class SpellFocusingSash : BaseMiddleTorso
ResetSequence(caster);
_spellCastTarget = target;
ActiveSashes.Add(this);
}
offset = GetDamageOffset(_spellCastCount, target.Player);
@ -209,6 +239,7 @@ public partial class SpellFocusingSash : BaseMiddleTorso
private void ResetSequence(Mobile caster)
{
ActiveSashes.Remove(this);
_spellCastTarget = null;
_spellCastCount = 0;

View file

@ -616,7 +616,7 @@ namespace Server
}
// The SA event sash emits its fixed Mana/Defense lines in artifact order from AddNameProperties.
if ((Owner is not SpellFocusingSash || !Core.SA) && (prop = DefendChance) != 0)
if (Owner is not SpellFocusingSash && (prop = DefendChance) != 0)
{
list.Add(1060408, prop); // defense chance increase ~1_val~%
}
@ -671,7 +671,7 @@ namespace Server
list.Add(1060436, prop); // luck ~1_val~
}
if ((Owner is not SpellFocusingSash || !Core.SA) && (prop = BonusMana) != 0)
if (Owner is not SpellFocusingSash && (prop = BonusMana) != 0)
{
list.Add(1060439, prop); // mana increase ~1_val~
}
@ -792,7 +792,7 @@ namespace Server
{
var attrs = clothing.Attributes;
if (attrs != null)
if (attrs != null && (clothing is not SpellFocusingSash || Core.SA))
{
value += attrs[attribute];
}