From c1bcaa54ccc85f76134cd2cb9c83a448d900b193 Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Wed, 23 Dec 2020 17:03:21 -0500 Subject: [PATCH] move more --- src/js/utilsArcology.js | 47 +++++++++++++++++ src/js/utilsAssessSlave.js | 19 +++++++ src/js/utilsFC.js | 102 ------------------------------------- src/js/utilsSlave.js | 22 ++++++++ 4 files changed, 88 insertions(+), 102 deletions(-) create mode 100644 src/js/utilsArcology.js diff --git a/src/js/utilsArcology.js b/src/js/utilsArcology.js new file mode 100644 index 00000000000..4e75e1ee3ed --- /dev/null +++ b/src/js/utilsArcology.js @@ -0,0 +1,47 @@ +/** Returns the revivalist nationality associated with the player's arcology, or 0 if none + * @returns {string|0} + */ +globalThis.getRevivalistNationality = function() { + if (V.arcologies[0].FSRomanRevivalist > 90) { + return "Roman Revivalist"; + } else if (V.arcologies[0].FSAztecRevivalist > 90) { + return "Aztec Revivalist"; + } else if (V.arcologies[0].FSEgyptianRevivalist > 90) { + return "Ancient Egyptian Revivalist"; + } else if (V.arcologies[0].FSEdoRevivalist > 90) { + return "Edo Revivalist"; + } else if (V.arcologies[0].FSArabianRevivalist > 90) { + return "Arabian Revivalist"; + } else if (V.arcologies[0].FSChineseRevivalist > 90) { + return "Ancient Chinese Revivalist"; + } + return 0; +}; + +/** Calculate and return economic uncertainty multiplier for a given arcology + * @param {number} arcologyID + * @returns {number} + */ +App.Utils.economicUncertainty = function(arcologyID) { + let uncertainty = arcologyID === 0 ? 5 : 10; + if (assistant.power === 1) { + uncertainty -= Math.max(Math.trunc(uncertainty/2), 0); + } else if (assistant.power > 1) { + uncertainty = 0; + } + return jsRandom(100 - uncertainty, 100 + uncertainty) / 100; +}; + +/** + * @returns {number} + */ +App.Utils.schoolCounter = function() { + return Array.from(App.Data.misc.schools.keys()).filter(s => V[s].schoolPresent).length; +}; + +/** + * @returns {string} + */ +App.Utils.schoolFailure = function() { + return Array.from(App.Data.misc.schools.keys()).find(s => V[s].schoolPresent && V[s].schoolProsperity <= -10); +}; diff --git a/src/js/utilsAssessSlave.js b/src/js/utilsAssessSlave.js index e90d5749052..f42e0ad0677 100644 --- a/src/js/utilsAssessSlave.js +++ b/src/js/utilsAssessSlave.js @@ -222,3 +222,22 @@ globalThis.isShelterSlave = function(slave) { globalThis.perceivedGender = function(slave) { return -1; }; + +/** + * @param {App.Entity.SlaveState} A + * @param {App.Entity.SlaveState} B + * @returns {boolean} + */ +globalThis.sameAssignmentP = function(A, B) { + return A.assignment === B.assignment; +}; + +/** Determine whether a given penthouse slave can move into a private room or not. + * @param {App.Entity.SlaveState} slave + * @returns {boolean} + */ +globalThis.canMoveToRoom = function(slave) { + const partner = slave.relationship >= 4 ? getSlave(slave.relationshipTarget) : null; + const partnerHasRoom = partner && assignmentVisible(partner) && partner.rules.living === "luxurious"; + return partnerHasRoom || V.rooms - V.roomsPopulation >= 1; +}; diff --git a/src/js/utilsFC.js b/src/js/utilsFC.js index 9196be05032..0592144c545 100644 --- a/src/js/utilsFC.js +++ b/src/js/utilsFC.js @@ -117,26 +117,6 @@ globalThis.arrayToSentence = function(array) { return array.reduce((res, ch, i, arr) => res + (i === arr.length - 1 ? ' and ' : ', ') + ch); }; -/** Returns the revivalist nationality associated with the player's arcology, or 0 if none - * @returns {string|0} - */ -globalThis.getRevivalistNationality = function() { - if (V.arcologies[0].FSRomanRevivalist > 90) { - return "Roman Revivalist"; - } else if (V.arcologies[0].FSAztecRevivalist > 90) { - return "Aztec Revivalist"; - } else if (V.arcologies[0].FSEgyptianRevivalist > 90) { - return "Ancient Egyptian Revivalist"; - } else if (V.arcologies[0].FSEdoRevivalist > 90) { - return "Edo Revivalist"; - } else if (V.arcologies[0].FSArabianRevivalist > 90) { - return "Arabian Revivalist"; - } else if (V.arcologies[0].FSChineseRevivalist > 90) { - return "Ancient Chinese Revivalist"; - } - return 0; -}; - globalThis.penthouseCensus = function() { function occupiesRoom(slave) { if (slave.rules.living !== "luxurious") { @@ -159,16 +139,6 @@ globalThis.penthouseCensus = function() { V.dormitoryPopulation = penthouseSlaves.filter(s => s.rules.living !== "luxurious").length; }; -/** Determine whether a given penthouse slave can move into a private room or not. - * @param {App.Entity.SlaveState} slave - * @returns {boolean} - */ -globalThis.canMoveToRoom = function(slave) { - const partner = slave.relationship >= 4 ? getSlave(slave.relationshipTarget) : null; - const partnerHasRoom = partner && assignmentVisible(partner) && partner.rules.living === "luxurious"; - return partnerHasRoom || V.rooms - V.roomsPopulation >= 1; -}; - /** * @param {App.Entity.Facilities.Job|App.Entity.Facilities.Facility} jobOrFacility job or facility object * @returns {App.Entity.SlaveState[]} array of slaves employed at the job or facility, sorted in accordance to user choice @@ -203,20 +173,6 @@ App.Utils.countAssignmentWorkers = function(assignments) { return assignments.reduce((acc, cur) => { acc[cur] = V.JobIDMap[cur].size; return acc; }, {}); }; -/** Calculate and return economic uncertainty multiplier for a given arcology - * @param {number} arcologyID - * @returns {number} - */ -App.Utils.economicUncertainty = function(arcologyID) { - let uncertainty = arcologyID === 0 ? 5 : 10; - if (assistant.power === 1) { - uncertainty -= Math.max(Math.trunc(uncertainty/2), 0); - } else if (assistant.power > 1) { - uncertainty = 0; - } - return jsRandom(100 - uncertainty, 100 + uncertainty) / 100; -}; - /** Notify the game that the sidebar needs to be refreshed as soon as possible, but do not do it immediately. * This allows us to call this function repeatedly without impacting performance (for example, from repX() and cashX()). * The game will redraw the sidebar exactly once, as soon as all the scripts have finished executing. @@ -268,14 +224,6 @@ App.Utils.masterSuiteAverages = (function() { }; })(); -App.Utils.schoolCounter = function() { - return Array.from(App.Data.misc.schools.keys()).filter(s => V[s].schoolPresent).length; -}; - -App.Utils.schoolFailure = function() { - return Array.from(App.Data.misc.schools.keys()).find(s => V[s].schoolPresent && V[s].schoolProsperity <= -10); -}; - App.Utils.alphabetizeIterable = function(iterable) { const compare = function(a, b) { let aTitle = a.toLowerCase(); @@ -571,53 +519,3 @@ globalThis.randomRapeRivalryTarget = function(slave, predicate) { globalThis.getBestSlavesIDs = function(info) { return getBestSlaves(info).map(slave => slave.ID); }; - -/* -//Example -getBestSlaves({part:"butt", count: 5}); -getBestSlaves({part:"boobs"});//defaults to top 3 -getBestSlaves({part:"dick", smallest:true, filter:(slave)=>slave.dick > 0});//defaults to top 3 -getBestSlaves({part:slave=>slave.intelligence+slave.intelligenceImplant}); -*/ - -/** - * Generates a new slave ID that is guaranteed to be unused - * @returns {number} slave ID - */ -globalThis.generateSlaveID = function() { - // household liquidators and recETS generate slaves at an offset of 1000 (and many such slaves already exist) - // if you go through enough slaves you WILL generate collisions, so make sure we haven't just done that. - let allSlaveIDs = [...V.slaves.map((s) => s.ID), ...V.tanks.map((s) => s.ID), ...V.cribs.map((s) => s.ID)]; - while (allSlaveIDs.includes(V.IDNumber)) { - V.IDNumber++; - } - return V.IDNumber++; -}; - -globalThis.ASDump = function() { - if ((typeof V.activeSlave === undefined) || (V.activeSlave === 0)) { - return `<span class="red">ERROR:</span> AS Dump, activeSlave invalid, returnTo is 'V.returnTo', previous passage was '${previous()}'. Please report this. `; - } else { - let SL = V.slaves.length; - let ID = V.activeSlave.ID; - if (V.i >= 0 && V.i < SL && V.slaves[V.i].ID === ID) { /* shortcut if V.i is already pointing to this slave */ - V.slaves[V.i] = V.activeSlave; - } else { - V.i = V.slaveIndices[ID]; // find V.i if exists - if (typeof V.i === undefined) { /* not found, so new slave */ - newSlave(V.activeSlave); - } else { - V.slaves[V.i] = V.activeSlave; - } - } - } -}; - -/** - * @param {App.Entity.SlaveState} A - * @param {App.Entity.SlaveState} B - * @returns {boolean} - */ -globalThis.sameAssignmentP = function(A, B) { - return A.assignment === B.assignment; -}; diff --git a/src/js/utilsSlave.js b/src/js/utilsSlave.js index 0059cb694f8..51c864ea895 100644 --- a/src/js/utilsSlave.js +++ b/src/js/utilsSlave.js @@ -3446,3 +3446,25 @@ globalThis.slaveSkillIncrease = function(targetSkill, slave, skillIncrease = 1) slave.skill[targetSkill] += skillIncrease; return r; }; + +/* +//Example +getBestSlaves({part:"butt", count: 5}); +getBestSlaves({part:"boobs"});//defaults to top 3 +getBestSlaves({part:"dick", smallest:true, filter:(slave)=>slave.dick > 0});//defaults to top 3 +getBestSlaves({part:slave=>slave.intelligence+slave.intelligenceImplant}); +*/ + +/** + * Generates a new slave ID that is guaranteed to be unused + * @returns {number} slave ID + */ +globalThis.generateSlaveID = function() { + // household liquidators and recETS generate slaves at an offset of 1000 (and many such slaves already exist) + // if you go through enough slaves you WILL generate collisions, so make sure we haven't just done that. + let allSlaveIDs = [...V.slaves.map((s) => s.ID), ...V.tanks.map((s) => s.ID), ...V.cribs.map((s) => s.ID)]; + while (allSlaveIDs.includes(V.IDNumber)) { + V.IDNumber++; + } + return V.IDNumber++; +}; \ No newline at end of file -- GitLab