FlameSpear.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class FlameSpear : MonsterObject
  7. {
  8. public long FearTime;
  9. public byte AttackRange = 4;
  10. protected internal FlameSpear(MonsterInfo info)
  11. : base(info)
  12. {
  13. }
  14. protected override bool InAttackRange()
  15. {
  16. if (Target.CurrentMap != CurrentMap) return false;
  17. if (Target.CurrentLocation == CurrentLocation) return false;
  18. int x = Math.Abs(Target.CurrentLocation.X - CurrentLocation.X);
  19. int y = Math.Abs(Target.CurrentLocation.Y - CurrentLocation.Y);
  20. if (x > AttackRange || y > AttackRange) return false;
  21. return (x == 0) || (y == 0) || (x == y);
  22. }
  23. protected override void Attack()
  24. {
  25. ShockTime = 0;
  26. if (!Target.IsAttackTarget(this))
  27. {
  28. Target = null;
  29. return;
  30. }
  31. AttackTime = Envir.Time + AttackSpeed;
  32. ActionTime = Envir.Time + 300;
  33. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  34. if (Functions.InRange(Target.CurrentLocation, CurrentLocation, 1))
  35. {
  36. base.Attack();
  37. }
  38. else
  39. {
  40. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  41. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  42. if (damage == 0) return;
  43. LineAttack(damage, 4, 300, DefenceType.MACAgility);
  44. }
  45. }
  46. protected override void ProcessTarget()
  47. {
  48. if (Target == null || !CanAttack) return;
  49. if (InAttackRange() && Envir.Time < FearTime)
  50. {
  51. Attack();
  52. return;
  53. }
  54. FearTime = Envir.Time + 5000;
  55. if (Envir.Time < ShockTime)
  56. {
  57. Target = null;
  58. return;
  59. }
  60. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  61. if (dist >= AttackRange)
  62. MoveTo(Target.CurrentLocation);
  63. else
  64. {
  65. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  66. if (Walk(dir)) return;
  67. switch (Envir.Random.Next(2)) //No favour
  68. {
  69. case 0:
  70. for (int i = 0; i < 7; i++)
  71. {
  72. dir = Functions.NextDir(dir);
  73. if (Walk(dir))
  74. return;
  75. }
  76. break;
  77. default:
  78. for (int i = 0; i < 7; i++)
  79. {
  80. dir = Functions.PreviousDir(dir);
  81. if (Walk(dir))
  82. return;
  83. }
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. }