diff --git a/src/interaction/multiImplant.js b/src/interaction/multiImplant.js new file mode 100644 index 0000000000000000000000000000000000000000..d37d59fcfd3cda6371cac02c816d867471e0c70a --- /dev/null +++ b/src/interaction/multiImplant.js @@ -0,0 +1,66 @@ +App.UI.multiImplant = function() { + const frag = document.createDocumentFragment(); + + let r = []; + r.push("You head down to your"); + if (V.surgeryUpgrade === 1) { + r.push("heavily upgraded and customized"); + } + r.push("remote surgery and start having the slaves with"); + if (V.completedOrgans.length > 0 && V.adjustProstheticsCompleted > 0) { + r.push("organs or prosthetics"); + } else if (V.completedOrgans.length > 1) { + r.push("organs"); + } else if (V.adjustProstheticsCompleted > 1) { + r.push("prosthetics"); + } + r.push("that are ready be sent down."); + + App.UI.DOM.appendNewElement("p", frag, r.join(" ")); + + App.UI.DOM.appendNewElement("h1", frag, "Implant Organs"); + + let F = App.Medicine.OrganFarm; + for (const slave of V.slaves) { + let sortedOrgans = F.getSortedOrgans(slave); + if (sortedOrgans.length === 0) { + continue; + } + + App.UI.DOM.appendNewElement("h2", frag, slave.slaveName); + + for (let j = 0; j < sortedOrgans.length; j++) { + App.UI.DOM.appendNewElement("h3", frag, F.Organs[sortedOrgans[j]].name); + + let actions = F.Organs[sortedOrgans[j]].implantActions; + let manual = false, success = false, cancel = false; + for (let k = 0; k < actions.length; k++) { + if (!actions[k].autoImplant) { + if (actions[k].canImplant(slave)) { + manual = true; + } + continue; + } + if (!actions[k].canImplant(slave)) { + let error = actions[k].implantError(slave); + if (error !== "") { + App.UI.DOM.appendNewElement("div", frag, error, "warning"); + } + } else if (slave.health.health - actions[k].healthImpact < -75) { + App.UI.Dom.appendNewElement("div", frag, "Estimated health impact too high, skipping further surgeries."); + cancel = true; + break; + } else { + App.Medicine.OrganFarm.implant(slave, sortedOrgans[j], k); + App.UI.DOM.appendNewElement("p", frag, App.UI.SlaveInteract.surgeryDegradation(slave)); + success = true; + } + } + if (cancel) { break; } + if (!success && manual) { + App.UI.Dom.appendNewElement("div", frag, `Cannot implant ${F.Organs[sortedOrgans[j]].name.toLowerCase()} automatically, try implanting manually in the remote surgery.`, "note"); + } + } + } + return frag; +}; diff --git a/src/uncategorized/multiImplant.tw b/src/uncategorized/multiImplant.tw index 3f07842a777d8509ec79a340b279a159d8719253..5e377d7b3ca713cef14eb5d3b8a6d11c26979f80 100644 --- a/src/uncategorized/multiImplant.tw +++ b/src/uncategorized/multiImplant.tw @@ -1,62 +1,6 @@ :: Multiple Organ Implant [nobr] -You head down to your -<<if $surgeryUpgrade == 1>> - heavily upgraded and customized -<</if>> -remote surgery and start having the slaves with -<<if ($completedOrgans.length > 0) && ($adjustProstheticsCompleted > 0)>> - organs or prosthetics -<<elseif ($completedOrgans.length > 1)>> - organs -<<elseif ($adjustProstheticsCompleted > 1)>> - prosthetics -<</if>> -that are ready be sent down. - -<h1>Implant Organs</h1> - -<<set _F = App.Medicine.OrganFarm>> -<<for _i = 0; _i < $slaves.length; _i++>> - <<set $AS = $slaves[_i].ID>> - <<set _sortedOrgans = _F.getSortedOrgans(getSlave($AS))>> - <<if _sortedOrgans.length === 0>><<continue>><</if>> - - <h2><<= getSlave($AS).slaveName>></h2> - - <<for _k = 0; _k < _sortedOrgans.length; _k++>> - <h3><<print _F.Organs[_sortedOrgans[_k]].name>></h3> - <<set _actions = _F.Organs[_sortedOrgans[_k]].implantActions>> - <<set _manual = false, _success = false, _break = false>> - <<for _l = 0; _l < _actions.length; _l++>> - <<if !_actions[_l].autoImplant>> - <<if _actions[_l].canImplant(getSlave($AS))>> - <<set _manual = true>> - <</if>> - <<continue>> - <</if>> - <<if !_actions[_l].canImplant(getSlave($AS))>> - <<set _error = _actions[_l].implantError(getSlave($AS))>> - <<if _error !== "">> - @@.red;ERROR: <<print _error>>@@<br> - <</if>> - <<elseif getSlave($AS).health.health - _actions[_l].healthImpact < -75>> - Estimated health impact too high, skipping further surgeries. - <<set _break = true>> - <<break>> - <<else>> - <<run App.Medicine.OrganFarm.implant(getSlave($AS), _sortedOrgans[_k], _l)>> - <<includeDOM App.UI.SlaveInteract.surgeryDegradation(getSlave($AS))>><br><br> - <<set _success = true>> - <</if>> - <</for>> - <<if _break>><<break>><</if>> - <<if !_success && _manual>> - //Cannot implant <<print _F.Organs[_sortedOrgans[_k]].name.toLowerCase()>> automatically, try implanting manually in the remote surgery.// - <</if>> - <</for>> -<</for>> - +<<includeDOM App.UI.multiImplant()>> <h1>Implant prosthetics</h1>