From 31105aac9207ab3ce1cf768f8d92796c22c96bcc Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Mon, 29 May 2017 22:52:06 -0500 Subject: [PATCH] Refactored Company job application code --- src/CompanyJobApplication.js | 61 +++++++++++++++--------------------- src/Prestige.js | 9 +++--- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/CompanyJobApplication.js b/src/CompanyJobApplication.js index 62546a05d..5d0034019 100644 --- a/src/CompanyJobApplication.js +++ b/src/CompanyJobApplication.js @@ -16,24 +16,7 @@ PlayerObject.prototype.applyForJob = function(entryPosType) { var pos = entryPosType; if (!this.isQualified(company, pos)) { - var offset = company.jobStatReqOffset; - var reqHacking = pos.requiredHacking > 0 ? pos.requiredHacking+offset : 0; - var reqStrength = pos.requiredStrength > 0 ? pos.requiredStrength+offset : 0; - var reqDefense = pos.requiredDefense > 0 ? pos.requiredDefense+offset : 0; - var reqDexterity = pos.requiredDexterity > 0 ? pos.requiredDexterity+offset : 0; - var reqAgility = pos.requiredDexterity > 0 ? pos.requiredDexterity+offset : 0; - var reqCharisma = pos.requiredCharisma > 0 ? pos.requiredCharisma+offset : 0; - var reqRep = pos.requiredReputation; - var reqText = "(Requires "; - if (reqHacking > 0) {reqText += (reqHacking + " hacking, ");} - if (reqStrength > 0) {reqText += (reqStrength + " strength, ");} - if (reqDefense > 0) {reqText += (reqDefense + " defense, ");} - if (reqDexterity > 0) {reqText += (reqDexterity + " dexterity, ");} - if (reqAgility > 0) {reqText += (reqAgility + " agility, ");} - if (reqCharisma > 0) {reqText += (reqCharisma + " charisma, ");} - if (reqRep > 1) {reqText += (reqRep + " reputation, ");} - reqText = reqText.substring(0, reqText.length - 2); - reqText += ")"; + var reqText = getJobRequirementText(company, pos); dialogBoxCreate("Unforunately, you do not qualify for this position", reqText); return; } @@ -67,24 +50,7 @@ PlayerObject.prototype.applyForJob = function(entryPosType) { if (currCompany.companyName == company.companyName && pos.positionName == currPositionName) { var nextPos = getNextCompanyPosition(pos); - var offset = company.jobStatReqOffset; - var reqHacking = nextPos.requiredHacking > 0 ? nextPos.requiredHacking+offset : 0; - var reqStrength = nextPos.requiredStrength > 0 ? nextPos.requiredStrength+offset : 0; - var reqDefense = nextPos.requiredDefense > 0 ? nextPos.requiredDefense+offset : 0; - var reqDexterity = nextPos.requiredDexterity > 0 ? nextPos.requiredDexterity+offset : 0; - var reqAgility = nextPos.requiredDexterity > 0 ? nextPos.requiredDexterity+offset : 0; - var reqCharisma = nextPos.requiredCharisma > 0 ? nextPos.requiredCharisma+offset : 0; - var reqRep = nextPos.requiredReputation; - var reqText = "(Requires "; - if (reqHacking > 0) {reqText += (reqHacking + " hacking, ");} - if (reqStrength > 0) {reqText += (reqStrength + " strength, ");} - if (reqDefense > 0) {reqText += (reqDefense + " defense, ");} - if (reqDexterity > 0) {reqText += (reqDexterity + " dexterity, ");} - if (reqAgility > 0) {reqText += (reqAgility + " agility, ");} - if (reqCharisma > 0) {reqText += (reqCharisma + " charisma, ");} - if (reqRep > 1) {reqText += (reqRep + " reputation, ");} - reqText = reqText.substring(0, reqText.length - 2); - reqText += ")"; + var reqText = getJobRequirementText(company, nextPos); dialogBoxCreate("Unfortunately, you do not qualify for a promotion", reqText); return; //Same job, do nothing @@ -120,6 +86,29 @@ PlayerObject.prototype.applyForJob = function(entryPosType) { Engine.loadLocationContent(); } +function getJobRequirementText(company, pos) { + var reqText = ""; + var offset = company.jobStatReqOffset; + var reqHacking = pos.requiredHacking > 0 ? pos.requiredHacking+offset : 0; + var reqStrength = pos.requiredStrength > 0 ? pos.requiredStrength+offset : 0; + var reqDefense = pos.requiredDefense > 0 ? pos.requiredDefense+offset : 0; + var reqDexterity = pos.requiredDexterity > 0 ? pos.requiredDexterity+offset : 0; + var reqAgility = pos.requiredDexterity > 0 ? pos.requiredDexterity+offset : 0; + var reqCharisma = pos.requiredCharisma > 0 ? pos.requiredCharisma+offset : 0; + var reqRep = pos.requiredReputation; + var reqText = "(Requires "; + if (reqHacking > 0) {reqText += (reqHacking + " hacking, ");} + if (reqStrength > 0) {reqText += (reqStrength + " strength, ");} + if (reqDefense > 0) {reqText += (reqDefense + " defense, ");} + if (reqDexterity > 0) {reqText += (reqDexterity + " dexterity, ");} + if (reqAgility > 0) {reqText += (reqAgility + " agility, ");} + if (reqCharisma > 0) {reqText += (reqCharisma + " charisma, ");} + if (reqRep > 1) {reqText += (reqRep + " reputation, ");} + reqText = reqText.substring(0, reqText.length - 2); + reqText += ")"; + return reqText; +} + PlayerObject.prototype.applyForSoftwareJob = function() { this.applyForJob(CompanyPositions.SoftwareIntern); } diff --git a/src/Prestige.js b/src/Prestige.js index b51ab2ca2..696e40b04 100644 --- a/src/Prestige.js +++ b/src/Prestige.js @@ -107,6 +107,11 @@ function prestigeAugmentation() { Player.lastUpdate = new Date().getTime(); + //Delete all running scripts objects + for (var i = 0; i < workerScripts.length; ++i) { + workerScripts[i].env.stopFlag = true; + } + var homeComp = Player.getHomeComputer(); //Delete all servers except home computer for (var member in AllServers) { @@ -157,10 +162,6 @@ function prestigeAugmentation() { s.moneyStolenMap.printConsole(); } - //Delete all running scripts objects - for (var i = 0; i < workerScripts.length; ++i) { - workerScripts[i].env.stopFlag = true; - } //Delete active scripts display elements var list = Engine.ActiveScriptsList.querySelectorAll('#active-scripts-list li'); for (var i = list.length-1; i >= 0; --i) {