diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java index f50758bbb..3dab5f52e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java @@ -68,6 +68,7 @@ import nautilus.game.arcade.kit.Perk; public class QuiverPayload extends TeamGame { + // Define all our constants. private static final long GAME_TIMEOUT = 600000; private static final double PAYLOAD_CAPTURE_RANGE = 4; private static final double PAYLOAD_INITIAL_VELOCITY = 0.1; @@ -90,7 +91,7 @@ public class QuiverPayload extends TeamGame private static final int END_EFFECT_EXPLOSION_RADIUS = 5; public static final int KIT_NINJA_SHURIKEN_AMOUNT = 15; - + public static final String DATA_POINT_MARKER_START = "PINK"; public static final String DATA_POINT_RED = "RED"; public static final String DATA_POINT_BLUE = "BLUE"; @@ -196,6 +197,7 @@ public class QuiverPayload extends TeamGame { if (event.GetState() == GameState.Prepare) { + // This hides all nametags of the enemy teams. for (Team team : Scoreboard.GetScoreboard().getTeams()) { team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); @@ -204,7 +206,13 @@ public class QuiverPayload extends TeamGame if (event.GetState() == GameState.Live) { + /* + * This is the location that the minecart will spawn at the start of + * the game. This is represented as a DATA_POINT_PAYLOAD coloured + * data point. + */ Location location = WorldData.GetDataLocs(DATA_POINT_PAYLOAD).get(0); + _minecart = location.getWorld().spawn(location, Minecart.class); _hologram = new Hologram(Manager.getHologramManager(), location.add(0, 1, 0), "None"); _lastSpeedIncrease = System.currentTimeMillis(); @@ -222,6 +230,7 @@ public class QuiverPayload extends TeamGame continue; } + // Give all players a Super Arrow item. player.getInventory().addItem(Quiver.SUPER_ARROW); } @@ -230,16 +239,48 @@ public class QuiverPayload extends TeamGame _powerupGenerators.add(new PowerupGenerator(this, powerup, POWERUP_SPAWN_DELAY)); } - // Sort path markers + /* + * The payload which is represented as a minecart follows a linear + * path connecting the two team's bases. The logic used to calculate + * the path that the minecart takes is done below. + * + * Initially we need to get a constant point we will use to start + * our calculations. This is a DATA_POINT_MARKER_START coloured data + * point. This is placed at the red team's base, at the end of the + * track. + */ Location start = WorldData.GetDataLocs(DATA_POINT_MARKER_START).get(0); Location last = start; ArrayList dataPoints = new ArrayList<>(); + /* + * The dataPoints ArrayList is an unordered list of all the data + * points. We add the start location and all red and blue data + * points. + * + * We use red and blue data points so that it is easier for the + * builders to see which direction the minecart would move when a + * certain team moved the minecart. + * + * Data points are placed above the track, they should be placed at + * intervals along the track where it is ensured that the next data + * point along the track is the closest relative to all other data + * points in the map as well on any point where the track curves. + * + */ + dataPoints.add(start); dataPoints.addAll(WorldData.GetDataLocs(DATA_POINT_RED)); dataPoints.addAll(WorldData.GetDataLocs(DATA_POINT_BLUE)); + /* + * While there are locations still left in the list, we search for + * the nearest different data point and add it to a new list, this + * list contains all the data points sorted in the correct order of + * the track's path. + */ + while (!dataPoints.isEmpty()) { Location dataPoint = UtilAlg.findClosest(last, dataPoints); @@ -249,6 +290,11 @@ public class QuiverPayload extends TeamGame last = dataPoint; } + /* + * We need to calculate the total linear distance between all the + * stored data points. This is used later when displaying the + * Dragon/Wither progression bar. + */ for (int i = 1; i < _pathMarkers.size(); i++) { _totalDistance += UtilMath.offset(_pathMarkers.get(i - 1), _pathMarkers.get(i)); @@ -267,11 +313,22 @@ public class QuiverPayload extends TeamGame if (event.getType() == UpdateType.SEC && IsLive()) { + + /* + * If the game lasts longer than GAME_TIMEOUT milliseconds. A winner + * is determined by calculating which team has the least amount of + * distance left the push the payload. + */ if (UtilTime.elapsed(GetStateTime(), GAME_TIMEOUT)) { GameTeam teamA = GetTeamList().get(0); GameTeam teamB = GetTeamList().get(1); + /* + * If the distance that teamA had to move the payload to their + * destination is less than that of teamB, then teamA is the + * winner and visa versa. + */ if (getTrackDistanceToMarker(getDestination(teamA), teamA) < getTrackDistanceToMarker(getDestination(teamB), teamB)) { WinnerTeam = teamA; @@ -285,6 +342,11 @@ public class QuiverPayload extends TeamGame SetState(GameState.End); return; } + + /* + * If the game only has 60 seconds left before it times out we sent + * all players a message. + */ else if (UtilTime.elapsed(GetStateTime(), GAME_TIMEOUT - 60000) && !_hasAnnouncedGameEnd) { _hasAnnouncedGameEnd = true; @@ -325,7 +387,7 @@ public class QuiverPayload extends TeamGame if (percentage >= 100) { - UtilTextBottom.display((_coloredMessage ? C.cWhiteB : C.cAquaB) + "ULTIMATE READY (DROP YOUR SWORD)", player); + UtilTextBottom.display((_coloredMessage ? C.cWhiteB : C.cAquaB) + "ULTIMATE READY (DROP YOUR WEAPON)", player); continue; } @@ -368,6 +430,12 @@ public class QuiverPayload extends TeamGame } } + /* + * In order to determine which direction the payload will move we + * calculate how many players are within PAYLOAD_CAPURE_RANGE blocks + * of the payload. + */ + int teamACount = 0, teamBCount = 0; for (Player player : UtilPlayer.getNearby(_minecart.getLocation(), PAYLOAD_CAPTURE_RANGE)) @@ -390,6 +458,11 @@ public class QuiverPayload extends TeamGame UtilTextTop.display(getTopBar(teamACount, teamBCount), UtilServer.getPlayers()); + /* + * _recentlyChanged is used to show that on the targetIndex needs to + * be updated as the payload's direction has changed. + */ + if (teamACount > teamBCount && teamBCount == 0) { if (_teamDirection != null) @@ -434,9 +507,10 @@ public class QuiverPayload extends TeamGame if (_teamDirection.equals(GetTeamList().get(0))) { + // If the minecart has never moved if (_lastDirection == null) { - _targetIndex = _pathMarkers.size() / PAYLOAD_MARKER_MAX_DISTANCE; + _targetIndex = _pathMarkers.size() / 2; } else if (isMinecartNearMarker(_pathMarkers.get(_targetIndex)) || _recentlyChanged) { @@ -446,6 +520,7 @@ public class QuiverPayload extends TeamGame } else { + // If the minecart has never moved if (_lastDirection == null) { _targetIndex = _pathMarkers.size() / 2 - 2; @@ -457,6 +532,11 @@ public class QuiverPayload extends TeamGame } } + /* + * If PAYLOAD_APPROACHING_TIME milliseconds has pasted and the + * minecart is within PAYLOAD_APPOACHING_DISTANCE blocks of the + * destination of it's current direction. + */ if (UtilTime.elapsed(_lastAnnoucement, PAYLOAD_APPROACHING_TIME) && isMinecartNearMarker(getDestination(_teamDirection), PAYLOAD_APPROACHING_DISTANCE)) { _lastAnnoucement = System.currentTimeMillis(); @@ -472,6 +552,14 @@ public class QuiverPayload extends TeamGame } } + /* + * The minecart's velocity is set to the vector between the the + * minecart's current location and the next data point it will + * reach. + * + * This is when multiplied by the _payloadVelocity which increase + * the game progresses. + */ _minecart.setVelocity(UtilAlg.getTrajectory(_minecart.getLocation(), _pathMarkers.get(_targetIndex)).normalize().multiply(_payloadVelocity)); _lastDirection = _minecart.getVelocity(); _hologram.setText(_teamDirection.GetFormattedName()); @@ -509,7 +597,7 @@ public class QuiverPayload extends TeamGame { return isMinecartNearMarker(marker, PAYLOAD_MARKER_MAX_DISTANCE); } - + private boolean isMinecartNearMarker(Location marker, double distance) { return UtilMath.offset(_minecart.getLocation(), marker) < distance; @@ -568,7 +656,8 @@ public class QuiverPayload extends TeamGame } else { - // distance += UtilMath.offset(_minecart.getLocation(), _pathMarkers.get(0)); + // distance += UtilMath.offset(_minecart.getLocation(), + // _pathMarkers.get(0)); } }