ModernUO/Projects/UOContent/Holiday Stuff/Halloween/2009/Engines/PumpkinPatch.cs
Kamron Batman 525cda5413
Cleanup & Fixes for .NET 5 (#309)
- [X] Fixes several bugs
- [X] Updates more ordinal issues
- [X] Cleans up the code a bit
- [X] Turns classes static that should have been
- [X] Changes TcpServer.Instances to a HashSet

Bumps release version
2020-11-15 10:03:50 -08:00

65 lines
2 KiB
C#

using System;
using System.Linq;
using Server.Events.Halloween;
using Server.Items;
namespace Server.Engines.Events
{
public static class PumpkinPatchSpawner
{
private static Timer m_Timer;
private static readonly Rectangle2D[] m_PumpkinFields =
{
new Rectangle2D(4557, 1471, 20, 10),
new Rectangle2D(796, 2152, 36, 24),
new Rectangle2D(816, 2251, 16, 8),
new Rectangle2D(816, 2261, 16, 8),
new Rectangle2D(816, 2271, 16, 8),
new Rectangle2D(816, 2281, 16, 8),
new Rectangle2D(835, 2344, 16, 16),
new Rectangle2D(816, 2344, 16, 24)
};
public static void Initialize()
{
var now = DateTime.UtcNow;
if (now >= HolidaySettings.StartHalloween && now <= HolidaySettings.FinishHalloween)
{
m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(30), 0, PumpkinPatchSpawnerCallback);
}
}
private static void PumpkinPatchSpawnerCallback()
{
AddPumpkin(Map.Felucca);
AddPumpkin(Map.Trammel);
}
private static void AddPumpkin(Map map)
{
for (var i = 0; i < m_PumpkinFields.Length; i++)
{
var rect = m_PumpkinFields[i];
var spawncount = rect.Height * rect.Width / 20;
var pumpkins = map.GetItemsInBounds(rect).OfType<HalloweenPumpkin>().Count();
if (spawncount > pumpkins)
{
new HalloweenPumpkin().MoveToWorld(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);
}
}
}