StrayCat.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 StrayCat : MonsterObject
  8. {
  9. protected internal StrayCat(MonsterInfo info)
  10. : base(info)
  11. {
  12. }
  13. protected override bool InAttackRange()
  14. {
  15. if (Target.CurrentMap != CurrentMap) return false;
  16. if (Target.CurrentLocation == CurrentLocation) return false;
  17. int x = Math.Abs(Target.CurrentLocation.X - CurrentLocation.X);
  18. int y = Math.Abs(Target.CurrentLocation.Y - CurrentLocation.Y);
  19. if (x > 2 || y > 2) return false;
  20. return (x <= 1 && y <= 1) || (x == y || x % 2 == y % 2);
  21. }
  22. protected override void Attack()
  23. {
  24. if (!Target.IsAttackTarget(this))
  25. {
  26. Target = null;
  27. return;
  28. }
  29. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  30. bool range = !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  31. ActionTime = Envir.Time + 300;
  32. AttackTime = Envir.Time + AttackSpeed;
  33. ShockTime = 0;
  34. if (!range && Envir.Random.Next(10) > 0)
  35. {
  36. if (Envir.Random.Next(10) > 0)
  37. {
  38. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  39. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  40. if (damage == 0) return;
  41. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.ACAgility);
  42. ActionList.Add(action);
  43. }
  44. else
  45. {
  46. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  47. Attack2();
  48. }
  49. }
  50. else
  51. {
  52. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 2 });
  53. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  54. if (damage == 0) return;
  55. LineAttack(damage, 2, 1000);
  56. }
  57. }
  58. private void Attack2()
  59. {
  60. int levelGap = 5;
  61. int mobLevel = this.Level;
  62. int targetLevel = Target.Level;
  63. if ((targetLevel <= mobLevel + levelGap))
  64. {
  65. if (Target.Pushed(this, Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation), 1) > 0)
  66. {
  67. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  68. if (damage == 0) return;
  69. LineAttack(damage, 2, 1000);
  70. }
  71. }
  72. }
  73. protected override void LineAttack(int damage, int distance, int additionalDelay = 500, DefenceType defenceType = DefenceType.ACAgility, bool push = false)
  74. {
  75. for (int i = 1; i <= distance; i++)
  76. {
  77. Point target = Functions.PointMove(CurrentLocation, Direction, i);
  78. if (!CurrentMap.ValidPoint(target)) continue;
  79. Cell cell = CurrentMap.GetCell(target);
  80. if (cell.Objects == null) continue;
  81. for (int o = 0; o < cell.Objects.Count; o++)
  82. {
  83. MapObject ob = cell.Objects[o];
  84. if (ob.Race == ObjectType.Monster || ob.Race == ObjectType.Player)
  85. {
  86. if (!ob.IsAttackTarget(this)) continue;
  87. if (push)
  88. {
  89. ob.Pushed(this, Direction, distance - 1);
  90. }
  91. int delay = Functions.MaxDistance(CurrentLocation, ob.CurrentLocation) * 50 + additionalDelay; //50 MS per Step
  92. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + delay, ob, damage, defenceType);
  93. ActionList.Add(action);
  94. }
  95. else continue;
  96. break;
  97. }
  98. }
  99. }
  100. }
  101. }