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.
This commit is contained in:
parent
8cced36794
commit
4e57ec2373
5 changed files with 182 additions and 61 deletions
|
|
@ -86,7 +86,11 @@ public partial class LordOaks : BaseChampion
|
|||
public override Poison PoisonImmune => Poison.Deadly;
|
||||
|
||||
private static MonsterAbility[] _abilities = { MonsterAbilities.SummonPixiesCounter };
|
||||
public override MonsterAbility[] GetMonsterAbilities() => CheckQueen() ? _abilities : MonsterAbilities.Empty;
|
||||
public override MonsterAbility[] GetMonsterAbilities() => _abilities;
|
||||
|
||||
public override bool CanUseAbility(MonsterAbility ability) => IsQueenAlive;
|
||||
|
||||
private bool IsQueenAlive => _queen?.Deleted == false;
|
||||
|
||||
public override void GenerateLoot()
|
||||
{
|
||||
|
|
@ -103,36 +107,41 @@ public partial class LordOaks : BaseChampion
|
|||
|
||||
public override int GetDeathSound() => 0x2F7;
|
||||
|
||||
public bool CheckQueen()
|
||||
// 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)
|
||||
{
|
||||
if (Map == null)
|
||||
base.AggressiveAction(aggressor, criminal);
|
||||
SpawnQueen();
|
||||
}
|
||||
|
||||
public override void OnCombatantChange()
|
||||
{
|
||||
base.OnCombatantChange();
|
||||
|
||||
if (Combatant != null)
|
||||
{
|
||||
return false;
|
||||
SpawnQueen();
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnQueen()
|
||||
{
|
||||
if (_spawnedQueen || Deleted || Map == null || Map == Map.Internal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_spawnedQueen)
|
||||
{
|
||||
Say(1042153); // Come forth my queen!
|
||||
Say(1042153); // Come forth my queen!
|
||||
|
||||
_queen = new Silvani { Team = Team };
|
||||
_queen.MoveToWorld(Location, Map);
|
||||
Queen = new Silvani { Team = Team };
|
||||
Queen.MoveToWorld(Location, Map);
|
||||
|
||||
_spawnedQueen = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_queen?.Deleted != false)
|
||||
{
|
||||
_queen = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
SpawnedQueen = true;
|
||||
}
|
||||
|
||||
public override void AlterDamageScalarFrom(Mobile caster, ref double scalar)
|
||||
{
|
||||
if (CheckQueen())
|
||||
if (IsQueenAlive)
|
||||
{
|
||||
scalar *= 0.1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,13 +163,13 @@ public partial class Neira : BaseChampion
|
|||
}
|
||||
}
|
||||
|
||||
public override void AlterDamageScalarFrom(Mobile caster, ref double scalar)
|
||||
public override void OnDamagedBySpell(Mobile from, int damage)
|
||||
{
|
||||
base.AlterDamageScalarFrom(caster, ref scalar);
|
||||
base.OnDamagedBySpell(from, damage);
|
||||
|
||||
if (Utility.RandomDouble() < 0.1) // 10% chance to throw an unholy bone
|
||||
{
|
||||
AddUnholyBone(caster, 1.0);
|
||||
AddUnholyBone(from, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue