Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. public static boolean canReach(Character attacker, CombatMethod method, Character target) {
  2. if (!validTarget(attacker, target)) {
  3. return false;
  4. }
  5.  
  6. // Walk back if npc is too far away from spawn position.
  7. if (attacker.isNpc()) {
  8. NPC npc = attacker.getAsNpc();
  9. if (npc.getDefinition().doesRetreat()) {
  10. if (npc.getMovementCoordinator().getCoordinateState() == CoordinateState.RETREATING) {
  11. npc.getCombat().reset();
  12. return false;
  13. }
  14. if (npc.getPosition().getDistance(npc.getSpawnPosition()) >= npc.getDefinition()
  15. .getCombatFollowDistance()) {
  16. npc.getCombat().reset();
  17. npc.getMovementCoordinator().setCoordinateState(CoordinateState.RETREATING);
  18. return false;
  19. }
  20. }
  21. }
  22.  
  23. int distance = method.getAttackDistance(attacker);
  24. distance += target.getSize() - 1;
  25.  
  26. // We're moving so increase the distance.
  27. if (attacker.getMovementQueue().isMoving()) {
  28. if (attacker.getMovementQueue().isRunToggled()) {
  29. distance++;
  30. }
  31. if (target.getMovementQueue().isMoving()) {
  32. distance++;
  33. }
  34. }
  35.  
  36. boolean goodDistance = attacker.getPosition().isWithinDistance(target.getPosition(), distance);
  37.  
  38. // Check good distance?
  39. if (!goodDistance) {
  40. return false;
  41. }
  42.  
  43. // Stop running forward if we're in distance.
  44. attacker.getMovementQueue().reset();
  45.  
  46. // Check diagonal
  47. if (method.getCombatType() == CombatType.MELEE) {
  48. if (RS317PathFinder.isInDiagonalBlock(attacker, target)) {
  49. RS317PathFinder.solveDiagonalBlock(attacker, target);
  50. return false;
  51. }
  52. }
  53.  
  54. // Check projectiles..
  55. if (!RegionManager.canProjectileAttack(attacker, target)) {
  56. return false;
  57. }
  58.  
  59. // Check same spot
  60. if (attacker.getPosition().equals(target.getPosition())) {
  61.  
  62. if (!attacker.getMovementQueue().canMove()) {
  63. return false;
  64. }
  65.  
  66. RS317PathFinder.solveDiagonalBlock(attacker, target);
  67. }
  68.  
  69. return true;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement