Advertisement
XConquer

Screen

Apr 11th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 131.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Threading;
  4. using System.Collections.Generic;
  5. using COServer.Interfaces;
  6. using COServer.Client;
  7. using COServer.Network.GamePackets;
  8. using System.Collections.Concurrent;
  9. using System.Diagnostics;
  10. using System.Threading.Generic;
  11.  
  12. namespace COServer.Game
  13. {
  14. public unsafe class EpicTaoIcon : Network.Writer, COServer.Interfaces.IPacket
  15. {
  16. byte[] Buffer = null;
  17. public EpicTaoIcon(bool Creat)
  18. {
  19. Buffer = new byte[72];
  20. WriteUInt16(64, 0, Buffer);
  21. WriteUInt16(10017, 2, Buffer);
  22. WriteUInt32((uint)Time32.timeGetTime().GetHashCode(), 4, Buffer);
  23. }
  24. public uint Energy
  25. {
  26. get { return BitConverter.ToUInt32(Buffer, 56); }
  27. set { WriteUInt32(value, 56, Buffer); }
  28. }
  29. public void Deserialize(byte[] buffer)
  30. {
  31. Buffer = buffer;
  32. }
  33. public byte[] ToArray()
  34. {
  35. return Buffer;
  36. }
  37. public void Send(COServer.Client.GameClient client)
  38. {
  39. if (Buffer != null)
  40. client.Send(Buffer);
  41. }
  42. }
  43. public class Screen
  44. {
  45. public ConcurrentDictionary<uint, Game.Statue> Statue = new ConcurrentDictionary<uint, Statue>();
  46. private static TimerRule<GameClient> MonsterBuffers, Guards, AliveMonsters, Items, FloorSpells;
  47. public static void CreateTimerFactories()
  48. {
  49. MonsterBuffers = new TimerRule<GameClient>(monsterBuffersCallback, 500);
  50. Guards = new TimerRule<GameClient>(guardsCallback, 700);
  51. AliveMonsters = new TimerRule<GameClient>(aliveMonstersCallback, 500);
  52. Items = new TimerRule<GameClient>(itemsCallback, 1000);
  53. FloorSpells = new TimerRule<GameClient>(FloorSpellsCallBack, 100);
  54. }
  55.  
  56. private static void FloorSpellsCallBack(GameClient client, int time)
  57. {
  58. if (!client.Socket.Alive)
  59. {
  60. client.Screen.DisposeTimers();
  61. return;
  62. }
  63. if (client.Entity == null) return;
  64. if (client.Map == null) return;
  65. Time32 Now = new Time32(time);
  66. #region ThunderCloud
  67. foreach (var Cloud in client.Map.Clouds.Values.ToArray())
  68. {
  69. if (Cloud == null) continue;
  70. if (Kernel.GetDistance(Cloud.X, Cloud.Y, client.Entity.X, client.Entity.Y) > 16) continue;
  71. if (DateTime.Now > Cloud.EndTime || Cloud.Owner == null)
  72. {
  73. Cloud.DisposeCloud(client);
  74. return;
  75. }
  76. #region ThunderCloud
  77. if (!Cloud.Dead && Time32.Now > Cloud.LastCloudAttack.AddSeconds(Cloud.ThunderBolt == true ? 1 : 2))
  78. {
  79. if (client.Entity.Cloud != null)
  80. {
  81. var spell = Database.SpellTable.GetSpell(12970, client);
  82. SpellUse suse = new SpellUse(true);
  83. suse.Attacker = client.Entity.Cloud.UID;
  84. suse.SpellID = 13190;
  85. suse.SpellLevel = 0;
  86. suse.X = client.Entity.Cloud.X;
  87. suse.Y = client.Entity.Cloud.Y;
  88. Entity attacked = null;
  89. foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  90. {
  91. if (_obj == null) continue;
  92. if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
  93. {
  94. Cloud.LastCloudAttack = Time32.Now;
  95. attacked = _obj as Entity;
  96. if (Kernel.GetDistance(Cloud.X, Cloud.Y, attacked.X, attacked.Y) <= 15)
  97. {
  98. Attack attack = new Attack(true);
  99. if (Game.Attacking.Handle.CanAttack(Cloud.Owner.Entity, attacked, spell, attack.AttackType == Attack.Melee))
  100. {
  101. attack.Effect1 = Attack.AttackEffects1.None;
  102. uint damage = Game.Attacking.Calculate.Melee(Cloud.Owner.Entity, attacked, ref attack);
  103. if (Cloud.ThunderBolt)
  104. damage += Game.Attacking.Calculate.Melee(Cloud.Owner.Entity, attacked, ref attack);
  105.  
  106. suse.Effect1 = attack.Effect1;
  107. Game.Attacking.Handle.ReceiveAttack(Cloud.Owner.Entity, attacked, attack, damage, spell);
  108. suse.AddTarget(attacked.UID, damage, attack);
  109. break;
  110. }
  111. }
  112. }
  113. }
  114. client.SendScreen(suse, true);
  115. }
  116. }
  117. #endregion
  118. }
  119. #endregion
  120. if (client.Entity.FloorSpells.Count != 0)
  121. {
  122. foreach (var ID in client.Entity.FloorSpells)
  123. {
  124. switch (ID.Key)
  125. {
  126. #region Habilidad TwilightDance
  127. case 12070://TwilightDance:
  128. {
  129. var spellclient = ID.Value;
  130. Queue<Game.Attacking.FloorSpell> RemoveSpells = new Queue<Game.Attacking.FloorSpell>();
  131. foreach (var spell in spellclient.Spells)
  132. {
  133. if (spellclient.CheckInvocke(Now, spell))
  134. {
  135. RemoveSpells.Enqueue(spell);
  136. spellclient.CreateMsgSpell(100);
  137. var attack = new Attack(true);
  138. attack.Attacker = client.Entity.UID;
  139. attack.AttackType = Attack.Melee;
  140. foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  141. {
  142. if (_obj == null) continue;
  143. if (_obj.MapObjType == MapObjectType.Player)
  144. {
  145. var attacked = _obj as Entity;
  146. var attacker = _obj as Entity;
  147. if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) < 3)
  148. {
  149. if (!Game.Attacking.Handle.CanAttack(client.Entity, attacked, spell.DBSkill, false)) continue;
  150. attack.Effect1 = Attack.AttackEffects1.None;
  151. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell.DBSkill, ref attack);
  152.  
  153. if (attacked.EntityFlag == EntityFlag.Player)
  154. {
  155. Console.WriteLine("Jugador " + attacker.Name + " Siendo " + attacker.NobilityRank + " Provoco Con Spell ID -> " + 12070 + " DaƱo == " + damage + " A Jugador " + attacked.Name + " Y Este Es " + attacked.NobilityRank + "");
  156. }
  157. spellclient.SpellPacket.Effect1 = attack.Effect1;
  158. attack.Damage = damage;
  159. Game.Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell.DBSkill);
  160. spellclient.SpellPacket.AddTarget(attacked.UID, damage, attack);
  161. }
  162. }
  163. else if (_obj.MapObjType == MapObjectType.Monster)
  164. {
  165. var attacked = _obj as Entity;
  166. var attacker = _obj as Entity;
  167. if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) < 3)
  168. {
  169. if (!Game.Attacking.Handle.CanAttack(client.Entity, attacked, spell.DBSkill, false)) continue;
  170. attack.Effect1 = Attack.AttackEffects1.None;
  171. uint damage = Game.Attacking.Calculate.PlayerToMonster(client.Entity, attacked, ref attack);
  172.  
  173. if (attacked.EntityFlag == EntityFlag.Monster)
  174. {
  175. damage = (damage * 2);
  176. }
  177.  
  178. spellclient.SpellPacket.Effect1 = attack.Effect1;
  179. attack.Damage = damage;
  180. Game.Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell.DBSkill);
  181. spellclient.SpellPacket.AddTarget(attacked.UID, damage, attack);
  182. }
  183. }
  184. else if (_obj.MapObjType == MapObjectType.SobNpc)
  185. {
  186. var attackedsob = _obj as SobNpcSpawn;
  187.  
  188. if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attackedsob.X, attackedsob.Y) < 3)
  189. {
  190. if (!Game.Attacking.Handle.CanAttack(client.Entity, attackedsob, spell.DBSkill)) continue;
  191. attack.Effect1 = Attack.AttackEffects1.None;
  192. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attackedsob, ref attack);
  193. attack.Damage = damage;
  194. Game.Attacking.Handle.ReceiveAttack(client.Entity, attackedsob, attack, damage, spell.DBSkill);
  195. spellclient.SpellPacket.AddTarget(attackedsob.UID, damage, attack);
  196. }
  197. }
  198. }
  199. if (spellclient.SpellPacket.Targets.Count > 0)
  200. spellclient.SendView(client);
  201. Data datap = new Data(true);
  202. datap.UID = spell.FloorPacket.UID;
  203. datap.dwParam = (uint)((spell.FloorPacket.Y << 16) | spell.FloorPacket.X);
  204. datap.wParam2 = (ushort)(spell.FloorPacket.Y - 2);
  205. datap.wParam1 = (ushort)(spell.FloorPacket.X - 3);
  206. datap.ID = Data.RemoveTrap;
  207. client.SendScreen(datap, true);
  208. spell.FloorPacket.Type = FloorItem.RemoveEffect;
  209. client.SendScreen(spell.FloorPacket, true);
  210. }
  211. }
  212. while (RemoveSpells.Count > 0)
  213. spellclient.RemoveItem(RemoveSpells.Dequeue());
  214. if (spellclient.Spells.Count == 0)
  215. {
  216. Game.Attacking.FloorSpell.ClientFloorSpells FloorSpell;
  217. client.Entity.FloorSpells.TryRemove(spellclient.DBSkill.ID, out FloorSpell);
  218. }
  219. break;
  220. }
  221. #endregion
  222.  
  223. #region Habilidad AuroraLotus
  224. case 12370://AuroraLouts:
  225. {
  226. var spellclient = ID.Value;
  227. Queue<Game.Attacking.FloorSpell> RemoveSpells = new Queue<Game.Attacking.FloorSpell>();
  228. foreach (var spell in spellclient.Spells)
  229. {
  230. if (spellclient.CheckInvocke(Now, spell))
  231. {
  232. RemoveSpells.Enqueue(spell);
  233. spellclient.CreateMsgSpell(100);
  234. var attack = new Attack(true);
  235. attack.Attacker = client.Entity.UID;
  236. attack.AttackType = Attack.Melee;
  237. foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  238. {
  239. if (_obj == null) continue;
  240. if (_obj.MapObjType == MapObjectType.Player)
  241. {
  242. var attacked = _obj as Entity;
  243. if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) <= 15)
  244. {
  245. attacked.BringToLifeLotus();
  246.  
  247. }
  248. }
  249. }
  250. spellclient.SendView(client);
  251.  
  252. spell.FloorPacket.Type = FloorItem.RemoveEffect;
  253. client.SendScreen(spell.FloorPacket, true);
  254. }
  255. }
  256. while (RemoveSpells.Count > 0)
  257. spellclient.RemoveItem(RemoveSpells.Dequeue());
  258. if (spellclient.Spells.Count == 0)
  259. {
  260. Game.Attacking.FloorSpell.ClientFloorSpells FloorSpell;
  261. client.Entity.FloorSpells.TryRemove(spellclient.DBSkill.ID, out FloorSpell);
  262. }
  263. break;
  264. }
  265. #endregion
  266.  
  267. #region Habilidad FlameLotus
  268. case 12380://FlameLouts:
  269. {
  270. var spellclient = ID.Value;
  271. Queue<Game.Attacking.FloorSpell> RemoveSpells = new Queue<Game.Attacking.FloorSpell>();
  272. foreach (var spell in spellclient.Spells)
  273. {
  274. if (spellclient.CheckInvocke(Now, spell))
  275. {
  276. RemoveSpells.Enqueue(spell);
  277. spellclient.CreateMsgSpell(100);
  278. var attack = new Attack(true);
  279. attack.Attacker = client.Entity.UID;
  280. attack.AttackType = Attack.Magic;
  281. foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  282. {
  283. if (_obj == null) continue;
  284. if (_obj.MapObjType == MapObjectType.Monster)
  285. {
  286. var attacked = _obj as Entity;
  287. if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) <= 15)
  288. {
  289. if (!Game.Attacking.Handle.CanAttack(client.Entity, attacked, spell.DBSkill, false)) continue;
  290. attack.Effect1 = Attack.AttackEffects1.None;
  291. uint damage = Game.Attacking.Calculate.Magic(client.Entity, attacked, spell.DBSkill, ref attack);
  292.  
  293.  
  294. spellclient.SpellPacket.Effect1 = attack.Effect1;
  295. Game.Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell.DBSkill);
  296. spellclient.SpellPacket.AddTarget(attacked.UID, damage, attack);
  297. }
  298. }
  299. if (_obj.MapObjType == MapObjectType.Player)
  300. {
  301. var attacked = _obj as Entity;
  302. if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) <= 15)
  303. {
  304. if (!Game.Attacking.Handle.CanAttack(client.Entity, attacked, spell.DBSkill, false)) continue;
  305. attack.Effect1 = Attack.AttackEffects1.None;
  306. uint damage = Game.Attacking.Calculate.MagicPerfectos(client.Entity, attacked, spell.DBSkill, ref attack);
  307. damage = damage * 10;
  308. Console.WriteLine("FlameLotus DMG -> " + damage + "");
  309. attack.Damage = damage;
  310. spellclient.SpellPacket.Effect1 = attack.Effect1;
  311. Game.Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell.DBSkill);
  312. spellclient.SpellPacket.AddTarget(attacked.UID, damage, attack);
  313. }
  314. }
  315. }
  316. spellclient.SendView(client);
  317.  
  318. spell.FloorPacket.Type = FloorItem.RemoveEffect;
  319. client.SendScreen(spell.FloorPacket, true);
  320. }
  321. }
  322. while (RemoveSpells.Count > 0)
  323. spellclient.RemoveItem(RemoveSpells.Dequeue());
  324. if (spellclient.Spells.Count == 0)
  325. {
  326. Game.Attacking.FloorSpell.ClientFloorSpells FloorSpell;
  327. client.Entity.FloorSpells.TryRemove(spellclient.DBSkill.ID, out FloorSpell);
  328. }
  329. break;
  330. }
  331. #endregion
  332.  
  333. }
  334. }
  335. }
  336.  
  337.  
  338. }
  339. private static void monsterBuffersCallback(GameClient client, int time)
  340. {
  341. if (!client.Socket.Alive)
  342. {
  343. client.Screen.DisposeTimers();
  344. return;
  345. }
  346. if (client.Entity == null)
  347. return;
  348. if (client.Map == null)
  349. return;
  350. if (client.Map.FreezeMonsters)
  351. return;
  352. #region EpicWater/Fire
  353. if (Database.DataHolder.IsTaoist(client.Entity.Class))
  354. {
  355. var Date = DateTime.Now;
  356. if (client.Entity.LastGetEnergy.AddSeconds(1) <= Date)
  357. {
  358. if (client.Entity.EpicTaoist())
  359. {
  360. if (client.Entity.Class >= 130 && client.Entity.Class <= 135)
  361. {
  362. if (220 > client.Entity.Energy)
  363. {
  364. client.Entity.Energy += 1;
  365. }
  366. }
  367. else
  368. {
  369. if (client.Entity.Energy < 330)
  370. {
  371. client.Entity.Energy += 1;
  372. }
  373. }
  374. client.Entity.LastGetEnergy = Date;
  375. }
  376. else
  377. {
  378. if (client.Entity.ContainsFlag3((ulong)Update.Flags3.AuroraLotus))
  379. {
  380. client.Entity.RemoveFlag3((ulong)Update.Flags3.AuroraLotus);
  381. }
  382. if (client.Entity.ContainsFlag3((ulong)Update.Flags3.FlameLotus))
  383. {
  384. client.Entity.RemoveFlag3((ulong)Update.Flags3.FlameLotus);
  385. }
  386. if (client.Entity.Energy > 0)
  387. {
  388. client.Entity.Energy = 0;
  389. }
  390. }
  391. }
  392. }
  393. #endregion
  394. #region Stamina
  395. if (client.Entity.StaminaStamp.Next(1000, time: time))
  396. {
  397. if (client.Vigor < client.MaxVigor)
  398. {
  399. ushort amount = (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
  400. if (client.Vigor + amount > client.MaxVigor)
  401. {
  402. amount = client.MaxVigor;
  403. client.Vigor = amount;
  404. }
  405. else
  406. {
  407. client.Vigor += amount;
  408. }
  409. Vigor vigor = new Vigor(true);
  410. vigor.Amount = client.Vigor;
  411. vigor.Send(client);
  412. }
  413. if (!client.Entity.ContainsFlag((ulong)Update.Flags.Ride) && !client.Entity.ContainsFlag((ulong)Update.Flags.Fly) || client.Equipment.TryGetItem(18) != null)
  414. {
  415. if (Database.DataHolder.IsFire(client.Entity.Class))
  416. {
  417. if (!client.Entity.ContainsFlag3((ulong)Network.GamePackets.Update.Flags3.FlameLotus))
  418. {
  419. client.Entity.AddFlag3((ulong)Network.GamePackets.Update.Flags3.FlameLotus);
  420. }
  421. if (client.Entity.Energy <= 300)
  422. {
  423. if (client.Entity.Action == Enums.ConquerAction.Sit)
  424. {
  425. if (client.Entity.Energy <= 280)
  426. {
  427. client.Entity.Energy += 4;
  428. EpicTaoIcon Icon = new EpicTaoIcon(true);
  429. Icon.Energy = (uint)client.Entity.Energy;
  430. Icon.Send(client);
  431. }
  432. else
  433. {
  434. if (client.Entity.Energy != 300)
  435. client.Entity.Energy += 1;
  436. EpicTaoIcon Icon = new EpicTaoIcon(true);
  437. Icon.Energy = (uint)client.Entity.Energy;
  438. Icon.Send(client);
  439. }
  440. }
  441. }
  442. }
  443. if (Database.DataHolder.IsWater(client.Entity.Class))
  444. {
  445. if (!client.Entity.ContainsFlag3((ulong)Network.GamePackets.Update.Flags3.AuroraLotus))
  446. {
  447. client.Entity.AddFlag3((ulong)Network.GamePackets.Update.Flags3.AuroraLotus);
  448. }
  449. if (client.Entity.Energy <= 200)
  450. {
  451. if (client.Entity.Action == Enums.ConquerAction.Sit)
  452. {
  453. if (client.Entity.Energy <= 180)
  454. {
  455. client.Entity.Energy += 4;
  456. EpicTaoIcon Icon = new EpicTaoIcon(true);
  457. Icon.Energy = (uint)client.Entity.Energy;
  458. Icon.Send(client);
  459. }
  460. else
  461. {
  462. if (client.Entity.Energy != 200)
  463. client.Entity.Energy += 1;
  464. EpicTaoIcon Icon = new EpicTaoIcon(true);
  465. Icon.Energy = (uint)client.Entity.Energy;
  466. Icon.Send(client);
  467. }
  468. }
  469. }
  470. }
  471. }
  472. if (client.Entity.StaminaStamp.Next(2000, time: time))
  473. {
  474. int limit = 0;
  475. if (client.Entity.HeavenBlessing > 0)
  476. limit = 50;
  477. if (client.Spells != null)
  478. {
  479. if (client.Spells.ContainsKey(12560))
  480. {
  481. var spell = client.Spells[12560];
  482. var skill = Database.SpellTable.SpellInformations[12560][spell.Level];
  483. limit += (int)skill.Power;
  484. }
  485. }
  486.  
  487. if (client.Entity.Stamina != 100 + limit)
  488. {
  489. if (client.Entity.Action == Enums.ConquerAction.Sit)
  490. {
  491. if (client.Entity.Stamina <= 88 + limit)
  492. {
  493. if (client.Entity.ContainsFlag((ulong)Update.Flags.Ride))
  494. {
  495. client.Entity.Stamina += 20;
  496.  
  497. }
  498. client.Entity.Stamina += 12;
  499. }
  500. else
  501. {
  502. if (client.Entity.Stamina != 100 + limit)
  503. client.Entity.Stamina = (byte)(100 + limit);
  504. }
  505. }
  506. else
  507. {
  508. if (client.Entity.Stamina <= 92 + limit)
  509. {
  510. if (client.Entity.ContainsFlag((ulong)Update.Flags.Ride))
  511. {
  512. client.Entity.Stamina += 15;
  513.  
  514. }
  515. client.Entity.Stamina += 8;
  516. }
  517. else
  518. {
  519. if (client.Entity.Stamina != 100 + limit)
  520. client.Entity.Stamina = (byte)(100 + limit);
  521. }
  522. }
  523. }
  524. client.Entity.StaminaStamp = new Time64(time);
  525. }
  526. }
  527. #endregion
  528. #region JusticeChant
  529. #region Chaser
  530. if (client.Entity.ContainsFlag4((ulong)Update.Flags4.JusticeChant))
  531. {
  532. if (client.Entity.Windwalker != 0)
  533. {
  534. if (Time32.Now > client.Entity.JusticeChantStamp.AddSeconds(5))
  535. {
  536. if (client.Entity.Stamina != 100)
  537. {
  538. if (client.Entity.Action == Enums.ConquerAction.Sit)
  539. {
  540. if (client.Entity.Stamina <= 86)
  541. {
  542. client.Entity.Stamina += 14;
  543. }
  544. else
  545. {
  546. if (client.Entity.Stamina != 100)
  547. client.Entity.Stamina = (byte)(100);
  548. }
  549. }
  550. else
  551. {
  552. if (client.Entity.Stamina <= 92)
  553. {
  554. client.Entity.Stamina += 8;
  555. }
  556. else
  557. {
  558. if (client.Entity.Stamina != 100)
  559. client.Entity.Stamina = (byte)(100);
  560. }
  561. }
  562. }
  563. client.Entity.JusticeChantStamp = Time32.Now;
  564. }
  565. }
  566.  
  567. #endregion
  568. #region Stomper
  569. else
  570. {
  571. if (Time32.Now > client.Entity.JusticeChantStamp.AddSeconds(8))
  572. {
  573. if (client.Entity.Stamina != 100)
  574. {
  575. if (client.Entity.Action == Enums.ConquerAction.Sit)
  576. {
  577. if (client.Entity.Stamina <= 80)
  578. {
  579. client.Entity.Stamina += 20;
  580. }
  581. else
  582. {
  583. if (client.Entity.Stamina != 100)
  584. client.Entity.Stamina = (byte)(100);
  585. }
  586. }
  587. else
  588. {
  589. if (client.Entity.Stamina <= 80)
  590. {
  591. client.Entity.Stamina += 80;
  592. }
  593. else
  594. {
  595. if (client.Entity.Stamina != 100)
  596. client.Entity.Stamina = (byte)(100);
  597. }
  598. }
  599. }
  600. client.Entity.JusticeChantStamp = Time32.Now;
  601. }
  602. }
  603. }
  604. #endregion
  605. #endregion
  606. if (client.Map.ID == 8880 || client.Map.ID == 8881 || client.Map.ID == 1002)
  607. {
  608. SafeDictionary<uint, PokerTable> ToRem = new SafeDictionary<uint, PokerTable>(40);
  609. foreach (PokerTable T in PokerTables.Values)
  610. {
  611. if (client.Map.ID == T.Map)
  612. if (Kernel.GetDistance(T.X, T.Y, client.Entity.X, client.Entity.Y) > Constants.nScreenDistance)
  613. ToRem.Add(T.Id, T);
  614. }
  615. foreach (PokerTable T in ToRem.Values)
  616. if (PokerTables.ContainsKey(T.Id))
  617. PokerTables.Remove(T.Id);
  618. }
  619. foreach (IMapObject obj in client.Screen.Objects)
  620. {
  621. if (obj != null)
  622. {
  623. if (obj.MapObjType == MapObjectType.Monster)
  624. {
  625. Entity monster = obj as Entity;
  626. if (monster == null) continue;
  627.  
  628. if (monster.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  629. {
  630. if (monster.StigmaStamp.AddSeconds(monster.StigmaTime).Next(time: time) || monster.Dead)
  631. {
  632. monster.StigmaTime = 0;
  633. monster.StigmaIncrease = 0;
  634. monster.RemoveFlag(Update.Flags.Stigma);
  635. }
  636. }
  637. if (monster.ContainsFlag(Update.Flags.Dodge))
  638. {
  639. if (monster.DodgeStamp.AddSeconds(monster.DodgeTime).Next(time: time) || monster.Dead)
  640. {
  641. monster.DodgeTime = 0;
  642. monster.DodgeIncrease = 0;
  643. monster.RemoveFlag(Network.GamePackets.Update.Flags.Dodge);
  644. }
  645. }
  646. if (monster.ContainsFlag(Update.Flags.Invisibility))
  647. {
  648. if (monster.InvisibilityStamp.AddSeconds(monster.InvisibilityTime).Next(time: time) || monster.Dead)
  649. {
  650. monster.RemoveFlag(Update.Flags.Invisibility);
  651. }
  652. }
  653. if (monster.ContainsFlag(Update.Flags.StarOfAccuracy))
  654. {
  655. if (monster.StarOfAccuracyTime != 0)
  656. {
  657. if (monster.StarOfAccuracyStamp.AddSeconds(monster.StarOfAccuracyTime).Next(time: time) || monster.Dead)
  658. {
  659. monster.RemoveFlag(Update.Flags.StarOfAccuracy);
  660. }
  661. }
  662. else
  663. {
  664. if (monster.AccuracyStamp.AddSeconds(monster.AccuracyTime).Next(time: time) || monster.Dead)
  665. {
  666. monster.RemoveFlag(Update.Flags.StarOfAccuracy);
  667. }
  668. }
  669. }
  670. if (monster.ContainsFlag(Update.Flags.MagicShield))
  671. {
  672. if (monster.MagicShieldTime != 0)
  673. {
  674. if (monster.MagicShieldStamp.AddSeconds(monster.MagicShieldTime).Next(time: time) || monster.Dead)
  675. {
  676. monster.MagicShieldIncrease = 0;
  677. monster.MagicShieldTime = 0;
  678. monster.RemoveFlag(Update.Flags.MagicShield);
  679. }
  680. }
  681. else
  682. {
  683. if (monster.ShieldStamp.AddSeconds(monster.ShieldTime).Next(time: time) || monster.Dead)
  684. {
  685. monster.ShieldIncrease = 0;
  686. monster.ShieldTime = 0;
  687. monster.RemoveFlag(Update.Flags.MagicShield);
  688. }
  689. }
  690. }
  691. if (monster.Dead || monster.Killed)
  692. {
  693. if (!monster.ContainsFlag(Update.Flags.Ghost) || monster.Killed)
  694. {
  695. monster.Killed = false;
  696. monster.MonsterInfo.InSight = 0;
  697. monster.AddFlag(Network.GamePackets.Update.Flags.Ghost);
  698. monster.AddFlag(Network.GamePackets.Update.Flags.Dead);
  699. monster.AddFlag(Network.GamePackets.Update.Flags.FadeAway);
  700. Network.GamePackets.Attack attack = new Network.GamePackets.Attack(true);
  701. attack.Attacker = monster.Killer.UID;
  702. attack.Attacked = monster.UID;
  703. attack.AttackType = Network.GamePackets.Attack.Kill;
  704. attack.X = monster.X;
  705. attack.Y = monster.Y;
  706. client.Map.Floor[monster.X, monster.Y, MapObjectType.Monster, monster] = true;
  707. attack.KOCount = ++monster.Killer.KOCount;
  708. if (monster.Killer.EntityFlag == EntityFlag.Player)
  709. {
  710. monster.MonsterInfo.ExcludeFromSend = monster.Killer.UID;
  711. monster.Killer.Owner.Send(attack);
  712. }
  713. monster.MonsterInfo.SendScreen(attack);
  714. monster.MonsterInfo.ExcludeFromSend = 0;
  715. }
  716. if (monster.DeathStamp.AddSeconds(4).Next(time: time))
  717. {
  718. Data data = new Data(true);
  719. data.UID = monster.UID;
  720. data.ID = Network.GamePackets.Data.RemoveEntity;
  721. monster.MonsterInfo.SendScreen(data);
  722. }
  723. }
  724. }
  725. }
  726. }
  727. }
  728. #region OLD
  729. //private static void monsterBuffersCallback(GameClient client, int time)
  730. //{
  731. // if (!client.Socket.Alive)
  732. // {
  733. // client.Screen.DisposeTimers();
  734. // return;
  735. // }
  736. // if (client.Entity == null)
  737. // return;
  738. // if (client.Map == null)
  739. // return;
  740. // if (client.Map.FreezeMonsters)
  741. // return;
  742.  
  743. // #region Stamina
  744. // if (client.Entity.StaminaStamp.Next(500, time: time))
  745. // {
  746. // if (client.Vigor < client.Entity.ExtraVigor)
  747. // {
  748. // client.Vigor += (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
  749.  
  750. // {
  751. // Vigor vigor = new Vigor(true);
  752. // vigor.Amount = client.Vigor;
  753. // vigor.Send(client);
  754. // }
  755. // }
  756. // if (!client.Entity.ContainsFlag(Update.Flags.Ride) && !client.Entity.ContainsFlag(Update.Flags.Fly) || client.Equipment.TryGetItem(18) != null)
  757. // {
  758. // int limit = 0;
  759. // if (client.Entity.HeavenBlessing > 0)
  760. // limit = 50;
  761. // if (client.Entity.Stamina != 100 + limit)
  762. // {
  763. // if (client.Entity.Action == Enums.ConquerAction.Sit)
  764. // {
  765. // if (client.Entity.Stamina <= 93 + limit)
  766. // {
  767. // client.Entity.Stamina += 7;
  768. // }
  769. // else
  770. // {
  771. // if (client.Entity.Stamina != 100 + limit)
  772. // client.Entity.Stamina = (byte)(100 + limit);
  773. // }
  774. // }
  775. // else
  776. // {
  777. // if (client.Entity.Stamina <= 97 + limit)
  778. // {
  779. // client.Entity.Stamina += 3;
  780. // }
  781. // else
  782. // {
  783. // if (client.Entity.Stamina != 100 + limit)
  784. // client.Entity.Stamina = (byte)(100 + limit);
  785. // }
  786. // }
  787. // }
  788. // client.Entity.StaminaStamp = new Time64(time);
  789. // }
  790. // }
  791. // #endregion
  792. // #region Energia Epica Taoista Agua/Fuego
  793. // if (Database.DataHolder.IsTaoist(client.Entity.Class))
  794. // {
  795. // var Date = DateTime.Now;
  796. // if (client.Entity.LastGetEnergy.AddSeconds(1) <= Date)
  797. // {
  798. // if (client.Entity.EpicTaoist())
  799. // {
  800. // if (client.Entity.Class >= 130 && client.Entity.Class <= 135)
  801. // {
  802. // if (220 > client.Entity.Energy)
  803. // {
  804. // client.Entity.Energy += 4;
  805. // }
  806. // }
  807. // else
  808. // {
  809. // if (client.Entity.Energy < 330)
  810. // {
  811. // client.Entity.Energy += 7;
  812. // }
  813. // }
  814. // client.Entity.LastGetEnergy = Date;
  815. // }
  816. // else
  817. // {
  818. // if (client.Entity.ContainsFlag3((ulong)Update.Flags3.AuroraLotus))
  819. // {
  820. // client.Entity.RemoveFlag3((ulong)Update.Flags3.AuroraLotus);
  821. // }
  822. // if (client.Entity.ContainsFlag3((ulong)Update.Flags3.FlameLotus))
  823. // {
  824. // client.Entity.RemoveFlag3((ulong)Update.Flags3.FlameLotus);
  825. // }
  826. // if (client.Entity.Energy > 0)
  827. // {
  828. // client.Entity.Energy = 0;
  829. // }
  830. // }
  831. // }
  832. // }
  833. // #endregion
  834. // if (client.Map.ID == 8880 || client.Map.ID == 8881)
  835. // {
  836. // SafeDictionary<uint, PokerTable> ToRem = new SafeDictionary<uint, PokerTable>(40);
  837. // foreach (PokerTable T in PokerTables.Values)
  838. // {
  839. // if (client.Map.ID == T.Map)
  840. // if (Kernel.GetDistance(T.X, T.Y, client.Entity.X, client.Entity.Y) > Constants.nScreenDistance)
  841. // ToRem.Add(T.Id, T);
  842. // }
  843. // foreach (PokerTable T in ToRem.Values)
  844. // if (PokerTables.ContainsKey(T.Id))
  845. // PokerTables.Remove(T.Id);
  846. // }
  847. // foreach (IMapObject obj in client.Screen.Objects)
  848. // {
  849. // if (obj != null)
  850. // {
  851. // if (obj.MapObjType == MapObjectType.Monster)
  852. // {
  853. // Entity monster = obj as Entity;
  854. // if (monster == null) continue;
  855.  
  856. // if (monster.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  857. // {
  858. // if (monster.StigmaStamp.AddSeconds(monster.StigmaTime).Next(time: time) || monster.Dead)
  859. // {
  860. // monster.StigmaTime = 0;
  861. // monster.StigmaIncrease = 0;
  862. // monster.RemoveFlag(Update.Flags.Stigma);
  863. // }
  864. // }
  865. // if (monster.ContainsFlag(Update.Flags.Dodge))
  866. // {
  867. // if (monster.DodgeStamp.AddSeconds(monster.DodgeTime).Next(time: time) || monster.Dead)
  868. // {
  869. // monster.DodgeTime = 0;
  870. // monster.DodgeIncrease = 0;
  871. // monster.RemoveFlag(Network.GamePackets.Update.Flags.Dodge);
  872. // }
  873. // }
  874. // if (monster.ContainsFlag(Update.Flags.Invisibility))
  875. // {
  876. // if (monster.InvisibilityStamp.AddSeconds(monster.InvisibilityTime).Next(time: time) || monster.Dead)
  877. // {
  878. // monster.RemoveFlag(Update.Flags.Invisibility);
  879. // }
  880. // }
  881. // if (monster.ContainsFlag(Update.Flags.StarOfAccuracy))
  882. // {
  883. // if (monster.StarOfAccuracyTime != 0)
  884. // {
  885. // if (monster.StarOfAccuracyStamp.AddSeconds(monster.StarOfAccuracyTime).Next(time: time) || monster.Dead)
  886. // {
  887. // monster.RemoveFlag(Update.Flags.StarOfAccuracy);
  888. // }
  889. // }
  890. // else
  891. // {
  892. // if (monster.AccuracyStamp.AddSeconds(monster.AccuracyTime).Next(time: time) || monster.Dead)
  893. // {
  894. // monster.RemoveFlag(Update.Flags.StarOfAccuracy);
  895. // }
  896. // }
  897. // }
  898. // if (monster.ContainsFlag(Update.Flags.MagicShield))
  899. // {
  900. // if (monster.MagicShieldTime != 0)
  901. // {
  902. // if (monster.MagicShieldStamp.AddSeconds(monster.MagicShieldTime).Next(time: time) || monster.Dead)
  903. // {
  904. // monster.MagicShieldIncrease = 0;
  905. // monster.MagicShieldTime = 0;
  906. // monster.RemoveFlag(Update.Flags.MagicShield);
  907. // }
  908. // }
  909. // else
  910. // {
  911. // if (monster.ShieldStamp.AddSeconds(monster.ShieldTime).Next(time: time) || monster.Dead)
  912. // {
  913. // monster.ShieldIncrease = 0;
  914. // monster.ShieldTime = 0;
  915. // monster.RemoveFlag(Update.Flags.MagicShield);
  916. // }
  917. // }
  918. // }
  919. // if (monster.Dead || monster.Killed && monster.Killer != null)
  920. // {
  921. // if (!monster.ContainsFlag(Update.Flags.Ghost) || monster.Killed)
  922. // {
  923. // monster.Killed = false;
  924. // monster.MonsterInfo.InSight = 0;
  925. // monster.AddFlag(Network.GamePackets.Update.Flags.Ghost);
  926. // monster.AddFlag(Network.GamePackets.Update.Flags.Dead);
  927. // monster.AddFlag(Network.GamePackets.Update.Flags.FadeAway);
  928. // Network.GamePackets.Attack attack = new Network.GamePackets.Attack(true);
  929. // attack.Attacker = monster.Killer.UID;
  930. // attack.Attacked = monster.UID;
  931. // attack.AttackType = Network.GamePackets.Attack.Kill;
  932. // attack.X = monster.X;
  933. // attack.Y = monster.Y;
  934. // client.Map.Floor[monster.X, monster.Y, MapObjectType.Monster, monster] = true;
  935. // attack.KOCount = ++monster.Killer.KOCount;
  936. // if (monster.Killer.EntityFlag == EntityFlag.Player)
  937. // {
  938. // monster.MonsterInfo.ExcludeFromSend = monster.Killer.UID;
  939. // monster.Killer.Owner.Send(attack);
  940. // }
  941. // monster.MonsterInfo.SendScreen(attack);
  942. // monster.MonsterInfo.ExcludeFromSend = 0;
  943. // }
  944. // if (monster.DeathStamp.AddSeconds(4).Next(time: time))
  945. // {
  946. // Data data = new Data(true);
  947. // data.UID = monster.UID;
  948. // data.ID = Network.GamePackets.Data.RemoveEntity;
  949. // monster.MonsterInfo.SendScreen(data);
  950. // }
  951. // }
  952. // }
  953. // }
  954. // }
  955. //}
  956. #endregion
  957. private static void guardsCallback(GameClient client, int time)
  958. {
  959. if (!client.Socket.Alive)
  960. {
  961. client.Screen.DisposeTimers();
  962. return;
  963. }
  964. if (client.Entity == null)
  965. return;
  966. if (client.Map == null)
  967. return;
  968. if (client.Map.FreezeMonsters)
  969. return;
  970.  
  971. Time64 Now = new Time64(time);
  972. foreach (IMapObject obj in client.Screen.Objects)
  973. {
  974. if (obj != null)
  975. {
  976. if (obj.MapObjType == MapObjectType.Monster)
  977. {
  978. Entity monster = obj as Entity;
  979. if (monster.Companion) continue;
  980. if (monster.Dead || monster.Killed) continue;
  981.  
  982. if (monster.MonsterInfo.Guard)
  983. {
  984. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  985. {
  986. if (monster.MonsterInfo.InSight == 0)
  987. {
  988. if (monster.X != monster.MonsterInfo.BoundX || monster.Y != monster.MonsterInfo.BoundY)
  989. {
  990. monster.X = monster.MonsterInfo.BoundX;
  991. monster.Y = monster.MonsterInfo.BoundY;
  992. TwoMovements jump = new TwoMovements();
  993. jump.X = monster.MonsterInfo.BoundX;
  994. jump.Y = monster.MonsterInfo.BoundY;
  995. jump.EntityCount = 1;
  996. jump.FirstEntity = monster.UID;
  997. jump.MovementType = TwoMovements.Jump;
  998. client.SendScreen(jump, true);
  999. }
  1000. if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1001. monster.MonsterInfo.InSight = client.Entity.UID;
  1002. }
  1003. else
  1004. {
  1005. if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1006. {
  1007. if (monster.MonsterInfo.InSight == client.Entity.UID)
  1008. {
  1009. if (!client.Entity.Dead)
  1010. {
  1011. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  1012. {
  1013. short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  1014.  
  1015. if (distance <= monster.MonsterInfo.AttackRange)
  1016. {
  1017. monster.MonsterInfo.LastMove = Time64.Now;
  1018. new Game.Attacking.Handle(null, monster, client.Entity);
  1019. }
  1020. else
  1021. {
  1022. if (distance <= monster.MonsterInfo.ViewRange)
  1023. {
  1024. TwoMovements jump = new TwoMovements();
  1025. jump.X = client.Entity.X;
  1026. jump.Y = client.Entity.Y;
  1027. monster.X = client.Entity.X;
  1028. monster.Y = client.Entity.Y;
  1029. jump.EntityCount = 1;
  1030. jump.FirstEntity = monster.UID;
  1031. jump.MovementType = TwoMovements.Jump;
  1032. client.SendScreen(jump, true);
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. else
  1040. {
  1041. if (monster.MonsterInfo.InSight == client.Entity.UID)
  1042. {
  1043. monster.MonsterInfo.InSight = 0;
  1044. }
  1045. }
  1046. }
  1047.  
  1048. foreach (IMapObject obj2 in client.Screen.Objects)
  1049. {
  1050. if (obj2 == null) continue;
  1051. if (obj2.MapObjType == MapObjectType.Monster)
  1052. {
  1053. Entity monster2 = obj2 as Entity;
  1054.  
  1055. if (monster2 == null) continue;
  1056. if (monster2.Dead) continue;
  1057.  
  1058. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  1059. {
  1060. if (!monster2.MonsterInfo.Guard && (!monster2.Companion || monster2.Owner.Entity.ContainsFlag(Update.Flags.FlashingName)))
  1061. {
  1062. short distance = Kernel.GetDistance(monster.X, monster.Y, monster2.X, monster2.Y);
  1063.  
  1064. if (distance <= monster.MonsterInfo.AttackRange)
  1065. {
  1066. monster.MonsterInfo.LastMove = Time64.Now;
  1067. new Game.Attacking.Handle(null, monster, monster2);
  1068. }
  1069. }
  1070. }
  1071. }
  1072. }
  1073. }
  1074. }
  1075. }
  1076. }
  1077. }
  1078. }
  1079. private static void aliveMonstersCallback(GameClient client, int time)
  1080. {
  1081. if (!client.Socket.Alive)
  1082. {
  1083. client.Screen.DisposeTimers();
  1084. return;
  1085. }
  1086. if (client.Entity == null)
  1087. return;
  1088. if (client.Map == null)
  1089. return;
  1090. if (client.Map.FreezeMonsters)
  1091. return;
  1092.  
  1093. Time64 Now = new Time64(time);
  1094. foreach (IMapObject obj in client.Screen.Objects)
  1095. {
  1096. if (obj != null)
  1097. {
  1098. if (obj.MapObjType == MapObjectType.Monster)
  1099. {
  1100. Entity monster = obj as Entity;
  1101. if (monster == null) continue;
  1102. if (monster.MonsterInfo.Guard || monster.Companion || monster.Dead) continue;
  1103. short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  1104. if (distance > Constants.pScreenDistance)
  1105. {
  1106. client.Screen.Remove(obj);
  1107. continue;
  1108. }
  1109. if (monster.MonsterInfo.InSight != 0 && monster.MonsterInfo.InSight != client.Entity.UID)
  1110. {
  1111. if (monster.MonsterInfo.InSight > 1000000)
  1112. {
  1113. GameClient cl;
  1114. if (Kernel.GamePool.TryGetValue(monster.MonsterInfo.InSight, out cl))
  1115. {
  1116. short dst = Kernel.GetDistance(monster.X, monster.Y, cl.Entity.X, cl.Entity.Y);
  1117. if (dst > Constants.pScreenDistance)
  1118. monster.MonsterInfo.InSight = 0;
  1119. }
  1120. else
  1121. monster.MonsterInfo.InSight = 0;
  1122. }
  1123. else
  1124. {
  1125. Entity companion = client.Map.Companions[monster.MonsterInfo.InSight];
  1126. if (companion != null)
  1127. {
  1128. short dst = Kernel.GetDistance(monster.X, monster.Y, companion.X, companion.Y);
  1129. if (dst > Constants.pScreenDistance)
  1130. monster.MonsterInfo.InSight = 0;
  1131. }
  1132. else
  1133. monster.MonsterInfo.InSight = 0;
  1134. }
  1135. }
  1136. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  1137. {
  1138. if (distance <= Constants.pScreenDistance)
  1139. {
  1140.  
  1141. #region Companions
  1142. if (client.Companion != null)
  1143. {
  1144. if (client.Companion.Companion && !client.Companion.Dead)
  1145. {
  1146. short distance2 = Kernel.GetDistance(monster.X, monster.Y, client.Companion.X, client.Companion.Y);
  1147. if (distance > distance2 || client.Entity.ContainsFlag(Update.Flags.Invisibility) || client.Entity.ContainsFlag(Update.Flags.Fly))
  1148. {
  1149. if (monster.MonsterInfo.InSight == 0)
  1150. {
  1151. monster.MonsterInfo.InSight = client.Companion.UID;
  1152. }
  1153. else
  1154. {
  1155. if (monster.MonsterInfo.InSight == client.Companion.UID)
  1156. {
  1157. if (distance2 > Constants.pScreenDistance)
  1158. {
  1159. monster.MonsterInfo.InSight = 0;
  1160. }
  1161. else
  1162. {
  1163. if (distance2 <= monster.MonsterInfo.AttackRange)
  1164. {
  1165. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  1166. {
  1167. monster.MonsterInfo.LastMove = Time64.Now;
  1168. new Game.Attacking.Handle(null, monster, client.Companion);
  1169. continue;
  1170. }
  1171. }
  1172. else
  1173. {
  1174. if (distance2 > monster.MonsterInfo.ViewRange / 2)
  1175. {
  1176. if (distance2 < Constants.pScreenDistance)
  1177. {
  1178. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  1179. {
  1180. monster.MonsterInfo.LastMove = Time64.Now;
  1181.  
  1182. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Companion.X, client.Companion.Y);
  1183. if (!monster.Move(facing))
  1184. {
  1185. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  1186. if (monster.Move(facing))
  1187. {
  1188. monster.Facing = facing;
  1189. GroundMovement move = new GroundMovement(true);
  1190. move.Direction = facing;
  1191. move.UID = monster.UID;
  1192. move.Type = GroundMovement.Mode.Run;
  1193. monster.MonsterInfo.SendScreen(move);
  1194. continue;
  1195. }
  1196. }
  1197. else
  1198. {
  1199. monster.Facing = facing;
  1200. GroundMovement move = new GroundMovement(true);
  1201. move.Direction = facing;
  1202. move.UID = monster.UID;
  1203. move.Type = GroundMovement.Mode.Run;
  1204. monster.MonsterInfo.SendScreen(move);
  1205. continue;
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. monster.MonsterInfo.InSight = 0;
  1212. }
  1213. }
  1214. else
  1215. {
  1216. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  1217. {
  1218. monster.MonsterInfo.LastMove = Time64.Now;
  1219. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Companion.X, client.Companion.Y);
  1220. if (!monster.Move(facing))
  1221. {
  1222. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  1223. if (monster.Move(facing))
  1224. {
  1225. monster.Facing = facing;
  1226. GroundMovement move = new GroundMovement(true);
  1227. move.Direction = facing;
  1228. move.UID = monster.UID;
  1229. monster.MonsterInfo.SendScreen(move);
  1230. continue;
  1231. }
  1232. }
  1233. else
  1234. {
  1235. monster.Facing = facing;
  1236. GroundMovement move = new GroundMovement(true);
  1237. move.Direction = facing;
  1238. move.UID = monster.UID;
  1239. monster.MonsterInfo.SendScreen(move);
  1240. continue;
  1241. }
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. #endregion
  1252. #region Player
  1253. if (monster.MonsterInfo.InSight == 0)
  1254. {
  1255. if (distance <= monster.MonsterInfo.ViewRange)
  1256. {
  1257. if (!client.Entity.ContainsFlag(Update.Flags.Invisibility))
  1258. {
  1259. if (monster.MonsterInfo.SpellID != 0 || !client.Entity.ContainsFlag(Update.Flags.Fly))
  1260. {
  1261. monster.MonsterInfo.InSight = client.Entity.UID;
  1262. }
  1263. }
  1264. }
  1265. }
  1266. else
  1267. {
  1268. if (monster.MonsterInfo.InSight == client.Entity.UID)
  1269. {
  1270. if (monster.MonsterInfo.SpellID == 0 && client.Entity.ContainsFlag(Update.Flags.Fly))
  1271. {
  1272. monster.MonsterInfo.InSight = 0;
  1273. return;
  1274. }
  1275.  
  1276. if (client.Entity.Dead)
  1277. {
  1278. monster.MonsterInfo.InSight = 0;
  1279. return;
  1280. }
  1281. if (distance > Constants.pScreenDistance)
  1282. {
  1283. monster.MonsterInfo.InSight = 0;
  1284. }
  1285. else
  1286. {
  1287. if (distance <= monster.MonsterInfo.AttackRange)
  1288. {
  1289. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  1290. {
  1291. monster.MonsterInfo.LastMove = Time64.Now;
  1292. new Game.Attacking.Handle(null, monster, client.Entity);
  1293. }
  1294. }
  1295. else
  1296. {
  1297. if (distance > monster.MonsterInfo.ViewRange / 2)
  1298. {
  1299. if (distance < Constants.pScreenDistance)
  1300. {
  1301. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  1302. {
  1303. monster.MonsterInfo.LastMove = Time64.Now;
  1304.  
  1305. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  1306. if (!monster.Move(facing))
  1307. {
  1308. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  1309. if (monster.Move(facing))
  1310. {
  1311. monster.Facing = facing;
  1312. GroundMovement move = new GroundMovement(true);
  1313. move.Direction = facing;
  1314. move.UID = monster.UID;
  1315. move.Type = Network.GamePackets.GroundMovement.Mode.Run;
  1316. monster.MonsterInfo.SendScreen(move);
  1317. }
  1318. }
  1319. else
  1320. {
  1321. monster.Facing = facing;
  1322. GroundMovement move = new GroundMovement(true);
  1323. move.Direction = facing;
  1324. move.UID = monster.UID;
  1325. move.Type = Network.GamePackets.GroundMovement.Mode.Run;
  1326. monster.MonsterInfo.SendScreen(move);
  1327. }
  1328. }
  1329. }
  1330. else
  1331. {
  1332. monster.MonsterInfo.InSight = 0;
  1333. }
  1334. }
  1335. else
  1336. {
  1337. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  1338. {
  1339. monster.MonsterInfo.LastMove = Time64.Now;
  1340. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  1341. if (!monster.Move(facing))
  1342. {
  1343. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  1344. if (monster.Move(facing))
  1345. {
  1346. monster.Facing = facing;
  1347. GroundMovement move = new GroundMovement(true);
  1348. move.Direction = facing;
  1349. move.UID = monster.UID;
  1350. monster.MonsterInfo.SendScreen(move);
  1351. }
  1352. }
  1353. else
  1354. {
  1355. monster.Facing = facing;
  1356. GroundMovement move = new GroundMovement(true);
  1357. move.Direction = facing;
  1358. move.UID = monster.UID;
  1359. monster.MonsterInfo.SendScreen(move);
  1360. }
  1361. }
  1362. }
  1363. }
  1364. }
  1365. }
  1366. }
  1367. #endregion
  1368. }
  1369. }
  1370. }
  1371. else if (obj.MapObjType == MapObjectType.Item)
  1372. {
  1373. FloorItem item = obj as FloorItem;
  1374. if (item == null) continue;
  1375.  
  1376. if (item.Type == FloorItem.Effect)
  1377. {
  1378.  
  1379. #region Taoista Agua/Fuego
  1380. if (item.ItemID == FloorItem.FlameLotus || item.ItemID == FloorItem.AuroraLotus)
  1381. {
  1382. if (item.OnFloor.AddSeconds(12).Next(time: time))
  1383. {
  1384. IEnumerable<Client.GameClient> array = null;
  1385. Database.SpellInformation Spell = null;
  1386. if (item.ItemID == FloorItem.FlameLotus)
  1387. {
  1388. Spell = Database.SpellTable.GetSpell(12380, 6);
  1389. if (item.Owner.Team != null)
  1390. {
  1391. array = Kernel.GamePool.Values.Where
  1392. (x =>
  1393. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1394. x.Entity.Dead == true &&
  1395. item.Owner.Team.IsTeammate(x.Entity.UID)
  1396. );
  1397. }
  1398. else if (item.Owner.Guild != null)
  1399. {
  1400. array = Kernel.GamePool.Values.Where
  1401. (x =>
  1402. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1403. x.Entity.Dead == true && x.Entity.GuildID == item.Owner.Entity.GuildID
  1404. );
  1405. }
  1406. else if (item.Owner.Entity.GetClan != null)
  1407. {
  1408. array = Kernel.GamePool.Values.Where
  1409. (x =>
  1410. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1411. x.Entity.Dead == true && x.Entity.ClanId == item.Owner.Entity.ClanId
  1412. );
  1413. }
  1414. else
  1415. {
  1416. array = Kernel.GamePool.Values.Where
  1417. (x =>
  1418. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1419. x.Entity.Dead == true
  1420. );
  1421. }
  1422. }
  1423. if (item.ItemID == FloorItem.AuroraLotus)
  1424. {
  1425. Spell = Database.SpellTable.GetSpell(12370, 6);
  1426. if (item.Owner.Team != null)
  1427. {
  1428. array = Kernel.GamePool.Values.Where
  1429. (x =>
  1430. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1431. x.Entity.Dead == true &&
  1432. item.Owner.Team.IsTeammate(x.Entity.UID)
  1433. );
  1434. }
  1435. else if (item.Owner.Guild != null)
  1436. {
  1437. array = Kernel.GamePool.Values.Where
  1438. (x =>
  1439. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1440. x.Entity.Dead == true && x.Entity.GuildID == item.Owner.Entity.GuildID
  1441. );
  1442. }
  1443. else if (item.Owner.Entity.GetClan != null)
  1444. {
  1445. array = Kernel.GamePool.Values.Where
  1446. (x =>
  1447. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1448. x.Entity.Dead == true && x.Entity.ClanId == item.Owner.Entity.ClanId
  1449. );
  1450. }
  1451. else
  1452. {
  1453. array = Kernel.GamePool.Values.Where
  1454. (x =>
  1455. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1456. x.Entity.Dead == true
  1457. );
  1458. }
  1459. }
  1460. foreach (GameClient pClient in array)
  1461. {
  1462. if (pClient == null) return;
  1463. if (pClient.Entity == null) return;
  1464. if (pClient.Entity.UID != item.Owner.Entity.UID)
  1465. {
  1466. if (Spell.ID == 12370)
  1467. {
  1468. SpellUse suse = new SpellUse(true);
  1469. suse.Attacker = item.Owner.Entity.UID;
  1470. suse.SpellID = 1100;
  1471. suse.SpellLevel = 0;
  1472. suse.X = pClient.Entity.X;
  1473. suse.Y = pClient.Entity.Y;
  1474. suse.AddTarget(client.Entity.UID, 0, null);
  1475. pClient.Entity.Action =
  1476. Game.Enums.ConquerAction.None;
  1477. pClient.ReviveStamp = Time64.Now;
  1478. pClient.Attackable = false;
  1479. pClient.Entity.TransformationID = 0;
  1480. pClient.Entity.RemoveFlag((ulong)Update.Flags.Dead);
  1481. pClient.Entity.RemoveFlag((ulong)Update.Flags.Ghost);
  1482. pClient.Entity.Hitpoints = pClient.Entity.MaxHitpoints;
  1483. pClient.Entity.Ressurect();
  1484. pClient.SendScreen(suse, true);
  1485. //Stigma
  1486. pClient.Entity.AddFlag((ulong)Update.Flags.Stigma);
  1487. pClient.Entity.StigmaStamp = Time64.Now;
  1488. pClient.Entity.StigmaIncrease = 15;
  1489. pClient.Entity.StigmaTime = 80;
  1490. //Escudos
  1491. pClient.Entity.AddFlag((ulong)Update.Flags.MagicShield);
  1492. pClient.Entity.MagicShieldStamp = Time64.Now;
  1493. pClient.Entity.MagicShieldIncrease = 15;
  1494. pClient.Entity.MagicShieldTime = 80;
  1495. //Precision
  1496. pClient.Entity.AddFlag((ulong)Update.Flags.StarOfAccuracy);
  1497. pClient.Entity.StarOfAccuracyStamp = Time64.Now;
  1498. pClient.Entity.StarOfAccuracyTime = 80;
  1499. }
  1500. }
  1501. }
  1502. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1503. client.Map.RemoveFloorItem(item);
  1504. client.RemoveScreenSpawn(item, true);
  1505. }
  1506. }
  1507.  
  1508. #endregion
  1509. //if (item.ItemID >= FloorItem.DaggerStorm && item.ItemID <= 42)
  1510. if (item.ItemID >= FloorItem.DaggerStorm && item.ItemID <= 1044 || item.ItemID == FloorItem.Twilight)
  1511. {
  1512. if (item.Owner == client)
  1513. {
  1514. if (Time64.Now > item.UseTime.AddSeconds(1))
  1515. {
  1516. item.UseTime = Time64.Now;
  1517. var spell = Database.SpellTable.GetSpell(11600, client);
  1518.  
  1519. var attack = new Attack(true);
  1520. attack.Attacker = item.Owner.Entity.UID;
  1521. attack.AttackType = Attack.Melee;
  1522.  
  1523. foreach (var obj1 in client.Screen.Objects)
  1524. {
  1525. if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  1526. {
  1527. if (obj1.MapObjType == MapObjectType.Monster || obj1.MapObjType == MapObjectType.Player)
  1528. {
  1529. var attacked = obj1 as Entity;
  1530. if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  1531. {
  1532. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack)/2;
  1533.  
  1534. attack.Damage = damage;
  1535. attack.Attacked = attacked.UID;
  1536. attack.X = attacked.X;
  1537. attack.Y = attacked.Y;
  1538.  
  1539. Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell);
  1540. }
  1541. }
  1542. else if (obj1.MapObjType == MapObjectType.SobNpc)
  1543. {
  1544. var attacked = obj1 as SobNpcSpawn;
  1545. if (Attacking.Handle.CanAttack(client.Entity, attacked, spell))
  1546. {
  1547. uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, ref attack);
  1548. damage = (uint)(damage * spell.PowerPercent);
  1549.  
  1550. attack.Damage = damage;
  1551. attack.Attacked = attacked.UID;
  1552. attack.X = attacked.X;
  1553. attack.Y = attacked.Y;
  1554.  
  1555. Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell);
  1556. }
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. }
  1567. }
  1568. private static void itemsCallback(GameClient client, int time)
  1569. {
  1570. if (!client.Socket.Alive)
  1571. {
  1572. client.Screen.DisposeTimers();
  1573. return;
  1574. }
  1575. if (client.Entity == null)
  1576. return;
  1577. if (client.Map == null)
  1578. return;
  1579. if (client.Map.FreezeMonsters)
  1580. return;
  1581.  
  1582. Time64 Now = new Time64(time);
  1583. foreach (IMapObject obj in client.Screen.Objects)
  1584. {
  1585. if (obj != null)
  1586. {
  1587. if (obj.MapObjType == MapObjectType.Item)
  1588. {
  1589. FloorItem item = obj as FloorItem;
  1590. if (item == null) continue;
  1591.  
  1592. if (item.Type == FloorItem.Effect)
  1593. {
  1594. if (item.ItemID == FloorItem.InfroEcho)
  1595. {
  1596. if (item.OnFloor.AddSeconds(3).Next(time: time))
  1597. {
  1598. Attacking.Handle.InfroEcho(item);
  1599. }
  1600. if (item.OnFloor.AddSeconds(7).Next(time: time))
  1601. {
  1602. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1603. client.Map.RemoveFloorItem(item);
  1604. client.RemoveScreenSpawn(item, true);
  1605. client.Entity.FloorItems.Remove(item.UID);
  1606. client.Screen.Remove(item);
  1607. //client.SendScreen(item, true);
  1608. }
  1609. }
  1610. if (item.ItemID == FloorItem.HorrorofStomper)
  1611. {
  1612. if (item.OnFloor.AddSeconds(1).Next(time: time))
  1613. {
  1614. Game.Attacking.Handle.StomperMelee(item, 12990);
  1615. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1616. client.Map.RemoveFloorItem(item);
  1617. client.RemoveScreenSpawn(item, true);
  1618. }
  1619. }
  1620. if (item.ItemID == FloorItem.PeaceofStomper)
  1621. {
  1622. if (item.OnFloor.AddSeconds(2).Next(time: time))
  1623. {
  1624. Game.Attacking.Handle.StomperMelee(item, 13000);
  1625. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1626. client.Map.RemoveFloorItem(item);
  1627. client.RemoveScreenSpawn(item, true);
  1628. }
  1629. }
  1630. //if (item.ItemID >= FloorItem.DaggerStorm && item.ItemID <= 42)
  1631. if (item.ItemID >= FloorItem.DaggerStorm && item.ItemID <= 1044 || item.ItemID == FloorItem.Twilight)
  1632. {
  1633. if (item.OnFloor.AddSeconds(4).Next(time: time))
  1634. {
  1635. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1636. //client.SendScreen(item, true);
  1637. client.Map.RemoveFloorItem(item);
  1638. client.RemoveScreenSpawn(item, true);
  1639. }
  1640. }
  1641. if (item.ItemID == FloorItem.FlameLotus ||
  1642. item.ItemID == FloorItem.AuroraLotus)
  1643. {
  1644. if (item.OnFloor.AddSeconds(8).Next(time: time))
  1645. {
  1646. IEnumerable<Client.GameClient> array = null;
  1647. Database.SpellInformation Spell = null;
  1648. if (item.ItemID == FloorItem.FlameLotus)
  1649. {
  1650. Spell = Database.SpellTable.GetSpell(12380, 6);
  1651. if (item.Owner.Team != null)
  1652. {
  1653. array = Kernel.GamePool.Values.Where
  1654. (x =>
  1655. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1656. x.Entity.Dead == true &&
  1657. item.Owner.Team.IsTeammate(x.Entity.UID)
  1658. );
  1659. }
  1660. else if (item.Owner.Guild != null)
  1661. {
  1662. array = Kernel.GamePool.Values.Where
  1663. (x =>
  1664. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1665. x.Entity.Dead == true && x.Entity.GuildID == item.Owner.Entity.GuildID
  1666. );
  1667. }
  1668. else if (item.Owner.Entity.GetClan != null)
  1669. {
  1670. array = Kernel.GamePool.Values.Where
  1671. (x =>
  1672. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1673. x.Entity.Dead == true && x.Entity.ClanId == item.Owner.Entity.ClanId
  1674. );
  1675. }
  1676. else
  1677. {
  1678. array = Kernel.GamePool.Values.Where
  1679. (x =>
  1680. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1681. x.Entity.Dead == true
  1682. );
  1683. }
  1684. }
  1685.  
  1686. if (item.ItemID == FloorItem.AuroraLotus)
  1687. {
  1688. Spell = Database.SpellTable.GetSpell(12370, 6);
  1689. if (item.Owner.Team != null)
  1690. {
  1691. array = Kernel.GamePool.Values.Where
  1692. (x =>
  1693. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1694. x.Entity.Dead == true &&
  1695. item.Owner.Team.IsTeammate(x.Entity.UID)
  1696. );
  1697. }
  1698. else if (item.Owner.Guild != null)
  1699. {
  1700. array = Kernel.GamePool.Values.Where
  1701. (x =>
  1702. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1703. x.Entity.Dead == true && x.Entity.GuildID == item.Owner.Entity.GuildID
  1704. );
  1705. }
  1706. else if (item.Owner.Entity.GetClan != null)
  1707. {
  1708. array = Kernel.GamePool.Values.Where
  1709. (x =>
  1710. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1711. x.Entity.Dead == true && x.Entity.ClanId == item.Owner.Entity.ClanId
  1712. );
  1713. }
  1714. else
  1715. {
  1716. array = Kernel.GamePool.Values.Where
  1717. (x =>
  1718. Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1719. x.Entity.Dead == true
  1720. );
  1721. }
  1722. }
  1723. foreach (GameClient pClient in array)
  1724. {
  1725. Database.SpellInformation spell = null;
  1726. if (pClient == null) return;
  1727. if (pClient.Entity == null) return;
  1728. if (pClient.Entity.UID != item.Owner.Entity.UID)
  1729. {
  1730. if (Spell.ID == 12370)
  1731. {
  1732. SpellUse suse = new SpellUse(true);
  1733. suse.Attacker = item.Owner.Entity.UID;
  1734. suse.SpellID = 1100;
  1735. suse.SpellLevel = 0;
  1736. suse.X = pClient.Entity.X;
  1737. suse.Y = pClient.Entity.Y;
  1738. suse.AddTarget(pClient.Entity.UID, 0, null);
  1739. pClient.Entity.Action =
  1740. COServer.Game.Enums.ConquerAction.None;
  1741. pClient.ReviveStamp = Time64.Now;
  1742. pClient.Attackable = false;
  1743. pClient.Entity.TransformationID = 0;
  1744. pClient.Entity.RemoveFlag((ulong)Update.Flags.Dead);
  1745. pClient.Entity.RemoveFlag((ulong)Update.Flags.Ghost);
  1746. pClient.Entity.Hitpoints = pClient.Entity.MaxHitpoints;
  1747. pClient.Entity.Ressurect();
  1748. pClient.SendScreen(suse, true);
  1749. pClient.Entity.AddFlag((ulong)Update.Flags.Stigma);
  1750. pClient.Entity.AddFlag((ulong)Update.Flags.MagicShield);
  1751. pClient.Entity.AddFlag((ulong)Update.Flags.StarOfAccuracy);
  1752. pClient.Entity.StigmaStamp = Time64.Now;
  1753. pClient.Entity.StarOfAccuracyTime = 25;
  1754. pClient.Entity.StigmaTime = 25;
  1755. pClient.Entity.MagicShieldTime = 25;
  1756. pClient.Entity.StigmaIncrease = 15;
  1757. pClient.Entity.MagicShieldIncrease = 15;
  1758. pClient.Entity.ShieldTime = 0;
  1759. pClient.Entity.ShieldTime = 0;
  1760. pClient.Entity.AccuracyTime = 0;
  1761. pClient.Entity.AccuracyStamp = Time64.Now;
  1762. pClient.Entity.StarOfAccuracyStamp = Time64.Now;
  1763. pClient.Entity.ShieldStamp = Time64.Now;
  1764. pClient.Entity.MagicShieldStamp = Time64.Now;
  1765. if (pClient.Entity.EntityFlag == EntityFlag.Player)
  1766. //pClient.Player.Owner.Send(Constants.Shield(spell.PowerPercent, spell.Duration));
  1767. pClient.Entity.Owner.Send(Constants.Accuracy(spell.Duration));
  1768. pClient.Entity.Owner.Send(Constants.Stigma(spell.PowerPercent, spell.Duration));
  1769. }
  1770. }
  1771. }
  1772. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1773. client.Map.RemoveFloorItem(item);
  1774. client.RemoveScreenSpawn(item, true);
  1775. }
  1776. }
  1777. else
  1778. if (item.ItemID == FloorItem.AuroraLotus || item.ItemID == FloorItem.FlameLotus) return;
  1779. }
  1780. else
  1781. {
  1782. if (item.OnFloor.AddSeconds(Constants.FloorItemSeconds).Next(time: time))
  1783. {
  1784. item.Type = Network.GamePackets.FloorItem.Remove;
  1785. foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  1786. if (_obj != null)
  1787. if (_obj.MapObjType == MapObjectType.Player)
  1788. (_obj as Entity).Owner.Send(item);
  1789. client.Map.RemoveFloorItem(item);
  1790. client.Screen.Remove(item);
  1791. }
  1792. }
  1793. }
  1794. }
  1795. }
  1796. }
  1797.  
  1798. private IDisposable[] TimerSubscriptions;
  1799. private object DisposalSyncRoot;
  1800.  
  1801. private Interfaces.IMapObject[] _objects;
  1802. private static ConcurrentDictionary<uint, PokerTable> PokerTables;
  1803. public Interfaces.IMapObject[] Objects { get { return _objects; } }
  1804.  
  1805. private ConcurrentDictionary<uint, Interfaces.IMapObject> _objectDictionary;
  1806.  
  1807. public Client.GameClient Owner;
  1808.  
  1809. public Screen(Client.GameClient client)
  1810. {
  1811. Owner = client;
  1812. _objects = new Interfaces.IMapObject[0];
  1813. PokerTables = new ConcurrentDictionary<uint, PokerTable>();
  1814. _objectDictionary = new ConcurrentDictionary<uint, IMapObject>();
  1815.  
  1816. TimerSubscriptions = new IDisposable[]
  1817. {
  1818. MonsterBuffers.Add(client),
  1819. Guards.Add(client),
  1820. AliveMonsters.Add(client),
  1821. Items.Add(client),
  1822. FloorSpells.Add(client)
  1823. };
  1824. DisposalSyncRoot = new object();
  1825. }
  1826. ~Screen()
  1827. {
  1828. DisposeTimers();
  1829. Clear();
  1830. _objects = null;
  1831. _objectDictionary = null;
  1832. Owner = null;
  1833. }
  1834.  
  1835. public void DisposeTimers()
  1836. {
  1837. lock (DisposalSyncRoot)
  1838. {
  1839. if (TimerSubscriptions == null) return;
  1840. for (int i = 0; i < TimerSubscriptions.Length; i++)
  1841. {
  1842. if (TimerSubscriptions[i] != null)
  1843. {
  1844. TimerSubscriptions[i].Dispose();
  1845. TimerSubscriptions[i] = null;
  1846. }
  1847. }
  1848. }
  1849. }
  1850.  
  1851. private void updateBase()
  1852. {
  1853. _objects = _objectDictionary.Values.ToArray();
  1854. }
  1855.  
  1856. public bool Add(Interfaces.IMapObject _object)
  1857. {
  1858. if (_object == null) return false;
  1859.  
  1860. if (_objectDictionary.ContainsKey(_object.UID))
  1861. if (_objectDictionary[_object.UID] == null) // should never happen
  1862. _objectDictionary.Remove(_object.UID);
  1863.  
  1864. if (!_objectDictionary.ContainsKey(_object.UID))
  1865. {
  1866. if (Kernel.GetDistance(_object.X, _object.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.pScreenDistance)
  1867. {
  1868. _objectDictionary[_object.UID] = _object;
  1869. updateBase();
  1870. return true;
  1871. }
  1872. }
  1873. return false;
  1874. }
  1875. public bool Remove(Interfaces.IMapObject _object)
  1876. {
  1877. if (_object == null) return false;
  1878.  
  1879. if (_objectDictionary.Remove(_object.UID))
  1880. {
  1881. updateBase();
  1882. if (_object.MapObjType == MapObjectType.Item)
  1883. {
  1884. FloorItem item = _object as FloorItem;
  1885. if (item.Type >= FloorItem.Effect)
  1886. {
  1887. item.Type = FloorItem.RemoveEffect;
  1888. Owner.Send(item);
  1889. }
  1890. else
  1891. {
  1892. item.Type = FloorItem.Remove;
  1893. Owner.Send(item);
  1894. item.Type = FloorItem.Drop;
  1895. }
  1896. }
  1897. else if (_object.MapObjType == MapObjectType.Player)
  1898. {
  1899. Owner.Send(new Data(true)
  1900. {
  1901. UID = _object.UID,
  1902. ID = Network.GamePackets.Data.RemoveEntity
  1903. });
  1904. }
  1905. else if (_object.MapObjType == MapObjectType.StaticEntity)
  1906. {
  1907. Owner.Send(new Data(true)
  1908. {
  1909. UID = _object.UID,
  1910. ID = Network.GamePackets.Data.RemoveEntity
  1911. });
  1912. }
  1913. return true;
  1914. }
  1915. return false;
  1916. }
  1917.  
  1918. public bool TryGetValue(uint uid, out Entity entity)
  1919. {
  1920. entity = null;
  1921. Interfaces.IMapObject imo = null;
  1922. if (_objectDictionary.TryGetValue(uid, out imo))
  1923. {
  1924. if (imo == null)
  1925. {
  1926. _objectDictionary.Remove(uid);
  1927. updateBase();
  1928. return false;
  1929. }
  1930. if (imo is Entity)
  1931. {
  1932. entity = imo as Entity;
  1933. return true;
  1934. }
  1935. }
  1936. return false;
  1937. }
  1938. public bool GetRaceObject(Func<IMapObject, bool> predicate, out StaticEntity entity)
  1939. {
  1940. entity = null;
  1941. foreach (var obj in Objects)
  1942. if (obj is StaticEntity)
  1943. if (predicate(obj))
  1944. entity = obj as StaticEntity;
  1945. return entity != null;
  1946. }
  1947. public bool TryGetSob(uint uid, out SobNpcSpawn sob)
  1948. {
  1949. sob = null;
  1950. Interfaces.IMapObject imo = null;
  1951. if (_objectDictionary.TryGetValue(uid, out imo))
  1952. {
  1953. if (imo == null)
  1954. {
  1955. _objectDictionary.Remove(uid);
  1956. updateBase();
  1957. return false;
  1958. }
  1959. if (imo is SobNpcSpawn)
  1960. {
  1961. sob = imo as SobNpcSpawn;
  1962. return true;
  1963. }
  1964. }
  1965. return false;
  1966. }
  1967. public bool TryGetFloorItem(uint uid, out FloorItem item)
  1968. {
  1969. item = null;
  1970. Interfaces.IMapObject imo = null;
  1971. if (_objectDictionary.TryGetValue(uid, out imo))
  1972. {
  1973. if (imo == null)
  1974. {
  1975. _objectDictionary.Remove(uid);
  1976. updateBase();
  1977. return false;
  1978. }
  1979. if (imo is FloorItem)
  1980. {
  1981. item = imo as FloorItem;
  1982. return true;
  1983. }
  1984. }
  1985. return false;
  1986. }
  1987.  
  1988.  
  1989. public IEnumerable<T> Select<T>(MapObjectType type) where T : class
  1990. {
  1991. foreach (var obj in Objects)
  1992. if (obj != null)
  1993. if (obj.MapObjType == type)
  1994. yield return obj as T;
  1995. }
  1996. public IEnumerable<T> Where<T>(Func<IMapObject, bool> predicate) where T : class
  1997. {
  1998. foreach (var obj in Objects)
  1999. if (obj != null)
  2000. if (predicate(obj))
  2001. yield return obj as T;
  2002. }
  2003. public IEnumerable<T> SelectWhere<T>(MapObjectType type, Func<T, bool> predicate) where T : class
  2004. {
  2005. foreach (var obj in Objects)
  2006. if (obj != null)
  2007. if (obj.MapObjType == type)
  2008. if (predicate(obj as T))
  2009. yield return obj as T;
  2010. }
  2011.  
  2012.  
  2013. public bool Contains(Interfaces.IMapObject _object)
  2014. {
  2015. if (_object == null) return false;
  2016. return _objectDictionary.ContainsKey(_object.UID);
  2017. }
  2018. public bool Contains(uint uid)
  2019. {
  2020. return _objectDictionary.ContainsKey(uid);
  2021. }
  2022.  
  2023. public void CleanUp(Interfaces.IPacket spawnWith)
  2024. {
  2025. bool remove;
  2026. try
  2027. {
  2028. foreach (IMapObject Base in Objects)
  2029. {
  2030. if (Base == null) continue;
  2031. remove = false;
  2032. if (Base.MapObjType == MapObjectType.Monster)
  2033. {
  2034. if ((Base as Entity).Dead)
  2035. {
  2036. if (Time64.Now > (Base as Entity).DeathStamp.AddSeconds(8))
  2037. remove = true;
  2038. else
  2039. remove = false;
  2040. }
  2041. if (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance)
  2042. remove = true;
  2043. if (remove)
  2044. {
  2045. if ((Base as Entity).MonsterInfo.InSight == Owner.Entity.UID)
  2046. (Base as Entity).MonsterInfo.InSight = 0;
  2047. }
  2048. }
  2049. else if (Base.MapObjType == MapObjectType.Player)
  2050. {
  2051. if (remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.pScreenDistance))
  2052. {
  2053. GameClient pPlayer = Base.Owner as GameClient;
  2054. pPlayer.Screen.Remove(Owner.Entity);
  2055. }
  2056. }
  2057. else if (Base.MapObjType == MapObjectType.Item)
  2058. {
  2059. remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= 22);
  2060.  
  2061. }
  2062. else
  2063. {
  2064. remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance);
  2065. }
  2066. if (Base.MapID != Owner.Map.ID)
  2067. remove = true;
  2068. if (remove)
  2069. {
  2070. Remove(Base);
  2071. }
  2072. }
  2073. }
  2074. catch (Exception e) { Program.SaveException(e); }
  2075. }
  2076. public void FullWipe()
  2077. {
  2078. foreach (IMapObject Base in Objects)
  2079. {
  2080. if (Base == null) continue;
  2081.  
  2082. Data data = new Data(true);
  2083. data.UID = Base.UID;
  2084. data.ID = Network.GamePackets.Data.RemoveEntity;
  2085. Owner.Send(data);
  2086.  
  2087. if (Base.MapObjType == Game.MapObjectType.Player)
  2088. {
  2089. GameClient pPlayer = Base.Owner as GameClient;
  2090. pPlayer.Screen.Remove(Owner.Entity);
  2091. }
  2092. }
  2093. Clear();
  2094. }
  2095. public void Clear()
  2096. {
  2097. _objectDictionary.Clear();
  2098. _objects = new IMapObject[0];
  2099. }
  2100. public void Reload(Interfaces.IPacket spawnWith)
  2101. {
  2102. CleanUp(spawnWith);
  2103. try
  2104. {
  2105.  
  2106. foreach (GameClient pClient in Kernel.GamePool.Values)
  2107. {
  2108. if (pClient == null) return;
  2109. if (pClient.Entity == null) return;
  2110. if (Owner == null) return;
  2111. if (Owner.Entity == null) return;
  2112. if (pClient.Entity.UID != Owner.Entity.UID)
  2113. {
  2114. if (pClient.Map.ID == Owner.Map.ID)
  2115. {
  2116. short dist = Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, Owner.Entity.X, Owner.Entity.Y);
  2117. if (dist <= Constants.pScreenDistance && !Contains(pClient.Entity))
  2118. {
  2119. if (pClient.Guild != null)
  2120. pClient.Guild.SendName(Owner);
  2121. if (Owner.Guild != null)
  2122. Owner.Guild.SendName(pClient);
  2123. if (pClient.Entity.InteractionInProgress && pClient.Entity.InteractionWith != Owner.Entity.UID && pClient.Entity.InteractionSet)
  2124. {
  2125. if (pClient.Entity.Body == 1003 || pClient.Entity.Body == 1004)
  2126. {
  2127. if (pClient.Entity.InteractionX == pClient.Entity.X && pClient.Entity.Y == pClient.Entity.InteractionY)
  2128. {
  2129. Network.GamePackets.Attack atak = new COServer.Network.GamePackets.Attack(true);
  2130. atak.Attacker = pClient.Entity.UID;
  2131. atak.Attacked = pClient.Entity.InteractionWith;
  2132. atak.X = pClient.Entity.X;
  2133. atak.Y = pClient.Entity.Y;
  2134. atak.AttackType = 49;
  2135. atak.Damage = pClient.Entity.InteractionType;
  2136. Owner.Send(atak);
  2137. }
  2138. }
  2139. else
  2140. {
  2141. if (COServer.Kernel.GamePool.ContainsKey(pClient.Entity.InteractionWith))
  2142. {
  2143. Client.GameClient Cs = COServer.Kernel.GamePool[pClient.Entity.InteractionWith] as Client.GameClient;
  2144. if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  2145. {
  2146. Network.GamePackets.Attack atak = new COServer.Network.GamePackets.Attack(true);
  2147. atak.Attacker = pClient.Entity.UID;
  2148. atak.Attacked = pClient.Entity.InteractionWith;
  2149. atak.X = pClient.Entity.X;
  2150. atak.Y = pClient.Entity.Y;
  2151. atak.AttackType = 49;
  2152. atak.Damage = pClient.Entity.InteractionType;
  2153. Owner.Send(atak);
  2154. }
  2155. }
  2156. }
  2157. }
  2158. if (pClient.Map.BaseID == 700)
  2159. {
  2160. if (Owner.InQualifier())
  2161. {
  2162. if (pClient.InQualifier())
  2163. {
  2164. Owner.Entity.SendSpawn(pClient);
  2165. pClient.Entity.SendSpawn(Owner);
  2166. if (pClient.Guild != null)
  2167. Owner.Entity.SendSpawn(pClient, false);
  2168. if (Owner.Guild != null)
  2169. pClient.Entity.SendSpawn(Owner, false);
  2170. if (spawnWith != null)
  2171. pClient.Send(spawnWith);
  2172. }
  2173. else
  2174. {
  2175. Owner.Entity.SendSpawn(pClient);
  2176.  
  2177. if (pClient.Guild != null)
  2178. Owner.Entity.SendSpawn(pClient, false);
  2179. Add(pClient.Entity);
  2180. if (spawnWith != null)
  2181. pClient.Send(spawnWith);
  2182. }
  2183. }
  2184. else
  2185. {
  2186. if (pClient.InQualifier())
  2187. {
  2188. pClient.Entity.SendSpawn(Owner);
  2189. if (Owner.Guild != null)
  2190. pClient.Entity.SendSpawn(Owner, false);
  2191. pClient.Screen.Add(Owner.Entity);
  2192. if (spawnWith != null)
  2193. Owner.Send(spawnWith);
  2194. }
  2195. else
  2196. {
  2197. Owner.Entity.SendSpawn(pClient);
  2198. pClient.Entity.SendSpawn(Owner);
  2199.  
  2200. if (pClient.Guild != null)
  2201. Owner.Entity.SendSpawn(pClient, false);
  2202. if (Owner.Guild != null)
  2203. pClient.Entity.SendSpawn(Owner, false);
  2204.  
  2205. if (spawnWith != null)
  2206. pClient.Send(spawnWith);
  2207. }
  2208. }
  2209. }
  2210. else
  2211. {
  2212. Owner.Entity.SendSpawn(pClient);
  2213. pClient.Entity.SendSpawn(Owner);
  2214.  
  2215. if (pClient.Guild != null)
  2216. Owner.Entity.SendSpawn(pClient, false);
  2217. if (Owner.Guild != null)
  2218. pClient.Entity.SendSpawn(Owner, false);
  2219.  
  2220. if (spawnWith != null)
  2221. pClient.Send(spawnWith);
  2222. }
  2223. #region Other Pet & Clones
  2224.  
  2225. if (pClient.Pet.Pets.Count > 0)
  2226. {
  2227. foreach (var pet in pClient.Pet.Pets.Values)
  2228. {
  2229. if (pet == null) continue;
  2230. if (pet.Entity == null) continue;
  2231. if (Kernel.GetDistance(pet.Entity.X, pet.Entity.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(pet.Entity.UID))
  2232. {
  2233. if (!pet.Entity.Dead)
  2234. pet.Entity.SendSpawn(Owner);
  2235. }
  2236. }
  2237. }
  2238. #endregion
  2239. }
  2240. }
  2241. }
  2242. }
  2243. var Map = Owner.Map;
  2244. #region Npcs
  2245. foreach (Interfaces.INpc npc in Map.Npcs.Values)
  2246. {
  2247. if (npc == null) continue;
  2248. if (Kernel.GetDistance(npc.X, npc.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2249. if (Contains(npc.UID)) continue;
  2250. npc.SendSpawn(Owner, false);
  2251. }
  2252. #endregion
  2253. #region Items + map effects
  2254. foreach (var item in Map.FloorItems.Values)
  2255. {
  2256. if (item == null) continue;
  2257. if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2258. if (Contains(item.UID)) continue;
  2259. if (item.Type == FloorItem.Effect)
  2260. {
  2261. #region Taoista Agua/Fuego
  2262. if (item.ItemID == FloorItem.FlameLotus || item.ItemID == FloorItem.AuroraLotus)
  2263. {
  2264.  
  2265. if (item.OnFloor.AddSeconds(12).Next(time: Time32.Now.AllMilliseconds()))
  2266. {
  2267. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  2268. foreach (Interfaces.IMapObject _obj in Objects)
  2269. if (_obj != null)
  2270. if (_obj.MapObjType == MapObjectType.Player)
  2271. (_obj as Entity).Owner.Send(item);
  2272. Map.RemoveFloorItem(item);
  2273. }
  2274. else
  2275. item.SendSpawn(Owner, false);
  2276. }
  2277.  
  2278. #endregion
  2279. //if (item.ItemID >= FloorItem.DaggerStorm && item.ItemID <= 42)
  2280. if (item.ItemID >= FloorItem.DaggerStorm && item.ItemID <= 1044 || item.ItemID == FloorItem.Twilight)
  2281. {
  2282. if (item.OnFloor.AddSeconds(4).Next(time: Time32.Now.AllMilliseconds()))
  2283. {
  2284. item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  2285. foreach (Interfaces.IMapObject _obj in Objects)
  2286. if (_obj != null)
  2287. if (_obj.MapObjType == MapObjectType.Player)
  2288. (_obj as Entity).Owner.Send(item);
  2289. Map.RemoveFloorItem(item);
  2290. }
  2291. else
  2292. item.SendSpawn(Owner, false);
  2293. }
  2294. else
  2295. item.SendSpawn(Owner, false);
  2296. }
  2297. else
  2298. {
  2299. if ((Time64.Now > item.OnFloor.AddSeconds(Constants.FloorItemSeconds)) || item.PickedUpAlready)
  2300. {
  2301. item.Type = Network.GamePackets.FloorItem.Remove;
  2302. Map.RemoveFloorItem(item);
  2303. }
  2304. }
  2305. item.SendSpawn(Owner);
  2306. }
  2307. #endregion
  2308. foreach (Game.Entity monster in Map.Entities.Values)
  2309. {
  2310. if (monster == null) continue;
  2311. if (Kernel.GetDistance(monster.X, monster.Y, Owner.Entity.X, Owner.Entity.Y) <= 16 && !Contains(monster.UID))
  2312. {
  2313. if (!monster.Dead)
  2314. {
  2315. monster.SendSpawn(Owner, false);
  2316. if (monster.MaxHitpoints > 65535)
  2317. {
  2318. Update upd = new Update(true) { UID = monster.UID };
  2319. upd.Append(Update.MaxHitpoints, monster.MaxHitpoints);
  2320. upd.Append(Update.Hitpoints, monster.Hitpoints);
  2321. Owner.Send(upd);
  2322. }
  2323. }
  2324. }
  2325. }
  2326. #region RaceItems
  2327. if (Owner.Map.StaticEntities.Count != 0)
  2328. {
  2329. foreach (var item in Owner.Map.StaticEntities.Values)
  2330. {
  2331. if (item == null) continue;
  2332. if (!item.Viable) continue;
  2333. if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2334. if (Contains(item.UID)) continue;
  2335. item.SendSpawn(Owner);
  2336. }
  2337. }
  2338. #endregion
  2339. foreach (Game.Entity monster in Map.Companions.Values)
  2340. {
  2341. if (monster == null) continue;
  2342. if (Kernel.GetDistance(monster.X, monster.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(monster.UID))
  2343. {
  2344. if (!monster.Dead)
  2345. {
  2346. monster.SendSpawn(Owner);
  2347. }
  2348. }
  2349. }
  2350. if (Owner.Map.ID == 8880 || Owner.Map.ID == 8881)
  2351. {
  2352. foreach (Game.PokerTable T in Kernel.PokerTables.Values)
  2353. {
  2354. if (T.Map == Owner.Map.ID)
  2355. {
  2356. if (Kernel.GetDistance(T.X, T.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.nScreenDistance && !PokerTables.ContainsKey(T.Id))
  2357. {
  2358. Owner.Send(Game.PokerPackets.PokerTable(T));
  2359. PokerTables.Add(T.Id, T);
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. catch (Exception e) { Program.SaveException(e); }
  2366. }
  2367.  
  2368. public void SendScreen(Interfaces.IPacket buffer, bool self)
  2369. {
  2370. foreach (Interfaces.IMapObject _obj in Objects)
  2371. {
  2372. if (_obj != null)
  2373. {
  2374. if (_obj.UID != Owner.Entity.UID)
  2375. {
  2376. if (_obj.MapObjType == Game.MapObjectType.Player)
  2377. {
  2378. GameClient client = _obj.Owner as GameClient;
  2379. if (Owner.WatchingGroup != null && client.WatchingGroup == null)
  2380. continue;
  2381. if (Owner.TeamWatchingGroup != null && client.TeamWatchingGroup == null)
  2382. continue;
  2383. client.Send(buffer);
  2384. }
  2385. }
  2386. }
  2387. }
  2388.  
  2389. if (self)
  2390. Owner.Send(buffer);
  2391. }
  2392. }
  2393. }
  2394.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement