ElementGuard.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class ElementGuard : MonsterObject
  6. {
  7. protected internal ElementGuard(MonsterInfo info)
  8. : base(info)
  9. {
  10. }
  11. protected override bool InAttackRange()
  12. {
  13. return CurrentMap == Target.CurrentMap && 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 + 300, Target, damage, DefenceType.MAC, true);
  33. ActionList.Add(action);
  34. }
  35. else
  36. {
  37. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  38. AttackTime = Envir.Time + AttackSpeed + 500;
  39. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  40. if (damage == 0) return;
  41. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MAC, false);
  42. ActionList.Add(action);
  43. }
  44. }
  45. protected override void CompleteAttack(IList<object> data)
  46. {
  47. MapObject target = (MapObject)data[0];
  48. int damage = (int)data[1];
  49. DefenceType defence = (DefenceType)data[2];
  50. bool poison = (bool)data[3];
  51. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  52. if (target.Attacked(this, damage, defence) <= 0) return;
  53. if (poison)
  54. {
  55. PoisonTarget(target, 5, 5, PoisonType.Red, 1000);
  56. }
  57. }
  58. protected override void CompleteRangeAttack(IList<object> data)
  59. {
  60. MapObject target = (MapObject)data[0];
  61. int damage = (int)data[1];
  62. DefenceType defence = (DefenceType)data[2];
  63. bool poison = (bool)data[3];
  64. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  65. if (target.Attacked(this, damage, defence) <= 0) return;
  66. if (poison)
  67. {
  68. PoisonTarget(target, 5, 3, PoisonType.Green, 1000);
  69. }
  70. }
  71. protected override void ProcessTarget()
  72. {
  73. if (Target == null) return;
  74. if (InAttackRange() && CanAttack)
  75. {
  76. Attack();
  77. return;
  78. }
  79. if (Envir.Time < ShockTime)
  80. {
  81. Target = null;
  82. return;
  83. }
  84. MoveTo(Target.CurrentLocation);
  85. }
  86. }
  87. }