mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 09:43:54 +01:00
Offline money gain is based off hacking exp / time since last aug instead
This commit is contained in:
parent
0f2b7517b4
commit
5af10c8406
@ -15,6 +15,8 @@ import { GetServerByHostname } from "./Server/ServerHelpers";
|
||||
import { hackWorldDaemon } from "./RedPill";
|
||||
import { StockMarket } from "./StockMarket/StockMarket";
|
||||
import { Stock } from "./StockMarket/Stock";
|
||||
import { Engine, indexedDb } from "./engine";
|
||||
import { saveObject } from "./SaveObject";
|
||||
|
||||
import { dialogBoxCreate } from "../utils/DialogBox";
|
||||
import { createElement } from "../utils/uiHelpers/createElement";
|
||||
@ -641,6 +643,15 @@ class DevMenuComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
timeskip(time) {
|
||||
return () => {
|
||||
Player.lastUpdate -= time;
|
||||
Engine._lastUpdate -= time;
|
||||
saveObject.saveGame(indexedDb);
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
let factions = [];
|
||||
for (const i in Factions) {
|
||||
@ -1212,6 +1223,19 @@ class DevMenuComponent extends Component {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row">
|
||||
<div className="col">
|
||||
<div className="row">
|
||||
<h2>Offline time skip:</h2>
|
||||
</div>
|
||||
<div className="row">
|
||||
<button className="std-button" onClick={this.timeskip(60*1000)}>1 minute</button>
|
||||
<button className="std-button" onClick={this.timeskip(60*60*1000)}>1 hour</button>
|
||||
<button className="std-button" onClick={this.timeskip(24*60*60*1000)}>1 day</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -564,7 +564,6 @@ export function updateOnlineScriptTimes(numCycles = 1) {
|
||||
* into worker scripts so that they will start running
|
||||
*/
|
||||
export function loadAllRunningScripts() {
|
||||
var total = 0;
|
||||
let skipScriptLoad = (window.location.href.toLowerCase().indexOf("?noscripts") !== -1);
|
||||
if (skipScriptLoad) { console.info("Skipping the load of any scripts during startup"); }
|
||||
for (const property in AllServers) {
|
||||
@ -587,13 +586,11 @@ export function loadAllRunningScripts() {
|
||||
createAndAddWorkerScript(server.runningScripts[j], server);
|
||||
|
||||
// Offline production
|
||||
total += scriptCalculateOfflineProduction(server.runningScripts[j]);
|
||||
scriptCalculateOfflineProduction(server.runningScripts[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,90 +311,51 @@ function saveAndCloseScriptEditor() {
|
||||
|
||||
export function scriptCalculateOfflineProduction(runningScriptObj) {
|
||||
//The Player object stores the last update time from when we were online
|
||||
var thisUpdate = new Date().getTime();
|
||||
var lastUpdate = Player.lastUpdate;
|
||||
var timePassed = (thisUpdate - lastUpdate) / 1000; //Seconds
|
||||
const thisUpdate = new Date().getTime();
|
||||
const lastUpdate = Player.lastUpdate;
|
||||
const timePassed = (thisUpdate - lastUpdate) / 1000; //Seconds
|
||||
|
||||
//Calculate the "confidence" rating of the script's true production. This is based
|
||||
//entirely off of time. We will arbitrarily say that if a script has been running for
|
||||
//4 hours (14400 sec) then we are completely confident in its ability
|
||||
var confidence = (runningScriptObj.onlineRunningTime) / 14400;
|
||||
let confidence = (runningScriptObj.onlineRunningTime) / 14400;
|
||||
if (confidence >= 1) {confidence = 1;}
|
||||
|
||||
//Data map: [MoneyStolen, NumTimesHacked, NumTimesGrown, NumTimesWeaken]
|
||||
|
||||
// Grow
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
for (const ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
if (runningScriptObj.dataMap[ip][2] == 0 || runningScriptObj.dataMap[ip][2] == null) {continue;}
|
||||
var serv = AllServers[ip];
|
||||
const serv = AllServers[ip];
|
||||
if (serv == null) {continue;}
|
||||
var timesGrown = Math.round(0.5 * runningScriptObj.dataMap[ip][2] / runningScriptObj.onlineRunningTime * timePassed);
|
||||
runningScriptObj.log("Called grow() on " + serv.hostname + " " + timesGrown + " times while offline");
|
||||
var growth = processSingleServerGrowth(serv, timesGrown, Player);
|
||||
runningScriptObj.log(serv.hostname + " grown by " + numeralWrapper.format(growth * 100 - 100, '0.000000%') + " from grow() calls made while offline");
|
||||
}
|
||||
}
|
||||
|
||||
// Money from hacking
|
||||
var totalOfflineProduction = 0;
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
if (runningScriptObj.dataMap[ip][0] == 0 || runningScriptObj.dataMap[ip][0] == null) {continue;}
|
||||
var serv = AllServers[ip];
|
||||
if (serv == null) {continue;}
|
||||
var production = 0.5 * runningScriptObj.dataMap[ip][0] / runningScriptObj.onlineRunningTime * timePassed;
|
||||
production *= confidence;
|
||||
if (production > serv.moneyAvailable) {
|
||||
production = serv.moneyAvailable;
|
||||
}
|
||||
totalOfflineProduction += production;
|
||||
Player.gainMoney(production);
|
||||
Player.recordMoneySource(production, "hacking");
|
||||
runningScriptObj.log(runningScriptObj.filename + " generated $" + production + " while offline by hacking " + serv.hostname);
|
||||
serv.moneyAvailable -= production;
|
||||
if (serv.moneyAvailable < 0) {serv.moneyAvailable = 0;}
|
||||
if (isNaN(serv.moneyAvailable)) {serv.moneyAvailable = 0;}
|
||||
const timesGrown = Math.round(0.5 * runningScriptObj.dataMap[ip][2] / runningScriptObj.onlineRunningTime * timePassed);
|
||||
runningScriptObj.log(`Called on ${serv.hostname} ${timesGrown} times while offline`);
|
||||
const growth = processSingleServerGrowth(serv, timesGrown, Player);
|
||||
runningScriptObj.log(`'${serv.hostname}' grown by ${numeralWrapper.format(growth * 100 - 100, '0.000000%')} while offline`);
|
||||
}
|
||||
}
|
||||
|
||||
// Offline EXP gain
|
||||
// A script's offline production will always be at most half of its online production.
|
||||
var expGain = 0.5 * (runningScriptObj.onlineExpGained / runningScriptObj.onlineRunningTime) * timePassed;
|
||||
expGain *= confidence;
|
||||
|
||||
const expGain = confidence * (runningScriptObj.onlineExpGained / runningScriptObj.onlineRunningTime) * timePassed;
|
||||
Player.gainHackingExp(expGain);
|
||||
|
||||
// Update script stats
|
||||
runningScriptObj.offlineMoneyMade += totalOfflineProduction;
|
||||
runningScriptObj.offlineRunningTime += timePassed;
|
||||
runningScriptObj.offlineExpGained += expGain;
|
||||
|
||||
// Fortify a server's security based on how many times it was hacked
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
if (runningScriptObj.dataMap[ip][1] == 0 || runningScriptObj.dataMap[ip][1] == null) {continue;}
|
||||
var serv = AllServers[ip];
|
||||
if (serv == null) {continue;}
|
||||
var timesHacked = Math.round(0.5 * runningScriptObj.dataMap[ip][1] / runningScriptObj.onlineRunningTime * timePassed);
|
||||
runningScriptObj.log("Hacked " + serv.hostname + " " + timesHacked + " times while offline");
|
||||
serv.fortify(CONSTANTS.ServerFortifyAmount * timesHacked);
|
||||
}
|
||||
}
|
||||
|
||||
// Weaken
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
for (const ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
if (runningScriptObj.dataMap[ip][3] == 0 || runningScriptObj.dataMap[ip][3] == null) {continue;}
|
||||
var serv = AllServers[ip];
|
||||
const serv = AllServers[ip];
|
||||
if (serv == null) {continue;}
|
||||
var timesWeakened = Math.round(0.5 * runningScriptObj.dataMap[ip][3] / runningScriptObj.onlineRunningTime * timePassed);
|
||||
runningScriptObj.log("Called weaken() on " + serv.hostname + " " + timesWeakened + " times while offline");
|
||||
const timesWeakened = Math.round(0.5 * runningScriptObj.dataMap[ip][3] / runningScriptObj.onlineRunningTime * timePassed);
|
||||
runningScriptObj.log(`Called weaken() on ${serv.hostname} ${timesWeakened} times while offline`);
|
||||
serv.weaken(CONSTANTS.ServerWeakenAmount * timesWeakened);
|
||||
}
|
||||
}
|
||||
|
||||
return totalOfflineProduction;
|
||||
}
|
||||
|
||||
//Returns a RunningScript object matching the filename and arguments on the
|
||||
|
@ -32,6 +32,11 @@ import {
|
||||
processPassiveFactionRepGain,
|
||||
inviteToFaction,
|
||||
} from "./Faction/FactionHelpers";
|
||||
import {
|
||||
getHackingWorkRepGain,
|
||||
getFactionSecurityWorkRepGain,
|
||||
getFactionFieldWorkRepGain,
|
||||
} from "./PersonObjects/formulas/reputation";
|
||||
import { FconfSettings } from "./Fconf/FconfSettings";
|
||||
import {
|
||||
hasHacknetServers,
|
||||
@ -91,6 +96,7 @@ import { Page, routing } from "./ui/navigationTracking";
|
||||
import { setSettingsLabels } from "./ui/setSettingsLabels";
|
||||
import { Money } from "./ui/React/Money";
|
||||
import { Hashes } from "./ui/React/Hashes";
|
||||
import { Reputation } from "./ui/React/Reputation";
|
||||
|
||||
import { ActiveScriptsRoot } from "./ui/ActiveScripts/Root";
|
||||
import { initializeMainMenuHeaders } from "./ui/MainMenu/Headers";
|
||||
@ -1079,11 +1085,15 @@ const Engine = {
|
||||
|
||||
// Calculate the number of cycles have elapsed while offline
|
||||
Engine._lastUpdate = new Date().getTime();
|
||||
var lastUpdate = Player.lastUpdate;
|
||||
var numCyclesOffline = Math.floor((Engine._lastUpdate - lastUpdate) / Engine._idleSpeed);
|
||||
const lastUpdate = Player.lastUpdate;
|
||||
const timeOffline = Engine._lastUpdate - lastUpdate;
|
||||
const numCyclesOffline = Math.floor(timeOffline / Engine._idleSpeed);
|
||||
|
||||
let offlineReputation = 0
|
||||
const offlineHackingIncome = Player.moneySourceA.hacking/(Player.playtimeSinceLastAug)*timeOffline*0.75;
|
||||
Player.gainMoney(offlineHackingIncome);
|
||||
// Process offline progress
|
||||
var offlineProductionFromScripts = loadAllRunningScripts(); // This also takes care of offline production for those scripts
|
||||
loadAllRunningScripts(); // This also takes care of offline production for those scripts
|
||||
if (Player.isWorking) {
|
||||
if (Player.workType == CONSTANTS.WorkTypeFaction) {
|
||||
Player.workForFaction(numCyclesOffline);
|
||||
@ -1098,6 +1108,31 @@ const Engine = {
|
||||
} else {
|
||||
Player.work(numCyclesOffline);
|
||||
}
|
||||
} else {
|
||||
|
||||
for(let i = 0; i < Player.factions.length; i++) {
|
||||
const facName = Player.factions[i];
|
||||
if (!Factions.hasOwnProperty(facName)) continue;
|
||||
const faction = Factions[facName];
|
||||
if (!faction.isMember) continue;
|
||||
// No rep for special factions.
|
||||
const info = faction.getInfo();
|
||||
if(!info.offersWork()) continue;
|
||||
// No rep for gangs.
|
||||
if(Player.getGangName() === facName) continue;
|
||||
|
||||
|
||||
const hRep = getHackingWorkRepGain(Player, faction);
|
||||
const sRep = getFactionSecurityWorkRepGain(Player, faction);
|
||||
const fRep = getFactionFieldWorkRepGain(Player, faction);
|
||||
// can be infinite, doesn't matter.
|
||||
const reputationRate = Math.max(hRep, sRep, fRep) / Player.factions.length;
|
||||
|
||||
const rep = reputationRate *
|
||||
(numCyclesOffline);
|
||||
faction.playerReputation += rep
|
||||
offlineReputation += rep;
|
||||
}
|
||||
}
|
||||
|
||||
// Hacknet Nodes offline progress
|
||||
@ -1157,7 +1192,10 @@ const Engine = {
|
||||
removeLoadingScreen();
|
||||
const timeOfflineString = convertTimeMsToTimeElapsedString(time);
|
||||
dialogBoxCreate(<>
|
||||
Offline for {timeOfflineString}. While you were offline, your scripts generated {Money(offlineProductionFromScripts)} and your Hacknet Nodes generated {hacknetProdInfo}.
|
||||
Offline for {timeOfflineString}. While you were offline, your scripts
|
||||
generated {Money(offlineHackingIncome)}, your Hacknet Nodes
|
||||
generated {hacknetProdInfo} and you
|
||||
gained {Reputation(offlineReputation)} divided amongst your factions.
|
||||
</>);
|
||||
// Close main menu accordions for loaded game
|
||||
var visibleMenuTabs = [terminal, createScript, activeScripts, stats,
|
||||
@ -1599,4 +1637,4 @@ window.onload = function() {
|
||||
}
|
||||
};
|
||||
|
||||
export {Engine};
|
||||
export {Engine, indexedDb};
|
||||
|
Loading…
Reference in New Issue
Block a user