FlameScythe.cs 3.5 KB

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