Changed picking rotation

* Teams are now picked 1-2-1-1-1-1-1-1-1-1
This commit is contained in:
Absurdon 2018-11-18 15:11:23 +01:00
parent 422b87d18a
commit ec17c604b9

View file

@ -9,7 +9,7 @@
* - Selection (Selecting teams) * - Selection (Selecting teams)
* - Done * - Done
* *
*/ */
const Gatherer = require("./gatherer"); const Gatherer = require("./gatherer");
const StateMachine = require("javascript-state-machine"); const StateMachine = require("javascript-state-machine");
@ -22,14 +22,14 @@ function Gather (options) {
} }
this.gatherers = []; this.gatherers = [];
let noop = () => {}; let noop = () => {};
this.onDone = (typeof options.onDone === 'function') ? this.onDone = (typeof options.onDone === 'function') ?
options.onDone : noop; options.onDone : noop;
this.onEvent = (typeof options.onEvent === 'function') ? this.onEvent = (typeof options.onEvent === 'function') ?
options.onEvent : noop; options.onEvent : noop;
this.done = { this.done = {
time: null time: null
}; };
this.teamSize = options.teamSize || 6; this.teamSize = options.teamSize || 6;
// Store cooldown times for gather leaves // Store cooldown times for gather leaves
@ -43,7 +43,7 @@ function Gather (options) {
this.name = options.name || "Classic Gather"; this.name = options.name || "Classic Gather";
this.description = options.description || "No player requirements"; this.description = options.description || "No player requirements";
this.election = { this.election = {
INTERVAL: 60000, // 1 Minute INTERVAL: 60000, // 1 Minute
startTime: null, startTime: null,
@ -65,10 +65,10 @@ StateMachine.create({
{ name: "selectLeader", from: "election", to: "selection" }, { name: "selectLeader", from: "election", to: "selection" },
{ name: "electionTimeout", from: "election", to: "selection" }, { name: "electionTimeout", from: "election", to: "selection" },
{ name: "confirmSelection", from: "selection", to: "done" }, { name: "confirmSelection", from: "selection", to: "done" },
{ {
name: "removeGatherer", name: "removeGatherer",
from: ["gathering", "election", "selection"], from: ["gathering", "election", "selection"],
to: "gathering" to: "gathering"
}, },
{ {
name: "regather", name: "regather",
@ -88,13 +88,13 @@ StateMachine.create({
if (this.failsTest(user)) return false; if (this.failsTest(user)) return false;
this.addUser(user); this.addUser(user);
if (!this.lobbyFull()) { if (!this.lobbyFull()) {
if(this.gatherers.length > this.teamSize && if(this.gatherers.length > this.teamSize &&
(null === discordBot.spamProtection.fillStatus || (null === discordBot.spamProtection.fillStatus ||
((new Date()).getTime() - discordBot.spamProtection.fillStatus.getTime())/1000 > 180)) { ((new Date()).getTime() - discordBot.spamProtection.fillStatus.getTime())/1000 > 180)) {
discordBot.notifyChannel("Join the gather at https://gathers.ensl.org | " + this.gatherers.length + " players are already waiting!"); discordBot.notifyChannel("Join the gather at https://gathers.ensl.org | " + this.gatherers.length + " players are already waiting!");
discordBot.spamProtection.fillStatus = new Date(); discordBot.spamProtection.fillStatus = new Date();
} }
return false; return false;
} }
}, },
@ -115,7 +115,7 @@ StateMachine.create({
this.cancelElectionCountdown(); this.cancelElectionCountdown();
}, },
// Selection State // Selection State
onenterselection: function () { onenterselection: function () {
// Remove all leaders and teams // Remove all leaders and teams
this.gatherers.forEach(gatherer => { this.gatherers.forEach(gatherer => {
@ -231,7 +231,7 @@ Gather.prototype.containsUser = function (user) {
return this.gatherers.some(gatherer => { return this.gatherers.some(gatherer => {
return gatherer.id === user.id; return gatherer.id === user.id;
}); });
}; };
Gather.prototype.addUser = function (user) { Gather.prototype.addUser = function (user) {
if (this.containsUser(user)) return null; if (this.containsUser(user)) return null;
@ -259,11 +259,11 @@ Gather.prototype.pickingTurn = function () {
let alienCount = this.aliens().length; let alienCount = this.aliens().length;
let marineCount = this.marines().length; let marineCount = this.marines().length;
let total = marineCount + alienCount; let total = marineCount + alienCount;
if (alienCount + marineCount === 2) return "marine"; if (total === 2) return "marine"; // first pick for marines
if (marineCount > alienCount) return "alien"; if (total === 4) return "alien"; // first pick round aliens got to picks
if (marineCount > alienCount) return "alien"; // applies only after first pick
if (marineCount < alienCount) return "marine"; if (marineCount < alienCount) return "marine";
if (total % 4 === 0) return "alien"; return "alien"; // after aliens picked two whenever numbers are equal its aliens turn again
return "marine";
}; };
// Moves player to marine // Moves player to marine
@ -274,7 +274,7 @@ Gather.prototype.moveToMarine = function (user, mover) {
if (mover && this.containsUser(mover)) { if (mover && this.containsUser(mover)) {
let leader = this.getGatherer(mover); let leader = this.getGatherer(mover);
if (leader.team !== "marine" || if (leader.team !== "marine" ||
!leader.leader || !leader.leader ||
this.pickingTurn() !== "marine") return; this.pickingTurn() !== "marine") return;
@ -295,7 +295,7 @@ Gather.prototype.moveToAlien = function (user, mover) {
if (mover && this.containsUser(mover)) { if (mover && this.containsUser(mover)) {
let leader = this.getGatherer(mover); let leader = this.getGatherer(mover);
if (leader.team !== "alien" || if (leader.team !== "alien" ||
!leader.leader || !leader.leader ||
this.pickingTurn() !== "alien") return; this.pickingTurn() !== "alien") return;
@ -304,7 +304,7 @@ Gather.prototype.moveToAlien = function (user, mover) {
} }
} }
return this.modifyGatherer(user, gatherer => gatherer.team = "alien"); return this.modifyGatherer(user, gatherer => gatherer.team = "alien");
}; };
Gather.prototype.moveToLobby = function (user) { Gather.prototype.moveToLobby = function (user) {
@ -328,7 +328,7 @@ Gather.prototype.marines = function () {
}; };
Gather.prototype.electionStartTime = function () { Gather.prototype.electionStartTime = function () {
return (this.election.startTime === null) ? return (this.election.startTime === null) ?
null : this.election.startTime.toISOString(); null : this.election.startTime.toISOString();
}; };