## 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.
228 lines
5.8 KiB
C#
228 lines
5.8 KiB
C#
using System;
|
|
using ModernUO.Serialization;
|
|
using Server.Engines.CannedEvil;
|
|
using Server.Items;
|
|
|
|
namespace Server.Mobiles;
|
|
|
|
[SerializationGenerator(1, false)]
|
|
public partial class Neira : BaseChampion
|
|
{
|
|
private const double SpeedBoostScalar = 1.2;
|
|
|
|
private bool _speedBoost;
|
|
|
|
[Constructible]
|
|
public Neira() : base(AIType.AI_Mage)
|
|
{
|
|
Title = "the necromancer";
|
|
Body = 401;
|
|
Hue = 0x83EC;
|
|
|
|
SetStr(305, 425);
|
|
SetDex(72, 150);
|
|
SetInt(505, 750);
|
|
|
|
SetHits(4800);
|
|
SetStam(102, 300);
|
|
|
|
SetDamage(25, 35);
|
|
|
|
SetDamageType(ResistanceType.Physical, 100);
|
|
|
|
SetResistance(ResistanceType.Physical, 25, 30);
|
|
SetResistance(ResistanceType.Fire, 35, 45);
|
|
SetResistance(ResistanceType.Cold, 50, 60);
|
|
SetResistance(ResistanceType.Poison, 30, 40);
|
|
SetResistance(ResistanceType.Energy, 20, 30);
|
|
|
|
SetSkill(SkillName.EvalInt, 120.0);
|
|
SetSkill(SkillName.Magery, 120.0);
|
|
SetSkill(SkillName.Meditation, 120.0);
|
|
SetSkill(SkillName.MagicResist, 150.0);
|
|
SetSkill(SkillName.Tactics, 97.6, 100.0);
|
|
SetSkill(SkillName.Wrestling, 97.6, 100.0);
|
|
|
|
Fame = 22500;
|
|
Karma = -22500;
|
|
|
|
VirtualArmor = 30;
|
|
Female = true;
|
|
|
|
Item shroud = new HoodedShroudOfShadows();
|
|
shroud.Movable = false;
|
|
|
|
AddItem(shroud);
|
|
|
|
var weapon = new Scimitar
|
|
{
|
|
Skill = SkillName.Wrestling,
|
|
Hue = 38,
|
|
Movable = false
|
|
};
|
|
|
|
AddItem(weapon);
|
|
|
|
// new SkeletalMount().Rider = this;
|
|
AddItem(new VirtualMountItem(this));
|
|
}
|
|
|
|
public override ChampionSkullType SkullType => ChampionSkullType.Death;
|
|
|
|
public override Type[] UniqueList => new[] { typeof(ShroudOfDeciet) };
|
|
|
|
public override Type[] SharedList => new[]
|
|
{
|
|
typeof(ANecromancerShroud),
|
|
|
|
typeof(CaptainJohnsHat)
|
|
};
|
|
|
|
public override Type[] DecorativeList => new[] { typeof(WallBlood), typeof(TatteredAncientMummyWrapping) };
|
|
|
|
public override MonsterStatuetteType[] StatueTypes => Array.Empty<MonsterStatuetteType>();
|
|
|
|
public override string DefaultName => "Neira";
|
|
|
|
public override bool AlwaysMurderer => true;
|
|
public override bool BardImmune => !Core.SE;
|
|
public override bool Unprovokable => Core.SE;
|
|
public override bool Uncalmable => Core.SE;
|
|
public override Poison PoisonImmune => Poison.Deadly;
|
|
|
|
public override bool ShowFameTitle => false;
|
|
public override bool ClickTitle => false;
|
|
|
|
public override void GenerateLoot()
|
|
{
|
|
AddLoot(LootPack.UltraRich, 3);
|
|
AddLoot(LootPack.Meager);
|
|
}
|
|
|
|
public override bool OnBeforeDeath()
|
|
{
|
|
var mount = Mount;
|
|
|
|
if (mount != null)
|
|
{
|
|
mount.Rider = null;
|
|
}
|
|
|
|
(mount as Item)?.Delete();
|
|
|
|
return base.OnBeforeDeath();
|
|
}
|
|
|
|
public override void OnDamage(int amount, Mobile from, bool willKill)
|
|
{
|
|
CheckSpeedBoost();
|
|
base.OnDamage(amount, from, willKill);
|
|
}
|
|
|
|
private void CheckSpeedBoost()
|
|
{
|
|
if (Hits < HitsMax / 4)
|
|
{
|
|
if (!_speedBoost)
|
|
{
|
|
ActiveSpeed /= SpeedBoostScalar;
|
|
PassiveSpeed /= SpeedBoostScalar;
|
|
_speedBoost = true;
|
|
}
|
|
}
|
|
else if (_speedBoost)
|
|
{
|
|
ActiveSpeed *= SpeedBoostScalar;
|
|
PassiveSpeed *= SpeedBoostScalar;
|
|
_speedBoost = false;
|
|
}
|
|
|
|
// Assume active
|
|
CurrentSpeed = ActiveSpeed;
|
|
}
|
|
|
|
public override void OnGaveMeleeAttack(Mobile defender, int damage)
|
|
{
|
|
base.OnGaveMeleeAttack(defender, damage);
|
|
|
|
if (Utility.RandomDouble() < 0.1) // 10% chance to drop or throw an unholy bone
|
|
{
|
|
AddUnholyBone(defender, 0.25);
|
|
}
|
|
|
|
CheckSpeedBoost();
|
|
}
|
|
|
|
public override void OnGotMeleeAttack(Mobile attacker, int damage)
|
|
{
|
|
base.OnGotMeleeAttack(attacker, damage);
|
|
|
|
if (Utility.RandomDouble() < 0.1) // 10% chance to drop or throw an unholy bone
|
|
{
|
|
AddUnholyBone(attacker, 0.25);
|
|
}
|
|
}
|
|
|
|
public override void OnDamagedBySpell(Mobile from, int damage)
|
|
{
|
|
base.OnDamagedBySpell(from, damage);
|
|
|
|
if (Utility.RandomDouble() < 0.1) // 10% chance to throw an unholy bone
|
|
{
|
|
AddUnholyBone(from, 1.0);
|
|
}
|
|
}
|
|
|
|
public void AddUnholyBone(Mobile target, double chanceToThrow)
|
|
{
|
|
if (Map == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (chanceToThrow >= Utility.RandomDouble())
|
|
{
|
|
Direction = GetDirectionTo(target);
|
|
MovingEffect(target, 0xF7E, 10, 1, true, false, 0x496, 0);
|
|
new DelayTimer(this, target).Start();
|
|
}
|
|
else
|
|
{
|
|
new UnholyBone().MoveToWorld(Location, Map);
|
|
}
|
|
}
|
|
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
// We don't need to serialize this
|
|
reader.ReadBool(); // _speedBoost
|
|
}
|
|
|
|
[AfterDeserialization]
|
|
private void AfterDeserialization()
|
|
{
|
|
CheckSpeedBoost();
|
|
}
|
|
|
|
private class DelayTimer : Timer
|
|
{
|
|
private readonly Mobile m_Mobile;
|
|
private readonly Mobile m_Target;
|
|
|
|
public DelayTimer(Mobile m, Mobile target) : base(TimeSpan.FromSeconds(1.0))
|
|
{
|
|
m_Mobile = m;
|
|
m_Target = target;
|
|
}
|
|
|
|
protected override void OnTick()
|
|
{
|
|
if (m_Mobile.CanBeHarmful(m_Target))
|
|
{
|
|
m_Mobile.DoHarmful(m_Target);
|
|
AOS.Damage(m_Target, m_Mobile, Utility.RandomMinMax(10, 20), 100, 0, 0, 0, 0);
|
|
new UnholyBone().MoveToWorld(m_Target.Location, m_Target.Map);
|
|
}
|
|
}
|
|
}
|
|
}
|