Doe.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class Doe : MonsterObject
  7. {
  8. public long FearTime;
  9. public long teleportTime = 5000;
  10. protected internal Doe(MonsterInfo info)
  11. : base(info)
  12. {
  13. }
  14. protected override void ProcessTarget()
  15. {
  16. if (Target == null || !CanAttack) return;
  17. if (Envir.Time < FearTime)
  18. {
  19. Attack();
  20. return;
  21. }
  22. FearTime = Envir.Time + 5000;
  23. var hpPercent = (HP * 100) / Stats[Stat.HP];
  24. bool halfHealth = hpPercent <= 50;
  25. if(halfHealth == true && Envir.Time > teleportTime)
  26. {
  27. TeleportRandom(1, 5, CurrentMap);
  28. }
  29. if (Envir.Time < ShockTime)
  30. {
  31. Target = null;
  32. return;
  33. }
  34. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  35. if (dist >= Info.ViewRange)
  36. MoveTo(Target.CurrentLocation);
  37. else
  38. {
  39. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  40. if (Walk(dir)) return;
  41. switch (Envir.Random.Next(2)) //No favour
  42. {
  43. case 0:
  44. for (int i = 0; i < 7; i++)
  45. {
  46. dir = Functions.NextDir(dir);
  47. if (Walk(dir))
  48. return;
  49. }
  50. break;
  51. default:
  52. for (int i = 0; i < 7; i++)
  53. {
  54. dir = Functions.PreviousDir(dir);
  55. if (Walk(dir))
  56. return;
  57. }
  58. break;
  59. }
  60. }
  61. }
  62. public override bool TeleportRandom(int attempts, int distance, Map temp = null)
  63. {
  64. for (int i = 0; i < attempts; i++)
  65. {
  66. Point location;
  67. if (distance <= 0)
  68. location = new Point(Envir.Random.Next(CurrentMap.Width), Envir.Random.Next(CurrentMap.Height));
  69. else
  70. location = new Point(CurrentLocation.X + Envir.Random.Next(-distance, distance + 1),
  71. CurrentLocation.Y + Envir.Random.Next(-distance, distance + 1));
  72. if (Teleport(CurrentMap, location, true, 9)) return true;
  73. }
  74. return false;
  75. }
  76. }
  77. }