ModernUO/Projects/UOContent/Mobiles/Abilities/AreaEffectMonsterAbility.cs
Kamron Batman 28c06c1cc0
fix: Changes Map.Sector.Mobiles to link list & Fixes various related crash bugs (#1553)
### Summary

Eliminates `IPooledEnumerable<T>` and `eable.Free()` from `Map` for mobiles. This drastically simplifies code that iterates in range, for example:

```cs
foreach (var m in m.GetMobilesInRange(5))
{
}
```
The code above no longer requires an eable and calling `Free()`.

- [X] Fixed several locations where an NPC that was damaged would cause a server crash.
- [X] Removed an unnecessary allocation in guard fake calls (NPCs calling guards on you)
- [X] Fixes damage precision loss in Poison Strike Spell
- [X] BogThing no longer attempts to "search" for boglings to eat when it is at full health
2023-10-29 22:42:46 -07:00

34 lines
1.1 KiB
C#

using Server.Collections;
namespace Server.Mobiles;
public abstract class AreaEffectMonsterAbility : MonsterAbility
{
public virtual int AreaRange => 3;
public override void Trigger(MonsterAbilityTrigger trigger, BaseCreature source, Mobile target)
{
using var queue = PooledRefQueue<Mobile>.Create();
foreach (var m in source.GetMobilesInRange(AreaRange))
{
if (CanEffectTarget(source, m))
{
queue.Enqueue(m);
}
}
while (queue.Count > 0)
{
DoEffectTarget(source, queue.Dequeue());
}
base.Trigger(trigger, source, target);
}
protected virtual bool CanEffectTarget(BaseCreature source, Mobile defender) =>
source != defender && defender.Alive && source.CanBeHarmful(defender)
&& (defender.Player || defender is BaseCreature bc && (bc.Team == source.Team || bc.Controlled || bc.Summoned))
&& (!Core.AOS || source.InLOS(defender));
protected abstract void DoEffectTarget(BaseCreature source, Mobile defender);
}