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:
parent
27f0cec1fa
commit
28c06c1cc0
71 changed files with 796 additions and 591 deletions
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Collections;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Items;
|
||||
|
|
@ -343,28 +344,13 @@ public abstract partial class BaseDoor : Item, ILockable, ITelekinesisable
|
|||
}
|
||||
}
|
||||
|
||||
var mobs = map.GetSector(x, y).Mobiles;
|
||||
|
||||
for (var i = 0; i < mobs.Count; ++i)
|
||||
foreach (var m in map.GetMobilesAt(x, y))
|
||||
{
|
||||
var m = mobs[i];
|
||||
|
||||
if (m.Location.X == x && m.Location.Y == y)
|
||||
// At the same location, not hidden, or is a player, alive, and within z-bounds - then cannot fit
|
||||
if (m.Location.X == x && m.Location.Y == y &&
|
||||
(!m.Hidden || m.AccessLevel == AccessLevel.Player) && m.Alive && m.Z + 16 > z && z + height > m.Z)
|
||||
{
|
||||
if (m.Hidden && m.AccessLevel > AccessLevel.Player)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!m.Alive)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m.Z + 16 > z && z + height > m.Z)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public partial class Acid : Item
|
|||
|
||||
using var queue = PooledRefQueue<Mobile>.Create();
|
||||
|
||||
foreach (var m in GetMobilesInRange(0))
|
||||
foreach (var m in GetMobilesAt())
|
||||
{
|
||||
if (m.AccessLevel == AccessLevel.Player &&
|
||||
m.Alive && !m.IsDeadBondedPet && (m is not BaseCreature bc || bc.Controlled || bc.Summoned))
|
||||
|
|
|
|||
|
|
@ -122,9 +122,8 @@ public partial class Firebomb : Item
|
|||
}
|
||||
else if (RootParent == null)
|
||||
{
|
||||
var eable = Map.GetMobilesInRange(Location, 1);
|
||||
using var targets = PooledRefQueue<Mobile>.Create();
|
||||
foreach (var m in eable)
|
||||
foreach (var m in Map.GetMobilesInRange(Location, 1))
|
||||
{
|
||||
if (m_LitBy == null || SpellHelper.ValidIndirectTarget(m_LitBy, m) &&
|
||||
m_LitBy.CanBeHarmful(m, false))
|
||||
|
|
|
|||
|
|
@ -78,8 +78,7 @@ public partial class MorphItem : Item
|
|||
public void Refresh()
|
||||
{
|
||||
var found = false;
|
||||
var eable = GetMobilesInRange(CurrentRange);
|
||||
foreach (var mob in eable)
|
||||
foreach (var mob in GetMobilesInRange(CurrentRange))
|
||||
{
|
||||
if (!mob.Hidden || mob.AccessLevel <= AccessLevel.Player)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Collections;
|
||||
using Server.Spells;
|
||||
using Server.Targeting;
|
||||
|
||||
|
|
@ -275,17 +276,24 @@ public abstract partial class BaseConflagrationPotion : BasePotion
|
|||
return;
|
||||
}
|
||||
|
||||
foreach (var m in _item.GetMobilesInRange(0))
|
||||
using var queue = PooledRefQueue<Mobile>.Create();
|
||||
foreach (var m in _item.GetMobilesAt())
|
||||
{
|
||||
if (m.Z + 16 > _item.Z && _item.Z + 12 > m.Z && (!Core.AOS || m != from) &&
|
||||
SpellHelper.ValidIndirectTarget(from, m) && from.CanBeHarmful(m, false))
|
||||
{
|
||||
from.DoHarmful(m);
|
||||
|
||||
AOS.Damage(m, from, _item.GetDamage(), 0, 100, 0, 0, 0);
|
||||
m.PlaySound(0x208);
|
||||
queue.Enqueue(m);
|
||||
}
|
||||
}
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var m = queue.Dequeue();
|
||||
|
||||
from.DoHarmful(m);
|
||||
AOS.Damage(m, from, _item.GetDamage(), 0, 100, 0, 0, 0);
|
||||
m.PlaySound(0x208);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,13 +82,8 @@ public abstract partial class BaseConfusionBlastPotion : BasePotion
|
|||
|
||||
foreach (var mobile in map.GetMobilesInRange(loc, Radius))
|
||||
{
|
||||
if (mobile is BaseCreature mon)
|
||||
if (mobile is BaseCreature { Controlled: false, Summoned: false } mon)
|
||||
{
|
||||
if (mon.Controlled || mon.Summoned)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mon.Pacify(from, Core.Now + TimeSpan.FromSeconds(5.0)); // TODO check
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,10 +98,9 @@ public partial class FireHorn : Item
|
|||
);
|
||||
|
||||
var playerVsPlayer = false;
|
||||
var eable = from.Map.GetMobilesInRange(loc, 2);
|
||||
|
||||
using var targets = PooledRefQueue<Mobile>.Create();
|
||||
foreach (var m in eable)
|
||||
foreach (var m in from.Map.GetMobilesInRange(loc, 2))
|
||||
{
|
||||
if (from != m && SpellHelper.ValidIndirectTarget(from, m) && from.CanBeHarmful(m, false) &&
|
||||
(!Core.AOS || from.InLOS(m)))
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ public partial class FlameSpurtTrap : BaseTrap
|
|||
if (_spurt?.Deleted != false)
|
||||
{
|
||||
_spurt = new Static(0x3709);
|
||||
|
||||
// This MoveToWorld is generally not safe in a range loop, except we return after this on L100
|
||||
_spurt.MoveToWorld(Location, Map);
|
||||
|
||||
Effects.PlaySound(GetWorldLocation(), Map, 0x309);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Collections;
|
||||
using Server.Spells;
|
||||
|
||||
namespace Server.Items;
|
||||
|
|
@ -92,14 +93,21 @@ public partial class SpikeTrap : BaseTrap
|
|||
Effects.SendLocationEffect(Location, Map, GetBaseID(Type) + 1, 18, 3, GetEffectHue());
|
||||
Effects.PlaySound(Location, Map, 0x22C);
|
||||
|
||||
foreach (var mob in GetMobilesInRange(0))
|
||||
var queue = PooledRefQueue<Mobile>.Create();
|
||||
foreach (var mob in GetMobilesAt())
|
||||
{
|
||||
if (mob.Alive && !mob.IsDeadBondedPet)
|
||||
if (mob.Alive && !mob.IsDeadBondedPet && mob.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
SpellHelper.Damage(TimeSpan.FromTicks(1), mob, mob, Utility.RandomMinMax(1, 6) * 6);
|
||||
queue.Enqueue(mob);
|
||||
}
|
||||
}
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var mob = queue.Dequeue();
|
||||
SpellHelper.Damage(TimeSpan.FromTicks(1), mob, mob, Utility.RandomMinMax(1, 6) * 6);
|
||||
}
|
||||
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1.0), OnSpikeExtended);
|
||||
|
||||
from.LocalOverheadMessage(MessageType.Regular, 0x22, 500852); // You stepped onto a spike trap!
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Collections;
|
||||
using Server.Spells;
|
||||
|
||||
namespace Server.Items;
|
||||
|
|
@ -94,13 +95,20 @@ public partial class StoneFaceTrap : BaseTrap
|
|||
|
||||
public virtual void TriggerDamage()
|
||||
{
|
||||
var queue = PooledRefQueue<Mobile>.Create();
|
||||
foreach (var mob in GetMobilesInRange(1))
|
||||
{
|
||||
if (mob.Alive && !mob.IsDeadBondedPet && mob.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
SpellHelper.Damage(TimeSpan.FromTicks(1), mob, mob, Utility.Dice(3, 15, 0));
|
||||
queue.Enqueue(mob);
|
||||
}
|
||||
}
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var mob = queue.Dequeue();
|
||||
SpellHelper.Damage(TimeSpan.FromTicks(1), mob, mob, Utility.Dice(3, 15, 0));
|
||||
}
|
||||
}
|
||||
|
||||
[AfterDeserialization]
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ namespace Server.Items
|
|||
|
||||
bool didEffect = false;
|
||||
|
||||
var eable = attacker.GetMobilesInRange(1);
|
||||
foreach (var m in eable)
|
||||
foreach (var m in attacker.GetMobilesInRange(1))
|
||||
{
|
||||
if (m?.Deleted == false && m != defender && m != attacker &&
|
||||
SpellHelper.ValidIndirectTarget(attacker, m) &&
|
||||
|
|
|
|||
|
|
@ -36,10 +36,9 @@ namespace Server.Items
|
|||
attacker.FixedEffect(0x3728, 10, 15);
|
||||
attacker.PlaySound(0x2A1);
|
||||
|
||||
var eable = attacker.GetMobilesInRange(1);
|
||||
using var queue = PooledRefQueue<Mobile>.Create();
|
||||
|
||||
foreach (var m in eable)
|
||||
foreach (var m in attacker.GetMobilesInRange(1))
|
||||
{
|
||||
if (m?.Deleted == false && m != defender && m != attacker &&
|
||||
m.Map == attacker.Map && m.Alive &&
|
||||
|
|
|
|||
|
|
@ -1718,9 +1718,8 @@ public abstract partial class BaseWeapon : Item, IWeapon, IFactionItem, ICraftab
|
|||
return 0;
|
||||
}
|
||||
|
||||
var eable = defender.GetMobilesInRange<BaseCreature>(1);
|
||||
var inPack = 1;
|
||||
foreach (var m in eable)
|
||||
foreach (var m in defender.GetMobilesInRange<BaseCreature>(1))
|
||||
{
|
||||
if (m != attacker && (m.PackInstinct & bc.PackInstinct) != 0 && (m.Controlled || m.Summoned) &&
|
||||
master == (m.ControlMaster ?? m.SummonMaster) && m.Combatant == defender)
|
||||
|
|
@ -1743,8 +1742,7 @@ public abstract partial class BaseWeapon : Item, IWeapon, IFactionItem, ICraftab
|
|||
{
|
||||
if (MirrorImage.HasClone(defender) && defender.Skills.Ninjitsu.Value / 150.0 > Utility.RandomDouble())
|
||||
{
|
||||
var eable = defender.GetMobilesInRange<Clone>(4);
|
||||
foreach (var m in eable)
|
||||
foreach (var m in defender.GetMobilesInRange<Clone>(4))
|
||||
{
|
||||
if (m?.Summoned == true && m.SummonMaster == defender)
|
||||
{
|
||||
|
|
@ -3570,11 +3568,8 @@ public abstract partial class BaseWeapon : Item, IWeapon, IFactionItem, ICraftab
|
|||
return;
|
||||
}
|
||||
|
||||
var range = Core.ML ? 5 : 10;
|
||||
|
||||
var eable = from.GetMobilesInRange(range);
|
||||
using var queue = PooledRefQueue<Mobile>.Create();
|
||||
foreach (var m in eable)
|
||||
foreach (var m in from.GetMobilesInRange(Core.ML ? 5 : 10))
|
||||
{
|
||||
if (from != m && defender != m && SpellHelper.ValidIndirectTarget(from, m)
|
||||
&& from.CanBeHarmful(m, false) && (!Core.ML || from.InLOS(m)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue