PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/CoreNew/Server/Region.cs

https://bitbucket.org/Kel/crepuscule
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

  1. /*namespace Server
  2. {
  3. using Server.Network;
  4. using Server.Targeting;
  5. using System;
  6. using System.Collections;
  7. using System.IO;
  8. using System.Xml;
  9. public class Region : IComparable
  10. {
  11. public const int HighestPriority = 150;
  12. public const int HousePriority = 150;
  13. public const int InnPriority = 0x33;
  14. public const int LowestPriority = 0;
  15. private ArrayList m_Coords;
  16. private static TimeSpan m_DefaultLogoutDelay = TimeSpan.FromMinutes(5.0);
  17. private static TimeSpan m_GMLogoutDelay = TimeSpan.FromSeconds(10.0);
  18. private Point3D m_GoLoc;
  19. private ArrayList m_InnBounds;
  20. private static TimeSpan m_InnLogoutDelay = TimeSpan.Zero;
  21. private bool m_Load;
  22. private ArrayList m_LoadCoords;
  23. private Server.Map m_Map;
  24. private int m_MaxZ;
  25. private int m_MinZ;
  26. private ArrayList m_Mobiles;
  27. private MusicName m_Music;
  28. private string m_Name;
  29. private ArrayList m_Players;
  30. private string m_Prefix;
  31. private int m_Priority;
  32. private static ArrayList m_Regions = new ArrayList();
  33. private static int m_RegionUID = 1;
  34. private static bool m_SupressXmlWarnings;
  35. private int m_UId;
  36. public const int TownPriority = 50;
  37. public Region(string prefix, string name, Server.Map map)
  38. {
  39. this.m_Music = MusicName.Invalid;
  40. this.m_MinZ = -32768;
  41. this.m_MaxZ = 0x7fff;
  42. this.m_Prefix = prefix;
  43. this.m_Name = name;
  44. this.m_Map = map;
  45. this.m_Priority = 0;
  46. this.m_GoLoc = Point3D.Zero;
  47. this.m_Players = new ArrayList();
  48. this.m_Mobiles = new ArrayList();
  49. this.m_Load = true;
  50. this.m_UId = m_RegionUID++;
  51. }
  52. public Region(string prefix, string name, Server.Map map, int uid) : this(prefix, name, map)
  53. {
  54. this.m_UId = uid | 0x40000000;
  55. }
  56. public static void AddRegion(Region region)
  57. {
  58. m_Regions.Add(region);
  59. region.Register();
  60. region.Map.Regions.Add(region);
  61. region.Map.Regions.Sort();
  62. }
  63. public virtual bool AllowBenificial(Mobile from, Mobile target)
  64. {
  65. if (Mobile.AllowBeneficialHandler != null)
  66. {
  67. return Mobile.AllowBeneficialHandler(from, target);
  68. }
  69. return true;
  70. }
  71. public virtual bool AllowHarmful(Mobile from, Mobile target)
  72. {
  73. if (Mobile.AllowHarmfulHandler != null)
  74. {
  75. return Mobile.AllowHarmfulHandler(from, target);
  76. }
  77. return true;
  78. }
  79. public virtual bool AllowHousing(Mobile from, Point3D p)
  80. {
  81. return true;
  82. }
  83. public virtual bool AllowSpawn()
  84. {
  85. return true;
  86. }
  87. public virtual void AlterLightLevel(Mobile m, ref int global, ref int personal)
  88. {
  89. }
  90. public virtual bool CanUseStuckMenu(Mobile m)
  91. {
  92. return true;
  93. }
  94. public virtual bool CheckAccessibility(Item item, Mobile from)
  95. {
  96. return true;
  97. }
  98. public int CompareTo(object o)
  99. {
  100. if (o is Region)
  101. {
  102. Region region = (Region) o;
  103. int priority = region.m_Priority;
  104. int num2 = this.m_Priority;
  105. if (priority < num2)
  106. {
  107. return -1;
  108. }
  109. if (priority > num2)
  110. {
  111. return 1;
  112. }
  113. }
  114. return 0;
  115. }
  116. public virtual bool Contains(Point3D p)
  117. {
  118. if (this.m_Coords != null)
  119. {
  120. for (int i = 0; i < this.m_Coords.Count; i++)
  121. {
  122. object obj2 = this.m_Coords[i];
  123. if (obj2 is Rectangle3D)
  124. {
  125. Rectangle3D rectangled = (Rectangle3D) obj2;
  126. if (rectangled.Contains(p))
  127. {
  128. return true;
  129. }
  130. }
  131. else if (obj2 is Rectangle2D)
  132. {
  133. Rectangle2D rectangled2 = (Rectangle2D) obj2;
  134. if ((rectangled2.Contains(p) && (p.m_Z >= this.m_MinZ)) && (p.m_Z <= this.m_MaxZ))
  135. {
  136. return true;
  137. }
  138. }
  139. }
  140. }
  141. return false;
  142. }
  143. public virtual void Deserialize(GenericReader reader)
  144. {
  145. reader.ReadInt();
  146. }
  147. public override bool Equals(object o)
  148. {
  149. return (((o is Region) && (o != null)) && (((Region) o) == this));
  150. }
  151. public static Region Find(Point3D p, Server.Map map)
  152. {
  153. if (map == null)
  154. {
  155. return Server.Map.Internal.DefaultRegion;
  156. }
  157. ArrayList regions = map.GetSector(p).Regions;
  158. for (int i = 0; i < regions.Count; i++)
  159. {
  160. Region region = (Region) regions[i];
  161. if (region.Contains(p))
  162. {
  163. return region;
  164. }
  165. }
  166. return map.DefaultRegion;
  167. }
  168. public static Region FindByUId(int uid)
  169. {
  170. for (int i = 0; i < m_Regions.Count; i++)
  171. {
  172. Region region = (Region) m_Regions[i];
  173. if (region.UId == uid)
  174. {
  175. return region;
  176. }
  177. }
  178. return null;
  179. }
  180. public static Region GetByName(string name, Server.Map map)
  181. {
  182. for (int i = 0; i < m_Regions.Count; i++)
  183. {
  184. Region region = (Region) m_Regions[i];
  185. if ((region.Map == map) && (region.Name == name))
  186. {
  187. return region;
  188. }
  189. }
  190. return null;
  191. }
  192. public override int GetHashCode()
  193. {
  194. return this.m_UId;
  195. }
  196. public virtual TimeSpan GetLogoutDelay(Mobile m)
  197. {
  198. if (((m.Aggressors.Count == 0) && (m.Aggressed.Count == 0)) && this.IsInInn(m.Location))
  199. {
  200. return m_InnLogoutDelay;
  201. }
  202. if (m.AccessLevel >= AccessLevel.GameMaster)
  203. {
  204. return m_GMLogoutDelay;
  205. }
  206. return m_DefaultLogoutDelay;
  207. }
  208. public virtual Type GetResource(Type type)
  209. {
  210. return type;
  211. }
  212. public void InternalEnter(Mobile m)
  213. {
  214. if (m.Player && !this.m_Players.Contains(m))
  215. {
  216. this.m_Players.Add(m);
  217. m.CheckLightLevels(false);
  218. this.OnPlayerAdd(m);
  219. }
  220. if (!this.m_Mobiles.Contains(m))
  221. {
  222. this.m_Mobiles.Add(m);
  223. this.OnMobileAdd(m);
  224. }
  225. this.OnEnter(m);
  226. this.PlayMusic(m);
  227. }
  228. public void InternalExit(Mobile m)
  229. {
  230. if (m.Player && this.m_Players.Contains(m))
  231. {
  232. this.m_Players.Remove(m);
  233. this.OnPlayerRemove(m);
  234. }
  235. if (this.m_Mobiles.Contains(m))
  236. {
  237. this.m_Mobiles.Remove(m);
  238. this.OnMobileRemove(m);
  239. }
  240. this.OnExit(m);
  241. this.StopMusic(m);
  242. }
  243. public virtual bool IsInInn(Point3D p)
  244. {
  245. if (this.m_InnBounds != null)
  246. {
  247. for (int i = 0; i < this.m_InnBounds.Count; i++)
  248. {
  249. Rectangle2D rectangled = (Rectangle2D) this.m_InnBounds[i];
  250. if (rectangled.Contains(p))
  251. {
  252. return true;
  253. }
  254. }
  255. }
  256. return false;
  257. }
  258. public static bool IsNull(Region r)
  259. {
  260. return object.ReferenceEquals(r, null);
  261. }
  262. public static void Load()
  263. {
  264. if (!File.Exists("Data/Regions.xml"))
  265. {
  266. Console.WriteLine("Error: Data/Regions.xml does not exist");
  267. }
  268. else
  269. {
  270. Console.Write("Regions: Loading...");
  271. XmlDocument document = new XmlDocument();
  272. document.Load("Data/Regions.xml");
  273. XmlElement element = document["ServerRegions"];
  274. foreach (XmlElement element2 in element.GetElementsByTagName("Facet"))
  275. {
  276. string attribute = element2.GetAttribute("name");
  277. Server.Map map = null;
  278. try
  279. {
  280. map = Server.Map.Parse(attribute);
  281. }
  282. catch
  283. {
  284. }
  285. if ((map == null) || (map == Server.Map.Internal))
  286. {
  287. if (!m_SupressXmlWarnings)
  288. {
  289. Console.WriteLine("Regions.xml: Invalid facet name '{0}'", attribute);
  290. }
  291. continue;
  292. }
  293. foreach (XmlElement element3 in element2.GetElementsByTagName("region"))
  294. {
  295. string name = element3.GetAttribute("name");
  296. if ((name != null) && (name.Length > 0))
  297. {
  298. Region byName = GetByName(name, map);
  299. if (byName != null)
  300. {
  301. if (!byName.LoadFromXml)
  302. {
  303. if (!m_SupressXmlWarnings)
  304. {
  305. Console.WriteLine("Regions.xml: Region '{0}' has an XML entry, but is set not to LoadFromXml.", name);
  306. }
  307. continue;
  308. }
  309. try
  310. {
  311. byName.Priority = int.Parse(element3.GetAttribute("priority"));
  312. }
  313. catch
  314. {
  315. if (!m_SupressXmlWarnings)
  316. {
  317. Console.WriteLine("Regions.xml: Could not parse priority for region '{0}' (assuming TownPriority)", byName.Name);
  318. }
  319. byName.Priority = 50;
  320. }
  321. XmlElement element4 = element3["go"];
  322. if (element4 != null)
  323. {
  324. try
  325. {
  326. byName.GoLocation = Point3D.Parse(element4.GetAttribute("location"));
  327. }
  328. catch
  329. {
  330. if (!m_SupressXmlWarnings)
  331. {
  332. Console.WriteLine("Regions.xml: Could not parse go location for region '{0}'", byName.Name);
  333. }
  334. }
  335. }
  336. element4 = element3["music"];
  337. if (element4 != null)
  338. {
  339. try
  340. {
  341. byName.Music = (MusicName) Enum.Parse(typeof(MusicName), element4.GetAttribute("name"), true);
  342. }
  343. catch
  344. {
  345. if (!m_SupressXmlWarnings)
  346. {
  347. Console.WriteLine("Regions.xml: Could not parse music for region '{0}'", byName.Name);
  348. }
  349. }
  350. }
  351. element4 = element3["zrange"];
  352. if (element4 != null)
  353. {
  354. string s = element4.GetAttribute("min");
  355. if ((s != null) && (s != ""))
  356. {
  357. try
  358. {
  359. byName.MinZ = int.Parse(s);
  360. }
  361. catch
  362. {
  363. if (!m_SupressXmlWarnings)
  364. {
  365. Console.WriteLine("Regions.xml: Could not parse zrange:min for region '{0}'", byName.Name);
  366. }
  367. }
  368. }
  369. s = element4.GetAttribute("max");
  370. if ((s != null) && (s != ""))
  371. {
  372. try
  373. {
  374. byName.MaxZ = int.Parse(s);
  375. }
  376. catch
  377. {
  378. if (!m_SupressXmlWarnings)
  379. {
  380. Console.WriteLine("Regions.xml: Could not parse zrange:max for region '{0}'", byName.Name);
  381. }
  382. }
  383. }
  384. }
  385. foreach (XmlElement element5 in element3.GetElementsByTagName("rect"))
  386. {
  387. try
  388. {
  389. if (byName.m_LoadCoords == null)
  390. {
  391. byName.m_LoadCoords = new ArrayList(1);
  392. }
  393. byName.m_LoadCoords.Add(ParseRectangle(element5, true));
  394. continue;
  395. }
  396. catch
  397. {
  398. if (!m_SupressXmlWarnings)
  399. {
  400. Console.WriteLine("Regions.xml: Error parsing rect for region '{0}'", byName.Name);
  401. }
  402. continue;
  403. }
  404. }
  405. foreach (XmlElement element6 in element3.GetElementsByTagName("inn"))
  406. {
  407. try
  408. {
  409. if (byName.InnBounds == null)
  410. {
  411. byName.InnBounds = new ArrayList(1);
  412. }
  413. byName.InnBounds.Add(ParseRectangle(element6, false));
  414. continue;
  415. }
  416. catch
  417. {
  418. if (!m_SupressXmlWarnings)
  419. {
  420. Console.WriteLine("Regions.xml: Error parsing inn for region '{0}'", byName.Name);
  421. }
  422. continue;
  423. }
  424. }
  425. continue;
  426. }
  427. }
  428. }
  429. }
  430. ArrayList list = new ArrayList(m_Regions);
  431. int num = 0;
  432. while (num < list.Count)
  433. {
  434. Region region2 = (Region) list[num];
  435. if (!region2.LoadFromXml && (region2.m_Coords == null))
  436. {
  437. region2.Coords = new ArrayList();
  438. }
  439. else if (region2.LoadFromXml)
  440. {
  441. if (region2.m_LoadCoords == null)
  442. {
  443. region2.m_LoadCoords = new ArrayList();
  444. }
  445. region2.Coords = region2.m_LoadCoords;
  446. }
  447. num++;
  448. }
  449. for (num = 0; num < Server.Map.AllMaps.Count; num++)
  450. {
  451. ((Server.Map) Server.Map.AllMaps[num]).Regions.Sort();
  452. }
  453. ArrayList list2 = new ArrayList(World.Mobiles.Values);
  454. foreach (Mobile mobile in list2)
  455. {
  456. mobile.ForceRegionReEnter(true);
  457. }
  458. Console.WriteLine("done");
  459. }
  460. }
  461. public virtual void MakeGuard(Mobile focus)
  462. {
  463. }
  464. public virtual void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
  465. {
  466. }
  467. public virtual bool OnBeginSpellCast(Mobile m, ISpell s)
  468. {
  469. return true;
  470. }
  471. public virtual void OnBenificialAction(Mobile helper, Mobile target)
  472. {
  473. }
  474. public virtual bool OnCombatantChange(Mobile m, Mobile Old, Mobile New)
  475. {
  476. return true;
  477. }
  478. public virtual void OnCriminalAction(Mobile m, bool message)
  479. {
  480. if (message)
  481. {
  482. m.SendLocalizedMessage(0xf55f0);
  483. }
  484. }
  485. public virtual bool OnDamage(Mobile m, ref int Damage)
  486. {
  487. return true;
  488. }
  489. public virtual bool OnDeath(Mobile m)
  490. {
  491. return true;
  492. }
  493. public virtual bool OnDecay(Item item)
  494. {
  495. return true;
  496. }
  497. public virtual void OnDidHarmful(Mobile harmer, Mobile harmed)
  498. {
  499. }
  500. public virtual bool OnDoubleClick(Mobile m, object o)
  501. {
  502. return true;
  503. }
  504. public virtual void OnEnter(Mobile m)
  505. {
  506. if (this.ToString() != "")
  507. {
  508. m.SendMessage("You have entered {0}", new object[] { this });
  509. }
  510. }
  511. public virtual void OnExit(Mobile m)
  512. {
  513. if (this.ToString() != "")
  514. {
  515. m.SendMessage("You have left {0}", new object[] { this });
  516. }
  517. }
  518. public virtual void OnGotBenificialAction(Mobile helper, Mobile target)
  519. {
  520. }
  521. public virtual void OnGotHarmful(Mobile harmer, Mobile harmed)
  522. {
  523. }
  524. public virtual bool OnHeal(Mobile m, ref int Heal)
  525. {
  526. return true;
  527. }
  528. public virtual void OnLocationChanged(Mobile m, Point3D oldLocation)
  529. {
  530. }
  531. public virtual void OnMobileAdd(Mobile m)
  532. {
  533. }
  534. public virtual void OnMobileRemove(Mobile m)
  535. {
  536. }
  537. public virtual bool OnMoveInto(Mobile m, Direction d, Point3D newLocation, Point3D oldLocation)
  538. {
  539. return true;
  540. }
  541. public virtual void OnPlayerAdd(Mobile m)
  542. {
  543. }
  544. public virtual void OnPlayerRemove(Mobile m)
  545. {
  546. }
  547. public virtual bool OnResurrect(Mobile m)
  548. {
  549. return true;
  550. }
  551. public virtual bool OnSingleClick(Mobile m, object o)
  552. {
  553. return true;
  554. }
  555. public virtual bool OnSkillUse(Mobile m, int Skill)
  556. {
  557. return true;
  558. }
  559. public virtual void OnSpeech(SpeechEventArgs args)
  560. {
  561. }
  562. public virtual void OnSpellCast(Mobile m, ISpell s)
  563. {
  564. }
  565. public virtual bool OnTarget(Mobile m, Target t, object o)
  566. {
  567. return true;
  568. }
  569. public static bool operator ==(Region l, Region r)
  570. {
  571. if (IsNull(l))
  572. {
  573. return IsNull(r);
  574. }
  575. if (IsNull(r))
  576. {
  577. return false;
  578. }
  579. return (l.UId == r.UId);
  580. }
  581. public static bool operator >(Region l, Region r)
  582. {
  583. if (IsNull(l) && IsNull(r))
  584. {
  585. return false;
  586. }
  587. if (IsNull(l))
  588. {
  589. return false;
  590. }
  591. return (IsNull(r) || (l.Priority < r.Priority));
  592. }
  593. public static bool operator !=(Region l, Region r)
  594. {
  595. if (IsNull(l))
  596. {
  597. return !IsNull(r);
  598. }
  599. return (IsNull(r) || (l.UId != r.UId));
  600. }
  601. public static bool operator <(Region l, Region r)
  602. {
  603. if (IsNull(l) && IsNull(r))
  604. {
  605. return false;
  606. }
  607. if (IsNull(l))
  608. {
  609. return true;
  610. }
  611. if (IsNull(r))
  612. {
  613. return false;
  614. }
  615. return (l.Priority > r.Priority);
  616. }
  617. public static object ParseRectangle(XmlElement rect, bool supports3d)
  618. {
  619. int num;
  620. int num2;
  621. int num3;
  622. int num4;
  623. if ((rect.HasAttribute("x") && rect.HasAttribute("y")) && (rect.HasAttribute("width") && rect.HasAttribute("height")))
  624. {
  625. num = int.Parse(rect.GetAttribute("x"));
  626. num2 = int.Parse(rect.GetAttribute("y"));
  627. num3 = num + int.Parse(rect.GetAttribute("width"));
  628. num4 = num2 + int.Parse(rect.GetAttribute("height"));
  629. }
  630. else
  631. {
  632. if ((!rect.HasAttribute("x1") || !rect.HasAttribute("y1")) || (!rect.HasAttribute("x2") || !rect.HasAttribute("y2")))
  633. {
  634. throw new ArgumentException("Wrong attributes specified.");
  635. }
  636. num = int.Parse(rect.GetAttribute("x1"));
  637. num2 = int.Parse(rect.GetAttribute("y1"));
  638. num3 = int.Parse(rect.GetAttribute("x2"));
  639. num4 = int.Parse(rect.GetAttribute("y2"));
  640. }
  641. if (!supports3d || (!rect.HasAttribute("zmin") && !rect.HasAttribute("zmax")))
  642. {
  643. return new Rectangle2D(num, num2, num3 - num, num4 - num2);
  644. }
  645. int z = -32768;
  646. int num6 = 0x7fff;
  647. if (rect.HasAttribute("zmin"))
  648. {
  649. z = int.Parse(rect.GetAttribute("zmin"));
  650. }
  651. if (rect.HasAttribute("zmax"))
  652. {
  653. num6 = int.Parse(rect.GetAttribute("zmax"));
  654. }
  655. return new Rectangle3D(num, num2, z, num3 - num, num4 - num2, (num6 - z) + 1);
  656. }
  657. public virtual void PlayMusic(Mobile m)
  658. {
  659. if ((this.m_Music != MusicName.Invalid) && (m.NetState != null))
  660. {
  661. m.Send(Server.Network.PlayMusic.GetInstance(this.m_Music));
  662. }
  663. }
  664. public virtual void Register()
  665. {
  666. if ((this.m_Coords != null) && (this.m_Map != null))
  667. {
  668. for (int i = 0; i < this.m_Coords.Count; i++)
  669. {
  670. Point2D pointd;
  671. Point2D pointd2;
  672. object obj2 = this.m_Coords[i];
  673. if (obj2 is Rectangle2D)
  674. {
  675. Rectangle2D rectangled = (Rectangle2D) obj2;
  676. pointd = this.m_Map.Bound(rectangled.Start);
  677. pointd2 = this.m_Map.Bound(rectangled.End);
  678. }
  679. else
  680. {
  681. if (!(obj2 is Rectangle3D))
  682. {
  683. goto Label_011D;
  684. }
  685. Rectangle3D rectangled2 = (Rectangle3D) obj2;
  686. pointd = this.m_Map.Bound(new Point2D(rectangled2.Start));
  687. pointd2 = this.m_Map.Bound(new Point2D(rectangled2.End));
  688. }
  689. Sector sector = this.m_Map.GetSector(pointd);
  690. Sector sector2 = this.m_Map.GetSector(pointd2);
  691. for (int j = sector.X; j <= sector2.X; j++)
  692. {
  693. for (int k = sector.Y; k <= sector2.Y; k++)
  694. {
  695. this.m_Map.GetRealSector(j, k).OnEnter(this);
  696. }
  697. }
  698. Label_011D:;
  699. }
  700. }
  701. }
  702. public static void RemoveRegion(Region region)
  703. {
  704. m_Regions.Remove(region);
  705. region.Unregister();
  706. region.Map.Regions.Remove(region);
  707. ArrayList list = new ArrayList(region.Mobiles);
  708. for (int i = 0; i < list.Count; i++)
  709. {
  710. ((Mobile) list[i]).ForceRegionReEnter(false);
  711. }
  712. }
  713. public virtual bool SendInaccessibleMessage(Item item, Mobile from)
  714. {
  715. return false;
  716. }
  717. public virtual void Serialize(GenericWriter writer)
  718. {
  719. writer.Write(0);
  720. }
  721. public virtual void SpellDamageScalar(Mobile caster, Mobile target, ref double damage)
  722. {
  723. }
  724. public virtual void StopMusic(Mobile m)
  725. {
  726. if ((this.m_Music != MusicName.Invalid) && (m.NetState != null))
  727. {
  728. m.Send(Server.Network.PlayMusic.InvalidInstance);
  729. }
  730. }
  731. public override string ToString()
  732. {
  733. if (this.Prefix != "")
  734. {
  735. return string.Format("{0} {1}", this.Prefix, this.Name);
  736. }
  737. return this.Name;
  738. }
  739. public virtual void Unregister()
  740. {
  741. if ((this.m_Coords != null) && (this.m_Map != null))
  742. {
  743. for (int i = 0; i < this.m_Coords.Count; i++)
  744. {
  745. Point2D pointd;
  746. Point2D pointd2;
  747. object obj2 = this.m_Coords[i];
  748. if (obj2 is Rectangle2D)
  749. {
  750. Rectangle2D rectangled = (Rectangle2D) obj2;
  751. pointd = this.m_Map.Bound(rectangled.Start);
  752. pointd2 = this.m_Map.Bound(rectangled.End);
  753. }
  754. else
  755. {
  756. if (!(obj2 is Rectangle3D))
  757. {
  758. goto Label_011D;
  759. }
  760. Rectangle3D rectangled2 = (Rectangle3D) obj2;
  761. pointd = this.m_Map.Bound(new Point2D(rectangled2.Start));
  762. pointd2 = this.m_Map.Bound(new Point2D(rectangled2.End));
  763. }
  764. Sector sector = this.m_Map.GetSector(pointd);
  765. Sector sector2 = this.m_Map.GetSector(pointd2);
  766. for (int j = sector.X; j <= sector2.X; j++)
  767. {
  768. for (int k = sector.Y; k <= sector2.Y; k++)
  769. {
  770. this.m_Map.GetRealSector(j, k).OnLeave(this);
  771. }
  772. }
  773. Label_011D:;
  774. }
  775. }
  776. }
  777. public ArrayList Coords
  778. {
  779. get
  780. {
  781. return this.m_Coords;
  782. }
  783. set
  784. {
  785. if (this.m_Coords != value)
  786. {
  787. RemoveRegion(this);
  788. this.m_Coords = value;
  789. AddRegion(this);
  790. }
  791. }
  792. }
  793. public static TimeSpan DefaultLogoutDelay
  794. {
  795. get
  796. {
  797. return m_DefaultLogoutDelay;
  798. }
  799. set
  800. {
  801. m_DefaultLogoutDelay = value;
  802. }
  803. }
  804. public static TimeSpan GMLogoutDelay
  805. {
  806. get
  807. {
  808. return m_GMLogoutDelay;
  809. }
  810. set
  811. {
  812. m_GMLogoutDelay = value;
  813. }
  814. }
  815. public Point3D GoLocation
  816. {
  817. get
  818. {
  819. return this.m_GoLoc;
  820. }
  821. set
  822. {
  823. this.m_GoLoc = value;
  824. }
  825. }
  826. public ArrayList InnBounds
  827. {
  828. get
  829. {
  830. return this.m_InnBounds;
  831. }
  832. set
  833. {
  834. this.m_InnBounds = value;
  835. }
  836. }
  837. public static TimeSpan InnLogoutDelay
  838. {
  839. get
  840. {
  841. return m_InnLogoutDelay;
  842. }
  843. set
  844. {
  845. m_InnLogoutDelay = value;
  846. }
  847. }
  848. public bool IsDefault
  849. {
  850. get
  851. {
  852. return (this == this.m_Map.DefaultRegion);
  853. }
  854. }
  855. public bool LoadFromXml
  856. {
  857. get
  858. {
  859. return this.m_Load;
  860. }
  861. set
  862. {
  863. this.m_Load = value;
  864. }
  865. }
  866. public Server.Map Map
  867. {
  868. get
  869. {
  870. return this.m_Map;
  871. }
  872. set
  873. {
  874. RemoveRegion(this);
  875. this.m_Map = value;
  876. AddRegion(this);
  877. }
  878. }
  879. public int MaxZ
  880. {
  881. get
  882. {
  883. return this.m_MaxZ;
  884. }
  885. set
  886. {
  887. RemoveRegion(this);
  888. this.m_MaxZ = value;
  889. AddRegion(this);
  890. }
  891. }
  892. public int MinZ
  893. {
  894. get
  895. {
  896. return this.m_MinZ;
  897. }
  898. set
  899. {
  900. RemoveRegion(this);
  901. this.m_MinZ = value;
  902. AddRegion(this);
  903. }
  904. }
  905. public ArrayList Mobiles
  906. {
  907. get
  908. {
  909. return this.m_Mobiles;
  910. }
  911. }
  912. public MusicName Music
  913. {
  914. get
  915. {
  916. return this.m_Music;
  917. }
  918. set
  919. {
  920. this.m_Music = value;
  921. }
  922. }
  923. public string Name
  924. {
  925. get
  926. {
  927. return this.m_Name;
  928. }
  929. set
  930. {
  931. this.m_Name = value;
  932. }
  933. }
  934. public ArrayList Players
  935. {
  936. get
  937. {
  938. return this.m_Players;
  939. }
  940. }
  941. public string Prefix
  942. {
  943. get
  944. {
  945. return this.m_Prefix;
  946. }
  947. set
  948. {
  949. this.m_Prefix = value;
  950. }
  951. }
  952. public int Priority
  953. {
  954. get
  955. {
  956. return this.m_Priority;
  957. }
  958. set
  959. {
  960. if (value != this.m_Priority)
  961. {
  962. this.m_Priority = value;
  963. if (this.m_Priority < 0)
  964. {
  965. this.m_Priority = 0;
  966. }
  967. else if (this.m_Priority > 150)
  968. {
  969. this.m_Priority = 150;
  970. }
  971. this.m_Map.Regions.Sort();
  972. }
  973. }
  974. }
  975. public static ArrayList Regions
  976. {
  977. get
  978. {
  979. return m_Regions;
  980. }
  981. }
  982. public virtual bool Saves
  983. {
  984. get
  985. {
  986. return false;
  987. }
  988. }
  989. public static bool SupressXmlWarnings
  990. {
  991. get
  992. {
  993. return m_SupressXmlWarnings;
  994. }
  995. set
  996. {
  997. m_SupressXmlWarnings = value;
  998. }
  999. }
  1000. public int UId
  1001. {
  1002. get
  1003. {
  1004. return this.m_UId;
  1005. }
  1006. }
  1007. }
  1008. }
  1009. */
  1010. /***************************************************************************
  1011. * BaseRegion.cs
  1012. * -------------------
  1013. * begin : May 1, 2002
  1014. * copyright : (C) The RunUO Software Team
  1015. * email : info@runuo.com
  1016. *
  1017. * $Id: BaseRegion.cs,v 1.4 2005/01/22 04:25:04 krrios Exp $
  1018. * $Author: krrios $
  1019. * $Date: 2005/01/22 04:25:04 $
  1020. *
  1021. *
  1022. ***************************************************************************/
  1023. /***************************************************************************
  1024. *
  1025. * This program is free software; you can redistribute it and/or modify
  1026. * it under the terms of the GNU General Public License as published by
  1027. * the Free Software Foundation; either version 2 of the License, or
  1028. * (at your option) any later version.
  1029. *
  1030. ***************************************************************************/
  1031. using Server;
  1032. using System;
  1033. using System.Collections;
  1034. using System.Xml;
  1035. using Server.Targeting;
  1036. using System.Collections.Generic;
  1037. namespace Server
  1038. {
  1039. public class Region : IComparable
  1040. {
  1041. private int m_Priority;
  1042. private ArrayList m_Coords;//Rectangle2D
  1043. private ArrayList m_InnBounds;
  1044. private Map m_Map;
  1045. private string m_Name;
  1046. private string m_Prefix;
  1047. private Point3D m_GoLoc;
  1048. private int m_UId;
  1049. private bool m_Load;
  1050. private List<Mobile> m_Players;
  1051. private List<Mobile> m_Mobiles;
  1052. private MusicName m_Music = MusicName.Invalid;
  1053. public int CompareTo(object o)
  1054. {
  1055. if (!(o is Region))
  1056. return 0;
  1057. Region r = (Region)o;
  1058. int a = r.m_Priority;
  1059. int b = m_Priority;
  1060. if (a < b)
  1061. return -1;
  1062. else if (a > b)
  1063. return 1;
  1064. else
  1065. return 0;
  1066. /*if ( o is Region )
  1067. {
  1068. return ((Region)o).Priority.CompareTo( Priority );
  1069. }
  1070. else
  1071. return 0;*/
  1072. }
  1073. public Region(string prefix, string name, Map map, int uid)
  1074. : this(prefix, name, map)
  1075. {
  1076. m_UId = uid | 0x40000000;
  1077. }
  1078. public Region(string prefix, string name, Map map)
  1079. {
  1080. m_Prefix = prefix;
  1081. m_Name = name;
  1082. m_Map = map;
  1083. m_Priority = Region.LowestPriority;
  1084. m_GoLoc = Point3D.Zero;
  1085. m_Players = new List<Mobile>();
  1086. m_Mobiles = new List<Mobile>();
  1087. m_Load = true;
  1088. m_UId = m_RegionUID++;
  1089. }
  1090. public virtual void Serialize(GenericWriter writer)
  1091. {
  1092. writer.Write((int)0);//version
  1093. }
  1094. public virtual void Deserialize(GenericReader reader)
  1095. {
  1096. int version = reader.ReadInt();
  1097. }
  1098. public virtual void MakeGuard(Mobile focus)
  1099. {
  1100. }
  1101. public virtual Type GetResource(Type type)
  1102. {
  1103. return type;
  1104. }
  1105. public virtual bool CanUseStuckMenu(Mobile m)
  1106. {
  1107. return true;
  1108. }
  1109. public virtual void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
  1110. {
  1111. }
  1112. public virtual void OnDidHarmful(Mobile harmer, Mobile harmed)
  1113. {
  1114. }
  1115. public virtual void OnGotHarmful(Mobile harmer, Mobile harmed)
  1116. {
  1117. }
  1118. public virtual void OnPlayerAdd(Mobile m)
  1119. {
  1120. }
  1121. public virtual void OnPlayerRemove(Mobile m)
  1122. {
  1123. }
  1124. public virtual void OnMobileAdd(Mobile m)
  1125. {
  1126. }
  1127. public virtual void OnMobileRemove(Mobile m)
  1128. {
  1129. }
  1130. public virtual bool OnMoveInto(Mobile m, Direction d, Point3D newLocation, Point3D oldLocation)
  1131. {
  1132. return true;
  1133. }
  1134. public virtual void OnLocationChanged(Mobile m, Point3D oldLocation)
  1135. {
  1136. }
  1137. public virtual void PlayMusic(Mobile m)
  1138. {
  1139. if (m_Music != MusicName.Invalid && m.NetState != null)
  1140. m.Send(Network.PlayMusic.GetInstance(m_Music));
  1141. }
  1142. public virtual void StopMusic(Mobile m)
  1143. {
  1144. if (m_Music != MusicName.Invalid && m.NetState != null)
  1145. m.Send(Network.PlayMusic.InvalidInstance);
  1146. }
  1147. public void InternalEnter(Mobile m)
  1148. {
  1149. //Console.WriteLine(this.Name + ", " + m_Mobiles.Count.ToString());
  1150. if (m.Player && !m_Players.Contains(m))
  1151. {
  1152. m_Players.Add(m);
  1153. m.CheckLightLevels(false);
  1154. OnPlayerAdd(m);
  1155. }
  1156. if (!m_Mobiles.Contains(m))
  1157. {
  1158. m_Mobiles.Add(m);
  1159. OnMobileAdd(m);
  1160. }
  1161. OnEnter(m);
  1162. PlayMusic(m);
  1163. }
  1164. public virtual void OnEnter(Mobile m)
  1165. {
  1166. string s = ToString();
  1167. if (s != "")
  1168. m.SendMessage("You have entered {0}", this);
  1169. }
  1170. public void InternalExit(Mobile m)
  1171. {
  1172. if (m.Player && m_Players.Contains(m))
  1173. {
  1174. m_Players.Remove(m);
  1175. OnPlayerRemove(m);
  1176. }
  1177. if (m_Mobiles.Contains(m))
  1178. {
  1179. m_Mobiles.Remove(m);
  1180. OnMobileRemove(m);
  1181. }
  1182. OnExit(m);
  1183. StopMusic(m);
  1184. }
  1185. public virtual void OnExit(Mobile m)
  1186. {
  1187. string s = ToString();
  1188. if (s != "")
  1189. m.SendMessage("You have left {0}", this);
  1190. }
  1191. public virtual bool OnTarget(Mobile m, Target t, object o)
  1192. {
  1193. return true;
  1194. }
  1195. public virtual bool OnCombatantChange(Mobile m, Mobile Old, Mobile New)
  1196. {
  1197. return true;
  1198. }
  1199. public virtual bool AllowHousing(Mobile from, Point3D p)
  1200. {
  1201. return true;
  1202. }
  1203. public virtual bool SendInaccessibleMessage(Item item, Mobile from)
  1204. {
  1205. return false;
  1206. }
  1207. public virtual bool CheckAccessibility(Item item, Mobile from)
  1208. {
  1209. return true;
  1210. }
  1211. public virtual bool OnDecay(Item item)
  1212. {
  1213. return true;
  1214. }
  1215. public virtual bool AllowHarmful(Mobile from, Mobile target)
  1216. {
  1217. if (Mobile.AllowHarmfulHandler != null)
  1218. return Mobile.AllowHarmfulHandler(from, target);
  1219. return true;
  1220. /*if ( (Map.Rules & MapRules.HarmfulRestrictions) != 0 )
  1221. return false;
  1222. else
  1223. return true;*/
  1224. }
  1225. public virtual void OnCriminalAction(Mobile m, bool message)
  1226. {
  1227. if (message)
  1228. m.SendLocalizedMessage(1005040); // You've committed a criminal act!!
  1229. }
  1230. public virtual bool AllowBenificial(Mobile from, Mobile target)
  1231. {
  1232. if (Mobile.AllowBeneficialHandler != null)
  1233. return Mobile.AllowBeneficialHandler(from, target);
  1234. return true;
  1235. /*if ( (Map.Rules & MapRules.BeneficialRestrictions) != 0 )
  1236. {
  1237. int n = Notoriety.Compute( from, target );
  1238. if (n == Notoriety.Criminal || n == Notoriety.Murderer)
  1239. {
  1240. return false;
  1241. }
  1242. else if ( target.Guild != null && target.Guild.Type != Guilds.GuildType.Regular )//disallow Chaos/order for healing each other or being healed by blues
  1243. {
  1244. if ( from.Guild == null || from.Guild.Type != target.Guild.Type )
  1245. return false;
  1246. }
  1247. }
  1248. return true;*/
  1249. }
  1250. public virtual void OnBenificialAction(Mobile helper, Mobile target)
  1251. {
  1252. }
  1253. public virtual void OnGotBenificialAction(Mobile helper, Mobile target)
  1254. {
  1255. }
  1256. public virtual bool IsInInn(Point3D p)
  1257. {
  1258. if (m_InnBounds == null)
  1259. return false;
  1260. for (int i = 0; i < m_InnBounds.Count; ++i)
  1261. {
  1262. Rectangle2D rect = (Rectangle2D)m_InnBounds[i];
  1263. if (rect.Contains(p))
  1264. return true;
  1265. }
  1266. return false;
  1267. }
  1268. private static TimeSpan m_InnLogoutDelay = TimeSpan.Zero;
  1269. private static TimeSpan m_GMLogoutDelay = TimeSpan.FromSeconds(10.0);
  1270. private static TimeSpan m_DefaultLogoutDelay = TimeSpan.FromMinutes(5.0);
  1271. public static TimeSpan InnLogoutDelay
  1272. {
  1273. get { return m_InnLogoutDelay; }
  1274. set { m_InnLogoutDelay = value; }
  1275. }
  1276. public static TimeSpan GMLogoutDelay
  1277. {
  1278. get { return m_GMLogoutDelay; }
  1279. set { m_GMLogoutDelay = value; }
  1280. }
  1281. public static TimeSpan DefaultLogoutDelay
  1282. {
  1283. get { return m_DefaultLogoutDelay; }
  1284. set { m_DefaultLogoutDelay = value; }
  1285. }
  1286. public virtual TimeSpan GetLogoutDelay(Mobile m)
  1287. {
  1288. if (m.Aggressors.Count == 0 && m.Aggressed.Count == 0 && IsInInn(m.Location))
  1289. return m_InnLogoutDelay;
  1290. else if (m.AccessLevel >= AccessLevel.GameMaster)
  1291. return m_GMLogoutDelay;
  1292. else
  1293. return m_DefaultLogoutDelay;
  1294. }
  1295. public virtual void AlterLightLevel(Mobile m, ref int global, ref int personal)
  1296. {
  1297. }
  1298. /*public virtual double LightLevel( Mobile m, double level )
  1299. {
  1300. return level;
  1301. }*/
  1302. public virtual void SpellDamageScalar(Mobile caster, Mobile target, ref double damage)
  1303. {
  1304. }
  1305. public virtual void OnSpeech(SpeechEventArgs args)
  1306. {
  1307. }
  1308. public virtual bool AllowSpawn()
  1309. {
  1310. return true;
  1311. }
  1312. public virtual bool OnSkillUse(Mobile m, int Skill)
  1313. {
  1314. return true;
  1315. }
  1316. public virtual bool OnBeginSpellCast(Mobile m, ISpell s)
  1317. {
  1318. return true;
  1319. }
  1320. public virtual void OnSpellCast(Mobile m, ISpell s)
  1321. {
  1322. }
  1323. public virtual bool OnResurrect(Mobile m)
  1324. {
  1325. return true;
  1326. }
  1327. public virtual bool OnDeath(Mobile m)
  1328. {
  1329. return true;
  1330. }
  1331. public virtual bool OnDamage(Mobile m, ref int Damage)
  1332. {
  1333. return true;
  1334. }
  1335. public virtual bool OnHeal(Mobile m, ref int Heal)
  1336. {
  1337. return true;
  1338. }
  1339. public virtual bool OnDoubleClick(Mobile m, object o)
  1340. {
  1341. return true;
  1342. }
  1343. public virtual bool OnSingleClick(Mobile m, object o)
  1344. {
  1345. return true;
  1346. }
  1347. //Should this region be loaded from the xml?
  1348. public bool LoadFromXml
  1349. {
  1350. get
  1351. {
  1352. return m_Load;
  1353. }
  1354. set
  1355. {
  1356. m_Load = value;
  1357. }
  1358. }
  1359. //does this region save?
  1360. public virtual bool Saves
  1361. {
  1362. get
  1363. {
  1364. return false;
  1365. }
  1366. }
  1367. public List<Mobile> Mobiles
  1368. {
  1369. get
  1370. {
  1371. return m_Mobiles;
  1372. }
  1373. }
  1374. public List<Mobile> Players
  1375. {
  1376. get
  1377. {
  1378. return m_Players;
  1379. }
  1380. }
  1381. public string Name
  1382. {
  1383. get
  1384. {
  1385. return m_Name;
  1386. }
  1387. set
  1388. {
  1389. m_Name = value;
  1390. }
  1391. }
  1392. public string Prefix
  1393. {
  1394. get
  1395. {
  1396. return m_Prefix;
  1397. }
  1398. set
  1399. {
  1400. m_Prefix = value;
  1401. }
  1402. }
  1403. public MusicName Music
  1404. {
  1405. get { return m_Music; }
  1406. set { m_Music = value; }
  1407. }
  1408. public Point3D GoLocation
  1409. {
  1410. get
  1411. {
  1412. return m_GoLoc;
  1413. }
  1414. set
  1415. {
  1416. m_GoLoc = value;
  1417. }
  1418. }
  1419. public Map Map
  1420. {
  1421. get
  1422. {
  1423. return m_Map;
  1424. }
  1425. set
  1426. {
  1427. RemoveRegion(this);
  1428. m_Map = value;
  1429. AddRegion(this);
  1430. }
  1431. }
  1432. public ArrayList InnBounds
  1433. {
  1434. get { return m_InnBounds; }
  1435. set { m_InnBounds = value; }
  1436. }
  1437. private ArrayList m_LoadCoords;
  1438. public ArrayList Coords
  1439. {
  1440. get
  1441. {
  1442. return m_Coords;
  1443. }
  1444. set
  1445. {
  1446. if (m_Coords != value)
  1447. {
  1448. RemoveRegion(this);
  1449. m_Coords = value;
  1450. AddRegion(this);
  1451. }
  1452. }
  1453. }
  1454. public int Priority
  1455. {
  1456. get
  1457. {
  1458. return m_Priority;
  1459. }
  1460. set
  1461. {
  1462. if (value != m_Priority)
  1463. {
  1464. m_Priority = value;
  1465. /*if ( m_Priority < Region.LowestPriority ) m_Priority = Region.LowestPriority;
  1466. else if ( m_Priority > Region.HighestPriority ) m_Priority = Region.HighestPriority;*/
  1467. m_Map.Regions.Sort();
  1468. }
  1469. }
  1470. }
  1471. public int UId
  1472. {
  1473. get
  1474. {
  1475. return m_UId;
  1476. }
  1477. }
  1478. private int m_MinZ = short.MinValue;
  1479. private int m_MaxZ = short.MaxValue;
  1480. public int MinZ { get { return m_MinZ; } set { RemoveRegion(this); m_MinZ = value; AddRegion(this); } }
  1481. public int MaxZ { get { return m_MaxZ; } set { RemoveRegion(this); m_MaxZ = value; AddRegion(this); } }
  1482. public virtual bool Contains(Point3D p)
  1483. {//possibly use a binary search instead, to increase speed?
  1484. if (m_Coords == null)
  1485. return false;
  1486. for (int i = 0; i < m_Coords.Count; ++i)
  1487. {
  1488. object obj = m_Coords[i];
  1489. if (obj is Rectangle3D)
  1490. {
  1491. Rectangle3D r3d = (Rectangle3D)obj;
  1492. if (r3d.Contains(p))
  1493. return true;
  1494. }
  1495. else if (obj is Rectangle2D)
  1496. {
  1497. Rectangle2D r2d = (Rectangle2D)obj;
  1498. if (r2d.Contains(p) && p.m_Z >= m_MinZ && p.m_Z <= m_MaxZ)
  1499. return true;
  1500. }
  1501. }
  1502. return false;
  1503. }
  1504. public override string ToString()
  1505. {
  1506. if (Prefix != "")
  1507. return string.Format("{0} {1}", Prefix, Name);
  1508. else
  1509. return Name;
  1510. }
  1511. public static bool IsNull(Region r)
  1512. {
  1513. return Object.ReferenceEquals(r, null);
  1514. }
  1515. //high priorities first (high priority is less than low priority)
  1516. public static bool operator <(Region l, Region r)
  1517. {
  1518. if (IsNull(l) && IsNull(r))
  1519. return false;
  1520. else if (IsNull(l))
  1521. return true;
  1522. else if (IsNull(r))
  1523. return false;
  1524. return l.Priority > r.Priority;
  1525. }
  1526. public static bool operator >(Region l, Region r)
  1527. {
  1528. if (IsNull(l) && IsNull(r))
  1529. return false;
  1530. else if (IsNull(l))
  1531. return false;
  1532. else if (IsNull(r))
  1533. return true;
  1534. return l.Priority < r.Priority;
  1535. }
  1536. public static bool operator ==(Region l, Region r)
  1537. {

Large files files are truncated, but you can click here to view the full file