diff --git a/src/js/DefaultRules.js b/src/js/DefaultRules.js index 64eb2e3db4c148c03f9f5f06ff61653071c87a39..3b455b568b1331b06ff4c165b5d597fb020b0e4c 100644 --- a/src/js/DefaultRules.js +++ b/src/js/DefaultRules.js @@ -3,10 +3,48 @@ window.DefaultRules = (function() { "use strict"; + const descriptionTypes = { + "auto": {success:"has been automatically assigned", unable: "could not be assigned"}, + "allowed": {success:"is allowed", unable: "could not be allowed"}, + }; + // TODO: This should probably go into a facililites description object of some sort + // The slave has been automatically assigned to... + const assignmentDescriptions = { + "live with your Head Girl": {description: ()=> `live in your Head Girl's private suite`}, + "be confined in the arcade": {description: ()=> `be confined in ${V.arcadeName}`}, + "serve in the master suite": {description: ()=> `${V.masterSuiteName}`}, + "get treatment in the clinic": {description: ()=> `get treatment in ${V.clinicName}`}, + "rest in the spa": {description: ()=> `rest in ${V.spaName}`}, + "work as a nanny": {description: ()=> `work in ${V.nurseryName}`}, + "work in the brothel": {description: ()=> `work in ${V.brothelName}`}, + "serve in the club": {description: ()=> `serve in ${V.clubName}`}, + "work in the dairy": {description: ()=> `be milked in ${V.dairyName}`}, + "work as a farmhand": {description: ()=> `work in ${V.farmyardName}`}, + "work as a servant": {description: ()=> `work in ${V.servantsQuartersName}`}, + "learn in the schoolroom": {description: ()=> `study in ${V.schoolroomName}`}, + "be confined in the cellblock": {description: ()=> `be confined in ${V.cellblockName}`}, + "choose her own job": {description: ({pronouns:{his}})=>`select ${his} own assignments`, descriptionType: "allowed"}, + }; + const getAssignmentDescription = function({rule, slave, assignmentResult, append=null}) { + const assignmentInfo = assignmentDescriptions[rule.setAssignment]; + let work = rule.setAssignment; + let descriptionType = "auto"; + if(assignmentInfo != null) { + if(assignmentInfo.description != null) { + work = assignmentInfo.description({slave, pronouns, rule}); + } + if(assignmentInfo.descriptionType != null) { + descriptionType = assignmentInfo.descriptionType; + } + } + const descriptionTypeInfo = descriptionTypes[descriptionType]; + if(descriptionTypeInfo == null) { throw Error(`Unknown description type ${JSON.stringify(descriptionType)} in ${JSON.stringify(rule.setAssignment)}`); } + const hasBeenAssigned = descriptionTypeInfo[assignmentResult]; + return `<br>${slave.slaveName} ${hasBeenAssigned} to ${work}${append || ''}.`; + }; + let r; - let he; - let him; - let his; + let pronouns, he, him, his; /** * @param {App.Entity.SlaveState} slave @@ -15,7 +53,7 @@ window.DefaultRules = (function() { function DefaultRules(slave) { if (slave.useRulesAssistant === 0) { return r; } // exempted r = ""; - ({he, him, his} = getPronouns(slave)); + ({he, him, his} = pronouns = getPronouns(slave)); const slaveReadOnly = createReadonlyProxy(slave); const {rule, ruleIds} = runWithReadonlyProxy(()=>ProcessSlaveRules(slaveReadOnly)); slave.currentRules = ruleIds; @@ -36,7 +74,7 @@ window.DefaultRules = (function() { ProcessArmAccessory(slave, rule); ProcessLegAccessory(slave, rule); } - ProcessPit(slave,rule); + ProcessPit(slave, rule); ProcessBellyImplant(slave, rule); if (isFertile(slave) || slave.pregWeek < 0) { ProcessContraceptives(slave, rule); @@ -111,20 +149,28 @@ window.DefaultRules = (function() { r += `<span class="red">raWidgets missing case for assignment 'V.{rule.setAssignment}'</span>.`; return rule; } + const removeAssignment = ()=> { + if (job.facility !== App.Entity.facilities.penthouse) { + RAFacilityRemove(slave, rule); // before deleting rule.setAssignment + } + delete rule.setAssignment; + }; switch (rule.setAssignment) { case "rest": case "please you": // slaves always qualify for this assignment break; default: - if (job.checkRequirements(slave).length === 0 && job.facility.hasFreeSpace) { - break; - } else { - if (job.facility !== App.Entity.facilities.penthouse) { - RAFacilityRemove(slave, rule); // before deleting rule.setAssignment - } - delete rule.setAssignment; + if (job.checkRequirements(slave).length !== 0) { + // no message to prevent spam + removeAssignment(); + } else if (!job.facility.hasFreeSpace) { + r += getAssignmentDescription({ +rule, slave, assignmentResult:"unable", append:" because it was full" +}); + removeAssignment(); } + break; } return rule; } @@ -137,53 +183,7 @@ window.DefaultRules = (function() { // place slave on assignment defined by the rule if ((rule.setAssignment !== undefined && rule.setAssignment !== null)) { if (((rule.setAssignment === "choose her own job" && !slave.choosesOwnAssignment) || rule.setAssignment !== slave.assignment)) { - switch (rule.setAssignment) { - case "live with your Head Girl": - r += `<br>${slave.slaveName} has been automatically assigned to live in your Head Girl's private suite.`; - break; - case "be confined in the arcade": - r += `<br>${slave.slaveName} has been automatically assigned to be confined in ${V.arcadeName}.`; - break; - case "serve in the master suite": - r += `<br>${slave.slaveName} has been automatically assigned to ${V.masterSuiteName}.`; - break; - case "get treatment in the clinic": - r += `<br>${slave.slaveName} has been automatically assigned to get treatment in ${V.clinicName}.`; - break; - case "rest in the spa": - r += `<br>${slave.slaveName} has been automatically assigned to rest in ${V.spaName}.`; - break; - case "work as a nanny": - r += `<br>${slave.slaveName} has been automatically assigned to work in ${V.nurseryName}.`; - break; - case "work in the brothel": - r += `<br>${slave.slaveName} has been automatically assigned to work in ${V.brothelName}.`; - break; - case "serve in the club": - r += `<br>${slave.slaveName} has been automatically assigned to serve in ${V.clubName}.`; - break; - case "work in the dairy": - r += `<br>${slave.slaveName} has been automatically assigned to be milked in ${V.dairyName}.`; - break; - case "work as a farmhand": - r += `<br>${slave.slaveName} has been automatically assigned to work in ${V.farmyardName}.`; - break; - case "work as a servant": - r += `<br>${slave.slaveName} has been automatically assigned to work in ${V.servantsQuartersName}.`; - break; - case "learn in the schoolroom": - r += `<br>${slave.slaveName} has been automatically assigned to study in ${V.schoolroomName}.`; - break; - case "be confined in the cellblock": - r += `<br>${slave.slaveName} has been automatically assigned to be confined in ${V.cellblockName}.`; - break; - case "choose her own job": - r += `<br>${slave.slaveName} is now allowed to select ${his} own assignments.`; - break; - default: - r += `<br>${slave.slaveName} has been automatically assigned to ${rule.setAssignment}.`; - break; - } + r += getAssignmentDescription({rule, slave, assignmentResult:"success"}); assignJob(slave, rule.setAssignment); } } @@ -1521,7 +1521,7 @@ window.DefaultRules = (function() { * @param {App.RA.RuleSetters} rule */ - function ProcessPit(slave,rule){ + function ProcessPit(slave, rule){ if (rule.pitRules !== undefined && rule.pitRules !== null){ if (V.pit > 0){ if (rule.pitRules === 0){