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(); } } }