HornedMage.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. namespace Server.MirObjects.Monsters
  6. {
  7. public class HornedMage : AxeSkeleton
  8. {
  9. protected internal HornedMage(MonsterInfo info)
  10. : base(info)
  11. {
  12. }
  13. protected override void Attack()
  14. {
  15. if (!Target.IsAttackTarget(this))
  16. {
  17. Target = null;
  18. return;
  19. }
  20. bool ranged = CurrentLocation != Target.CurrentLocation && !Functions.InRange(CurrentLocation, Target.CurrentLocation, 3);
  21. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  22. ShockTime = 0;
  23. if (!ranged)
  24. {
  25. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  26. if (damage == 0) return;
  27. ActionTime = Envir.Time + 500;
  28. AttackTime = Envir.Time + AttackSpeed;
  29. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  30. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.MACAgility);
  31. ActionList.Add(action);
  32. }
  33. else
  34. {
  35. if (Envir.Random.Next(5) > 0)
  36. {
  37. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  38. if (damage == 0) return;
  39. ActionTime = Envir.Time + 500;
  40. AttackTime = Envir.Time + AttackSpeed;
  41. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  42. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 800, Target, damage, DefenceType.AC);
  43. ActionList.Add(action);
  44. }
  45. else
  46. {
  47. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 1 });
  48. TeleportTarget(4, 4);
  49. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  50. }
  51. }
  52. }
  53. public bool TeleportTarget(int attempts, int distance)
  54. {
  55. for (int i = 0; i < attempts; i++)
  56. {
  57. Point location;
  58. if (distance <= 0)
  59. location = new Point(Envir.Random.Next(CurrentMap.Width), Envir.Random.Next(CurrentMap.Height));
  60. else
  61. location = new Point(CurrentLocation.X + Envir.Random.Next(-distance, distance + 1),
  62. CurrentLocation.Y + Envir.Random.Next(-distance, distance + 1));
  63. if (Target.Teleport(CurrentMap, location, true, Info.Effect)) return true;
  64. }
  65. return false;
  66. }
  67. protected override void CompleteRangeAttack(IList<object> data)
  68. {
  69. MapObject target = (MapObject)data[0];
  70. int damage = (int)data[1];
  71. DefenceType defence = (DefenceType)data[2];
  72. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  73. target.Attacked(this, damage, defence);
  74. }
  75. protected override void CompleteAttack(IList<object> data)
  76. {
  77. MapObject target = (MapObject)data[0];
  78. int damage = (int)data[1];
  79. DefenceType defence = (DefenceType)data[2];
  80. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  81. List<MapObject> targets = FindAllTargets(3, CurrentLocation);
  82. for (int i = 0; i < targets.Count; i++)
  83. {
  84. targets[i].Attacked(this, damage, defence);
  85. }
  86. return;
  87. }
  88. }
  89. }