Advertisement
Guest User

RunUO 2.0 Hearthstone: HomeEntry

a guest
Apr 18th, 2010
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.48 KB | None | 0 0
  1. using System;
  2. using Server;
  3. using Server.Mobiles;
  4. using Server.Regions;
  5.  
  6. namespace Server.Items
  7. {
  8.     public partial class Hearthstone : Item
  9.     {
  10.         [PropertyObject]
  11.         public sealed class HomeEntry
  12.         {
  13.             private Hearthstone _Link;
  14.  
  15.             private string _Name;
  16.             private Point3D _Location;
  17.             private Map _Map;
  18.  
  19.             [CommandProperty(AccessLevel.GameMaster)]
  20.             public Hearthstone Link { get { return _Link; } set { } }
  21.  
  22.             [CommandProperty(AccessLevel.GameMaster)]
  23.             public string Name
  24.             {
  25.                 get { return _Name; }
  26.                 set
  27.                 {
  28.                     _Name = value;
  29.                     _Link.InvalidateProperties();
  30.                 }
  31.             }
  32.  
  33.             [CommandProperty(AccessLevel.GameMaster)]
  34.             public Point3D Location
  35.             {
  36.                 get { return _Location; }
  37.                 set
  38.                 {
  39.                     _Location = value;
  40.                     _Link.InvalidateProperties();
  41.                 }
  42.             }
  43.  
  44.             [CommandProperty(AccessLevel.GameMaster)]
  45.             public Map Map
  46.             {
  47.                 get { return _Map; }
  48.                 set
  49.                 {
  50.                     _Map = value;
  51.                     _Link.InvalidateProperties();
  52.                 }
  53.             }
  54.  
  55.             [CommandProperty(AccessLevel.GameMaster)]
  56.             public bool Valid { get { return IsValid(); } }
  57.  
  58.             [CommandProperty(AccessLevel.GameMaster)]
  59.             public Region Region { get { return GetRegion(); } }
  60.  
  61.             public HomeEntry(Hearthstone link)
  62.                 : this(link, Point3D.Zero, Map.Internal)
  63.             { }
  64.  
  65.             public HomeEntry(Hearthstone link, Point3D location, Map map)
  66.             {
  67.                 _Link = link;
  68.  
  69.                 Set(location, map);
  70.             }
  71.  
  72.             public void Set(Mobile m)
  73.             {
  74.                 string name = "Unknown";
  75.  
  76.                 Region r = GetRegion(m);
  77.  
  78.                 if (r != null && !String.IsNullOrEmpty(r.Name))
  79.                     name = r.Name;
  80.  
  81.                 Set(m.Location, m.Map, name);
  82.             }
  83.  
  84.             public void Set(Point3D location, Map map)
  85.             {
  86.                 string name = "Unknown";
  87.  
  88.                 Region r = GetRegion(location, map);
  89.  
  90.                 if (r != null && !String.IsNullOrEmpty(r.Name))
  91.                     name = r.Name;
  92.  
  93.                 Set(location, map, name);
  94.             }
  95.  
  96.             public void Set(Point3D location, Map map, string name)
  97.             {
  98.                 _Location = location;
  99.                 _Map = map;
  100.                 _Name = name;
  101.  
  102.                 _Link.InvalidateProperties();
  103.             }
  104.  
  105.             public bool IsValid()
  106.             {
  107.                 if (_Link == null || _Link.Deleted)
  108.                     return false;
  109.  
  110.                 if (_Location == Point3D.Zero || _Map == Map.Internal)
  111.                     return false;
  112.  
  113.                 if (GetRegion() == null)
  114.                     return false;
  115.  
  116.                 return true;
  117.             }
  118.  
  119.             public Region GetRegion()
  120.             {
  121.                 Region reg = Region.Find(_Location, _Map);
  122.  
  123.                 return GetTopRegion(reg);
  124.             }
  125.  
  126.             public Region GetRegion(Mobile m)
  127.             {
  128.                 return GetTopRegion(m.Region);
  129.             }
  130.  
  131.             public Region GetRegion(Point3D location, Map map)
  132.             {
  133.                 Region reg = Region.Find(location, map);
  134.  
  135.                 return GetTopRegion(reg);
  136.             }
  137.  
  138.             public Region GetTopRegion(Region reg)
  139.             {
  140.                 if (!reg.IsDefault && reg.Parent != null)
  141.                 {
  142.                     Region parent = reg.Parent;
  143.  
  144.                     while (parent != null)
  145.                     {
  146.                         reg = parent;
  147.                         parent = reg.Parent;
  148.                     }
  149.                 }
  150.  
  151.                 return reg;
  152.             }
  153.  
  154.             public void Serialize(GenericWriter writer)
  155.             {
  156.                 writer.Write(0);
  157.  
  158.                 writer.Write((Item)_Link);
  159.                 writer.Write((string)_Name);
  160.                 writer.Write((Point3D)_Location);
  161.                 writer.Write((Map)_Map);
  162.             }
  163.  
  164.             public void Deserialize(GenericReader reader)
  165.             {
  166.                 int version = reader.ReadInt();
  167.  
  168.                 _Link = (Hearthstone)reader.ReadItem();
  169.                 _Name = reader.ReadString();
  170.                 _Location = reader.ReadPoint3D();
  171.                 _Map = reader.ReadMap();
  172.             }
  173.  
  174.             public override string ToString()
  175.             {
  176.                 return String.Format("{0} {1}, {2}", _Name, _Location, _Map.Name);
  177.             }
  178.         }
  179.     }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement