ChieftainArcher.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. //TODO - Has a retreat Animation, can't get motion accurate
  7. public class ChieftainArcher : MonsterObject
  8. {
  9. public long FearTime;
  10. protected virtual byte AttackRange
  11. {
  12. get
  13. {
  14. return 6;
  15. }
  16. }
  17. protected internal ChieftainArcher(MonsterInfo info)
  18. : base(info)
  19. {
  20. }
  21. protected override bool InAttackRange()
  22. {
  23. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  24. }
  25. protected override void Attack()
  26. {
  27. if (!Target.IsAttackTarget(this))
  28. {
  29. Target = null;
  30. return;
  31. }
  32. ShockTime = 0;
  33. byte level = (byte)Envir.Random.Next(0, 3);
  34. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  35. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0, Level = level });
  36. ActionTime = Envir.Time + 300;
  37. AttackTime = Envir.Time + AttackSpeed;
  38. int damage = 0;
  39. switch (level)
  40. {
  41. case 0:
  42. default:
  43. damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  44. break;
  45. case 1:
  46. damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  47. break;
  48. case 2:
  49. damage = GetAttackPower(Stats[Stat.MinSC], Stats[Stat.MaxSC]);
  50. break;
  51. }
  52. if (damage == 0) return;
  53. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500;
  54. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.ACAgility, level);
  55. ActionList.Add(action);
  56. }
  57. protected override void ProcessTarget()
  58. {
  59. if (Target == null || !CanAttack) return;
  60. if (InAttackRange() && Envir.Time < FearTime)
  61. {
  62. Attack();
  63. return;
  64. }
  65. FearTime = Envir.Time + 5000;
  66. if (Envir.Time < ShockTime)
  67. {
  68. Target = null;
  69. return;
  70. }
  71. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  72. if (dist >= AttackRange)
  73. MoveTo(Target.CurrentLocation);
  74. else
  75. {
  76. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  77. if (Walk(dir)) return;
  78. switch (Envir.Random.Next(2)) //No favour
  79. {
  80. case 0:
  81. for (int i = 0; i < 7; i++)
  82. {
  83. dir = Functions.NextDir(dir);
  84. if (Walk(dir))
  85. return;
  86. }
  87. break;
  88. default:
  89. for (int i = 0; i < 7; i++)
  90. {
  91. dir = Functions.PreviousDir(dir);
  92. if (Walk(dir))
  93. return;
  94. }
  95. break;
  96. }
  97. }
  98. }
  99. protected override void CompleteRangeAttack(IList<object> data)
  100. {
  101. MapObject target = (MapObject)data[0];
  102. int damage = (int)data[1];
  103. DefenceType defence = (DefenceType)data[2];
  104. byte level = (byte)data[3];
  105. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  106. if (target.Attacked(this, damage, defence) <= 0) return;
  107. if (level == 2)
  108. {
  109. target.Pushed(this, Direction, 1);
  110. }
  111. }
  112. }
  113. }