The pure SerializationGenerator conversion of `BaseCreature`, split out of #2592 so it can serve as the reference for converting every other large hand-written class in the Delta Saves project (#7, phase 3). Two behaviour changes from #2592 are deliberately not here and follow in their own PRs on top of this one: `SpeedClass`, and the collapse of `ControlMaster`/`SummonMaster` into one reference (a creature can lose or keep either independently: Blade Spirits and Energy Vortexes are summoned but never controlled, EnragedCreature and talisman summons keep a summon master with neither flag set). ## What this is - `BaseCreature` becomes `[SerializationGenerator(23, false)]` with a `[SerializableField]` per serialized slot and `[SaveFlag]` elision on nearly every field, so a stock creature serializes to its version plus flags. Field orders run 0..53 with no gaps (54 fields). - The hand-written reader stays as `private void Deserialize(IGenericReader reader, int version)` for every pre-codegen version (0..22); post-codegen bumps use `MigrateFrom` from here on. `[AfterDeserialization]` carries the post-load fixups main did after reading (stat timers, AI type, followers, reacquire seeding). - `ControlMaster` and `SummonMaster` stay two independent fields with main's semantics, each elided when null. - `DamageMin`/`DamageMax`/`ActiveSpeed`/`PassiveSpeed` are no longer virtual (nothing in the tree overrode them); comments swept to the constraints that matter. - Direct writes to serialized backing fields outside the generated setters (`SetDamage`, `SetResistance`, the move-speed helpers, the loot flag, feed loyalty, the delete timer) call `this.MarkDirty()`, matching the #2609 standard, so the class is ready for delta saves once `Mobile` is audited. - Schema `Server.Mobiles.BaseCreature.v23.json` regenerated by the tool (a second run produces no diff). ## Deferred to follow-up PRs SpeedClass: the serialized `_speedClass` field, `DefaultSpeedClass` replacing the type constant, `ApplySpeedClass`/`OnSpeedClassChange`, "None means custom", the four-speeds-as-one-block elision, `NPCSpeeds.FindEntry(SpeedLevel)`, the constructor fallback to Medium, and their tests. Master references: serializing one `Master` with a `Controlled`/`Summoned` fan-out and the `SetControlMaster` lockstep. ## Tests UOContent.Tests 776 / Server.Tests 855 green. `BaseCreatureSerializationTests` covers: a default creature elides to version + flags; a populated creature round-trips with exact byte consumption; back-to-back saves are byte-identical; an uncontrolled summon keeps its SummonMaster; byte-authentic v22 legacy streams (replicas of main's `Serialize`) load through the legacy reader for a wild tamable, a controlled pet, a controlled summon with an anchored `SummonEnd`, and a summon-master-only creature (the EnragedCreature shape); a running delete timer round-trips through `[DeserializeTimer]`; `Friends`, `CurrentWayPoint` and `HomeMap` round-trip; a `BaseVendor` stub round-trips the generated BaseVendor v2 → generated BaseCreature v23 chain. ## Behaviour notes for reviewers - `ActiveMoveSpeed`/`PassiveMoveSpeed` getters return the raw override (0 = inherit); `CurrentMoveSpeed` is the resolved pace. - Speeds elided as table defaults re-snap to the current `npc-speeds.json` on load, so table edits reach unmodified spawns on restart. - `GetSpeeds` no longer throws on the save/load path when the table has no entry for the type: saves elide against the creature's own values and loads keep the stream. Construction still throws (`InvalidOperationException`, was `KeyNotFoundException`). An elided load with no table entry would otherwise resume at speed 0, so `[AfterDeserialization]` logs once and paces it at Medium. - `virtual` removed from `ActiveSpeed`, `PassiveSpeed`, `DamageMin`, `DamageMax` (no overrides in the tree; forks may have some). - `ControlMaster`, `SummonMaster`, `ControlOrder`, `Tamable`, `IsParagon` are `[SerializableProperty]` over hand-written setters because follower bookkeeping must run before the assignment, which a `fieldChanged` hook cannot express; the wire format is identical. ## Prerequisites for cherry-picking #2609 (BaseVendor is already generated on top of BaseCreature) and SerializationGenerator 4.1.0.
207 lines
6.9 KiB
C#
207 lines
6.9 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;
|
|
|
|
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.Controlled && bc.ControlMaster?.Deleted == false && bc.ControlMaster.Alive)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|