Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 95.66 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using Naruto.Client;
  4. using System.Threading;
  5. using System.Diagnostics;
  6. using Naruto.Interfaces;
  7. using System.Threading.Generic;
  8. using System.Collections.Generic;
  9. using Naruto.Network.GamePackets;
  10. using System.Collections.Concurrent;
  11.  
  12. namespace Naruto.Game
  13. {
  14. public unsafe class Screen
  15. {
  16. private static TimerRule<GameState> MonsterBuffers, Guards, AliveMonsters, Items, FloorSpells, MatrixMobs;
  17. public ConcurrentDictionary<uint, Game.EntityAdd> ConcurrentDictionaryPlayers = new ConcurrentDictionary<uint, EntityAdd>();
  18. public static void CreateTimerFactories()
  19. {
  20. MonsterBuffers = new TimerRule<GameState>(monsterBuffersCallback, 500);
  21. Guards = new TimerRule<GameState>(guardsCallback, 700);
  22. MatrixMobs = new TimerRule<GameState>(MatrixMobsCallback, 700);
  23. AliveMonsters = new TimerRule<GameState>(aliveMonstersCallback, 500);
  24. Items = new TimerRule<GameState>(itemsCallback, 1000);
  25. FloorSpells = new TimerRule<GameState>(FloorSpellsCallBack, 100);
  26. }
  27. private static void FloorSpellsCallBack(GameState client, int time)
  28. {
  29. if (!client.Socket.Alive)
  30. {
  31. client.Screen.DisposeTimers();
  32. return;
  33. }
  34. if (client.Entity == null) return;
  35. if (client.Map == null) return;
  36. Time32 Now = new Time32(time);
  37. if (client.Entity.FloorSpells.Count != 0)
  38. {
  39. foreach (var ID in client.Entity.FloorSpells)
  40. {
  41. switch (ID.Key)
  42. {
  43. }
  44. }
  45. }
  46. }
  47. private static void monsterBuffersCallback(GameState client, int time)
  48. {
  49. if (!client.Socket.Alive)
  50. {
  51. client.Screen.DisposeTimers(); return;
  52. }
  53. if (client.Entity == null) return;
  54. if (client.Map == null) return;
  55. if (client.Map.FreezeMonsters) return;
  56. #region Stamina
  57. //if (client.Entity.StaminaStamp.Next(500, time: time))
  58. //{
  59. // if (client.Vigor < client.MaxVigor)
  60. // {
  61. // ushort amount = (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
  62. // if (client.Vigor + amount > client.MaxVigor)
  63. // {
  64. // amount = client.MaxVigor;
  65. // client.Vigor = amount;
  66. // }
  67. // else
  68. // {
  69. // client.Vigor += amount;
  70. // }
  71. // Vigor vigor = new Vigor(true);
  72. // vigor.Amount = client.Vigor;
  73. // vigor.Send(client);
  74. // }
  75. // if (!client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Ride) && !client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly) || client.Equipment.TryGetItem(18) != null)
  76. // {
  77. // int limit = 0;
  78. // if (client.Entity.HeavenBlessing > 0)
  79. // limit = 50;
  80. // if (client.Spells != null)
  81. // {
  82. // if (client.Spells.ContainsKey(12560))
  83. // {
  84. // var spelll = client.Spells[12560];
  85. // var skilll = Database.SpellTable.SpellInformations[12560][spelll.Level];
  86. // limit += (int)skilll.Power;
  87. // }
  88. // }
  89. // if (client.Entity.Stamina != 100 + limit)
  90. // {
  91. // if (client.Entity.Action == Enums.ConquerAction.Sit)
  92. // {
  93. // if (client.Entity.Stamina <= 90 + limit)
  94. // {
  95. // client.Entity.Stamina += 10;
  96. // }
  97. // else
  98. // {
  99. // if (client.Entity.Stamina != 100 + limit)
  100. // client.Entity.Stamina = (byte)(100 + limit);
  101. // }
  102. // }
  103. // else
  104. // {
  105. // if (client.Entity.Stamina <= 95 + limit)
  106. // {
  107. // client.Entity.Stamina += 5;
  108. // }
  109. // else
  110. // {
  111. // if (client.Entity.Stamina != 100 + limit)
  112. // client.Entity.Stamina = (byte)(100 + limit);
  113. // }
  114. // }
  115. // }
  116. // client.Entity.StaminaStamp = new Time32(time);
  117. // }
  118. //}
  119. #endregion
  120. #region Stamina
  121. if (client.Entity.StaminaStamp.Next(500, time: time))
  122. {
  123. if (client.Vigor < client.Entity.ExtraVigor)
  124. {
  125. client.Vigor += (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
  126. {
  127. Vigor vigor = new Vigor(true);
  128. vigor.Amount = client.Vigor;
  129. vigor.Send(client);
  130. }
  131. }
  132. if (!client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Ride) && !client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly) || client.Equipment.TryGetItem(18) != null)
  133. {
  134. int limit = 0;
  135. if (client.Entity.HeavenBlessing > 0)
  136. limit = 50;
  137. if (client.Spells != null)
  138. {
  139. if (client.Spells.ContainsKey(12560))
  140. {
  141. var spell = client.Spells[12560];
  142. var skill = Database.SpellTable.SpellInformations[12560][spell.Level];
  143. limit += (int)skill.Power;
  144. }
  145. }
  146. if (client.Entity.Stamina != 100 + limit)
  147. {
  148. if (client.Entity.Action == Enums.ConquerAction.Sit)
  149. {
  150. if (client.Entity.Stamina <= 93 + limit)
  151. {
  152. client.Entity.Stamina += 7;
  153. }
  154. else
  155. {
  156. if (client.Entity.Stamina != 100 + limit)
  157. client.Entity.Stamina = (byte)(100 + limit);
  158. }
  159. }
  160. else
  161. {
  162. if (client.Entity.Stamina <= 97 + limit)
  163. {
  164. client.Entity.Stamina += 3;
  165. }
  166. else
  167. {
  168. if (client.Entity.Stamina != 100 + limit)
  169. client.Entity.Stamina = (byte)(100 + limit);
  170. }
  171. }
  172. }
  173. client.Entity.StaminaStamp = new Time32(time);
  174. }
  175. }
  176. #endregion
  177. #region Energia Aurora Lotus / Flame Lotus
  178. if (!client.Entity.Dead)
  179. {
  180. if (client.Entity.LotusEnergyStamp.Next(1000, time: time))
  181. {
  182. if (client.Entity.Class >= 130 && client.Entity.Class <= 135)
  183. {
  184. if (client.Entity.ContainsFlag3((ulong)FlagsUpdate.Flags3.AuroraLotus))
  185. {
  186. if (client.Entity.AuroraLotusEnergy < 220)
  187. client.Entity.AuroraLotusEnergy = (uint)Math.Min(220, client.Entity.AuroraLotusEnergy + 2);
  188. client.Entity.Lotus(client.Entity.AuroraLotusEnergy, FlagsUpdate.AuroraLotus);
  189. }
  190. }
  191. if (client.Entity.Class >= 140 && client.Entity.Class <= 145)
  192. {
  193. if (client.Entity.ContainsFlag3((ulong)FlagsUpdate.Flags3.FlameLotus))
  194. {
  195. if (client.Entity.FlameLotusEnergy < 330)
  196. client.Entity.FlameLotusEnergy = (uint)Math.Min(330, client.Entity.FlameLotusEnergy + 3);
  197. client.Entity.Lotus(client.Entity.FlameLotusEnergy, FlagsUpdate.FlameLotus);
  198.  
  199. }
  200. }
  201. client.Entity.LotusEnergyStamp = new Time32(time);
  202. }
  203. }
  204. #endregion
  205. if (client.Map.ID == 8880 || client.Map.ID == 8881)
  206. {
  207. SafeDictionary<uint, PokerTable> ToRem = new SafeDictionary<uint, PokerTable>(40);
  208. foreach (PokerTable T in PokerTables.Values)
  209. {
  210. if (client.Map.ID == T.Map)
  211. if (Kernel.GetDistance(T.X, T.Y, client.Entity.X, client.Entity.Y) > Constants.nScreenDistance)
  212. ToRem.Add(T.Id, T);
  213. }
  214. foreach (PokerTable T in ToRem.Values)
  215. if (PokerTables.ContainsKey(T.Id))
  216. PokerTables.Remove(T.Id);
  217. }
  218. foreach (IMapObject obj in client.Screen.Objects)
  219. {
  220. if (obj != null)
  221. {
  222. if (obj.MapObjType == MapObjectType.Monster)
  223. {
  224. Entity monster = obj as Entity;
  225. if (monster == null) continue;
  226.  
  227. if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.Stigma))
  228. {
  229. if (monster.StigmaStamp.AddSeconds(monster.StigmaTime).Next(time: time) || monster.Dead)
  230. {
  231. monster.StigmaTime = 0;
  232. monster.StigmaIncrease = 0;
  233. monster.RemoveFlag((ulong)FlagsUpdate.Flags.Stigma);
  234. }
  235. }
  236. if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.Dodge))
  237. {
  238. if (monster.DodgeStamp.AddSeconds(monster.DodgeTime).Next(time: time) || monster.Dead)
  239. {
  240. monster.DodgeTime = 0;
  241. monster.DodgeIncrease = 0;
  242. monster.RemoveFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.Dodge);
  243. }
  244. }
  245. if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.Invisibility))
  246. {
  247. if (monster.InvisibilityStamp.AddSeconds(monster.InvisibilityTime).Next(time: time) || monster.Dead)
  248. {
  249. monster.RemoveFlag((ulong)FlagsUpdate.Flags.Invisibility);
  250. }
  251. }
  252. if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.StarOfAccuracy))
  253. {
  254. if (monster.StarOfAccuracyTime != 0)
  255. {
  256. if (monster.StarOfAccuracyStamp.AddSeconds(monster.StarOfAccuracyTime).Next(time: time) || monster.Dead)
  257. {
  258. monster.RemoveFlag((ulong)FlagsUpdate.Flags.StarOfAccuracy);
  259. }
  260. }
  261. else
  262. {
  263. if (monster.AccuracyStamp.AddSeconds(monster.AccuracyTime).Next(time: time) || monster.Dead)
  264. {
  265. monster.RemoveFlag((ulong)FlagsUpdate.Flags.StarOfAccuracy);
  266. }
  267. }
  268. }
  269. if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.MagicShield))
  270. {
  271. if (monster.MagicShieldTime != 0)
  272. {
  273. if (monster.MagicShieldStamp.AddSeconds(monster.MagicShieldTime).Next(time: time) || monster.Dead)
  274. {
  275. monster.MagicShieldIncrease = 0;
  276. monster.MagicShieldTime = 0;
  277. monster.RemoveFlag((ulong)FlagsUpdate.Flags.MagicShield);
  278. }
  279. }
  280. else
  281. {
  282. if (monster.ShieldStamp.AddSeconds(monster.ShieldTime).Next(time: time) || monster.Dead)
  283. {
  284. monster.ShieldIncrease = 0;
  285. monster.ShieldTime = 0;
  286. monster.RemoveFlag((ulong)FlagsUpdate.Flags.MagicShield);
  287. }
  288. }
  289. }
  290. if (monster.Dead || monster.Killed)
  291. {
  292. if (!monster.ContainsFlag((ulong)FlagsUpdate.Flags.Ghost) || monster.Killed)
  293. {
  294. monster.Killed = false;
  295. monster.MonsterInfo.InSight = 0;
  296. monster.AddFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.Ghost);
  297. monster.AddFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.Dead);
  298. monster.AddFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.FadeAway);
  299. Network.GamePackets.Attack attack = new Network.GamePackets.Attack(true);
  300. attack.Attacker = monster.Killer.UID;
  301. attack.Attacked = monster.UID;
  302. attack.AttackType = Network.GamePackets.Attack.Kill;
  303. attack.X = monster.X;
  304. attack.Y = monster.Y;
  305. client.Map.Floor[monster.X, monster.Y, MapObjectType.Monster, monster] = true;
  306. attack.KOCount = ++monster.Killer.KOCount;
  307. if (monster.Killer.EntityFlag == EntityFlag.Player)
  308. {
  309. monster.MonsterInfo.ExcludeFromSend = monster.Killer.UID;
  310. monster.Killer.Owner.Send(attack);
  311. }
  312. monster.MonsterInfo.SendScreen(attack);
  313. monster.MonsterInfo.ExcludeFromSend = 0;
  314. }
  315. if (monster.DeathStamp.AddSeconds(4).Next(time: time))
  316. {
  317. Data data = new Data(true);
  318. data.UID = monster.UID;
  319. data.ID = Network.GamePackets.Data.RemoveEntity;
  320. monster.MonsterInfo.SendScreen(data);
  321. }
  322. }
  323. }
  324. }
  325. }
  326. }
  327. private static void guardsCallback(GameState client, int time)
  328. {
  329. if (!client.Socket.Alive)
  330. {
  331. client.Screen.DisposeTimers(); return;
  332. }
  333. if (client.Entity == null) return;
  334. if (client.Map == null) return;
  335. if (client.Map.FreezeMonsters) return;
  336. Time32 Now = new Time32(time);
  337. foreach (IMapObject obj in client.Screen.Objects)
  338. {
  339. if (obj != null)
  340. {
  341. if (obj.MapObjType == MapObjectType.Monster)
  342. {
  343. Entity monster = obj as Entity;
  344. if (!monster.Companion && !monster.Dead && !monster.Killed && monster.MonsterInfo.Guard && !monster.MonsterInfo.Boss && monster.Name != "NemesisTyrant" && monster.Name != "SwordMaster" && monster.Name != "ThrillingSpook" && monster.Name != "LavaBeast" && monster.Name != "SnowBanshee" && monster.Name != "PurpleBanshee" && monster.Name != "SnowBansheeSoul" && monster.Name != "TeratoDragon" && Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  345. {
  346. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  347. {
  348. if (monster.MonsterInfo.InSight == 0)
  349. {
  350. if (monster.X != monster.MonsterInfo.BoundX || monster.Y != monster.MonsterInfo.BoundY)
  351. {
  352. monster.X = monster.MonsterInfo.BoundX;
  353. monster.Y = monster.MonsterInfo.BoundY;
  354. TwoMovements jump = new TwoMovements();
  355. jump.X = monster.MonsterInfo.BoundX;
  356. jump.Y = monster.MonsterInfo.BoundY;
  357. jump.EntityCount = 1;
  358. jump.FirstEntity = monster.UID;
  359. jump.MovementType = TwoMovements.Jump;
  360. client.SendScreen(jump, true);
  361. }
  362. /*
  363. if (monster.MonsterInfo.Type != 1)
  364. client.Send(new Network.GamePackets.Message("WelCoMe In "+ Constants.ServerName +"#38", client.Entity.Name, monster.MonsterInfo.Name, System.Drawing.Color.White, Message.Talk));
  365. client.Send(new Network.GamePackets.Message("WelCoMe In " + Constants.ServerName + "#00", client.Entity.Name, monster.Name, System.Drawing.Color.White, Message.Talk));
  366. */
  367. if (client.Entity.ContainsFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.FlashingName))
  368. monster.MonsterInfo.InSight = client.Entity.UID;
  369. }
  370. else
  371. {
  372. if (client.Entity.ContainsFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.FlashingName))
  373. {
  374. if (monster.MonsterInfo.InSight == client.Entity.UID)
  375. {
  376. if (!client.Entity.Dead)
  377. {
  378. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  379. {
  380. short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  381.  
  382. if (distance <= monster.MonsterInfo.AttackRange)
  383. {
  384. monster.MonsterInfo.LastMove = Time32.Now;
  385. new Game.Attacking.Handle(null, monster, client.Entity);
  386. }
  387. else
  388. {
  389. if (distance <= monster.MonsterInfo.ViewRange)
  390. {
  391. TwoMovements jump = new TwoMovements();
  392. jump.X = client.Entity.X;
  393. jump.Y = client.Entity.Y;
  394. monster.X = client.Entity.X;
  395. monster.Y = client.Entity.Y;
  396. jump.EntityCount = 1;
  397. jump.FirstEntity = monster.UID;
  398. jump.MovementType = TwoMovements.Jump;
  399. client.SendScreen(jump, true);
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. else
  407. {
  408. if (monster.MonsterInfo.InSight == client.Entity.UID)
  409. {
  410. monster.MonsterInfo.InSight = 0;
  411. }
  412. }
  413. }
  414. foreach (IMapObject obj2 in client.Screen.Objects)
  415. {
  416. if (obj2 == null) continue;
  417. if (obj2.MapObjType == MapObjectType.Monster)
  418. {
  419. Entity monster2 = obj2 as Entity;
  420.  
  421. if (monster2 == null) continue;
  422. if (monster2.Dead) continue;
  423.  
  424. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  425. {
  426. if (!monster2.MonsterInfo.Guard && (!monster2.Companion || monster2.Owner.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.FlashingName)))
  427. {
  428. short distance = Kernel.GetDistance(monster.X, monster.Y, monster2.X, monster2.Y);
  429.  
  430. if (distance <= monster.MonsterInfo.AttackRange)
  431. {
  432. monster.MonsterInfo.LastMove = Time32.Now;
  433. new Game.Attacking.Handle(null, monster, monster2);
  434. }
  435. }
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }
  443. }
  444. }
  445. private static void aliveMonstersCallback(GameState client, int time)
  446. {
  447. if (!client.Socket.Alive)
  448. {
  449. client.Screen.DisposeTimers();
  450. return;
  451. }
  452. if (client.Entity == null) return;
  453. if (client.Map == null) return;
  454. if (client.Map.FreezeMonsters) return;
  455. Time32 Now = new Time32(time);
  456. foreach (IMapObject obj in client.Screen.Objects)
  457. {
  458. if (obj != null)
  459. {
  460. if (obj.MapObjType == MapObjectType.Monster)
  461. {
  462. Entity monster = obj as Entity;
  463.  
  464. if (monster == null) continue;
  465. if (monster.MonsterInfo.Guard || monster.Companion || monster.Dead) continue;
  466. if (monster.MonsterInfo.Reviver)
  467. {
  468. if (client.Entity.Dead && Now > client.Entity.DeathStamp.AddSeconds(5))
  469. {
  470. client.Entity.BringToLife();
  471. SpellUse use = new SpellUse(true);
  472. use.Attacker = monster.UID;
  473. use.X = client.Entity.X;
  474. use.Y = client.Entity.Y;
  475. use.SpellID = 1100;
  476. use.AddTarget(client.Entity.UID, 0, null);
  477. Kernel.SendWorldMessage(use, Server.GamePool, monster.MapID);
  478. }
  479. return;
  480. }
  481. short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  482. if (distance > Constants.pScreenDistance)
  483. {
  484. client.Screen.Remove(obj);
  485. continue;
  486. }
  487. if (monster.MonsterInfo.InSight != 0 && monster.MonsterInfo.InSight != client.Entity.UID)
  488. {
  489. if (monster.MonsterInfo.InSight > 1000000)
  490. {
  491. GameState cl;
  492. if (Kernel.GamePool.TryGetValue(monster.MonsterInfo.InSight, out cl))
  493. {
  494. short dst = Kernel.GetDistance(monster.X, monster.Y, cl.Entity.X, cl.Entity.Y);
  495. if (dst > Constants.pScreenDistance)
  496. monster.MonsterInfo.InSight = 0;
  497. }
  498. else
  499. monster.MonsterInfo.InSight = 0;
  500. }
  501. else
  502. {
  503. Entity companion = client.Map.Companions[monster.MonsterInfo.InSight];
  504. if (companion != null)
  505. {
  506. short dst = Kernel.GetDistance(monster.X, monster.Y, companion.X, companion.Y);
  507. if (dst > Constants.pScreenDistance)
  508. monster.MonsterInfo.InSight = 0;
  509. }
  510. else
  511. monster.MonsterInfo.InSight = 0;
  512. }
  513. }
  514. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  515. {
  516. if (distance <= Constants.pScreenDistance)
  517. {
  518. #region Companions
  519. if (client.Pet != null)
  520. {
  521. if (client.Pet.Pets != null)
  522. {
  523. foreach (var pet in client.Pet.Pets.Values)
  524. {
  525. if (pet != null)
  526. {
  527. #region Pets
  528. if (pet.Entity.Companion && !pet.Entity.Dead)
  529. {
  530. short distance2 = Kernel.GetDistance(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  531. if (distance > distance2 || client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Invisibility) || client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly))
  532. {
  533. if (monster.MonsterInfo.InSight == 0)
  534. {
  535. monster.MonsterInfo.InSight = pet.Entity.UID;
  536. }
  537. else
  538. {
  539. if (monster.MonsterInfo.InSight == pet.Entity.UID)
  540. {
  541. if (distance2 > Constants.pScreenDistance)
  542. {
  543. monster.MonsterInfo.InSight = 0;
  544. }
  545. else
  546. {
  547. if (distance2 <= monster.MonsterInfo.AttackRange)
  548. {
  549. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  550. {
  551. monster.MonsterInfo.LastMove = Time32.Now;
  552. new Game.Attacking.Handle(null, monster, pet.Entity);
  553. if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  554. {
  555. monster.MonsterInfo.Lastpop = Time32.Now;
  556. continue;
  557. }
  558. }
  559. }
  560. else
  561. {
  562. if (distance2 > monster.MonsterInfo.ViewRange / 2)
  563. {
  564. if (distance2 < Constants.pScreenDistance)
  565. {
  566. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  567. {
  568. monster.MonsterInfo.LastMove = Time32.Now;
  569. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  570. if (!monster.Move(facing))
  571. {
  572. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  573. if (monster.Move(facing))
  574. {
  575. monster.Facing = facing;
  576. GroundMovement move = new GroundMovement(true);
  577. move.Direction = facing;
  578. move.UID = monster.UID;
  579. move.GroundMovementType = GroundMovement.Run;
  580. monster.MonsterInfo.SendScreen(move);
  581. continue;
  582. }
  583. }
  584. else
  585. {
  586. monster.Facing = facing;
  587. GroundMovement move = new GroundMovement(true);
  588. move.Direction = facing;
  589. move.UID = monster.UID;
  590. move.GroundMovementType = GroundMovement.Run;
  591. monster.MonsterInfo.SendScreen(move);
  592. continue;
  593. }
  594. }
  595. }
  596. else
  597. {
  598. monster.MonsterInfo.InSight = 0;
  599. }
  600. }
  601. else
  602. {
  603. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  604. {
  605. monster.MonsterInfo.LastMove = Time32.Now;
  606. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  607. if (!monster.Move(facing))
  608. {
  609. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  610. if (monster.Move(facing))
  611. {
  612. monster.Facing = facing;
  613. GroundMovement move = new GroundMovement(true);
  614. move.Direction = facing;
  615. move.UID = monster.UID;
  616. monster.MonsterInfo.SendScreen(move);
  617. continue;
  618. }
  619. }
  620. else
  621. {
  622. monster.Facing = facing;
  623. GroundMovement move = new GroundMovement(true);
  624. move.Direction = facing;
  625. move.UID = monster.UID;
  626. monster.MonsterInfo.SendScreen(move);
  627. continue;
  628. }
  629. }
  630. }
  631. }
  632. }
  633. }
  634. }
  635. }
  636. }
  637. #endregion
  638. }
  639.  
  640. }
  641. }
  642. }
  643. #endregion
  644. #region Player
  645. if (monster.MonsterInfo.InSight == 0)
  646. {
  647. if (distance <= monster.MonsterInfo.ViewRange)
  648. {
  649. if (!client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Invisibility))
  650. {
  651. if (monster.MonsterInfo.SpellID != 0 || !client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly))
  652. {
  653. monster.MonsterInfo.InSight = client.Entity.UID;
  654. }
  655. }
  656. }
  657. }
  658. else
  659. {
  660. if (monster.MonsterInfo.InSight == client.Entity.UID)
  661. {
  662. if (monster.MonsterInfo.SpellID == 0 && client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly))
  663. {
  664. monster.MonsterInfo.InSight = 0;
  665. return;
  666. }
  667. if (client.Entity.Dead)
  668. {
  669. monster.MonsterInfo.InSight = 0;
  670. return;
  671. }
  672. if (distance > Constants.pScreenDistance)
  673. {
  674. monster.MonsterInfo.InSight = 0;
  675. }
  676. else
  677. {
  678. if (distance <= monster.MonsterInfo.AttackRange)
  679. {
  680. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  681. {
  682. monster.MonsterInfo.LastMove = Time32.Now;
  683. new Game.Attacking.Handle(null, monster, client.Entity);
  684. }
  685. }
  686. else
  687. {
  688. if (distance > monster.MonsterInfo.ViewRange / 2)
  689. {
  690. if (distance < Constants.pScreenDistance)
  691. {
  692. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  693. {
  694. monster.MonsterInfo.LastMove = Time32.Now;
  695. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  696. if (!monster.Move(facing))
  697. {
  698. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  699. if (monster.Move(facing))
  700. {
  701. monster.Facing = facing;
  702. GroundMovement move = new GroundMovement(true);
  703. move.Direction = facing;
  704. move.UID = monster.UID;
  705. move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  706. monster.MonsterInfo.SendScreen(move);
  707. }
  708. }
  709. else
  710. {
  711. monster.Facing = facing;
  712. GroundMovement move = new GroundMovement(true);
  713. move.Direction = facing;
  714. move.UID = monster.UID;
  715. move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  716. monster.MonsterInfo.SendScreen(move);
  717. }
  718. }
  719. }
  720. else
  721. {
  722. monster.MonsterInfo.InSight = 0;
  723. }
  724. }
  725. else
  726. {
  727. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  728. {
  729. monster.MonsterInfo.LastMove = Time32.Now;
  730. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  731. if (!monster.Move(facing))
  732. {
  733. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  734. if (monster.Move(facing))
  735. {
  736. monster.Facing = facing;
  737. GroundMovement move = new GroundMovement(true);
  738. move.Direction = facing;
  739. move.UID = monster.UID;
  740. monster.MonsterInfo.SendScreen(move);
  741. }
  742. }
  743. else
  744. {
  745. monster.Facing = facing;
  746. GroundMovement move = new GroundMovement(true);
  747. move.Direction = facing;
  748. move.UID = monster.UID;
  749. monster.MonsterInfo.SendScreen(move);
  750. }
  751. }
  752. }
  753. }
  754. }
  755. }
  756. }
  757. #endregion
  758. }
  759. }
  760. }
  761. else if (obj.MapObjType == MapObjectType.Item)
  762. {
  763. FloorItem item = obj as FloorItem;
  764. if (item == null) continue;
  765.  
  766. if (item.Type == FloorItem.Effect)
  767. {
  768. if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce || item.ItemID == 31)
  769. {
  770. if (item.Owner == client)
  771. {
  772. if (Time32.Now > item.UseTime.AddSeconds(1))
  773. {
  774. item.UseTime = Time32.Now;
  775. var spell = Database.SpellTable.GetSpell(11600, client);
  776. var attack = new Attack(true);
  777. attack.Attacker = item.Owner.Entity.UID;
  778. attack.AttackType = Attack.Melee;
  779. foreach (var obj1 in client.Screen.Objects)
  780. {
  781. if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  782. {
  783. if (obj1.MapObjType == MapObjectType.Monster || obj1.MapObjType == MapObjectType.Player)
  784. {
  785. var attacked = obj1 as Entity;
  786. if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  787. {
  788. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  789. damage = (uint)((damage) / 12);
  790. attack.Damage = damage;
  791. attack.Attacked = attacked.UID;
  792. attack.X = attacked.X;
  793. attack.Y = attacked.Y;
  794. Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  795. }
  796. }
  797. else if (obj1.MapObjType == MapObjectType.SobNpc)
  798. {
  799. var attacked = obj1 as SobNpcSpawn;
  800. if (Attacking.Handle.CanAttack(client.Entity, attacked, spell))
  801. {
  802. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, ref attack);
  803. damage = (uint)(damage * spell.PowerPercent);
  804. attack.Damage = damage;
  805. attack.Attacked = attacked.UID;
  806. attack.X = attacked.X;
  807. attack.Y = attacked.Y;
  808. Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell);
  809. }
  810. }
  811. }
  812. }
  813. }
  814. }
  815. }
  816. if (item.ItemID == 1397)
  817. {
  818. if (item.Owner == client)
  819. {
  820. if (item.OnFloor.AddSeconds(3).Next(time: time))
  821. {
  822. item.UseTime = Time32.Now;
  823. var spell = Database.SpellTable.GetSpell(12550, client);
  824. var attack = new Attack(true);
  825. attack.Attacker = item.Owner.Entity.UID;
  826. attack.AttackType = Attack.Melee;
  827. foreach (var obj1 in client.Screen.Objects)
  828. {
  829. if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  830. {
  831. if (obj1.MapObjType == MapObjectType.Player)
  832. {
  833. var attacked = obj1 as Entity;
  834. if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  835. {
  836. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  837. // damage = (uint)(damage * 3);
  838. // damage = damage * 10;
  839. attack.Damage = damage;
  840. attack.Attacked = attacked.UID;
  841. attack.X = attacked.X;
  842. attack.Y = attacked.Y;
  843. Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  844. }
  845. }
  846. else if (obj1.MapObjType == MapObjectType.Monster)
  847. {
  848. var attacked = obj1 as Entity;
  849. if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  850. {
  851. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  852. // damage = (uint)(damage * 3);
  853. // damage = damage * 10;
  854. attack.Damage = damage;
  855. attack.Attacked = attacked.UID;
  856. attack.X = attacked.X;
  857. attack.Y = attacked.Y;
  858. Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  859. }
  860. }
  861. }
  862. }
  863. }
  864. }
  865. }
  866. }
  867. }
  868. }
  869. }
  870. }
  871. private static void itemsCallback(GameState client, int time)
  872. {
  873. if (!client.Socket.Alive)
  874. {
  875. client.Screen.DisposeTimers(); return;
  876. }
  877. if (client.Entity == null) return;
  878. if (client.Map == null) return;
  879. if (client.Map.FreezeMonsters) return;
  880. if (!client.Entity.FullyLoaded) return;
  881. Time32 Now = new Time32(time);
  882. foreach (IMapObject obj in client.Screen.Objects)
  883. {
  884. if (obj != null)
  885. {
  886. if (obj.MapObjType == MapObjectType.Item)
  887. {
  888. FloorItem item = obj as FloorItem;
  889. if (item == null) continue;
  890. if (item.Type == FloorItem.Effect)
  891. {
  892. if (item.ItemID == 1397)
  893. {
  894. if (item.OnFloor.AddSeconds(3).Next(time: time))
  895. {
  896. Attacking.Handle.InfroEcho(item);
  897. item.Type = FloorItem.RemoveEffect;
  898. client.Map.RemoveFloorItem(item);
  899. client.RemoveScreenSpawn(item, true);
  900. }
  901. }
  902. if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce || item.ItemID == 31)
  903. {
  904. if (item.OnFloor.AddSeconds(4).Next(time: time))
  905. {
  906. item.Type = FloorItem.RemoveEffect;
  907. client.Map.RemoveFloorItem(item);
  908. client.RemoveScreenSpawn(item, true);
  909. }
  910. }
  911. if (item.ItemID == FloorItem.AuroraLotus)
  912. {
  913. if (item.OnFloor.AddSeconds(7).Next(time: time))
  914. {
  915. item.Type = FloorItem.RemoveEffect;
  916. client.Map.RemoveFloorItem(item);
  917. client.RemoveScreenSpawn(item, true);
  918. Attacking.Handle.AuroraLotus(item);
  919. }
  920. }
  921. if (item.ItemID == FloorItem.FlameLotus)
  922. {
  923. if (item.OnFloor.AddSeconds(7).Next(time: time))
  924. {
  925. item.Type = FloorItem.RemoveEffect;
  926. client.Map.RemoveFloorItem(item);
  927. client.RemoveScreenSpawn(item, true);
  928. Attacking.Handle.FlameLotus(item);
  929. }
  930. }
  931. if (item.ItemID == FloorItem.TwilightDance)
  932. {
  933. if (item.OnFloor.AddMilliseconds(500).Next(time: time))
  934. {
  935. item.Type = FloorItem.RemoveEffect;
  936. client.Map.RemoveFloorItem(item);
  937. client.RemoveScreenSpawn(item, true);
  938. }
  939. }
  940. else
  941. {
  942. if (item.OnFloor.AddSeconds(Constants.FloorItemSeconds).Next(time: time))
  943. {
  944. item.Type = FloorItem.Remove;
  945. foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  946. if (_obj != null)
  947. if (_obj.MapObjType == MapObjectType.Player)
  948. (_obj as Entity).Owner.Send(item);
  949. client.Map.RemoveFloorItem(item);
  950. client.Screen.Remove(item);
  951. }
  952. }
  953. }
  954. }
  955. }
  956. }
  957. }
  958. private static void MatrixMobsCallback(GameState client, int time)
  959. {
  960. if (!client.Socket.Alive)
  961. {
  962. client.Screen.DisposeTimers();
  963. return;
  964. }
  965. if (client.Entity == null)
  966. return;
  967. if (client.Map == null)
  968. return;
  969. if (client.Map.FreezeMonsters)
  970. return;
  971.  
  972. Time32 Now = new Time32(time);
  973. foreach (IMapObject obj in client.Screen.Objects)
  974. {
  975. if (obj != null)
  976. {
  977. if (obj.MapObjType == MapObjectType.Monster)
  978. {
  979. Entity monster = obj as Entity;
  980. if (monster.Companion) continue;
  981. if (monster.Dead || monster.Killed) continue;
  982.  
  983. if (monster.MonsterInfo.Type == 2 || monster.Mesh == 482)
  984. {
  985. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  986. {
  987. if (monster.MonsterInfo.InSight == 0)
  988. {
  989. ushort xx = (ushort)Kernel.Random.Next(monster.X - 10, monster.X + 10);
  990. ushort yy = (ushort)Kernel.Random.Next(monster.Y - 10, monster.Y + 10);
  991. if (monster.X != xx || monster.Y != yy)
  992. {
  993. monster.X = xx;
  994. monster.Y = yy;
  995. TwoMovements jump = new TwoMovements();
  996. jump.X = xx;
  997. jump.Y = yy;
  998. jump.EntityCount = 1;
  999. jump.FirstEntity = monster.UID;
  1000. jump.MovementType = TwoMovements.Jump;
  1001. client.SendScreen(jump, true);
  1002. }
  1003. // if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1004. // monster.MonsterInfo.InSight = client.Entity.UID;
  1005. }
  1006. else
  1007. {
  1008. // if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1009. {
  1010. if (monster.MonsterInfo.InSight == client.Entity.UID)
  1011. {
  1012. if (!client.Entity.Dead)
  1013. {
  1014. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  1015. {
  1016. short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  1017.  
  1018. if (distance <= monster.MonsterInfo.AttackRange)
  1019. {
  1020. monster.MonsterInfo.LastMove = Time32.Now;
  1021. new Game.Attacking.Handle(null, monster, client.Entity);
  1022. if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  1023. {
  1024. monster.MonsterInfo.Lastpop = Time32.Now;
  1025.  
  1026. }
  1027. }
  1028. else
  1029. {
  1030. if (distance <= monster.MonsterInfo.ViewRange)
  1031. {
  1032. TwoMovements jump = new TwoMovements();
  1033. jump.X = client.Entity.X;
  1034. jump.Y = client.Entity.Y;
  1035. monster.X = client.Entity.X;
  1036. monster.Y = client.Entity.Y;
  1037. jump.EntityCount = 1;
  1038. jump.FirstEntity = monster.UID;
  1039. jump.MovementType = TwoMovements.Jump;
  1040. client.SendScreen(jump, true);
  1041. }
  1042. }
  1043. }
  1044. }
  1045. }
  1046. }
  1047. }
  1048. }
  1049. }
  1050. }
  1051. }
  1052. }
  1053. }
  1054. private IDisposable[] TimerSubscriptions;
  1055. private object DisposalSyncRoot;
  1056. public ConcurrentDictionary<uint, Game.Statue> Statue = new ConcurrentDictionary<uint, Statue>();
  1057. private Interfaces.IMapObject[] _objects;
  1058. private static ConcurrentDictionary<uint, PokerTable> PokerTables;
  1059. public Interfaces.IMapObject[] Objects
  1060. {
  1061. get { return _objects; }
  1062. }
  1063. private ConcurrentDictionary<uint, Interfaces.IMapObject> _objectDictionary;
  1064. public Client.GameState Owner;
  1065. public Screen(Client.GameState client)
  1066. {
  1067. Owner = client;
  1068. _objects = new Interfaces.IMapObject[0];
  1069. PokerTables = new ConcurrentDictionary<uint, PokerTable>();
  1070. _objectDictionary = new ConcurrentDictionary<uint, IMapObject>();
  1071. TimerSubscriptions = new IDisposable[]
  1072. {
  1073. MonsterBuffers.Add(client),
  1074. Guards.Add(client),
  1075. AliveMonsters.Add(client),
  1076. Items.Add(client),
  1077. FloorSpells.Add(client),
  1078. MatrixMobs.Add(client)
  1079. };
  1080. DisposalSyncRoot = new object();
  1081. }
  1082. ~Screen()
  1083. {
  1084. DisposeTimers();
  1085. Clear();
  1086. _objects = null;
  1087. _objectDictionary = null;
  1088. Owner = null;
  1089. }
  1090. public void DisposeTimers()
  1091. {
  1092. lock (DisposalSyncRoot)
  1093. {
  1094. if (TimerSubscriptions == null) return;
  1095. for (int i = 0; i < TimerSubscriptions.Length; i++)
  1096. {
  1097. if (TimerSubscriptions[i] != null)
  1098. {
  1099. TimerSubscriptions[i].Dispose();
  1100. TimerSubscriptions[i] = null;
  1101. }
  1102. }
  1103. }
  1104. }
  1105. private void updateBase()
  1106. {
  1107. _objects = _objectDictionary.Values.ToArray();
  1108. }
  1109. public bool Add(Interfaces.IMapObject _object)
  1110. {
  1111. if (_object == null) return false;
  1112. if (_objectDictionary.ContainsKey(_object.UID))
  1113. if (_objectDictionary[_object.UID] == null)
  1114. _objectDictionary.Remove(_object.UID);
  1115. if (!_objectDictionary.ContainsKey(_object.UID))
  1116. {
  1117. if (Kernel.GetDistance(_object.X, _object.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.pScreenDistance)
  1118. {
  1119. _objectDictionary[_object.UID] = _object;
  1120. updateBase();
  1121. return true;
  1122. }
  1123. }
  1124. return false;
  1125. }
  1126. public bool Remove(Interfaces.IMapObject _object)
  1127. {
  1128. if (_object == null) return false;
  1129. if (_objectDictionary.Remove(_object.UID))
  1130. {
  1131. updateBase();
  1132. if (_object.MapObjType == MapObjectType.Item)
  1133. {
  1134. FloorItem item = _object as FloorItem;
  1135. if (item.Type >= FloorItem.Effect)
  1136. {
  1137. item.Type = FloorItem.RemoveEffect;
  1138. Owner.Send(item);
  1139. }
  1140. else
  1141. {
  1142. item.Type = FloorItem.Remove;
  1143. Owner.Send(item);
  1144. item.Type = FloorItem.Drop;
  1145. }
  1146. }
  1147. else if (_object.MapObjType == MapObjectType.Player)
  1148. {
  1149. Owner.Send(new Data(true)
  1150. {
  1151. UID = _object.UID,
  1152. ID = Network.GamePackets.Data.RemoveEntity
  1153. });
  1154. }
  1155. else if (_object.MapObjType == MapObjectType.StaticEntity)
  1156. {
  1157. Owner.Send(new Data(true)
  1158. {
  1159. UID = _object.UID,
  1160. ID = Network.GamePackets.Data.RemoveEntity
  1161. });
  1162. }
  1163. return true;
  1164. }
  1165. return false;
  1166. }
  1167. public bool TryGetValue(uint uid, out Entity entity)
  1168. {
  1169. entity = null;
  1170. Interfaces.IMapObject imo = null;
  1171. if (_objectDictionary.TryGetValue(uid, out imo))
  1172. {
  1173. if (imo == null)
  1174. {
  1175. _objectDictionary.Remove(uid);
  1176. updateBase();
  1177. return false;
  1178. }
  1179. if (imo is Entity)
  1180. {
  1181. entity = imo as Entity;
  1182. return true;
  1183. }
  1184. }
  1185. return false;
  1186. }
  1187. public bool GetRaceObject(Func<IMapObject, bool> predicate, out StaticEntity entity)
  1188. {
  1189. entity = null;
  1190. foreach (var obj in Objects)
  1191. if (obj is StaticEntity)
  1192. if (predicate(obj))
  1193. entity = obj as StaticEntity;
  1194. return entity != null;
  1195. }
  1196. public bool TryGetSob(uint uid, out SobNpcSpawn sob)
  1197. {
  1198. sob = null;
  1199. Interfaces.IMapObject imo = null;
  1200. if (_objectDictionary.TryGetValue(uid, out imo))
  1201. {
  1202. if (imo == null)
  1203. {
  1204. _objectDictionary.Remove(uid);
  1205. updateBase();
  1206. return false;
  1207. }
  1208. if (imo is SobNpcSpawn)
  1209. {
  1210. sob = imo as SobNpcSpawn;
  1211. return true;
  1212. }
  1213. }
  1214. return false;
  1215. }
  1216. public bool TryGetFloorItem(uint uid, out FloorItem item)
  1217. {
  1218. item = null;
  1219. Interfaces.IMapObject imo = null;
  1220. if (_objectDictionary.TryGetValue(uid, out imo))
  1221. {
  1222. if (imo == null)
  1223. {
  1224. _objectDictionary.Remove(uid);
  1225. updateBase();
  1226. return false;
  1227. }
  1228. if (imo is FloorItem)
  1229. {
  1230. item = imo as FloorItem;
  1231. return true;
  1232. }
  1233. }
  1234. return false;
  1235. }
  1236. public IEnumerable<T> Select<T>(MapObjectType type) where T : class
  1237. {
  1238. foreach (var obj in Objects)
  1239. if (obj != null)
  1240. if (obj.MapObjType == type)
  1241. yield return obj as T;
  1242. }
  1243. public IEnumerable<T> Where<T>(Func<IMapObject, bool> predicate) where T : class
  1244. {
  1245. foreach (var obj in Objects)
  1246. if (obj != null)
  1247. if (predicate(obj))
  1248. yield return obj as T;
  1249. }
  1250. public IEnumerable<T> SelectWhere<T>(MapObjectType type, Func<T, bool> predicate) where T : class
  1251. {
  1252. foreach (var obj in Objects)
  1253. if (obj != null)
  1254. if (obj.MapObjType == type)
  1255. if (predicate(obj as T))
  1256. yield return obj as T;
  1257. }
  1258. public bool Contains(Interfaces.IMapObject _object)
  1259. {
  1260. if (_object == null) return false;
  1261. return _objectDictionary.ContainsKey(_object.UID);
  1262. }
  1263. public bool Contains(uint uid)
  1264. {
  1265. return _objectDictionary.ContainsKey(uid);
  1266. }
  1267. public void FullWipe()
  1268. {
  1269. foreach (IMapObject Base in Objects)
  1270. {
  1271. if (Base == null) continue;
  1272. Data data = new Data(true);
  1273. data.UID = Base.UID;
  1274. data.ID = Data.RemoveEntity;
  1275. Owner.Send(data);
  1276. if (Base.MapObjType == Game.MapObjectType.Player)
  1277. {
  1278. GameState pPlayer = Base.Owner as GameState;
  1279. pPlayer.Screen.Remove(Owner.Entity);
  1280. }
  1281. }
  1282. Clear();
  1283. }
  1284. public void Clear()
  1285. {
  1286. _objectDictionary.Clear();
  1287. _objects = new IMapObject[0];
  1288. }
  1289. public ConcurrentDictionary<uint, Game.BotShop> BOTSTALL = new ConcurrentDictionary<uint, BotShop>();
  1290. public void Reload(Interfaces.IPacket spawnWith = null)
  1291. {
  1292. CleanUp(spawnWith);
  1293. if (Owner.Entity.MapID == 1002)
  1294. {
  1295. foreach (var statue in Game.Statue.Statues.Values)
  1296. {
  1297. if (statue > Owner)
  1298. {
  1299. Statue.TryAdd(statue.UID, statue);
  1300. }
  1301. else if (statue < Owner)
  1302. {
  1303. Game.Statue astatue;
  1304. Statue.TryRemove(statue.UID, out astatue);
  1305. }
  1306. }
  1307. }
  1308. else
  1309. {
  1310. if (Statue.Count > 0)
  1311. Statue.Clear();
  1312. }
  1313. try
  1314. {
  1315. foreach (GameState pClient in Kernel.GamePool.Values)
  1316. {
  1317. if (pClient == null) return;
  1318. if (pClient.Entity == null) return;
  1319. if (Owner == null) return;
  1320. if (Owner.Entity == null) return;
  1321. if (pClient.Entity.UID != Owner.Entity.UID)
  1322. {
  1323. if (pClient.Map.ID == Owner.Map.ID)
  1324. {
  1325. short dist = Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, Owner.Entity.X, Owner.Entity.Y);
  1326. if (dist <= Constants.pScreenDistance && !Contains(pClient.Entity))
  1327. {
  1328. if (pClient.Guild != null)
  1329. pClient.Guild.SendName(Owner);
  1330. if (Owner.Guild != null)
  1331. Owner.Guild.SendName(pClient);
  1332. if (pClient.Entity.InteractionInProgress && pClient.Entity.InteractionWith != Owner.Entity.UID && pClient.Entity.InteractionSet)
  1333. {
  1334. if (pClient.Entity.Body == 1003 || pClient.Entity.Body == 1004)
  1335. {
  1336. if (pClient.Entity.InteractionX == pClient.Entity.X && pClient.Entity.Y == pClient.Entity.InteractionY)
  1337. {
  1338. Attack atak = new Attack(true);
  1339. atak.Attacker = pClient.Entity.UID;
  1340. atak.Attacked = pClient.Entity.InteractionWith;
  1341. atak.X = pClient.Entity.X;
  1342. atak.Y = pClient.Entity.Y;
  1343. atak.AttackType = 49;
  1344. atak.Damage = pClient.Entity.InteractionType;
  1345. Owner.Send(atak);
  1346. }
  1347. }
  1348. else
  1349. {
  1350. if (Kernel.GamePool.ContainsKey(pClient.Entity.InteractionWith))
  1351. {
  1352. Client.GameState Cs = Kernel.GamePool[pClient.Entity.InteractionWith] as Client.GameState;
  1353. if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  1354. {
  1355. Attack atak = new Attack(true);
  1356. atak.Attacker = pClient.Entity.UID;
  1357. atak.Attacked = pClient.Entity.InteractionWith;
  1358. atak.X = pClient.Entity.X;
  1359. atak.Y = pClient.Entity.Y;
  1360. atak.AttackType = 49;
  1361. atak.Damage = pClient.Entity.InteractionType;
  1362. Owner.Send(atak);
  1363. }
  1364. }
  1365. }
  1366. }
  1367. if (pClient.Entity.MyClones.Count > 0)
  1368. {
  1369. foreach (var clone in pClient.Entity.MyClones.Values)
  1370. {
  1371. if (clone == null) continue;
  1372. if (Kernel.GetDistance(clone.X, clone.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(clone.UID))
  1373. {
  1374. if (!clone.Dead)
  1375. clone.SendSpawn(Owner);
  1376. }
  1377. }
  1378. }
  1379. if (pClient.Pet.Pets.Count > 0)
  1380. {
  1381. foreach (var pet in pClient.Pet.Pets.Values)
  1382. {
  1383. if (pet == null) continue;
  1384. if (pet.Entity == null) continue;
  1385. if (Kernel.GetDistance(pet.Entity.X, pet.Entity.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(pet.Entity.UID))
  1386. {
  1387. if (!pet.Entity.Dead)
  1388. pet.Entity.SendSpawn(Owner);
  1389. }
  1390. }
  1391. }
  1392. if (pClient.Map.BaseID == 700)
  1393. {
  1394. if (Owner.InQualifier())
  1395. {
  1396. if (pClient.InQualifier())
  1397. {
  1398. Owner.Entity.SendSpawn(pClient);
  1399. pClient.Entity.SendSpawn(Owner);
  1400. if (pClient.Guild != null)
  1401. Owner.Entity.SendSpawn(pClient, false);
  1402. if (Owner.Guild != null)
  1403. pClient.Entity.SendSpawn(Owner, false);
  1404. if (spawnWith != null)
  1405. pClient.Send(spawnWith);
  1406. }
  1407. else
  1408. {
  1409. Owner.Entity.SendSpawn(pClient);
  1410. if (pClient.Guild != null)
  1411. Owner.Entity.SendSpawn(pClient, false);
  1412. Add(pClient.Entity);
  1413. if (spawnWith != null)
  1414. pClient.Send(spawnWith);
  1415. }
  1416. }
  1417. else
  1418. {
  1419. if (pClient.InQualifier())
  1420. {
  1421. pClient.Entity.SendSpawn(Owner);
  1422. if (Owner.Guild != null)
  1423. pClient.Entity.SendSpawn(Owner, false);
  1424. pClient.Screen.Add(Owner.Entity);
  1425. if (spawnWith != null)
  1426. Owner.Send(spawnWith);
  1427. }
  1428. else
  1429. {
  1430. Owner.Entity.SendSpawn(pClient);
  1431. pClient.Entity.SendSpawn(Owner);
  1432. if (pClient.Guild != null)
  1433. Owner.Entity.SendSpawn(pClient, false);
  1434. if (Owner.Guild != null)
  1435. pClient.Entity.SendSpawn(Owner, false);
  1436. if (spawnWith != null)
  1437. pClient.Send(spawnWith);
  1438. }
  1439. }
  1440. }
  1441. else
  1442. {
  1443. Owner.Entity.SendSpawn(pClient);
  1444. pClient.Entity.SendSpawn(Owner);
  1445. if (pClient.Guild != null)
  1446. Owner.Entity.SendSpawn(pClient, false);
  1447. if (Owner.Guild != null)
  1448. pClient.Entity.SendSpawn(Owner, false);
  1449. if (spawnWith != null)
  1450. pClient.Send(spawnWith);
  1451. }
  1452. }
  1453. }
  1454. }
  1455. }
  1456. var Map = Owner.Map;
  1457. #region Npcs
  1458. foreach (Interfaces.INpc npc in Map.Npcs.Values)
  1459. {
  1460. if (npc == null) continue;
  1461. if (Kernel.GetDistance(npc.X, npc.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  1462. if (Contains(npc.UID)) continue;
  1463. npc.SendSpawn(Owner, false);
  1464. }
  1465. #endregion
  1466. #region PlayersAdd
  1467. foreach (var p in Game.EntityAdd.DictionaryPlayers.Values)
  1468. {
  1469. if (p > Owner)
  1470. {
  1471. ConcurrentDictionaryPlayers.TryAdd(p.UID, p);
  1472. }
  1473. else if (p < Owner)
  1474. {
  1475. Game.EntityAdd outbot;
  1476. ConcurrentDictionaryPlayers.TryRemove(p.UID, out outbot);
  1477. }
  1478. }
  1479. #endregion
  1480. #region Items + map effects
  1481. foreach (var item in Map.FloorItems.Values)
  1482. {
  1483. if (item == null) continue;
  1484. if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  1485. if (Contains(item.UID)) continue;
  1486. if (item.Type == FloorItem.Effect)
  1487. {
  1488. if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce || item.ItemID == 31 || item.ItemID == 1397)
  1489. {
  1490. if (item.OnFloor.AddSeconds(4).Next(time: Time32.Now.AllMilliseconds()))
  1491. {
  1492. item.Type = FloorItem.RemoveEffect;
  1493. foreach (Interfaces.IMapObject _obj in Objects)
  1494. if (_obj != null)
  1495. if (_obj.MapObjType == MapObjectType.Player)
  1496. (_obj as Entity).Owner.Send(item);
  1497. Map.RemoveFloorItem(item);
  1498. }
  1499. else
  1500. item.SendSpawn(Owner, false);
  1501. }
  1502. else
  1503. item.SendSpawn(Owner, false);
  1504. }
  1505. else
  1506. {
  1507. if ((Time32.Now > item.OnFloor.AddSeconds(Constants.FloorItemSeconds)) || item.PickedUpAlready)
  1508. {
  1509. item.Type = Network.GamePackets.FloorItem.Remove;
  1510. Map.RemoveFloorItem(item);
  1511. }
  1512. }
  1513. item.SendSpawn(Owner);
  1514. if (item.ItemID == FloorItem.AuroraLotus)
  1515. {
  1516. if (item.OnFloor.AddSeconds(7).Next(time: Time32.Now.AllMilliseconds()))
  1517. {
  1518. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1519. foreach (Interfaces.IMapObject _obj in Objects)
  1520. if (_obj != null)
  1521. if (_obj.MapObjType == MapObjectType.Player)
  1522. (_obj as Entity).Owner.Send(item);
  1523. Map.RemoveFloorItem(item);
  1524. Attacking.Handle.AuroraLotus(item);
  1525. }
  1526. else
  1527. item.SendSpawn(Owner, false);
  1528. }
  1529. else if (item.ItemID == FloorItem.FlameLotus)
  1530. {
  1531. if (item.OnFloor.AddSeconds(7).Next(time: Time32.Now.AllMilliseconds()))
  1532. {
  1533. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1534. foreach (Interfaces.IMapObject _obj in Objects)
  1535. if (_obj != null)
  1536. if (_obj.MapObjType == MapObjectType.Player)
  1537. (_obj as Entity).Owner.Send(item);
  1538. Map.RemoveFloorItem(item);
  1539. Attacking.Handle.FlameLotus(item);
  1540. }
  1541. else
  1542. item.SendSpawn(Owner, false);
  1543. }
  1544. else if (item.ItemID == FloorItem.TwilightDance)
  1545. {
  1546. if (item.OnFloor.AddSeconds(1).Next(time: Time32.Now.AllMilliseconds()))
  1547. {
  1548. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1549. foreach (Interfaces.IMapObject _obj in Objects)
  1550. if (_obj != null)
  1551. if (_obj.MapObjType == MapObjectType.Player)
  1552. (_obj as Entity).Owner.Send(item);
  1553. Map.RemoveFloorItem(item);
  1554. }
  1555. else
  1556. item.SendSpawn(Owner, false);
  1557. }
  1558. }
  1559. #endregion
  1560. foreach (Game.Entity monster in Map.Entities.Values)
  1561. {
  1562. if (monster == null) continue;
  1563. if (Kernel.GetDistance(monster.X, monster.Y, Owner.Entity.X, Owner.Entity.Y) <= 16 && !Contains(monster.UID))
  1564. {
  1565. if (!monster.Dead)
  1566. {
  1567. monster.SendSpawn(Owner, false);
  1568. if (monster.MaxHitpoints > 65535)
  1569. {
  1570. FlagsUpdate upd = new FlagsUpdate(true)
  1571. {
  1572. UID = monster.UID
  1573. };
  1574. upd.Append((byte)FlagsUpdate.DataType.Hitpoints, monster.Hitpoints);
  1575. Owner.Send(upd);
  1576. }
  1577. }
  1578. }
  1579. }
  1580. #region RaceItems
  1581. if (Owner.Map.StaticEntities.Count != 0)
  1582. {
  1583. foreach (var item in Owner.Map.StaticEntities.Values)
  1584. {
  1585. if (item == null) continue;
  1586. if (!item.Viable) continue;
  1587. if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  1588. if (Contains(item.UID)) continue;
  1589. item.SendSpawn(Owner);
  1590. }
  1591. }
  1592. #endregion
  1593. #region Flooritems
  1594. foreach (var f in Database.FloorItemTable.FloorItems)
  1595. {
  1596. if (f == null) continue;
  1597. if (Kernel.GetDistance(f.X, f.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.pScreenDistance)
  1598. {
  1599. if (f.MapID == Owner.Entity.MapID && !Owner.Entity.FloorItems.ContainsKey(f.UID))
  1600. {
  1601. Owner.Entity.FloorItems.Add(f.UID, f);
  1602. f.SendSpawn(Owner);
  1603. }
  1604. }
  1605. else
  1606. {
  1607. if (Owner.Entity.FloorItems.ContainsKey(f.UID))
  1608. {
  1609. Owner.Entity.FloorItems.Remove(f.UID);
  1610. Remove(f);
  1611. }
  1612. }
  1613. if (Owner.Entity.MapID != f.MapID && Owner.Entity.FloorItems.ContainsKey(f.UID))
  1614. {
  1615. Owner.Entity.FloorItems.Remove(f.UID);
  1616. }
  1617. }
  1618. #endregion
  1619. foreach (Game.Entity monster in Map.Companions.Values)
  1620. {
  1621. if (monster == null) continue;
  1622. if (Kernel.GetDistance(monster.X, monster.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(monster.UID))
  1623. {
  1624. if (!monster.Dead)
  1625. {
  1626. monster.SendSpawn(Owner);
  1627. }
  1628. }
  1629. }
  1630. foreach (var bot in Game.BotShop.STATICSTALLS.Values)
  1631. {
  1632. if (bot > Owner)
  1633. {
  1634. BOTSTALL.TryAdd(bot.UID, bot);
  1635. }
  1636. else if (bot < Owner)
  1637. {
  1638. Game.BotShop outbot;
  1639. BOTSTALL.TryRemove(bot.UID, out outbot);
  1640. }
  1641. }
  1642. if (Owner.Map.ID == 8880 || Owner.Map.ID == 8881 || Owner.Map.ID == 1002)
  1643. {
  1644. foreach (Game.PokerTable T in Kernel.PokerTables.Values)
  1645. {
  1646. if (T.Map == Owner.Map.ID)
  1647. {
  1648. if (Kernel.GetDistance(T.X, T.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.nScreenDistance && !PokerTables.ContainsKey(T.Id))
  1649. {
  1650. Owner.Send(Game.PokerPackets.PokerTable(T));
  1651. PokerTables.Add(T.Id, T);
  1652. }
  1653. }
  1654. }
  1655. }
  1656. if (Owner.Map.ID == Roulette.Database.Roulettes.RouletteTable.MapID)
  1657. {
  1658. foreach (var R in Roulette.Database.Roulettes.RoulettesPoll.Values)
  1659. {
  1660. if (Kernel.GetDistance(R.SpawnPacket.X, R.SpawnPacket.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.nScreenDistance && !PokerTables.ContainsKey(R.SpawnPacket.UID))
  1661. {
  1662. Owner.Send(R.SpawnPacket);
  1663. }
  1664. }
  1665. }
  1666. }
  1667. catch (Exception e)
  1668. {
  1669. Server.SaveException(e);
  1670. }
  1671. }
  1672. public void CleanUp(Interfaces.IPacket spawnWith)
  1673. {
  1674. bool remove;
  1675. try
  1676. {
  1677. foreach (IMapObject Base in Objects)
  1678. {
  1679. if (Base == null) continue;
  1680. remove = false;
  1681. if (Base.MapObjType == MapObjectType.Monster)
  1682. {
  1683. if ((Base as Entity).Dead)
  1684. {
  1685. if (Time32.Now > (Base as Entity).DeathStamp.AddSeconds(8))
  1686. remove = true;
  1687. else remove = false;
  1688. }
  1689. if (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance)
  1690. remove = true;
  1691. if (remove)
  1692. {
  1693. if ((Base as Entity).MonsterInfo.InSight == Owner.Entity.UID)
  1694. (Base as Entity).MonsterInfo.InSight = 0;
  1695. }
  1696. }
  1697. else if (Base.MapObjType == MapObjectType.Player)
  1698. {
  1699. if (remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.pScreenDistance))
  1700. {
  1701. GameState pPlayer = Base.Owner as GameState;
  1702. pPlayer.Screen.Remove(Owner.Entity);
  1703. }
  1704. }
  1705. else if (Base.MapObjType == MapObjectType.Item)
  1706. {
  1707. remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= 22);
  1708. }
  1709. else
  1710. {
  1711. remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance);
  1712. }
  1713. if (Base.MapID != Owner.Map.ID)
  1714. remove = true;
  1715. if (remove)
  1716. {
  1717. Remove(Base);
  1718. }
  1719. }
  1720. }
  1721. catch (Exception e)
  1722. {
  1723. Server.SaveException(e);
  1724. }
  1725. }
  1726. }
  1727. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement