improvements

This commit is contained in:
walterhiggins 2013-05-11 16:03:49 +01:00
parent 81e2e2f76b
commit bbb2aabeb8
2 changed files with 37 additions and 10 deletions

View file

@ -42,7 +42,10 @@ var arrows = arrows || plugin("arrows",{
/* /*
change player's arrows to strike lightning where they land change player's arrows to strike lightning where they land
*/ */
lightning: function(player){} lightning: function(player){},
explosiveYield: 2.5
},true); },true);
/* /*
initialize data initialize data
@ -104,7 +107,7 @@ ready(function()
switch (arrowType){ switch (arrowType){
case 1: case 1:
projectile.remove(); projectile.remove();
world.createExplosion(projectile.location,2.5); world.createExplosion(projectile.location,arrows.explosiveYield);
break; break;
case 2: case 2:
projectile.remove(); projectile.remove();

View file

@ -34,23 +34,24 @@ SnowBallFight.prototype.start = function(){};
(function(){ (function(){
var _snowBalls = new org.bukkit.inventory.ItemStack(org.bukkit.Material.SNOW_BALL, 64);
/* /*
setup game setup game
*/ */
var _startGame = function(gameState){ var _startGame = function(gameState){
// don't let game start if already in progress (wait for game to finish) // don't let game start if already in progress (wait for game to finish)
if (gameState.inProgress) if (gameState.inProgress){
return; return;
}
gameState.inProgress = true; gameState.inProgress = true;
// reset timer // reset timer
gameState.duration = gameState.originalDuration; gameState.duration = gameState.originalDuration;
// put all players in survival mode and give them each 200 snowballs // put all players in survival mode and give them each 200 snowballs
// 64 snowballs for every 30 seconds should be more than enough // 64 snowballs for every 30 seconds should be more than enough
for (var i = 30;i < gameState.duration;i+=30) for (var i = 10;i < gameState.duration;i+=10)
gameState.ammo.push(_snowBalls); gameState.ammo.push(gameState.ammo[0]);
for (var teamName in gameState.teams) { for (var teamName in gameState.teams)
{
gameState.teamScores[teamName] = 0; gameState.teamScores[teamName] = 0;
var team = gameState.teams[teamName]; var team = gameState.teams[teamName];
for (var i = 0;i < team.length;i++) { for (var i = 0;i < team.length;i++) {
@ -66,8 +67,16 @@ SnowBallFight.prototype.start = function(){};
*/ */
var _endGame = function(gameState){ var _endGame = function(gameState){
var scores = []; var scores = [];
for (var tn in gameState.teamScores)
scores.push("Team " + tn + " scored " + gameState.teamScores[tn]); var leaderBoard = [];
for (var tn in gameState.teamScores){
leaderBoard.push([tn,gameState.teamScores[tn]]);
}
leaderBoard.sort(function(a,b){ return b[1] - a[1];});
for (var i = 0;i < leaderBoard.length; i++){
scores.push("Team " + leaderBoard[i][0] + " scored " + leaderBoard[i][1]);
}
for (var teamName in gameState.teams) { for (var teamName in gameState.teams) {
var team = gameState.teams[teamName]; var team = gameState.teams[teamName];
@ -99,7 +108,9 @@ SnowBallFight.prototype.start = function(){};
/* /*
construct a new game construct a new game
*/ */
var _constructor = function(teams, duration) { var _constructor = function(duration, teams) {
var _snowBalls = new org.bukkit.inventory.ItemStack(org.bukkit.Material.SNOW_BALL, 64);
var _gameState = { var _gameState = {
teams: teams, teams: teams,
@ -111,6 +122,19 @@ SnowBallFight.prototype.start = function(){};
savedModes: {}, savedModes: {},
ammo: [_snowBalls] ammo: [_snowBalls]
}; };
if (typeof duration == "undefined"){
duration = 60;
}
if (typeof teams == "undefined"){
/*
wph 20130511 use all players
*/
teams = [];
var players = server.onlinePlayers;
for (var i = 0;i < players.length; i++){
teams.push(players[i].name);
}
}
// //
// allow for teams param to be either {red:['player1','player2'],blue:['player3']} or // allow for teams param to be either {red:['player1','player2'],blue:['player3']} or
// ['player1','player2','player3'] if all players are against each other (no teams) // ['player1','player2','player3'] if all players are against each other (no teams)