diff --git a/src/js/utils.js b/src/js/utils.js index eca740c543cbcfbf5729fa9fbd766671d7152e05..2885e290d0761c5f6b1eb9c9931eab8e8409c562 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -297,3 +297,30 @@ App.Utils.topologicalSort = function(keys, edges) { return sorted; }; + +window.getBestSlaves = function({part, count=3, smallest=false, filter=null}={}){ + if(!_.isFunction(part)) { + const partName = part; + part = (slave)=>slave[partName]; + } + const sortMethod = smallest ? (left, right) => left.value - right.value : (left, right) => right.value - left.value; + if(filter == null) { + filter = ()=>true; + } + return V.slaves.map((slave, index)=>({slave, index})) + .filter(slaveInfo=>filter(slaveInfo.slave)) + .map(slaveInfo=>{ slaveInfo.value = part(slaveInfo.slave); return slaveInfo; }) + .sort(sortMethod) + .slice(0, count); +}; +window.getBestSlavesIndices= function(info) { + return getBestSlaves(info).map(slaveInfo => slaveInfo.index); +}; + +/* +//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}); +*/ diff --git a/src/uncategorized/costsBudget.tw b/src/uncategorized/costsBudget.tw index 90a07edc109863477f8980587a85fc791c74fb8b..303859b1d96cb426fa6506428611351650ec21f9 100644 --- a/src/uncategorized/costsBudget.tw +++ b/src/uncategorized/costsBudget.tw @@ -192,7 +192,7 @@ for (var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){ <h2>Slaves</h2> </tr> - <<print budgetLine("slaveUpkeep", "[[Slave maintenance|Costs Report Slaves][$nextButton = \"Back to Budget\", $nextLink = \"Costs Budget\"]] ($slaves.length slaves)")>> + <<print budgetLine("slaveUpkeep", "[[Slave maintenance|Costs Report Slaves][$nextButton = \"Back to Budget\", $nextLink = \"Costs Budget\"]] ($slaves.length slaves) <br> [[Underperforming Slaves|Underperforming Slaves]]")>> <<print budgetLine("extraMilk", "Extra milk")>> diff --git a/src/uncategorized/underperformingSlaves.tw b/src/uncategorized/underperformingSlaves.tw new file mode 100644 index 0000000000000000000000000000000000000000..5dcb8fe52a73651f1f5aceb473de884cbe8553d0 --- /dev/null +++ b/src/uncategorized/underperformingSlaves.tw @@ -0,0 +1,46 @@ +:: Underperforming Slaves [nobr] + +<<set $nextButton = "Back", $nextLink = "Costs Budget", $returnTo = "Costs Budget", $showEncyclopedia = 1>> +<p> + Master, while many of your slaves work hard to earn ยค each week, some succeed more than others. As a trader in slaves, you may appretiate the opportunity that comes when a particularly valuable slave is a low earner. Or perhaps you just want the chance to tweak these problem slaves and train them to be better. The choice is yours. +</p> +<<run App.UI.tabbar.handlePreSelectedTab($tabChoice.Options)>> + +<button class="tablinks" onclick="App.UI.tabbar.openTab(event, 'highSale')" id="tab highSale">Worth much but earning little</button> +<button class="tablinks" onclick="App.UI.tabbar.openTab(event, 'expensive')" id="tab expensive">Costing more than earning</button> + +<div id="highSale" class="tabcontent"> + <div class="content"> + <i>The following list is determined by dividing the sale price of a slave by their income last week (assuming they had income, that is).</i> + <<print App.UI.SlaveList.render.listMarkup( + getBestSlavesIndices( + { + part:(slave)=>(slaveCost(slave) / slave.lastWeeksCashIncome), + smallest:false, + count: 3, + filter:(slave)=>(["get milked", "work in the dairy", "whore", "work in the brothel", "work a glory hole", "be confined in the arcade"].includes(slave.assignment) && ((slave.weekAcquired + 1) < V.week) && slave.lastWeeksCashIncome) + } + ), + [], + App.UI.SlaveList.SlaveInteract.stdInteract + )>> + </div> +</div> + +<div id="expensive" class="tabcontent"> + <div class="content"> + <i>This list looks for slackers by weighing their weekly income against the weekly cost of providing for them.</i> + <<print App.UI.SlaveList.render.listMarkup( + getBestSlavesIndices( + { + part:(slave)=>(slave.lastWeeksCashIncome - getSlaveCost(slave)), + smallest:true, + count: 3, + filter:(slave)=>(["get milked", "work in the dairy", "whore", "work in the brothel", "work a glory hole", "be confined in the arcade"].includes(slave.assignment) && ((slave.weekAcquired + 1) < V.week)) + } + ), + [], + App.UI.SlaveList.SlaveInteract.stdInteract + )>> + </div> +</div>