Khazard.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class Khazard : MonsterObject
  7. {
  8. public long PullTime;
  9. public bool Range;
  10. protected internal Khazard(MonsterInfo info)
  11. : base(info)
  12. {
  13. PullTime = Envir.Time;
  14. }
  15. protected bool CanPull
  16. {
  17. get
  18. {
  19. return Range && Envir.Time >= PullTime;
  20. }
  21. }
  22. protected override bool InAttackRange()
  23. {
  24. if (Target.CurrentMap != CurrentMap) return false;
  25. if (Target.CurrentLocation == CurrentLocation) return false;
  26. int x = Math.Abs(Target.CurrentLocation.X - CurrentLocation.X);
  27. int y = Math.Abs(Target.CurrentLocation.Y - CurrentLocation.Y);
  28. if (x > 4 || y > 4) return false;
  29. bool targetinrange = (x == 0) || (y == 0) || (x == y);
  30. if (!targetinrange) return false;
  31. Range = (x > 1 || y > 1) ? true : false;
  32. return (!Range || CanPull) ? true : false;
  33. }
  34. protected override void Attack()
  35. {
  36. if (!Target.IsAttackTarget(this))
  37. {
  38. Target = null;
  39. return;
  40. }
  41. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  42. if (Range && CanPull)
  43. {
  44. PullAttack();
  45. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  46. ActionTime = Envir.Time + 300;
  47. AttackTime = Envir.Time + AttackSpeed;
  48. PullTime = Envir.Time + 5000;
  49. }
  50. else
  51. {
  52. if (!Range) base.Attack();
  53. }
  54. }
  55. private void PullAttack()
  56. {
  57. for (int i = 1; i <= 4; i++)
  58. {
  59. Point target = Functions.PointMove(CurrentLocation, Direction, i);
  60. if (target == Target.CurrentLocation)
  61. {
  62. if (Envir.Random.Next(Settings.MagicResistWeight) < Target.Stats[Stat.MagicResist]) continue;
  63. MirDirection pushdir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  64. Target.Pushed(this, pushdir, i);
  65. }
  66. }
  67. }
  68. protected override void ProcessTarget()
  69. {
  70. if (Target == null) return;
  71. if (InAttackRange() && CanAttack)
  72. {
  73. Attack();
  74. if (Target.Dead)
  75. FindTarget();
  76. return;
  77. }
  78. if (Envir.Time < ShockTime)
  79. {
  80. Target = null;
  81. return;
  82. }
  83. MoveTo(Target.CurrentLocation);
  84. }
  85. }
  86. }