From eb6c3ac721c1c80c655fe73700b4c950f473ef90 Mon Sep 17 00:00:00 2001 From: ShinyDialga Date: Sat, 30 Dec 2017 06:22:24 -0600 Subject: [PATCH] Add checkpoints for assault and fix temporary location fix --- .../main/i18n/templates/pgm/PGMUI.properties | 3 +- .../match/PayloadEnemyCheckpointFilter.java | 9 +++- .../PayloadFriendlyCheckpointFilter.java | 9 +++- .../parser/FilterDefinitionParser.java | 6 +++ .../main/java/tc/oc/pgm/payload/Payload.java | 51 ++++++++++++------- .../tc/oc/pgm/payload/PayloadDefinition.java | 11 ++++ .../java/tc/oc/pgm/payload/PayloadParser.java | 3 +- .../oc/pgm/payload/PayloadPlayerTracker.java | 2 +- 8 files changed, 67 insertions(+), 27 deletions(-) diff --git a/Commons/core/src/main/i18n/templates/pgm/PGMUI.properties b/Commons/core/src/main/i18n/templates/pgm/PGMUI.properties index 09e97b0..603a8a8 100644 --- a/Commons/core/src/main/i18n/templates/pgm/PGMUI.properties +++ b/Commons/core/src/main/i18n/templates/pgm/PGMUI.properties @@ -240,8 +240,7 @@ match.flag.willRespawn = {0} will respawn in {1} seconds match.flag.captureDenied.byFlag = {0} will be captured when {1} is dropped # {0} team reaching a checkpoint -# {1} the checkpoint number reached -match.payload.checkpoint = {0} reached Checkpoint {1} +match.payload.checkpoint = {0} reached a Checkpoint # {0} = the player # {1} = singular / plural substitution diff --git a/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadEnemyCheckpointFilter.java b/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadEnemyCheckpointFilter.java index 17fca92..a98483f 100644 --- a/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadEnemyCheckpointFilter.java +++ b/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadEnemyCheckpointFilter.java @@ -38,8 +38,13 @@ public class PayloadEnemyCheckpointFilter extends TypedFilter.Impl @Override public boolean matches(IMatchQuery query) { - Payload s = query.feature(payload); + Payload p = query.feature(payload); - return this.checkpointRange.contains(s.getCheckpointCount()); + for (int i = checkpointRange.lowerEndpoint(); i <= checkpointRange.upperEndpoint(); i++) { + if (p.enemyReachedCheckpoints.contains(p.allCheckpoints.get(i))) { + return true; + } + } + return false; } } diff --git a/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadFriendlyCheckpointFilter.java b/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadFriendlyCheckpointFilter.java index 0950baf..86c3bbe 100644 --- a/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadFriendlyCheckpointFilter.java +++ b/PGM/src/main/java/tc/oc/pgm/filters/matcher/match/PayloadFriendlyCheckpointFilter.java @@ -33,8 +33,13 @@ public class PayloadFriendlyCheckpointFilter extends TypedFilter.Impl imp XMLUtils.parseNumericRange(new Node(el), Integer.class)); } + @MethodParser("payload-friendly-checkpoint") + public PayloadFriendlyCheckpointFilter parseFriendlyPayloadCheckpoint(Element el) throws InvalidXMLException { + return new PayloadFriendlyCheckpointFilter(features.reference(Node.fromAttr(el, "payload-id"), PayloadDefinition.class), + XMLUtils.parseNumericRange(new Node(el), Integer.class)); + } + protected FlagStateFilter parseFlagState(Element el, Class state) throws InvalidXMLException { return new FlagStateFilter(features.reference(new Node(el), FlagDefinition.class), Node.tryAttr(el, "post").map(rethrowFunction(attr -> features.reference(attr, Post.class))), diff --git a/PGM/src/main/java/tc/oc/pgm/payload/Payload.java b/PGM/src/main/java/tc/oc/pgm/payload/Payload.java index eaace7a..19949d0 100644 --- a/PGM/src/main/java/tc/oc/pgm/payload/Payload.java +++ b/PGM/src/main/java/tc/oc/pgm/payload/Payload.java @@ -53,8 +53,9 @@ public class Payload extends OwnedGoal { private Path currentPath; - private Set friendlyReachedCheckpoints = new HashSet<>(); - private Set enemyReachedCheckpoints = new HashSet<>(); + public List allCheckpoints = new LinkedList<>(); + public Set friendlyReachedCheckpoints = new HashSet<>(); + public Set enemyReachedCheckpoints = new HashSet<>(); // This is set false after the first state change if definition.permanent == true protected boolean capturable = true; @@ -263,7 +264,7 @@ public class Payload extends OwnedGoal { } double speed = isInEnemyControl() ? this.definition.getEnemySpeed() : this.definition.getFriendlySpeed(); - if (!isInEnemyControl() && this.currentPath.hasNext() && this.currentPath.next().isCheckpoint()) { + if (!isInEnemyControl() && this.currentPath.hasNext() && this.currentPath.next().isCheckpoint() && !this.definition.hasFriendlyCheckpoints()) { return; } @@ -308,17 +309,24 @@ public class Payload extends OwnedGoal { } if (currentPath.isCheckpoint()) { - if (false) { //TODO: Friendly checkpoints + if (this.definition.hasFriendlyCheckpoints()) { if (isInEnemyControl() && this.enemyReachedCheckpoints.add(currentPath)) { friendlyReachedCheckpoints.remove(currentPath); + final Component message = new Component(ChatColor.GRAY); + message.translate("match.payload.checkpoint", + this.getCurrentOwner().getComponentName()); + match.sendMessage(message); } else if (!isInEnemyControl() && this.friendlyReachedCheckpoints.add(currentPath)) { enemyReachedCheckpoints.remove(currentPath); + final Component message = new Component(ChatColor.GRAY); + message.translate("match.payload.checkpoint", + this.getCurrentOwner().getComponentName()); + match.sendMessage(message); } } else if (isInEnemyControl() && this.enemyReachedCheckpoints.add(currentPath)) { final Component message = new Component(ChatColor.GRAY); message.translate("match.payload.checkpoint", - this.getCurrentOwner().getComponentName(), - Math.abs(getCheckpointCount())); + this.getCurrentOwner().getComponentName()); match.sendMessage(message); } } @@ -793,6 +801,7 @@ public class Payload extends OwnedGoal { headPath = null; + boolean reachedMiddle = false; boolean moreRails = currentPath.hasNext(); while (moreRails) { Path nextPath = currentPath.next(); @@ -810,6 +819,7 @@ public class Payload extends OwnedGoal { this.currentPath = headPath; } else { newPath = new Path(this.railSize, newLocation, lastPath, null, currentPath.isCheckpoint()); + this.railSize++; lastPath.setNext(newPath); lastPath = newPath; @@ -819,7 +829,14 @@ public class Payload extends OwnedGoal { if (this.getSpawnLocation().getX() == currentPath.getLocation().getX() && this.getSpawnLocation().getY() == currentPath.getLocation().getY() && this.getSpawnLocation().getZ() == currentPath.getLocation().getZ()) { + reachedMiddle = true; this.currentPath = newPath; + if (currentPath.isCheckpoint()) { + this.allCheckpoints.add(lastPath); + } + } else if (currentPath.isCheckpoint()) { + this.allCheckpoints.add(lastPath); + boolean add = reachedMiddle ? this.friendlyReachedCheckpoints.add(lastPath) : this.enemyReachedCheckpoints.add(lastPath); } currentPath = nextPath; moreRails = currentPath.hasNext(); @@ -854,7 +871,7 @@ public class Payload extends OwnedGoal { Location location = path.getLocation(); - /*if (direction == null) { + if (direction == null) { differingX.add(-1.0); differingX.add(0.0); differingX.add(1.0); @@ -879,14 +896,7 @@ public class Payload extends OwnedGoal { differingX.add(0.0); differingZ.add(direction.equals(BlockFace.NORTH_WEST) || direction.equals(BlockFace.NORTH_EAST) ? 1.0 : -1.0); } - }*/ - - differingX.add(-1.0); - differingX.add(0.0); - differingX.add(1.0); - differingZ.add(-1.0); - differingZ.add(0.0); - differingZ.add(1.0); + } Location newLocation = location.clone(); for (double x : differingX) { @@ -898,17 +908,20 @@ public class Payload extends OwnedGoal { if (isRails(newLocation.getBlock().getType()) || isCheckpoint) { Path currentPath = path; - if (currentPath.equals(headPath)) { - return new Path(newLocation, path, null, isCheckpoint); - } boolean alreadyExists = false; + + if (headPath.getLocation().getX() == newLocation.getX() && + headPath.getLocation().getY() == newLocation.getY() && + headPath.getLocation().getZ() == newLocation.getZ()) { + alreadyExists = true; + } + while (currentPath.hasPrevious()) { if (currentPath.getLocation().getX() == newLocation.getX() && currentPath.getLocation().getY() == newLocation.getY() && currentPath.getLocation().getZ() == newLocation.getZ()) { alreadyExists = true; - break; } currentPath = currentPath.previous(); } diff --git a/PGM/src/main/java/tc/oc/pgm/payload/PayloadDefinition.java b/PGM/src/main/java/tc/oc/pgm/payload/PayloadDefinition.java index 059f225..4de5514 100644 --- a/PGM/src/main/java/tc/oc/pgm/payload/PayloadDefinition.java +++ b/PGM/src/main/java/tc/oc/pgm/payload/PayloadDefinition.java @@ -53,6 +53,8 @@ public interface PayloadDefinition extends OwnableGoalDefinition, Gamem boolean hasNeutralState(); + boolean hasFriendlyCheckpoints(); + float getRadius(); float getHeight(); @@ -117,6 +119,8 @@ class PayloadDefinitionImpl extends OwnableGoalDefinitionImpl implement // NOTE: points always start in an unowned state, regardless of this value private final boolean neutralState; + private final boolean friendlyCheckpoints; + //The radius of the control point of the payload private final float radius; @@ -158,6 +162,7 @@ class PayloadDefinitionImpl extends OwnableGoalDefinitionImpl implement TeamFactory owner, CaptureCondition captureCondition, boolean neutralState, + boolean friendlyCheckpoints, float radius, float height, MaterialPattern checkpointMaterial, @@ -181,6 +186,7 @@ class PayloadDefinitionImpl extends OwnableGoalDefinitionImpl implement this.initialOwner = initialOwner; this.captureCondition = captureCondition; this.neutralState = neutralState; + this.friendlyCheckpoints = friendlyCheckpoints; this.radius = radius; this.height = height; this.checkpointMaterial = checkpointMaterial; @@ -291,6 +297,11 @@ class PayloadDefinitionImpl extends OwnableGoalDefinitionImpl implement return this.neutralState; } + @Override + public boolean hasFriendlyCheckpoints() { + return this.friendlyCheckpoints; + } + @Override public float getRadius() { return this.radius; diff --git a/PGM/src/main/java/tc/oc/pgm/payload/PayloadParser.java b/PGM/src/main/java/tc/oc/pgm/payload/PayloadParser.java index 645c8b2..107253a 100644 --- a/PGM/src/main/java/tc/oc/pgm/payload/PayloadParser.java +++ b/PGM/src/main/java/tc/oc/pgm/payload/PayloadParser.java @@ -70,6 +70,7 @@ public final class PayloadParser implements FeatureDefinitionParser