#W# Spawn work. Also added TaskManager script that cleans up floor traps.
This commit is contained in:
parent
23e3ede401
commit
ed813fc86c
4 changed files with 229 additions and 1 deletions
57
Scripts/TaskManager.cs
Normal file
57
Scripts/TaskManager.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Scripts.Custom
|
||||
{
|
||||
public class TasksManager
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
// Timer.DelayCall parameters: (Initial Delay, Interval between runs, Method to call)
|
||||
// We give the server 1 minute to finish booting up before running the first sweep,
|
||||
// then it runs exactly every 1 hour after that.
|
||||
Timer.DelayCall(TimeSpan.FromMinutes(1), TimeSpan.FromHours(1), new TimerCallback(ExecuteTasks));
|
||||
|
||||
Console.WriteLine("TasksManager: Hourly automated tasks initialized.");
|
||||
}
|
||||
|
||||
public static void ExecuteTasks()
|
||||
{
|
||||
Console.WriteLine("TasksManager: Running scheduled hourly tasks...");
|
||||
|
||||
// Task 1: Wipe all floor traps so spawners can place new ones
|
||||
ClearSpawnedTraps();
|
||||
|
||||
// FUTURE TASKS:
|
||||
// Just add new methods here as your server grows!
|
||||
// Example: ClearAbandonedTents();
|
||||
// Example: AnnounceHourlyLottery();
|
||||
}
|
||||
|
||||
private static void ClearSpawnedTraps()
|
||||
{
|
||||
// We must put them in a list first. If we delete them while actively
|
||||
// searching the World.Items dictionary, it will cause a crash.
|
||||
List<Item> trapsToDelete = new List<Item>();
|
||||
|
||||
// Scan the entire world for any item that acts as a floor trap
|
||||
foreach (Item item in World.Items.Values)
|
||||
{
|
||||
if (item is BaseTrap)
|
||||
{
|
||||
trapsToDelete.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through our safe list and delete them all
|
||||
foreach (Item trap in trapsToDelete)
|
||||
{
|
||||
trap.Delete();
|
||||
}
|
||||
|
||||
Console.WriteLine($"TasksManager: Wiped {trapsToDelete.Count} floor traps. Spawners will now replace them.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue