ModernUO/Projects/UOContent/Mobiles/Special/LordOaks.cs
Kamron Batman 4e57ec2373
fix: monster ability queries no longer have side effects (#2716)
## Problem
`GetMonsterAbilities()` answers three questions through one virtual: which abilities a creature has (`GetAbility`, `AOS.cs` reflect/barrier, bard fire-breath difficulty), which abilities are enabled right now, and where cooldown state must be cleaned up (`InvalidateNextAbilityTriggers` on death and delete). Every caller assumes it is a pure, stable list. About 70 creatures return a static array; only LordOaks computed it:

```
Mobile.Delete()
 → BaseCreature.OnDelete() → CreatureDeletedEvent
 → MonsterAbility.InvalidateNextAbilityTriggers()
 → LordOaks.GetMonsterAbilities() → CheckQueen() → new Silvani().MoveToWorld(...)
```

- Deleting a Lord Oaks nobody had fought (champion reset, `DeleteCreatures`, GM delete) spawned an orphaned Silvani where he stood.
- The spell damage scalar (`AlterDamageScalarFrom`) spawned her too.
- With the queen dead his list was empty, so cleanup skipped his cooldown entries. The static `Dictionary<BaseCreature, long>` on the ability singleton kept a reference to the deleted creature. `MonsterAbilityGroup` children's entries were never cleaned either.
- Neira threw unholy bones from `AlterDamageScalarFrom`, so any caller asking for a damage scalar (a preview gump, for example) could fire the effect.

## Changes
- **Per-creature cooldowns:** a lazy `Dictionary<MonsterAbility, long>` on `BaseCreature` (`IsAbilityOnCooldown`, `SetAbilityCooldown`, `ClearAbilityCooldowns`). The static dictionaries and the query-driven cleanup are gone, and death still resets cooldowns. Tick comparisons are wraparound-safe.
- **Pure contract:** `GetMonsterAbilities()` is documented as pure. The new `virtual bool CanUseAbility(MonsterAbility)` gates abilities that only work some of the time. Every `TriggerAbility*` loop and `GetAbility` check it.
- **LordOaks:** always lists his abilities; `CanUseAbility` and the 10% spell shield read "queen alive". The queen spawns when he is first aggressed or first given a combatant, never on the internal map. Aggression lands before the damage it causes, so the first spell is still shielded, as before.
- **Neira:** the unholy bone throw moves to `OnDamagedBySpell`.

A follow-up PR makes minions such as the queen, pixies and Barracoon's rats belong to their champion spawn, so a spawn reset cleans them up.

## Testing
- `LordOaksTests` covers three cases:
  - querying or deleting an unengaged Lord Oaks spawns nothing;
  - aggression spawns the queen exactly once, and the shield and abilities follow her life;
  - an Oaks on the internal map never spawns her.
- UOContent.Tests: 1234 passed, 2 skipped.
- A local constructor sweep (every Mobile built and deleted repeatedly) no longer reports LordOaks.
2026-10-18 17:41:27 -07:00

167 lines
4.6 KiB
C#

using System;
using ModernUO.Serialization;
using Server.Engines.CannedEvil;
using Server.Items;
namespace Server.Mobiles;
[SerializationGenerator(0, false)]
public partial class LordOaks : BaseChampion
{
[SerializableField(0)]
private Silvani _queen;
[SerializableField(1)]
private bool _spawnedQueen;
[Constructible]
public LordOaks() : base(AIType.AI_Mage, FightMode.Evil)
{
Body = 175;
SetStr(403, 850);
SetDex(101, 150);
SetInt(503, 800);
SetHits(3000);
SetStam(202, 400);
SetDamage(21, 33);
SetDamageType(ResistanceType.Physical, 75);
SetDamageType(ResistanceType.Fire, 25);
SetResistance(ResistanceType.Physical, 85, 90);
SetResistance(ResistanceType.Fire, 60, 70);
SetResistance(ResistanceType.Cold, 60, 70);
SetResistance(ResistanceType.Poison, 80, 90);
SetResistance(ResistanceType.Energy, 80, 90);
SetSkill(SkillName.Anatomy, 75.1, 100.0);
SetSkill(SkillName.EvalInt, 120.1, 130.0);
SetSkill(SkillName.Magery, 120.0);
SetSkill(SkillName.Meditation, 120.1, 130.0);
SetSkill(SkillName.MagicResist, 100.5, 150.0);
SetSkill(SkillName.Tactics, 100.0);
SetSkill(SkillName.Wrestling, 100.0);
Fame = 22500;
Karma = 22500;
VirtualArmor = 100;
}
public override ChampionSkullType SkullType => ChampionSkullType.Enlightenment;
public override Type[] UniqueList => new[] { typeof(OrcChieftainHelm) };
public override Type[] SharedList => new[]
{
typeof(RoyalGuardSurvivalKnife),
typeof(DjinnisRing),
typeof(LieutenantOfTheBritannianRoyalGuard),
typeof(SamaritanRobe),
typeof(DetectiveBoots),
typeof(TheMostKnowledgePerson)
};
public override Type[] DecorativeList => new[]
{
typeof(WaterTile),
typeof(WindSpirit),
typeof(Pier),
typeof(DirtPatch)
};
public override MonsterStatuetteType[] StatueTypes => Array.Empty<MonsterStatuetteType>();
public override string DefaultName => "Lord Oaks";
public override bool AutoDispel => true;
public override bool CanFly => true;
public override bool BardImmune => !Core.SE;
public override bool Unprovokable => Core.SE;
public override bool Uncalmable => Core.SE;
public override OppositionGroup OppositionGroup => OppositionGroup.FeyAndUndead;
public override Poison PoisonImmune => Poison.Deadly;
private static MonsterAbility[] _abilities = { MonsterAbilities.SummonPixiesCounter };
public override MonsterAbility[] GetMonsterAbilities() => _abilities;
public override bool CanUseAbility(MonsterAbility ability) => IsQueenAlive;
private bool IsQueenAlive => _queen?.Deleted == false;
public override void GenerateLoot()
{
AddLoot(LootPack.UltraRich, 5);
}
public override int GetAngerSound() => 0x2F8;
public override int GetIdleSound() => 0x2F8;
public override int GetAttackSound() => Utility.Random(0x2F5, 2);
public override int GetHurtSound() => 0x2F9;
public override int GetDeathSound() => 0x2F7;
// Aggression lands before the damage it causes, so the queen is up before the first hit is scaled.
public override void AggressiveAction(Mobile aggressor, bool criminal)
{
base.AggressiveAction(aggressor, criminal);
SpawnQueen();
}
public override void OnCombatantChange()
{
base.OnCombatantChange();
if (Combatant != null)
{
SpawnQueen();
}
}
private void SpawnQueen()
{
if (_spawnedQueen || Deleted || Map == null || Map == Map.Internal)
{
return;
}
Say(1042153); // Come forth my queen!
Queen = new Silvani { Team = Team };
Queen.MoveToWorld(Location, Map);
SpawnedQueen = true;
}
public override void AlterDamageScalarFrom(Mobile caster, ref double scalar)
{
if (IsQueenAlive)
{
scalar *= 0.1;
}
}
public override void OnGaveMeleeAttack(Mobile defender, int damage)
{
base.OnGaveMeleeAttack(defender, damage);
defender.Damage(Utility.Random(20, 10), this);
defender.Stam -= Utility.Random(20, 10);
defender.Mana -= Utility.Random(20, 10);
}
public override void OnGotMeleeAttack(Mobile attacker, int damage)
{
base.OnGotMeleeAttack(attacker, damage);
attacker.Damage(Utility.Random(20, 10), this);
attacker.Stam -= Utility.Random(20, 10);
attacker.Mana -= Utility.Random(20, 10);
}
}