Add checkpoints for assault and fix temporary location fix

This commit is contained in:
ShinyDialga 2017-12-30 06:22:24 -06:00
parent 9f73d2a620
commit eb6c3ac721
8 changed files with 67 additions and 27 deletions

View File

@ -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

View File

@ -38,8 +38,13 @@ public class PayloadEnemyCheckpointFilter extends TypedFilter.Impl<IMatchQuery>
@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;
}
}

View File

@ -33,8 +33,13 @@ public class PayloadFriendlyCheckpointFilter extends TypedFilter.Impl<IMatchQuer
@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.friendlyReachedCheckpoints.contains(p.allCheckpoints.get(i))) {
return true;
}
}
return false;
}
}

View File

@ -350,6 +350,12 @@ public class FilterDefinitionParser extends MagicMethodFeatureParser<Filter> 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<? extends State> 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))),

View File

@ -53,8 +53,9 @@ public class Payload extends OwnedGoal<PayloadDefinition> {
private Path currentPath;
private Set<Path> friendlyReachedCheckpoints = new HashSet<>();
private Set<Path> enemyReachedCheckpoints = new HashSet<>();
public List<Path> allCheckpoints = new LinkedList<>();
public Set<Path> friendlyReachedCheckpoints = new HashSet<>();
public Set<Path> 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<PayloadDefinition> {
}
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<PayloadDefinition> {
}
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<PayloadDefinition> {
headPath = null;
boolean reachedMiddle = false;
boolean moreRails = currentPath.hasNext();
while (moreRails) {
Path nextPath = currentPath.next();
@ -810,6 +819,7 @@ public class Payload extends OwnedGoal<PayloadDefinition> {
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<PayloadDefinition> {
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<PayloadDefinition> {
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<PayloadDefinition> {
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<PayloadDefinition> {
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();
}

View File

@ -53,6 +53,8 @@ public interface PayloadDefinition extends OwnableGoalDefinition<Payload>, Gamem
boolean hasNeutralState();
boolean hasFriendlyCheckpoints();
float getRadius();
float getHeight();
@ -117,6 +119,8 @@ class PayloadDefinitionImpl extends OwnableGoalDefinitionImpl<Payload> 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<Payload> implement
TeamFactory owner,
CaptureCondition captureCondition,
boolean neutralState,
boolean friendlyCheckpoints,
float radius,
float height,
MaterialPattern checkpointMaterial,
@ -181,6 +186,7 @@ class PayloadDefinitionImpl extends OwnableGoalDefinitionImpl<Payload> 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<Payload> implement
return this.neutralState;
}
@Override
public boolean hasFriendlyCheckpoints() {
return this.friendlyCheckpoints;
}
@Override
public float getRadius() {
return this.radius;

View File

@ -70,6 +70,7 @@ public final class PayloadParser implements FeatureDefinitionParser<PayloadDefin
}
boolean neutralState = XMLUtils.parseBoolean(elPayload.getAttribute("neutral-state"), true);
boolean friendlyCheckpoints = XMLUtils.parseBoolean(elPayload.getAttribute("friendly-checkpoints"), false);
float radius = XMLUtils.parseNumber(elPayload.getAttribute("radius"), Float.class, 5f);
float height = XMLUtils.parseNumber(elPayload.getAttribute("height"), Float.class, 3f);
MaterialPattern checkpointMaterial = XMLUtils.parseMaterialPattern(Node.fromAttr(elPayload, "checkpoint-material"));
@ -91,7 +92,7 @@ public final class PayloadParser implements FeatureDefinitionParser<PayloadDefin
name, required, visible,
location, spawnLocation, yaw, captureFilter, playerFilter,
timeToCapture, timeMultiplier, recoveryRate, decayRate, emptyDecayRate, initialOwner, owner, captureCondition,
neutralState, radius, height, checkpointMaterial, friendlySpeed, enemySpeed, points, friendlyPoints, showProgress
neutralState, friendlyCheckpoints, radius, height, checkpointMaterial, friendlySpeed, enemySpeed, points, friendlyPoints, showProgress
);
}
}

View File

@ -88,7 +88,7 @@ public class PayloadPlayerTracker implements Listener {
if(!MatchPlayers.canInteract(player)) return;
if(isOnPoint(player, to)) { //Determine if they are in the height
this.playersOnPoint.add(player); //TODO!!! Since the point is moving, if the player stands still, the payload will keep moving no matter what.
this.playersOnPoint.add(player);
} else {
this.playersOnPoint.remove(player);
}