ModernUO/Projects/UOContent/Items/Weapons/Abilities/WhirlwindAttack.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

78 lines
2.2 KiB
C#

using System;
using Server.Collections;
using Server.Spells;
namespace Server.Items
{
/// <summary>
/// A godsend to a warrior surrounded, the Whirlwind Attack allows the fighter to strike at all nearby targets in one mighty
/// spinning swing.
/// </summary>
public class WhirlwindAttack : WeaponAbility
{
public override int BaseMana => 15;
public override void OnHit(Mobile attacker, Mobile defender, int damage)
{
if (!Validate(attacker) || !CheckMana(attacker, true))
{
return;
}
ClearCurrentAbility(attacker);
var map = attacker.Map;
if (map == null)
{
return;
}
if (attacker.Weapon is not BaseWeapon weapon)
{
return;
}
attacker.FixedEffect(0x3728, 10, 15);
attacker.PlaySound(0x2A1);
using var queue = PooledRefQueue<Mobile>.Create();
foreach (var m in attacker.GetMobilesInRange(1))
{
if (m?.Deleted == false && m != defender && m != attacker &&
m.Map == attacker.Map && m.Alive &&
SpellHelper.ValidIndirectTarget(attacker, m) &&
attacker.CanSee(m) && attacker.CanBeHarmful(m) &&
attacker.InRange(m, weapon.MaxRange) && attacker.InLOS(m))
{
queue.Enqueue(m);
}
}
if (queue.Count <= 0)
{
return;
}
var bushido = attacker.Skills.Bushido.Value;
var damageBonus = 1.0 + Math.Pow(queue.Count * bushido / 60, 2) / 100;
if (damageBonus > 2.0)
{
damageBonus = 2.0;
}
attacker.RevealingAction();
while (queue.Count > 0)
{
var m = queue.Dequeue();
attacker.SendLocalizedMessage(1060161); // The whirling attack strikes a target!
m.SendLocalizedMessage(1060162); // You are struck by the whirling attack and take damage!
weapon.OnHit(attacker, m, damageBonus);
}
}
}
}