Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean canReach(Character attacker, CombatMethod method, Character target) {
- if (!validTarget(attacker, target)) {
- return false;
- }
- // Walk back if npc is too far away from spawn position.
- if (attacker.isNpc()) {
- NPC npc = attacker.getAsNpc();
- if (npc.getDefinition().doesRetreat()) {
- if (npc.getMovementCoordinator().getCoordinateState() == CoordinateState.RETREATING) {
- npc.getCombat().reset();
- return false;
- }
- if (npc.getPosition().getDistance(npc.getSpawnPosition()) >= npc.getDefinition()
- .getCombatFollowDistance()) {
- npc.getCombat().reset();
- npc.getMovementCoordinator().setCoordinateState(CoordinateState.RETREATING);
- return false;
- }
- }
- }
- int distance = method.getAttackDistance(attacker);
- distance += target.getSize() - 1;
- // We're moving so increase the distance.
- if (attacker.getMovementQueue().isMoving()) {
- if (attacker.getMovementQueue().isRunToggled()) {
- distance++;
- }
- if (target.getMovementQueue().isMoving()) {
- distance++;
- }
- }
- boolean goodDistance = attacker.getPosition().isWithinDistance(target.getPosition(), distance);
- // Check good distance?
- if (!goodDistance) {
- return false;
- }
- // Stop running forward if we're in distance.
- attacker.getMovementQueue().reset();
- // Check diagonal
- if (method.getCombatType() == CombatType.MELEE) {
- if (RS317PathFinder.isInDiagonalBlock(attacker, target)) {
- RS317PathFinder.solveDiagonalBlock(attacker, target);
- return false;
- }
- }
- // Check projectiles..
- if (!RegionManager.canProjectileAttack(attacker, target)) {
- return false;
- }
- // Check same spot
- if (attacker.getPosition().equals(target.getPosition())) {
- if (!attacker.getMovementQueue().canMove()) {
- return false;
- }
- RS317PathFinder.solveDiagonalBlock(attacker, target);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement