From c95a9261547048a6bb33dc953fc64bdc6724bfb5 Mon Sep 17 00:00:00 2001 From: Daniel Ferri Date: Tue, 11 May 2021 15:19:07 +0200 Subject: [PATCH 1/3] Add overflow time of bladeburner updates to the next update --- src/Bladeburner.jsx | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Bladeburner.jsx b/src/Bladeburner.jsx index 6893feaeb..824259577 100644 --- a/src/Bladeburner.jsx +++ b/src/Bladeburner.jsx @@ -158,6 +158,7 @@ function Bladeburner(params={}) { // These times are in seconds this.actionTimeToComplete = 0; // 0 or -1 is an infinite running action (like training) this.actionTimeCurrent = 0; + this.actionTimeOverflow = 0; // ActionIdentifier Object var idleActionType = ActionTypes["Idle"]; @@ -406,7 +407,8 @@ Bladeburner.prototype.process = function() { this.randomEventCounter -= seconds; if (this.randomEventCounter <= 0) { this.randomEvent(); - this.randomEventCounter = getRandomInt(240, 600); + // Add instead of setting because we might have gone over the required time for the event + this.randomEventCounter += getRandomInt(240, 600); } this.processAction(seconds); @@ -664,8 +666,12 @@ Bladeburner.prototype.processAction = function(seconds) { throw new Error("Bladeburner.action is not an ActionIdentifier Object"); } - this.actionTimeCurrent += seconds; + // If the previous action went past its completion time, add to the next action + // This is not added inmediatly in case the automation changes the action + this.actionTimeCurrent += seconds + this.actionTimeOverflow; + this.actionTimeOverflow = 0; if (this.actionTimeCurrent >= this.actionTimeToComplete) { + this.actionTimeOverflow = this.actionTimeCurrent - this.actionTimeToComplete; return this.completeAction(); } } @@ -1889,17 +1895,18 @@ Bladeburner.prototype.updateActionAndSkillsContent = function() { Bladeburner.prototype.updateGeneralActionsUIElement = function(el, action) { removeChildrenFromElement(el); var isActive = el.classList.contains(ActiveActionCssClass); + var computedActionTimeCurrent = Math.min(this.actionTimeCurrent+this.actionTimeOverflow,this.actionTimeToComplete); el.appendChild(createElement("h2", { // Header innerText:isActive ? action.name + " (IN PROGRESS - " + - formatNumber(this.actionTimeCurrent, 0) + " / " + + formatNumber(computedActionTimeCurrent, 0) + " / " + formatNumber(this.actionTimeToComplete, 0) + ")" : action.name, display:"inline-block", })); if (isActive) { // Progress bar if its active - var progress = this.actionTimeCurrent / this.actionTimeToComplete; + var progress = computedActionTimeCurrent / this.actionTimeToComplete; el.appendChild(createElement("p", { display:"block", innerText:createProgressBarText({progress:progress}), @@ -1931,17 +1938,18 @@ Bladeburner.prototype.updateContractsUIElement = function(el, action) { removeChildrenFromElement(el); var isActive = el.classList.contains(ActiveActionCssClass); var estimatedSuccessChance = action.getSuccessChance(this, {est:true}); + var computedActionTimeCurrent = Math.min(this.actionTimeCurrent+this.actionTimeOverflow,this.actionTimeToComplete); el.appendChild(createElement("h2", { // Header innerText:isActive ? action.name + " (IN PROGRESS - " + - formatNumber(this.actionTimeCurrent, 0) + " / " + + formatNumber(computedActionTimeCurrent, 0) + " / " + formatNumber(this.actionTimeToComplete, 0) + ")" : action.name, display:"inline-block", })); if (isActive) { // Progress bar if its active - var progress = this.actionTimeCurrent / this.actionTimeToComplete; + var progress = computedActionTimeCurrent / this.actionTimeToComplete; el.appendChild(createElement("p", { display:"block", innerText:createProgressBarText({progress:progress}), @@ -2030,16 +2038,18 @@ Bladeburner.prototype.updateOperationsUIElement = function(el, action) { removeChildrenFromElement(el); var isActive = el.classList.contains(ActiveActionCssClass); var estimatedSuccessChance = action.getSuccessChance(this, {est:true}); + var computedActionTimeCurrent = Math.min(this.actionTimeCurrent+this.actionTimeOverflow,this.actionTimeToComplete); + el.appendChild(createElement("h2", { // Header innerText:isActive ? action.name + " (IN PROGRESS - " + - formatNumber(this.actionTimeCurrent, 0) + " / " + + formatNumber(computedActionTimeCurrent, 0) + " / " + formatNumber(this.actionTimeToComplete, 0) + ")" : action.name, display:"inline-block", })); if (isActive) { // Progress bar if its active - var progress = this.actionTimeCurrent / this.actionTimeToComplete; + var progress = computedActionTimeCurrent / this.actionTimeToComplete; el.appendChild(createElement("p", { display:"block", innerText:createProgressBarText({progress:progress}), @@ -2171,6 +2181,7 @@ Bladeburner.prototype.updateBlackOpsUIElement = function(el, action) { var estimatedSuccessChance = action.getSuccessChance(this, {est:true}); var actionTime = action.getActionTime(this); var hasReqdRank = this.rank >= action.reqdRank; + var computedActionTimeCurrent = Math.min(this.actionTimeCurrent+this.actionTimeOverflow,this.actionTimeToComplete); // UI for Completed Black Op if (isCompleted) { @@ -2182,14 +2193,14 @@ Bladeburner.prototype.updateBlackOpsUIElement = function(el, action) { el.appendChild(createElement("h2", { // Header innerText:isActive ? action.name + " (IN PROGRESS - " + - formatNumber(this.actionTimeCurrent, 0) + " / " + + formatNumber(computedActionTimeCurrent, 0) + " / " + formatNumber(this.actionTimeToComplete, 0) + ")" : action.name, display:"inline-block", })); if (isActive) { // Progress bar if its active - var progress = this.actionTimeCurrent / this.actionTimeToComplete; + var progress = computedActionTimeCurrent / this.actionTimeToComplete; el.appendChild(createElement("p", { display:"block", innerText:createProgressBarText({progress:progress}), From f8a085af7ac0046b7d3eabaa1457f61ccbba4ef6 Mon Sep 17 00:00:00 2001 From: Daniel Ferri Date: Tue, 11 May 2021 15:34:05 +0200 Subject: [PATCH 2/3] Autofocus the input when opening a "Set Team Size" popup --- src/Bladeburner.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Bladeburner.jsx b/src/Bladeburner.jsx index 824259577..843d43a7a 100644 --- a/src/Bladeburner.jsx +++ b/src/Bladeburner.jsx @@ -2103,6 +2103,7 @@ Bladeburner.prototype.updateOperationsUIElement = function(el, action) { }, }); createPopup(popupId, [txt, input, setBtn, cancelBtn]); + input.focus(); }, })); } @@ -2254,6 +2255,7 @@ Bladeburner.prototype.updateBlackOpsUIElement = function(el, action) { }, }); createPopup(popupId, [txt, input, setBtn, cancelBtn]); + input.focus(); }, })); } From 1b57c1f7e0e9d5448e4379a0e0b0550db55b8ffb Mon Sep 17 00:00:00 2001 From: Daniel Ferri Date: Tue, 11 May 2021 20:16:18 +0200 Subject: [PATCH 3/3] Changed loops to be more concise --- src/Bladeburner.jsx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Bladeburner.jsx b/src/Bladeburner.jsx index 843d43a7a..514a0a2d5 100644 --- a/src/Bladeburner.jsx +++ b/src/Bladeburner.jsx @@ -382,22 +382,16 @@ Bladeburner.prototype.process = function() { this.stamina = Math.min(this.maxStamina, this.stamina); // Count increase for contracts/operations - for (var contractName in this.contracts) { - if (this.contracts.hasOwnProperty(contractName)) { - var contract = this.contracts[contractName]; - contract.count += (seconds * contract.countGrowth/BladeburnerConstants.ActionCountGrowthPeriod); - } + for (let contract of Object.values(this.contracts)) { + contract.count += (seconds * contract.countGrowth/BladeburnerConstants.ActionCountGrowthPeriod); } - for (var operationName in this.operations) { - if (this.operations.hasOwnProperty(operationName)) { - var op = this.operations[operationName]; - op.count += (seconds * op.countGrowth/BladeburnerConstants.ActionCountGrowthPeriod); - } + for (let op of Object.values(this.operations)) { + op.count += (seconds * op.countGrowth/BladeburnerConstants.ActionCountGrowthPeriod); } // Chaos goes down very slowly - for (var i = 0; i < BladeburnerConstants.CityNames.length; ++i) { - var city = this.cities[BladeburnerConstants.CityNames[i]]; + for (let cityName of BladeburnerConstants.CityNames) { + var city = this.cities[cityName]; if (!(city instanceof City)) {throw new Error("Invalid City object when processing passive chaos reduction in Bladeburner.process");} city.chaos -= (0.0001 * seconds); city.chaos = Math.max(0, city.chaos);