mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-01-19 16:11:01 +00:00
Implemented logic for ordered captain selection of team
This commit is contained in:
parent
2f07de1d1c
commit
eef26b30c0
3 changed files with 121 additions and 11 deletions
|
@ -98,8 +98,8 @@ StateMachine.create({
|
||||||
rank.sort((a, b) => {
|
rank.sort((a, b) => {
|
||||||
return a.count - b.count;
|
return a.count - b.count;
|
||||||
});
|
});
|
||||||
this.assignAlienLeader(parseInt(rank.pop().candidate, 0));
|
|
||||||
this.assignMarineLeader(parseInt(rank.pop().candidate, 0));
|
this.assignMarineLeader(parseInt(rank.pop().candidate, 0));
|
||||||
|
this.assignAlienLeader(parseInt(rank.pop().candidate, 0));
|
||||||
},
|
},
|
||||||
|
|
||||||
onbeforeconfirmSelection: (event, from, to, leader) => {
|
onbeforeconfirmSelection: (event, from, to, leader) => {
|
||||||
|
@ -197,14 +197,46 @@ Gather.prototype.pickingTurn = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Gather.prototype.moveToMarine = user => {
|
// 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 = (user, mover) => {
|
||||||
if (this.marines().length >= this.TEAM_SIZE) return;
|
if (this.marines().length >= this.TEAM_SIZE) return;
|
||||||
|
|
||||||
|
if (mover && this.containsUser(mover)) {
|
||||||
|
let leader = this.getGatherer(mover);
|
||||||
|
if (leader.team !== "marine" ||
|
||||||
|
!leader.leader ||
|
||||||
|
this.pickingTurn() !== "marine") return;
|
||||||
|
|
||||||
|
if (user && this.containsUser(user)) {
|
||||||
|
if (this.getGatherer(user).team !== "lobby") return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.modifyGatherer(user, gatherer => gatherer.team = "marine");
|
this.modifyGatherer(user, gatherer => gatherer.team = "marine");
|
||||||
};
|
};
|
||||||
|
|
||||||
Gather.prototype.moveToAlien = user => {
|
// Moves player to alien
|
||||||
|
// 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.moveToAlien = (user, mover) => {
|
||||||
if (this.aliens().length >= this.TEAM_SIZE) return;
|
if (this.aliens().length >= this.TEAM_SIZE) return;
|
||||||
this.modifyGatherer(user, gatherer => gatherer.team = "alien");
|
|
||||||
|
if (mover && this.containsUser(mover)) {
|
||||||
|
let leader = this.getGatherer(mover);
|
||||||
|
if (leader.team !== "alien" ||
|
||||||
|
!leader.leader ||
|
||||||
|
this.pickingTurn() !== "alien") return;
|
||||||
|
|
||||||
|
if (user && this.containsUser(user)) {
|
||||||
|
if (this.getGatherer(user).team !== "lobby") return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return this.modifyGatherer(user, gatherer => gatherer.team = "alien");
|
||||||
};
|
};
|
||||||
|
|
||||||
Gather.prototype.moveToLobby = user => {
|
Gather.prototype.moveToLobby = user => {
|
||||||
|
|
|
@ -199,6 +199,44 @@ describe("Gather Model:", function () {
|
||||||
assert.isTrue(gather.marines().length <= gather.TEAM_SIZE);
|
assert.isTrue(gather.marines().length <= gather.TEAM_SIZE);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("with mover argument", function () {
|
||||||
|
var marineCount, gathererCursor, alienLeader, marineLeader;
|
||||||
|
beforeEach(function () {
|
||||||
|
helper.populateGatherAndVotes(gather, gatherers);
|
||||||
|
alienLeader = gather.gatherers[1];
|
||||||
|
assert.equal(alienLeader.team, "alien");
|
||||||
|
marineLeader = gather.gatherers[0];
|
||||||
|
assert.equal(marineLeader.team, "marine");
|
||||||
|
gathererCursor = 2;
|
||||||
|
marineCount = gather.marines().length;
|
||||||
|
});
|
||||||
|
it ("moves player if mover is captain & is marine & current turn", function () {
|
||||||
|
gather.moveToMarine(gather.gatherers[gathererCursor], marineLeader);
|
||||||
|
assert.equal(gather.marines().length, marineCount + 1);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor].team, "marine");
|
||||||
|
});
|
||||||
|
it ("does not move player if mover is not in team", function () {
|
||||||
|
gather.moveToMarine(gather.gatherers[gathererCursor], alienLeader);
|
||||||
|
assert.equal(gather.marines().length, marineCount);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor].team, "lobby");
|
||||||
|
});
|
||||||
|
it ("does not move player if not captain", function () {
|
||||||
|
gather.moveToMarine(gather.gatherers[gathererCursor], marineLeader);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor].team, "marine");
|
||||||
|
gather.moveToAlien(gather.gatherers[gathererCursor + 1], alienLeader);
|
||||||
|
gather.moveToAlien(gather.gatherers[gathererCursor + 2], alienLeader);
|
||||||
|
assert.equal(gather.marines().length, 2);
|
||||||
|
assert.equal(gather.aliens().length, 3);
|
||||||
|
gather.moveToMarine(gather.gatherers[gathererCursor + 3],
|
||||||
|
gather.gatherers[gathererCursor]);
|
||||||
|
assert.equal(gather.marines().length, marineCount + 1);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor + 3].team, "lobby");
|
||||||
|
});
|
||||||
|
it ("does not move player if already assigned to team", function () {
|
||||||
|
gather.moveToMarine(alienLeader, marineLeader);
|
||||||
|
assert.equal(gather.gatherers[1].team, "alien");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("moveToAlien", function () {
|
describe("moveToAlien", function () {
|
||||||
|
@ -215,18 +253,48 @@ describe("Gather Model:", function () {
|
||||||
assert.isTrue(gather.aliens().length <= gather.TEAM_SIZE);
|
assert.isTrue(gather.aliens().length <= gather.TEAM_SIZE);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("with mover argument", function () {
|
||||||
|
var alienCount, gathererCursor, alienLeader, marineLeader;
|
||||||
|
beforeEach(function () {
|
||||||
|
helper.populateGatherAndVotes(gather, gatherers);
|
||||||
|
gather.moveToMarine(gather.gatherers[2]);
|
||||||
|
alienLeader = gather.gatherers[1];
|
||||||
|
assert.equal(alienLeader.team, "alien");
|
||||||
|
marineLeader = gather.gatherers[0];
|
||||||
|
assert.equal(marineLeader.team, "marine");
|
||||||
|
gathererCursor = 3;
|
||||||
|
alienCount = gather.aliens().length;
|
||||||
|
});
|
||||||
|
it ("moves player if mover is captain & is alien & current turn", function () {
|
||||||
|
gather.moveToAlien(gather.gatherers[gathererCursor], alienLeader);
|
||||||
|
assert.equal(gather.aliens().length, alienCount + 1);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor].team, "alien");
|
||||||
|
});
|
||||||
|
it ("does not move player if mover is not in team", function () {
|
||||||
|
gather.moveToAlien(gather.gatherers[gathererCursor], marineLeader);
|
||||||
|
assert.equal(gather.aliens().length, alienCount);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor].team, "lobby");
|
||||||
|
});
|
||||||
|
it ("does not move player if not captain", function () {
|
||||||
|
gather.moveToAlien(gather.gatherers[gathererCursor], alienLeader);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor].team, "alien");
|
||||||
|
alienCount++;
|
||||||
|
gather.moveToAlien(gather.gatherers[gathererCursor + 1],
|
||||||
|
gather.gatherers[gathererCursor]);
|
||||||
|
assert.equal(gather.aliens().length, alienCount);
|
||||||
|
assert.equal(gather.gatherers[gathererCursor + 1].team, "lobby");
|
||||||
|
});
|
||||||
|
it ("does not move player if already assigned to team", function () {
|
||||||
|
gather.moveToMarine(alienLeader, marineLeader);
|
||||||
|
assert.equal(gather.gatherers[1].team, "alien");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("pickingTurn", function () {
|
describe("pickingTurn", function () {
|
||||||
var marineLeader, alienLeader;
|
var marineLeader, alienLeader;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
gatherers.forEach(function (gatherer, index) {
|
helper.populateGatherAndVotes(gather, gatherers);
|
||||||
gather.addGatherer(gatherer);
|
|
||||||
});
|
|
||||||
gatherers.forEach(function (gatherer, index) {
|
|
||||||
let candidate = gather.gatherers[index % 2];
|
|
||||||
gather.selectLeader(gatherer, candidate);
|
|
||||||
});
|
|
||||||
marineLeader = gather.marineLeader();
|
marineLeader = gather.marineLeader();
|
||||||
alienLeader = gather.alienLeader();
|
alienLeader = gather.alienLeader();
|
||||||
assert.isNotNull(marineLeader);
|
assert.isNotNull(marineLeader);
|
||||||
|
|
|
@ -82,4 +82,14 @@ helpers.createMessage = function (options, callback) {
|
||||||
}, callback);
|
}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
helpers.populateGatherAndVotes = function (gather, gatherers) {
|
||||||
|
gatherers.forEach(function (gatherer, index) {
|
||||||
|
gather.addGatherer(gatherer);
|
||||||
|
});
|
||||||
|
gatherers.forEach(function (gatherer, index) {
|
||||||
|
let candidate = gather.gatherers[index % 2];
|
||||||
|
gather.selectLeader(gatherer, candidate);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = helpers;
|
module.exports = helpers;
|
Loading…
Reference in a new issue