Advertisement
XConquer

AliveMonster

Nov 2nd, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.28 KB | None | 0 0
  1. private static void AliveMonstersCallback(GameState client, int time)
  2. {
  3. if (!client.Socket.IsAlive)
  4. {
  5. client.Screen.DisposeTimers();
  6. return;
  7. }
  8. if (client.Player == null)
  9. return;
  10. if (client.Map == null)
  11. return;
  12. if (client.Map.FreezeMonsters)
  13. return;
  14.  
  15. Time32 Now = new Time32(time);
  16. foreach (IMapObject obj in client.Screen.Objects)
  17. {
  18. if (obj != null)
  19. {
  20. if (obj.MapObjType == MapObjectType.Monster)
  21. {
  22. Entity monster = obj as Entity;
  23. if (monster == null) continue;
  24. if (monster.Name == "CasprGuard" && !monster.Dead)
  25. {
  26. if (client.Player.Dead && !client.Player.ContainsFlag2(Update.Flags2.SoulShackle))
  27. {
  28. if (MyMath.Success(50.0))
  29. {
  30. client.Player.BringToLife();
  31. SpellUse use = new SpellUse(true);
  32. use.Attacker = monster.UID;
  33. use.X = client.Player.X;
  34. use.Y = client.Player.Y;
  35. use.SpellID = 1100;
  36. use.AddTarget(client.Player, 0, null);
  37. Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
  38. if (MyMath.Success(50.0))
  39. {
  40. use = new SpellUse(true);
  41. use.Attacker = monster.UID;
  42. use.X = client.Player.X;
  43. use.Y = client.Player.Y;
  44. use.SpellID = 30000;
  45. use.AddTarget(client.Player, 0, null);
  46. Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
  47.  
  48. client.Player.AzureShieldDefence = (ushort)(3000 * 4);
  49. client.Player.AzureShieldLevel = 4;
  50. client.Player.MagicShieldStamp = Time32.Now;
  51.  
  52. client.Player.AzureShieldStamp = DateTime.Now;
  53. client.Player.AddFlag2(Update.Flags2.AzureShield);
  54. client.Player.MagicShieldTime = 60;
  55. client.Player.AzureShieldPacket();
  56.  
  57. if (client.Player.EntityFlag == EntityFlag.Entity)
  58. client.Send(Constants.Shield(12000, client.Player.MagicShieldTime));
  59. }
  60. else
  61. {
  62. use = new SpellUse(true);
  63. use.Attacker = monster.UID;
  64. use.X = client.Player.X;
  65. use.Y = client.Player.Y;
  66. use.SpellID = 6002;
  67. use.AddTarget(client.Player, 0, null);
  68. Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
  69.  
  70. client.Player.AddFlag2(Update.Flags2.EffectBall);
  71. client.Player.NoDrugsStamp = Time32.Now;
  72. client.Player.NoDrugsTime = (short)60;
  73. if (client.Player.EntityFlag == EntityFlag.Entity)
  74. client.Send(Constants.NoDrugs(60));
  75. }
  76. }
  77. else
  78. {
  79. SpellUse use = new SpellUse(true);
  80. use.Attacker = monster.UID;
  81. use.X = client.Player.X;
  82. use.Y = client.Player.Y;
  83. use.SpellID = 10405;
  84. use.AddTarget(client.Player, 0, null);
  85. Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
  86.  
  87. if (!client.Player.ContainsFlag2(Update.Flags2.SoulShackle))
  88. {
  89. client.Player.AddFlag2(Update.Flags2.SoulShackle);//Give them shackeld effect
  90. client.Player.ShackleStamp = Time32.Now;//Set stamp so source can remove the flag after X seconds
  91. client.Player.ShackleTime = 35;//(short)(30 + 15 * spell.Level);//double checking here. Could be db has this wrong.
  92. Network.GamePackets.Update upgrade = new Network.GamePackets.Update(true);
  93. upgrade.UID = client.Player.UID;
  94. upgrade.Append(Network.GamePackets.Update.SoulShackle
  95. , 111
  96. , 35, 0, 4);
  97. client.Player.Owner.Send(upgrade.ToArray());
  98.  
  99. if (client.Player.EntityFlag == EntityFlag.Entity)
  100. client.Send(Constants.Shackled(client.Player.ShackleTime));
  101. }
  102. }
  103. }
  104.  
  105. }
  106. if (monster.MonsterInfo.Guard || monster.Companion || monster.Dead) continue;
  107.  
  108. if (monster.MonsterInfo.Reviver)
  109. {
  110. if (client.Player.Dead && Now > client.Player.DeathStamp.AddSeconds(5))
  111. {
  112. client.Player.BringToLife();
  113. SpellUse use = new SpellUse(true);
  114. use.Attacker = monster.UID;
  115. use.X = client.Player.X;
  116. use.Y = client.Player.Y;
  117. use.SpellID = 1100;
  118. use.AddTarget(client.Player, 0, null);
  119. Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
  120. }
  121. return;
  122. }
  123. short distance = Kernel.GetDistance(monster.X, monster.Y, client.Player.X, client.Player.Y);
  124. if (distance > Constants.pScreenDistance)
  125. {
  126. client.Screen.Remove(obj);
  127. continue;
  128. }
  129. if (monster.MonsterInfo.InSight != 0 && monster.MonsterInfo.InSight != client.Player.UID)
  130. {
  131. if (monster.MonsterInfo.InSight > 1000000)
  132. {
  133. GameState cl;
  134. if (Kernel.GamePool.TryGetValue(monster.MonsterInfo.InSight, out cl))
  135. {
  136. short dst = Kernel.GetDistance(monster.X, monster.Y, cl.Player.X, cl.Player.Y);
  137. if (dst > Constants.pScreenDistance)
  138. monster.MonsterInfo.InSight = 0;
  139. }
  140. else
  141. monster.MonsterInfo.InSight = 0;
  142. }
  143. //else
  144. //{
  145. // Entity companion = client.Map.Companions[monster.MonsterInfo.InSight];
  146. // if (companion != null)
  147. // {
  148. // short dst = Kernel.GetDistance(monster.X, monster.Y, companion.X, companion.Y);
  149. // if (dst > Constants.pScreenDistance)
  150. // monster.MonsterInfo.InSight = 0;
  151. // }
  152. // else
  153. // monster.MonsterInfo.InSight = 0;
  154. //}
  155. }
  156. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  157. {
  158. if (distance <= Constants.pScreenDistance)
  159. {
  160. #region Companions
  161. foreach (var pet in client.Pet.Pets.Values)
  162. {
  163. if (pet != null)
  164. {
  165. #region Pets
  166. if (pet.Entity.Companion && !pet.Entity.Dead)
  167. {
  168. short distance2 = Kernel.GetDistance(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  169. if (distance > distance2 || client.Player.ContainsFlag(Update.Flags.Invisibility) || client.Player.ContainsFlag(Update.Flags.Fly))
  170. {
  171. if (monster.MonsterInfo.InSight == 0)
  172. {
  173. monster.MonsterInfo.InSight = pet.Entity.UID;
  174. }
  175. else
  176. {
  177. if (monster.MonsterInfo.InSight == pet.Entity.UID)
  178. {
  179. if (distance2 > Constants.pScreenDistance)
  180. {
  181. monster.MonsterInfo.InSight = 0;
  182. }
  183. else
  184. {
  185. if (distance2 <= monster.MonsterInfo.AttackRange)
  186. {
  187. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  188. {
  189. monster.MonsterInfo.LastMove = Time32.Now;
  190. new Game.Attacking.Handle(null, monster, pet.Entity);
  191. if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  192. {
  193. monster.MonsterInfo.Lastpop = Time32.Now;
  194.  
  195. continue;
  196. }
  197. }
  198. }
  199. else
  200. {
  201. if (distance2 > monster.MonsterInfo.ViewRange / 2)
  202. {
  203. if (distance2 < Constants.pScreenDistance)
  204. {
  205. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  206. {
  207. monster.MonsterInfo.LastMove = Time32.Now;
  208.  
  209. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  210. if (!monster.Move(facing))
  211. {
  212. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  213. if (monster.Move(facing))
  214. {
  215. monster.Facing = facing;
  216. GroundMovement move = new GroundMovement(true);
  217. move.Direction = facing;
  218. move.UID = monster.UID;
  219. move.GroundMovementType = GroundMovement.Run;
  220. monster.MonsterInfo.SendScreen(move);
  221. continue;
  222. }
  223. }
  224. else
  225. {
  226. monster.Facing = facing;
  227. GroundMovement move = new GroundMovement(true);
  228. move.Direction = facing;
  229. move.UID = monster.UID;
  230. move.GroundMovementType = GroundMovement.Run;
  231. monster.MonsterInfo.SendScreen(move);
  232. continue;
  233. }
  234. }
  235. }
  236. else
  237. {
  238. monster.MonsterInfo.InSight = 0;
  239. }
  240. }
  241. else
  242. {
  243. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  244. {
  245. monster.MonsterInfo.LastMove = Time32.Now;
  246. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  247. if (!monster.Move(facing))
  248. {
  249. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  250. if (monster.Move(facing))
  251. {
  252. monster.Facing = facing;
  253. GroundMovement move = new GroundMovement(true);
  254. move.Direction = facing;
  255. move.UID = monster.UID;
  256. monster.MonsterInfo.SendScreen(move);
  257. continue;
  258. }
  259. }
  260. else
  261. {
  262. monster.Facing = facing;
  263. GroundMovement move = new GroundMovement(true);
  264. move.Direction = facing;
  265. move.UID = monster.UID;
  266. monster.MonsterInfo.SendScreen(move);
  267. continue;
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. #endregion
  278. }
  279.  
  280. }
  281. #endregion
  282. #region Entity
  283. if (monster.MonsterInfo.InSight == 0)
  284. {
  285. if (distance <= monster.MonsterInfo.ViewRange)
  286. {
  287. if (!client.Player.ContainsFlag(Update.Flags.Invisibility))
  288. {
  289. if (monster.MonsterInfo.SpellID != 0 || !client.Player.ContainsFlag(Update.Flags.Fly))
  290. {
  291. monster.MonsterInfo.InSight = client.Player.UID;
  292. }
  293. }
  294. }
  295. }
  296. else
  297. {
  298. if (monster.MonsterInfo.InSight == client.Player.UID)
  299. {
  300. if (monster.MonsterInfo.SpellID == 0 && client.Player.ContainsFlag(Update.Flags.Fly))
  301. {
  302. monster.MonsterInfo.InSight = 0;
  303. return;
  304. }
  305.  
  306. if (client.Player.Dead)
  307. {
  308. monster.MonsterInfo.InSight = 0;
  309. return;
  310. }
  311. if (distance > Constants.pScreenDistance)
  312. {
  313. monster.MonsterInfo.InSight = 0;
  314. }
  315. else
  316. {
  317. if (distance <= monster.MonsterInfo.AttackRange)
  318. {
  319. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  320. {
  321. monster.MonsterInfo.LastMove = Time32.Now;
  322. new Game.Attacking.Handle(null, monster, client.Player);
  323. if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  324. {
  325. monster.MonsterInfo.Lastpop = Time32.Now;
  326. }
  327. }
  328. }
  329. else
  330. {
  331. if (distance > monster.MonsterInfo.ViewRange / 2)
  332. {
  333. if (distance < Constants.pScreenDistance)
  334. {
  335. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  336. {
  337. monster.MonsterInfo.LastMove = Time32.Now;
  338.  
  339. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Player.X, client.Player.Y);
  340. if (!monster.Move(facing))
  341. {
  342. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  343. if (monster.Move(facing))
  344. {
  345. monster.Facing = facing;
  346. GroundMovement move = new GroundMovement(true);
  347. move.Direction = facing;
  348. move.UID = monster.UID;
  349. move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  350. monster.MonsterInfo.SendScreen(move);
  351. }
  352. }
  353. else
  354. {
  355. monster.Facing = facing;
  356. GroundMovement move = new GroundMovement(true);
  357. move.Direction = facing;
  358. move.UID = monster.UID;
  359. move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  360. monster.MonsterInfo.SendScreen(move);
  361. }
  362. }
  363. }
  364. else
  365. {
  366. monster.MonsterInfo.InSight = 0;
  367. }
  368. }
  369. else
  370. {
  371. if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  372. {
  373. monster.MonsterInfo.LastMove = Time32.Now;
  374. Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Player.X, client.Player.Y);
  375. if (!monster.Move(facing))
  376. {
  377. facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  378. if (monster.Move(facing))
  379. {
  380. monster.Facing = facing;
  381. GroundMovement move = new GroundMovement(true);
  382. move.Direction = facing;
  383. move.UID = monster.UID;
  384. monster.MonsterInfo.SendScreen(move);
  385. }
  386. }
  387. else
  388. {
  389. monster.Facing = facing;
  390. GroundMovement move = new GroundMovement(true);
  391. move.Direction = facing;
  392. move.UID = monster.UID;
  393. monster.MonsterInfo.SendScreen(move);
  394. }
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. #endregion
  402. }
  403. }
  404. }
  405. else if (obj.MapObjType == MapObjectType.Item)
  406. {
  407. FloorItem item = obj as FloorItem;
  408. if (item == null) continue;
  409. //if (item.ItemID == FloorItem.InfernalEcho)
  410. //{
  411. // if (item.Owner == client)
  412. // {
  413. // if (item.OnFloor.AddSeconds(4).Next(time: time))
  414. // {
  415. // item.UseTime = Time32.Now;
  416. // var spell = Database.SpellTable.GetSpell(12550, client);
  417.  
  418. // var attack = new Attack(true);
  419. // attack.Attacker = item.Owner.Player.UID;
  420. // attack.AttackType = Attack.Melee;
  421.  
  422. // foreach (var obj1 in client.Screen.Objects)
  423. // {
  424. // if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 10)
  425. // {
  426. // if (obj1.MapObjType == MapObjectType.Entity && client.Player.PKMode != Enums.PKMode.Capture)
  427. // {
  428. // var attacked = obj1 as Entity;
  429. // if (Attacking.Handle.CanAttack(client.Player, attacked, spell, false))
  430. // {
  431. // uint damage = Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack);
  432. // damage = (uint)(damage * 1.4);
  433. // attack.Damage = damage;
  434. // attack.Attacked = attacked.UID;
  435. // attack.X = attacked.X;
  436. // attack.Y = attacked.Y;
  437. // attacked.Update(_String.Effect, "twz_xldy_gj", true);
  438.  
  439. // Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
  440. // }
  441. // }
  442. // if (obj1.MapObjType == MapObjectType.Monster)
  443. // {
  444. // var attacked = obj1 as Entity;
  445. // if (Attacking.Handle.CanAttack(client.Player, attacked, spell, false))
  446. // {
  447. // uint damage = Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack);
  448. // damage = (damage * 200) / 100;
  449. // attack.Damage = damage;
  450. // attack.Attacked = attacked.UID;
  451. // attack.X = attacked.X;
  452. // attack.Y = attacked.Y;
  453. // attacked.Update(_String.Effect, "twz_xldy_gj", true);
  454. // Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
  455. // }
  456. // }
  457. // }
  458. // }
  459. // }
  460. // }
  461. //}
  462. if (item.Type == FloorItem.Effect)
  463. {
  464. if (item.ItemID == FloorItem.RageOfWarTrap)
  465. {
  466. if (item.Owner == client)
  467. {
  468. if (item.OnFloor.AddSeconds(2).Next(time: time))
  469. {
  470. var spell = Database.SpellTable.GetSpell(12930, client);
  471. if (spell == null) return;
  472. var attack = new Attack(true);
  473. attack.Attacker = client.Player.UID;
  474. attack.AttackType = Attack.Melee;
  475.  
  476. foreach (var obj1 in client.Screen.Objects)
  477. {
  478. if (obj1 == null)
  479. continue;
  480. var attacked = obj1 as Entity;
  481. if (attacked == null) continue;
  482. if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  483. {
  484. if (Attacking.Handle.CanAttack(client.Player, attacked, spell, attack.AttackType == Attack.Melee))
  485. {
  486. uint damage = (uint)(Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack) * (spell.SecondDamage - 30000) / 100);
  487. attack.Effect1 = Attack.AttackEffects1.None;
  488. attack.Damage = damage;
  489. attack.Attacked = attacked.UID;
  490. attack.X = attacked.X;
  491. attack.Y = attacked.Y;
  492. attack.Effect1 = Attack.AttackEffects1.None;
  493. Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
  494.  
  495. }
  496.  
  497. }
  498. }
  499. }
  500. }
  501. }
  502. if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce)
  503. {
  504. if (item.Owner == client)
  505. {
  506. if (Time32.Now > item.UseTime.AddSeconds(1))
  507. {
  508. item.UseTime = Time32.Now;
  509. var spell = Database.SpellTable.GetSpell(11600, client);
  510.  
  511. var attack = new Attack(true);
  512. attack.Attacker = item.Owner.Player.UID;
  513. attack.AttackType = Attack.Melee;
  514.  
  515. foreach (var obj1 in client.Screen.Objects)
  516. {
  517. if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  518. {
  519. if (obj1.MapObjType == MapObjectType.Monster || obj1.MapObjType == MapObjectType.Entity)
  520. {
  521. var attacked = obj1 as Entity;
  522. if (Attacking.Handle.CanAttack(client.Player, attacked, spell, false))
  523. {
  524. uint damage = Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack);
  525.  
  526. attack.Damage = damage;
  527. attack.Attacked = attacked.UID;
  528. attack.X = attacked.X;
  529. attack.Y = attacked.Y;
  530.  
  531. Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
  532. }
  533. }
  534. else if (obj1.MapObjType == MapObjectType.SobNpc)
  535. {
  536. var attacked = obj1 as SobNpcSpawn;
  537. if (Attacking.Handle.CanAttack(client.Player, attacked, spell))
  538. {
  539. uint damage = Game.Attacking.Calculate.Melee(client.Player, attacked, ref attack);
  540. attack.Damage = damage;
  541. attack.Attacked = attacked.UID;
  542. attack.X = attacked.X;
  543. attack.Y = attacked.Y;
  544.  
  545. Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, damage, spell);
  546. }
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. }
  557. }
  558. =======================================
  559.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement