From 08baf3c35dffc5a2f682f1704b50f2203ed55d42 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 4 Dec 2021 11:31:52 -0800 Subject: [PATCH] fix: Fixes explosion potions (#873) * Fixes the users list not being cleared out * Removes the LINQ allocations --- .../Explosion Potions/BaseExplosionPotion.cs | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs b/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs index 3ada8a14a..01de15b12 100644 --- a/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs +++ b/Projects/UOContent/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; +using Server.Collections; using Server.Network; using Server.Spells; using Server.Targeting; @@ -30,7 +30,7 @@ namespace Server.Items public override bool RequireFreeHand => false; - public List Users { get; private set; } + private HashSet _users; public override void Serialize(IGenericWriter writer) { @@ -84,12 +84,8 @@ namespace Server.Items from.RevealingAction(); - Users ??= new List(); - - if (!Users.Contains(from)) - { - Users.Add(from); - } + _users ??= new HashSet(); + _users.Add(from); from.Target = new ThrowTarget(this); @@ -195,65 +191,69 @@ namespace Server.Items Consume(); - for (var i = 0; i < Users?.Count; ++i) + foreach (var user in _users) { - var m = Users[i]; - - if (m.Target is ThrowTarget targ && targ.Potion == this) + if (user.Target is ThrowTarget targ && targ.Potion == this) { - Target.Cancel(m); + Target.Cancel(user); } } + _users.Clear(); + if (map == null) { return; } Effects.PlaySound(loc, map, 0x307); - Effects.SendLocationEffect(loc, map, 0x36B0, 9); - var alchemyBonus = 0; + var alchemyBonus = 0; if (direct) { alchemyBonus = (int)(from.Skills.Alchemy.Value / (Core.AOS ? 5 : 10)); } var eable = map.GetObjectsInRange(loc, ExplosionRange, LeveledExplosion); + using var queue = PooledRefQueue.Create(); + var toDamage = 0; + foreach (var entity in eable) + { + if (entity == this) + { + continue; + } - var toExplode = eable.Where( - o => + if (entity is Mobile mobile) + { + if (from == null || SpellHelper.ValidIndirectTarget(from, mobile) && from.CanBeHarmful(mobile, false)) { - if (!(o is Mobile mobile) || from != null && - (!SpellHelper.ValidIndirectTarget(from, mobile) || !from.CanBeHarmful(mobile, false))) - { - return o is BaseExplosionPotion && o != this; - } - ++toDamage; - return true; + queue.Enqueue(entity); } - ) - .ToList(); + } + else if (entity is BaseExplosionPotion) + { + queue.Enqueue(entity); + } + } eable.Free(); var min = Scale(from, MinDamage); var max = Scale(from, MaxDamage); - for (var i = 0; i < toExplode.Count; ++i) + while (queue.Count > 0) { - var o = toExplode[i]; + var entity = queue.Dequeue(); - if (o is Mobile m) + if (entity is Mobile m) { from?.DoHarmful(m); - var damage = Utility.RandomMinMax(min, max); - - damage += alchemyBonus; + var damage = Utility.RandomMinMax(min, max) + alchemyBonus; if (!Core.AOS && damage > 40) { @@ -266,7 +266,7 @@ namespace Server.Items AOS.Damage(m, from, damage, 0, 100, 0, 0, 0); } - else if (o is BaseExplosionPotion pot) + else if (entity is BaseExplosionPotion pot) { pot.Explode(from, false, pot.GetWorldLocation(), pot.Map); }