PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/CoreNew/Server/Map.cs

https://bitbucket.org/Kel/crepuscule
C# | 1850 lines | 1698 code | 152 blank | 0 comment | 360 complexity | 7ce87e8cc6af5b3766bdbd9c6ef7e760 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.Items;
  4. using Server.Network;
  5. using Server.Targeting;
  6. using System;
  7. using System.Collections;
  8. using System.Runtime.InteropServices;
  9. [Parsable]
  10. public sealed class Map
  11. {
  12. private static ArrayList m_AllMaps = new ArrayList();
  13. private Region m_DefaultRegion;
  14. private int m_FileIndex;
  15. private int m_Height;
  16. private static int[] m_InvalidLandTiles = new int[] { 580 };
  17. private Sector m_InvalidSector;
  18. private int m_MapID;
  19. private int m_MapIndex;
  20. private static string[] m_MapNames;
  21. private static Map[] m_Maps = new Map[0x100];
  22. private static Map[] m_MapValues;
  23. private static int m_MaxLOSDistance = 0x19;
  24. private string m_Name;
  25. private static Point3DList m_PathList = new Point3DList();
  26. private ArrayList m_Regions;
  27. private MapRules m_Rules;
  28. private int m_Season;
  29. private Sector[][] m_Sectors;
  30. private int m_SectorsHeight;
  31. private int m_SectorsWidth;
  32. private TileMatrix m_Tiles;
  33. private int m_Width;
  34. public static int SectorActiveRange = 2;
  35. public const int SectorShift = 4;
  36. public const int SectorSize = 0x10;
  37. public Map(int mapID, int mapIndex, int fileIndex, int width, int height, int season, string name, MapRules rules)
  38. {
  39. this.m_MapID = mapID;
  40. this.m_MapIndex = mapIndex;
  41. this.m_FileIndex = fileIndex;
  42. this.m_Width = width;
  43. this.m_Height = height;
  44. this.m_Season = season;
  45. this.m_Name = name;
  46. this.m_Rules = rules;
  47. this.m_Regions = new ArrayList();
  48. this.m_InvalidSector = new Sector(0, 0, this);
  49. this.m_SectorsWidth = width >> 4;
  50. this.m_SectorsHeight = height >> 4;
  51. this.m_Sectors = new Sector[this.m_SectorsWidth][];
  52. }
  53. public void ActivateSectors(int cx, int cy)
  54. {
  55. for (int i = cx - SectorActiveRange; i <= (cx + SectorActiveRange); i++)
  56. {
  57. for (int j = cy - SectorActiveRange; j <= (cy + SectorActiveRange); j++)
  58. {
  59. Sector realSector = this.GetRealSector(i, j);
  60. if (realSector != this.m_InvalidSector)
  61. {
  62. realSector.Activate();
  63. }
  64. }
  65. }
  66. }
  67. public void AddMulti(Item item, Sector start, Sector end)
  68. {
  69. if (this != Internal)
  70. {
  71. for (int i = start.X; i <= end.X; i++)
  72. {
  73. for (int j = start.Y; j <= end.Y; j++)
  74. {
  75. this.InternalGetSector(i, j).OnMultiEnter(item);
  76. }
  77. }
  78. }
  79. }
  80. public Point2D Bound(Point2D p)
  81. {
  82. int x = p.m_X;
  83. int y = p.m_Y;
  84. if (x < 0)
  85. {
  86. x = 0;
  87. }
  88. else if (x >= this.m_Width)
  89. {
  90. x = this.m_Width - 1;
  91. }
  92. if (y < 0)
  93. {
  94. y = 0;
  95. }
  96. else if (y >= this.m_Height)
  97. {
  98. y = this.m_Height - 1;
  99. }
  100. return new Point2D(x, y);
  101. }
  102. public void Bound(int x, int y, out int newX, out int newY)
  103. {
  104. if (x < 0)
  105. {
  106. newX = 0;
  107. }
  108. else if (x >= this.m_Width)
  109. {
  110. newX = this.m_Width - 1;
  111. }
  112. else
  113. {
  114. newX = x;
  115. }
  116. if (y < 0)
  117. {
  118. newY = 0;
  119. }
  120. else if (y >= this.m_Height)
  121. {
  122. newY = this.m_Height - 1;
  123. }
  124. else
  125. {
  126. newY = y;
  127. }
  128. }
  129. public bool CanFit(Point3D p, int height)
  130. {
  131. return this.CanFit(p.m_X, p.m_Y, p.m_Z, height, false, true, true);
  132. }
  133. public bool CanFit(Point2D p, int z, int height)
  134. {
  135. return this.CanFit(p.m_X, p.m_Y, z, height, false, true, true);
  136. }
  137. public bool CanFit(Point3D p, int height, bool checkBlocksFit)
  138. {
  139. return this.CanFit(p.m_X, p.m_Y, p.m_Z, height, checkBlocksFit, true, true);
  140. }
  141. public bool CanFit(Point2D p, int z, int height, bool checkBlocksFit)
  142. {
  143. return this.CanFit(p.m_X, p.m_Y, z, height, checkBlocksFit, true, true);
  144. }
  145. public bool CanFit(Point3D p, int height, bool checkBlocksFit, bool checkMobiles)
  146. {
  147. return this.CanFit(p.m_X, p.m_Y, p.m_Z, height, checkBlocksFit, checkMobiles, true);
  148. }
  149. public bool CanFit(int x, int y, int z, int height)
  150. {
  151. return this.CanFit(x, y, z, height, false, true, true);
  152. }
  153. public bool CanFit(int x, int y, int z, int height, bool checksBlocksFit)
  154. {
  155. return this.CanFit(x, y, z, height, false, true, true);
  156. }
  157. public bool CanFit(int x, int y, int z, int height, bool checkBlocksFit, bool checkMobiles)
  158. {
  159. return this.CanFit(x, y, z, height, checkBlocksFit, checkMobiles, true);
  160. }
  161. public bool CanFit(int x, int y, int z, int height, bool checkBlocksFit, bool checkMobiles, bool requireSurface)
  162. {
  163. bool surface;
  164. bool impassable;
  165. if (this == Internal)
  166. {
  167. return false;
  168. }
  169. if (((x < 0) || (y < 0)) || ((x >= this.m_Width) || (y >= this.m_Height)))
  170. {
  171. return false;
  172. }
  173. bool flag = false;
  174. Tile landTile = this.Tiles.GetLandTile(x, y);
  175. int num = 0;
  176. int avg = 0;
  177. int top = 0;
  178. this.GetAverageZ(x, y, ref num, ref avg, ref top);
  179. TileFlag flags = TileData.LandTable[landTile.ID & 0x3fff].Flags;
  180. if ((((flags & TileFlag.Impassable) != TileFlag.None) && (avg > z)) && ((z + height) > num))
  181. {
  182. return false;
  183. }
  184. if ((((flags & TileFlag.Impassable) == TileFlag.None) && (z == avg)) && !landTile.Ignored)
  185. {
  186. flag = true;
  187. }
  188. Tile[] tileArray = this.Tiles.GetStaticTiles(x, y, true);
  189. for (int i = 0; i < tileArray.Length; i++)
  190. {
  191. ItemData data = TileData.ItemTable[tileArray[i].ID & 0x3fff];
  192. surface = data.Surface;
  193. impassable = data.Impassable;
  194. if ((surface || impassable) && (((tileArray[i].Z + data.CalcHeight) > z) && ((z + height) > tileArray[i].Z)))
  195. {
  196. return false;
  197. }
  198. if ((surface && !impassable) && (z == (tileArray[i].Z + data.CalcHeight)))
  199. {
  200. flag = true;
  201. }
  202. }
  203. Sector sector = this.GetSector(x, y);
  204. ArrayList items = sector.Items;
  205. ArrayList mobiles = sector.Mobiles;
  206. for (int j = 0; j < items.Count; j++)
  207. {
  208. Item item = (Item) items[j];
  209. if ((item.ItemID < 0x4000) && item.AtWorldPoint(x, y))
  210. {
  211. ItemData itemData = item.ItemData;
  212. surface = itemData.Surface;
  213. impassable = itemData.Impassable;
  214. if (((surface || impassable) || (checkBlocksFit && item.BlocksFit)) && (((item.Z + itemData.CalcHeight) > z) && ((z + height) > item.Z)))
  215. {
  216. return false;
  217. }
  218. if ((surface && !impassable) && (z == (item.Z + itemData.CalcHeight)))
  219. {
  220. flag = true;
  221. }
  222. }
  223. }
  224. if (checkMobiles)
  225. {
  226. for (int k = 0; k < mobiles.Count; k++)
  227. {
  228. Mobile mobile = (Mobile) mobiles[k];
  229. if (((mobile.Location.m_X == x) && (mobile.Location.m_Y == y)) && (((mobile.Z + 0x10) > z) && ((z + height) > mobile.Z)))
  230. {
  231. return false;
  232. }
  233. }
  234. }
  235. if (requireSurface)
  236. {
  237. return flag;
  238. }
  239. return true;
  240. }
  241. public bool CanSpawnMobile(Point3D p)
  242. {
  243. return this.CanSpawnMobile(p.m_X, p.m_Y, p.m_Z);
  244. }
  245. public bool CanSpawnMobile(Point2D p, int z)
  246. {
  247. return this.CanSpawnMobile(p.m_X, p.m_Y, z);
  248. }
  249. public bool CanSpawnMobile(int x, int y, int z)
  250. {
  251. if (!Region.Find(new Point3D(x, y, z), this).AllowSpawn())
  252. {
  253. return false;
  254. }
  255. return this.CanFit(x, y, z, 0x10);
  256. }
  257. private static void CheckNamesAndValues()
  258. {
  259. if ((m_MapNames == null) || (m_MapNames.Length != m_AllMaps.Count))
  260. {
  261. m_MapNames = new string[m_AllMaps.Count];
  262. m_MapValues = new Map[m_AllMaps.Count];
  263. for (int i = 0; i < m_AllMaps.Count; i++)
  264. {
  265. Map map = (Map) m_AllMaps[i];
  266. m_MapNames[i] = map.Name;
  267. m_MapValues[i] = map;
  268. }
  269. }
  270. }
  271. public void DeactivateSectors(int cx, int cy)
  272. {
  273. for (int i = cx - SectorActiveRange; i <= (cx + SectorActiveRange); i++)
  274. {
  275. for (int j = cy - SectorActiveRange; j <= (cy + SectorActiveRange); j++)
  276. {
  277. Sector realSector = this.GetRealSector(i, j);
  278. if ((realSector != this.m_InvalidSector) && !this.PlayersInRange(realSector, SectorActiveRange))
  279. {
  280. realSector.Deactivate();
  281. }
  282. }
  283. }
  284. }
  285. public void FixColumn(int x, int y)
  286. {
  287. Tile landTile = this.Tiles.GetLandTile(x, y);
  288. int z = 0;
  289. int avg = 0;
  290. int top = 0;
  291. this.GetAverageZ(x, y, ref z, ref avg, ref top);
  292. Tile[] tileArray = this.Tiles.GetStaticTiles(x, y, true);
  293. ArrayList list = new ArrayList();
  294. IPooledEnumerable itemsInRange = this.GetItemsInRange(new Point3D(x, y, 0), 0);
  295. foreach (Item item in itemsInRange)
  296. {
  297. if (item.ItemID < 0x4000)
  298. {
  299. list.Add(item);
  300. if (list.Count > 100)
  301. {
  302. break;
  303. }
  304. }
  305. }
  306. itemsInRange.Free();
  307. if (list.Count <= 100)
  308. {
  309. list.Sort(ZComparer.Default);
  310. for (int i = 0; i < list.Count; i++)
  311. {
  312. Item item2 = (Item) list[i];
  313. if (item2.Movable)
  314. {
  315. int num5 = -2147483648;
  316. int num6 = item2.Z;
  317. if (!landTile.Ignored && (avg <= num6))
  318. {
  319. num5 = avg;
  320. }
  321. for (int j = 0; j < tileArray.Length; j++)
  322. {
  323. Tile tile2 = tileArray[j];
  324. ItemData data = TileData.ItemTable[tile2.ID & 0x3fff];
  325. int num8 = tile2.Z;
  326. int num9 = num8 + data.CalcHeight;
  327. if ((num9 == num8) && !data.Surface)
  328. {
  329. num9++;
  330. }
  331. if ((num9 > num5) && (num9 <= num6))
  332. {
  333. num5 = num9;
  334. }
  335. }
  336. for (int k = 0; k < list.Count; k++)
  337. {
  338. if (k != i)
  339. {
  340. Item item3 = (Item) list[k];
  341. ItemData itemData = item3.ItemData;
  342. int num11 = item3.Z;
  343. int num12 = num11 + itemData.CalcHeight;
  344. if ((num12 == num11) && !itemData.Surface)
  345. {
  346. num12++;
  347. }
  348. if ((num12 > num5) && (num12 <= num6))
  349. {
  350. num5 = num12;
  351. }
  352. }
  353. }
  354. if (num5 != -2147483648)
  355. {
  356. item2.Location = new Point3D(item2.X, item2.Y, num5);
  357. }
  358. }
  359. }
  360. }
  361. }
  362. public int GetAverageZ(int x, int y)
  363. {
  364. int z = 0;
  365. int avg = 0;
  366. int top = 0;
  367. this.GetAverageZ(x, y, ref z, ref avg, ref top);
  368. return avg;
  369. }
  370. public void GetAverageZ(int x, int y, ref int z, ref int avg, ref int top)
  371. {
  372. int num = this.Tiles.GetLandTile(x, y).Z;
  373. int num2 = this.Tiles.GetLandTile(x, y + 1).Z;
  374. int num3 = this.Tiles.GetLandTile(x + 1, y).Z;
  375. int num4 = this.Tiles.GetLandTile(x + 1, y + 1).Z;
  376. z = num;
  377. if (num2 < z)
  378. {
  379. z = num2;
  380. }
  381. if (num3 < z)
  382. {
  383. z = num3;
  384. }
  385. if (num4 < z)
  386. {
  387. z = num4;
  388. }
  389. top = num;
  390. if (num2 > top)
  391. {
  392. top = num2;
  393. }
  394. if (num3 > top)
  395. {
  396. top = num3;
  397. }
  398. if (num4 > top)
  399. {
  400. top = num4;
  401. }
  402. if (Math.Abs((int) (num - num4)) > Math.Abs((int) (num2 - num3)))
  403. {
  404. avg = (int) Math.Floor((double) (((double) (num2 + num3)) / 2.0));
  405. }
  406. else
  407. {
  408. avg = (int) Math.Floor((double) (((double) (num + num4)) / 2.0));
  409. }
  410. }
  411. public IPooledEnumerable GetClientsInBounds(Rectangle2D bounds)
  412. {
  413. if (this == Internal)
  414. {
  415. return NullEnumerable.Instance;
  416. }
  417. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, bounds, SectorEnumeratorType.Clients));
  418. }
  419. public IPooledEnumerable GetClientsInRange(Point3D p)
  420. {
  421. if (this == Internal)
  422. {
  423. return NullEnumerable.Instance;
  424. }
  425. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, new Rectangle2D(p.m_X - 0x12, p.m_Y - 0x12, 0x25, 0x25), SectorEnumeratorType.Clients));
  426. }
  427. public IPooledEnumerable GetClientsInRange(Point3D p, int range)
  428. {
  429. if (this == Internal)
  430. {
  431. return NullEnumerable.Instance;
  432. }
  433. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, (range * 2) + 1, (range * 2) + 1), SectorEnumeratorType.Clients));
  434. }
  435. public IPooledEnumerable GetItemsInBounds(Rectangle2D bounds)
  436. {
  437. if (this == Internal)
  438. {
  439. return NullEnumerable.Instance;
  440. }
  441. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, bounds, SectorEnumeratorType.Items));
  442. }
  443. public IPooledEnumerable GetItemsInRange(Point3D p)
  444. {
  445. if (this == Internal)
  446. {
  447. return NullEnumerable.Instance;
  448. }
  449. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, new Rectangle2D(p.m_X - 0x12, p.m_Y - 0x12, 0x25, 0x25), SectorEnumeratorType.Items));
  450. }
  451. public IPooledEnumerable GetItemsInRange(Point3D p, int range)
  452. {
  453. if (this == Internal)
  454. {
  455. return NullEnumerable.Instance;
  456. }
  457. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, (range * 2) + 1, (range * 2) + 1), SectorEnumeratorType.Items));
  458. }
  459. public static string[] GetMapNames()
  460. {
  461. CheckNamesAndValues();
  462. return m_MapNames;
  463. }
  464. public static Map[] GetMapValues()
  465. {
  466. CheckNamesAndValues();
  467. return m_MapValues;
  468. }
  469. public IPooledEnumerable GetMobilesInBounds(Rectangle2D bounds)
  470. {
  471. if (this == Internal)
  472. {
  473. return NullEnumerable.Instance;
  474. }
  475. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, bounds, SectorEnumeratorType.Mobiles));
  476. }
  477. public IPooledEnumerable GetMobilesInRange(Point3D p)
  478. {
  479. if (this == Internal)
  480. {
  481. return NullEnumerable.Instance;
  482. }
  483. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, new Rectangle2D(p.m_X - 0x12, p.m_Y - 0x12, 0x25, 0x25), SectorEnumeratorType.Mobiles));
  484. }
  485. public IPooledEnumerable GetMobilesInRange(Point3D p, int range)
  486. {
  487. if (this == Internal)
  488. {
  489. return NullEnumerable.Instance;
  490. }
  491. return PooledEnumerable.Instantiate(TypedEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, (range * 2) + 1, (range * 2) + 1), SectorEnumeratorType.Mobiles));
  492. }
  493. public Sector GetMultiMaxSector(Point3D loc, MultiComponentList mcl)
  494. {
  495. return this.GetSector(this.Bound(new Point2D(loc.m_X + mcl.Max.m_X, loc.m_Y + mcl.Max.m_Y)));
  496. }
  497. public Sector GetMultiMinSector(Point3D loc, MultiComponentList mcl)
  498. {
  499. return this.GetSector(this.Bound(new Point2D(loc.m_X + mcl.Min.m_X, loc.m_Y + mcl.Min.m_Y)));
  500. }
  501. public IPooledEnumerable GetMultiTilesAt(int x, int y)
  502. {
  503. if (this == Internal)
  504. {
  505. return NullEnumerable.Instance;
  506. }
  507. Sector sector = this.GetSector(x, y);
  508. if (sector.Multis.Count == 0)
  509. {
  510. return NullEnumerable.Instance;
  511. }
  512. return PooledEnumerable.Instantiate(MultiTileEnumerator.Instantiate(sector, new Point2D(x, y)));
  513. }
  514. public IPooledEnumerable GetObjectsInBounds(Rectangle2D bounds)
  515. {
  516. if (this == Internal)
  517. {
  518. return NullEnumerable.Instance;
  519. }
  520. return PooledEnumerable.Instantiate(ObjectEnumerator.Instantiate(this, bounds));
  521. }
  522. public IPooledEnumerable GetObjectsInRange(Point3D p)
  523. {
  524. if (this == Internal)
  525. {
  526. return NullEnumerable.Instance;
  527. }
  528. return PooledEnumerable.Instantiate(ObjectEnumerator.Instantiate(this, new Rectangle2D(p.m_X - 0x12, p.m_Y - 0x12, 0x25, 0x25)));
  529. }
  530. public IPooledEnumerable GetObjectsInRange(Point3D p, int range)
  531. {
  532. if (this == Internal)
  533. {
  534. return NullEnumerable.Instance;
  535. }
  536. return PooledEnumerable.Instantiate(ObjectEnumerator.Instantiate(this, new Rectangle2D(p.m_X - range, p.m_Y - range, (range * 2) + 1, (range * 2) + 1)));
  537. }
  538. public Point3D GetPoint(object o, bool eye)
  539. {
  540. Point3D location;
  541. if (o is Mobile)
  542. {
  543. location = ((Mobile) o).Location;
  544. location.Z += eye ? 15 : 10;
  545. return location;
  546. }
  547. if (o is Item)
  548. {
  549. location = ((Item) o).GetWorldLocation();
  550. location.Z += (((Item) o).ItemData.Height / 2) + 1;
  551. return location;
  552. }
  553. if (o is Point3D)
  554. {
  555. return (Point3D) o;
  556. }
  557. if (o is LandTarget)
  558. {
  559. location = ((LandTarget) o).Location;
  560. int z = 0;
  561. int avg = 0;
  562. int top = 0;
  563. this.GetAverageZ(location.X, location.Y, ref z, ref avg, ref top);
  564. location.Z = top + 1;
  565. return location;
  566. }
  567. if (o is StaticTarget)
  568. {
  569. StaticTarget target = (StaticTarget) o;
  570. ItemData data = TileData.ItemTable[target.ItemID & 0x3fff];
  571. return new Point3D(target.X, target.Y, ((target.Z - data.CalcHeight) + (data.Height / 2)) + 1);
  572. }
  573. if (o is IPoint3D)
  574. {
  575. return new Point3D((IPoint3D) o);
  576. }
  577. Console.WriteLine("Warning: Invalid object ({0}) in line of sight", o);
  578. return Point3D.Zero;
  579. }
  580. public Sector GetRealSector(int x, int y)
  581. {
  582. return this.InternalGetSector(x, y);
  583. }
  584. public Sector GetSector(IPoint2D p)
  585. {
  586. return this.InternalGetSector(p.X >> 4, p.Y >> 4);
  587. }
  588. public Sector GetSector(Point2D p)
  589. {
  590. return this.InternalGetSector(p.m_X >> 4, p.m_Y >> 4);
  591. }
  592. public Sector GetSector(Point3D p)
  593. {
  594. return this.InternalGetSector(p.m_X >> 4, p.m_Y >> 4);
  595. }
  596. public Sector GetSector(int x, int y)
  597. {
  598. return this.InternalGetSector(x >> 4, y >> 4);
  599. }
  600. public ArrayList GetTilesAt(Point2D p, bool items, bool land, bool statics)
  601. {
  602. ArrayList list = new ArrayList();
  603. if (this != Internal)
  604. {
  605. if (land)
  606. {
  607. list.Add(this.Tiles.GetLandTile(p.m_X, p.m_Y));
  608. }
  609. if (statics)
  610. {
  611. list.AddRange(this.Tiles.GetStaticTiles(p.m_X, p.m_Y, true));
  612. }
  613. if (!items)
  614. {
  615. return list;
  616. }
  617. foreach (Item item in this.GetSector(p).Items)
  618. {
  619. if (item.AtWorldPoint(p.m_X, p.m_Y))
  620. {
  621. list.Add(new Tile((short) ((item.ItemID & 0x3fff) + 0x4000), (sbyte) item.Z));
  622. }
  623. }
  624. }
  625. return list;
  626. }
  627. private Sector InternalGetSector(int x, int y)
  628. {
  629. if (((x < 0) || (x >= this.m_SectorsWidth)) || ((y < 0) || (y >= this.m_SectorsHeight)))
  630. {
  631. return this.m_InvalidSector;
  632. }
  633. Sector[] sectorArray = this.m_Sectors[x];
  634. if (sectorArray == null)
  635. {
  636. this.m_Sectors[x] = sectorArray = new Sector[this.m_SectorsHeight];
  637. }
  638. Sector sector = sectorArray[y];
  639. if (sector == null)
  640. {
  641. sectorArray[y] = sector = new Sector(x, y, this);
  642. }
  643. return sector;
  644. }
  645. public bool LineOfSight(Mobile from, Mobile to)
  646. {
  647. if ((from == to) || (from.AccessLevel > AccessLevel.Player))
  648. {
  649. return true;
  650. }
  651. Point3D location = from.Location;
  652. Point3D dest = to.Location;
  653. location.Z += 14;
  654. dest.Z += 10;
  655. return this.LineOfSight(location, dest);
  656. }
  657. public bool LineOfSight(Mobile from, Point3D target)
  658. {
  659. if (from.AccessLevel > AccessLevel.Player)
  660. {
  661. return true;
  662. }
  663. Point3D location = from.Location;
  664. location.Z += 14;
  665. return this.LineOfSight(location, target);
  666. }
  667. public bool LineOfSight(Point3D org, Point3D dest)
  668. {
  669. if (this == Internal)
  670. {
  671. return false;
  672. }
  673. if (!Utility.InRange(org, dest, m_MaxLOSDistance))
  674. {
  675. return false;
  676. }
  677. Point3DList pathList = m_PathList;
  678. if (org != dest)
  679. {
  680. double num4;
  681. if (pathList.Count > 0)
  682. {
  683. pathList.Clear();
  684. }
  685. int num8 = dest.m_X - org.m_X;
  686. int num9 = dest.m_Y - org.m_Y;
  687. int num10 = dest.m_Z - org.m_Z;
  688. double num3 = Math.Sqrt((double) ((num8 * num8) + (num9 * num9)));
  689. if (num10 != 0)
  690. {
  691. num4 = Math.Sqrt((num3 * num3) + (num10 * num10));
  692. }
  693. else
  694. {
  695. num4 = num3;
  696. }
  697. double num = ((double) num9) / num4;
  698. double num2 = ((double) num8) / num4;
  699. num3 = ((double) num10) / num4;
  700. double y = org.m_Y;
  701. double z = org.m_Z;
  702. double x = org.m_X;
  703. while ((Utility.NumberBetween(x, dest.m_X, org.m_X, 0.5) && Utility.NumberBetween(y, dest.m_Y, org.m_Y, 0.5)) && Utility.NumberBetween(z, dest.m_Z, org.m_Z, 0.5))
  704. {
  705. int num11 = (int) Math.Round(x);
  706. int num12 = (int) Math.Round(y);
  707. int num13 = (int) Math.Round(z);
  708. if (pathList.Count > 0)
  709. {
  710. Point3D last = pathList.Last;
  711. if (((last.m_X != num11) || (last.m_Y != num12)) || (last.m_Z != num13))
  712. {
  713. pathList.Add(num11, num12, num13);
  714. }
  715. }
  716. else
  717. {
  718. pathList.Add(num11, num12, num13);
  719. }
  720. x += num2;
  721. y += num;
  722. z += num3;
  723. }
  724. if (pathList.Count != 0)
  725. {
  726. int calcHeight;
  727. if (pathList.Last != dest)
  728. {
  729. pathList.Add(dest);
  730. }
  731. Point3D top = org;
  732. Point3D bottom = dest;
  733. Utility.FixPoints(ref top, ref bottom);
  734. int count = pathList.Count;
  735. for (int i = 0; i < count; i++)
  736. {
  737. Point3D p = pathList[i];
  738. Tile landTile = this.Tiles.GetLandTile(p.X, p.Y);
  739. int num17 = 0;
  740. int avg = 0;
  741. int num19 = 0;
  742. this.GetAverageZ(p.m_X, p.m_Y, ref num17, ref avg, ref num19);
  743. if ((((num17 <= p.m_Z) && (num19 >= p.m_Z)) && (((p.m_X != dest.m_X) || (p.m_Y != dest.m_Y)) || ((num17 > dest.m_Z) || (num19 < dest.m_Z)))) && !landTile.Ignored)
  744. {
  745. return false;
  746. }
  747. Tile[] tileArray = this.Tiles.GetStaticTiles(p.m_X, p.m_Y, true);
  748. bool flag3 = false;
  749. int iD = landTile.ID;
  750. for (int j = 0; !flag3 && (j < m_InvalidLandTiles.Length); j++)
  751. {
  752. flag3 = iD == m_InvalidLandTiles[j];
  753. }
  754. if (flag3 && (tileArray.Length == 0))
  755. {
  756. IPooledEnumerable itemsInRange = this.GetItemsInRange(p, 0);
  757. foreach (Item item in itemsInRange)
  758. {
  759. if (item.Visible)
  760. {
  761. flag3 = false;
  762. }
  763. if (!flag3)
  764. {
  765. break;
  766. }
  767. }
  768. itemsInRange.Free();
  769. if (flag3)
  770. {
  771. return false;
  772. }
  773. }
  774. for (int k = 0; k < tileArray.Length; k++)
  775. {
  776. Tile tile2 = tileArray[k];
  777. ItemData data = TileData.ItemTable[tile2.ID & 0x3fff];
  778. TileFlag flags = data.Flags;
  779. calcHeight = data.CalcHeight;
  780. if ((((tile2.Z <= p.Z) && ((tile2.Z + calcHeight) >= p.Z)) && ((flags & (TileFlag.NoShoot | TileFlag.Window)) != TileFlag.None)) && (((p.m_X != dest.m_X) || (p.m_Y != dest.m_Y)) || ((tile2.Z > dest.m_Z) || ((tile2.Z + calcHeight) < dest.m_Z))))
  781. {
  782. return false;
  783. }
  784. }
  785. }
  786. Rectangle2D bounds = new Rectangle2D(top.m_X, top.m_Y, (bottom.m_X - top.m_X) + 1, (bottom.m_Y - top.m_Y) + 1);
  787. IPooledEnumerable itemsInBounds = this.GetItemsInBounds(bounds);
  788. foreach (Item item2 in itemsInBounds)
  789. {
  790. if (!item2.Visible || (item2.ItemID >= 0x4000))
  791. {
  792. continue;
  793. }
  794. ItemData itemData = item2.ItemData;
  795. if ((itemData.Flags & (TileFlag.NoShoot | TileFlag.Window)) != TileFlag.None)
  796. {
  797. calcHeight = itemData.CalcHeight;
  798. bool flag = false;
  799. int num23 = pathList.Count;
  800. for (int m = 0; m < num23; m++)
  801. {
  802. Point3D pointd5 = pathList[m];
  803. Point3D location = item2.Location;
  804. if ((((location.m_X == pointd5.m_X) && (location.m_Y == pointd5.m_Y)) && ((location.m_Z <= pointd5.m_Z) && ((location.m_Z + calcHeight) >= pointd5.m_Z))) && (((location.m_X != dest.m_X) || (location.m_Y != dest.m_Y)) || ((location.m_Z > dest.m_Z) || ((location.m_Z + calcHeight) < dest.m_Z))))
  805. {
  806. flag = true;
  807. break;
  808. }
  809. }
  810. if (flag)
  811. {
  812. itemsInBounds.Free();
  813. return false;
  814. }
  815. }
  816. }
  817. itemsInBounds.Free();
  818. }
  819. }
  820. return true;
  821. }
  822. public bool LineOfSight(object from, object dest)
  823. {
  824. return (((from == dest) || ((from is Mobile) && (((Mobile) from).AccessLevel > AccessLevel.Player))) || ((((dest is Item) && (from is Mobile)) && (((Item) dest).RootParent == from)) || this.LineOfSight(this.GetPoint(from, true), this.GetPoint(dest, false))));
  825. }
  826. public void OnClientChange(NetState oldState, NetState newState, Mobile m)
  827. {
  828. if (this != Internal)
  829. {
  830. this.GetSector(m).OnClientChange(oldState, newState);
  831. }
  832. }
  833. public void OnEnter(Item item)
  834. {
  835. if (this != Internal)
  836. {
  837. this.GetSector(item).OnEnter(item);
  838. if (item is BaseMulti)
  839. {
  840. MultiComponentList components = ((BaseMulti) item).Components;
  841. Sector multiMinSector = this.GetMultiMinSector(item.Location, components);
  842. Sector multiMaxSector = this.GetMultiMaxSector(item.Location, components);
  843. this.AddMulti(item, multiMinSector, multiMaxSector);
  844. }
  845. }
  846. }
  847. public void OnEnter(Mobile m)
  848. {
  849. if (this != Internal)
  850. {
  851. this.GetSector(m).OnEnter(m);
  852. }
  853. }
  854. public void OnLeave(Item item)
  855. {
  856. if (this != Internal)
  857. {
  858. this.GetSector(item).OnLeave(item);
  859. if (item is BaseMulti)
  860. {
  861. MultiComponentList components = ((BaseMulti) item).Components;
  862. Sector multiMinSector = this.GetMultiMinSector(item.Location, components);
  863. Sector multiMaxSector = this.GetMultiMaxSector(item.Location, components);
  864. this.RemoveMulti(item, multiMinSector, multiMaxSector);
  865. }
  866. }
  867. }
  868. public void OnLeave(Mobile m)
  869. {
  870. if (this != Internal)
  871. {
  872. this.GetSector(m).OnLeave(m);
  873. }
  874. }
  875. public void OnMove(Point3D oldLocation, Item item)
  876. {
  877. if (this != Internal)
  878. {
  879. Sector sector = this.GetSector(oldLocation);
  880. Sector sector2 = this.GetSector(item.Location);
  881. if (sector != sector2)
  882. {
  883. sector.OnLeave(item);
  884. sector2.OnEnter(item);
  885. }
  886. if (item is BaseMulti)
  887. {
  888. MultiComponentList components = ((BaseMulti) item).Components;
  889. Sector multiMinSector = this.GetMultiMinSector(item.Location, components);
  890. Sector multiMaxSector = this.GetMultiMaxSector(item.Location, components);
  891. Sector start = this.GetMultiMinSector(oldLocation, components);
  892. Sector end = this.GetMultiMaxSector(oldLocation, components);
  893. if ((start != multiMinSector) || (end != multiMaxSector))
  894. {
  895. this.RemoveMulti(item, start, end);
  896. this.AddMulti(item, multiMinSector, multiMaxSector);
  897. }
  898. }
  899. }
  900. }
  901. public void OnMove(Point3D oldLocation, Mobile m)
  902. {
  903. if (this != Internal)
  904. {
  905. Sector sector = this.GetSector(oldLocation);
  906. Sector sector2 = this.GetSector(m.Location);
  907. if (sector != sector2)
  908. {
  909. sector.OnLeave(m);
  910. sector2.OnEnter(m);
  911. }
  912. }
  913. }
  914. public static Map Parse(string value)
  915. {
  916. CheckNamesAndValues();
  917. for (int i = 0; i < m_MapNames.Length; i++)
  918. {
  919. if (Insensitive.Equals(m_MapNames[i], value))
  920. {
  921. return m_MapValues[i];
  922. }
  923. }
  924. try
  925. {
  926. int index = int.Parse(value);
  927. if (((index >= 0) && (index < m_Maps.Length)) && (m_Maps[index] != null))
  928. {
  929. return m_Maps[index];
  930. }
  931. }
  932. catch
  933. {
  934. }
  935. throw new Exception("Invalid map name");
  936. }
  937. private bool PlayersInRange(Sector sect, int range)
  938. {
  939. for (int i = sect.X - range; i <= (sect.X + range); i++)
  940. {
  941. for (int j = sect.Y - range; j <= (sect.Y + range); j++)
  942. {
  943. Sector realSector = this.GetRealSector(i, j);
  944. if ((realSector != this.m_InvalidSector) && (realSector.Players.Count > 0))
  945. {
  946. return true;
  947. }
  948. }
  949. }
  950. return false;
  951. }
  952. public void RemoveMulti(Item item, Sector start, Sector end)
  953. {
  954. if (this != Internal)
  955. {
  956. for (int i = start.X; i <= end.X; i++)
  957. {
  958. for (int j = start.Y; j <= end.Y; j++)
  959. {
  960. this.InternalGetSector(i, j).OnMultiLeave(item);
  961. }
  962. }
  963. }
  964. }
  965. public override string ToString()
  966. {
  967. return this.m_Name;
  968. }
  969. public static ArrayList AllMaps
  970. {
  971. get
  972. {
  973. return m_AllMaps;
  974. }
  975. }
  976. public Region DefaultRegion
  977. {
  978. get
  979. {
  980. if (this.m_DefaultRegion == null)
  981. {
  982. this.m_DefaultRegion = new Region("", "", this);
  983. }
  984. return this.m_DefaultRegion;
  985. }
  986. set
  987. {
  988. this.m_DefaultRegion = value;
  989. }
  990. }
  991. public static Map Felucca
  992. {
  993. get
  994. {
  995. return m_Maps[0];
  996. }
  997. }
  998. public int Height
  999. {
  1000. get
  1001. {
  1002. return this.m_Height;
  1003. }
  1004. }
  1005. public static Map Ilshenar
  1006. {
  1007. get
  1008. {
  1009. return m_Maps[2];
  1010. }
  1011. }
  1012. public static Map Internal
  1013. {
  1014. get
  1015. {
  1016. return m_Maps[0x7f];
  1017. }
  1018. }
  1019. public static int[] InvalidLandTiles
  1020. {
  1021. get
  1022. {
  1023. return m_InvalidLandTiles;
  1024. }
  1025. set
  1026. {
  1027. m_InvalidLandTiles = value;
  1028. }
  1029. }
  1030. public Sector InvalidSector
  1031. {
  1032. get
  1033. {
  1034. return this.m_InvalidSector;
  1035. }
  1036. }
  1037. public static Map Malas
  1038. {
  1039. get
  1040. {
  1041. return m_Maps[3];
  1042. }
  1043. }
  1044. public int MapID
  1045. {
  1046. get
  1047. {
  1048. return this.m_MapID;
  1049. }
  1050. }
  1051. public int MapIndex
  1052. {
  1053. get
  1054. {
  1055. return this.m_MapIndex;
  1056. }
  1057. }
  1058. public static Map[] Maps
  1059. {
  1060. get
  1061. {
  1062. return m_Maps;
  1063. }
  1064. }
  1065. public static int MaxLOSDistance
  1066. {
  1067. get
  1068. {
  1069. return m_MaxLOSDistance;
  1070. }
  1071. set
  1072. {
  1073. m_MaxLOSDistance = value;
  1074. }
  1075. }
  1076. public string Name
  1077. {
  1078. get
  1079. {
  1080. return this.m_Name;
  1081. }
  1082. set
  1083. {
  1084. this.m_Name = value;
  1085. }
  1086. }
  1087. public ArrayList Regions
  1088. {
  1089. get
  1090. {
  1091. return this.m_Regions;
  1092. }
  1093. }
  1094. public MapRules Rules
  1095. {
  1096. get
  1097. {
  1098. return this.m_Rules;
  1099. }
  1100. set
  1101. {
  1102. this.m_Rules = value;
  1103. }
  1104. }
  1105. public int Season
  1106. {
  1107. get
  1108. {
  1109. return this.m_Season;
  1110. }
  1111. set
  1112. {
  1113. this.m_Season = value;
  1114. }
  1115. }
  1116. public TileMatrix Tiles
  1117. {
  1118. get
  1119. {
  1120. if (this.m_Tiles == null)
  1121. {
  1122. this.m_Tiles = new TileMatrix(this, this.m_FileIndex, this.m_MapID, this.m_Width, this.m_Height);
  1123. }
  1124. return this.m_Tiles;
  1125. }
  1126. }
  1127. public static Map Trammel
  1128. {
  1129. get
  1130. {
  1131. return m_Maps[1];
  1132. }
  1133. }
  1134. public int Width
  1135. {
  1136. get
  1137. {
  1138. return this.m_Width;
  1139. }
  1140. }
  1141. private class MultiTileEnumerator : IPooledEnumerator, IEnumerator, IDisposable
  1142. {
  1143. private object m_Current;
  1144. private IPooledEnumerable m_Enumerable;
  1145. private int m_Index;
  1146. private static Queue m_InstancePool = new Queue();
  1147. private ArrayList m_List;
  1148. private Point2D m_Location;
  1149. private MultiTileEnumerator(Sector sector, Point2D loc)
  1150. {
  1151. this.m_List = sector.Multis;
  1152. this.m_Location = loc;
  1153. this.Reset();
  1154. }
  1155. public void Dispose()
  1156. {
  1157. this.Free();
  1158. }
  1159. public void Free()
  1160. {
  1161. if (this.m_List != null)
  1162. {
  1163. m_InstancePool.Enqueue(this);
  1164. this.m_List = null;
  1165. if (this.m_Enumerable != null)
  1166. {
  1167. this.m_Enumerable.Free();
  1168. }
  1169. }
  1170. }
  1171. public static Map.MultiTileEnumerator Instantiate(Sector sector, Point2D loc)
  1172. {
  1173. if (m_InstancePool.Count > 0)
  1174. {
  1175. Map.MultiTileEnumerator enumerator = (Map.MultiTileEnumerator) m_InstancePool.Dequeue();
  1176. enumerator.m_List = sector.Multis;
  1177. enumerator.m_Location = loc;
  1178. enumerator.Reset();
  1179. return enumerator;
  1180. }
  1181. return new Map.MultiTileEnumerator(sector, loc);
  1182. }
  1183. public bool MoveNext()
  1184. {
  1185. while (++this.m_Index < this.m_List.Count)
  1186. {
  1187. BaseMulti multi = this.m_List[this.m_Index] as BaseMulti;
  1188. if ((multi != null) && !multi.Deleted)
  1189. {
  1190. MultiComponentList components = multi.Components;
  1191. int index = this.m_Location.m_X - (multi.Location.m_X + components.Min.m_X);
  1192. int num2 = this.m_Location.m_Y - (multi.Location.m_Y + components.Min.m_Y);
  1193. if (((index >= 0) && (index < components.Width)) && ((num2 >= 0) && (num2 < components.Height)))
  1194. {
  1195. Tile[] tileArray = components.Tiles[index][num2];
  1196. if (tileArray.Length > 0)
  1197. {
  1198. Tile[] tileArray2 = new Tile[tileArray.Length];
  1199. for (int i = 0; i < tileArray2.Length; i++)
  1200. {
  1201. tileArray2[i] = tileArray[i];
  1202. tileArray2[i].Z += multi.Z;
  1203. }
  1204. this.m_Current = tileArray2;
  1205. return true;
  1206. }
  1207. }
  1208. }
  1209. }
  1210. return false;
  1211. }
  1212. public void Reset()
  1213. {
  1214. this.m_Current = null;
  1215. this.m_Index = -1;
  1216. }
  1217. public object Current
  1218. {
  1219. get
  1220. {
  1221. return this.m_Current;
  1222. }
  1223. }
  1224. public IPooledEnumerable Enumerable
  1225. {
  1226. get
  1227. {
  1228. return this.m_Enumerable;
  1229. }
  1230. set
  1231. {
  1232. this.m_Enumerable = value;
  1233. }
  1234. }
  1235. }
  1236. public class NullEnumerable : IPooledEnumerable, IEnumerable
  1237. {
  1238. public static readonly Map.NullEnumerable Instance = new Map.NullEnumerable();
  1239. private InternalEnumerator m_Enumerator = new InternalEnumerator();
  1240. private NullEnumerable()
  1241. {
  1242. }
  1243. public void Free()
  1244. {
  1245. }
  1246. public IEnumerator GetEnumerator()
  1247. {
  1248. return this.m_Enumerator;
  1249. }
  1250. private class InternalEnumerator : IEnumerator
  1251. {
  1252. public bool MoveNext()
  1253. {
  1254. return false;
  1255. }
  1256. public void Reset()
  1257. {
  1258. }
  1259. public object Current
  1260. {
  1261. get
  1262. {
  1263. return null;
  1264. }
  1265. }
  1266. }
  1267. }
  1268. private class ObjectEnumerator : IPooledEnumerator, IEnumerator, IDisposable
  1269. {
  1270. private Rectangle2D m_Bounds;
  1271. private object m_Current;
  1272. private IPooledEnumerable m_Enumerable;
  1273. private Map.SectorEnumerator m_Enumerator;
  1274. private static Queue m_InstancePool = new Queue();
  1275. private Map m_Map;
  1276. private int m_Stage;
  1277. private ObjectEnumerator(Map map, Rectangle2D bounds)
  1278. {
  1279. this.m_Map = map;
  1280. this.m_Bounds = bounds;
  1281. this.Reset();
  1282. }
  1283. public void Dispose()
  1284. {
  1285. this.Free();
  1286. }
  1287. public void Free()
  1288. {
  1289. if (this.m_Map != null)
  1290. {
  1291. m_InstancePool.Enqueue(this);
  1292. this.m_Map = null;
  1293. if (this.m_Enumerator != null)
  1294. {
  1295. this.m_Enumerator.Free();
  1296. this.m_Enumerator = null;
  1297. }
  1298. if (this.m_Enumerable != null)
  1299. {
  1300. this.m_Enumerable.Free();
  1301. }
  1302. }
  1303. }
  1304. public static Map.ObjectEnumerator Instantiate(Map map, Rectangle2D bounds)
  1305. {
  1306. if (m_InstancePool.Count > 0)
  1307. {
  1308. Map.ObjectEnumerator enumerator = (Map.ObjectEnumerator) m_InstancePool.Dequeue();
  1309. enumerator.m_Map = map;
  1310. enumerator.m_Bounds = bounds;
  1311. enumerator.Reset();
  1312. return enumerator;
  1313. }
  1314. return new Map.ObjectEnumerator(map, bounds);
  1315. }
  1316. public bool MoveNext()
  1317. {
  1318. while (true)
  1319. {
  1320. if (m_Enumerator.MoveNext())
  1321. {
  1322. object o = m_Enumerator.Current;
  1323. if (o is Mobile)
  1324. {
  1325. Mobile m = (Mobile)o;
  1326. if (m_Bounds.Contains(m.Location))
  1327. {
  1328. m_Current = o;
  1329. return true;
  1330. }
  1331. }
  1332. else if (o is Item)
  1333. {
  1334. Item item = (Item)o;
  1335. if (item.Parent == null && m_Bounds.Contains(item.Location))
  1336. {
  1337. m_Current = o;
  1338. return true;
  1339. }
  1340. }
  1341. }
  1342. else if (m_Stage == 0)
  1343. {
  1344. m_Enumerator.Free();
  1345. m_Enumerator = SectorEnumerator.Instantiate(m_Map, m_Bounds, SectorEnumeratorType.Mobiles);
  1346. m_Current = null;
  1347. m_Stage = 1;
  1348. }
  1349. else
  1350. {
  1351. m_Enumerator.Free();
  1352. m_Enumerator = null;
  1353. m_Current = null;
  1354. m_Stage = -1;
  1355. return false;
  1356. }
  1357. }
  1358. }
  1359. public void Reset()
  1360. {
  1361. this.m_Stage = 0;
  1362. this.m_Current = null;
  1363. if (this.m_Enumerator != null)
  1364. {
  1365. this.m_Enumerator.Free();
  1366. }
  1367. this.m_Enumerator = Map.SectorEnumerator.Instantiate(this.m_Map, this.m_Bounds, Map.SectorEnumeratorType.Items);
  1368. }
  1369. public object Current
  1370. {
  1371. get
  1372. {
  1373. return this.m_Current;
  1374. }
  1375. }
  1376. public IPooledEnumerable Enumerable
  1377. {
  1378. get
  1379. {
  1380. return this.m_Enumerable;
  1381. }
  1382. set
  1383. {
  1384. this.m_Enumerable = value;
  1385. }
  1386. }
  1387. }
  1388. private class PooledEnumerable : IPooledEnumerable, IEnumerable, IDisposable
  1389. {
  1390. private static int m_Depth = 0;
  1391. private IPooledEnumerator m_Enumerator;
  1392. private static Queue m_InstancePool = new Queu

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