Skip to content

Commit

Permalink
Make fight.reach distances (survival) configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Mar 13, 2013
1 parent a04f4ad commit c075e67
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Expand Up @@ -98,6 +98,10 @@ public static FightConfig getConfig(final Player player) {
public final long reachPenalty;
public final boolean reachPrecision;
public final boolean reachReduce;
public final double reachSurvivalDistance;
public final double reachReduceDistance;
public final double reachReduceStep;

public final ActionList reachActions;

public final boolean selfHitCheck;
Expand All @@ -116,7 +120,7 @@ public static FightConfig getConfig(final Player player) {
// Special flags:
public final boolean yawRateCheck;
public final boolean cancelDead;

/**
* Instantiates a new fight configuration.
*
Expand Down Expand Up @@ -157,9 +161,12 @@ public FightConfig(final ConfigFile data) {
noSwingActions = data.getOptimizedActionList(ConfPaths.FIGHT_NOSWING_ACTIONS, Permissions.FIGHT_NOSWING);

reachCheck = data.getBoolean(ConfPaths.FIGHT_REACH_CHECK);
reachSurvivalDistance = data.getDouble(ConfPaths.FIGHT_REACH_SURVIVALDISTANCE, 3.5, 6.0, 4.4);
reachPenalty = data.getLong(ConfPaths.FIGHT_REACH_PENALTY);
reachPrecision = data.getBoolean(ConfPaths.FIGHT_REACH_PRECISION);
reachReduce = data.getBoolean(ConfPaths.FIGHT_REACH_REDUCE);
reachReduceDistance = data.getDouble(ConfPaths.FIGHT_REACH_REDUCEDISTANCE, 0, reachSurvivalDistance, 0.9);
reachReduceStep = data.getDouble(ConfPaths.FIGHT_REACH_REDUCESTEP, 0, reachReduceDistance, 0.15);
reachActions = data.getOptimizedActionList(ConfPaths.FIGHT_REACH_ACTIONS, Permissions.FIGHT_REACH);

selfHitCheck = data.getBoolean(ConfPaths.FIGHT_SELFHIT_CHECK);
Expand Down
Expand Up @@ -32,15 +32,6 @@ public class Reach extends Check {

/** The maximum distance allowed to interact with an entity in creative mode. */
public static final double CREATIVE_DISTANCE = 6D;

/** The maximum distance allowed to interact with an entity in survival mode. */
public static final double SURVIVAL_DISTANCE = 4.25D;

/** Amount which can be reduced by reach adaption. */
public static final double DYNAMIC_RANGE = 0.75;

/** Adaption amount for dynamic range. */
public static final double DYNAMIC_STEP = DYNAMIC_RANGE / 3.0;

/** Additum for distance, based on entity. */
private static double getDistMod(final Entity damaged) {
Expand Down Expand Up @@ -74,6 +65,13 @@ public boolean check(final Player player, final Entity damaged) {
final FightData data = FightData.getData(player);

boolean cancel = false;

// The maximum distance allowed to interact with an entity in survival mode.
final double SURVIVAL_DISTANCE = cc.reachSurvivalDistance; // 4.4D;
// Amount which can be reduced by reach adaption.
final double DYNAMIC_RANGE = cc.reachReduceDistance; // 0.9
// Adaption amount for dynamic range.
final double DYNAMIC_STEP = cc.reachReduceStep / SURVIVAL_DISTANCE; // 0.15

final double distanceLimit = player.getGameMode() == GameMode.CREATIVE ? CREATIVE_DISTANCE : SURVIVAL_DISTANCE + getDistMod(damaged);
final double distanceMin = (distanceLimit - DYNAMIC_RANGE) / distanceLimit;
Expand Down Expand Up @@ -145,8 +143,9 @@ else if (lenpRel > distanceLimit - DYNAMIC_RANGE){
if (data.reachLastViolationTime + cc.reachPenalty > System.currentTimeMillis()) {
// A safeguard to avoid people getting stuck in penalty time indefinitely in case the system time of the
// server gets changed.
if (data.reachLastViolationTime > System.currentTimeMillis())
data.reachLastViolationTime = 0;
if (data.reachLastViolationTime > System.currentTimeMillis()){
data.reachLastViolationTime = 0;
}

// He is in penalty time, therefore request cancelling of the event.
cancelByPenalty = !cancel;
Expand Down
Expand Up @@ -417,9 +417,12 @@ public abstract class ConfPaths {

private static final String FIGHT_REACH = FIGHT + "reach.";
public static final String FIGHT_REACH_CHECK = FIGHT_REACH + "active";
public static final String FIGHT_REACH_SURVIVALDISTANCE = FIGHT_REACH + "survivaldistance";
public static final String FIGHT_REACH_PENALTY = FIGHT_REACH + "penalty";
public static final String FIGHT_REACH_PRECISION = FIGHT_REACH + "precision";
public static final String FIGHT_REACH_REDUCE = FIGHT_REACH + "reduce";
public static final String FIGHT_REACH_REDUCEDISTANCE = FIGHT_REACH + "reducedistance";
public static final String FIGHT_REACH_REDUCESTEP = FIGHT_REACH + "reducestep";
public static final String FIGHT_REACH_ACTIONS = FIGHT_REACH + "actions";

public static final String FIGHT_SELFHIT = FIGHT + "selfhit.";
Expand Down
Expand Up @@ -328,8 +328,11 @@ public DefaultConfig() {
set(ConfPaths.FIGHT_NOSWING_ACTIONS, "cancel vl>10 log:noswing:0:5:if cancel");

set(ConfPaths.FIGHT_REACH_CHECK, true);
set(ConfPaths.FIGHT_REACH_SURVIVALDISTANCE, 4.4);
set(ConfPaths.FIGHT_REACH_PENALTY, 500);
set(ConfPaths.FIGHT_REACH_REDUCE, true);
set(ConfPaths.FIGHT_REACH_REDUCEDISTANCE, 0.9);
set(ConfPaths.FIGHT_REACH_REDUCESTEP, 0.15);
set(ConfPaths.FIGHT_REACH_ACTIONS, "cancel vl>10 log:freach:2:5:if cancel");

set(ConfPaths.FIGHT_SELFHIT_CHECK, true);
Expand Down

0 comments on commit c075e67

Please sign in to comment.