Fixes #2462 ## Summary Removes the per-object `VirtualHairInfo` heap wrapper for mobile/corpse hair. Hair is now stored **inline** on `Mobile` and `Corpse` as `int _hairItemId` / `int _hairHue` plus a lazily-allocated, **non-serialized** ephemeral `Serial _hairSerial` (in the high virtual-serial range) — and likewise for facial hair. The `VirtualHairInfo` class is deleted, with a **lossless** save migration. This delivers three things: 1. **Fixes a hair-removal bug.** `Delta(MobileDelta.Hair)` is deferred (it enqueues; `ProcessDeltaQueue` runs later in the tick). The old `HairItemID = 0` setter nulled `_hair` *immediately*, so by the time `ProcessDelta` built the remove packet the equipped virtual serial was already gone — the old `??=` code then re-materialized a **fresh** serial (≠ the equipped one), so clients never removed the right entity, and it left a phantom ItemId-0 object behind. The serial now lives on the entity and **persists across removal**, so remove packets carry the correct serial. 2. **Lightens the entity.** No heap hair object; bald mobiles allocate nothing (the serial is minted lazily only when hair is present). This was the original reason `HairItemID`/`HairHue` exist. 3. **Removes `VirtualHairInfo` entirely**, keeping the high-range virtual serial behavior. ## How - **Mobile** (manual serialization): inline `_hairItemId/_hairHue/_hairSerial` (+facial); lazy `HairSerial`/`FacialHairSerial`; `ProcessDelta` reads those. Serialization **v36 → v37** — the v30-v37 deserialize is unified, reading the legacy per-hair `VirtualHairInfo` version int only when `version < 37`. Setting item id to 0 clears the hue (matching the old object-nulling) while retaining the serial. - **Corpse** (codegen serialization): decomposed to `[SerializableField] int _hairItemId/_hairHue` (+facial) + ephemeral serial; **v16 → v17** with `MigrateFrom(V16Content)`. - **Lossless migration:** the loader validates exact byte length, and the old corpse hair is a presence-bool-gated block, so a tiny **migration-only** `LegacyHairInfo` reader (no runtime role) consumes the legacy `[bool][int ver][int itemId][int hue]` bytes. Frozen `Corpse.v14/v15/v16.json` are retyped to it; `v17.json` describes the new int fields. - All consumers updated to discrete accessors: `OutgoingMobilePackets`, `CorpsePackets`, corpse subclasses (`MilitiaFighterCorpse`, `SchmendrickApprenticeCorpse`), and the packet test mirrors. - `VirtualHair.cs` renamed to `OutgoingVirtualHairPackets.cs` (the only type left in it after `VirtualHairInfo` was removed). ## Test Plan - [x] Full solution build: **0 warnings, 0 errors** (`TreatWarningsAsErrors`). - [x] `Server.Tests`: **708 passed** (incl. new `RemoveHairUsesEquippedSerial` / `RemoveFacialHairUsesEquippedSerial` proving the serial survives removal + hue clears). - [x] `UOContent.Tests` corpse/hair: **6 passed** (incl. `CorpseHairMigrationTests` asserting the legacy hair bytes are consumed exactly — the loader's length invariant). - [x] Generated migration code inspected: V14/V15/V16 readers consume the legacy block byte-for-byte; serial never written to disk. ## Upgrade notes - Old Mobile (v30–v36) and Corpse (v13–v16) saves load losslessly. - Minor cosmetic-only change: `SchmendrickApprenticeCorpse` hair/facial-hair RNG draws shift order within each pair (same draw count); irrelevant for a quest NPC corpse.
137 lines
3.5 KiB
C#
137 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using ModernUO.Serialization;
|
|
using Server.Items;
|
|
using Server.Misc;
|
|
using Server.Mobiles;
|
|
using Server.Network;
|
|
|
|
namespace Server.Engines.Quests.Haven;
|
|
|
|
[SerializationGenerator(0, false)]
|
|
public partial class MilitiaFighter : BaseCreature
|
|
{
|
|
[Constructible]
|
|
public MilitiaFighter() : base(AIType.AI_Melee)
|
|
{
|
|
InitStats(40, 30, 5);
|
|
Title = "the Militia Fighter";
|
|
|
|
SpeechHue = Utility.RandomDyedHue();
|
|
|
|
Hue = Race.Human.RandomSkinHue();
|
|
|
|
Female = false;
|
|
Body = 0x190;
|
|
Name = NameList.RandomName("male");
|
|
|
|
Utility.AssignRandomHair(this);
|
|
Utility.AssignRandomFacialHair(this, HairHue);
|
|
|
|
AddItem(new ThighBoots(0x1BB));
|
|
AddItem(new LeatherChest());
|
|
AddItem(new LeatherArms());
|
|
AddItem(new LeatherLegs());
|
|
AddItem(new LeatherCap());
|
|
AddItem(new LeatherGloves());
|
|
AddItem(new LeatherGorget());
|
|
|
|
var weapon = Utility.Random(6) switch
|
|
{
|
|
0 => (Item)new Broadsword(),
|
|
1 => new Cutlass(),
|
|
2 => new Katana(),
|
|
3 => new Longsword(),
|
|
4 => new Scimitar(),
|
|
_ => new VikingSword()
|
|
};
|
|
|
|
weapon.Movable = false;
|
|
AddItem(weapon);
|
|
|
|
Item shield = new BronzeShield
|
|
{
|
|
Movable = false
|
|
};
|
|
|
|
AddItem(shield);
|
|
|
|
SetSkill(SkillName.Swords, 20.0);
|
|
}
|
|
|
|
public override bool ClickTitle => false;
|
|
|
|
public override bool IsEnemy(Mobile m)
|
|
{
|
|
while (!m.Player && m is not BaseVendor)
|
|
{
|
|
if (m is BaseCreature bc)
|
|
{
|
|
var master = bc.GetMaster();
|
|
if (master != null)
|
|
{
|
|
m = master;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return m.Karma < 0;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[SerializationGenerator(0, false)]
|
|
public partial class MilitiaFighterCorpse : Corpse
|
|
{
|
|
public MilitiaFighterCorpse(
|
|
Mobile owner, int hairItemId, int hairHue, int facialHairItemId, int facialHairHue, List<Item> equipItems
|
|
) : base(
|
|
owner,
|
|
hairItemId,
|
|
hairHue,
|
|
facialHairItemId,
|
|
facialHairHue,
|
|
equipItems
|
|
)
|
|
{
|
|
}
|
|
|
|
public override void AddNameProperty(IPropertyList list)
|
|
{
|
|
if (ItemID == 0x2006) // Corpse form
|
|
{
|
|
list.Add("a human corpse");
|
|
list.Add(1049318, Name); // the remains of ~1_NAME~ the militia fighter
|
|
}
|
|
else
|
|
{
|
|
list.Add(1049319); // the remains of a militia fighter
|
|
}
|
|
}
|
|
|
|
public override void OnSingleClick(Mobile from)
|
|
{
|
|
var hue = Notoriety.GetHue(NotorietyHandlers.CorpseNotoriety(from, this));
|
|
|
|
if (ItemID == 0x2006) // Corpse form
|
|
{
|
|
// the remains of ~1_NAME~ the militia fighter
|
|
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1049318, "", Name);
|
|
}
|
|
else
|
|
{
|
|
// the remains of a militia fighter
|
|
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1049319);
|
|
}
|
|
}
|
|
|
|
public override void Open(Mobile from, bool checkSelfLoot)
|
|
{
|
|
if (from.InRange(GetWorldLocation(), 2))
|
|
{
|
|
// Thinking about his sacrifice, you can't bring yourself to loot the body of this militia fighter.
|
|
from.SendLocalizedMessage(1049661, "", 0x22);
|
|
}
|
|
}
|
|
}
|