ModernUO/Projects/UOContent/Spells/Chivalry/DispelEvil.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

121 lines
4.1 KiB
C#

using System;
using Server.Collections;
using Server.Items;
using Server.Mobiles;
using Server.Spells.Necromancy;
namespace Server.Spells.Chivalry
{
public class DispelEvilSpell : PaladinSpell
{
private static readonly SpellInfo _info = new(
"Dispel Evil",
"Dispiro Malas",
-1,
9002
);
public DispelEvilSpell(Mobile caster, Item scroll = null) : base(caster, scroll, _info)
{
}
public override TimeSpan CastDelayBase => TimeSpan.FromSeconds(0.25);
public override double RequiredSkill => 35.0;
public override int RequiredMana => 10;
public override int RequiredTithing => 10;
public override int MantraNumber => 1060721; // Dispiro Malas
public override bool BlocksMovement => false;
public override bool DelayedDamage => false;
public override void SendCastEffect()
{
Caster.FixedEffect(0x37C4, 10, 7, 4, 3); // At player
}
public override void OnCast()
{
if (CheckSequence())
{
Caster.PlaySound(0xF5);
Caster.PlaySound(0x299);
Caster.FixedParticles(0x37C4, 1, 25, 9922, 14, 3, EffectLayer.Head);
var dispelSkill = ComputePowerValue(2);
var chiv = Caster.Skills.Chivalry.Value;
using var queue = PooledRefQueue<Mobile>.Create();
foreach (var m in Caster.GetMobilesInRange(8))
{
if (Caster != m && SpellHelper.ValidIndirectTarget(Caster, m) && Caster.CanBeHarmful(m, false))
{
queue.Enqueue(m);
}
}
while (queue.Count > 0)
{
var m = queue.Dequeue();
if (m is BaseCreature bc)
{
if (bc.Summoned && !bc.IsAnimatedDead)
{
var dispelChance = (50.0 + 100 * (chiv - bc.DispelDifficulty) / (bc.DispelFocus * 2)) / 100;
dispelChance *= dispelSkill / 100.0;
if (dispelChance > Utility.RandomDouble())
{
Effects.SendLocationParticles(
EffectItem.Create(m.Location, m.Map, EffectItem.DefaultDuration),
0x3728,
8,
20,
5042
);
Effects.PlaySound(m, 0x201);
m.Delete();
continue;
}
}
var evil = !bc.Controlled && bc.Karma < 0;
if (evil)
{
// TODO: Is this right?
var fleeChance = (100 - Math.Sqrt(m.Fame / 2.0)) * chiv * dispelSkill;
fleeChance /= 1000000;
if (fleeChance > Utility.RandomDouble())
{
bc.BeginFlee(TimeSpan.FromSeconds(30.0));
}
}
}
var context = TransformationSpellHelper.GetContext(m);
if (context?.Spell is NecromancerSpell) // Trees are not evil! TODO: OSI confirm?
{
// transformed ..
var drainChance = 0.5 * (Caster.Skills.Chivalry.Value / Math.Max(m.Skills.Necromancy.Value, 1));
if (drainChance > Utility.RandomDouble())
{
var drain = 5 * dispelSkill / 100;
m.Stam -= drain;
m.Mana -= drain;
}
}
}
}
FinishSequence();
}
}
}