KingGuard.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class KingGuard : MonsterObject
  7. {
  8. protected virtual byte AttackRange
  9. {
  10. get
  11. {
  12. return 10;
  13. }
  14. }
  15. protected internal KingGuard(MonsterInfo info)
  16. : base(info)
  17. {
  18. }
  19. protected override bool InAttackRange()
  20. {
  21. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  22. }
  23. protected override void Attack()
  24. {
  25. if (!Target.IsAttackTarget(this))
  26. {
  27. Target = null;
  28. return;
  29. }
  30. ShockTime = 0;
  31. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  32. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  33. ActionTime = Envir.Time + 300;
  34. AttackTime = Envir.Time + AttackSpeed;
  35. if (!ranged && Envir.Random.Next(3) > 0)
  36. {
  37. if (Envir.Random.Next(5) > 0)
  38. {
  39. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  40. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  41. if (damage == 0) return;
  42. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.ACAgility, false);
  43. ActionList.Add(action);
  44. }
  45. else
  46. {
  47. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  48. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC] * 2);
  49. if (damage == 0) return;
  50. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.AC, true);
  51. ActionList.Add(action);
  52. }
  53. }
  54. else
  55. {
  56. if (Envir.Random.Next(3) > 0)
  57. {
  58. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  59. AttackTime = Envir.Time + AttackSpeed + 500;
  60. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  61. if (damage == 0) return;
  62. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MAC, false);
  63. ActionList.Add(action);
  64. }
  65. else
  66. {
  67. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 1 });
  68. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC] * 2);
  69. if (damage == 0) return;
  70. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MAC, true);
  71. ActionList.Add(action);
  72. }
  73. }
  74. }
  75. protected override void CompleteAttack(IList<object> data)
  76. {
  77. MapObject target = (MapObject)data[0];
  78. int damage = (int)data[1];
  79. DefenceType defence = (DefenceType)data[2];
  80. bool aoe = (bool)data[3];
  81. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  82. if (aoe)
  83. {
  84. List<MapObject> targets = FindAllTargets(3, CurrentLocation);
  85. if (targets.Count == 0) return;
  86. for (int i = 0; i < targets.Count; i++)
  87. {
  88. if (targets[i].Attacked(this, damage, defence) <= 0) continue;
  89. }
  90. }
  91. else
  92. {
  93. if (target.Attacked(this, damage, defence) <= 0) return;
  94. }
  95. }
  96. protected override void CompleteRangeAttack(IList<object> data)
  97. {
  98. MapObject target = (MapObject)data[0];
  99. int damage = (int)data[1];
  100. DefenceType defence = (DefenceType)data[2];
  101. bool aoe = (bool)data[3];
  102. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  103. if (aoe)
  104. {
  105. List<MapObject> targets = FindAllTargets(AttackRange, CurrentLocation);
  106. if (targets.Count == 0) return;
  107. for (int i = 0; i < targets.Count; i++)
  108. {
  109. if (targets[i].Attacked(this, damage, defence) <= 0) continue;
  110. if (Envir.Random.Next(3) >= 0)
  111. {
  112. Broadcast(new S.ObjectEffect { ObjectID = targets[i].ObjectID, Effect = SpellEffect.KingGuard, EffectType = 0 });
  113. PoisonTarget(targets[i], 5, 10, PoisonType.Slow, 1000);
  114. }
  115. else
  116. {
  117. Broadcast(new S.ObjectEffect { ObjectID = targets[i].ObjectID, Effect = SpellEffect.KingGuard, EffectType = 1 });
  118. PoisonTarget(targets[i], 5, 10, PoisonType.Paralysis, 1000);
  119. }
  120. }
  121. }
  122. else
  123. {
  124. if (target.Attacked(this, damage, defence) <= 0) return;
  125. PoisonTarget(target, 10, 5, PoisonType.Green, 1000);
  126. }
  127. }
  128. protected override void ProcessTarget()
  129. {
  130. if (Target == null) return;
  131. if (InAttackRange() && CanAttack)
  132. {
  133. Attack();
  134. return;
  135. }
  136. if (Envir.Time < ShockTime)
  137. {
  138. Target = null;
  139. return;
  140. }
  141. MoveTo(Target.CurrentLocation);
  142. }
  143. }
  144. }