Prepare more changes to fight checks using (location trace based).

* Use a SharedContext for properties used in all checks.
* Rename (locationTraceChecks).
This commit is contained in:
asofold 2014-11-26 17:03:52 +01:00
parent 5f0c70f138
commit a9f9a3dced
5 changed files with 31 additions and 14 deletions

View File

@ -95,13 +95,13 @@ public class Direction extends Check {
* @param cc
* @return
*/
public DirectionContext getContext(final Player player, final Location loc, final Entity damaged, final Location damagedLoc, final FightData data, final FightConfig cc) {
public DirectionContext getContext(final Player player, final Location loc, final Entity damaged, final Location damagedLoc, final FightData data, final FightConfig cc, final SharedContext sharedContext) {
final DirectionContext context = new DirectionContext();
context.damagedComplex = mcAccess.isComplexPart(damaged);
// Find out how wide the entity is.
context.damagedWidth = mcAccess.getWidth(damaged);
// entity.height is broken and will always be 0, therefore. Calculate height instead based on boundingBox.
context.damagedHeight = mcAccess.getHeight(damaged);
context.damagedHeight = sharedContext.damagedHeight;
context.direction = loc.getDirection();
context.lengthDirection = context.direction.length();
return context;

View File

@ -240,7 +240,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
if (reachEnabled || directionEnabled) {
if (damagedTrace != null) {
// Checks that use the LocationTrace instance of the attacked entity/player.
cancelled = movingTraceChecks(player, loc, data, cc, damaged, damagedLoc, damagedTrace, tick, reachEnabled, directionEnabled);
cancelled = locationTraceChecks(player, loc, data, cc, damaged, damagedLoc, damagedTrace, tick, reachEnabled, directionEnabled);
} else {
// Still use the classic methods for non-players. maybe[]
if (reachEnabled && reach.check(player, loc, damaged, damagedLoc, data, cc)) {
@ -323,7 +323,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
}
/**
* Quick split-off: Checks using a moving trace.
* Quick split-off: Checks using a location trace.
* @param player
* @param loc
* @param data
@ -337,12 +337,15 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
* @param directionEnabled
* @return If to cancel (true) or not (false).
*/
private boolean movingTraceChecks(Player player, Location loc, FightData data, FightConfig cc, Entity damaged, Location damagedLoc, LocationTrace damagedTrace, long tick, boolean reachEnabled, boolean directionEnabled) {
private boolean locationTraceChecks(Player player, Location loc, FightData data, FightConfig cc, Entity damaged, Location damagedLoc, LocationTrace damagedTrace, long tick, boolean reachEnabled, boolean directionEnabled) {
// TODO: Order / splitting off generic stuff.
boolean cancelled = false;
// TODO: Order / splitting off generic stuff.
final ReachContext reachContext = reachEnabled ? reach.getContext(player, loc, damaged, damagedLoc, data, cc) : null;
final DirectionContext directionContext = directionEnabled ? direction.getContext(player, loc, damaged, damagedLoc, data, cc) : null;
// (Might pass generic context to factories, for shared + heavy properties.)
final SharedContext sharedContext = new SharedContext(damaged, mcAccess);
final ReachContext reachContext = reachEnabled ? reach.getContext(player, loc, damaged, damagedLoc, data, cc, sharedContext) : null;
final DirectionContext directionContext = directionEnabled ? direction.getContext(player, loc, damaged, damagedLoc, data, cc, sharedContext) : null;
final long traceOldest = tick; // - damagedTrace.getMaxSize(); // TODO: Set by window.
// TODO: Iterating direction, which, static/dynamic choice.
final Iterator<TraceEntry> traceIt = damagedTrace.maxAgeIterator(traceOldest);
@ -364,7 +367,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
reachPassed = true;
}
}
// TODO: For efficiency one could omit checking at all if reach is failed all the time.
// TODO: Efficiency: don't check at all, if strict and !thisPassed.
if (directionEnabled && (reachPassed || !directionPassed)) {
if (direction.loopCheck(player, damagedLoc, damaged, entry, directionContext, data, cc)) {
thisPassed = false;
@ -380,6 +383,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
}
// TODO: How to treat mixed state: violation && reachPassed && directionPassed [current: use min violation // thinkable: silent cancel, if actions have cancel (!)]
// TODO: Adapt according to strictness settings?
// TODO: violation vs. reachPassed + directionPassed (current: fail one = fail all).
if (reachEnabled) {
// TODO: Might ignore if already cancelled by mixed/silent cancel.
if (reach.loopFinish(player, loc, damaged, reachContext, violation, data, cc)) {

View File

@ -145,11 +145,11 @@ public class Reach extends Check {
* @param cc
* @return
*/
public ReachContext getContext(final Player player, final Location pLoc, final Entity damaged, final Location damagedLoc, final FightData data, final FightConfig cc) {
public ReachContext getContext(final Player player, final Location pLoc, final Entity damaged, final Location damagedLoc, final FightData data, final FightConfig cc, final SharedContext sharedContext) {
final ReachContext context = new ReachContext();
context.distanceLimit = player.getGameMode() == GameMode.CREATIVE ? CREATIVE_DISTANCE : cc.reachSurvivalDistance + getDistMod(damaged);
context.distanceMin = (context.distanceLimit - cc.reachReduceDistance) / context.distanceLimit;
context.damagedHeight = mcAccess.getHeight(damaged);
context.damagedHeight = sharedContext.damagedHeight;
//context.eyeHeight = player.getEyeHeight();
context.pY = pLoc.getY() + player.getEyeHeight();
return context;

View File

@ -10,8 +10,8 @@ public class ReachContext {
public double distanceLimit;
public double distanceMin;
public double damagedHeight;
/** Attacking player. */
public double eyeHeight;
// /** Attacking player. */
// public double eyeHeight;
/** Eye location y of the attacking player. */
public double pY;
/** Minimum value of lenpRel that was a violation. */

View File

@ -0,0 +1,13 @@
package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.entity.Entity;
import fr.neatmonster.nocheatplus.compat.MCAccess;
public class SharedContext {
public final double damagedHeight;
public SharedContext(Entity damaged, MCAccess mcAccess) {
this.damagedHeight = mcAccess.getHeight(damaged);
}
}