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
This commit is contained in:
Kamron Batman 2023-10-29 22:42:46 -07:00 • committed by GitHub
parent 27f0cec1fa
commit 28c06c1cc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 796 additions and 591 deletions

View file

@ -114,8 +114,7 @@ namespace Server.Spells.Spellweaving
private bool CheckArcanists()
{
var spellWeaving = Caster.Skills.Spellweaving.Value;
var eable = Caster.GetMobilesInRange(1);
foreach (var m in eable)
foreach (var m in Caster.GetMobilesInRange(1))
{
if (m != Caster && m is PlayerMobile && Caster.CanBeBeneficial(m, false) &&
Math.Abs(spellWeaving - m.Skills.Spellweaving.Value) <= 20)
@ -132,9 +131,7 @@ namespace Server.Spells.Spellweaving
// Everyone gets the Arcane Focus, power capped elsewhere
var pool = PooledRefQueue<Mobile>.Create();
var eable = Caster.GetMobilesInRange(1);
foreach (var m in eable)
foreach (var m in Caster.GetMobilesInRange(1))
{
if (m != Caster && m is PlayerMobile && Caster.CanBeBeneficial(m, false) &&
Math.Abs(spellWeaving - m.Skills.Spellweaving.Value) <= 20)

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Server.Collections;
namespace Server.Spells.Spellweaving
{
@ -24,7 +25,6 @@ namespace Server.Spells.Spellweaving
{
Caster.PlaySound(0x5C6);
var range = 5 + FocusLevel;
var damage = 25 + FocusLevel;
var skill = Caster.Skills.Spellweaving.Value;
@ -34,9 +34,8 @@ namespace Server.Spells.Spellweaving
var fcMalus = FocusLevel + 1;
var ssiMalus = 2 * (FocusLevel + 1);
var eable = Caster.GetMobilesInRange(range);
foreach (var m in eable)
using var queue = PooledRefQueue<Mobile>.Create();
foreach (var m in Caster.GetMobilesInRange(5 + FocusLevel))
{
if (Caster == m || !Caster.InLOS(m) || !SpellHelper.ValidIndirectTarget(Caster, m) ||
!Caster.CanBeHarmful(m, false))
@ -44,6 +43,12 @@ namespace Server.Spells.Spellweaving
continue;
}
queue.Enqueue(m);
}
while (queue.Count > 0)
{
var m = queue.Dequeue();
Caster.DoHarmful(m);
SpellHelper.Damage(this, m, damage, 0, 0, 100, 0, 0);

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Server.Collections;
namespace Server.Spells.Spellweaving
{
@ -38,12 +39,10 @@ namespace Server.Spells.Spellweaving
var pvpDamage = damage * (100 + Math.Min(sdiBonus, 15)) / 100;
var range = 2 + FocusLevel;
var duration = TimeSpan.FromSeconds(5 + FocusLevel);
var eable = Caster.GetMobilesInRange(range);
foreach (var m in eable)
using var queue = PooledRefQueue<Mobile>.Create();
foreach (var m in Caster.GetMobilesInRange(2 + FocusLevel))
{
if (Caster == m || !SpellHelper.ValidIndirectTarget(Caster, m) || !Caster.CanBeHarmful(m, false) ||
!Caster.InLOS(m))
@ -51,6 +50,12 @@ namespace Server.Spells.Spellweaving
continue;
}
queue.Enqueue(m);
}
while (queue.Count > 0)
{
var m = queue.Dequeue();
Caster.DoHarmful(m);
var oldSpell = m.Spell as Spell;