From a6a945281a041b54a91d16581ed3320e5b6ecd9a Mon Sep 17 00:00:00 2001 From: ArturPhilibin <1541024+ArturPhilibin@users.noreply.github.com> Date: Thu, 14 Feb 2019 20:22:03 +0000 Subject: [PATCH] New picking system (#133) * Changed picking system to 1-1-1-2-1-1-2-1 * removed code committed by accident from customizable picking system branch * changes picking order logic to handle cases where teams are larger than 6v6 * add a safety check on the picking logic to prevent a team ever growing beyond the team size limit regardless of the picking order defined * add a safety check on the picking logic to prevent a team ever growing beyond the team size limit regardless of the picking order defined --- lib/gather/gather.js | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/gather/gather.js b/lib/gather/gather.js index b8bad0b..b3a8a7a 100644 --- a/lib/gather/gather.js +++ b/lib/gather/gather.js @@ -256,19 +256,37 @@ Gather.prototype.modifyGatherer = function (user, callback){ }; // Determines picking order of teams -// Marine 1 pick first -// 2 picks for each team subsequently - +// Marine pick first Gather.prototype.pickingTurn = function () { if (this.current !== 'selection') return null; - let alienCount = this.aliens().length; - let marineCount = this.marines().length; - let total = marineCount + alienCount; - if (total === 2) return "marine"; // first pick for marines - 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"; - return "alien"; // after aliens picked two whenever numbers are equal its aliens turn again + + const captainCount = 2; + const alienCount = this.aliens().length; + const marineCount = this.marines().length; + const alreadyPickedCount = (marineCount + alienCount) - captainCount; + const pickingPattern = [ // 1-1-1-2-1-1-2-1 + "marine", + "alien", + "marine", + "alien", + "alien", + "marine", + "alien", + "marine", + "marine", + "alien", + ]; + + const pickingTurn = alreadyPickedCount % pickingPattern.length; + + // prevent any team from growing beyond the team size limit + if (marineCount >= this.teamSize) { + return "alien"; + } else if (alienCount >= this.teamSize) { + return "marine"; + } + + return pickingPattern[pickingTurn]; }; // Moves player to marine