#W# Added Knives TownHouses. Also wrote my own static house system that is configured with a cfg file.
This commit is contained in:
parent
3132211847
commit
dc5e0577fd
31 changed files with 7009 additions and 11 deletions
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Custom.StaticHousing;
|
||||
|
||||
namespace Server.Scripts.Custom
|
||||
{
|
||||
|
|
@ -9,9 +11,6 @@ namespace Server.Scripts.Custom
|
|||
{
|
||||
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.");
|
||||
|
|
@ -25,20 +24,98 @@ namespace Server.Scripts.Custom
|
|||
{
|
||||
ClearSpawnedTraps();
|
||||
}
|
||||
CheckStaticHouses();
|
||||
}
|
||||
|
||||
// FUTURE TASKS:
|
||||
// Just add new methods here as your server grows!
|
||||
// Example: ClearAbandonedTents();
|
||||
// Example: AnnounceHourlyLottery();
|
||||
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()
|
||||
{
|
||||
// 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)
|
||||
|
|
@ -47,7 +124,6 @@ namespace Server.Scripts.Custom
|
|||
}
|
||||
}
|
||||
|
||||
// Loop through our safe list and delete them all
|
||||
foreach (Item trap in trapsToDelete)
|
||||
{
|
||||
trap.Delete();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue