WitchDoctor.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 WitchDoctor : MonsterObject
  8. {
  9. public long FearTime;
  10. public byte AttackRange = 6;
  11. protected internal WitchDoctor(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. if (Envir.Random.Next(5) == 0)
  28. {
  29. TeleportRandom(10, AttackRange);
  30. }
  31. else
  32. {
  33. var hpPercent = (HP * 100) / Stats[Stat.HP];
  34. if (Envir.Random.Next(3) == 0 && hpPercent < 50)
  35. {
  36. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 0 });
  37. ActionTime = Envir.Time + 300;
  38. AttackTime = Envir.Time + AttackSpeed;
  39. ChangeHP(Stats[Stat.HP] / 4);
  40. }
  41. else
  42. {
  43. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  44. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  45. ActionTime = Envir.Time + 300;
  46. AttackTime = Envir.Time + AttackSpeed;
  47. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  48. if (damage == 0) return;
  49. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  50. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MACAgility);
  51. ActionList.Add(action);
  52. }
  53. }
  54. }
  55. protected override void ProcessTarget()
  56. {
  57. if (Target == null || !CanAttack) return;
  58. if (InAttackRange() && Envir.Time < FearTime)
  59. {
  60. Attack();
  61. return;
  62. }
  63. FearTime = Envir.Time + 5000;
  64. if (Envir.Time < ShockTime)
  65. {
  66. Target = null;
  67. return;
  68. }
  69. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  70. if (dist >= AttackRange)
  71. MoveTo(Target.CurrentLocation);
  72. else
  73. {
  74. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  75. if (Walk(dir)) return;
  76. switch (Envir.Random.Next(2)) //No favour
  77. {
  78. case 0:
  79. for (int i = 0; i < 7; i++)
  80. {
  81. dir = Functions.NextDir(dir);
  82. if (Walk(dir))
  83. return;
  84. }
  85. break;
  86. default:
  87. for (int i = 0; i < 7; i++)
  88. {
  89. dir = Functions.PreviousDir(dir);
  90. if (Walk(dir))
  91. return;
  92. }
  93. break;
  94. }
  95. }
  96. }
  97. public override bool TeleportRandom(int attempts, int distance, Map temp = null)
  98. {
  99. if (Target == null) return false;
  100. for (int i = 0; i < attempts; i++)
  101. {
  102. Point location;
  103. location = new Point(Target.CurrentLocation.X + Envir.Random.Next(-distance, distance + 1),
  104. Target.CurrentLocation.Y + Envir.Random.Next(-distance, distance + 1));
  105. if (Teleport(CurrentMap, location, true, 5)) return true;
  106. }
  107. return false;
  108. }
  109. }
  110. }