RestlessJar.cs 5.5 KB

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