IceGuard.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class IceGuard : MonsterObject
  6. {
  7. protected virtual byte AttackRange
  8. {
  9. get
  10. {
  11. return 8;
  12. }
  13. }
  14. protected internal IceGuard(MonsterInfo info)
  15. : base(info)
  16. {
  17. }
  18. protected override bool InAttackRange()
  19. {
  20. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  21. }
  22. protected override void Attack()
  23. {
  24. if (!Target.IsAttackTarget(this))
  25. {
  26. Target = null;
  27. return;
  28. }
  29. ShockTime = 0;
  30. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  31. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  32. ActionTime = Envir.Time + 300;
  33. AttackTime = Envir.Time + AttackSpeed;
  34. if (!ranged)
  35. {
  36. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  37. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  38. if (damage == 0) return;
  39. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.MAC, true);
  40. ActionList.Add(action);
  41. }
  42. else
  43. {
  44. if (Envir.Random.Next(3) > 0)
  45. {
  46. //Ice Attack
  47. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  48. AttackTime = Envir.Time + AttackSpeed + 500;
  49. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  50. if (damage == 0) return;
  51. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MAC, true);
  52. ActionList.Add(action);
  53. }
  54. else
  55. {
  56. //Fire Attack
  57. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 1 });
  58. AttackTime = Envir.Time + AttackSpeed + 500;
  59. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  60. if (damage == 0) return;
  61. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MAC, false);
  62. ActionList.Add(action);
  63. }
  64. }
  65. }
  66. protected override void CompleteRangeAttack(IList<object> data)
  67. {
  68. MapObject target = (MapObject)data[0];
  69. int damage = (int)data[1];
  70. DefenceType defence = (DefenceType)data[2];
  71. bool poison = (bool)data[3];
  72. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  73. if (target.Attacked(this, damage, defence) <= 0) return;
  74. if (poison)
  75. {
  76. PoisonTarget(target, 5, 5, PoisonType.Slow, 1000);
  77. PoisonTarget(target, 10, 3, PoisonType.Frozen, 1000);
  78. }
  79. }
  80. protected override void ProcessTarget()
  81. {
  82. if (Target == null) return;
  83. if (InAttackRange() && CanAttack)
  84. {
  85. Attack();
  86. return;
  87. }
  88. if (Envir.Time < ShockTime)
  89. {
  90. Target = null;
  91. return;
  92. }
  93. MoveTo(Target.CurrentLocation);
  94. }
  95. }
  96. }