140 lines
5.3 KiB
C#
140 lines
5.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections;
|
|
using Server;
|
|
using Server.Items;
|
|
using Server.Custom.InnRooms;
|
|
|
|
namespace Server.Commands
|
|
{
|
|
public class GenInnDoors
|
|
{
|
|
public static void Initialize()
|
|
{
|
|
CommandSystem.Register("InnGen", AccessLevel.Administrator, new CommandEventHandler(GenInnDoors_OnCommand));
|
|
}
|
|
|
|
[Usage("InnGen")]
|
|
[Description("Generates Inn Doors from a configuration file.")]
|
|
public static void GenInnDoors_OnCommand(CommandEventArgs e)
|
|
{
|
|
e.Mobile.SendMessage("Generating Inn Doors from config, please wait.");
|
|
|
|
int count = new InnDoorCreator().CreateDoors();
|
|
|
|
e.Mobile.SendMessage("Inn Door generation complete. {0} doors were generated.", count);
|
|
}
|
|
|
|
public class InnDoorCreator
|
|
{
|
|
private int m_Count;
|
|
private static Queue m_Queue = new Queue();
|
|
|
|
public static bool FindExistingDoor(Map map, Point3D p)
|
|
{
|
|
IPooledEnumerable eable = map.GetItemsInRange(p, 0);
|
|
|
|
foreach (Item item in eable)
|
|
{
|
|
if (item is InnDoor)
|
|
{
|
|
int delta = item.Z - p.Z;
|
|
|
|
if (delta >= -12 && delta <= 12)
|
|
m_Queue.Enqueue(item);
|
|
}
|
|
}
|
|
|
|
eable.Free();
|
|
|
|
while (m_Queue.Count > 0)
|
|
((Item)m_Queue.Dequeue()).Delete();
|
|
|
|
return false;
|
|
}
|
|
|
|
// --- ADDED RECTANGLE2D PARAMETER ---
|
|
public void CreateDoor(Point3D loc, Map mapLoc, Point3D roomLoc, Map roomMap, int rentCost, int itemID, Rectangle2D roomArea)
|
|
{
|
|
if (!FindExistingDoor(mapLoc, loc))
|
|
{
|
|
m_Count++;
|
|
|
|
// Passing the custom boundary into the door!
|
|
InnDoor door = new InnDoor(itemID, roomArea, rentCost);
|
|
|
|
door.RoomLocation = roomLoc;
|
|
door.RoomMap = roomMap;
|
|
|
|
door.MoveToWorld(loc, mapLoc);
|
|
}
|
|
}
|
|
|
|
public int CreateDoors()
|
|
{
|
|
string filePath = Path.Combine(Core.BaseDirectory, "Data", "Config", "inndoors.cfg");
|
|
|
|
if (!File.Exists(filePath))
|
|
{
|
|
Console.WriteLine("Warning: {0} not found. No Inn Doors generated.", filePath);
|
|
return 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);
|
|
|
|
// --- EXPANDED TO 13 ARGUMENTS ---
|
|
if (split.Length >= 14)
|
|
{
|
|
try
|
|
{
|
|
Map mapLoc = Map.Parse(split[0]);
|
|
int xLoc = int.Parse(split[1]);
|
|
int yLoc = int.Parse(split[2]);
|
|
int zLoc = int.Parse(split[3]);
|
|
|
|
Map mapRoom = Map.Parse(split[4]);
|
|
int xRoom = int.Parse(split[5]);
|
|
int yRoom = int.Parse(split[6]);
|
|
int zRoom = int.Parse(split[7]);
|
|
int rentCost = int.Parse(split[8]);
|
|
int itemID = 1765;
|
|
if (split[8].StartsWith("0x", StringComparison.OrdinalIgnoreCase))
|
|
itemID = Convert.ToInt32(split[9], 16);
|
|
else
|
|
itemID = int.Parse(split[9]);
|
|
|
|
// Parsing the new custom boundaries
|
|
int startX = int.Parse(split[10]);
|
|
int startY = int.Parse(split[11]);
|
|
int width = int.Parse(split[12]);
|
|
int height = int.Parse(split[13]);
|
|
Rectangle2D roomArea = new Rectangle2D(startX, startY, width, height);
|
|
|
|
if (mapLoc != null && mapRoom != null)
|
|
{
|
|
CreateDoor(new Point3D(xLoc, yLoc, zLoc), mapLoc, new Point3D(xRoom, yRoom, zRoom), mapRoom, rentCost, itemID, roomArea);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error parsing Inn Door config line: {0}\n{1}", line, ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return m_Count;
|
|
}
|
|
}
|
|
}
|
|
}
|