KingHydrax.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class KingHydrax : MonsterObject
  6. {
  7. protected internal KingHydrax(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. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  30. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  31. if (damage == 0) return;
  32. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility);
  33. ActionList.Add(action);
  34. }
  35. else
  36. {
  37. if (Envir.Random.Next(2) == 0)
  38. {
  39. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  40. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  41. if (damage == 0) return;
  42. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MACAgility, false);
  43. ActionList.Add(action);
  44. }
  45. else
  46. {
  47. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 1 });
  48. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  49. if (damage == 0) return;
  50. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  51. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MACAgility, true);
  52. ActionList.Add(action);
  53. }
  54. }
  55. }
  56. protected override void CompleteRangeAttack(IList<object> data)
  57. {
  58. MapObject target = (MapObject)data[0];
  59. int damage = (int)data[1];
  60. DefenceType defence = (DefenceType)data[2];
  61. bool poison = (bool)data[3];
  62. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  63. if (target.Attacked(this, damage, defence) <= 0) return;
  64. if (poison)
  65. {
  66. PoisonTarget(target, 2, 10, PoisonType.Green, 1000);
  67. }
  68. else
  69. {
  70. PoisonTarget(target, 3, 10, PoisonType.Paralysis, 1000);
  71. }
  72. }
  73. protected override void ProcessTarget()
  74. {
  75. if (Target == null) return;
  76. if (InAttackRange() && CanAttack)
  77. {
  78. Attack();
  79. return;
  80. }
  81. if (Envir.Time < ShockTime)
  82. {
  83. Target = null;
  84. return;
  85. }
  86. MoveTo(Target.CurrentLocation);
  87. }
  88. public override void Die()
  89. {
  90. ActionList.Add(new DelayedAction(DelayedType.Die, Envir.Time + 1000));
  91. base.Die();
  92. }
  93. protected override void CompleteDeath(IList<object> data)
  94. {
  95. SpawnSlaves();
  96. }
  97. private void SpawnSlaves()
  98. {
  99. for (int i = 0; i < 2; i++)
  100. {
  101. var mob = GetMonster(Envir.GetMonsterInfo(Settings.KingHydraxMob));
  102. if (mob == null) continue;
  103. if (!mob.Spawn(CurrentMap, Front))
  104. mob.Spawn(CurrentMap, CurrentLocation);
  105. mob.Target = Target;
  106. mob.ActionTime = Envir.Time + 2000;
  107. }
  108. }
  109. }
  110. }