Completed 7 player gather implementation

This commit is contained in:
Chris Blanchard 2016-04-01 13:26:43 +01:00
parent 8de18207d9
commit e35aebc802
5 changed files with 82 additions and 35 deletions

View file

@ -173,8 +173,9 @@ const GatherProgress = React.createClass({
},
gatheringProgress() {
const num = this.props.gather.gatherers.length;
const den = 12;
const gather = this.props.gather;
const num = gather.gatherers.length;
const den = gather.teamSize * 2;
const remaining = den - num;
const message = (remaining === 1) ?
"Waiting for last player" : `Waiting for ${remaining} more players`;
@ -186,11 +187,12 @@ const GatherProgress = React.createClass({
},
electionProgress() {
const num = this.props.gather.gatherers.reduce((acc, gatherer) => {
const gather = this.props.gather;
const num = gather.gatherers.reduce((acc, gatherer) => {
if (gatherer.leaderVote) acc++;
return acc;
}, 0);
const den = 12;
const den = gather.teamSize * 2;
return {
num: num,
den: den,
@ -199,17 +201,18 @@ const GatherProgress = React.createClass({
},
selectionProgress() {
const num = this.props.gather.gatherers.reduce((acc, gatherer) => {
const gather = this.props.gather;
const num = gather.gatherers.reduce((acc, gatherer) => {
if (gatherer.team !== "lobby") acc++;
return acc;
}, 0);
const den = 12;
const den = gather.teamSize * 2;
return {
num: num,
den: den,
message: `${num} out of ${den} players assigned. Waiting
on ${_.capitalize(this.props.gather.pickingTurn)}s to pick next...`
on ${_.capitalize(gather.pickingTurn)}s to pick next...`
};
},
@ -730,7 +733,7 @@ const GatherMenu = exports.GatherMenu = React.createClass({
key={gather.type}>
<strong>{gather.name}</strong>
<br />
{gather.description}
{`${gather.teamSize} v ${gather.teamSize} - ${gather.description}`}
</li>
);
})

View file

@ -158,7 +158,7 @@ const GatherPage = React.createClass({
public: {
gatherers: []
},
skilled: {
large: {
gatherers: []
}
},
@ -280,7 +280,7 @@ const GatherPage = React.createClass({
updateTitle() {
let gather = this.currentGather();
if (gather && this.state.updateTitle) {
document.title = `NSL Gathers (${gather.gatherers.length}/12)`;
document.title = `NSL Gathers (${gather.gatherers.length}/${gather.teamSize * 2})`;
return;
}
document.title = "NSL Gathers";

View file

@ -29,19 +29,19 @@ function Gather (options) {
time: null
};
this.TEAM_SIZE = 6;
this.teamSize = options.teamSize || 6;
// Store cooldown times for gather leaves
this.cooldown = {};
this.COOLDOWN_TIME = 60 * 3;// 3 Minutes
this.REGATHER_THRESHOLD = 8;
this.REGATHER_THRESHOLD = Math.floor(this.teamSize / 2) + 2;
this.type = options.type || "public";
this.name = options.name || "Public Gather";
this.description = options.description || "6 v 6 - No player requirements";
this.description = options.description || "No player requirements";
this.election = {
INTERVAL: 60000, // 1 Minute
@ -81,13 +81,13 @@ StateMachine.create({
onbeforeaddGatherer: function (event, from, to, user) {
if (this.needsToCoolOff(user)) return false;
this.addUser(user);
if (this.gatherers.length !== 12) return false;
if (!this.lobbyFull()) return false;
},
// Election State
onbeforeselectLeader: function (event, from, to, voter, candidate) {
this.voteForLeader(voter, candidate);
if (this.leaderVotes().length !== 12) return false;
if (!this.leaderVotesFull()) return false;
},
onenterelection: function () {
@ -133,8 +133,8 @@ StateMachine.create({
},
onbeforeconfirmSelection: function (event, from, to, leader) {
return (this.aliens().length === this.TEAM_SIZE
&& this.marines().length === this.TEAM_SIZE);
return (this.aliens().length === this.teamSize
&& this.marines().length === this.teamSize);
},
// Remove gatherer event
@ -167,8 +167,17 @@ StateMachine.create({
}
});
Gather.prototype.lobbyFull = function () {
return this.gatherers.length === (this.teamSize * 2);
};
Gather.prototype.leaderVotesFull = function () {
return this.leaderVotes().length === (this.teamSize * 2);
};
Gather.prototype.resetState = function () {
this.gatherers = [];
this.cancelElectionCountdown();
return this;
};
@ -235,23 +244,15 @@ Gather.prototype.pickingTurn = function () {
if (alienCount + marineCount === 2) return "marine";
if (marineCount > alienCount) return "alien";
if (marineCount < alienCount) return "marine";
switch (total) {
case 4:
return "alien";
case 6:
return "marine";
case 8:
return "alien";
case 10:
return "marine";
}
if (total % 4 === 0) return "alien";
return "marine";
};
// Moves player to marine
// Optional `mover` argument which will check mover credentials to select
// Credentials: Must be leader, must belong to team, must be turn to pick
Gather.prototype.moveToMarine = function (user, mover) {
if (this.marines().length >= this.TEAM_SIZE) return;
if (this.marines().length >= this.teamSize) return;
if (mover && this.containsUser(mover)) {
let leader = this.getGatherer(mover);
@ -272,7 +273,7 @@ Gather.prototype.moveToMarine = function (user, mover) {
// Credentials: Must be leader, must belong to team, must be turn to pick
Gather.prototype.moveToAlien = function (user, mover) {
if (this.aliens().length >= this.TEAM_SIZE) return;
if (this.aliens().length >= this.teamSize) return;
if (mover && this.containsUser(mover)) {
let leader = this.getGatherer(mover);
@ -325,6 +326,7 @@ Gather.prototype.toJson = function () {
startTime: this.electionStartTime(),
interval: this.election.INTERVAL
},
teamSize: this.teamSize,
done: {
time: this.done.time
},

View file

@ -19,12 +19,13 @@ const GATHER_CONFIGS = [
{
type: "public",
name: "Public Gather",
description: "No requirements, 6v6"
description: "No Requirements"
},
{
type: "skilled",
name: "Competitive Gather",
description: "Hive Requirements, 6v6"
type: "large",
name: "Large Gather",
description: "No Requirements",
teamSize: 7
}
];

View file

@ -41,6 +41,47 @@ describe("Gather Model:", function () {
});
});
describe("lobbyFull", () => {
let teamSize = 3;
beforeEach(() => {
gather = Gather({ teamSize: teamSize })
});
it ("returns false if lobby isn't full", () => {
assert.isFalse(gather.lobbyFull());
gather.addUser(user);
assert.isFalse(gather.lobbyFull());
});
it ("returns true if lobby is full", () => {
gatherers.forEach((g, i) => {
if (i < 6) gather.addUser(g);
});
assert.isTrue(gather.lobbyFull());
});
});
describe("leaderVotesFull", () => {
const teamSize = 3;
const gathererSubset = [];
let candidate;
beforeEach(() => {
gather = Gather({ teamSize: teamSize })
gatherers.forEach((g, i) => {
if (i < 6) gathererSubset.push(gather.addUser(g));
});
candidate = gatherers[0];
});
it ("returns false if leader votes are not all in", () => {
assert.isFalse(gather.leaderVotesFull());
gather.voteForLeader(gathererSubset[1], candidate);
assert.isFalse(gather.leaderVotesFull());
});
it ("returns true if leader votes are all in", () => {
gathererSubset.forEach(g => gather.voteForLeader(g, candidate));
assert.isTrue(gather.leaderVotesFull());
});
});
describe("moveToMarine", function () {
it ("moves a player to marine", function () {
gather.addUser(user);
@ -52,7 +93,7 @@ describe("Gather Model:", function () {
gatherers.forEach(function (gatherer, index) {
gather.addUser(gatherer);
gather.moveToMarine(gatherer);
assert.isTrue(gather.marines().length <= gather.TEAM_SIZE);
assert.isTrue(gather.marines().length <= gather.teamSize);
});
});
describe("with mover argument", function () {
@ -106,7 +147,7 @@ describe("Gather Model:", function () {
gatherers.forEach(function (gatherer, index) {
gather.addUser(gatherer);
gather.moveToAlien(gatherer);
assert.isTrue(gather.aliens().length <= gather.TEAM_SIZE);
assert.isTrue(gather.aliens().length <= gather.teamSize);
});
});
describe("with mover argument", function () {