/CoreNew/Server/Region.cs
C# | 2518 lines | 821 code | 196 blank | 1501 comment | 174 complexity | 8b410f67ae0c881f661e041586a1cb5d MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*namespace Server
- {
- using Server.Network;
- using Server.Targeting;
- using System;
- using System.Collections;
- using System.IO;
- using System.Xml;
- public class Region : IComparable
- {
- public const int HighestPriority = 150;
- public const int HousePriority = 150;
- public const int InnPriority = 0x33;
- public const int LowestPriority = 0;
- private ArrayList m_Coords;
- private static TimeSpan m_DefaultLogoutDelay = TimeSpan.FromMinutes(5.0);
- private static TimeSpan m_GMLogoutDelay = TimeSpan.FromSeconds(10.0);
- private Point3D m_GoLoc;
- private ArrayList m_InnBounds;
- private static TimeSpan m_InnLogoutDelay = TimeSpan.Zero;
- private bool m_Load;
- private ArrayList m_LoadCoords;
- private Server.Map m_Map;
- private int m_MaxZ;
- private int m_MinZ;
- private ArrayList m_Mobiles;
- private MusicName m_Music;
- private string m_Name;
- private ArrayList m_Players;
- private string m_Prefix;
- private int m_Priority;
- private static ArrayList m_Regions = new ArrayList();
- private static int m_RegionUID = 1;
- private static bool m_SupressXmlWarnings;
- private int m_UId;
- public const int TownPriority = 50;
- public Region(string prefix, string name, Server.Map map)
- {
- this.m_Music = MusicName.Invalid;
- this.m_MinZ = -32768;
- this.m_MaxZ = 0x7fff;
- this.m_Prefix = prefix;
- this.m_Name = name;
- this.m_Map = map;
- this.m_Priority = 0;
- this.m_GoLoc = Point3D.Zero;
- this.m_Players = new ArrayList();
- this.m_Mobiles = new ArrayList();
- this.m_Load = true;
- this.m_UId = m_RegionUID++;
- }
- public Region(string prefix, string name, Server.Map map, int uid) : this(prefix, name, map)
- {
- this.m_UId = uid | 0x40000000;
- }
- public static void AddRegion(Region region)
- {
- m_Regions.Add(region);
- region.Register();
- region.Map.Regions.Add(region);
- region.Map.Regions.Sort();
- }
- public virtual bool AllowBenificial(Mobile from, Mobile target)
- {
- if (Mobile.AllowBeneficialHandler != null)
- {
- return Mobile.AllowBeneficialHandler(from, target);
- }
- return true;
- }
- public virtual bool AllowHarmful(Mobile from, Mobile target)
- {
- if (Mobile.AllowHarmfulHandler != null)
- {
- return Mobile.AllowHarmfulHandler(from, target);
- }
- return true;
- }
- public virtual bool AllowHousing(Mobile from, Point3D p)
- {
- return true;
- }
- public virtual bool AllowSpawn()
- {
- return true;
- }
- public virtual void AlterLightLevel(Mobile m, ref int global, ref int personal)
- {
- }
- public virtual bool CanUseStuckMenu(Mobile m)
- {
- return true;
- }
- public virtual bool CheckAccessibility(Item item, Mobile from)
- {
- return true;
- }
- public int CompareTo(object o)
- {
- if (o is Region)
- {
- Region region = (Region) o;
- int priority = region.m_Priority;
- int num2 = this.m_Priority;
- if (priority < num2)
- {
- return -1;
- }
- if (priority > num2)
- {
- return 1;
- }
- }
- return 0;
- }
- public virtual bool Contains(Point3D p)
- {
- if (this.m_Coords != null)
- {
- for (int i = 0; i < this.m_Coords.Count; i++)
- {
- object obj2 = this.m_Coords[i];
- if (obj2 is Rectangle3D)
- {
- Rectangle3D rectangled = (Rectangle3D) obj2;
- if (rectangled.Contains(p))
- {
- return true;
- }
- }
- else if (obj2 is Rectangle2D)
- {
- Rectangle2D rectangled2 = (Rectangle2D) obj2;
- if ((rectangled2.Contains(p) && (p.m_Z >= this.m_MinZ)) && (p.m_Z <= this.m_MaxZ))
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- public virtual void Deserialize(GenericReader reader)
- {
- reader.ReadInt();
- }
- public override bool Equals(object o)
- {
- return (((o is Region) && (o != null)) && (((Region) o) == this));
- }
- public static Region Find(Point3D p, Server.Map map)
- {
- if (map == null)
- {
- return Server.Map.Internal.DefaultRegion;
- }
- ArrayList regions = map.GetSector(p).Regions;
- for (int i = 0; i < regions.Count; i++)
- {
- Region region = (Region) regions[i];
- if (region.Contains(p))
- {
- return region;
- }
- }
- return map.DefaultRegion;
- }
- public static Region FindByUId(int uid)
- {
- for (int i = 0; i < m_Regions.Count; i++)
- {
- Region region = (Region) m_Regions[i];
- if (region.UId == uid)
- {
- return region;
- }
- }
- return null;
- }
- public static Region GetByName(string name, Server.Map map)
- {
- for (int i = 0; i < m_Regions.Count; i++)
- {
- Region region = (Region) m_Regions[i];
- if ((region.Map == map) && (region.Name == name))
- {
- return region;
- }
- }
- return null;
- }
- public override int GetHashCode()
- {
- return this.m_UId;
- }
- public virtual TimeSpan GetLogoutDelay(Mobile m)
- {
- if (((m.Aggressors.Count == 0) && (m.Aggressed.Count == 0)) && this.IsInInn(m.Location))
- {
- return m_InnLogoutDelay;
- }
- if (m.AccessLevel >= AccessLevel.GameMaster)
- {
- return m_GMLogoutDelay;
- }
- return m_DefaultLogoutDelay;
- }
- public virtual Type GetResource(Type type)
- {
- return type;
- }
- public void InternalEnter(Mobile m)
- {
- if (m.Player && !this.m_Players.Contains(m))
- {
- this.m_Players.Add(m);
- m.CheckLightLevels(false);
- this.OnPlayerAdd(m);
- }
- if (!this.m_Mobiles.Contains(m))
- {
- this.m_Mobiles.Add(m);
- this.OnMobileAdd(m);
- }
- this.OnEnter(m);
- this.PlayMusic(m);
- }
- public void InternalExit(Mobile m)
- {
- if (m.Player && this.m_Players.Contains(m))
- {
- this.m_Players.Remove(m);
- this.OnPlayerRemove(m);
- }
- if (this.m_Mobiles.Contains(m))
- {
- this.m_Mobiles.Remove(m);
- this.OnMobileRemove(m);
- }
- this.OnExit(m);
- this.StopMusic(m);
- }
- public virtual bool IsInInn(Point3D p)
- {
- if (this.m_InnBounds != null)
- {
- for (int i = 0; i < this.m_InnBounds.Count; i++)
- {
- Rectangle2D rectangled = (Rectangle2D) this.m_InnBounds[i];
- if (rectangled.Contains(p))
- {
- return true;
- }
- }
- }
- return false;
- }
- public static bool IsNull(Region r)
- {
- return object.ReferenceEquals(r, null);
- }
- public static void Load()
- {
- if (!File.Exists("Data/Regions.xml"))
- {
- Console.WriteLine("Error: Data/Regions.xml does not exist");
- }
- else
- {
- Console.Write("Regions: Loading...");
- XmlDocument document = new XmlDocument();
- document.Load("Data/Regions.xml");
- XmlElement element = document["ServerRegions"];
- foreach (XmlElement element2 in element.GetElementsByTagName("Facet"))
- {
- string attribute = element2.GetAttribute("name");
- Server.Map map = null;
- try
- {
- map = Server.Map.Parse(attribute);
- }
- catch
- {
- }
- if ((map == null) || (map == Server.Map.Internal))
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Invalid facet name '{0}'", attribute);
- }
- continue;
- }
- foreach (XmlElement element3 in element2.GetElementsByTagName("region"))
- {
- string name = element3.GetAttribute("name");
- if ((name != null) && (name.Length > 0))
- {
- Region byName = GetByName(name, map);
- if (byName != null)
- {
- if (!byName.LoadFromXml)
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Region '{0}' has an XML entry, but is set not to LoadFromXml.", name);
- }
- continue;
- }
- try
- {
- byName.Priority = int.Parse(element3.GetAttribute("priority"));
- }
- catch
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Could not parse priority for region '{0}' (assuming TownPriority)", byName.Name);
- }
- byName.Priority = 50;
- }
- XmlElement element4 = element3["go"];
- if (element4 != null)
- {
- try
- {
- byName.GoLocation = Point3D.Parse(element4.GetAttribute("location"));
- }
- catch
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Could not parse go location for region '{0}'", byName.Name);
- }
- }
- }
- element4 = element3["music"];
- if (element4 != null)
- {
- try
- {
- byName.Music = (MusicName) Enum.Parse(typeof(MusicName), element4.GetAttribute("name"), true);
- }
- catch
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Could not parse music for region '{0}'", byName.Name);
- }
- }
- }
- element4 = element3["zrange"];
- if (element4 != null)
- {
- string s = element4.GetAttribute("min");
- if ((s != null) && (s != ""))
- {
- try
- {
- byName.MinZ = int.Parse(s);
- }
- catch
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Could not parse zrange:min for region '{0}'", byName.Name);
- }
- }
- }
- s = element4.GetAttribute("max");
- if ((s != null) && (s != ""))
- {
- try
- {
- byName.MaxZ = int.Parse(s);
- }
- catch
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Could not parse zrange:max for region '{0}'", byName.Name);
- }
- }
- }
- }
- foreach (XmlElement element5 in element3.GetElementsByTagName("rect"))
- {
- try
- {
- if (byName.m_LoadCoords == null)
- {
- byName.m_LoadCoords = new ArrayList(1);
- }
- byName.m_LoadCoords.Add(ParseRectangle(element5, true));
- continue;
- }
- catch
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Error parsing rect for region '{0}'", byName.Name);
- }
- continue;
- }
- }
- foreach (XmlElement element6 in element3.GetElementsByTagName("inn"))
- {
- try
- {
- if (byName.InnBounds == null)
- {
- byName.InnBounds = new ArrayList(1);
- }
- byName.InnBounds.Add(ParseRectangle(element6, false));
- continue;
- }
- catch
- {
- if (!m_SupressXmlWarnings)
- {
- Console.WriteLine("Regions.xml: Error parsing inn for region '{0}'", byName.Name);
- }
- continue;
- }
- }
- continue;
- }
- }
- }
- }
- ArrayList list = new ArrayList(m_Regions);
- int num = 0;
- while (num < list.Count)
- {
- Region region2 = (Region) list[num];
- if (!region2.LoadFromXml && (region2.m_Coords == null))
- {
- region2.Coords = new ArrayList();
- }
- else if (region2.LoadFromXml)
- {
- if (region2.m_LoadCoords == null)
- {
- region2.m_LoadCoords = new ArrayList();
- }
- region2.Coords = region2.m_LoadCoords;
- }
- num++;
- }
- for (num = 0; num < Server.Map.AllMaps.Count; num++)
- {
- ((Server.Map) Server.Map.AllMaps[num]).Regions.Sort();
- }
- ArrayList list2 = new ArrayList(World.Mobiles.Values);
- foreach (Mobile mobile in list2)
- {
- mobile.ForceRegionReEnter(true);
- }
- Console.WriteLine("done");
- }
- }
- public virtual void MakeGuard(Mobile focus)
- {
- }
- public virtual void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
- {
- }
- public virtual bool OnBeginSpellCast(Mobile m, ISpell s)
- {
- return true;
- }
- public virtual void OnBenificialAction(Mobile helper, Mobile target)
- {
- }
- public virtual bool OnCombatantChange(Mobile m, Mobile Old, Mobile New)
- {
- return true;
- }
- public virtual void OnCriminalAction(Mobile m, bool message)
- {
- if (message)
- {
- m.SendLocalizedMessage(0xf55f0);
- }
- }
- public virtual bool OnDamage(Mobile m, ref int Damage)
- {
- return true;
- }
- public virtual bool OnDeath(Mobile m)
- {
- return true;
- }
- public virtual bool OnDecay(Item item)
- {
- return true;
- }
- public virtual void OnDidHarmful(Mobile harmer, Mobile harmed)
- {
- }
- public virtual bool OnDoubleClick(Mobile m, object o)
- {
- return true;
- }
- public virtual void OnEnter(Mobile m)
- {
- if (this.ToString() != "")
- {
- m.SendMessage("You have entered {0}", new object[] { this });
- }
- }
- public virtual void OnExit(Mobile m)
- {
- if (this.ToString() != "")
- {
- m.SendMessage("You have left {0}", new object[] { this });
- }
- }
- public virtual void OnGotBenificialAction(Mobile helper, Mobile target)
- {
- }
- public virtual void OnGotHarmful(Mobile harmer, Mobile harmed)
- {
- }
- public virtual bool OnHeal(Mobile m, ref int Heal)
- {
- return true;
- }
- public virtual void OnLocationChanged(Mobile m, Point3D oldLocation)
- {
- }
- public virtual void OnMobileAdd(Mobile m)
- {
- }
- public virtual void OnMobileRemove(Mobile m)
- {
- }
- public virtual bool OnMoveInto(Mobile m, Direction d, Point3D newLocation, Point3D oldLocation)
- {
- return true;
- }
- public virtual void OnPlayerAdd(Mobile m)
- {
- }
- public virtual void OnPlayerRemove(Mobile m)
- {
- }
- public virtual bool OnResurrect(Mobile m)
- {
- return true;
- }
- public virtual bool OnSingleClick(Mobile m, object o)
- {
- return true;
- }
- public virtual bool OnSkillUse(Mobile m, int Skill)
- {
- return true;
- }
- public virtual void OnSpeech(SpeechEventArgs args)
- {
- }
- public virtual void OnSpellCast(Mobile m, ISpell s)
- {
- }
- public virtual bool OnTarget(Mobile m, Target t, object o)
- {
- return true;
- }
- public static bool operator ==(Region l, Region r)
- {
- if (IsNull(l))
- {
- return IsNull(r);
- }
- if (IsNull(r))
- {
- return false;
- }
- return (l.UId == r.UId);
- }
- public static bool operator >(Region l, Region r)
- {
- if (IsNull(l) && IsNull(r))
- {
- return false;
- }
- if (IsNull(l))
- {
- return false;
- }
- return (IsNull(r) || (l.Priority < r.Priority));
- }
- public static bool operator !=(Region l, Region r)
- {
- if (IsNull(l))
- {
- return !IsNull(r);
- }
- return (IsNull(r) || (l.UId != r.UId));
- }
- public static bool operator <(Region l, Region r)
- {
- if (IsNull(l) && IsNull(r))
- {
- return false;
- }
- if (IsNull(l))
- {
- return true;
- }
- if (IsNull(r))
- {
- return false;
- }
- return (l.Priority > r.Priority);
- }
- public static object ParseRectangle(XmlElement rect, bool supports3d)
- {
- int num;
- int num2;
- int num3;
- int num4;
- if ((rect.HasAttribute("x") && rect.HasAttribute("y")) && (rect.HasAttribute("width") && rect.HasAttribute("height")))
- {
- num = int.Parse(rect.GetAttribute("x"));
- num2 = int.Parse(rect.GetAttribute("y"));
- num3 = num + int.Parse(rect.GetAttribute("width"));
- num4 = num2 + int.Parse(rect.GetAttribute("height"));
- }
- else
- {
- if ((!rect.HasAttribute("x1") || !rect.HasAttribute("y1")) || (!rect.HasAttribute("x2") || !rect.HasAttribute("y2")))
- {
- throw new ArgumentException("Wrong attributes specified.");
- }
- num = int.Parse(rect.GetAttribute("x1"));
- num2 = int.Parse(rect.GetAttribute("y1"));
- num3 = int.Parse(rect.GetAttribute("x2"));
- num4 = int.Parse(rect.GetAttribute("y2"));
- }
- if (!supports3d || (!rect.HasAttribute("zmin") && !rect.HasAttribute("zmax")))
- {
- return new Rectangle2D(num, num2, num3 - num, num4 - num2);
- }
- int z = -32768;
- int num6 = 0x7fff;
- if (rect.HasAttribute("zmin"))
- {
- z = int.Parse(rect.GetAttribute("zmin"));
- }
- if (rect.HasAttribute("zmax"))
- {
- num6 = int.Parse(rect.GetAttribute("zmax"));
- }
- return new Rectangle3D(num, num2, z, num3 - num, num4 - num2, (num6 - z) + 1);
- }
- public virtual void PlayMusic(Mobile m)
- {
- if ((this.m_Music != MusicName.Invalid) && (m.NetState != null))
- {
- m.Send(Server.Network.PlayMusic.GetInstance(this.m_Music));
- }
- }
- public virtual void Register()
- {
- if ((this.m_Coords != null) && (this.m_Map != null))
- {
- for (int i = 0; i < this.m_Coords.Count; i++)
- {
- Point2D pointd;
- Point2D pointd2;
- object obj2 = this.m_Coords[i];
- if (obj2 is Rectangle2D)
- {
- Rectangle2D rectangled = (Rectangle2D) obj2;
- pointd = this.m_Map.Bound(rectangled.Start);
- pointd2 = this.m_Map.Bound(rectangled.End);
- }
- else
- {
- if (!(obj2 is Rectangle3D))
- {
- goto Label_011D;
- }
- Rectangle3D rectangled2 = (Rectangle3D) obj2;
- pointd = this.m_Map.Bound(new Point2D(rectangled2.Start));
- pointd2 = this.m_Map.Bound(new Point2D(rectangled2.End));
- }
- Sector sector = this.m_Map.GetSector(pointd);
- Sector sector2 = this.m_Map.GetSector(pointd2);
- for (int j = sector.X; j <= sector2.X; j++)
- {
- for (int k = sector.Y; k <= sector2.Y; k++)
- {
- this.m_Map.GetRealSector(j, k).OnEnter(this);
- }
- }
- Label_011D:;
- }
- }
- }
- public static void RemoveRegion(Region region)
- {
- m_Regions.Remove(region);
- region.Unregister();
- region.Map.Regions.Remove(region);
- ArrayList list = new ArrayList(region.Mobiles);
- for (int i = 0; i < list.Count; i++)
- {
- ((Mobile) list[i]).ForceRegionReEnter(false);
- }
- }
- public virtual bool SendInaccessibleMessage(Item item, Mobile from)
- {
- return false;
- }
- public virtual void Serialize(GenericWriter writer)
- {
- writer.Write(0);
- }
- public virtual void SpellDamageScalar(Mobile caster, Mobile target, ref double damage)
- {
- }
- public virtual void StopMusic(Mobile m)
- {
- if ((this.m_Music != MusicName.Invalid) && (m.NetState != null))
- {
- m.Send(Server.Network.PlayMusic.InvalidInstance);
- }
- }
- public override string ToString()
- {
- if (this.Prefix != "")
- {
- return string.Format("{0} {1}", this.Prefix, this.Name);
- }
- return this.Name;
- }
- public virtual void Unregister()
- {
- if ((this.m_Coords != null) && (this.m_Map != null))
- {
- for (int i = 0; i < this.m_Coords.Count; i++)
- {
- Point2D pointd;
- Point2D pointd2;
- object obj2 = this.m_Coords[i];
- if (obj2 is Rectangle2D)
- {
- Rectangle2D rectangled = (Rectangle2D) obj2;
- pointd = this.m_Map.Bound(rectangled.Start);
- pointd2 = this.m_Map.Bound(rectangled.End);
- }
- else
- {
- if (!(obj2 is Rectangle3D))
- {
- goto Label_011D;
- }
- Rectangle3D rectangled2 = (Rectangle3D) obj2;
- pointd = this.m_Map.Bound(new Point2D(rectangled2.Start));
- pointd2 = this.m_Map.Bound(new Point2D(rectangled2.End));
- }
- Sector sector = this.m_Map.GetSector(pointd);
- Sector sector2 = this.m_Map.GetSector(pointd2);
- for (int j = sector.X; j <= sector2.X; j++)
- {
- for (int k = sector.Y; k <= sector2.Y; k++)
- {
- this.m_Map.GetRealSector(j, k).OnLeave(this);
- }
- }
- Label_011D:;
- }
- }
- }
- public ArrayList Coords
- {
- get
- {
- return this.m_Coords;
- }
- set
- {
- if (this.m_Coords != value)
- {
- RemoveRegion(this);
- this.m_Coords = value;
- AddRegion(this);
- }
- }
- }
- public static TimeSpan DefaultLogoutDelay
- {
- get
- {
- return m_DefaultLogoutDelay;
- }
- set
- {
- m_DefaultLogoutDelay = value;
- }
- }
- public static TimeSpan GMLogoutDelay
- {
- get
- {
- return m_GMLogoutDelay;
- }
- set
- {
- m_GMLogoutDelay = value;
- }
- }
- public Point3D GoLocation
- {
- get
- {
- return this.m_GoLoc;
- }
- set
- {
- this.m_GoLoc = value;
- }
- }
- public ArrayList InnBounds
- {
- get
- {
- return this.m_InnBounds;
- }
- set
- {
- this.m_InnBounds = value;
- }
- }
- public static TimeSpan InnLogoutDelay
- {
- get
- {
- return m_InnLogoutDelay;
- }
- set
- {
- m_InnLogoutDelay = value;
- }
- }
- public bool IsDefault
- {
- get
- {
- return (this == this.m_Map.DefaultRegion);
- }
- }
- public bool LoadFromXml
- {
- get
- {
- return this.m_Load;
- }
- set
- {
- this.m_Load = value;
- }
- }
- public Server.Map Map
- {
- get
- {
- return this.m_Map;
- }
- set
- {
- RemoveRegion(this);
- this.m_Map = value;
- AddRegion(this);
- }
- }
- public int MaxZ
- {
- get
- {
- return this.m_MaxZ;
- }
- set
- {
- RemoveRegion(this);
- this.m_MaxZ = value;
- AddRegion(this);
- }
- }
- public int MinZ
- {
- get
- {
- return this.m_MinZ;
- }
- set
- {
- RemoveRegion(this);
- this.m_MinZ = value;
- AddRegion(this);
- }
- }
- public ArrayList Mobiles
- {
- get
- {
- return this.m_Mobiles;
- }
- }
- public MusicName Music
- {
- get
- {
- return this.m_Music;
- }
- set
- {
- this.m_Music = value;
- }
- }
- public string Name
- {
- get
- {
- return this.m_Name;
- }
- set
- {
- this.m_Name = value;
- }
- }
- public ArrayList Players
- {
- get
- {
- return this.m_Players;
- }
- }
- public string Prefix
- {
- get
- {
- return this.m_Prefix;
- }
- set
- {
- this.m_Prefix = value;
- }
- }
- public int Priority
- {
- get
- {
- return this.m_Priority;
- }
- set
- {
- if (value != this.m_Priority)
- {
- this.m_Priority = value;
- if (this.m_Priority < 0)
- {
- this.m_Priority = 0;
- }
- else if (this.m_Priority > 150)
- {
- this.m_Priority = 150;
- }
- this.m_Map.Regions.Sort();
- }
- }
- }
- public static ArrayList Regions
- {
- get
- {
- return m_Regions;
- }
- }
- public virtual bool Saves
- {
- get
- {
- return false;
- }
- }
- public static bool SupressXmlWarnings
- {
- get
- {
- return m_SupressXmlWarnings;
- }
- set
- {
- m_SupressXmlWarnings = value;
- }
- }
- public int UId
- {
- get
- {
- return this.m_UId;
- }
- }
- }
- }
- */
- /***************************************************************************
- * BaseRegion.cs
- * -------------------
- * begin : May 1, 2002
- * copyright : (C) The RunUO Software Team
- * email : info@runuo.com
- *
- * $Id: BaseRegion.cs,v 1.4 2005/01/22 04:25:04 krrios Exp $
- * $Author: krrios $
- * $Date: 2005/01/22 04:25:04 $
- *
- *
- ***************************************************************************/
- /***************************************************************************
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- ***************************************************************************/
- using Server;
- using System;
- using System.Collections;
- using System.Xml;
- using Server.Targeting;
- using System.Collections.Generic;
- namespace Server
- {
- public class Region : IComparable
- {
- private int m_Priority;
- private ArrayList m_Coords;//Rectangle2D
- private ArrayList m_InnBounds;
- private Map m_Map;
- private string m_Name;
- private string m_Prefix;
- private Point3D m_GoLoc;
- private int m_UId;
- private bool m_Load;
- private List<Mobile> m_Players;
- private List<Mobile> m_Mobiles;
- private MusicName m_Music = MusicName.Invalid;
- public int CompareTo(object o)
- {
- if (!(o is Region))
- return 0;
- Region r = (Region)o;
- int a = r.m_Priority;
- int b = m_Priority;
- if (a < b)
- return -1;
- else if (a > b)
- return 1;
- else
- return 0;
- /*if ( o is Region )
- {
- return ((Region)o).Priority.CompareTo( Priority );
- }
- else
- return 0;*/
- }
- public Region(string prefix, string name, Map map, int uid)
- : this(prefix, name, map)
- {
- m_UId = uid | 0x40000000;
- }
- public Region(string prefix, string name, Map map)
- {
- m_Prefix = prefix;
- m_Name = name;
- m_Map = map;
- m_Priority = Region.LowestPriority;
- m_GoLoc = Point3D.Zero;
- m_Players = new List<Mobile>();
- m_Mobiles = new List<Mobile>();
- m_Load = true;
- m_UId = m_RegionUID++;
- }
- public virtual void Serialize(GenericWriter writer)
- {
- writer.Write((int)0);//version
- }
- public virtual void Deserialize(GenericReader reader)
- {
- int version = reader.ReadInt();
- }
- public virtual void MakeGuard(Mobile focus)
- {
- }
- public virtual Type GetResource(Type type)
- {
- return type;
- }
- public virtual bool CanUseStuckMenu(Mobile m)
- {
- return true;
- }
- public virtual void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
- {
- }
- public virtual void OnDidHarmful(Mobile harmer, Mobile harmed)
- {
- }
- public virtual void OnGotHarmful(Mobile harmer, Mobile harmed)
- {
- }
- public virtual void OnPlayerAdd(Mobile m)
- {
- }
- public virtual void OnPlayerRemove(Mobile m)
- {
- }
- public virtual void OnMobileAdd(Mobile m)
- {
- }
- public virtual void OnMobileRemove(Mobile m)
- {
- }
- public virtual bool OnMoveInto(Mobile m, Direction d, Point3D newLocation, Point3D oldLocation)
- {
- return true;
- }
- public virtual void OnLocationChanged(Mobile m, Point3D oldLocation)
- {
- }
- public virtual void PlayMusic(Mobile m)
- {
- if (m_Music != MusicName.Invalid && m.NetState != null)
- m.Send(Network.PlayMusic.GetInstance(m_Music));
- }
- public virtual void StopMusic(Mobile m)
- {
- if (m_Music != MusicName.Invalid && m.NetState != null)
- m.Send(Network.PlayMusic.InvalidInstance);
- }
- public void InternalEnter(Mobile m)
- {
- //Console.WriteLine(this.Name + ", " + m_Mobiles.Count.ToString());
- if (m.Player && !m_Players.Contains(m))
- {
- m_Players.Add(m);
- m.CheckLightLevels(false);
- OnPlayerAdd(m);
- }
- if (!m_Mobiles.Contains(m))
- {
- m_Mobiles.Add(m);
- OnMobileAdd(m);
- }
- OnEnter(m);
- PlayMusic(m);
- }
-
- public virtual void OnEnter(Mobile m)
- {
- string s = ToString();
- if (s != "")
- m.SendMessage("You have entered {0}", this);
- }
- public void InternalExit(Mobile m)
- {
- if (m.Player && m_Players.Contains(m))
- {
- m_Players.Remove(m);
- OnPlayerRemove(m);
- }
- if (m_Mobiles.Contains(m))
- {
- m_Mobiles.Remove(m);
- OnMobileRemove(m);
- }
- OnExit(m);
- StopMusic(m);
- }
- public virtual void OnExit(Mobile m)
- {
- string s = ToString();
- if (s != "")
- m.SendMessage("You have left {0}", this);
- }
- public virtual bool OnTarget(Mobile m, Target t, object o)
- {
- return true;
- }
- public virtual bool OnCombatantChange(Mobile m, Mobile Old, Mobile New)
- {
- return true;
- }
- public virtual bool AllowHousing(Mobile from, Point3D p)
- {
- return true;
- }
- public virtual bool SendInaccessibleMessage(Item item, Mobile from)
- {
- return false;
- }
- public virtual bool CheckAccessibility(Item item, Mobile from)
- {
- return true;
- }
- public virtual bool OnDecay(Item item)
- {
- return true;
- }
- public virtual bool AllowHarmful(Mobile from, Mobile target)
- {
- if (Mobile.AllowHarmfulHandler != null)
- return Mobile.AllowHarmfulHandler(from, target);
- return true;
- /*if ( (Map.Rules & MapRules.HarmfulRestrictions) != 0 )
- return false;
- else
- return true;*/
- }
- public virtual void OnCriminalAction(Mobile m, bool message)
- {
- if (message)
- m.SendLocalizedMessage(1005040); // You've committed a criminal act!!
- }
- public virtual bool AllowBenificial(Mobile from, Mobile target)
- {
- if (Mobile.AllowBeneficialHandler != null)
- return Mobile.AllowBeneficialHandler(from, target);
- return true;
- /*if ( (Map.Rules & MapRules.BeneficialRestrictions) != 0 )
- {
- int n = Notoriety.Compute( from, target );
- if (n == Notoriety.Criminal || n == Notoriety.Murderer)
- {
- return false;
- }
- else if ( target.Guild != null && target.Guild.Type != Guilds.GuildType.Regular )//disallow Chaos/order for healing each other or being healed by blues
- {
- if ( from.Guild == null || from.Guild.Type != target.Guild.Type )
- return false;
- }
- }
- return true;*/
- }
- public virtual void OnBenificialAction(Mobile helper, Mobile target)
- {
- }
- public virtual void OnGotBenificialAction(Mobile helper, Mobile target)
- {
- }
- public virtual bool IsInInn(Point3D p)
- {
- if (m_InnBounds == null)
- return false;
- for (int i = 0; i < m_InnBounds.Count; ++i)
- {
- Rectangle2D rect = (Rectangle2D)m_InnBounds[i];
- if (rect.Contains(p))
- return true;
- }
- return false;
- }
- private static TimeSpan m_InnLogoutDelay = TimeSpan.Zero;
- private static TimeSpan m_GMLogoutDelay = TimeSpan.FromSeconds(10.0);
- private static TimeSpan m_DefaultLogoutDelay = TimeSpan.FromMinutes(5.0);
- public static TimeSpan InnLogoutDelay
- {
- get { return m_InnLogoutDelay; }
- set { m_InnLogoutDelay = value; }
- }
- public static TimeSpan GMLogoutDelay
- {
- get { return m_GMLogoutDelay; }
- set { m_GMLogoutDelay = value; }
- }
- public static TimeSpan DefaultLogoutDelay
- {
- get { return m_DefaultLogoutDelay; }
- set { m_DefaultLogoutDelay = value; }
- }
- public virtual TimeSpan GetLogoutDelay(Mobile m)
- {
- if (m.Aggressors.Count == 0 && m.Aggressed.Count == 0 && IsInInn(m.Location))
- return m_InnLogoutDelay;
- else if (m.AccessLevel >= AccessLevel.GameMaster)
- return m_GMLogoutDelay;
- else
- return m_DefaultLogoutDelay;
- }
- public virtual void AlterLightLevel(Mobile m, ref int global, ref int personal)
- {
- }
- /*public virtual double LightLevel( Mobile m, double level )
- {
- return level;
- }*/
- public virtual void SpellDamageScalar(Mobile caster, Mobile target, ref double damage)
- {
- }
- public virtual void OnSpeech(SpeechEventArgs args)
- {
- }
- public virtual bool AllowSpawn()
- {
- return true;
- }
- public virtual bool OnSkillUse(Mobile m, int Skill)
- {
- return true;
- }
- public virtual bool OnBeginSpellCast(Mobile m, ISpell s)
- {
- return true;
- }
- public virtual void OnSpellCast(Mobile m, ISpell s)
- {
- }
- public virtual bool OnResurrect(Mobile m)
- {
- return true;
- }
- public virtual bool OnDeath(Mobile m)
- {
- return true;
- }
- public virtual bool OnDamage(Mobile m, ref int Damage)
- {
- return true;
- }
- public virtual bool OnHeal(Mobile m, ref int Heal)
- {
- return true;
- }
- public virtual bool OnDoubleClick(Mobile m, object o)
- {
- return true;
- }
- public virtual bool OnSingleClick(Mobile m, object o)
- {
- return true;
- }
- //Should this region be loaded from the xml?
- public bool LoadFromXml
- {
- get
- {
- return m_Load;
- }
- set
- {
- m_Load = value;
- }
- }
- //does this region save?
- public virtual bool Saves
- {
- get
- {
- return false;
- }
- }
- public List<Mobile> Mobiles
- {
- get
- {
- return m_Mobiles;
- }
- }
- public List<Mobile> Players
- {
- get
- {
- return m_Players;
- }
- }
- public string Name
- {
- get
- {
- return m_Name;
- }
- set
- {
- m_Name = value;
- }
- }
- public string Prefix
- {
- get
- {
- return m_Prefix;
- }
- set
- {
- m_Prefix = value;
- }
- }
- public MusicName Music
- {
- get { return m_Music; }
- set { m_Music = value; }
- }
- public Point3D GoLocation
- {
- get
- {
- return m_GoLoc;
- }
- set
- {
- m_GoLoc = value;
- }
- }
- public Map Map
- {
- get
- {
- return m_Map;
- }
- set
- {
- RemoveRegion(this);
- m_Map = value;
- AddRegion(this);
- }
- }
- public ArrayList InnBounds
- {
- get { return m_InnBounds; }
- set { m_InnBounds = value; }
- }
- private ArrayList m_LoadCoords;
- public ArrayList Coords
- {
- get
- {
- return m_Coords;
- }
- set
- {
- if (m_Coords != value)
- {
- RemoveRegion(this);
- m_Coords = value;
- AddRegion(this);
- }
- }
- }
- public int Priority
- {
- get
- {
- return m_Priority;
- }
- set
- {
- if (value != m_Priority)
- {
- m_Priority = value;
- /*if ( m_Priority < Region.LowestPriority ) m_Priority = Region.LowestPriority;
- else if ( m_Priority > Region.HighestPriority ) m_Priority = Region.HighestPriority;*/
- m_Map.Regions.Sort();
- }
- }
- }
- public int UId
- {
- get
- {
- return m_UId;
- }
- }
- private int m_MinZ = short.MinValue;
- private int m_MaxZ = short.MaxValue;
- public int MinZ { get { return m_MinZ; } set { RemoveRegion(this); m_MinZ = value; AddRegion(this); } }
- public int MaxZ { get { return m_MaxZ; } set { RemoveRegion(this); m_MaxZ = value; AddRegion(this); } }
- public virtual bool Contains(Point3D p)
- {//possibly use a binary search instead, to increase speed?
- if (m_Coords == null)
- return false;
- for (int i = 0; i < m_Coords.Count; ++i)
- {
- object obj = m_Coords[i];
- if (obj is Rectangle3D)
- {
- Rectangle3D r3d = (Rectangle3D)obj;
- if (r3d.Contains(p))
- return true;
- }
- else if (obj is Rectangle2D)
- {
- Rectangle2D r2d = (Rectangle2D)obj;
- if (r2d.Contains(p) && p.m_Z >= m_MinZ && p.m_Z <= m_MaxZ)
- return true;
- }
- }
- return false;
- }
- public override string ToString()
- {
- if (Prefix != "")
- return string.Format("{0} {1}", Prefix, Name);
- else
- return Name;
- }
- public static bool IsNull(Region r)
- {
- return Object.ReferenceEquals(r, null);
- }
- //high priorities first (high priority is less than low priority)
- public static bool operator <(Region l, Region r)
- {
- if (IsNull(l) && IsNull(r))
- return false;
- else if (IsNull(l))
- return true;
- else if (IsNull(r))
- return false;
- return l.Priority > r.Priority;
- }
- public static bool operator >(Region l, Region r)
- {
- if (IsNull(l) && IsNull(r))
- return false;
- else if (IsNull(l))
- return false;
- else if (IsNull(r))
- return true;
- return l.Priority < r.Priority;
- }
- public static bool operator ==(Region l, Region r)
- {
- …
Large files files are truncated, but you can click here to view the full file