fix: Cleans up LINQ calls. (#965)

- [X] Removes several `ToList()` uses with `PooledRefQueue`
- [X] Adds a `PeekRandom` to PooledRefQueue
- [X] Updates EV/BS so they dispel each other in a more efficient manner.
- [X] Fixes Firebomb so it works like a normal firefield.
- [X] Fixes field spells so they aren't unnecessarily using a Point3D ref more than necessary.
- [X] Removes extra allocation in campfire by using reverse loop.
- [X] Removes other LINQ calls that aren't needed.
This commit is contained in:
Kamron Batman 2022-03-20 19:20:54 -07:00 • committed by GitHub
parent daf89686d1
commit 23532db603
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 585 additions and 447 deletions

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using Server.Events.Halloween;
using Server.Items;
@ -51,22 +50,23 @@ namespace Server.Engines.Events
var rect = m_PumpkinFields[i];
var spawncount = rect.Height * rect.Width / 20;
var pumpkins = map.GetItemsInBounds(rect).OfType<HalloweenPumpkin>().Count();
var eable = map.GetItemsInBounds<HalloweenPumpkin>(rect);
var pumpkins = 0;
foreach (var p in eable)
{
if (pumpkins++ >= spawncount)
{
break;
}
}
eable.Free();
if (spawncount > pumpkins)
{
new HalloweenPumpkin().MoveToWorld(RandomPointIn(rect, map), map);
new HalloweenPumpkin().MoveToWorld(Utility.RandomPointIn(rect, map), map);
}
}
}
private static Point3D RandomPointIn(Rectangle2D rect, Map map)
{
var x = Utility.Random(rect.X, rect.Width);
var y = Utility.Random(rect.Y, rect.Height);
var z = map.GetAverageZ(x, y);
return new Point3D(x, y, z);
}
}
}

View file

@ -115,8 +115,7 @@ namespace Server.Engines.Events
}
var map = Utility.RandomBool() ? Map.Trammel : Map.Felucca;
var home = GetRandomPointInRect(m_Cemetaries.RandomElement(), map);
var home = Utility.RandomPointIn(m_Cemetaries.RandomElement(), map);
if (map.CanSpawnMobile(home))
{
@ -131,14 +130,6 @@ namespace Server.Engines.Events
_deathQueue.Remove(player);
}
}
private static Point3D GetRandomPointInRect(Rectangle2D rect, Map map)
{
var x = Utility.Random(rect.X, rect.Width);
var y = Utility.Random(rect.Y, rect.Height);
return new Point3D(x, y, map.GetAverageZ(x, y));
}
}
[Serializable(0, false)]