TownArcher.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class TownArcher : MonsterObject
  7. {
  8. public long FearTime;
  9. public byte AttackRange = 10;
  10. protected override bool CanMove
  11. {
  12. get { return Route.Count > 0 && !Dead && Envir.Time > MoveTime && Envir.Time > ActionTime && Envir.Time > ShockTime; }
  13. }
  14. protected internal TownArcher(MonsterInfo info) : base(info) { }
  15. public override bool IsAttackTarget(MonsterObject attacker) { return false; }
  16. public override void Spawned()
  17. {
  18. if (Respawn != null && Respawn.Info.Direction < 8)
  19. Direction = (MirDirection)Respawn.Info.Direction;
  20. base.Spawned();
  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. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  32. ActionTime = Envir.Time + 300;
  33. AttackTime = Envir.Time + AttackSpeed;
  34. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  35. if (damage == 0) return;
  36. ProjectileAttack(damage);
  37. }
  38. protected override void ProcessTarget()
  39. {
  40. if (Target == null || !CanAttack) return;
  41. if (InAttackRange() && Envir.Time < FearTime)
  42. {
  43. Attack();
  44. return;
  45. }
  46. FearTime = Envir.Time + 2000;
  47. if (Envir.Time < ShockTime)
  48. {
  49. Target = null;
  50. return;
  51. }
  52. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  53. if (dist > AttackRange) // || Target.PKPoints <= 99
  54. {
  55. Target = null;
  56. if (Respawn != null)
  57. Direction = (MirDirection)Respawn.Info.Direction;
  58. }
  59. }
  60. protected override void FindTarget()
  61. {
  62. for (int d = 0; d <= Info.ViewRange; d++)
  63. {
  64. for (int y = CurrentLocation.Y - d; y <= CurrentLocation.Y + d; y++)
  65. {
  66. if (y < 0) continue;
  67. if (y >= CurrentMap.Height) break;
  68. for (int x = CurrentLocation.X - d; x <= CurrentLocation.X + d; x += Math.Abs(y - CurrentLocation.Y) == d ? 1 : d * 2)
  69. {
  70. if (x < 0) continue;
  71. if (x >= CurrentMap.Width) break;
  72. Cell cell = CurrentMap.GetCell(x, y);
  73. if (!cell.Valid || cell.Objects == null) continue;
  74. for (int i = 0; i < cell.Objects.Count; i++)
  75. {
  76. MapObject ob = cell.Objects[i];
  77. switch (ob.Race)
  78. {
  79. case ObjectType.Player:
  80. PlayerObject playerob = (PlayerObject)ob;
  81. if (!ob.IsAttackTarget(this)) continue;
  82. if (playerob.PKPoints < 200 || ob.Hidden && (!CoolEye || Level < ob.Level)) continue;
  83. Target = ob;
  84. return;
  85. default:
  86. continue;
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. protected override bool InAttackRange()
  94. {
  95. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  96. }
  97. }
  98. }