Skip to content

Instantly share code, notes, and snippets.

@HoeenCoder
Created April 14, 2017 15:13
Show Gist options
  • Save HoeenCoder/d012d39eeb5e0f941a278e04040b785f to your computer and use it in GitHub Desktop.
Save HoeenCoder/d012d39eeb5e0f941a278e04040b785f to your computer and use it in GitHub Desktop.
Bot Hockey by HoeenHero
'use strict';
/*
Hockey Game for PS Node Bot
Coded by HoeenHero
*/
let names = ['Hurricanes', 'Blue Jackets', 'Devils', 'Islanders', 'Rangers', 'Flyers', 'Penguins', 'Capitals', 'Bruins', 'Sabers', 'Red Wings', 'Panthers', 'Canadians', 'Senators', 'Lightning', 'Maple Leafs', 'Blackhawks', 'Avalanche', 'Stars', 'Wild', 'Predators', 'Blues', 'Jets', 'Ducks', 'Coyotes', 'Flames', 'Oilers', 'Kings', 'Sharks', 'Canucks', 'Golden Knights'];
function generateBoxScore(room, goal, final) {
if (!hGames[room]) return '<span style="color:red">An error has occured.</span>';
let period = 'Error while calculating period';
if (hGames[room].period === 0) period = 'Pre-Game';
if (hGames[room].period < 4 && hGames[room].period !== 0) {
period = (hGames[room].intermission ? 'Intermission #' + hGames[room].period : 'Period #' + hGames[room].period);
} else if (hGames[room].period !== 0) {
let otNum = hGames[room].period - 3;
period = (otNum === 1 ? 'Overtime' : 'Overtime Period #' + otNum);
}
if (final) period = 'Final';
if (final && hGames[room].period > 3) period = 'Final/OT';
let output = '<center><div class="broadcast-blue" style="border: 5px solid white"><h2>' + hGames[room].team1.name + ' || ' + (goal === 1 ? '<blink>' + hGames[room].team1.goals + '</blink>' : hGames[room].team1.goals) + ' - ' + (goal === 2 ? '<blink>' + hGames[room].team2.goals + '</blink>' : hGames[room].team2.goals) + ' || ' + hGames[room].team2.name + '</h2><h5>' + period + '</h5><br/>';
output += '<div style="display: inline-block; width: 48%">';
output += '<b>Captain: </b>' + (hGames[room].team1.captain ? hGames[room].team1.captain : 'None Yet') + '<br/>';
for (let i = 0; i < hGames[room].team1.players.length; i++) {
if (hGames[room].team1.captain === hGames[room].team1.players[i]) continue;
if (hGames[room].team1.goalie === hGames[room].team1.players[i]) continue;
output += hGames[room].team1.players[i] + '<br/>';
}
output += '<b>Goalie: </b>' + (hGames[room].team1.goalie ? hGames[room].team1.goalie : 'None') + '<br/>';
output += '</div><div style="display: inline-block; width: 48%">';
output += '<b>Captain: </b>' + (hGames[room].team2.captain ? hGames[room].team2.captain : 'None Yet') + '<br/>';
for (let i = 0; i < hGames[room].team2.players.length; i++) {
if (hGames[room].team2.captain === hGames[room].team2.players[i]) continue;
if (hGames[room].team2.goalie === hGames[room].team2.players[i]) continue;
output += hGames[room].team2.players[i] + '<br/>';
}
output += '<b>Goalie: </b>' + (hGames[room].team2.goalie ? hGames[room].team2.goalie : 'None') + '<br/>';
output += '</div></div></center>';
return output;
}
function shuffle(arr) {
// In-place shuffle by Fisher-Yates algorithm
for (let i = arr.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
let temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
return arr;
}
function findZone(room, by) {
by = toId(by);
if (!hGames[room]) return false;
if (!hGames[room].playerList.indexOf(by) < 0) return false;
if (hGames[room].ice.zone1.indexOf(by) > -1) return 'zone1';
if (hGames[room].ice.center.indexOf(by) > -1) return 'center';
if (hGames[room].ice.zone2.indexOf(by) > -1) return 'zone2';
return false;
}
function setupTimer(room, quiet, ot) {
if (!hGames[room]) return Bot.say(room, 'An error occured in setupTimer(), please contact HoeenHero.');
if (!hGames[room].intermission && hGames[room].period === 3 && !ot) return endGame(room);
if (ot) {
if (hGames[room].intermission) {
hGames[room].intermission = false;
hGames[room].period++;
Bot.say(room, '/announce It\'s time to start Overtime ' + (hGames[room].period === 4 ? '' : ' period #' + (hGames[room].period-3)) + '!');
Bot.say(room, '/announce 3 minutes to play.');
runFaceOff(room, hGames[room].team1.captain, hGames[room].team2.captain);
clearTimeout(gameTimers[room]);
gameTimers[room] = setTimeout(function() {
setupTimer(room, false, true);
}, 300000);
return;
} else {
hGames[room].intermission = true;
if (!quiet) {
if (hGames[room].period === 3) {
Bot.say(room, '/announce End of period #3!');
Bot.say(room, '/announce You have 30 seconds to prepare before Overtime starts.');
} else {
Bot.say(room, '/announce End of Overtime ' + (hGames[room].period === 4 ? '' : ' period #' + (hGames[room].period-3)) + '!');
Bot.say(room, '/announce You have 30 seconds to prepare before Overtime period #' + (hGames[room].period-2) + ' starts.');
}
}
clearTimeout(gameTimers[room]);
gameTimers[room] = setTimeout(function() {
setupTimer(room, false, true);
}, 30000);
return;
}
}
if (hGames[room].intermission) {
hGames[room].intermission = false;
hGames[room].period++;
Bot.say(room, '/announce It\'s time to start period #' + hGames[room].period + '!');
Bot.say(room, '/announce 3 minutes to play.');
resetIce(room);
runFaceOff(room, hGames[room].team1.captain, hGames[room].team2.captain);
clearTimeout(gameTimers[room]);
gameTimers[room] = setTimeout(function() {
setupTimer(room, false);
}, 180000);
return;
} else {
hGames[room].intermission = true;
if (!quiet) {
Bot.say(room, '/announce End of period #' + hGames[room].period + '!');
Bot.say(room, '/announce You have 30 seconds to prepare before period #' + (hGames[room].period+1) + ' starts.');
}
clearTimeout(gameTimers[room]);
gameTimers[room] = setTimeout(function() {
setupTimer(room, false);
}, 30000);
return;
}
}
function runFaceOff(room, C1, C2) {
if (!hGames[room]) return Bot.say(room, 'An error has occured in runFaceOff(). Contact HoeenHero.');
let winner = Math.round(Math.random());
if (winner === 0) {
Bot.say(room, '/announce ' + C1 + ' has won the faceoff.');
hGames[room].ice.hasPuck = C1;
} else {
Bot.say(room, '/announce ' + C2 + ' has won the faceoff.');
hGames[room].ice.hasPuck = C2;
}
hGames[room].paused = false;
}
function runGoal(room, team, by, ot) {
by = toId(by);
if (!hGames[room]) return Bot.say(room, 'An error has occured in runGoal(). Contact HoeenHero.');
hGames[room].paused = true;
Bot.say(room, '/announce ' + by + ' SCORES!');
hGames[room][team].goals++;
if (ot) return endGame(room);
Bot.say(room, '/addhtmlbox ' + generateBoxScore(room, Number(team.substring(4)), false));
Bot.say(room, '/announce Faceoff in 5 seconds.')
setTimeout(function() {
Bot.say(room, '/announce Faceoff');
resetIce(room);
runFaceOff(room, hGames[room].team1.captain, hGames[room].team2.captain);
}, 5000);
}
function resetIce(room) {
if (!hGames[room]) return Bot.say(room, 'An error has occured in resetIce(). Contact HoeenHero.');
let t1 = hGames[room].team1.players.slice(0);
if (hGames[room].team1.players.length >= 2) t1.splice(hGames[room].team1.players.indexOf(hGames[room].team1.goalie), 1);
let t2 = hGames[room].team2.players.slice(0);
if (hGames[room].team2.players.length >= 2) t2.splice(hGames[room].team2.players.indexOf(hGames[room].team2.goalie), 1);
hGames[room].ice = new ice(t1, t2, hGames[room].team1.goalie, hGames[room].team2.goalie);
}
function freezePuck(room, team) {
if (!hGames[room]) return Bot.say(room, 'An error has occured in freezePuck(). Contact HoeenHero.');
hGames[room].paused = true;
Bot.say(room, '/me blows whistle');
Bot.say(room, '/announce Puck frozen by ' + (hGames[room][team].goalie ? hGames[room][team].goalie : 'The ' + hGames[room][team].name + ' goalie') + '.');
Bot.say(room, '/announce Faceoff in 5 seconds.')
setTimeout(function() {
Bot.say(room, '/announce Faceoff');
resetIce(room);
runFaceOff(room, hGames[room].team1.captain, hGames[room].team2.captain);
}, 5000);
}
function checkOffside(room, team) {
if (!hGames[room]) return Bot.say(room, 'An error has occured in checkOffisde(). Contact HoeenHero.');
let opp = (team === 1 ? 2 : 1);
let oZone = hGames[room].ice['zone' + opp];
for (let i in oZone) {
if(hGames[room]['team' + team].players.indexOf(i) > -1) return true;
}
return false;
}
function endGame(room, forced) {
if (forced) {
Bot.say(room, '/announce Game forcibly ended.');
clearTimeout(gameTimers[room]);
delete hGames[room];
return;
}
if (hGames[room].team1.goals > hGames[room].team2.goals) {
Bot.say(room, 'The ' + hGames[room].team1.name + ' have won the game!');
Bot.say(room, '/addhtmlbox ' + generateBoxScore(room, 1, true));
} else if (hGames[room].team1.goals < hGames[room].team2.goals) {
Bot.say(room, 'The ' + hGames[room].team2.name + ' have won the game!');
Bot.say(room, '/addhtmlbox ' + generateBoxScore(room, 2, true));
} else {
//hGames[room].period++;
if (hGames[room].period === 3 && !hGames[room].intermission) Bot.say(room, '/announce Were going into overtime!');
return setupTimer(room, false, true);
}
clearTimeout(gameTimers[room]);
delete hGames[room];
}
function team(name) {
this.name = name;
this.id = toId(name);
this.captain = false;
this.players = [];
this.goalie = false;
this.goals = 0;
}
function game(team1, team2) {
let team1Name = (team1 ? team1.toString() : false);
let team2Name = (team2 ? team2.toString() : false);
let deck = shuffle(names);
if (!team1Name) team1Name = deck[Math.floor(Math.random() * deck.length)];
if (!team2Name) team2Name = deck[Math.floor(Math.random() * deck.length)];
if (toId(team1Name) === toId(team2Name)) {
let reroll = true;
while (reroll) {
team2Name = deck[Math.floor(Math.random() * deck.length)];
if (toId(team1Name) !== toId(team2Name)) reroll = false;
}
}
this.started = false;
this.ice = false; //for later
this.team1 = new team(team1Name, false, false);
this.team2 = new team(team2Name, false, false);
this.preSetTeams = false;
this.playerList = [];
this.period = 0;
this.intermission = false;
this.paused = false;
}
function ice(team1, team2, G1, G2) {
this.zone1 = (G1 ? [G1] : []);
this.center = team1.concat(team2);
this.zone2 = (G2 ? [G2] : []);
this.hasPuck = false;
this.pass = 0;
this.savePer = {
1: 70,
2: 70
};
this.block = {
1: false,
2: false
};
this.glove = {
1: false,
2: false
};
this.thief = {
1: 0,
2: 0,
active1: [],
active2: []
}
}
global.hGames = {};
global.gameTimers = {};
exports.commands = {
"h": 'hockey',
hockey: function (arg, by, room, cmd) {
by = toId(by);
let bypassArgs = ['help', 'h', 'c', 'code', 'v', 'version'];
if (this.roomType !== 'chat' && bypassArgs.indexOf(toId(arg)) === -1) return this.say(room, 'This game can only be played in chat rooms.');
if (this.roomType === 'chat' && Bot.rooms[room].users[toId(Bot.status.nickName)].substring(0, 1) !== '*') return this.restrictReply('I require rank * or higher to host this game.', 'wall');
arg = arg.split(',');
switch (toId(arg[0])) {
case 'new':
case 'n':
if (!this.isRoomRanked (room, '%')) return this.restrictReply('hockey new - Access denied.', 'wall');
if (hGames[room]) return this.restrictReply('There is already a game of hockey in this room.', 'wall');
if (this.roomType === 'pm') return this.pmReply('Games can only be made in chatrooms');
this.say(room, '/announce A new game of hockey is starting! Do ~h join to join the game.');
if ((arg[1] && arg[2]) && arg[1].trim() === arg[2].trim()) arg[2] = undefined; //No duplicate teams
hGames[room] = new game((arg[1] !== undefined ? arg[1].trim() : false), (arg[2] !== undefined ? arg[2].trim() : false));
gameTimers[room] = false;
break;
case 'join':
case 'j':
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].started) return this.pmReply('The game has already started.');
if (hGames[room].playerList.length >= 12) return this.pmReply('The game is full.');
if (hGames[room].playerList.indexOf(by) > -1) return this.pmReply('You already join the game.');
hGames[room].playerList.push(by);
this.say(room, '/announce ' + by + ' has joined the game.');
if (hGames[room].playerList.length >= 12) this.say(room, '/announce The player cap has been reached.');
break;
case 'leave':
case 'l':
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].started) return this.pmReply('The game has already started.');
let idx = hGames[room].playerList.indexOf(by);
if (idx === -1) return this.pmReply('You aren\'t in the game.');
hGames[room].playerList.splice(idx, 1);
this.say(room, '/announce ' + by + ' has left the game.');
if (hGames[room].preSetTeams) {
if (hGames[room].team1.players.length > Math.floor(hGames[room].playerList.length/2)) {
hGames[room].team1.players.splice(hGames[room].team1.players.length-1, 1);
this.say(room, hGames[room].team1.name + ' has lost a player to keep them below the player count.');
}
if (hGames[room].team2.players.length > Math.floor(hGames[room].playerList.length/2)) {
hGames[room].team2.players.splice(hGames[room].team2.players.length-1, 1);
this.say(room, hGames[room].team2.name + ' has lost a player to keep them below the player count.');
}
if (hGames[room].playerList.length === 3) {
hGames[room].team1.goalie = false;
hGames[room].team2.goalie = false;
this.say(room, 'Because there are less than 4 players, goalies have been disabled.');
}
}
break;
case 'scoreboard':
case 'sb':
if (!this.isRoomRanked (room, '%')) return this.restrictReply('hockey scoreboard - Access denied.', 'wall');
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
return this.say(room, '/addhtmlbox ' + generateBoxScore(room));
break;
case 'st':
case 'setteam':
if (!this.isRoomRanked (room, '%')) return this.restrictReply('hockey setteam - Access denied.', 'wall');
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].started) return this.pmReply('The game has already started.');
if (!hGames[room].preSetTeams) {
hGames[room].preSetTeams = true;
this.say(room, '/wall Teams will now be pre-set by a staff member. Anyone not set to a team when the game starts, will be asigned a random team.');
}
if (!arg[2]) return this.restrictReply('Usage: ~hockey setteam, [user], [0|1|2] - Set a player to the respective team. 0 means set to a random team.', 'wall');
arg[1] = toId(arg[1]);
let indx = hGames[room].playerList.indexOf(arg[1]);
if (indx === -1) return this.pmReply(arg[1] + ' isn\'t in the game.');
arg[2] = parseInt(arg[2]);
if (isNaN(arg[2])) return this.pmReply('Valid values for team are: 0, 1 or 2');
if (arg[2] === 0) {
if (hGames[room]['team1'].players.indexOf(arg[1]) > -1) {
if (hGames[room]['team1'].captain === arg[1]) hGames[room]['team1'].captain = false;
if (hGames[room]['team1'].goalie === arg[1]) hGames[room]['team1'].goalie = false;
hGames[room]['team1'].players.splice(hGames[room]['team1'].players.indexOf(arg[1]), 1);
return this.say(room, arg[1] + '\'s team will be randomly decided when the game starts.');
} else if (hGames[room]['team2'].players.indexOf(arg[1]) > -1) {
if (hGames[room]['team2'].captain === arg[1]) hGames[room]['team2'].captain = false;
if (hGames[room]['team2'].goalie === arg[1]) hGames[room]['team2'].goalie = false;
hGames[room]['team2'].players.splice(hGames[room]['team2'].players.indexOf(arg[1]), 1);
return this.say(room, arg[1] + '\'s team will be randomly decided when the game starts.');
} else return this.pmReply(arg[1] + ' is not on any team yet.');
}
if (hGames[room]['team' + arg[2]].players.indexOf(arg[1]) > -1) return this.pmReply(arg[1] + ' is already on the ' + hGames[room]['team' + arg[2]].name + '.');
let opp = arg[2] === 1 ? 2 : 1;
if (hGames[room]['team' + arg[2]].players.length >= Math.floor(hGames[room].playerList.length/2)) return this.say(room, 'This team is full. Try adding more players to the game to increase the team size limit.');
if (hGames[room]['team' + opp].players.indexOf(arg[1]) > -1) {
if (hGames[room]['team' + opp].captain === arg[1]) hGames[room]['team' + opp].captain = false;
if (hGames[room]['team' + opp].goalie === arg[1]) hGames[room]['team' + opp].goalie = false;
hGames[room]['team' + opp].players.splice(hGames[room]['team' + opp].players.indexOf(arg[1]), 1);
hGames[room]['team' + arg[2]].players.push(arg[1]);
return this.say(room, arg[1] + '\'s team was switched. They are now on the ' + hGames[room]['team' + arg[2]].name + '.');
} else {
hGames[room]['team' + arg[2]].players.push(arg[1]);
return this.say(room, arg[1] + ' was added to the ' + hGames[room]['team' + arg[2]].name + '\'s roster.');
}
break;
case 'sp':
case 'setposition':
if (!this.isRoomRanked (room, '%')) return this.restrictReply('hockey setposition - Access denied.', 'wall');
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].started) return this.pmReply('The game has already started.');
if (!hGames[room].preSetTeams) return this.restrictReply('Teams are currently random. If you want to do this, you need to set up teams with ~hockey setteam');
if (!arg[2]) return this.restrictReply('Usage: ~hockey setposition, [user], [captain|goalie|none] - Set a player to a position on a team. The user must be set to a team first.', 'wall');
arg[1] = toId(arg[1]);
let index = hGames[room].playerList.indexOf(arg[1]);
if (index === -1) return this.pmReply(arg[1] + ' isn\'t in the game.');
let cteam = 0;
if (hGames[room].team1.players.indexOf(arg[1]) > -1) cteam = 1;
if (hGames[room].team2.players.indexOf(arg[1]) > -1) cteam = 2;
if (!cteam) return this.restrictReply(arg[1] + ' is not assigned a team yet.', 'wall');
arg[2] = toId(arg[2]);
if (arg[2] !== 'captain' && arg[2] !== 'goalie' && arg[2] !== 'none') return this.pmReply('Valid positions are: captain, goalie, and none');
if (arg[2] === 'captain') {
if (hGames[room]['team' + cteam].captain === arg[1]) return this.pmReply(arg[1] + 'is already the ' + hGames[room]['team' + cteam].name + ' captain.');
if (hGames[room]['team' + cteam].goalie === arg[1]) hGames[room]['team' + cteam].goalie = false;
hGames[room]['team' + cteam].captain = arg[1];
return this.say(room, '/wall ' + arg[1] + ' is now the ' + hGames[room]['team' + cteam].name + ' captain.');
} else if (arg[2] === 'goalie') {
if (hGames[room].playerList.length < 4) return this.pmReply('We need 4 usokers to have goalies.');
if (hGames[room]['team' + cteam].goalie === arg[1]) return this.pmReply(arg[1] + 'is already the ' + hGames[room]['team' + cteam].name + ' goalie.');
if (hGames[room]['team' + cteam].captain === arg[1]) hGames[room]['team' + cteam].captain = false;
hGames[room]['team' + cteam].goalie = arg[1];
return this.say(room, '/wall ' + arg[1] + ' is now the ' + hGames[room]['team' + cteam].name + ' goalie.');
} else {
if (hGames[room]['team' + cteam].captain === arg[1]) hGames[room]['team' + cteam].captain = false;
if (hGames[room]['team' + cteam].goalie === arg[1]) hGames[room]['team' + cteam].goalie = false;
return this.say(room, arg[1] + '\'s position was set to none.');
}
break;
case 'rt':
case 'randomteams':
case 'randomizeteams':
if (!this.isRoomRanked (room, '%')) return this.restrictReply('hockey randomizeteams - Access denied.', 'wall');
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].started) return this.pmReply('The game has already started.');
if (!hGames[room].preSetTeams) return this.restrictReply('Teams are already random.', 'wall');
hGames[room].preSetTeams = false;
let team1Name = hGames[room].team1.name, team2Name = hGames[room].team2.name;
hGames[room].team1 = new team(team1Name, false, false);
hGames[room].team2 = new team(team2Name, false, false);
return this.say(room, '/wall Teams will now be decided randomly.');
break;
case 'start':
case 's':
if (!this.isRoomRanked (room, '%')) return this.restrictReply('hockey start - Access denied.', 'wall');
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].started) return this.pmReply('The game has already started.');
if (hGames[room].playerList.length < 2) return this.restrictReply('We need at least 2 players to start.', 'wall');
if (hGames[room].playerList.length % 2 !== 0) return this.restrictReply('We need an even number of players to start.', 'wall');
hGames[room].started = true;
//final check
if (hGames[room].playerList.length % 2 !== 0) {
hGames[room].started = false;
return this.restrictReply('We need an even number of players to start.', 'wall');
}
this.say(room, '/announce Signups are now closed.');
hGames[room].playerList = shuffle(hGames[room].playerList);
let list = hGames[room].playerList.slice(0);
for (let j = 0; j < list.length; j++) {
if (!hGames[room].preSetTeams) break;
if (hGames[room].team1.players.indexOf(list[j]) > -1) {
list.splice(j, 1);
j--;
}
if (hGames[room].team2.players.indexOf(list[j]) > -1) {
list.splice(j, 1);
j--;
}
}
let low = hGames[room].team1.players.length > hGames[room].team2.players.length ? 2 : 1; //Defaults to start with team 1 if equal
let high = low === 1 ? 2 : 1;
for(let i = 0; i < list.length; i++) {
if (list.length === 0) break;
if (hGames[room]['team' + low].players.length < hGames[room]['team' + high].players.length) {
hGames[room]['team' + low].players.push(list[i]);
continue;
} else hGames[room]['team' + high].players.push(list[i]);
}
if (!hGames[room].team1.captain) hGames[room].team1.captain = hGames[room].team1.players[0];
if (!hGames[room].team2.captain) hGames[room].team2.captain = hGames[room].team2.players[0];
if (hGames[room].team1.players.length >= 2 && !hGames[room].team1.goalie) hGames[room].team1.goalie = hGames[room].team1.players[(hGames[room].team1.players.length -1)];
if (hGames[room].team2.players.length >= 2 && !hGames[room].team2.goalie) hGames[room].team2.goalie = hGames[room].team2.players[(hGames[room].team2.players.length -1)];
this.say(room, '/addhtmlbox ' + generateBoxScore(room));
this.say(room, 'Teams have 30 seconds to plan for the game. Use ~hockey help for command help.');
resetIce(room);
setupTimer(room, true);
break;
case 'end':
case 'e':
if (!this.isRoomRanked (room, '%')) return this.restrictReply('hockey end - Access denied.', 'wall');
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
return endGame(room, true);
break;
case 'version':
case 'v':
return this.restrictReply('Bot Hockey by HoeenHero: v1.1.1', 'info');
break;
case 'help':
case 'h':
return this.restrictReply('Hockey instructions and help: http://pastebin.com/9DEyAfJg', 'info');
break;
case 'code':
case 'c':
return this.restrictReply('Hockey code, Coded by HoeenHero: http://pastebin.com/RPkNcZMY', 'info');
break;
default:
return this.restrictReply('Unrecoginized command. Use ~hockey help for a list of commands.', 'wall');
}
},
//forward commands
"s": 'shoot',
shoot: function (arg, by, room, cmd) {
by = toId(by);
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].playerList.indexOf(by) === -1) return this.pmReply('You are not in this game.');
if (hGames[room].team1.goalie === by || hGames[room].team2.goalie === by) return this.pmReply('Only forwards may do this.');
if (hGames[room].intermission || hGames[room].paused) return this.pmReply('You can only do this while play is in progress.');
if (hGames[room].ice.hasPuck === false || toId(hGames[room].ice.hasPuck) !== toId(by)) return this.pmReply('You cant shoot the puck if you dont have the puck.');
let team = 1;
let opp = 2;
if (hGames[room].team2.players.indexOf(by) > -1) team = 2;
if (team === 2) opp = 1;
if (hGames[room].ice['zone' + team].indexOf(by) > -1 || hGames[room].ice.center.indexOf(by) > -1) return this.pmReply('You can only shoot in the offensive zone, if your trying to shoot the puck up there without passing, try ~lob');
Bot.say('/announce ' + hGames[room].ice.hasPuck + ' shoots!');
let msg3 = 'Bounced off ' + (hGames[room]['team' + opp].goalie ? hGames[room]['team' + opp].goalie + '!' : 'the ' + hGames[room]['team' + opp].name + ' goalie!');
let blockMsg = 'Blocked by ' + (hGames[room]['team' + opp].goalie ? hGames[room]['team' + opp].goalie + '!' : 'the ' + hGames[room]['team' + opp].name + ' goalie!');
let messages = ['Shot is wide.', 'Just missed the net!', msg3, 'Off the goal post!', 'OUTSTANDING SAVE!'];
let shot = Math.round(Math.random() * 100);
if (shot > (hGames[room].ice.savePer[opp]-(hGames[room].ice.pass*2))) {
//GOAL!
if (hGames[room].period <= 3) {
return runGoal(room, 'team' + team, by);
} else return runGoal(room, 'team' + team, by, true);
} else {
if (shot > hGames[room].ice.savePer[opp]-20 && shot !== hGames[room].ice.savePer[opp] && hGames[room].ice.block[opp]) {
Bot.say(room, '/announce ' + blockMsg);
} else if (shot === hGames[room].ice.savePer[opp]) {
Bot.say(room, '/announce ' + messages[messages.length-1]);
} else if (hGames[room].ice.savePer[opp] - (hGames[room].ice.savePer[opp]/8) < shot) {
Bot.say(room, '/announce ' + messages[messages.length-2]);
} else if (hGames[room].ice.savePer[opp] - (hGames[room].ice.savePer[opp]/6) < shot) {
Bot.say(room, '/announce ' + messages[messages.length-3]);
} else if (hGames[room].ice.savePer[opp] - (hGames[room].ice.savePer[opp]/4) < shot) {
Bot.say(room, '/announce ' + messages[messages.length-4]);
} else Bot.say(room, '/announce ' + messages[messages.length-5]);
if (hGames[room].ice.glove[opp]) {
let chance = Math.round(Math.random());
if (chance === 1) return freezePuck(room, 'team'+opp);
}
//lose chance
if (Math.round(Math.random()) === 1) {
Bot.say(room, '/announce ' + hGames[room].ice.hasPuck + ' lost the puck!');
let taker = hGames[room].ice['zone' + opp][Math.floor(Math.random() * hGames[room].ice['zone' + opp].length)];
if (taker === by) return Bot.say(room, '/announce But ' + by + ' recovered the puck.');
Bot.say(room, '/announce ' + taker + ' took the puck.');
hGames[room].ice.hasPuck = taker;
}
}
},
"m": 'move',
move: function (arg, by, room, cmd) {
by = toId(by);
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].playerList.indexOf(by) === -1) return this.pmReply('You are not in this game.');
if (hGames[room].team1.goalie === by || hGames[room].team2.goalie === by) return this.pmReply('Only forwards may do this.');
if (hGames[room].intermission || hGames[room].paused) return this.pmReply('You can only do this while play is in progress.');
let team = 1;
let opp = 2;
if (hGames[room].team2.players.indexOf(by) > -1) team = 2;
if (team === 2) opp = 1;
if (hGames[room].ice.thief['active' + team].indexOf(by) > -1) return this.pmReply('You cannot move while trying to steal the puck.');
if (!arg) return this.pmReply('Where? Valid choices are o (offensive zone), c (Center), or d (Defensize zone)');
arg = toId(arg);
if (arg !== 'o' && arg !== 'c' && arg !== 'd') return this.pmReply('Invalid zone. Valid choices are o (offensive zone), c (Center), or d (Defensize zone)');
if ((hGames[room].ice['zone' + team].indexOf(by) > -1 && arg === 'o') || (hGames[room].ice['zone' + opp].indexOf(by) > -1 && arg === 'd')) return this.pmReply('You cannot move over multiple zones at once, move to center first. (use: ~m c)');
if ((hGames[room].ice['zone' + team].indexOf(by) > -1 && arg === 'd') || (hGames[room].ice['zone' + opp].indexOf(by) > -1 && arg === 'o') || (hGames[room].ice.center.indexOf(by) > -1 && arg === 'c')) return this.pmReply('Your already in that zone.');
let zone = findZone(room, by);
if (!zone) return Bot.say(room, 'An error has occured in ~move. Contact HoeenHero.');
if (hGames[room].ice.hasPuck && hGames[room].ice.hasPuck === by && arg === 'o' && checkOffside(room, team)) {
hGames[room].paused = true;
this.say(room, '/me blows whistle.');
this.say(room, '/announce The ' + hGames[room]['team' + team].name + ' are Offside.');
this.say(room, '/announce Faceoff in 5 seconds.');
setTimeout(function() {
Bot.say(room, '/announce Faceoff');
resetIce(room);
runFaceOff(room, hGames[room].team1.capitan, hGames[room].team2.capitan);
}, 5000);
return;
}
hGames[room].ice[zone].splice(hGames[room].ice[zone].indexOf(by), 1);
arg = (arg === 'o' ? ('zone' + opp) : (arg === 'c' ? 'center' : ('zone' + team)));
hGames[room].ice[arg].push(by);
if (hGames[room].ice.hasPuck !== false && hGames[room].ice.hasPuck === by) this.say(room, '/announce Puck moves to ' + (arg === 'center' ? arg : (arg === 'zone1' ? 'the ' + hGames[room].team1.name + ' zone' : 'the ' + hGames[room].team2.name + ' zone')));
this.pmReply('Moved to ' + (arg === 'center' ? arg : (arg === 'zone1' ? 'the ' + hGames[room].team1.name + ' zone' : 'the ' + hGames[room].team2.name + ' zone')));
if (hGames[room].ice.hasPuck === false && arg === ('zone' + hGames[room].ice.looseZone)) {
//take the puck
this.say(room, '/announce ' + by + ' recovers the loose puck.');
hGames[room].ice.loosePuck = false;
return hGames[room].ice.hasPuck = by;
}
return;
},
"t": 'thief',
thief: function (arg, by, room, cmd) {
by = toId(by);
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].playerList.indexOf(by) === -1) return this.pmReply('You are not in this game.');
if (hGames[room].team1.goalie === by || hGames[room].team2.goalie === by) return this.pmReply('Only forwards may do this.');
if (hGames[room].intermission || hGames[room].paused) return this.pmReply('You can only do this while play is in progress.');
if (hGames[room].ice.hasPuck && toId(hGames[room].ice.hasPuck) === toId(by)) return this.pmReply('You already have the puck!');
let team = 1;
let opp = 2;
if (hGames[room].team2.players.indexOf(by) > -1) team = 2;
if (team === 2) opp = 1;
if (hGames[room].ice.thief['active' + team].indexOf(by) > -1) return this.pmReply('You are already trying to steal the puck.');
if (hGames[room].ice.hasPuck === false) return this.pmReply('Nobody has the puck right now!');
if (hGames[room]['team' + team].players.indexOf(hGames[room].ice.hasPuck) > -1 || hGames[room].ice.hasPuck === hGames[room]['team' + team].goalie) return this.pmReply('You cant steal from a teammate!');
let zone = findZone(room, by);
if (!zone) return Bot.say(room, 'An error has occured in ~thief. Contact HoeenHero.');
let quickTheif = false;
if (hGames[room].ice[zone].indexOf(hGames[room].ice.hasPuck) > -1) quickTheif = true;
let chance = Math.ceil(Math.random() * 100);
if (chance > 90 && quickTheif) {
//steal
this.say(room, '/announce ' + by + ' takes the puck!');
return hGames[room].ice.hasPuck = by;
}
hGames[room].ice.thief['active' + team].push(by);
hGames[room].ice.thief[team] += 5;
setTimeout(function() {
hGames[room].ice.thief['active' + team].splice(hGames[room].ice.thief['active' + team].indexOf(by, 1));
hGames[room].ice.thief[team] -= 5;
Bot.pm(toId(by), 'Your thief has worn off!');
}, 3000);
return this.pmReply('Now trying to steal the puck.');
},
//commands useable by all positions
"p": 'pass',
pass: function (arg, by, room, cmd) {
by = toId(by);
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].playerList.indexOf(by) === -1) return this.pmReply('You are not in this game.');
if (hGames[room].intermission || hGames[room].paused) return this.pmReply('You can only do this while play is in progress.');
if (hGames[room].ice.hasPuck === false || toId(hGames[room].ice.hasPuck) !== toId(by)) return this.pmReply('You cant pass the puck if you dont have the puck.');
let team = 1;
let opp = 2;
if (hGames[room].team2.players.indexOf(by) > -1) team = 2;
if (team === 2) opp = 1;
let zone = findZone(room, by);
if (!zone) return Bot.say(room, 'An error has occured in ~pass. Contact HoeenHero.');
let isAlly = [];
let isOpp = [];
for (let player in hGames[room].ice[zone]) {
if (hGames[room]['team' + team].players.indexOf(hGames[room].ice[zone][player]) > -1 && hGames[room].ice[zone][player] !== by) {
isAlly.push(hGames[room].ice[zone][player]);
} else if (hGames[room].ice[zone][player] !== by) isOpp.push(hGames[room].ice[zone][player]);
}
if (isAlly.length === 0) return this.pmReply('There is nobody to pass to.');
isAlly = shuffle(isAlly);
let target = isAlly[Math.floor(Math.random() * isAlly.length)];
this.say(room, '/announce ' + by + ' passes to ' + target);
if (Math.ceil(Math.random() * 100) < (20 + hGames[room].ice.thief[opp]) && isOpp.length > 0) {
let taker = isOpp[Math.floor(Math.random() * isOpp.length)];
this.say(room, '/announce But it was intercepted by ' + taker + '!');
hGames[room].ice.pass = 0;
return hGames[room].ice.hasPuck = taker;
} else {
hGames[room].ice.pass++;
return hGames[room].ice.hasPuck = target;
}
},
"l": 'lob',
lob: function (arg, by, room, cmd) {
by = toId(by);
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].playerList.indexOf(by) === -1) return this.pmReply('You are not in this game.');
if (hGames[room].intermission || hGames[room].paused) return this.pmReply('You can only do this while play is in progress.');
if (hGames[room].ice.hasPuck === false || toId(hGames[room].ice.hasPuck) !== toId(by)) return this.pmReply('You cant lob the puck if you dont have the puck.');
let team = 1;
let opp = 2;
if (hGames[room].team2.players.indexOf(by) > -1) team = 2;
if (team === 2) opp = 1;
if (hGames[room].ice['zone' + opp].indexOf(by) > -1) return this.pmReply('You can only lob outside of the offensive zone, if your trying to shoot the puck, try ~shoot');
this.say(room, '/announce ' + by + ' lobs the puck.');
hGames[room].ice.pass = 0;
let zone = findZone(room, by);
if (!zone) return Bot.say(room, 'An error has occured in ~lob. Contact HoeenHero.');
let isOpp = [];
let end = hGames[room].ice['zone' + opp];
for (let player in hGames[room]['team' + opp].players) {
if (hGames[room].ice['zone' + opp].indexOf(hGames[room]['team' + opp].players[player]) > -1) {
//endOpp.push(hGames[room]['team' + opp].players[player]);
continue;
}
if (hGames[room].ice['zone' + team].indexOf(hGames[room]['team' + opp].players[player]) > -1 && zone === 'center') continue;
isOpp.push(hGames[room]['team' + opp].players[player]);
}
let chance = Math.ceil(Math.random() * 100);
if (chance < (30 + hGames[room].ice.thief[opp]) && isOpp.length > 0) {
//Intercepted
let taker = isOpp[Math.floor(Math.random() * isOpp.length)];
let takerZone = findZone(room, taker);
if (takerZone !== 'center') takerZone = 'the ' + hGames[room]['team' + zone.substring(4)].name + ' zone';
this.say(room, '/announce But it was intercepted by ' + taker + ' at ' + takerZone + '!');
return hGames[room].ice.hasPuck = taker;
} else {
if (hGames[room].ice['zone' + opp].length === 0) {
this.say(room, '/announce The puck is uncontrolled in the ' + hGames[room]['team' + opp].name + ' zone!');
hGames[room].ice.hasPuck = false; //loose puck
hGames[room].ice.looseZone = opp;
return;
} else {
let taker = false;
if (end.length !== 0) {
taker = end[Math.floor(Math.random() * end.length)];
} else {
taker = hGames[zone].ice['zone' + opp][Math.floor(Math.random() * hGames[zone].ice['zone' + opp].length)];
}
this.say(room, '/announce ' + taker + ' took the puck in the ' + hGames[room]['team' + opp].name + ' zone.');
return hGames[room].ice.hasPuck = taker;
}
}
},
//goalie commands
"g": 'glove',
glove: function (arg, by, room, cmd) {
by = toId(by);
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].playerList.indexOf(by) === -1) return this.pmReply('You are not in this game.');
if (hGames[room].team1.goalie !== by && hGames[room].team2.goalie !== by) return this.pmReply('Only goalies may do this.');
if (hGames[room].intermission || hGames[room].paused) return this.pmReply('You can only do this while play is in progress.');
let team = 1;
let opp = 2;
if (hGames[room].team2.players.indexOf(by) > -1) team = 2;
if (team === 2) opp = 1;
if (hGames[room].ice.block[team]) return this.pmReply('Your already blocking a shot!');
if (hGames[room].ice.glove[team]) return this.pmReply('Your already gloving a shot!');
hGames[room].ice.glove[team] = true;
hGames[room].ice.savePer[team] += 10;
setTimeout(function() {
hGames[room].ice.glove[team] = false;
hGames[room].ice.savePer[team] -= 10;
Bot.pm(toId(by), 'Your glove has worn off!');
}, 3000);
return this.pmReply('Now gloving the shot.');
},
"b": 'block',
block: function (arg, by, room, cmd) {
by = toId(by);
if (!hGames[room]) return this.pmReply('There is no active game in this room.');
if (hGames[room].playerList.indexOf(by) === -1) return this.pmReply('You are not in this game.');
if (hGames[room].team1.goalie !== by && hGames[room].team2.goalie !== by) return this.pmReply('Only goalies may do this.');
if (hGames[room].intermission || hGames[room].paused) return this.pmReply('You can only do this while play is in progress.');
let team = 1;
let opp = 2;
if (hGames[room].team2.players.indexOf(by) > -1) team = 2;
if (team === 2) opp = 1;
if (hGames[room].ice.block[team]) return this.pmReply('Your already blocking a shot!');
if (hGames[room].ice.glove[team]) return this.pmReply('Your already gloving a shot!');
hGames[room].ice.block[team] = true;
hGames[room].ice.savePer[team] += 20;
setTimeout(function() {
hGames[room].ice.block[team] = false;
hGames[room].ice.savePer[team] -= 20;
Bot.pm(toId(by), 'Your block has worn off!');
}, 3000);
return this.pmReply('Now blocking the shot.');
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment