Added team points and capture points (monuments). This is fun. :)

This commit is contained in:
taoneill 2011-01-04 01:16:05 -05:00
parent bc68f59611
commit 4bbb3f8c40
5 changed files with 441 additions and 23 deletions

View File

@ -0,0 +1,112 @@
public class Monument {
private Location location;
private int[] initialState = new int[10];
private War war = null;
private Team ownerTeam = null;
private final String name;
public Monument(String name, War war, Location location) {
this.name = name;
this.location = location;
this.war = war;
int x = (int)location.x;
int y = (int)location.y;
int z = (int)location.z;
initialState[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
initialState[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
initialState[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
initialState[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
initialState[4] = war.getServer().getBlockIdAt(x, y-1, z);
initialState[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
initialState[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
initialState[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
initialState[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
initialState[9] = war.getServer().getBlockIdAt(x, y, z);
this.reset();
}
public boolean isNear(Location playerLocation) {
int x = (int)getLocation().x;
int y = (int)getLocation().y;
int z = (int)getLocation().z;
int playerX = (int)playerLocation.x;
int playerY = (int)playerLocation.y;
int playerZ = (int)playerLocation.z;
int diffX = Math.abs(playerX - x);
int diffY = Math.abs(playerY - y);
int diffZ = Math.abs(playerZ - z);
if(diffX < 6 && diffY < 6 && diffZ < 6) {
return true;
}
return false;
}
public boolean isOwner(Team team) {
if(team == ownerTeam) {
return true;
}
return false;
}
public boolean hasOwner() {
return ownerTeam != null;
}
public void ignite(Team team) {
ownerTeam = team;
}
public void smother() {
ownerTeam = null;
}
public void reset() {
this.ownerTeam = null;
int x = (int)getLocation().x;
int y = (int)getLocation().y;
int z = (int)getLocation().z;
war.getServer().setBlockAt(49, x+1, y-1, z+1);
war.getServer().setBlockAt(49, x+1, y-1, z);
war.getServer().setBlockAt(49, x+1, y-1, z-1);
war.getServer().setBlockAt(49, x, y-1, z+1);
war.getServer().setBlockAt(87, x, y-1, z);
war.getServer().setBlockAt(49, x, y-1, z-1);
war.getServer().setBlockAt(49, x-1, y-1, z+1);
war.getServer().setBlockAt(49, x-1, y-1, z);
war.getServer().setBlockAt(49, x-1, y-1, z-1);
war.getServer().setBlockAt(0, x, y, z);
}
public void remove() {
int x = (int)getLocation().x;
int y = (int)getLocation().y;
int z = (int)getLocation().z;
war.getServer().setBlockAt(initialState[0], x+1, y-1, z+1);
war.getServer().setBlockAt(initialState[1], x+1, y-1, z);
war.getServer().setBlockAt(initialState[2], x+1, y-1, z-1);
war.getServer().setBlockAt(initialState[3], x, y-1, z+1);
war.getServer().setBlockAt(initialState[4], x, y-1, z);
war.getServer().setBlockAt(initialState[5], x, y-1, z-1);
war.getServer().setBlockAt(initialState[6], x-1, y-1, z+1);
war.getServer().setBlockAt(initialState[7], x-1, y-1, z);
war.getServer().setBlockAt(initialState[8], x-1, y-1, z-1);
war.getServer().setBlockAt(initialState[9], x, y, z);
}
public Location getLocation() {
return location;
}
public void setOwnerTeam(Team team) {
this.ownerTeam = team;
}
public String getName() {
return name;
}
}

View File

@ -6,10 +6,13 @@ public class Team {
private Location teamSpawn = null;
private String name;
private int remainingTickets;
private int[] oldSpawnState = new int[10];
private int points = 0;
public Team(String name, Location teamSpawn) {
this.setName(name);
this.teamSpawn = teamSpawn;
this.remainingTickets = War.LIFEPOOL;
}
public void setTeamSpawn(Location teamSpawn) {
@ -64,4 +67,20 @@ public class Team {
return remainingTickets;
}
public int[] getOldSpawnState() {
return oldSpawnState;
}
public void setOldSpawnState(int[] oldSpawnState) {
this.oldSpawnState = oldSpawnState;
}
public void addPoint() {
points++;
}
public int getPoints() {
return points;
}
}

View File

@ -43,6 +43,19 @@ public class War extends Plugin {
listener,
this,
PluginListener.Priority.MEDIUM);
etc.getLoader().addListener( PluginLoader.Hook.DISCONNECT,
listener,
this,
PluginListener.Priority.MEDIUM);
etc.getLoader().addListener( PluginLoader.Hook.IGNITE,
listener,
this,
PluginListener.Priority.MEDIUM);
etc.getLoader().addListener( PluginLoader.Hook.FLOW,
listener,
this,
PluginListener.Priority.MEDIUM);
// etc.getLoader().addListener(
// PluginLoader.Hook.BLOCK_CREATED,

View File

@ -1,4 +1,5 @@
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
@ -6,9 +7,11 @@ import java.util.logging.Level;
public class WarListener extends PluginListener {
private final War war;
private Random random = null;
public WarListener(War war) {
this.war = war;
random = new Random(war.getServer().getTime());
}
public void onLogin(Player player) {
@ -95,7 +98,8 @@ public class WarListener extends PluginListener {
for(Team team : teams) {
if(team.getName().equals(name)) {
team.addPlayer(player);
player.teleportTo(team.getTeamSpawn());
Warzone zone = war.warzone(player.getLocation());
zone.respawnPlayer(team, player);
foundTeam = true;
}
}
@ -169,7 +173,9 @@ public class WarListener extends PluginListener {
"Must be in a warzone (try /warzones and /warzone). "));
} else {
String name = split[1];
war.warzone(player.getLocation()).getTeams().add(new Team(name, player.getLocation()));
Team newTeam = new Team(name, player.getLocation());
war.warzone(player.getLocation()).getTeams().add(newTeam);
addSpawnArea(newTeam, player.getLocation(), 41);
player.sendMessage(war.str("Team " + name + " created with spawn here."));
}
return true;
@ -177,14 +183,28 @@ public class WarListener extends PluginListener {
// /setteamspawn
else if(command.equals("/setteamspawn")) {
if(split.length < 2 || war.getPlayerTeam(player.getName()) == null) {
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /setteamspawn <team-name>. " +
"Sets the team spawn. " +
"Must be in warzone and team must already exist."));
} else {
Team playerTeam = war.getPlayerTeam(player.getName());
playerTeam.setTeamSpawn(player.getLocation());
player.sendMessage(war.str("Team " + playerTeam + " spawn relocated."));
List<Team> teams = war.warzone(player.getLocation()).getTeams();
Team team = null;
for(Team t : teams) {
if(t.getName().equals(split[1])) {
team = t;
}
}
if(team != null) {
removeSpawnArea(team);
addSpawnArea(team, player.getLocation(), 41);
team.setTeamSpawn(player.getLocation());
player.sendMessage(war.str("Team " + team.getName() + " spawn relocated."));
} else {
player.sendMessage(war.str("Usage: /setteamspawn <team-name>. " +
"Sets the team spawn. " +
"Must be in warzone and team must already exist."));
}
}
return true;
}
@ -281,9 +301,81 @@ public class WarListener extends PluginListener {
return true;
}
// /monument
else if(command.equals("/monument")) {
if(!war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /monument <name>. Must be in warzone."));
} else {
Warzone warzone = war.warzone(player.getLocation());
Monument monument = new Monument(split[1], war, player.getLocation());
warzone.getMomuments().add(monument);
player.sendMessage(war.str("Monument " + monument.getName() + " created."));
}
return true;
}
return false;
}
private void removeSpawnArea(Team team) {
// Reset spawn to what it was before the gold blocks
int[] spawnState = team.getOldSpawnState();
int x = (int)team.getTeamSpawn().x;
int y = (int)team.getTeamSpawn().y;
int z = (int)team.getTeamSpawn().z;
war.getServer().setBlockAt(spawnState[0], x+1, y-1, z+1);
war.getServer().setBlockAt(spawnState[1], x+1, y-1, z);
war.getServer().setBlockAt(spawnState[2], x+1, y-1, z-1);
war.getServer().setBlockAt(spawnState[3], x, y-1, z+1);
war.getServer().setBlockAt(spawnState[4], x, y-1, z);
war.getServer().setBlockAt(spawnState[5], x, y-1, z-1);
war.getServer().setBlockAt(spawnState[6], x-1, y-1, z+1);
war.getServer().setBlockAt(spawnState[7], x-1, y-1, z);
war.getServer().setBlockAt(spawnState[8], x-1, y-1, z-1);
war.getServer().setBlockAt(spawnState[9], x, y, z);
}
private void addSpawnArea(Team team, Location location, int blockType) {
// Save the spawn state (i.e. the nine block under the player spawn)
int[] spawnState = new int[10];
int x = (int)location.x;
int y = (int)location.y;
int z = (int)location.z;
spawnState[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
spawnState[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
spawnState[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
spawnState[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
spawnState[4] = war.getServer().getBlockIdAt(x, y-1, z);
spawnState[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
spawnState[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
spawnState[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
spawnState[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
spawnState[9] = war.getServer().getBlockIdAt(x, y, z);
team.setTeamSpawn(location);
team.setOldSpawnState(spawnState);
// Set the spawn as gold blocks
war.getServer().setBlockAt(blockType, x+1, y-1, z+1);
war.getServer().setBlockAt(blockType, x+1, y-1, z);
war.getServer().setBlockAt(blockType, x+1, y-1, z-1);
war.getServer().setBlockAt(blockType, x, y-1, z+1);
war.getServer().setBlockAt(blockType, x, y-1, z);
war.getServer().setBlockAt(blockType, x, y-1, z-1);
war.getServer().setBlockAt(blockType, x-1, y-1, z+1);
war.getServer().setBlockAt(blockType, x-1, y-1, z);
war.getServer().setBlockAt(blockType, x-1, y-1, z-1);
Block block = new Block(63, x, y, z, 8);
war.getServer().setBlock(block);
block = war.getServer().getBlockAt(x, y, z);
ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z);
Sign sign = (Sign)complexBlock;
sign.setText(0, "Team");
sign.setText(1, team.getName());
sign.setText(2, "spawn");
sign.update();
}
public boolean onDamage(PluginLoader.DamageType damageType, BaseEntity attacker, BaseEntity defender, int damageAmount) {
if(attacker != null && defender != null && attacker.isPlayer() && defender.isPlayer()) {
// only let adversaries (same warzone, different team) attack each other
@ -329,10 +421,15 @@ public class WarListener extends PluginListener {
synchronized(zone) {
int remaining = team.getRemainingTickets();
if(remaining == 0) { // your death caused your team to lose
player.sendMessage(war.str("You died and your team's life pool was empty!"));
List<Team> teams = zone.getTeams();
for(Team t : teams) {
t.teamcast(war.str(player.getName() + " died but team " + team.getName() + "'s lifepool was empty. The battle is over."));
t.teamcast(war.str(player.getName() + " died but team " + team.getName() + "'s life pool was empty. "));
t.teamcast(war.str("The battle is over. Team " + team.getName() + " lost. "));
t.teamcast(war.str("A new battle begins. Team life pools are being reset..."));
if(!t.getName().equals(team.getName())) {
// all other teams get a point
t.addPoint();
}
}
zone.resetState();
roundOver = true;
@ -341,9 +438,15 @@ public class WarListener extends PluginListener {
}
}
if(!roundOver) {
player.teleportTo(team.getTeamSpawn());
player.setHealth(20);
zone.respawnPlayer(team, player);
player.sendMessage(war.str("You died!"));
List<Team> teams = zone.getTeams();
for(Team t : teams) {
t.teamcast(war.str(player.getName() + " died. Team " + team.getName() + " has " + team.getRemainingTickets() + "/" + War.LIFEPOOL + " lives left."));
if(team.getRemainingTickets() == 0) {
t.teamcast(war.str("Team " + team.getName() + "'s life pool is empty. One more death and they will lose!"));
}
}
war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn");
} else {
war.getLogger().log(Level.INFO, player.getName() + " died and battle ended in team " + team.getName() + "'s disfavor");
@ -352,7 +455,7 @@ public class WarListener extends PluginListener {
return true;
//return true;
}
}
return false;
@ -372,6 +475,14 @@ public class WarListener extends PluginListener {
player.sendMessage(war.str("Brought you back to your team spawn. Use /leave to exit the battle."));
}
}
if(to != null && playerTeam != null
&& playerWarzone.nearAnyOwnedMonument(to, playerTeam)
&& random.nextInt(42) == 3 ) { // one chance out of many of getting healed
player.setHealth(30);
player.sendMessage(war.str("Your dance has awakened the monument's voodoo. You were granted full health!"));
}
}
private String getAllTeamsMsg(Player player){
@ -380,7 +491,7 @@ public class WarListener extends PluginListener {
teamsMessage += "none.";
}
for(Team team : war.warzone(player.getLocation()).getTeams()) {
teamsMessage += team.getName() + " (" + team.getRemainingTickets() + "/" + War.LIFEPOOL + " lives left. ";
teamsMessage += team.getName() + " (" + team.getPoints() + " points, "+ team.getRemainingTickets() + "/" + War.LIFEPOOL + " lives left. ";
for(Player member : team.getPlayers()) {
teamsMessage += member.getName() + " ";
}
@ -388,4 +499,60 @@ public class WarListener extends PluginListener {
}
return teamsMessage;
}
public void onDisconnect(Player player) {
Team team = war.getPlayerTeam(player.getName());
if(team != null) {
team.removePlayer(player.getName());
}
}
public boolean onIgnite(Block block, Player player) {
if(player != null) {
Team team = war.getPlayerTeam(player.getName());
Warzone zone = war.getPlayerWarzone(player.getName());
if(team != null && block != null && zone != null && zone.isMonumentFirestone(block)) {
Monument monument = zone.getMonumentForFirestone(block);
if(!monument.hasOwner()) {
monument.ignite(team);
List<Team> teams = zone.getTeams();
for(Team t : teams) {
t.teamcast(war.str("Monument " + monument.getName() + " has been ignited by team " + team.getName() + "."));
}
} else {
player.sendMessage(war.str("Monument must be smothered first."));
}
}
}
return false;
}
public boolean onFlow(Block blockFrom, Block blockTo) {
Block block = null;
if(blockTo != null) {
block = blockTo;
} else if (blockFrom != null) {
block = blockFrom;
}
if(block != null) {
Warzone zone = war.warzone(new Location(block.getX(), block.getY(), block.getZ()));
if(zone != null &&
((blockTo != null && zone.isMonumentFirestone(blockTo)
|| (blockFrom != null && zone.isMonumentFirestone(blockFrom))))) {
Monument monument = null;
if(blockTo != null) monument = zone.getMonumentForFirestone(blockTo);
if(monument == null && blockFrom != null) monument = zone.getMonumentForFirestone(blockFrom);
if(monument.hasOwner()) {
monument.setOwnerTeam(null);
List<Team> teams = zone.getTeams();
for(Team team : teams) {
team.teamcast(war.str("Monument " + monument.getName() + " has been smothered."));
}
}
}
}
return false;
}
}

View File

@ -1,12 +1,12 @@
import java.util.ArrayList;
import java.util.List;
public class Warzone {
private String name;
private Location northwest;
private Location southeast;
private final List<Team> teams = new ArrayList<Team>();
private final List<Monument> monuments = new ArrayList<Monument>();
private final Server server;
private int[][][] initialState = null;
@ -36,7 +36,7 @@ public class Warzone {
}
public boolean contains(Location point) {
return point.x <= getSoutheast().x && point.x >= getNorthwest().x
return ready() && point.x <= getSoutheast().x && point.x >= getNorthwest().x
&& point.z <= getNorthwest().z && point.z >= getSoutheast().z;
}
@ -61,10 +61,31 @@ public class Warzone {
}
public void setNorthwest(Location northwest) {
this.northwest = northwest;
if(ready()) {
saveState();
// remove old nw sign, if any (replace with air)
if(this.northwest != null) {
int x = (int)this.northwest.x;
int y = (int)this.northwest.y;
int z = (int)this.northwest.z;
Block block = new Block(0, x, y, z);
server.setBlock(block);
}
this.northwest = northwest;
// add sign
int x = (int)northwest.x;
int y = (int)northwest.y;
int z = (int)northwest.z;
Block block = new Block(63, x, y, z, 10); // towards southeast
server.setBlock(block);
block = server.getBlockAt(x, y, z);
ComplexBlock complexBlock = server.getComplexBlock(x, y, z);
Sign sign = (Sign)complexBlock;
sign.setText(0, "Northwest");
sign.setText(1, "corner of");
sign.setText(2, "warzone");
sign.setText(3, name);
sign.update();
saveState();
}
public Location getNorthwest() {
@ -72,10 +93,31 @@ public class Warzone {
}
public void setSoutheast(Location southeast) {
this.southeast = southeast;
if(ready()) {
saveState();
// remove old se sign, if any (replace with air)
if(this.southeast != null) {
int x = (int)this.southeast.x;
int y = (int)this.southeast.y;
int z = (int)this.southeast.z;
Block block = new Block(0, x, y, z);
server.setBlock(block);
}
this.southeast = southeast;
// add sign
int x = (int)southeast.x;
int y = (int)southeast.y;
int z = (int)southeast.z;
Block block = new Block(63, x, y, z, 2); // towards northwest
server.setBlock(block);
block = server.getBlockAt(x, y, z);
ComplexBlock complexBlock = server.getComplexBlock(x, y, z);
Sign sign = (Sign)complexBlock;
sign.setText(0, "Southeast");
sign.setText(1, "corner of");
sign.setText(2, "warzone");
sign.setText(3, name);
sign.update();
saveState();
}
public Location getSoutheast() {
@ -156,12 +198,19 @@ public class Warzone {
// everyone back to team spawn with full health
for(Team team : teams) {
for(Player player : team.getPlayers()) {
player.setHealth(20);
player.teleportTo(team.getTeamSpawn());
respawnPlayer(team, player);
}
team.setRemainingTickets(War.LIFEPOOL);
}
// reset monuments
for(Monument monument : monuments) {
monument.reset();
}
this.setNorthwest(this.getNorthwest());
this.setSoutheast(this.getSoutheast());
return noOfResetBlocks;
}
return 0;
@ -171,4 +220,62 @@ public class Warzone {
}
public void respawnPlayer(Team team, Player player) {
Inventory playerInv = player.getInventory();
playerInv.clearContents();
playerInv.update();
playerInv.setSlot(new Item(Item.Type.StoneSword), 0);
playerInv.setSlot(new Item(Item.Type.Bow), 1);
playerInv.setSlot(new Item(Item.Type.Arrow, 12), 2);
playerInv.setSlot(new Item(Item.Type.StonePickaxe), 3);
playerInv.setSlot(new Item(Item.Type.StoneSpade), 4);
playerInv.addItem(new Item(Item.Type.Bread, 3));
playerInv.setSlot(new Item(Item.Type.LeatherBoots), 100);
playerInv.setSlot(new Item(Item.Type.LeatherLeggings), 101);
playerInv.setSlot(new Item(Item.Type.LeatherChestplate), 102);
playerInv.setSlot(new Item(Item.Type.LeatherHelmet), 103);
playerInv.update();
player.setHealth(30);
player.setFireTicks(0);
player.teleportTo(team.getTeamSpawn());
}
public boolean isMonumentFirestone(Block block) {
for(Monument monument : monuments) {
int x = (int)monument.getLocation().x;
int y = (int)monument.getLocation().y;
int z = (int)monument.getLocation().z;
if(x == block.getX() && y == block.getY() && z == block.getZ()) {
return true;
}
}
return false;
}
public Monument getMonumentForFirestone(Block block) {
for(Monument monument : monuments) {
int x = (int)monument.getLocation().x;
int y = (int)monument.getLocation().y;
int z = (int)monument.getLocation().z;
if(x == block.getX() && y == block.getY() && z == block.getZ()) {
return monument;
}
}
return null;
}
public boolean nearAnyOwnedMonument(Location to, Team team) {
for(Monument monument : monuments) {
if(monument.isNear(to) && monument.isOwner(team)) {
return true;
}
}
return false;
}
public List<Monument> getMomuments() {
return monuments;
}
}