FrozenMagician.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class FrozenMagician : MonsterObject
  7. {
  8. private const byte AttackRange = 9;
  9. protected internal FrozenMagician(MonsterInfo info)
  10. : base(info)
  11. {
  12. }
  13. protected override bool InAttackRange()
  14. {
  15. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  16. }
  17. protected bool InRangeAttackRange()
  18. {
  19. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  20. }
  21. protected override void ProcessTarget()
  22. {
  23. if (Target == null || Dead) return;
  24. if (!InAttackRange())
  25. {
  26. if (CanAttack)
  27. {
  28. if (Envir.Random.Next(2) == 0)
  29. RangeAttack();
  30. }
  31. if (CurrentLocation == Target.CurrentLocation)
  32. {
  33. MirDirection direction = (MirDirection)Envir.Random.Next(8);
  34. int rotation = Envir.Random.Next(2) == 0 ? 1 : -1;
  35. for (int d = 0; d < 8; d++)
  36. {
  37. if (Walk(direction)) break;
  38. direction = Functions.ShiftDirection(direction, rotation);
  39. }
  40. }
  41. else
  42. MoveTo(Target.CurrentLocation);
  43. }
  44. if (!CanAttack) return;
  45. if (Envir.Random.Next(3) > 0)
  46. {
  47. if (InAttackRange())
  48. Attack();
  49. }
  50. else RangeAttack();
  51. if (Envir.Time < ShockTime)
  52. {
  53. Target = null;
  54. return;
  55. }
  56. }
  57. protected override void Attack()
  58. {
  59. if (!Target.IsAttackTarget(this))
  60. {
  61. Target = null;
  62. return;
  63. }
  64. ShockTime = 0;
  65. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  66. ActionTime = Envir.Time + 300;
  67. AttackTime = Envir.Time + AttackSpeed;
  68. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  69. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  70. if (damage == 0) return;
  71. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 600, Target, damage, DefenceType.ACAgility, false);
  72. ActionList.Add(action);
  73. }
  74. public void RangeAttack()
  75. {
  76. if (!Target.IsAttackTarget(this))
  77. {
  78. Target = null;
  79. return;
  80. }
  81. ShockTime = 0;
  82. ActionTime = Envir.Time + 1500;
  83. AttackTime = Envir.Time + AttackSpeed + 1000;
  84. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  85. if (damage == 0) return;
  86. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  87. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  88. if (Envir.Random.Next(3) > 0)
  89. {
  90. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  91. if (damage == 0) return;
  92. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 100 + delay, Target, damage, DefenceType.MACAgility);
  93. ActionList.Add(action);
  94. }
  95. else
  96. {
  97. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 1 });
  98. if (damage == 0) return;
  99. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 250 + delay, Target, damage * 3 / 2, DefenceType.MACAgility);
  100. ActionList.Add(action);
  101. }
  102. }
  103. }
  104. }