RedFoxman.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. namespace Server.MirObjects.Monsters
  6. {
  7. public class RedFoxman : MonsterObject
  8. {
  9. public long FearTime, TeleportTime;
  10. public byte AttackRange = 6;
  11. protected internal RedFoxman(MonsterInfo info)
  12. : base(info)
  13. {
  14. }
  15. protected override bool InAttackRange()
  16. {
  17. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  18. }
  19. protected override void Attack()
  20. {
  21. if (!Target.IsAttackTarget(this))
  22. {
  23. Target = null;
  24. return;
  25. }
  26. ShockTime = 0;
  27. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  28. byte spelltype = Envir.Random.Next(2) == 0 ? (byte)0 : (byte)1;
  29. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = spelltype });
  30. ActionTime = Envir.Time + 300;
  31. AttackTime = Envir.Time + AttackSpeed;
  32. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  33. if (damage == 0) return;
  34. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MAC);
  35. ActionList.Add(action);
  36. }
  37. protected override void ProcessTarget()
  38. {
  39. if (Target == null || !CanAttack) return;
  40. if (InAttackRange() && (Envir.Time < FearTime))
  41. {
  42. if (Functions.InRange(CurrentLocation, Target.CurrentLocation, 1) && Envir.Time > TeleportTime && Envir.Random.Next(1) == 0)
  43. {
  44. TeleportTime = Envir.Time + 10000;
  45. TeleportRandom(40, 14);
  46. return;
  47. }
  48. else
  49. {
  50. Attack();
  51. return;
  52. }
  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. public override bool TeleportRandom(int attempts, int distance, Map temp = null)
  89. {
  90. for (int i = 0; i < attempts; i++)
  91. {
  92. Point location;
  93. if (distance <= 0)
  94. location = new Point(Envir.Random.Next(CurrentMap.Width), Envir.Random.Next(CurrentMap.Height));
  95. else
  96. location = new Point(CurrentLocation.X + Envir.Random.Next(-distance, distance + 1),
  97. CurrentLocation.Y + Envir.Random.Next(-distance, distance + 1));
  98. if (Teleport(CurrentMap, location, true, 2)) return true;
  99. }
  100. return false;
  101. }
  102. }
  103. }