AntCommander.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class AntCommander : MonsterObject
  6. {
  7. protected internal AntCommander(MonsterInfo info)
  8. : base(info)
  9. {
  10. }
  11. protected override bool InAttackRange()
  12. {
  13. return CurrentMap == Target.CurrentMap && CanFly(Target.CurrentLocation) && Functions.InRange(CurrentLocation, Target.CurrentLocation, Info.ViewRange);
  14. }
  15. protected override void Attack()
  16. {
  17. if (!Target.IsAttackTarget(this))
  18. {
  19. Target = null;
  20. return;
  21. }
  22. ShockTime = 0;
  23. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  24. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  25. ActionTime = Envir.Time + 300;
  26. AttackTime = Envir.Time + AttackSpeed;
  27. if (!ranged)
  28. {
  29. switch (Envir.Random.Next(6))
  30. {
  31. case 0:
  32. case 3:
  33. case 4:
  34. {
  35. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  36. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  37. if (damage == 0) return;
  38. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility, false);
  39. ActionList.Add(action);
  40. }
  41. break;
  42. case 1:
  43. case 5:
  44. {
  45. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  46. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]) * 2;
  47. if (damage == 0) return;
  48. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 600, Target, damage, DefenceType.ACAgility, true);
  49. ActionList.Add(action);
  50. }
  51. break;
  52. case 2:
  53. {
  54. AttackTime = Envir.Time + AttackSpeed + 500;
  55. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  56. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  57. if (damage == 0) return;
  58. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  59. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MACAgility, true);
  60. ActionList.Add(action);
  61. }
  62. break;
  63. }
  64. }
  65. else
  66. {
  67. AttackTime = Envir.Time + AttackSpeed + 500;
  68. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  69. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  70. if (damage == 0) return;
  71. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  72. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MACAgility, true);
  73. ActionList.Add(action);
  74. }
  75. }
  76. protected override void CompleteRangeAttack(IList<object> data)
  77. {
  78. MapObject target = (MapObject)data[0];
  79. int damage = (int)data[1];
  80. DefenceType defence = (DefenceType)data[2];
  81. bool poison = (bool)data[3];
  82. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  83. var finalDamage = target.Attacked(this, damage, defence);
  84. if (finalDamage > 0 && poison)
  85. {
  86. PoisonTarget(target, 5, 7, PoisonType.Green, 1000);
  87. }
  88. }
  89. protected override void CompleteAttack(IList<object> data)
  90. {
  91. MapObject target = (MapObject)data[0];
  92. int damage = (int)data[1];
  93. DefenceType defence = (DefenceType)data[2];
  94. bool poison = (bool)data[3];
  95. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  96. if (target.Attacked(this, damage, defence) <= 0) return;
  97. var finalDamage = target.Attacked(this, damage, defence);
  98. if (finalDamage > 0 && poison)
  99. {
  100. PoisonTarget(target, 4, 5, PoisonType.Slow, 1000);
  101. PoisonTarget(target, 2, 5, PoisonType.Dazed, 1000);
  102. }
  103. }
  104. protected override void ProcessTarget()
  105. {
  106. if (Target == null) return;
  107. if (InAttackRange() && CanAttack)
  108. {
  109. Attack();
  110. return;
  111. }
  112. if (Envir.Time < ShockTime)
  113. {
  114. Target = null;
  115. return;
  116. }
  117. MoveTo(Target.CurrentLocation);
  118. }
  119. }
  120. }