diff --git a/src/endWeek/saWorkTheFarm.js b/src/endWeek/saWorkTheFarm.js index 078446acc99c8522b894fe1ada29fb1d63b8b76c..41b04763adc06c8e6064d7f4d4fa3400f330517a 100644 --- a/src/endWeek/saWorkTheFarm.js +++ b/src/endWeek/saWorkTheFarm.js @@ -556,102 +556,129 @@ App.SlaveAssignment.workTheFarm = function (slave) { // Open Vignettes - if (V.showVignettes) { - // TODO: move this entire section into new function - + function slaveVignettes() { const - vignettes = App.UI.DOM.appendNewElement("div", frag, '', "indent"); + vignette = GetVignette(slave); let r = []; - const vignette = GetVignette(slave); r.push(`<span class="story-label">This week</span> ${vignette.text}`); - if (vignette.type === "cash") { - let FResultNumber = FResult(slave); - const cashVign = Math.trunc(FResultNumber * vignette.effect); - if (vignette.effect > 0) { - r.push(`<span class="yellowgreen">making you an extra ${cashFormat(cashVign)}.</span> `); - cashX(cashVign, "slaveAssignmentFarmyardVign", slave); - } else if (vignette.effect < 0) { - r.push(`<span class="reputation dec">losing you ${cashFormat(Math.abs(cashVign))}.</span> `); - cashX(forceNeg(cashVign), "slaveAssignmentFarmyardVign", slave); - } else { - r.push(`an incident without lasting effect.`); - } + r.push(vignetteCash(vignette)); + r.push(vignetteDevotion(vignette)); + r.push(vignetteTrust(vignette)); + r.push(vignetteHealth(vignette)); + r.push(vignetteOther(vignette)); - incomeStats.income += cashVign; - } else if (vignette.type === "devotion") { - if (vignette.effect > 0) { - if (slave.devotion > 50) { - r.push(`<span class="devotion inc">increasing ${his} devotion to you.</span> `); - } else if (slave.devotion >= 20) { - r.push(`<span class="devotion inc">increasing ${his} acceptance of you.</span> `); - } else if (slave.devotion >= -20) { - r.push(`<span class="devotion inc">reducing ${his} dislike of you.</span> `); - } else { - r.push(`<span class="devotion inc">reducing ${his} hatred of you.</span> `); - } - } else if (vignette.effect < 0) { - if (slave.devotion > 50) { - r.push(`<span class="devotion dec">reducing ${his} devotion to you.</span> `); - } else if (slave.devotion >= 20) { - r.push(`<span class="devotion dec">reducing ${his} acceptance of you.</span> `); - } else if (slave.devotion >= -20) { - r.push(`<span class="devotion dec">increasing ${his} dislike of you.</span> `); - } else { - r.push(`<span class="devotion dec">increasing ${his} hatred of you.</span> `); - } + return r.join(' '); + } + + function vignetteCash(vignette) { + const + FResultNumber = FResult(slave), + cash = Math.trunc(FResultNumber * vignette.effect); + + incomeStats.income += cash; + + if (vignette.effect > 0) { + cashX(cashVign, "slaveAssignmentFarmyardVign", slave); + + return `<span class="yellowgreen">making you an extra ${cashFormat(cashVign)}.</span>`; + } else if (vignette.effect < 0) { + cashX(forceNeg(cashVign), "slaveAssignmentFarmyardVign", slave); + + return `<span class="reputation dec">losing you ${cashFormat(Math.abs(cashVign))}.</span>`; + } else { + return `an incident without lasting effect.`; + } + } + + function vignetteDevotion(vignette) { + slave.devotion += 1 * vignette.effect; + + if (vignette.effect > 0) { + if (slave.devotion > 50) { + return `<span class="devotion inc">increasing ${his} devotion to you.</span>`; + } else if (slave.devotion >= 20) { + return `<span class="devotion inc">increasing ${his} acceptance of you.</span>`; + } else if (slave.devotion >= -20) { + return `<span class="devotion inc">reducing ${his} dislike of you.</span>`; } else { - r.push(`an incident without lasting effect.`); + return `<span class="devotion inc">reducing ${his} hatred of you.</span>`; } - - slave.devotion += 1 * vignette.effect; - } else if (vignette.type === "trust") { - if (vignette.effect > 0) { - if (slave.trust > 20) { - r.push(`<span class="trust inc">increasing ${his} trust in you.</span> `); - } else if (slave.trust >= -20) { - r.push(`<span class="trust inc">reducing ${his} fear of you.</span> `); - } else { - r.push(`<span class="trust inc">reducing ${his} terror of you.</span> `); - } - } else if (vignette.effect < 0) { - if (slave.trust > 20) { - r.push(`<span class="trust dec">reducing ${his} trust in you.</span> `); - } else if (slave.trust >= -20) { - r.push(`<span class="trust dec">increasing ${his} fear of you.</span> `); - } else { - r.push(`<span class="trust dec">increasing ${his} terror of you.</span> `); - } + } else if (vignette.effect < 0) { + if (slave.devotion > 50) { + return `<span class="devotion dec">reducing ${his} devotion to you.</span>`; + } else if (slave.devotion >= 20) { + return `<span class="devotion dec">reducing ${his} acceptance of you.</span>`; + } else if (slave.devotion >= -20) { + return `<span class="devotion dec">increasing ${his} dislike of you.</span>`; } else { - r.push(`an incident without lasting effect.`); + return `<span class="devotion dec">increasing ${his} hatred of you.</span>`; } + } else { + return `an incident without lasting effect.`; + } + } + + function vignetteTrust(vignette) { + slave.trust += 1 * vignette.effect; - slave.trust += 1 * vignette.effect; - } else if (vignette.type === "health") { - if (vignette.effect > 0) { - r.push(`<span class="reputation inc">improving ${his} health.</span> `); - improveCondition(slave, 2 * vignette.effect); - } else if (vignette.effect < 0) { - r.push(`<span class="reputation dec">affecting ${his} health.</span> `); - healthDamage(slave, 2 * vignette.effect); + if (vignette.effect > 0) { + if (slave.trust > 20) { + return `<span class="trust inc">increasing ${his} trust in you.</span>`; + } else if (slave.trust >= -20) { + return `<span class="trust inc">reducing ${his} fear of you.</span>`; } else { - r.push(`an incident without lasting effect.`); + return `<span class="trust inc">reducing ${his} terror of you.</span>`; } - } else { - let FResultNumber = FResult(slave); - if (vignette.effect > 0) { - r.push(`<span class="reputation inc">gaining you a bit of reputation.</span> `); - } else if (vignette.effect < 0) { - r.push(`<span class="reputation dec">losing you a bit of reputation.</span> `); + } else if (vignette.effect < 0) { + if (slave.trust > 20) { + return `<span class="trust dec">reducing ${his} trust in you.</span>`; + } else if (slave.trust >= -20) { + return `<span class="trust dec">increasing ${his} fear of you.</span>`; } else { - r.push(`an incident without lasting effect.`); + return `<span class="trust dec">increasing ${his} terror of you.</span>`; } + } else { + return `an incident without lasting effect.`; + } + } + + function vignetteHealth(vignette) { + if (vignette.effect > 0) { + improveCondition(slave, 2 * vignette.effect); + + return `<span class="reputation inc">improving ${his} health.</span>`; + } else if (vignette.effect < 0) { + healthDamage(slave, 2 * vignette.effect); + + return `<span class="reputation dec">affecting ${his} health.</span>`; + } else { + return `an incident without lasting effect.`; + } + } - repX(Math.trunc(FResultNumber * vignette.effect * 0.1), "vignette", slave); - incomeStats.rep += Math.trunc(FResultNumber * vignette.effect * 0.1); + function vignetteOther(vignette) { + const FResultNumber = FResult(slave); + + repX(Math.trunc(FResultNumber * vignette.effect * 0.1), "vignette", slave); + incomeStats.rep += Math.trunc(FResultNumber * vignette.effect * 0.1); + + if (vignette.effect > 0) { + return `<span class="reputation inc">gaining you a bit of reputation.</span>`; + } else if (vignette.effect < 0) { + return `<span class="reputation dec">losing you a bit of reputation.</span>`; + } else { + return `an incident without lasting effect.`; } + } + + if (V.showVignettes) { + const + vignettes = App.UI.DOM.appendNewElement("div", frag, '', "indent"); + + slaveVignettes(); $(vignettes).append(r.join(' ')); }