ModernUO/Projects/UOContent/Items/Suits/BaseSuit.cs
Kamron Batman 4849c80750
refactor: fold hand-written serializable property setters into field hooks
Converts 113 [SerializableProperty] members whose setters only coerce the
value, reject it, or run post-change side effects into plain
[SerializableField] declarations using allowFieldChange and fieldChanged.
Wire- and schema-neutral: the migration schema regeneration produces zero
changes.

Kept as hand-written properties: custom getters (fallback defaults, lazy or
self-healing reads), virtual/override members, pre-assignment state capture
(durability unscale/scale sandwiches), and setters with exotic semantics
(work on equal assignment, early returns that skip persistence).

Behavioral notes: generated setters skip all work when the incoming value
equals the field, and always MarkDirty on change - a handful of converted
setters previously never marked dirty (their changes only persisted if
something else dirtied the entity) or re-ran side effects on equal
assignment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-22 18:07:47 -07:00

72 lines
1.6 KiB
C#

using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(1, false)]
public abstract partial class BaseSuit : Item
{
public BaseSuit(AccessLevel level, int hue, int itemID) : base(itemID)
{
Hue = hue;
Movable = false;
LootType = LootType.Newbied;
Layer = Layer.OuterTorso;
_accessLevel = level;
}
public override double DefaultWeight => 1.0;
[SerializableField(0, fieldChanged: nameof(OnAccessLevelChanged))]
[InvalidateProperties]
private AccessLevel _accessLevel;
public virtual void OnAccessLevelChanged(AccessLevel oldAccessLevel, AccessLevel accessLevel)
{
}
private void Deserialize(IGenericReader reader, int version)
{
AccessLevel = (AccessLevel)reader.ReadInt();
}
public bool Validate()
{
if (RootParent is not Mobile mobile || mobile.AccessLevel >= AccessLevel)
{
return true;
}
Delete();
return false;
}
public override void OnSingleClick(Mobile from)
{
if (Validate())
{
base.OnSingleClick(from);
}
}
public override void OnDoubleClick(Mobile from)
{
if (Validate())
{
base.OnDoubleClick(from);
}
}
public override bool VerifyMove(Mobile from) => from.AccessLevel >= AccessLevel;
public override bool OnEquip(Mobile from)
{
if (from.AccessLevel < AccessLevel)
{
from.SendMessage("You may not wear this.");
return false;
}
return true;
}
}