Capture point improvements

* Now gives one point every interval
* New setting: capturepointtime
* i18n
This commit is contained in:
Connor Monahan 2017-07-28 02:17:29 -05:00
parent 0f09410c66
commit 8ce9586b8d
6 changed files with 86 additions and 29 deletions

View File

@ -219,6 +219,7 @@ public class War extends JavaPlugin {
warzoneDefaultConfig.put(WarzoneConfig.SOUPHEALING, false); warzoneDefaultConfig.put(WarzoneConfig.SOUPHEALING, false);
warzoneDefaultConfig.put(WarzoneConfig.ALLOWENDER, true); warzoneDefaultConfig.put(WarzoneConfig.ALLOWENDER, true);
warzoneDefaultConfig.put(WarzoneConfig.RESETBLOCKS, true); warzoneDefaultConfig.put(WarzoneConfig.RESETBLOCKS, true);
warzoneDefaultConfig.put(WarzoneConfig.CAPTUREPOINTTIME, 15);
teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true); teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true);
teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false); teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false);

View File

@ -25,7 +25,8 @@ public enum WarzoneConfig {
SCOREBOARD (ScoreboardType.class, "Scoreboard type", "Type of scoreboard for this zone (none, points, lifepool, top kills)"), SCOREBOARD (ScoreboardType.class, "Scoreboard type", "Type of scoreboard for this zone (none, points, lifepool, top kills)"),
SOUPHEALING (Boolean.class, "Soup healing", "If true, allow players to heal by consuming soup"), SOUPHEALING (Boolean.class, "Soup healing", "If true, allow players to heal by consuming soup"),
ALLOWENDER (Boolean.class, "Allow ender chests", "Ender chests are usually blocked to prevent item duplication"), ALLOWENDER (Boolean.class, "Allow ender chests", "Ender chests are usually blocked to prevent item duplication"),
RESETBLOCKS (Boolean.class, "Reset blocks", "If true, reset warzone blocks each battle"); RESETBLOCKS (Boolean.class, "Reset blocks", "If true, reset warzone blocks each battle"),
CAPTUREPOINTTIME (Integer.class, "Cap control time", "Time, in seconds, required to gain control of a capture point");
private final Class<?> configType; private final Class<?> configType;

View File

@ -3,17 +3,16 @@ package com.tommytony.war.job;
import com.tommytony.war.Team; import com.tommytony.war.Team;
import com.tommytony.war.War; import com.tommytony.war.War;
import com.tommytony.war.Warzone; import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.structure.CapturePoint; import com.tommytony.war.structure.CapturePoint;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class CapturePointTimer extends BukkitRunnable { public class CapturePointTimer extends BukkitRunnable {
private static int iteration = 0;
@Override @Override
public void run() { public void run() {
iteration += 1;
if (!War.war.isLoaded()) { if (!War.war.isLoaded()) {
return; return;
} }
@ -42,13 +41,34 @@ public class CapturePointTimer extends BukkitRunnable {
} }
} }
} }
for (Warzone zone : War.war.getWarzones()) {
for (CapturePoint cp : zone.getCapturePoints()) {
if (cp.getController() != null && cp.getController() != cp.getDefaultController()
&& cp.getStrength() == cp.getMaxStrength()) {
int controlTime = cp.getControlTime() + 1;
cp.setControlTime(controlTime);
if (controlTime % cp.getMaxStrength() == 0) {
// give points for every control time which is a multiple of the time taken to capture
Team team = zone.getTeamByKind(cp.getController());
team.addPoint();
zone.broadcast("zone.capturepoint.addpoint",
cp.getController().getFormattedName(), cp.getName());
// Detect win conditions
if (team.getPoints() >= team.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
zone.handleScoreCapReached(team.getName());
} else {
// just added a point
team.resetSign();
zone.getLobby().resetTeamGateSign(team);
}
}
}
}
}
} }
private static void decrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) { private static void decrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) {
if (iteration % 5 != 0) {
return;
}
int strength = cp.getStrength(); int strength = cp.getStrength();
if (strength < 1) { if (strength < 1) {
// strength is already at minimum, ensure attributes are wiped // strength is already at minimum, ensure attributes are wiped
@ -58,38 +78,40 @@ public class CapturePointTimer extends BukkitRunnable {
} }
strength -= 1; strength -= 1;
if (strength == 0) { if (strength == 0) {
zone.broadcast("Team {0} has lost control of capture point {1}.", cp.getController().getFormattedName(), if (cp.antiChatSpam()) {
cp.getName()); zone.broadcast("zone.capturepoint.lose", cp.getController().getFormattedName(), cp.getName());
}
cp.setControlTime(0);
cp.setController(null); cp.setController(null);
} else if (strength == 3) { } else if (strength == cp.getMaxStrength() - 1) {
zone.broadcast("Capture point {0} is being contested by {1}!", cp.getName(), if (cp.antiChatSpam()) {
team.getKind().getColor() + player.getName() + ChatColor.WHITE); zone.broadcast("zone.capturepoint.contest", cp.getName(),
team.getKind().getColor() + player.getName() + ChatColor.WHITE);
}
} }
cp.setStrength(strength); cp.setStrength(strength);
} }
private static void incrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) { private static void incrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) {
if (iteration % 5 != 0) {
return;
}
int strength = cp.getStrength(); int strength = cp.getStrength();
if (strength > 4) { if (strength > cp.getMaxStrength()) {
// cap strength at 4 // cap strength at CapturePoint.MAX_STRENGTH
cp.setStrength(4); cp.setStrength(cp.getMaxStrength());
return; return;
} else if (strength == 4) { } else if (strength == cp.getMaxStrength()) {
// do nothing // do nothing
return; return;
} }
strength += 1; strength += 1;
if (strength == 4) { if (strength == cp.getMaxStrength()) {
zone.broadcast("Team {0} has captured point {1}, gaining 1 extra point.", if (cp.antiChatSpam()) {
cp.getController().getFormattedName(), cp.getName()); zone.broadcast("zone.capturepoint.capture", cp.getController().getFormattedName(), cp.getName());
}
team.addPoint(); team.addPoint();
} else if (strength == 1) { } else if (strength == 1) {
zone.broadcast("Team {0} is gaining control of point {1}!", if (cp.antiChatSpam()) {
team.getKind().getFormattedName(), cp.getName()); zone.broadcast("zone.capturepoint.fortify", team.getKind().getFormattedName(), cp.getName());
}
cp.setController(team.getKind()); cp.setController(team.getKind());
} }
cp.setStrength(strength); cp.setStrength(strength);

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.structure.*; import com.tommytony.war.structure.*;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -161,7 +162,7 @@ public class WarzoneYmlMapper {
int strength = 0; int strength = 0;
if (warzoneRootSection.contains(cpPrefix + "controller")) { if (warzoneRootSection.contains(cpPrefix + "controller")) {
controller = TeamKind.teamKindFromString(warzoneRootSection.getString(cpPrefix + "controller")); controller = TeamKind.teamKindFromString(warzoneRootSection.getString(cpPrefix + "controller"));
strength = 4; strength = warzone.getWarzoneConfig().getInt(WarzoneConfig.CAPTUREPOINTTIME);
} }
CapturePoint cp = new CapturePoint(cpName, new Location(world, cpX, cpY, cpZ, cpYaw, 0), controller, strength, warzone); CapturePoint cp = new CapturePoint(cpName, new Location(world, cpX, cpY, cpZ, cpYaw, 0), controller, strength, warzone);
warzone.getCapturePoints().add(cp); warzone.getCapturePoints().add(cp);

View File

@ -2,6 +2,7 @@ package com.tommytony.war.structure;
import com.tommytony.war.Warzone; import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamKind; import com.tommytony.war.config.TeamKind;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.volume.Volume; import com.tommytony.war.volume.Volume;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Location; import org.bukkit.Location;
@ -47,7 +48,7 @@ public class CapturePoint {
private Volume volume; private Volume volume;
private Location location; private Location location;
private TeamKind controller, defaultController; private TeamKind controller, defaultController;
private int strength; private int strength, controlTime;
private Warzone warzone; private Warzone warzone;
public CapturePoint(String name, Location location, TeamKind defaultController, int strength, Warzone warzone) { public CapturePoint(String name, Location location, TeamKind defaultController, int strength, Warzone warzone) {
@ -55,6 +56,7 @@ public class CapturePoint {
this.defaultController = defaultController; this.defaultController = defaultController;
this.controller = defaultController; this.controller = defaultController;
this.strength = strength; this.strength = strength;
this.controlTime = 0;
this.warzone = warzone; this.warzone = warzone;
this.volume = new Volume("cp-" + name, warzone.getWorld()); this.volume = new Volume("cp-" + name, warzone.getWorld());
this.setLocation(location); this.setLocation(location);
@ -64,7 +66,7 @@ public class CapturePoint {
return location.clone().subtract(1, 1, 1).getBlock().getLocation(); return location.clone().subtract(1, 1, 1).getBlock().getLocation();
} }
public void updateBlocks() { private void updateBlocks() {
Validate.notNull(location); Validate.notNull(location);
// Set origin to back left corner // Set origin to back left corner
Location origin = this.getOrigin(); Location origin = this.getOrigin();
@ -99,7 +101,8 @@ public class CapturePoint {
// Add flag block // Add flag block
if (strength > 0 && controller != null) { if (strength > 0 && controller != null) {
// Make flag point direction of player when setting the capture point // Make flag point direction of player when setting the capture point
Vector dir = new Vector(1 + -Math.round(Math.sin(Math.toRadians(location.getYaw()))), strength, int flagHeight = (int) (strength / (getMaxStrength() / 4.0));
Vector dir = new Vector(1 + -Math.round(Math.sin(Math.toRadians(location.getYaw()))), flagHeight,
1 + Math.round(Math.cos(Math.toRadians(location.getYaw())))); 1 + Math.round(Math.cos(Math.toRadians(location.getYaw()))));
BlockState state = origin.clone().add(dir).getBlock().getState(); BlockState state = origin.clone().add(dir).getBlock().getState();
state.setType(controller.getMaterial()); state.setType(controller.getMaterial());
@ -145,10 +148,19 @@ public class CapturePoint {
} }
public void setStrength(int strength) { public void setStrength(int strength) {
Validate.isTrue(strength <= getMaxStrength());
this.strength = strength; this.strength = strength;
this.updateBlocks(); this.updateBlocks();
} }
public int getControlTime() {
return controlTime;
}
public void setControlTime(int controlTime) {
this.controlTime = controlTime;
}
public Volume getVolume() { public Volume getVolume() {
return volume; return volume;
} }
@ -166,4 +178,18 @@ public class CapturePoint {
} }
this.updateBlocks(); this.updateBlocks();
} }
private long lastMessage = 0;
public boolean antiChatSpam() {
long now = System.currentTimeMillis();
if (now - lastMessage > 3000) {
lastMessage = now;
return true;
}
return false;
}
public int getMaxStrength() {
return warzone.getWarzoneConfig().getInt(WarzoneConfig.CAPTUREPOINTTIME);
}
} }

View File

@ -91,6 +91,11 @@ zone.battle.resetprogress = Reset progress: {0}%, {1} seconds...
zone.battle.resetcomplete = Warzone reset in {0} seconds. A new battle begins. zone.battle.resetcomplete = Warzone reset in {0} seconds. A new battle begins.
zone.bomb.broadcast = {0} blew up team {1}''s spawn. Team {2} scores one point. zone.bomb.broadcast = {0} blew up team {1}''s spawn. Team {2} scores one point.
zone.cake.broadcast = {0} captured cake {1}. Team {2} scores one point and gets a full lifepool. zone.cake.broadcast = {0} captured cake {1}. Team {2} scores one point and gets a full lifepool.
zone.capturepoint.addpoint = Team {0} gained one point for maintaining control of capture point {1}.
zone.capturepoint.lose = Team {0} has lost control of capture point {1}.
zone.capturepoint.contest = Capture point {0} is being contested by {1}!
zone.capturepoint.capture = Team {0} has captured point {1}, gaining 1 extra point.
zone.capturepoint.fortify = Team {0} is gaining control of point {1}!
zone.flagcapture.broadcast = {0} captured team {1}''s flag. Team {2} scores one point. zone.flagcapture.broadcast = {0} captured team {1}''s flag. Team {2} scores one point.
zone.flagreturn.deadlock = You can't capture the enemy flag until your team's flag is returned. zone.flagreturn.deadlock = You can't capture the enemy flag until your team's flag is returned.
zone.flagreturn.flag = You have to capture the enemy flag at your team's flag. zone.flagreturn.flag = You have to capture the enemy flag at your team's flag.
@ -108,6 +113,7 @@ zone.score.board404 = This warzone has not enabled a scoreboard.
zone.score.empty = You can't score until at least one player joins another team. zone.score.empty = You can't score until at least one player joins another team.
zone.spawn.minplayers = You can''t leave spawn until there''s a minimum of {0} player(s) on at least {1} team(s). zone.spawn.minplayers = You can''t leave spawn until there''s a minimum of {0} player(s) on at least {1} team(s).
zone.spawn.timer = You can''t leave spawn for {0} second(s) after respawning! zone.spawn.timer = You can''t leave spawn for {0} second(s) after respawning!
zone.spawn.timer.title = Respawn in {0} second(s)...
zone.steal.bomb.broadcast = {0} has bomb {1}. zone.steal.bomb.broadcast = {0} has bomb {1}.
zone.steal.bomb.notice = You have bomb {0}. Reach another team''s spawn to score. Don''t get touched by anyone or you''ll blow up! zone.steal.bomb.notice = You have bomb {0}. Reach another team''s spawn to score. Don''t get touched by anyone or you''ll blow up!
zone.steal.bomb.prevent = Prevent {0} from reaching your spawn with the bomb! zone.steal.bomb.prevent = Prevent {0} from reaching your spawn with the bomb!