Fixed leaving zone that was glitchy. Just approaching the gates now makes you leave. Fixed lifepool decrement by one too many bug with a dirty workaround for now. Ready to release v0.3 of next short test goes well.

This commit is contained in:
taoneill 2011-01-19 02:30:28 -05:00
parent 003b89f904
commit 3f164f60c5
4 changed files with 128 additions and 51 deletions

View File

@ -529,6 +529,7 @@ public class War extends JavaPlugin {
warzone.restorePlayerInventory(p);
player.sendMessage(this.str("You have left the warzone. Your inventory has (hopefully) been restored."));
}
team.getPlayers().clear();
}
Warzone resetWarzone = null;

View File

@ -71,55 +71,65 @@ public class WarPlayerListener extends PlayerListener {
// Player belongs to a warzone team but is outside: he just died! Handle death! Don't exempt the zone maker.
if(from != null && war.warzone(player.getLocation()) == null && team != null) {
// teleport to team spawn upon death
player.sendMessage(war.str("You died."));
boolean newBattle = false;
boolean scoreCapReached = false;
synchronized(playerWarzone) {
int remaining = team.getRemainingTickets();
if(remaining == 0) { // your death caused your team to lose
List<Team> teams = playerWarzone.getTeams();
for(Team t : teams) {
t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost: "
+ player.getName() + " died and there were no lives left in their life pool." ));
synchronized(player) {
int remaining = team.getRemainingTickets();
if(remaining == 0) { // your death caused your team to lose
List<Team> teams = playerWarzone.getTeams();
for(Team t : teams) {
t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost: "
+ player.getName() + " died and there were no lives left in their life pool." ));
if(!t.getName().equals(team.getName())) {
// all other teams get a point
t.addPoint();
t.resetSign();
if(!t.getName().equals(team.getName())) {
// all other teams get a point
t.addPoint();
t.resetSign();
}
}
}
// detect score cap
List<Team> scoreCapTeams = new ArrayList<Team>();
for(Team t : teams) {
if(t.getPoints() == playerWarzone.getScoreCap()) {
scoreCapTeams.add(t);
}
}
if(!scoreCapTeams.isEmpty()) {
String winnersStr = "Score cap reached! Winning team(s): ";
for(Team winner : scoreCapTeams) {
winnersStr += winner.getName() + " ";
}
winnersStr += ". The warzone is being reset... Please choose a new team.";
// Score cap reached. Reset everything.
// detect score cap
List<Team> scoreCapTeams = new ArrayList<Team>();
for(Team t : teams) {
t.teamcast(war.str(winnersStr));
t.getPlayers().clear(); // empty the team
if(t.getPoints() == playerWarzone.getScoreCap()) {
scoreCapTeams.add(t);
}
}
playerWarzone.getVolume().resetBlocks();
playerWarzone.initializeZone();
scoreCapReached = true;
} else {
// We can keep going
for(Team t : teams) {
t.teamcast(war.str("A new battle begins. The warzone is being reset..."));
if(!scoreCapTeams.isEmpty()) {
String winnersStr = "Score cap reached! Winning team(s): ";
for(Team winner : scoreCapTeams) {
winnersStr += winner.getName() + " ";
}
winnersStr += ". The warzone is being reset... Please choose a new team.";
// Score cap reached. Reset everything.
for(Team t : teams) {
t.teamcast(war.str(winnersStr));
for(Player tp : t.getPlayers()) {
if(tp.getName() != player.getName()) {
tp.teleportTo(playerWarzone.getTeleport());
}
}
t.setPoints(0);
t.getPlayers().clear(); // empty the team
}
playerWarzone.getVolume().resetBlocks();
playerWarzone.initializeZone();
scoreCapReached = true;
} else {
// We can keep going
for(Team t : teams) {
t.teamcast(war.str("A new battle begins. The warzone is being reset..."));
}
playerWarzone.getVolume().resetBlocks();
playerWarzone.initializeZone();
newBattle = true;
team.setRemainingTickets(team.getRemainingTickets()+1); // TODO get rid of this dirty workaround for the twice move-on-death bug
}
playerWarzone.getVolume().resetBlocks();
playerWarzone.initializeZone();
newBattle = true;
} else if(!team.getVolume().contains(player.getLocation())){
// only decrement points if the player is not already back at spawn
team.setRemainingTickets(remaining - 1);
}
} else {
team.setRemainingTickets(remaining - 1);
}
}
synchronized(player) {
@ -128,7 +138,7 @@ public class WarPlayerListener extends PlayerListener {
team.resetSign();
war.info(player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn");
} else if (scoreCapReached) {
player.teleportTo(playerWarzone.getTeleport());
event.setTo(playerWarzone.getTeleport());
team.resetSign();
war.info(player.getName() + " died and enemy team reached score cap");
} else if (newBattle){
@ -145,8 +155,8 @@ public class WarPlayerListener extends PlayerListener {
player.setHealth(20);
player.sendMessage(war.str("Your dance pleases the monument's voodoo. You gain full health!"));
}
} else if (war.inAnyWarzone(player.getLocation()) && !war.isZoneMaker(player.getName())) { // player is not in any team, but inside warzone boundaries, get him out
Warzone zone = war.warzone(player.getLocation());
} else if (war.inAnyWarzone(to) && !war.isZoneMaker(player.getName())) { // player is not in any team, but inside warzone boundaries, get him out
Warzone zone = war.warzone(to);
event.setTo(zone.getTeleport());
player.sendMessage(war.str("You can't be inside a warzone without a team."));
}
@ -223,11 +233,7 @@ public class WarPlayerListener extends PlayerListener {
event.setTo(war.getWarHub().getLocation());
player.sendMessage(war.str("Welcome to the War hub."));
}
} else if(war.inAnyWarzone(event.getFrom())) { // already in a team and in warzone, leaving
if(zone.getLobby().isAutoAssignGate(to)
|| zone.getLobby().isInTeamGate(TeamMaterials.TEAMDIAMOND, to)
|| zone.getLobby().isInTeamGate(TeamMaterials.TEAMIRON, to)
|| zone.getLobby().isInTeamGate(TeamMaterials.TEAMGOLD, to)) {
} else if(zone.getLobby().isLeavingZone(to)) { // already in a team and in warzone, leaving
// same as leave, except event.setTo
Team playerTeam = war.getPlayerTeam(player.getName());
playerTeam.removePlayer(player.getName());
@ -236,7 +242,7 @@ public class WarPlayerListener extends PlayerListener {
player.sendMessage(war.str("Left the zone."));
playerWarzone.restorePlayerInventory(player);
player.sendMessage(war.str("Your inventory has (hopefully) been restored."));
}
}
}
}

View File

@ -228,4 +228,8 @@ public class Team {
this.volume = volume;
}
public void setPoints(int score) {
this.points = score;
}
}

View File

@ -493,7 +493,12 @@ public class ZoneLobby {
||
(block.getX() == gateBlock.getFace(rightSide).getX()
&& block.getY() == gateBlock.getFace(rightSide).getY()
&& block.getZ() == gateBlock.getFace(rightSide).getZ());
&& block.getZ() == gateBlock.getFace(rightSide).getZ())
||
(block.getX() == gateBlock.getX()
&& block.getY() == gateBlock.getY() - 1
&& block.getZ() == gateBlock.getZ())
;
}
return false;
}
@ -573,4 +578,65 @@ public class ZoneLobby {
state.update(true);
}
}
public boolean isLeavingZone(Location location) {
BlockFace inside = null;
BlockFace left = null;
BlockFace right = null;
if (wall == BlockFace.NORTH) {
inside = BlockFace.SOUTH;
left = BlockFace.WEST;
right = BlockFace.EAST;
} else if (wall == BlockFace.EAST) {
inside = BlockFace.WEST;
left = BlockFace.NORTH;
right = BlockFace.SOUTH;
} else if (wall == BlockFace.SOUTH) {
inside = BlockFace.NORTH;
left = BlockFace.EAST;
right = BlockFace.WEST;
} else if (wall == BlockFace.WEST) {
inside = BlockFace.EAST;
left = BlockFace.SOUTH;
right = BlockFace.NORTH;
}
if(autoAssignGate != null){
if(leaving(location, autoAssignGate, inside, left, right)) return true;
} else if(diamondGate != null){
if(leaving(location, diamondGate, inside, left, right)) return true;
} else if(ironGate != null){
if(leaving(location, ironGate, inside, left, right)) return true;
} else if(goldGate != null){
if(leaving(location, goldGate, inside, left, right)) return true;
}
return false;
}
private boolean leaving(Location location, Block gate, BlockFace inside,
BlockFace left, BlockFace right) {
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
Block out = gate.getFace(inside);
Block outL = out.getFace(left);
Block outR = out.getFace(right);
Block out2 = gate.getFace(inside, 2);
Block out2L = out2.getFace(left);
Block out2R = out2.getFace(right);
if(out.getX() == x && out.getY() == y && out.getZ() == z) {
return true;
} else if(outL.getX() == x && outL.getY() == y && outL.getZ() == z) {
return true;
} else if(outR.getX() == x && outR.getY() == y && outR.getZ() == z) {
return true;
} else if(out2.getX() == x && out2.getY() == y && out2.getZ() == z) {
return true;
} else if(out2L.getX() == x && out2L.getY() == y && out2L.getZ() == z) {
return true;
} else if(out2R.getX() == x && out2R.getY() == y && out2R.getZ() == z) {
return true;
}
return false;
}
}