Skip to content
Snippets Groups Projects
itemAvailability.js 9.71 KiB
Newer Older
globalThis.isItemAccessible = (function() {
lowercasedonkey's avatar
lowercasedonkey committed
	return {
		array: array,
		entry: entry,
	};
lowercasedonkey's avatar
lowercasedonkey committed

lowercasedonkey's avatar
lowercasedonkey committed
	/**
lowercasedonkey's avatar
lowercasedonkey committed
	 * Checks whether an item is accessible
lowercasedonkey's avatar
lowercasedonkey committed
	 * @param {string} string Name of wearable item
	 * @param {string} [category="clothing"] that item is in clothing, collar, etc
	 * @param {App.Entity.SlaveState} [slave]
klorpa's avatar
klorpa committed
	 * @returns {boolean|string} Returns true if item is accessible, and false if it is not. If the slave param is set, it may sometimes return a string instead of false, explaining why the item can't be used with that slave.
lowercasedonkey's avatar
lowercasedonkey committed
	 */
lowercasedonkey's avatar
lowercasedonkey committed
	function entry(string, category = "clothing", slave) {
lowercasedonkey's avatar
lowercasedonkey committed
		if (V.cheatMode === 1) {
			return true;
		}
		let selectedDB;
		switch (category) {
			case "clothing":
			case "clothes":
				selectedDB = App.Data.clothes;
				break;
			case "collar":
				selectedDB = App.Data.slaveWear.collars;
				break;
			case "bellyAccessory":
				selectedDB = App.Data.slaveWear.bellyAccessories;
				break;
			case "buttplug":
				selectedDB = App.Data.buttplugs;
				break;
			case "buttplugAttachment":
				selectedDB = App.Data.slaveWear.buttplugAttachments;
				break;
			case "vaginalAccessory":
				selectedDB = App.Data.slaveWear.vaginalAccessories;
				break;
			case "vaginalAttachment":
				selectedDB = App.Data.slaveWear.vaginalAttachments;
				break;
			case "dickAccessory":
				selectedDB = App.Data.slaveWear.dickAccessories;
				break;
			case "shoes":
				selectedDB = App.Data.shoes;
				break;
lowercasedonkey's avatar
lowercasedonkey committed
			case "chastity":
				selectedDB = App.Data.slaveWear.chastityDevices;
lowercasedonkey's avatar
lowercasedonkey committed
				break;
			default:
				// console.log(`made a category for ${category} automatically, may need to define this by hand`);
				selectedDB = App.Data.slaveWear[category];
				break;
lowercasedonkey's avatar
lowercasedonkey committed
		}
		const item = selectedDB.get(string);
lowercasedonkey's avatar
lowercasedonkey committed
		if (!item) {
			console.log(`${string} is not a registered piece of clothing! Check App.Data.slaveWear.${category}`);
lowercasedonkey's avatar
lowercasedonkey committed
			return false; /* couldn't be found */
		}
		return isAvailable(item, category, slave);
lowercasedonkey's avatar
lowercasedonkey committed
	/**
lowercasedonkey's avatar
lowercasedonkey committed
	 * Returns array of wearable clothing in format [name, value], basically player facing / game data.
	 * @param {Map} map Map to look in (such as App.Data.clothes)
brickode's avatar
brickode committed
	 * @param {string} [filter] for example, if we want to filter clothing data by the "harsh" property, pass harsh as the parameter here.
lowercasedonkey's avatar
lowercasedonkey committed
	 * @param {any} [filterValue] remove any clothing where the .filter property does not match this value.  Function will evaluate undefined as false.
lowercasedonkey's avatar
lowercasedonkey committed
	 * @returns {Array}
	 */
	function array(map, filter, filterValue) {
lowercasedonkey's avatar
lowercasedonkey committed
		const array = [];
brickode's avatar
brickode committed
		for (const [key, obj] of map) {	// FIXME: 'key' is declared but its value is never read.
			if (filter && filterValue !== (obj[filter] || false)) {
				continue;
			}
			if (V.cheatMode || isAvailable(obj)) {
				const name = (obj.fs) ? `${obj.name} (FS)` : obj.name;
lowercasedonkey's avatar
lowercasedonkey committed
				array.push([name, key]);
lowercasedonkey's avatar
lowercasedonkey committed
			}
lowercasedonkey's avatar
lowercasedonkey committed
		return array;
lowercasedonkey's avatar
lowercasedonkey committed

Skriv's avatar
Skriv committed
	/**
	 * @param {object} item
	 * @param {string} [category="clothing"] that item is in clothing, collar, etc
	 * @param {App.Entity.SlaveState} [slave]
	 * @returns {boolean|string} Returns true if item is accessible, and false if it is not. If the slave param is set, it may sometimes return a string instead of false, explaining why the item can't be used with that slave.
	 */
	function isAvailable(item, category, slave) {
lowercasedonkey's avatar
lowercasedonkey committed
		let slaveResults;
lowercasedonkey's avatar
lowercasedonkey committed
		if (slave) {
lowercasedonkey's avatar
lowercasedonkey committed
			slaveResults = isAvailableForSlave(item, category, slave);
			if (slaveResults === false) {
lowercasedonkey's avatar
lowercasedonkey committed
				return slaveResults;
			}
		}
		if (!(item.hasOwnProperty("fs")) && !(item.hasOwnProperty("requirements"))) {
lowercasedonkey's avatar
lowercasedonkey committed
			// No restriction, this clothing item is available to everyone
		if (item.hasOwnProperty("requirements")) {
			if (item.requirements === true) {
lowercasedonkey's avatar
lowercasedonkey committed
				return true;
lowercasedonkey's avatar
lowercasedonkey committed
			}
		}
lowercasedonkey's avatar
lowercasedonkey committed
		if (item.hasOwnProperty("fs")) {
lowercasedonkey's avatar
lowercasedonkey committed
			if (V.arcologies[0][item.fs] > 0) {
				return true;
lowercasedonkey's avatar
lowercasedonkey committed
			}
lowercasedonkey's avatar
lowercasedonkey committed
		if (slaveResults && slaveResults !== true) { // If we still haven't returned true or false, then we display why this particular slave can't use the item.
lowercasedonkey's avatar
lowercasedonkey committed
			return slaveResults;
		}
lowercasedonkey's avatar
lowercasedonkey committed
		return false;
lowercasedonkey's avatar
lowercasedonkey committed
	}
lowercasedonkey's avatar
lowercasedonkey committed

Skriv's avatar
Skriv committed
	/**
	 * @param {object} item
	 * @param {string} [category="clothing"] that item is in clothing, collar, etc
	 * @param {App.Entity.SlaveState} [slave]
	 * @returns {boolean|string} Returns true if item is accessible, and false if it is not. If the slave param is set, it may sometimes return a string instead of false, explaining why the item can't be used with that slave.
	 */
lowercasedonkey's avatar
lowercasedonkey committed
	function isAvailableForSlave(item, category, slave) {
		switch (category) {
			case "clothing":
			case "clothes":
				break;
			case "collar":
				break;
			case "bellyAccessory": {
				switch (item.value) {
lowercasedonkey's avatar
lowercasedonkey committed
					case "a support band": {
						if (slave.belly > 10000) {
							return true;
						} else {
							return `Slave belly too small for this`;
						}
lowercasedonkey's avatar
lowercasedonkey committed
					}
					case "a small empathy belly":
					case "a medium empathy belly":
					case "a large empathy belly":
					case "a huge empathy belly": {
						if (slave.belly < 1500 && slave.weight < 130) {
							return true;
						} else {
							return `Slave belly too big for this`;
						}
					}
					default:
						return true;
				}
			}
			case "buttplug": {
				switch (item.value) {
lowercasedonkey's avatar
lowercasedonkey committed
					case "huge plug": {
						if (slave.anus < 2) {
							return `Slave's anus is too small for this right now`;
						} else {
							return true;
						}
lowercasedonkey's avatar
lowercasedonkey committed
					}
					case "long plug":
					case "long, large plug": {
						if (!(slave.breedingMark !== 1 || V.propOutcome === 0 || V.eugenicsFullControl === 1 || V.arcologies[0].FSRestart === "unset")) {
							return "Elites frown on this";
						} else {
							return true;
						}
					}
					case "long, huge plug": {
						if (slave.anus < 2) {
							return `Slave's anus is too small for this right now`;
						} else if (!(slave.breedingMark !== 1 || V.propOutcome === 0 || V.eugenicsFullControl === 1 || V.arcologies[0].FSRestart === "unset")) {
							return "Elites frown on this";
						} else {
							return true;
						}
					}
					default:
						return true;
				}
			}
			case "buttplugAttachment":
				break;
			case "vaginalAccessory": {
				if (slave.vagina < 0) {
					return false;
				}
				switch (item.value) {
lowercasedonkey's avatar
lowercasedonkey committed
					case "huge dildo": {
						if (slave.vagina < 2) {
							return `Slave's vagina is too small for this right now`;
						} else {
							return true;
						}
lowercasedonkey's avatar
lowercasedonkey committed
					}
					case "long dildo":
					case "long, large dildo": {
						if (!(slave.breedingMark !== 1 || V.propOutcome === 0 || V.eugenicsFullControl === 1 || V.arcologies[0].FSRestart === "unset")) {
							return "Elites frown on this";
						} else {
							return true;
						}
					}
					case "long, huge dildo": {
						if (slave.vagina < 2) {
							return `Slave's vagina is too small for this right now`;
						} else if (!(slave.breedingMark !== 1 || V.propOutcome === 0 || V.eugenicsFullControl === 1 || V.arcologies[0].FSRestart === "unset")) {
							return "Elites frown on this";
						} else {
							return true;
						}
					}
					default:
						return true;
				}
			}
			case "vaginalAttachment": {
				if (slave.vagina < 0) {
					return false;
				}
				switch (item.value) {
					case "vibrator":
						if (slave.vaginalAccessory === "none") {
							return "No vaginal accessory to attach it to";
						} else if (slave.vaginalAccessory === "bullet vibrator" || slave.vaginalAccessory === "smart bullet vibrator") {
							return "Vaginal accessory already vibrates";
						} else {
							return true;
						}
				}
				break;
			}
			case "dickAccessory":
Skriv's avatar
Skriv committed
				return (slave.dick >= 1);
			case "shoes":
				break;
			case "chastity": {
				switch (item.value) {
					case "chastity belt":
Skriv's avatar
Skriv committed
					case "combined chastity belt":
						return (slave.vagina > -1);
lowercasedonkey's avatar
lowercasedonkey committed
					case "chastity cage":
Skriv's avatar
Skriv committed
					case "combined chastity cage":
						return (slave.dick > 0);
lowercasedonkey's avatar
lowercasedonkey committed
					case "genital chastity":
Skriv's avatar
Skriv committed
					case "full chastity":
						return (slave.vagina > -1 && slave.dick > 0);
					case "choose own chastity":
						return (slave.choosesOwnChastity !== 1 && slave.devotion > 20 && slave.trust > 0);
					case "revoke choosing own chastity":
						return (slave.choosesOwnChastity > 0);
lowercasedonkey's avatar
lowercasedonkey committed
					default:
						return true;
lowercasedonkey's avatar
lowercasedonkey committed
		return true;
lowercasedonkey's avatar
lowercasedonkey committed
})();
Arkerthan's avatar
Arkerthan committed
/**
Arkerthan's avatar
Arkerthan committed
 * @param {App.Entity.SlaveState} slave
 * @param {string} prosthetic
 * @returns {boolean}
 */
globalThis.isProstheticAvailable = function(slave, prosthetic) {
	return slave.readyProsthetics.findIndex(function(p) { return p.id === prosthetic; }) !== -1;
};
Arkerthan's avatar
Arkerthan committed

/**
 * @param {App.Entity.SlaveState} slave
 * @param {string} prosthetic
 */
globalThis.addProsthetic = function(slave, prosthetic) {
Arkerthan's avatar
Arkerthan committed
	if (!isProstheticAvailable(slave, prosthetic)) {
		let limb = prostheticToLimb(prosthetic);
		if (limb > 0) {
			let p = {
				id: prosthetic,
lowercasedonkey's avatar
lowercasedonkey committed
				arm: {left: new App.Entity.LimbState(), right: new App.Entity.LimbState()},
				leg: {left: new App.Entity.LimbState(), right: new App.Entity.LimbState()}
			};
			p.arm.left.type = limb;
			p.arm.right.type = limb;
			p.leg.left.type = limb;
			p.leg.right.type = limb;
			slave.readyProsthetics.push(p);
		} else {
lowercasedonkey's avatar
lowercasedonkey committed
			slave.readyProsthetics.push({id: prosthetic});
Arkerthan's avatar
Arkerthan committed
	}
};
Arkerthan's avatar
Arkerthan committed
/**
 * @param {App.Entity.SlaveState} slave
 * @param {string} prosthetic
 * @returns {{}}
 */
globalThis.findProsthetic = function(slave, prosthetic) {
Arkerthan's avatar
Arkerthan committed
	return slave.readyProsthetics.find(p => p.id === prosthetic);
};

/**
 * @param {string} prosthetic
 * @returns {number}
 */
globalThis.prostheticToLimb = function(prosthetic) {
	switch (prosthetic) {
		case "basicL":
			return 2;
		case "sexL":
			return 3;
		case "beautyL":
			return 4;
		case "combatL":
			return 5;
		case "cyberneticL":
			return 6;
		default:
			return 0;
	}
};

/**
 *
 * @param {number} limb
 * @returns {string}
 */
globalThis.limbToProsthetic = function(limb) {
	switch (limb) {
		case 2:
			return "basicL";
		case 3:
			return "sexL";
		case 4:
			return "beautyL";
		case 5:
			return "combatL";
		case 6:
			return "cyberneticL";
		default:
			return "";
	}
};