#W# Move InnRoom folder to Item/Houses

This commit is contained in:
WarrentyExpired 2026-08-24 20:17:57 -04:00
parent eea0f9defb
commit 770b95bb64
7 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,107 @@
using System;
using System.IO;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Multis;
using Server.Commands;
namespace Server.Custom.StaticHousing
{
public class GenStaticHouses
{
public static void Initialize()
{
CommandSystem.Register("GenStaticHouses", AccessLevel.Administrator, new CommandEventHandler(GenStaticHouses_OnCommand));
}
[Usage("GenStaticHouses")]
[Description("Generates Static House signs from a configuration file.")]
public static void GenStaticHouses_OnCommand(CommandEventArgs e)
{
string filePath = Path.Combine(Core.BaseDirectory, "Data", "Config", "statichouses.cfg");
if (!File.Exists(filePath))
{
e.Mobile.SendMessage(33, "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);
// We need at least 14 arguments now (10 base + 4 for the first area)
if (split.Length >= 14)
{
try
{
Map map = Map.Parse(split[0]);
Point3D signLoc = new Point3D(int.Parse(split[1]), int.Parse(split[2]), int.Parse(split[3]));
int minZ = int.Parse(split[4]);
int maxZ = int.Parse(split[5]);
int price = int.Parse(split[6]);
int locks = int.Parse(split[7]);
int secures = int.Parse(split[8]);
int itemID = split[9].StartsWith("0x", StringComparison.OrdinalIgnoreCase)
? Convert.ToInt32(split[9], 16)
: int.Parse(split[9]);
// Loop to capture ALL blocks appended to the end of the line!
List<Rectangle2D> areas = new List<Rectangle2D>();
for (int i = 10; i < split.Length; i += 4)
{
if (i + 3 < split.Length)
{
Point2D start = new Point2D(int.Parse(split[i]), int.Parse(split[i + 1]));
Point2D end = new Point2D(start.X + int.Parse(split[i + 2]), start.Y + int.Parse(split[i + 3]));
areas.Add(new Rectangle2D(start, end));
}
}
if (map != null && !CheckForExistingHouse(map, signLoc) && areas.Count > 0)
{
StaticHouseSign sign = new StaticHouseSign(itemID, areas.ToArray(), minZ, maxZ, price, locks, secures);
sign.MoveToWorld(signLoc, map);
count++;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error parsing statichouses.cfg line: {line}\n{ex.Message}");
}
}
}
}
e.Mobile.SendMessage(68, $"Generation complete. {count} new Static House signs were spawned.");
}
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 HouseSign)
{
exists = true;
break;
}
}
eable.Free();
return exists;
}
}
}

View file

@ -0,0 +1,158 @@
using System;
using Server;
using Server.Multis;
namespace Server.Custom.StaticHousing
{
public class StaticHouse : BaseHouse
{
private Rectangle2D[] m_CustomAreas;
private int m_MinZ;
private int m_MaxZ;
private int m_CustomLockdowns;
private int m_CustomSecures;
// Dynamically computes the relative coordinates for the core engine based on all blocks
public override Rectangle2D[] Area
{
get
{
if (m_CustomAreas == null) return new Rectangle2D[0];
Rectangle2D[] rel = new Rectangle2D[m_CustomAreas.Length];
for (int i = 0; i < m_CustomAreas.Length; i++)
{
rel[i] = new Rectangle2D(
m_CustomAreas[i].Start.X - this.X,
m_CustomAreas[i].Start.Y - this.Y,
m_CustomAreas[i].Width,
m_CustomAreas[i].Height);
}
return rel;
}
}
public override Point3D BaseBanLocation
{
get
{
if (Sign != null) return new Point3D(Sign.X, Sign.Y + 1, Sign.Z);
return Point3D.Zero;
}
}
public override double BonusStorageScalar { get { return 1.0; } }
public StaticHouse(Mobile owner, Rectangle2D[] areas, int minZ, int maxZ, int locks, int secures, int price)
: base(0xA28, owner, locks, secures)
{
RestrictDecay = true;
Price = price;
m_CustomAreas = areas;
m_MinZ = minZ;
m_MaxZ = maxZ;
m_CustomLockdowns = locks;
m_CustomSecures = secures;
MaxLockDowns = locks;
MaxSecures = secures;
UpdateFootprint();
SetSign(0, 0, 0);
}
public StaticHouse(Serial serial) : base(serial) { }
public override int GetAosMaxLockdowns() { return m_CustomLockdowns; }
public override int GetAosMaxSecures() { return m_CustomSecures; }
public override bool IsInside(Point3D p, int height)
{
if (Deleted) return false;
// Z Check first
if (p.Z < m_MinZ || (p.Z + height) > m_MaxZ) return false;
// Loop through all defined blocks to see if they are in ANY of them
foreach (Rectangle2D rect in m_CustomAreas)
{
if (rect.Contains(new Point2D(p.X, p.Y)))
return true;
}
return false;
}
// Stretches the internal physical item bounds over the maximum extremes of all your blocks
private void UpdateFootprint()
{
if (m_CustomAreas == null || m_CustomAreas.Length == 0) return;
int minX = m_CustomAreas[0].Start.X;
int minY = m_CustomAreas[0].Start.Y;
int maxX = m_CustomAreas[0].End.X;
int maxY = m_CustomAreas[0].End.Y;
foreach (Rectangle2D rect in m_CustomAreas)
{
if (rect.Start.X < minX) minX = rect.Start.X;
if (rect.Start.Y < minY) minY = rect.Start.Y;
if (rect.End.X > maxX) maxX = rect.End.X;
if (rect.End.Y > maxY) maxY = rect.End.Y;
}
int width = maxX - minX;
int height = maxY - minY;
if (width < 1) width = 1;
if (height < 1) height = 1;
Components.Resize(width, height);
Components.Add(0x520, width - 1, height - 1, -5);
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)1);
writer.Write(m_CustomAreas.Length);
for (int i = 0; i < m_CustomAreas.Length; i++)
writer.Write(m_CustomAreas[i]);
writer.Write(m_MinZ);
writer.Write(m_MaxZ);
writer.Write(m_CustomLockdowns);
writer.Write(m_CustomSecures);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
if (version >= 1)
{
int count = reader.ReadInt();
m_CustomAreas = new Rectangle2D[count];
for (int i = 0; i < count; i++)
m_CustomAreas[i] = reader.ReadRect2D();
}
else
{
m_CustomAreas = new Rectangle2D[] { reader.ReadRect2D() };
}
m_MinZ = reader.ReadInt();
m_MaxZ = reader.ReadInt();
m_CustomLockdowns = reader.ReadInt();
m_CustomSecures = reader.ReadInt();
if (Price <= 0) Price = 1;
UpdateFootprint();
}
}
}

View file

@ -0,0 +1,204 @@
using System;
using Server;
using Server.Mobiles;
using Server.Gumps;
using Server.Network;
using Server.Multis;
namespace Server.Custom.StaticHousing
{
public class StaticHouseSign : Item
{
private Rectangle2D[] m_HouseAreas;
private int m_MinZ;
private int m_MaxZ;
private int m_Price;
private int m_CustomLockdowns;
private int m_CustomSecures;
public Rectangle2D[] HouseAreas { get { return m_HouseAreas; } }
public int MinZ { get { return m_MinZ; } }
public int MaxZ { get { return m_MaxZ; } }
public int Price { get { return m_Price; } }
public int CustomLockdowns { get { return m_CustomLockdowns; } }
public int CustomSecures { get { return m_CustomSecures; } }
[Constructable]
public StaticHouseSign(int itemID, Rectangle2D[] areas, int minZ, int maxZ, int price, int locks, int secures) : base(itemID)
{
Name = "A Vacant House For Sale";
Movable = false;
m_HouseAreas = areas;
m_MinZ = minZ;
m_MaxZ = maxZ;
m_Price = price;
m_CustomLockdowns = locks;
m_CustomSecures = secures;
}
public StaticHouseSign(Serial serial) : base(serial)
{
}
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
list.Add(1060658, "Price\t{0} Gold", m_Price);
list.Add(1060659, "Lockdowns\t{0}", m_CustomLockdowns);
list.Add(1060660, "Secures\t{0}", m_CustomSecures);
}
/*public override void OnDoubleClick(Mobile from)
{
if (!from.InRange(GetWorldLocation(), 3))
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045);
return;
}
if (from is PlayerMobile)
{
from.SendGump(new StaticPurchaseGump((PlayerMobile)from, this));
}
}*/
public override void OnDoubleClick(Mobile from)
{
if (!from.InRange(GetWorldLocation(), 3))
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045);
return;
}
if (from is PlayerMobile)
{
if (BaseHouse.HasAccountHouse(from))
{
from.SendMessage(33, "You already own the maximum number of houses allowed on this account.");
return;
}
from.SendGump(new StaticPurchaseGump((PlayerMobile)from, this));
}
}
public void Purchase(PlayerMobile pm)
{
if (Deleted) return;
if (Banker.Withdraw(pm, m_Price))
{
StaticHouse newHouse = new StaticHouse(pm, m_HouseAreas, m_MinZ, m_MaxZ, m_CustomLockdowns, m_CustomSecures, m_Price);
// 1. Move the house controller to the exact top-left corner of the property
int minX = m_HouseAreas[0].Start.X;
int minY = m_HouseAreas[0].Start.Y;
foreach (Rectangle2D rect in m_HouseAreas)
{
if (rect.Start.X < minX) minX = rect.Start.X;
if (rect.Start.Y < minY) minY = rect.Start.Y;
}
Point3D houseLoc = new Point3D(minX, minY, m_MinZ);
newHouse.MoveToWorld(houseLoc, this.Map);
// 2. Snap the brass House Sign back and match the orientation
if (newHouse.Sign != null)
{
newHouse.Sign.Location = this.Location;
if (this.ItemID == 0xC0B)
newHouse.Sign.ItemID = 0xBD1; // East Facing
else
newHouse.Sign.ItemID = 0xBD2; // North Facing
}
// 3. Set the eviction drop point 1 step south of the sign
newHouse.BanLocation = new Point3D(this.X, this.Y + 1, this.Z);
pm.PlaySound(0x249);
pm.SendMessage(68, $"You have purchased this home for {m_Price} gold.");
// Destroy the "For Sale" sign now that the real house sign has spawned!
this.Delete();
}
else
{
pm.SendMessage(33, $"You need {m_Price} gold in your bank to purchase this home.");
}
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)1); // Version bumped to 1 to support arrays!
writer.Write(m_HouseAreas.Length);
for (int i = 0; i < m_HouseAreas.Length; i++)
writer.Write(m_HouseAreas[i]);
writer.Write(m_MinZ);
writer.Write(m_MaxZ);
writer.Write(m_Price);
writer.Write(m_CustomLockdowns);
writer.Write(m_CustomSecures);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
if (version >= 1)
{
int count = reader.ReadInt();
m_HouseAreas = new Rectangle2D[count];
for (int i = 0; i < count; i++)
m_HouseAreas[i] = reader.ReadRect2D();
}
else
{
// Backwards compatibility for the original houses
m_HouseAreas = new Rectangle2D[] { reader.ReadRect2D() };
}
m_MinZ = reader.ReadInt();
m_MaxZ = reader.ReadInt();
m_Price = reader.ReadInt();
m_CustomLockdowns = reader.ReadInt();
m_CustomSecures = reader.ReadInt();
}
private class StaticPurchaseGump : Gump
{
private PlayerMobile m_Player;
private StaticHouseSign m_Sign;
public StaticPurchaseGump(PlayerMobile pm, StaticHouseSign sign) : base(200, 200)
{
m_Player = pm;
m_Sign = sign;
AddPage(0);
AddBackground(0, 0, 300, 150, 9270);
AddHtml(0, 15, 300, 20, "<CENTER><BASEFONT COLOR=#FFFFFF>Purchase Property?</BASEFONT></CENTER>", false, false);
AddHtml(20, 50, 260, 40, $"<BASEFONT COLOR=#FFFFFF>This will deduct {sign.Price} gold from your bank box.</BASEFONT>", false, false);
AddButton(40, 100, 4005, 4007, 1, GumpButtonType.Reply, 0);
AddHtml(75, 100, 100, 20, "<BASEFONT COLOR=#FFFFFF>Confirm</BASEFONT>", false, false);
AddButton(160, 100, 4005, 4007, 0, GumpButtonType.Reply, 0);
AddHtml(195, 100, 100, 20, "<BASEFONT COLOR=#FFFFFF>Cancel</BASEFONT>", false, false);
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID == 1 && m_Sign != null && !m_Sign.Deleted)
{
m_Sign.Purchase(m_Player);
}
}
}
}
}