diff --git a/Data/Config/statichouses.cfg b/Data/Config/statichouses.cfg index 8a6bc44..4b7b80a 100644 --- a/Data/Config/statichouses.cfg +++ b/Data/Config/statichouses.cfg @@ -1,3 +1,4 @@ -# Map SignX SignY SignZ StartX StartY Width Height MinZ MaxZ Price Locks Secures SignID <0xC0C/0xC0B> -Vaelen 863 595 5 861 583 11 13 0 55 5000 500 500 0xC0C -Vaelen 779 675 0 769 672 11 10 0 55 5000 500 500 0xC0B +# Map SignX SignY SignZ MinZ MaxZ Price Locks Secs ItemID Area1X Area1Y Area1W Area1H Area2X Area2Y Area2W Area2H +Vaelen 863 595 5 0 55 5000 500 500 0xC0C 861 583 11 13 +Vaelen 779 675 0 0 55 5000 500 500 0xC0B 769 672 11 10 +Vaelen 842 619 0 0 55 5000 500 500 0xC0B 834 614 8 16 826 620 9 10 diff --git a/Scripts/Items/Houses/GenStaticHouses.cs b/Scripts/Items/Houses/GenStaticHouses.cs index 64a85b2..aa9f404 100644 --- a/Scripts/Items/Houses/GenStaticHouses.cs +++ b/Scripts/Items/Houses/GenStaticHouses.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Collections.Generic; using Server; using Server.Items; using Server.Multis; @@ -38,37 +39,39 @@ namespace Server.Custom.StaticHousing string[] split = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); - if (split.Length >= 13) + // 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])); - 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 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]); - // --- NEW ITEM ID PARSING --- - int itemID = 0xC0B; // Defaults to the East-facing sign - if (split.Length >= 14) + 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 areas = new List(); + for (int i = 10; i < split.Length; i += 4) { - if (split[13].StartsWith("0x", StringComparison.OrdinalIgnoreCase)) - itemID = Convert.ToInt32(split[13], 16); - else - itemID = int.Parse(split[13]); + 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)) + if (map != null && !CheckForExistingHouse(map, signLoc) && areas.Count > 0) { - // Pass the parsed itemID into the new sign! - StaticHouseSign sign = new StaticHouseSign(itemID, area, minZ, maxZ, price, locks, secures); + StaticHouseSign sign = new StaticHouseSign(itemID, areas.ToArray(), minZ, maxZ, price, locks, secures); sign.MoveToWorld(signLoc, map); count++; } diff --git a/Scripts/Items/Houses/StaticHouse.cs b/Scripts/Items/Houses/StaticHouse.cs index f8bf0c7..3ef9095 100644 --- a/Scripts/Items/Houses/StaticHouse.cs +++ b/Scripts/Items/Houses/StaticHouse.cs @@ -6,17 +6,29 @@ namespace Server.Custom.StaticHousing { public class StaticHouse : BaseHouse { - private Rectangle2D m_CustomArea; + 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 { - return new Rectangle2D[] { new Rectangle2D(0, 0, m_CustomArea.Width, m_CustomArea.Height) }; + 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; } } @@ -24,21 +36,20 @@ namespace Server.Custom.StaticHousing { get { - if (Sign != null) - return new Point3D(Sign.X, Sign.Y + 1, Sign.Z); - + 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 area, int minZ, int maxZ, int locks, int secures, int price) + 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_CustomArea = area; + m_CustomAreas = areas; m_MinZ = minZ; m_MaxZ = maxZ; @@ -48,17 +59,11 @@ namespace Server.Custom.StaticHousing MaxLockDowns = locks; MaxSecures = secures; - Price = price; - - Components.Resize(area.Width, area.Height); - Components.Add(0x520, area.Width - 1, area.Height - 1, -5); - + UpdateFootprint(); SetSign(0, 0, 0); } - public StaticHouse(Serial serial) : base(serial) - { - } + public StaticHouse(Serial serial) : base(serial) { } public override int GetAosMaxLockdowns() { return m_CustomLockdowns; } public override int GetAosMaxSecures() { return m_CustomSecures; } @@ -67,21 +72,56 @@ namespace Server.Custom.StaticHousing { if (Deleted) return false; - if (!m_CustomArea.Contains(new Point2D(p.X, p.Y))) - return false; + // Z Check first + if (p.Z < m_MinZ || (p.Z + height) > m_MaxZ) return false; - if (p.Z >= m_MinZ && (p.Z + height) <= m_MaxZ) - return true; + // 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)0); + 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_CustomArea); writer.Write(m_MinZ); writer.Write(m_MaxZ); writer.Write(m_CustomLockdowns); @@ -93,14 +133,26 @@ namespace Server.Custom.StaticHousing base.Deserialize(reader); int version = reader.ReadInt(); - m_CustomArea = reader.ReadRect2D(); + 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(); - Components.Resize(m_CustomArea.Width, m_CustomArea.Height); - Components.Add(0x520, m_CustomArea.Width - 1, m_CustomArea.Height - 1, -5); + if (Price <= 0) Price = 1; + + UpdateFootprint(); } } } diff --git a/Scripts/Items/Houses/StaticHouseSign.cs b/Scripts/Items/Houses/StaticHouseSign.cs index 6a635f4..9eef56c 100644 --- a/Scripts/Items/Houses/StaticHouseSign.cs +++ b/Scripts/Items/Houses/StaticHouseSign.cs @@ -3,19 +3,20 @@ 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_HouseArea; + 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 HouseArea { get { return m_HouseArea; } } + 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; } } @@ -23,12 +24,12 @@ namespace Server.Custom.StaticHousing public int CustomSecures { get { return m_CustomSecures; } } [Constructable] - public StaticHouseSign(int itemID, Rectangle2D area, int minZ, int maxZ, int price, int locks, int secures) : base(itemID) + 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_HouseArea = area; + m_HouseAreas = areas; m_MinZ = minZ; m_MaxZ = maxZ; m_Price = price; @@ -48,16 +49,36 @@ namespace Server.Custom.StaticHousing list.Add(1060660, "Secures\t{0}", m_CustomSecures); } - public override void OnDoubleClick(Mobile from) + /*public override void OnDoubleClick(Mobile from) { if (!from.InRange(GetWorldLocation(), 3)) { - from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that. + 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)); } } @@ -68,19 +89,38 @@ namespace Server.Custom.StaticHousing if (Banker.Withdraw(pm, m_Price)) { - StaticHouse newHouse = new StaticHouse(pm, m_HouseArea, m_MinZ, m_MaxZ, m_CustomLockdowns, m_CustomSecures, m_Price); + StaticHouse newHouse = new StaticHouse(pm, m_HouseAreas, m_MinZ, m_MaxZ, m_CustomLockdowns, m_CustomSecures, m_Price); - Point3D houseLoc = new Point3D(m_HouseArea.Start.X, m_HouseArea.Start.Y, m_MinZ); + // 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 @@ -92,8 +132,12 @@ namespace Server.Custom.StaticHousing public override void Serialize(GenericWriter writer) { base.Serialize(writer); - writer.Write((int)0); - writer.Write(m_HouseArea); + 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); @@ -105,7 +149,20 @@ namespace Server.Custom.StaticHousing { base.Deserialize(reader); int version = reader.ReadInt(); - m_HouseArea = reader.ReadRect2D(); + + 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(); diff --git a/Scripts/Misc/ValidSettings.cs b/Scripts/Misc/ValidSettings.cs index 8e57319..ba026be 100644 --- a/Scripts/Misc/ValidSettings.cs +++ b/Scripts/Misc/ValidSettings.cs @@ -122,5 +122,18 @@ namespace Server } return Settings.S_HarvestRange; } + + public static int HousesPerAccount() + { + if ( Settings.S_HousesPerAccount == 0 ) + { + Settings.S_HousesPerAccount = 1; + } + else if ( Settings.S_HousesPerAccount < 0 ) + { + Settings.S_HousesPerAccount = -1; + } + return Settings.S_HousesPerAccount; + } } } diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index 107976f..2873891 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -3256,7 +3256,7 @@ namespace Server.Multis return false; } - public static bool HasAccountHouse( Mobile m ) + /*public static bool HasAccountHouse( Mobile m ) { Account a = m.Account as Account; @@ -3268,7 +3268,43 @@ namespace Server.Multis return true; return false; - } + }*/ + + public static bool HasAccountHouse( Mobile m ) + { + Account a = m.Account as Account; + + if ( a == null ) + return false; + + int limit = ValidSettings.HousesPerAccount(); + + if ( limit < 0 ) + return false; + + int count = 0; + + for ( int i = 0; i < a.Length; ++i ) + { + Mobile mob = a[i]; + + if ( mob != null ) + { + List list = null; + m_Table.TryGetValue( mob, out list ); + + if ( list != null ) + { + for ( int j = 0; j < list.Count; ++j ) + { + if ( !list[j].Deleted ) + count++; + } + } + } + } + return ( count >= limit ); + } public bool IsOwner( Mobile m ) { @@ -3976,4 +4012,4 @@ namespace Server.Multis return ( from == m_RegionOwner || AccountHandler.CheckAccount( from, m_RegionOwner ) ); } } -} \ No newline at end of file +} diff --git a/Scripts/Settings.cs b/Scripts/Settings.cs index 680a520..0907b1e 100644 --- a/Scripts/Settings.cs +++ b/Scripts/Settings.cs @@ -22,5 +22,6 @@ namespace Server public static bool S_DungeonFloorTraps = false; public static double S_FarmSpawnTimer = 15.0; public static int S_HarvestRange = 1; + public static int S_HousesPerAccount = 1; } } diff --git a/Scripts/TaskManager.cs b/Scripts/TaskManager.cs index f3e2797..5fe81c1 100644 --- a/Scripts/TaskManager.cs +++ b/Scripts/TaskManager.cs @@ -49,42 +49,45 @@ namespace Server.Scripts.Custom string[] split = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); - if (split.Length >= 13) + // Requires 14 parameters (10 base + 4 area variables) + 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])); - 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 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 = 0xC0B; - if (split.Length >= 14) + int itemID = split[9].StartsWith("0x", StringComparison.OrdinalIgnoreCase) + ? Convert.ToInt32(split[9], 16) + : int.Parse(split[9]); + + List areas = new List(); + for (int i = 10; i < split.Length; i += 4) { - if (split[13].StartsWith("0x", StringComparison.OrdinalIgnoreCase)) - itemID = Convert.ToInt32(split[13], 16); - else - itemID = int.Parse(split[13]); + 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)) + if (map != null && !CheckForExistingHouse(map, signLoc) && areas.Count > 0) { - StaticHouseSign sign = new StaticHouseSign(itemID, area, minZ, maxZ, price, locks, secures); + 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}"); + Console.WriteLine($"TasksManager: Error parsing statichouses.cfg line: {line}\n{ex.Message}"); } } }