## Summary `Mobile.DamageEntries` was a `List<DamageEntry>` allocated for every mobile, including the ~99% that never take damage. It is now an inline `ValueLinkList<DamageEntry>` (24 bytes in the `Mobile` object, no separate allocation) ordered least recent → most recent. - `DamageEntry` implements `IValueLinkListNode<DamageEntry>`. - `RegisterDamage` moves the entry to the tail in O(1) instead of `Remove` + `Add` on a list. - Expired entries are always a head prefix, so pruning walks from the head and stops at the first live entry. The `DamageEntries` getter prunes on access. - `DamageEntries` is exposed as `ref readonly`; enumerate with `foreach` or `.ByDescending()`. Mutation goes through `RegisterDamage` / `ClearDamageEntries`. - `BaseCreature.GetLootingRights` and `BaseCreature.ComputeBonusDamage` take `in ValueLinkList<DamageEntry>`; all callers compile unchanged. Files that `foreach` over `DamageEntries` need `using Server.Collections;` for the enumerator extension. - RunUO migration docs (`dev-docs/runuo-migration-docs/09`, `11`) and the `migrate-items-mobiles` skill document the change. Saves one object and 16 bytes per mobile (~8 MB and 500k gen2 objects on a 500k world). Second of three PRs from the lazy per-mobile collections design (first: #2604). Branched from `main`; the two diffs touch disjoint hunks of `Mobile.cs`. ## Breaking change - `Mobile.DamageEntries` is no longer a `List<DamageEntry>`. Indexing, `.Clear()`, `.Add()`, `.Remove()` no longer compile; use `foreach`, `.ByDescending()`, `.Count`, `ClearDamageEntries()`, and `RegisterDamage`. Calling a `ValueLinkList` mutator on the `ref readonly` property compiles but operates on a copy while still unlinking the real nodes; do not. - `BaseCreature.GetLootingRights` and `BaseCreature.ComputeBonusDamage` signatures changed to `(in ValueLinkList<DamageEntry>, …)`. Save format is untouched: damage entries are not serialized. ## Behavior Recency order, `allowSelf`, tie-breaking in `FindMostTotal`/`FindLeastTotal` (most recent wins), `Responsible` accounting, and loot-rights ordering are unchanged and covered by the new `DamageEntryTests` and `LootingRightsTests`. ## Testing - `dotnet build -c Release` clean. - New `DamageEntryTests` and `LootingRightsTests` plus full `Server.Tests` and `UOContent.Tests`.
3.1 KiB
3.1 KiB
| name | description |
|---|---|
| migrate-items-mobiles | Trigger: when converting RunUO Item, Mobile, or BaseCreature subclasses to ModernUO. Most common migration task. Covers: complete item/creature conversion combining serialization, timers, properties, naming. |
RunUO -> ModernUO Item/Mobile/Creature Migration
When This Activates
- Converting any
Itemsubclass from RunUO - Converting any
Mobile/BaseCreaturesubclass - This is the most common migration task -- combines all other systems
Item Conversion Checklist
- Foundation: file-scoped namespace,
using ModernUO.Serialization; - Class: add
[SerializationGenerator(N, false)](N = old version + 1,falseif oldDeserializeusedReadInt()), addpartial - Fields:
m_X->[SerializableField(N)] _xwith[SerializedCommandProperty] - Add
[InvalidateProperties]where RunUO setter calledInvalidateProperties() - Delete: Serial constructor, Serialize, Deserialize
[Constructable]->[Constructible]Name = "text"->public override string DefaultName => "text";- Timers: nested class ->
Timer.StartTimer()+TimerExecutionToken+[AfterDeserialization]+OnAfterDelete - Properties:
GetProperties(ObjectPropertyList)->GetProperties(IPropertyList), apply string hole rule - Context menus:
List<ContextMenuEntry>->ref PooledRefList<ContextMenuEntry>
Creature-Specific Changes
[CorpseName("...")]attribute ->public override string CorpseName => "...";BaseCreature(AI, Fight, 10, 1, 0.2, 0.4)->BaseCreature(AI, Fight)(extra params default)Name = "text"->public override string DefaultName => "text";- Expression-bodied overrides:
public override int Meat { get { return 1; } }->public override int Meat => 1; - AI movement calls lose the
runflag:MoveTo(m, true, range)->MoveTo(m, range)(alsoWalkMobileRange,ApproachTarget,MoveToPoint,PathFollower.Follow); the Running bit is derived from step pace ->dev-docs/runuo-migration-docs/09-items-mobiles-creatures.md§ AI Movement AcquireOnApproach(bool) ->AcquireOnApproachDelay(TimeSpan;Zero= old instant behavior) -> same doc § Target AcquisitionDamageEntriesis an inlineref readonly ValueLinkList<DamageEntry>, not aList: indexer/Add/Remove/Clear->foreach/.ByDescending()(needsusing Server.Collections;) andClearDamageEntries();GetLootingRightstakes it byin-> same doc § Damage Entries
Anti-Patterns
- Using
_field--instead ofProperty--(bypasses MarkDirty tracking) - Forgetting
[AfterDeserialization]for timer restoration - Forgetting
OnAfterDelete()for timer cancellation
See Also
dev-docs/runuo-migration-docs/09-items-mobiles-creatures.md-- detailed migration with before/after examplesdev-docs/content-patterns.md-- ModernUO content templatesdev-docs/claude-skills/modernuo-content-patterns.md-- ModernUO content skilldev-docs/claude-skills/modernuo-serialization.md-- serialization patternsdev-docs/claude-skills/modernuo-timers.md-- timer patterns