135 lines
4.7 KiB
C#
135 lines
4.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using Server;
|
|
using Server.Items;
|
|
using Server.Custom.StaticHousing;
|
|
|
|
namespace Server.Scripts.Custom
|
|
{
|
|
public class TasksManager
|
|
{
|
|
public static void Initialize()
|
|
{
|
|
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...");
|
|
|
|
if ( Settings.S_DungeonFloorTraps )
|
|
{
|
|
ClearSpawnedTraps();
|
|
}
|
|
CheckStaticHouses();
|
|
}
|
|
|
|
private static void CheckStaticHouses()
|
|
{
|
|
string filePath = Path.Combine(Core.BaseDirectory, "Data", "Config", "statichouses.cfg");
|
|
|
|
if (!File.Exists(filePath))
|
|
{
|
|
Console.WriteLine("TasksManager: Error - Data/Config/statichouses.cfg not found!");
|
|
return;
|
|
}
|
|
|
|
int count = 0;
|
|
|
|
using (StreamReader ip = new StreamReader(filePath))
|
|
{
|
|
string line;
|
|
while ((line = ip.ReadLine()) != null)
|
|
{
|
|
line = line.Trim();
|
|
if (line.Length == 0 || line.StartsWith("#")) continue;
|
|
|
|
string[] split = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (split.Length >= 13)
|
|
{
|
|
try
|
|
{
|
|
Map map = Map.Parse(split[0]);
|
|
Point3D signLoc = new Point3D(int.Parse(split[1]), int.Parse(split[2]), int.Parse(split[3]));
|
|
|
|
Point2D start = new Point2D(int.Parse(split[4]), int.Parse(split[5]));
|
|
Point2D end = new Point2D(start.X + int.Parse(split[6]), start.Y + int.Parse(split[7]));
|
|
Rectangle2D area = new Rectangle2D(start, end);
|
|
|
|
int minZ = int.Parse(split[8]);
|
|
int maxZ = int.Parse(split[9]);
|
|
int price = int.Parse(split[10]);
|
|
int locks = int.Parse(split[11]);
|
|
int secures = int.Parse(split[12]);
|
|
|
|
int itemID = 0xC0B;
|
|
if (split.Length >= 14)
|
|
{
|
|
if (split[13].StartsWith("0x", StringComparison.OrdinalIgnoreCase))
|
|
itemID = Convert.ToInt32(split[13], 16);
|
|
else
|
|
itemID = int.Parse(split[13]);
|
|
}
|
|
|
|
if (map != null && !CheckForExistingHouse(map, signLoc))
|
|
{
|
|
StaticHouseSign sign = new StaticHouseSign(itemID, area, minZ, maxZ, price, locks, secures);
|
|
sign.MoveToWorld(signLoc, map);
|
|
count++;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error parsing statichouses.cfg line: {line}\n{ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (count > 0)
|
|
Console.WriteLine($"TasksManager: Respawned {count} missing Static House signs.");
|
|
}
|
|
|
|
private static bool CheckForExistingHouse(Map map, Point3D loc)
|
|
{
|
|
bool exists = false;
|
|
IPooledEnumerable eable = map.GetItemsInRange(loc, 0);
|
|
|
|
foreach (Item item in eable)
|
|
{
|
|
if (item is StaticHouseSign || item is Server.Multis.HouseSign)
|
|
{
|
|
exists = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
eable.Free();
|
|
return exists;
|
|
}
|
|
|
|
private static void ClearSpawnedTraps()
|
|
{
|
|
List<Item> trapsToDelete = new List<Item>();
|
|
|
|
foreach (Item item in World.Items.Values)
|
|
{
|
|
if (item is BaseTrap)
|
|
{
|
|
trapsToDelete.Add(item);
|
|
}
|
|
}
|
|
|
|
foreach (Item trap in trapsToDelete)
|
|
{
|
|
trap.Delete();
|
|
}
|
|
|
|
Console.WriteLine($"TasksManager: Wiped {trapsToDelete.Count} floor traps. Spawners will now replace them.");
|
|
}
|
|
}
|
|
}
|