ModernUO/Projects/UOContent/Engines/Treasures of Tokuno/LesserArtifacts.cs
Kamron Batman b042edcf0b
refactor: fold hand-written serializable property setters into field hooks (#2587)
## Summary

Folds **113** hand-written `[SerializableProperty]` members into plain `[SerializableField]` declarations using the v4 setter hooks — value coercion/vetoes via `allowFieldChange`, post-change side effects via `fieldChanged` (whose `oldValue` parameter covers the old-house/old-sender unsubscribe patterns). Net **-450 lines** of setter boilerplate.

```cs
// before
[SerializableProperty(1)]
[CommandProperty(AccessLevel.GameMaster)]
public int Charges
{
    get => _charges;
    set
    {
        _charges = Math.Clamp(value, 0, MaxCharges);
        InvalidateProperties();
        this.MarkDirty();
    }
}

// after
[SerializableField(1, allowFieldChange: nameof(AllowChargesChange))]
[SerializedCommandProperty(AccessLevel.GameMaster)]
[InvalidateProperties]
private int _charges;

private bool AllowChargesChange(ref int value)
{
    value = Math.Clamp(value, 0, MaxCharges);
    return true;
}
```

## How sites were selected

A classifier parsed all 204 `[SerializableProperty]` sites and converted only those matching strict shapes: getter is exactly `get => _field;`, the assignment comes first (after at most an equality guard), and relocated side effects contain no `return`, no `value` mutation, and no field re-assignment. Everything else was left alone deliberately:

- **~34 custom getters** (fallback defaults like `_x == -1 ? Default : _x`, self-healing refs) — no setter hook can express these.
- **~35 pre-assignment logic** (durability Unscale/Scale sandwiches, old-state captures like PotionKeg's pile weight).
- **virtual/override members, name-mismatched backing fields (`m_`), exotic semantics** (guards' `Focus` does work on *equal* assignment; `ChampionSpawn.Active` never assigns its field).

Five sites the classifier refused were converted by hand where the hooks fit cleanly: `ReceiverCrystal.Sender`, `PlayerVendor.House`, `PlayerBarkeeper.House` (old-value unsubscribe via `oldValue`), `BaseSuit.AccessLevel` (its existing virtual `OnAccessLevelChanged` already had the exact callback shape), and `DyeTub.DyedHue` (a true veto: `AllowDyedHueChange(ref int value) => _redyable`).

## Verification

- Build: **0 errors, 0 warnings**.
- **Schema regeneration produces zero Migrations changes** — the conversion is wire- and schema-neutral by construction (same orders, types, and property names), and CI's schema diff check enforces it.
- **835 + 708 tests green.**

## Behavioral notes (all strict improvements, called out for review)

- Generated setters skip everything when the incoming value equals the current one; a few converted setters previously re-ran side effects on equal assignment (redundant `Update()`-style refreshes).
- Generated setters always `MarkDirty()` on change; several converted setters never did (e.g. `DyeTub.DyedHue`, `MorphItem` ranges) — their changes only persisted if something else dirtied the entity. Those latent persistence bugs are fixed by construction.
2026-08-22 18:20:39 -07:00

674 lines
16 KiB
C#

using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class AncientFarmersKasa : Kasa
{
[Constructible]
public AncientFarmersKasa()
{
Attributes.BonusStr = 5;
Attributes.BonusStam = 5;
Attributes.RegenStam = 5;
SkillBonuses.SetValues(0, SkillName.AnimalLore, 5.0);
}
public override int LabelNumber => 1070922; // Ancient Farmer's Kasa
public override int BaseColdResistance => 19;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class AncientSamuraiDo : PlateDo
{
[Constructible]
public AncientSamuraiDo()
{
ArmorAttributes.LowerStatReq = 100;
ArmorAttributes.MageArmor = 1;
SkillBonuses.SetValues(0, SkillName.Parry, 10.0);
}
public override int LabelNumber => 1070926; // Ancient Samurai Do
public override int BasePhysicalResistance => 15;
public override int BaseFireResistance => 12;
public override int BaseColdResistance => 10;
public override int BasePoisonResistance => 11;
public override int BaseEnergyResistance => 8;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class ArmsOfTacticalExcellence : LeatherHiroSode
{
[Constructible]
public ArmsOfTacticalExcellence()
{
Attributes.BonusDex = 5;
SkillBonuses.SetValues(0, SkillName.Tactics, 12.0);
}
public override int LabelNumber => 1070921; // Arms of Tactical Excellence
public override int BaseFireResistance => 9;
public override int BaseColdResistance => 13;
public override int BasePoisonResistance => 8;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class BlackLotusHood : ClothNinjaHood
{
[Constructible]
public BlackLotusHood()
{
Attributes.LowerManaCost = 6;
Attributes.AttackChance = 6;
ClothingAttributes.SelfRepair = 5;
}
public override int LabelNumber => 1070919; // Black Lotus Hood
public override int BasePhysicalResistance => 0;
public override int BaseFireResistance => 11;
public override int BaseColdResistance => 15;
public override int BasePoisonResistance => 11;
public override int BaseEnergyResistance => 11;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class DaimyosHelm : PlateBattleKabuto
{
[Constructible]
public DaimyosHelm()
{
ArmorAttributes.LowerStatReq = 100;
ArmorAttributes.MageArmor = 1;
ArmorAttributes.SelfRepair = 3;
Attributes.WeaponSpeed = 10;
}
public override int LabelNumber => 1070920; // Daimyo's Helm
public override int BaseColdResistance => 10;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class DemonForks : Sai
{
[Constructible]
public DemonForks()
{
WeaponAttributes.ResistFireBonus = 10;
WeaponAttributes.ResistPoisonBonus = 10;
Attributes.ReflectPhysical = 10;
Attributes.WeaponDamage = 35;
Attributes.DefendChance = 10;
}
public override int LabelNumber => 1070917; // Demon Forks
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class DragonNunchaku : Nunchaku
{
[Constructible]
public DragonNunchaku()
{
WeaponAttributes.ResistFireBonus = 5;
WeaponAttributes.SelfRepair = 3;
WeaponAttributes.HitFireball = 50;
Attributes.WeaponDamage = 40;
Attributes.WeaponSpeed = 20;
}
public override int LabelNumber => 1070914; // Dragon Nunchaku
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class Exiler : Tetsubo
{
[Constructible]
public Exiler()
{
WeaponAttributes.HitDispel = 33;
Slayer = SlayerName.Exorcism;
Attributes.WeaponDamage = 40;
Attributes.WeaponSpeed = 20;
}
public override int LabelNumber => 1070913; // Exiler
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
public override void GetDamageTypes(
Mobile wielder, out int phys, out int fire, out int cold, out int pois,
out int nrgy, out int chaos, out int direct
)
{
phys = fire = cold = pois = chaos = direct = 0;
nrgy = 100;
}
}
[SerializationGenerator(0, false)]
public partial class GlovesOfTheSun : LeatherNinjaMitts
{
[Constructible]
public GlovesOfTheSun()
{
Attributes.RegenHits = 2;
Attributes.NightSight = 1;
Attributes.LowerManaCost = 5;
Attributes.LowerRegCost = 18;
}
public override int LabelNumber => 1070924; // Gloves of the Sun
public override int BaseFireResistance => 24;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class HanzosBow : Yumi
{
[Constructible]
public HanzosBow()
{
WeaponAttributes.HitLeechHits = 40;
WeaponAttributes.SelfRepair = 3;
Attributes.WeaponDamage = 50;
SkillBonuses.SetValues(0, SkillName.Ninjitsu, 10);
}
public override int LabelNumber => 1070918; // Hanzo's Bow
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class LegsOfStability : PlateSuneate
{
[Constructible]
public LegsOfStability()
{
Attributes.BonusStam = 5;
ArmorAttributes.SelfRepair = 3;
ArmorAttributes.LowerStatReq = 100;
ArmorAttributes.MageArmor = 1;
}
public override int LabelNumber => 1070925; // Legs of Stability
public override int BasePhysicalResistance => 20;
public override int BasePoisonResistance => 18;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class PeasantsBokuto : Bokuto
{
[Constructible]
public PeasantsBokuto()
{
WeaponAttributes.SelfRepair = 3;
WeaponAttributes.HitLowerDefend = 30;
Attributes.WeaponDamage = 35;
Attributes.WeaponSpeed = 10;
Slayer = SlayerName.SnakesBane;
}
public override int LabelNumber => 1070912; // Peasant's Bokuto
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class PilferedDancerFans : Tessen
{
[Constructible]
public PilferedDancerFans()
{
Attributes.WeaponDamage = 20;
Attributes.WeaponSpeed = 20;
Attributes.CastRecovery = 2;
Attributes.DefendChance = 5;
Attributes.SpellChanneling = 1;
}
public override int LabelNumber => 1070916; // Pilfered Dancer Fans
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class TheDestroyer : NoDachi
{
[Constructible]
public TheDestroyer()
{
WeaponAttributes.HitLeechStam = 40;
Attributes.BonusStr = 6;
Attributes.AttackChance = 10;
Attributes.WeaponDamage = 50;
}
public override int LabelNumber => 1070915; // The Destroyer
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
[SerializationGenerator(0, false)]
public partial class TomeOfEnlightenment : Spellbook
{
[Constructible]
public TomeOfEnlightenment()
{
LootType = LootType.Regular;
Hue = 0x455;
Attributes.BonusInt = 5;
Attributes.SpellDamage = 10;
Attributes.CastSpeed = 1;
}
public override int LabelNumber => 1070934; // Tome of Enlightenment
}
[SerializationGenerator(0, false)]
public partial class LeurociansMempoOfFortune : LeatherMempo
{
[Constructible]
public LeurociansMempoOfFortune()
{
LootType = LootType.Regular;
Hue = 0x501;
Attributes.Luck = 300;
Attributes.RegenMana = 1;
}
public override int LabelNumber => 1071460; // Leurocian's mempo of fortune
public override int BasePhysicalResistance => 15;
public override int BaseFireResistance => 10;
public override int BaseColdResistance => 10;
public override int BasePoisonResistance => 10;
public override int BaseEnergyResistance => 15;
public override int InitMinHits => 255;
public override int InitMaxHits => 255;
}
// Non weapon/armor ones:
[SerializationGenerator(0, false)]
public partial class AncientUrn : Item
{
[InvalidateProperties]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private string _urnName;
[Constructible]
public AncientUrn() : this(Names.RandomElement())
{
}
[Constructible]
public AncientUrn(string urnName) : base(0x241D) => _urnName = urnName;
public override double DefaultWeight => 1.0;
public static string[] Names { get; } =
{
"Akira",
"Avaniaga",
"Aya",
"Chie",
"Emiko",
"Fumiyo",
"Gennai",
"Gennosuke",
"Genjo",
"Hamato",
"Harumi",
"Ikuyo",
"Juri",
"Kaori",
"Kaoru",
"Kiyomori",
"Mayako",
"Motoki",
"Musashi",
"Nami",
"Nobukazu",
"Roku",
"Romi",
"Ryo",
"Sanzo",
"Sakamae",
"Satoshi",
"Takamori",
"Takuro",
"Teruyo",
"Toshiro",
"Yago",
"Yeijiro",
"Yoshi",
"Zeshin"
};
public override int LabelNumber => 1071014; // Ancient Urn
[AfterDeserialization]
private void AfterDeserialization()
{
Utility.Intern(ref _urnName);
}
public override void AddNameProperty(IPropertyList list)
{
list.Add(1070935, _urnName); // Ancient Urn of ~1_name~
}
public override void OnSingleClick(Mobile from)
{
LabelTo(from, 1070935, _urnName); // Ancient Urn of ~1_name~
}
}
[SerializationGenerator(0, false)]
public partial class HonorableSwords : Item
{
[InvalidateProperties]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private string _swordsName;
[Constructible]
public HonorableSwords() : this(AncientUrn.Names.RandomElement())
{
}
[Constructible]
public HonorableSwords(string swordsName) : base(0x2853) => _swordsName = swordsName;
public override double DefaultWeight => 5.0;
public override int LabelNumber => 1071015; // Honorable Swords
public override void AddNameProperty(IPropertyList list)
{
list.Add(1070936, _swordsName); // Honorable Swords of ~1_name~
}
public override void OnSingleClick(Mobile from)
{
LabelTo(from, 1070936, _swordsName); // Honorable Swords of ~1_name~
}
[AfterDeserialization]
private void AfterDeserialization()
{
Utility.Intern(ref _swordsName);
}
}
[Furniture]
[Flippable(0x2811, 0x2812)]
[SerializationGenerator(0, false)]
public partial class ChestOfHeirlooms : LockableContainer
{
[Constructible]
public ChestOfHeirlooms() : base(0x2811)
{
Locked = true;
LockLevel = 95;
MaxLockLevel = 140;
RequiredSkill = 95;
TrapType = TrapType.ExplosionTrap;
TrapLevel = 10;
TrapPower = 100;
GumpID = 0x10B;
for (var i = 0; i < 10; ++i)
{
var item = Loot.RandomChestOfHeirloomsContent();
var attributeCount = Utility.RandomMinMax(1, 5);
var min = 20;
var max = 80;
if (item is BaseWeapon weapon)
{
if (Core.AOS)
{
BaseRunicTool.ApplyAttributesTo(weapon, attributeCount, min, max);
}
else
{
weapon.DamageLevel = (WeaponDamageLevel)Utility.Random(6);
weapon.AccuracyLevel = (WeaponAccuracyLevel)Utility.Random(6);
weapon.DurabilityLevel = (WeaponDurabilityLevel)Utility.Random(6);
}
}
else if (item is BaseArmor armor)
{
if (Core.AOS)
{
BaseRunicTool.ApplyAttributesTo(armor, attributeCount, min, max);
}
else
{
armor.ProtectionLevel = (ArmorProtectionLevel)Utility.Random(6);
armor.Durability = (ArmorDurabilityLevel)Utility.Random(6);
}
}
else if (Core.AOS)
{
if (item is BaseHat hat)
{
BaseRunicTool.ApplyAttributesTo(hat, attributeCount, min, max);
}
else if (item is BaseJewel jewel)
{
BaseRunicTool.ApplyAttributesTo(jewel, attributeCount, min, max);
}
}
DropItem(item);
}
}
public override int LabelNumber => 1070937; // Chest of heirlooms
}
[SerializationGenerator(0, false)]
public partial class FluteOfRenewal : BambooFlute
{
[Constructible]
public FluteOfRenewal()
{
// -1 to exclude Fey slayer. Try to confirm no fey slayer on this on OSI
Slayer = SlayerGroup.Groups[Utility.Random(SlayerGroup.Groups.Length - 1)].Super.Name;
ReplenishesCharges = true;
}
public override int LabelNumber => 1070927; // Flute of Renewal
public override int InitMinUses => 300;
public override int InitMaxUses => 300;
}
public enum LesserPigmentType
{
None,
PaleOrange,
FreshRose,
ChaosBlue,
Silver,
NobleGold,
LightGreen,
PaleBlue,
FreshPlum,
DeepBrown,
BurntBrown
}
[SerializationGenerator(0, false)]
public partial class LesserPigmentsOfTokuno : BasePigmentsOfTokuno
{
private static readonly int[][] _table =
{
// Hue, Label
new[]
{
/*PigmentType.None,*/ 0, -1
},
new[]
{
/*PigmentType.PaleOrange,*/ 0x02E, 1071458
},
new[]
{
/*PigmentType.FreshRose,*/ 0x4B9, 1071455
},
new[]
{
/*PigmentType.ChaosBlue,*/ 0x005, 1071459
},
new[]
{
/*PigmentType.Silver,*/ 0x3E9, 1071451
},
new[]
{
/*PigmentType.NobleGold,*/ 0x227, 1071457
},
new[]
{
/*PigmentType.LightGreen,*/ 0x1C8, 1071454
},
new[]
{
/*PigmentType.PaleBlue,*/ 0x24F, 1071456
},
new[]
{
/*PigmentType.FreshPlum,*/ 0x145, 1071450
},
new[]
{
/*PigmentType.DeepBrown,*/ 0x3F0, 1071452
},
new[]
{
/*PigmentType.BurntBrown,*/ 0x41A, 1071453
}
};
[Constructible]
public LesserPigmentsOfTokuno() : this((LesserPigmentType)Utility.Random(0, 11))
{
}
[Constructible]
public LesserPigmentsOfTokuno(LesserPigmentType type) : base(1) => Type = type;
[SerializableField(0, fieldChanged: nameof(OnTypeChanged))]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private LesserPigmentType _type;
private void OnTypeChanged(LesserPigmentType oldValue, LesserPigmentType newValue)
{
var v = (int)_type;
if (v >= 0 && v < _table.Length)
{
Hue = _table[v][0];
Label = _table[v][1];
}
else
{
Hue = 0;
Label = -1;
}
}
public static int[] GetInfo(LesserPigmentType type)
{
var v = (int)type;
if (v < 0 || v >= _table.Length)
{
v = 0;
}
return _table[v];
}
}
[SerializationGenerator(0, false)]
public partial class MetalPigmentsOfTokuno : BasePigmentsOfTokuno
{
[Constructible]
public MetalPigmentsOfTokuno() : base(1)
{
RandomHue();
Label = -1;
}
public void RandomHue()
{
var a = Utility.Random(0, 30);
if (a != 0)
{
Hue = a + 0x960;
}
else
{
Hue = 0;
}
}
}