ModernUO/Projects/UOContent/Engines/TaskManager.cs

114 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Server;
using Server.Commands;
using Server.Engines.Spawners;
using Server.Items;
using Server.Mobiles;
namespace Server.Engines.Tasks;
public static class TaskManager
{
private static Timer _timer30Min;
private static Timer _timer1Hour;
private static Timer _timer4Hour;
private static Timer _timer24Hour;
public static void Initialize()
{
EventSink.ServerStarted += OnServerBoot;
_timer30Min = Timer.DelayCall(TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(30), () => On30MinuteTick(null));
_timer1Hour = Timer.DelayCall(TimeSpan.FromHours(1), TimeSpan.FromHours(1), () => On1HourTick(null));
_timer4Hour = Timer.DelayCall(TimeSpan.FromHours(4), TimeSpan.FromHours(4), () => On4HourTick(null));
_timer24Hour = Timer.DelayCall(TimeSpan.FromHours(24), TimeSpan.FromHours(24), () => On24HourTick(null));
CommandSystem.Register("ForceTask30", AccessLevel.Developer, e => On30MinuteTick(e.Mobile));
CommandSystem.Register("ForceTask1H", AccessLevel.Developer, e => On1HourTick(e.Mobile));
CommandSystem.Register("ForceTask4H", AccessLevel.Developer, e => On4HourTick(e.Mobile));
CommandSystem.Register("ForceTask24H", AccessLevel.Developer, e => On24HourTick(e.Mobile));
}
// ==========================================
// 30-MINUTE INTERVAL LOGIC
// ==========================================
public static void On30MinuteTick(Mobile from = null)
{
// 1. Refresh ~33% of Tradesmen and Meeting Spots (CitizenNodes)
var nodes = World.Items.Values
.OfType<CitizenNode>()
.Where(n => !n.Deleted && n.Map != null && n.Map != Map.Internal)
.ToList();
int nodesRefreshed = 0;
if (nodes.Count > 0)
{
Utility.Shuffle(nodes);
int countToRefresh = Math.Max(1, nodes.Count / 3);
for (int i = 0; i < countToRefresh; i++)
{
nodes[i].RefreshNode();
nodesRefreshed++;
}
}
// 2. Despawn ~33% of wandering Citizens (standard spawners will naturally replace them)
var wanderers = World.Mobiles.Values
.OfType<Citizen>()
.Where(c => !c.Deleted && c.Map != null && c.Map != Map.Internal && !(c is GatheringCitizen))
.ToList();
int wanderersRemoved = 0;
if (wanderers.Count > 0)
{
Utility.Shuffle(wanderers);
int countToRemove = Math.Max(1, wanderers.Count / 3);
for (int i = 0; i < countToRemove; i++)
{
wanderers[i].Delete();
wanderersRemoved++;
}
}
if (from != null)
{
from.SendMessage($"[TaskManager 30M] Refreshed {nodesRefreshed} CitizenNode(s) and cycled {wanderersRemoved} wandering citizen(s).");
}
}
// ==========================================
// 1-HOUR INTERVAL LOGIC
// ==========================================
public static void On1HourTick(Mobile from = null)
{
}
// ==========================================
// 4-HOUR INTERVAL LOGIC
// ==========================================
public static void On4HourTick(Mobile from = null)
{
}
// ==========================================
// 24-HOUR INTERVAL LOGIC
// ==========================================
public static void On24HourTick(Mobile from = null)
{
}
// ==========================================
// RUN ONCE ON SERVER BOOT
// ==========================================
private static void OnServerBoot()
{
}
}