Skip to content

Commit

Permalink
Extract attack range to a setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 18, 2013
1 parent c5db55d commit f82264a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/citizensnpcs/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void loadFromKey(DataKey root) {
MAX_NPC_LIMIT_CHECKS("npc.limits.max-permission-checks", 100),
MAX_SPEED("npc.limits.max-speed", 100),
MESSAGE_COLOUR("general.color-scheme.message", "<a>"),
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75),
NPC_COST("economy.npc.cost", 100D),
QUICK_SELECT("npc.selection.quick-select", false),
REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Field;

import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.ai.AttackStrategy;
import net.citizensnpcs.api.ai.EntityTarget;
import net.citizensnpcs.api.ai.NavigatorParameters;
Expand Down Expand Up @@ -43,7 +44,7 @@ public MCTargetStrategy(NPC handle, org.bukkit.entity.Entity target, boolean agg
private boolean canAttack() {
return attackTicks == 0
&& (handle.boundingBox.e > target.boundingBox.b && handle.boundingBox.b < target.boundingBox.e)
&& distanceSquared() <= ATTACK_DISTANCE && hasLineOfSight();
&& distanceSquared() <= Setting.NPC_ATTACK_DISTANCE.asDouble() && hasLineOfSight();
}

@Override
Expand Down Expand Up @@ -157,7 +158,6 @@ public PathEntity findPath(Entity from, Entity to) {
}

private static final int ATTACK_DELAY_TICKS = 20;
private static final double ATTACK_DISTANCE = 1.75 * 1.75;
private static final Location HANDLE_LOCATION = new Location(null, 0, 0, 0);
private static Field NAV_E, NAV_J, NAV_M;

Expand Down

0 comments on commit f82264a

Please sign in to comment.