OmaKing.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class OmaKing : MonsterObject
  7. {
  8. public byte AttackRange = 7;
  9. protected internal OmaKing(MonsterInfo info)
  10. : base(info)
  11. {
  12. }
  13. protected override bool InAttackRange()
  14. {
  15. if (Target.CurrentMap != CurrentMap) return false;
  16. if (Target.CurrentLocation == CurrentLocation) return false;
  17. int x = Math.Abs(Target.CurrentLocation.X - CurrentLocation.X);
  18. int y = Math.Abs(Target.CurrentLocation.Y - CurrentLocation.Y);
  19. if (x > 2 || y > 2) return false;
  20. return (x <= 1 && y <= 1) || (x == y || x % 2 == y % 2);
  21. }
  22. protected bool InRangedAttackRange()
  23. {
  24. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  25. }
  26. protected override void CompleteAttack(IList<object> data)
  27. {
  28. int damage = (int)data[1];
  29. DefenceType defence = (DefenceType)data[2];
  30. List<MapObject> targets = FindAllTargets(AttackRange, CurrentLocation);
  31. if (targets.Count == 0) return;
  32. for (int i = 0; i < targets.Count; i++)
  33. {
  34. Target = targets[i];
  35. if (Target == null || !Target.IsAttackTarget(this) || Target.CurrentMap != CurrentMap || Target.Node == null) continue;
  36. Target.Attacked(this, damage, defence);
  37. }
  38. }
  39. protected override void Attack()
  40. {
  41. if (!Target.IsAttackTarget(this))
  42. {
  43. Target = null;
  44. return;
  45. }
  46. ShockTime = 0;
  47. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  48. bool ranged = CurrentLocation == Target.CurrentLocation || !InAttackRange();
  49. ActionTime = Envir.Time + 300;
  50. AttackTime = Envir.Time + AttackSpeed;
  51. if (!ranged && Envir.Random.Next(3) > 0)
  52. {
  53. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  54. List<MapObject> targets = FindAllTargets(1, CurrentLocation);
  55. if (targets.Count == 0) return;
  56. int levelgap;
  57. for (int i = 0; i < targets.Count; i++)
  58. {
  59. if (targets[i].IsAttackTarget(this))
  60. {
  61. levelgap = 60 - targets[i].Level;
  62. if (Envir.Random.Next(20) < 4 + levelgap)
  63. {
  64. if (Envir.Random.Next(Settings.MagicResistWeight) < targets[i].Stats[Stat.MagicResist]) continue;
  65. if (targets[i].Pushed(this, Functions.DirectionFromPoint(CurrentLocation, targets[i].CurrentLocation), 3 + Envir.Random.Next(3)) > 0
  66. && Envir.Random.Next(8) == 0)
  67. {
  68. PoisonTarget(targets[i], 1, 5, PoisonType.Paralysis, 1000, true);
  69. }
  70. }
  71. }
  72. }
  73. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  74. if (damage == 0) return;
  75. LineAttack(damage, 2, 300, DefenceType.ACAgility);
  76. }
  77. else
  78. {
  79. AttackTime = Envir.Time + AttackSpeed + 500;
  80. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  81. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  82. if (damage == 0) return;
  83. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.MAC);
  84. ActionList.Add(action);
  85. }
  86. }
  87. protected override void ProcessTarget()
  88. {
  89. if (Target == null) return;
  90. if (InRangedAttackRange() && CanAttack)
  91. {
  92. Attack();
  93. return;
  94. }
  95. if (Envir.Time < ShockTime)
  96. {
  97. Target = null;
  98. return;
  99. }
  100. MoveTo(Target.CurrentLocation);
  101. }
  102. }
  103. }