/** creates an array from App.Data.HeroSlaves that will be similar to the old $heroSlaves.
 * @returns {Array}
 */
App.Utils.buildHeroArray = function() {
	let array;
	$.wiki(`<<include "custom Slaves Database">>`);
	if (V.seeExtreme === 1) {
		array = App.Data.HeroSlaves.D.concat(
			App.Data.HeroSlaves.DD,
			App.Data.HeroSlaves.DF,
			App.Data.HeroSlaves.Dextreme,
			App.Data.HeroSlaves.DDextreme,
			App.Data.HeroSlaves.DFextreme,
			V.heroSlaves
		);
	} else {
		array = App.Data.HeroSlaves.D.concat(
			App.Data.HeroSlaves.DD,
			App.Data.HeroSlaves.DF,
			V.heroSlaves
		);
	}
	delete V.heroSlaves;

	for (let hero = 0; hero < array.length; hero++) {
		if (V.seePreg !== 1 && [900089, 900102].includes(array[hero].ID)) {
			array.splice(hero, 1);
			hero--;
			continue;
		}
		if (V.heroSlavesPurchased.includes(array[hero].ID)) {
			array.splice(hero, 1);
			hero--;
			continue;
		}
	}
	return array;
};

/**
 * @param {App.Entity.SlaveState} heroSlave
 * @returns {App.Entity.SlaveState}
 */
App.Utils.getHeroSlave = function(heroSlave) {
	function repairLimbs(slave) {
		if (slave.hasOwnProperty("removedLimbs")) {
			if (slave.removedLimbs[0] === 1) {
				removeLimbs(slave, "left arm");
			}
			if (slave.removedLimbs[1] === 1) {
				removeLimbs(slave, "right arm");
			}
			if (slave.removedLimbs[2] === 1) {
				removeLimbs(slave, "left leg");
			}
			if (slave.removedLimbs[3] === 1) {
				removeLimbs(slave, "right leg");
			}
			delete slave.removedLimbs;
		}
	}

	if (!heroSlave.hasOwnProperty("birthWeek")) {
		heroSlave.birthWeek = random(0, 51);
	}
	// Nationalities, races, surnames random fill
	if (!heroSlave.nationality) {
		// Check for a pre-set race and if the nationality fits, else regenerate
		if (heroSlave.race && setup.filterRacesLowercase.includes(heroSlave.race)) {
			raceToNationality(heroSlave);
		} else {
			heroSlave.nationality = hashChoice(V.nationalities);
		}
	}
	if (!heroSlave.race || !setup.filterRacesLowercase.includes(heroSlave.race)) {
		nationalityToRace(heroSlave);
	}
	if (!heroSlave.birthSurname && heroSlave.birthSurname !== "") {
		heroSlave.birthSurname = (setup.surnamePoolSelector[heroSlave.nationality + "." + heroSlave.race] ||
			setup.surnamePoolSelector[heroSlave.nationality] ||
			setup.whiteAmericanSlaveSurnames).random();
	}
	if (!heroSlave.birthName && heroSlave.birthName !== "") {
		heroSlave.birthName = (setup.namePoolSelector[heroSlave.nationality + "." + heroSlave.race] ||
			setup.namePoolSelector[heroSlave.nationality] ||
			setup.whiteAmericanSlaveNames).random();
	}
	generatePronouns(heroSlave);
	if (heroSlave.geneMods === undefined) {
		heroSlave.geneMods = {};
	}
	if (heroSlave.geneMods.NCS === undefined) {
		heroSlave.geneMods.NCS = 0;
	}
	if (heroSlave.geneMods.rapidCellGrowth === undefined) {
		heroSlave.geneMods.rapidCellGrowth = 0;
	}

	// WombInit(heroSlave);
	const newSlave = BaseSlave();
	deepAssign(newSlave, heroSlave);
	V.heroSlaveID = heroSlave.ID;
	newSlave.ID = generateSlaveID();
	repairLimbs(newSlave);
	generatePuberty(newSlave);
	newSlave.weekAcquired = V.week;
	if (!newSlave.pubicHColor) {
		newSlave.pubicHColor = newSlave.hColor;
	}
	if (!newSlave.underArmHColor) {
		newSlave.underArmHColor = newSlave.hColor;
	}
	if (newSlave.override_Race !== 1) {
		newSlave.origRace = newSlave.race;
	}
	if (newSlave.override_Eye_Color !== 1) {
		resetEyeColor(newSlave, "both");
	}
	if (newSlave.override_H_Color !== 1) {
		newSlave.hColor = getGeneticHairColor(newSlave);
	}
	if (newSlave.override_Arm_H_Color !== 1) {
		newSlave.underArmHColor = getGeneticHairColor(newSlave);
	}
	if (newSlave.override_Pubic_H_Color !== 1) {
		newSlave.pubicHColor = getGeneticHairColor(newSlave);
	}
	if (newSlave.override_Brow_H_Color !== 1) {
		newSlave.eyebrowHColor = getGeneticHairColor(newSlave);
	}
	if (newSlave.override_Skin !== 1) {
		newSlave.skin = getGeneticSkinColor(newSlave);
	}

	SetBellySize(newSlave);

	/* special slaves exceptions to keep siblings sensible */
	if (newSlave.mother === -9999 && newSlave.father === -9998) {
		/* The twins — Camille & Kennerly */
		for (let k = 0; k < V.slaves.length; k++) {
			if (areSisters(V.slaves[k], newSlave) > 0) {
				newSlave.actualAge = V.slaves[k].actualAge, newSlave.physicalAge = newSlave.actualAge, newSlave.visualAge = newSlave.actualAge, newSlave.ovaryAge = newSlave.actualAge, newSlave.birthWeek = V.slaves[k].birthWeek;
			}
		}
	}
	if (newSlave.mother === -9997 && newSlave.father === -9996) {
		/* The siblings — Elisa & Martin */
		for (let k = 0; k < V.slaves.length; k++) {
			if (areSisters(V.slaves[k], newSlave) > 0) {
				if (newSlave.birthName === "Elisa") {
					newSlave.actualAge = V.slaves[k].actualAge - 1, newSlave.physicalAge = newSlave.actualAge, newSlave.visualAge = newSlave.actualAge, newSlave.ovaryAge = newSlave.actualAge;
				} else if (newSlave.birthName === "Martin") {
					newSlave.actualAge = V.slaves[k].actualAge + 1, newSlave.physicalAge = newSlave.actualAge, newSlave.visualAge = newSlave.actualAge, newSlave.ovaryAge = newSlave.actualAge;
				}
			}
		}
	}
	if (newSlave.mother === -9995 && newSlave.father === -9994) {
		/* The fruit siblings — Green & Purple Grape */
		for (let k = 0; k < V.slaves.length; k++) {
			if (areSisters(V.slaves[k], newSlave) > 0) {
				if (newSlave.birthName === "Green Grape") {
					newSlave.actualAge = V.slaves[k].actualAge - 5, newSlave.physicalAge = newSlave.actualAge, newSlave.visualAge = newSlave.actualAge, newSlave.ovaryAge = newSlave.actualAge;
				} else if (newSlave.birthName === "Purple Grape") {
					newSlave.actualAge = V.slaves[k].actualAge + 5, newSlave.physicalAge = newSlave.actualAge, newSlave.visualAge = newSlave.actualAge, newSlave.ovaryAge = newSlave.actualAge;
				}
			}
		}
	}

	nationalityToAccent(newSlave);
	return newSlave;
};
/**
 * Marks limbs to be removed when going trough App.Utils.getHeroSlave.
 * Does not actually remove limbs, only use on slaves that go through App.Utils.getHeroSlave!!
 * @param {{}}hero
 * @param {string} limb
 */
App.Utils.removeHeroLimbs = function(hero, limb = "all") {
	if (!hero.hasOwnProperty("removedLimbs")) {
		hero.removedLimbs = [0, 0, 0, 0];
	}

	switch (limb) {
		case "all":
			hero.removedLimbs = [1, 1, 1, 1];
			break;
		case "left arm":
			hero.removedLimbs[0] = 1;
			break;
		case "right arm":
			hero.removedLimbs[1] = 1;
			break;
		case "left leg":
			hero.removedLimbs[2] = 1;
			break;
		case "right leg":
			hero.removedLimbs[3] = 1;
			break;
	}
};

src/js/heroCreator.js