ModernUO/Projects/UOContent/Mobiles/Monsters/LBR/Meers/MeerMage.cs
Kamron Batman 843a29e7dc
refactor: master views over BaseCreature's one master reference (#2674)
## 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
2026-09-24 22:45:24 -07:00

210 lines
7.1 KiB
C#

using ModernUO.Serialization;
using System;
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using Server.Items;
namespace Server.Mobiles
{
[SerializationGenerator(0, false)]
public partial class MeerMage : BaseCreature
{
private static readonly Dictionary<Mobile, TimerExecutionToken> m_Table = new();
private DateTime m_NextAbilityTime;
[Constructible]
public MeerMage() : base(AIType.AI_Mage, FightMode.Evil)
{
Body = 770;
SetStr(171, 200);
SetDex(126, 145);
SetInt(276, 305);
SetHits(103, 120);
SetDamage(24, 26);
SetDamageType(ResistanceType.Physical, 100);
SetResistance(ResistanceType.Physical, 45, 55);
SetResistance(ResistanceType.Fire, 15, 25);
SetResistance(ResistanceType.Cold, 50);
SetResistance(ResistanceType.Poison, 25, 35);
SetResistance(ResistanceType.Energy, 25, 35);
SetSkill(SkillName.EvalInt, 100.0);
SetSkill(SkillName.Magery, 70.1, 80.0);
SetSkill(SkillName.Meditation, 85.1, 95.0);
SetSkill(SkillName.MagicResist, 80.1, 100.0);
SetSkill(SkillName.Tactics, 70.1, 90.0);
SetSkill(SkillName.Wrestling, 60.1, 80.0);
Fame = 8000;
Karma = 8000;
VirtualArmor = 16;
m_NextAbilityTime = Core.Now + TimeSpan.FromSeconds(Utility.RandomMinMax(2, 5));
}
public override string CorpseName => "a meer's corpse";
public override string DefaultName => "a meer mage";
public override bool AutoDispel => true;
public override Poison PoisonImmune => Poison.Lethal;
public override bool CanRummageCorpses => true;
public override int TreasureMapLevel => 3;
public override bool InitialInnocent => true;
// FightMode.Evil would otherwise target our own enraged creatures for their negative karma.
public override bool IsEnemy(Mobile m) => (m as BaseEnraged)?.Master != this && base.IsEnemy(m);
public override void GenerateLoot()
{
AddLoot(LootPack.FilthyRich);
AddLoot(LootPack.MedScrolls, 2);
// TODO: Daemon bone ...
}
public override int GetHurtSound() => 0x14D;
public override int GetDeathSound() => 0x314;
public override int GetAttackSound() => 0x75;
public override void OnThink()
{
if (Core.Now >= m_NextAbilityTime)
{
var combatant = Combatant;
if (combatant != null && combatant.Map == Map && combatant.InRange(this, 12) && IsEnemy(combatant) &&
!UnderEffect(combatant))
{
m_NextAbilityTime = Core.Now + TimeSpan.FromSeconds(Utility.RandomMinMax(20, 30));
if (combatant is BaseCreature bc)
{
if (bc.ControlMaster is { Deleted: false, Alive: true })
{
if (bc.ControlMaster.Map == Map && bc.ControlMaster.InRange(this, 12) &&
!UnderEffect(bc.ControlMaster))
{
Combatant = combatant = bc.ControlMaster;
}
}
}
if (Utility.RandomDouble() < .1)
{
int[][] coord =
{
new[] { -4, -6 }, new[] { 4, -6 }, new[] { 0, -8 }, new[] { -5, 5 }, new[] { 5, 5 }
};
for (var i = 0; i < 5; i++)
{
var x = combatant.X + coord[i][0];
var y = combatant.Y + coord[i][1];
var loc = new Point3D(x, y, combatant.Map.GetAverageZ(x, y));
if (!combatant.Map.CanSpawnMobile(loc))
{
continue;
}
var rabid = i switch
{
0 => (BaseCreature)new EnragedRabbit(this),
1 => new EnragedHind(this),
2 => new EnragedHart(this),
3 => new EnragedBlackBear(this),
_ => new EnragedEagle(this)
};
rabid.FocusMob = combatant;
rabid.MoveToWorld(loc, combatant.Map);
}
// Creatures of the forest, I call to thee! Aid me in the fight against all that is evil!
Say(1071932);
}
else if (combatant.Player)
{
// I call a plague of insects to sting your flesh!
Say(1071931);
var count = 0;
Timer.StartTimer(
TimeSpan.FromSeconds(0.5),
TimeSpan.FromSeconds(7.0),
() => DoEffect(combatant, count++),
out var timerToken
);
m_Table[combatant] = timerToken;
}
}
}
base.OnThink();
}
public static bool UnderEffect(Mobile m) => m_Table.ContainsKey(m);
[OnEvent(nameof(PlayerMobile.PlayerDeathEvent))]
[OnEvent(nameof(CreatureEvents.CreatureDeathEvent))]
public static void StopEffect(Mobile m, bool message = false)
{
if (m_Table.Remove(m, out var timer))
{
if (message)
{
// * The open flame begins to scatter the swarm of insects! *
m.PublicOverheadMessage(MessageType.Emote, m.SpeechHue, 1071925);
}
timer.Cancel();
}
}
private void DoEffect(Mobile m, int count)
{
if (!m.Alive)
{
StopEffect(m);
return;
}
if (m.FindItemOnLayer<Torch>(Layer.TwoHanded)?.Burning == true)
{
StopEffect(m, true);
return;
}
if (count % 4 == 0)
{
// * The swarm of insects bites and stings your flesh! *
m.LocalOverheadMessage(MessageType.Emote, m.SpeechHue, 1071905);
// * ~1_VAL~ is stung by a swarm of insects *
m.NonlocalOverheadMessage(MessageType.Emote, m.SpeechHue, 1071924);
}
m.FixedParticles(0x91C, 10, 180, 9539, EffectLayer.Waist);
m.PlaySound(0x00E);
m.PlaySound(0x1BC);
AOS.Damage(m, this, Utility.RandomMinMax(30, 40) - (Core.AOS ? 0 : 10), 100, 0, 0, 0, 0);
if (!m.Alive)
{
StopEffect(m);
}
}
}
}