From 7b75c13079f502b551a07f7716b8e1669f3e05fd Mon Sep 17 00:00:00 2001 From: Anony <solosenpai@protonmail.com> Date: Sat, 18 Jan 2020 09:24:50 -0800 Subject: [PATCH] Extract repeated logic for intelligence upgrade, can now be used in RA --- devNotes/Useful JS Function Documentation.txt | 2 ++ src/js/assayJS.js | 10 ++++++++++ src/uncategorized/saDrugs.tw | 3 +-- src/uncategorized/slaveInteract.tw | 3 +-- src/utility/miscWidgets.tw | 3 +-- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/devNotes/Useful JS Function Documentation.txt b/devNotes/Useful JS Function Documentation.txt index 5c1848870ba..65831888e72 100644 --- a/devNotes/Useful JS Function Documentation.txt +++ b/devNotes/Useful JS Function Documentation.txt @@ -22,6 +22,8 @@ PiercingScore(slave) - Returns int representing degree of piercings. Higher mean TatScore(slave) - Returns int representing degree of tattooing. Higher means more tattoos. +canImproveIntelligence(slave) - Returns if slave intelligence can be improved with Psychostimulants + sameAssignmentP(slave, slave) - Returns if slaves are on the same assignment. haveRelationP(slave1, slave2) - Returns if slave1 is related to second slave2. (NOT extended family mode compliant). diff --git a/src/js/assayJS.js b/src/js/assayJS.js index 514f84e69ca..c4835e1eba9 100644 --- a/src/js/assayJS.js +++ b/src/js/assayJS.js @@ -7,6 +7,16 @@ window.sameAssignmentP = function sameAssignmentP(A, B) { return A.assignment === B.assignment; }; +/** + * @param {App.Entity.SlaveState} slave + * @returns {boolean} + */ +window.canImproveIntelligence = function canImproveIntelligence(slave) { + let origIntel = V.genePool.find(function(s) { return s.ID == slave.ID; }).intelligence + return (slave.intelligence < origIntel+15) && (slave.intelligence < 100) +}; + + /** * @param {App.Entity.SlaveState} slave * @param {App.Entity.SlaveState} target diff --git a/src/uncategorized/saDrugs.tw b/src/uncategorized/saDrugs.tw index fa8a1bac291..cc4ee86fb15 100644 --- a/src/uncategorized/saDrugs.tw +++ b/src/uncategorized/saDrugs.tw @@ -1519,8 +1519,7 @@ <<set $slaves[$i].drugs = "no drugs">> <</if>> <<case "psychostimulants">> - <<set _origIntel = $genePool.find(function(s) { return s.ID == $slaves[$i].ID; }).intelligence>> - <<if ($slaves[$i].intelligence >= _origIntel+15) || ($slaves[$i].intelligence >= 100)>> + <<if !canImproveIntelligence($activeSlave)>> $His intelligence has been improved as much as a drink possibly can. @@.yellow;$His drug regimen has been ended.@@ <<set $slaves[$i].drugs = "no drugs">> <</if>> diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw index 912fffb0399..f5276ac54f7 100644 --- a/src/uncategorized/slaveInteract.tw +++ b/src/uncategorized/slaveInteract.tw @@ -1044,8 +1044,7 @@ | Psychosuppressants <</if>> <<if $arcologies[0].FSSlaveProfessionalismResearch == 1>> - <<set _origIntel = $genePool.find(function(s) { return s.ID == $activeSlave.ID; }).intelligence>> - <<if ($activeSlave.intelligence < _origIntel+15) && ($activeSlave.intelligence < 100)>> + <<if canImproveIntelligence($activeSlave)>> | <<link "Psychostimulants">><<set $activeSlave.drugs = "psychostimulants">><<SlaveInteractDrugs>><</link>> <<else>> | Psychostimulants diff --git a/src/utility/miscWidgets.tw b/src/utility/miscWidgets.tw index adee9b46db7..bc92127207f 100644 --- a/src/utility/miscWidgets.tw +++ b/src/utility/miscWidgets.tw @@ -145,8 +145,7 @@ Call as <<SlaveInteractDrugs>> | Psychosuppressants <</if>> <<if $arcologies[0].FSSlaveProfessionalismResearch == 1>> - <<set _origIntel = $genePool.find(function(s) { return s.ID == $activeSlave.ID; }).intelligence>> - <<if ($activeSlave.intelligence < _origIntel+15) && ($activeSlave.intelligence < 100)>> + <<if canImproveIntelligence($activeSlave)>> | <<link "Psychostimulants">><<set $activeSlave.drugs = "psychostimulants">><<SlaveInteractDrugs>><</link>> <<else>> | Psychostimulants -- GitLab