"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDraftSets = exports.getRandomHeroesByFaction = exports.initHeroesFromJson = void 0; function shuffle(a) { for (var i = a.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var _ref = [a[j], a[i]]; a[i] = _ref[0]; a[j] = _ref[1]; } return a; } var initHeroesFromJson = function initHeroesFromJson(allHeroesJson) { var abilitiesMap = new Map(); allHeroesJson.abilities.forEach(function (ability) { abilitiesMap.set(ability.abilityName, { name: ability.abilityName, hook: ability.abilityHook, isOptionnal: ability.optionnal, desc: ability['abilityDesc-FR'] }); }); var heroesSet = new Set(); allHeroesJson.heroes.forEach(function (hero) { var i = 0; while (i < hero.nbInDeck) { heroesSet.add({ name: hero.name, cost: hero.cost, power: hero.power, faction: hero.faction, ability: abilitiesMap.get(hero.ability), isDraftable: hero.draftMode, popularity: hero.popularity }); i++; } }); return heroesSet; }; exports.initHeroesFromJson = initHeroesFromJson; var getRandomHeroesByFaction = function getRandomHeroesByFaction(allHeroes, faction) { var factionArray = allHeroes.filter(function (hero) { return hero.faction === faction; }); return shuffle(factionArray); }; exports.getRandomHeroesByFaction = getRandomHeroesByFaction; var getDraftSets = function getDraftSets(allHeroes) { var heroesDraftable = allHeroes.filter(function (hero) { return hero.isDraftable === true; }); var shuffledHeroes = shuffle(heroesDraftable); // Return two sets of 12 heroes for draft mode var draftSets = [shuffledHeroes.slice(0, 11), shuffledHeroes.slice(12, 23)]; return draftSets; }; exports.getDraftSets = getDraftSets; //# sourceMappingURL=heroesHelper.js.map