AvengingWarrior.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class AvengingWarrior : MonsterObject
  6. {
  7. public byte AttackRange = 6;
  8. protected internal AvengingWarrior(MonsterInfo info)
  9. : base(info)
  10. {
  11. }
  12. protected override bool InAttackRange()
  13. {
  14. return CurrentMap == Target.CurrentMap && CanFly(Target.CurrentLocation) && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  15. }
  16. protected override void Attack()
  17. {
  18. if (!Target.IsAttackTarget(this))
  19. {
  20. Target = null;
  21. return;
  22. }
  23. ShockTime = 0;
  24. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  25. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  26. ActionTime = Envir.Time + 300;
  27. AttackTime = Envir.Time + AttackSpeed;
  28. if (!ranged && Envir.Random.Next(5) > 0)
  29. {
  30. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  31. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  32. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 400, Target, damage, DefenceType.ACAgility, false);
  33. ActionList.Add(action);
  34. }
  35. else
  36. {
  37. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  38. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  39. if (damage == 0) return;
  40. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  41. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MACAgility);
  42. ActionList.Add(action);
  43. }
  44. }
  45. protected override void CompleteRangeAttack(IList<object> data)
  46. {
  47. MapObject target = (MapObject)data[0];
  48. int damage = (int)data[1];
  49. DefenceType defence = (DefenceType)data[2];
  50. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  51. if (target.Attacked(this, damage, defence) <= 0) return;
  52. PoisonTarget(target, 5, 8, PoisonType.Red);
  53. }
  54. protected override void ProcessTarget()
  55. {
  56. if (Target == null) return;
  57. if (InAttackRange() && CanAttack)
  58. {
  59. Attack();
  60. return;
  61. }
  62. if (Envir.Time < ShockTime)
  63. {
  64. Target = null;
  65. return;
  66. }
  67. MoveTo(Target.CurrentLocation);
  68. }
  69. }
  70. }