diff --git a/src/js/assignJS.js b/src/js/assignJS.js index 6794fb1a76591ab4b8391676ddf2685ae677802e..b166e89857d90595a0411685535c637cee8a2cc2 100644 --- a/src/js/assignJS.js +++ b/src/js/assignJS.js @@ -12,35 +12,48 @@ window.assignJob = function assignJob(slave, job) { if (job === "Pit" || job === "Coursing Association") { return r; } - removeJob(slave, slave.assignment); + removeJob(slave, slave.assignment, true); const idx = V.slaveIndices[slave.ID]; const uniqueJob = function(propName) { // this helper makes sure global references ($HeadGirl, etc) are set correctly if (V[propName] !== 0 && V[propName].ID !== slave.ID) { - removeJob(V[propName], job); + removeJob(V[propName], job, true); } V[propName] = slave; }; /* Tracking for the following cases: */ - if (V.assignmentRecords[slave.ID] !== "choose her own job") { // if choosesOwnAssignment was set before removeJob (which wipes it out), it's saved in assignmentRecords. We don't want to overwrite that here, as we want to be able to get it back. - switch (job.toLowerCase()) { - case "be confined in the cellblock": - case "cellblock": - case "get treatment in the clinic": - case "clinic": - case "learn in the schoolroom": - case "schoolroom": - case "rest in the spa": - case "spa": - if (oldJob !== "rest") { - V.assignmentRecords[slave.ID] = oldJob; // these jobs are temporary, so we save what the slave will return to if it is meaningful. - } - break; + if (V.assignmentRecords[slave.ID] !== "choose her own job") { // if choosesOwnAssignment was set before removeJob, it's saved in assignmentRecords. We don't want to overwrite that here, as we want to be able to get it back. + if (oldJob !== job && V.assignmentRecords[slave.ID] !== job && oldJob !== "rest") { // Check that there is a real change happening. Sometimes when you send someone to a classroom or something, this fires twice. + switch (job.toLowerCase()) { + case "be confined in the cellblock": + case "cellblock": + if (oldJob !== "be confined in the cellblock") { // Due to the way assignJob fires twice on assigning to a building, we have to make sure that we are keeping the original record. + V.assignmentRecords[slave.ID] = oldJob; + } + break; + case "get treatment in the clinic": + case "clinic": + if (oldJob !== "get treatment in the clinic") { + V.assignmentRecords[slave.ID] = oldJob; + } + break; + case "learn in the schoolroom": + case "schoolroom": + if (oldJob !== "learn in the schoolroom") { + V.assignmentRecords[slave.ID] = oldJob; + } + break; + case "rest in the spa": + case "spa": + if (oldJob !== "rest in the spa") { + V.assignmentRecords[slave.ID] = oldJob; + } + break; + } } } - /* use .toLowerCase() to get rid of a few dupe conditions. */ switch (job.toLowerCase()) { case "be confined in the arcade": @@ -429,9 +442,10 @@ window.assignJobSafely = function assignJobSafely(slave, assignmentStr){ /** * @param {App.Entity.SlaveState} slave * @param {string} assignment + * @param {boolean} saveRecord * @returns {string} */ -window.removeJob = function removeJob(slave, assignment) { +window.removeJob = function removeJob(slave, assignment, saveRecord) { "use strict"; let r = ""; @@ -442,7 +456,7 @@ window.removeJob = function removeJob(slave, assignment) { return r; } - if (V.assignmentRecords[slave.ID]) { + if (V.assignmentRecords[slave.ID] && !(saveRecord === true)) { delete V.assignmentRecords[slave.ID]; }