## Summary After #2670, `BaseCreature` stores one master. Callers still reached it through three differently gated names plus hand-rolled combinations of the `Controlled`/`Summoned` flags. Each gate is now one named view: | Member | Definition | Meaning | |---|---|---| | `Master` | the reference; its setter does the follower bookkeeping; serialized as before | whoever the creature answers to | | `ControlMaster` | `Controlled ? Master : null` | the owner | | `SummonMaster` | `Summoned ? Master : null` | the summoner | | `GetMaster()` | `ControlMaster ?? SummonMaster` | who answers for the creature | `ControlMaster` and `SummonMaster` stay settable so custom code keeps compiling: both setters assign `Master`. There is no guard, so a write through either one can read back as null until the matching flag is set. An enraged creature is the one shape with a master and neither flag. It keeps its meer through `Master`, while `GetMaster()` stays null, so the meer never answers for it (notoriety, kill credit). Readers move onto the view they mean: - "Owner or summoner" pairs and `ControlMaster ?? SummonMaster` collapse into `GetMaster()`: pack instinct, familiars, golem, house access, mounts, pack horse, Solen friendship, spell target and guild checks, and the `[` pet command. - Checks such as `Controlled && ControlMaster == from` drop the flag the view already applies. Checks that don't reduce keep it: `Controlled && ControlMaster != from`, a possibly-null `from`, and `MageAI.CanDispel`'s `Summoned &&`. **No behavior change, save format unchanged** (the schema generator produces no diff). Edge cases for custom code and shard operators: - `SummonMaster = x` on a plain pet now replaces its owner (#2670 made that a no-op), and `ControlMaster = null` on an uncontrolled summon now clears its caster (it did nothing before). - `SpellHelper.GetGuildFor` no longer falls back to an enraged creature's meer. Meer mages have no guild. ## Docs - `dev-docs/content-patterns.md` § Masters: which view answers which question, how to set a master, and which flag checks are redundant. - `dev-docs/runuo-migration-docs/09-items-mobiles-creatures.md` § Masters: RunUO's two-field reads mapped onto the views, plus the gotcha for creatures that set `SummonMaster` without `Summoned` (the write compiles, the read now returns null; use `Master`). - The `modernuo-content-patterns` and `migrate-items-mobiles` skills point at both. ## Test plan - [x] `MasterViewsTests`: all four views across wild, pet, controlled summon, uncontrolled summon and enraged shapes; reassigning `Master` moves follower slots; `SetControlMaster(null)` keeps an uncontrolled summon's caster; deleting a summon returns the caster's slots - [x] Serialization tests updated to the new views (round-trip, legacy v22, v23 migration) - [x] UOContent.Tests (1178 passed, 2 skipped) and Server.Tests (907) green
3.8 KiB
3.8 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 AcquisitionBaseAI.OnAggressiveAction(aggressor)isbool, notvoid: the AI owns the retaliation policy (BaseCreatureno longer setsCombatantafter it); an earlyreturn;that refused a fight ->return false;, otherwisereturn true;; swap-only overrides callPreferCloserAggressor(aggressor)instead ofbase-> same doc § RetaliationDamageEntriesis an inlineref readonly ValueLinkList<DamageEntry>, not aList: indexer/Add/Remove/Clear->foreach/.ByDescending()(needsusing Server.Collections;) andClearDamageEntries();GetLootingRightstakes it byin-> same doc § Damage EntriesControlMaster/SummonMasterare views of oneMaster, gated byControlled/Summoned; assignments still compile (they setMaster).ControlMaster ?? SummonMasterand controlled-or-summoned pairs ->GetMaster(); a creature that setsSummonMasterwithoutSummoned(RunUO'sBaseEnraged) must readMaster, becauseSummonMasternow reads null -> same doc § Masters
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