2019-05-16 08:05:36 +02:00
|
|
|
/**
|
2021-09-18 01:43:08 +02:00
|
|
|
* Game engine. Handles the main game loop.
|
2019-05-16 08:05:36 +02:00
|
|
|
*/
|
2021-09-16 21:49:37 +02:00
|
|
|
import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { Augmentations } from "./Augmentation/Augmentations";
|
2021-09-18 01:43:08 +02:00
|
|
|
import { initAugmentations } from "./Augmentation/AugmentationHelpers";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
|
2021-09-05 01:09:30 +02:00
|
|
|
import { initBitNodeMultipliers } from "./BitNode/BitNode";
|
2021-08-17 00:43:55 +02:00
|
|
|
import { Bladeburner } from "./Bladeburner/Bladeburner";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { generateRandomContract } from "./CodingContractGenerator";
|
|
|
|
import { initCompanies } from "./Company/Companies";
|
|
|
|
import { Corporation } from "./Corporation/Corporation";
|
|
|
|
import { CONSTANTS } from "./Constants";
|
|
|
|
import { Factions, initFactions } from "./Faction/Factions";
|
2021-09-09 05:47:34 +02:00
|
|
|
import { processPassiveFactionRepGain, inviteToFaction } from "./Faction/FactionHelpers";
|
2021-09-18 01:43:08 +02:00
|
|
|
import { GameRoot, Router } from "./ui/GameRoot";
|
2021-09-17 01:23:03 +02:00
|
|
|
import { TTheme as Theme } from "./ui/React/Theme";
|
2021-09-05 01:09:30 +02:00
|
|
|
import {
|
|
|
|
getHackingWorkRepGain,
|
|
|
|
getFactionSecurityWorkRepGain,
|
|
|
|
getFactionFieldWorkRepGain,
|
2021-05-11 02:11:03 +02:00
|
|
|
} from "./PersonObjects/formulas/reputation";
|
2021-09-09 09:17:01 +02:00
|
|
|
import { hasHacknetServers, processHacknetEarnings } from "./Hacknet/HacknetHelpers";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { iTutorialStart } from "./InteractiveTutorial";
|
|
|
|
import { checkForMessagesToSend, initMessages } from "./Message/MessageHelpers";
|
|
|
|
import { inMission, currMission } from "./Missions";
|
2021-09-09 05:47:34 +02:00
|
|
|
import { loadAllRunningScripts, updateOnlineScriptTimes } from "./NetscriptWorker";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { Player } from "./Player";
|
|
|
|
import { saveObject, loadGame } from "./SaveObject";
|
2021-09-18 01:43:08 +02:00
|
|
|
import { initForeignServers } from "./Server/AllServers";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { Settings } from "./Settings/Settings";
|
|
|
|
import { updateSourceFileFlags } from "./SourceFile/SourceFileFlags";
|
2019-05-15 09:37:11 +02:00
|
|
|
import { initSpecialServerIps } from "./Server/SpecialServerIps";
|
2021-09-17 08:31:19 +02:00
|
|
|
import { initSymbolToStockMap, processStockPrices } from "./StockMarket/StockMarket";
|
2021-09-16 08:52:45 +02:00
|
|
|
import { Terminal } from "./Terminal";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { Sleeve } from "./PersonObjects/Sleeve/Sleeve";
|
2019-01-18 18:57:21 +01:00
|
|
|
|
2021-03-31 06:45:21 +02:00
|
|
|
import { Money } from "./ui/React/Money";
|
|
|
|
import { Hashes } from "./ui/React/Hashes";
|
2021-05-11 02:11:03 +02:00
|
|
|
import { Reputation } from "./ui/React/Reputation";
|
2019-05-17 22:41:16 +02:00
|
|
|
|
2019-04-11 10:37:40 +02:00
|
|
|
import { dialogBoxCreate } from "../utils/DialogBox";
|
|
|
|
import { exceptionAlert } from "../utils/helpers/exceptionAlert";
|
|
|
|
import { removeLoadingScreen } from "../utils/uiHelpers/removeLoadingScreen";
|
2021-03-09 02:31:34 +01:00
|
|
|
import "./Exploits/tampering";
|
2021-03-22 19:48:48 +01:00
|
|
|
import "./Exploits/unclickable";
|
2019-01-18 18:57:21 +01:00
|
|
|
|
2019-04-11 10:37:40 +02:00
|
|
|
import React from "react";
|
|
|
|
import ReactDOM from "react-dom";
|
2019-01-18 18:57:21 +01:00
|
|
|
|
2018-09-06 18:07:59 +02:00
|
|
|
const Engine = {
|
2021-09-05 01:09:30 +02:00
|
|
|
// Display objects
|
|
|
|
// TODO-Refactor this into its own component
|
|
|
|
Display: {
|
|
|
|
missionContent: null,
|
|
|
|
},
|
|
|
|
|
|
|
|
indexedDb: undefined,
|
|
|
|
|
|
|
|
// Time variables (milliseconds unix epoch time)
|
|
|
|
_lastUpdate: new Date().getTime(),
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
updateGame: function (numCycles = 1) {
|
2021-09-18 01:43:08 +02:00
|
|
|
const time = numCycles * CONSTANTS._idleSpeed;
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Player.totalPlaytime == null) {
|
|
|
|
Player.totalPlaytime = 0;
|
|
|
|
}
|
|
|
|
if (Player.playtimeSinceLastAug == null) {
|
|
|
|
Player.playtimeSinceLastAug = 0;
|
|
|
|
}
|
|
|
|
if (Player.playtimeSinceLastBitnode == null) {
|
|
|
|
Player.playtimeSinceLastBitnode = 0;
|
|
|
|
}
|
|
|
|
Player.totalPlaytime += time;
|
|
|
|
Player.playtimeSinceLastAug += time;
|
|
|
|
Player.playtimeSinceLastBitnode += time;
|
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
Terminal.process(Router, Player, numCycles);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Working
|
|
|
|
if (Player.isWorking) {
|
|
|
|
if (Player.workType == CONSTANTS.WorkTypeFaction) {
|
|
|
|
Player.workForFaction(numCycles);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
|
|
|
|
Player.createProgramWork(numCycles);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeStudyClass) {
|
|
|
|
Player.takeClass(numCycles);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCrime) {
|
|
|
|
Player.commitCrime(numCycles);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) {
|
|
|
|
Player.workPartTime(numCycles);
|
|
|
|
} else {
|
|
|
|
Player.work(numCycles);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Update stock prices
|
|
|
|
if (Player.hasWseAccount) {
|
|
|
|
processStockPrices(numCycles);
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Gang, if applicable
|
|
|
|
if (Player.inGang()) {
|
|
|
|
Player.gang.process(numCycles, Player);
|
|
|
|
}
|
2019-05-17 22:41:16 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Mission
|
|
|
|
if (inMission && currMission) {
|
|
|
|
currMission.process(numCycles);
|
|
|
|
}
|
2018-05-10 19:14:45 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Corporation
|
|
|
|
if (Player.corporation instanceof Corporation) {
|
|
|
|
// Stores cycles in a "buffer". Processed separately using Engine Counters
|
|
|
|
Player.corporation.storeCycles(numCycles);
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Player.bladeburner instanceof Bladeburner) {
|
|
|
|
Player.bladeburner.storeCycles(numCycles);
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Sleeves
|
|
|
|
for (let i = 0; i < Player.sleeves.length; ++i) {
|
|
|
|
if (Player.sleeves[i] instanceof Sleeve) {
|
|
|
|
const expForOtherSleeves = Player.sleeves[i].process(Player, numCycles);
|
2017-08-18 19:20:51 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// This sleeve earns experience for other sleeves
|
|
|
|
if (expForOtherSleeves == null) {
|
|
|
|
continue;
|
2017-05-05 18:52:48 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
for (let j = 0; j < Player.sleeves.length; ++j) {
|
|
|
|
if (j === i) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-09 05:47:34 +02:00
|
|
|
Player.sleeves[j].gainExperience(Player, expForOtherSleeves, numCycles, true);
|
2021-03-08 00:41:04 +01:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-08 00:41:04 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Counters
|
|
|
|
Engine.decrementAllCounters(numCycles);
|
|
|
|
Engine.checkCounters();
|
2021-03-08 00:41:04 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Update the running time of all active scripts
|
|
|
|
updateOnlineScriptTimes(numCycles);
|
|
|
|
|
|
|
|
// Hacknet Nodes
|
2021-09-09 09:17:01 +02:00
|
|
|
processHacknetEarnings(Player, numCycles);
|
2021-09-05 01:09:30 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counters for the main event loop. Represent the number of game cycles that
|
|
|
|
* are required for something to happen. These counters are in game cycles,
|
|
|
|
* which is once every 200ms
|
|
|
|
*/
|
|
|
|
Counters: {
|
|
|
|
autoSaveCounter: 300,
|
|
|
|
updateSkillLevelsCounter: 10,
|
|
|
|
updateDisplays: 3,
|
|
|
|
updateDisplaysLong: 15,
|
|
|
|
updateActiveScriptsDisplay: 5,
|
|
|
|
createProgramNotifications: 10,
|
|
|
|
augmentationsNotifications: 10,
|
|
|
|
checkFactionInvitations: 100,
|
|
|
|
passiveFactionGrowth: 5,
|
|
|
|
messages: 150,
|
|
|
|
mechanicProcess: 5, // Processes certain mechanics (Corporation, Bladeburner)
|
|
|
|
contractGeneration: 3000, // Generate Coding Contracts
|
|
|
|
},
|
|
|
|
|
|
|
|
decrementAllCounters: function (numCycles = 1) {
|
|
|
|
for (var counter in Engine.Counters) {
|
|
|
|
if (Engine.Counters.hasOwnProperty(counter)) {
|
|
|
|
Engine.Counters[counter] = Engine.Counters[counter] - numCycles;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if any counters are 0. If they are, executes whatever
|
|
|
|
* is necessary and then resets the counter
|
|
|
|
*/
|
|
|
|
checkCounters: function () {
|
|
|
|
if (Engine.Counters.autoSaveCounter <= 0) {
|
|
|
|
if (Settings.AutosaveInterval == null) {
|
|
|
|
Settings.AutosaveInterval = 60;
|
|
|
|
}
|
|
|
|
if (Settings.AutosaveInterval === 0) {
|
|
|
|
Engine.Counters.autoSaveCounter = Infinity;
|
|
|
|
} else {
|
|
|
|
Engine.Counters.autoSaveCounter = Settings.AutosaveInterval * 5;
|
|
|
|
saveObject.saveGame(Engine.indexedDb);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-11 23:23:56 +02:00
|
|
|
if (Engine.Counters.checkFactionInvitations <= 0) {
|
|
|
|
const invitedFactions = Player.checkForFactionInvitations();
|
|
|
|
if (invitedFactions.length > 0) {
|
|
|
|
const randFaction = invitedFactions[Math.floor(Math.random() * invitedFactions.length)];
|
|
|
|
inviteToFaction(randFaction);
|
|
|
|
}
|
|
|
|
Engine.Counters.checkFactionInvitations = 100;
|
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Engine.Counters.passiveFactionGrowth <= 0) {
|
|
|
|
var adjustedCycles = Math.floor(5 - Engine.Counters.passiveFactionGrowth);
|
|
|
|
processPassiveFactionRepGain(adjustedCycles);
|
|
|
|
Engine.Counters.passiveFactionGrowth = 5;
|
|
|
|
}
|
2019-01-20 23:57:38 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Engine.Counters.messages <= 0) {
|
|
|
|
checkForMessagesToSend();
|
|
|
|
if (Augmentations[AugmentationNames.TheRedPill].owned) {
|
|
|
|
Engine.Counters.messages = 4500; // 15 minutes for Red pill message
|
|
|
|
} else {
|
|
|
|
Engine.Counters.messages = 150;
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Engine.Counters.mechanicProcess <= 0) {
|
|
|
|
if (Player.corporation instanceof Corporation) {
|
|
|
|
Player.corporation.process(Player);
|
|
|
|
}
|
|
|
|
if (Player.bladeburner instanceof Bladeburner) {
|
|
|
|
try {
|
2021-09-18 01:43:08 +02:00
|
|
|
Player.bladeburner.process(Router, Player);
|
2021-09-05 01:09:30 +02:00
|
|
|
} catch (e) {
|
|
|
|
exceptionAlert("Exception caught in Bladeburner.process(): " + e);
|
2017-05-05 23:27:35 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
Engine.Counters.mechanicProcess = 5;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Engine.Counters.contractGeneration <= 0) {
|
|
|
|
// X% chance of a contract being generated
|
|
|
|
if (Math.random() <= 0.25) {
|
|
|
|
generateRandomContract();
|
|
|
|
}
|
|
|
|
Engine.Counters.contractGeneration = 3000;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
load: function (saveString) {
|
|
|
|
// Load game from save or create new game
|
|
|
|
if (loadGame(saveString)) {
|
|
|
|
initBitNodeMultipliers(Player);
|
|
|
|
Engine.setDisplayElements(); // Sets variables for important DOM elements
|
|
|
|
updateSourceFileFlags(Player);
|
|
|
|
initAugmentations(); // Also calls Player.reapplyAllAugmentations()
|
|
|
|
Player.reapplyAllSourceFiles();
|
|
|
|
if (Player.hasWseAccount) {
|
|
|
|
initSymbolToStockMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the number of cycles have elapsed while offline
|
|
|
|
Engine._lastUpdate = new Date().getTime();
|
|
|
|
const lastUpdate = Player.lastUpdate;
|
|
|
|
const timeOffline = Engine._lastUpdate - lastUpdate;
|
2021-09-18 01:43:08 +02:00
|
|
|
const numCyclesOffline = Math.floor(timeOffline / CONSTANTS._idleSpeed);
|
2021-09-05 01:09:30 +02:00
|
|
|
|
|
|
|
let offlineReputation = 0;
|
2021-09-09 05:47:34 +02:00
|
|
|
const offlineHackingIncome = (Player.moneySourceA.hacking / Player.playtimeSinceLastAug) * timeOffline * 0.75;
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.gainMoney(offlineHackingIncome);
|
|
|
|
// Process offline progress
|
|
|
|
loadAllRunningScripts(); // This also takes care of offline production for those scripts
|
|
|
|
if (Player.isWorking) {
|
|
|
|
Player.focus = true;
|
|
|
|
if (Player.workType == CONSTANTS.WorkTypeFaction) {
|
|
|
|
Player.workForFaction(numCyclesOffline);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
|
|
|
|
Player.createProgramWork(numCyclesOffline);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeStudyClass) {
|
|
|
|
Player.takeClass(numCyclesOffline);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCrime) {
|
|
|
|
Player.commitCrime(numCyclesOffline);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) {
|
|
|
|
Player.workPartTime(numCyclesOffline);
|
|
|
|
} else {
|
|
|
|
Player.work(numCyclesOffline);
|
2019-01-18 18:57:21 +01:00
|
|
|
}
|
2021-09-18 01:43:08 +02:00
|
|
|
Player.focus = false;
|
2021-09-05 01:09:30 +02:00
|
|
|
} 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.
|
2021-09-09 05:47:34 +02:00
|
|
|
const reputationRate = Math.max(hRep, sRep, fRep) / Player.factions.length;
|
2021-09-05 01:09:30 +02:00
|
|
|
|
|
|
|
const rep = reputationRate * numCyclesOffline;
|
|
|
|
faction.playerReputation += rep;
|
|
|
|
offlineReputation += rep;
|
2017-07-22 00:54:55 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hacknet Nodes offline progress
|
2021-09-09 09:17:01 +02:00
|
|
|
var offlineProductionFromHacknetNodes = processHacknetEarnings(Player, numCyclesOffline);
|
|
|
|
const hacknetProdInfo = hasHacknetServers(Player) ? (
|
2021-09-05 01:09:30 +02:00
|
|
|
<>{Hashes(offlineProductionFromHacknetNodes)} hashes</>
|
|
|
|
) : (
|
|
|
|
<Money money={offlineProductionFromHacknetNodes} />
|
|
|
|
);
|
|
|
|
|
|
|
|
// Passive faction rep gain offline
|
|
|
|
processPassiveFactionRepGain(numCyclesOffline);
|
|
|
|
|
|
|
|
// Stock Market offline progress
|
|
|
|
if (Player.hasWseAccount) {
|
|
|
|
processStockPrices(numCyclesOffline);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gang progress for BitNode 2
|
|
|
|
if (Player.inGang()) {
|
|
|
|
Player.gang.process(numCyclesOffline, Player);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Corporation offline progress
|
|
|
|
if (Player.corporation instanceof Corporation) {
|
|
|
|
Player.corporation.storeCycles(numCyclesOffline);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bladeburner offline progress
|
|
|
|
if (Player.bladeburner instanceof Bladeburner) {
|
|
|
|
Player.bladeburner.storeCycles(numCyclesOffline);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sleeves offline progress
|
|
|
|
for (let i = 0; i < Player.sleeves.length; ++i) {
|
|
|
|
if (Player.sleeves[i] instanceof Sleeve) {
|
2021-09-09 05:47:34 +02:00
|
|
|
const expForOtherSleeves = Player.sleeves[i].process(Player, numCyclesOffline);
|
2021-09-05 01:09:30 +02:00
|
|
|
|
|
|
|
// This sleeve earns experience for other sleeves
|
|
|
|
if (expForOtherSleeves == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (let j = 0; j < Player.sleeves.length; ++j) {
|
|
|
|
if (j === i) {
|
|
|
|
continue;
|
2018-08-07 03:15:31 +02:00
|
|
|
}
|
2021-09-09 05:47:34 +02:00
|
|
|
Player.sleeves[j].gainExperience(Player, expForOtherSleeves, numCyclesOffline, true);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update total playtime
|
2021-09-18 01:43:08 +02:00
|
|
|
var time = numCyclesOffline * CONSTANTS._idleSpeed;
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Player.totalPlaytime == null) {
|
|
|
|
Player.totalPlaytime = 0;
|
|
|
|
}
|
|
|
|
if (Player.playtimeSinceLastAug == null) {
|
|
|
|
Player.playtimeSinceLastAug = 0;
|
|
|
|
}
|
|
|
|
if (Player.playtimeSinceLastBitnode == null) {
|
|
|
|
Player.playtimeSinceLastBitnode = 0;
|
|
|
|
}
|
|
|
|
Player.totalPlaytime += time;
|
|
|
|
Player.playtimeSinceLastAug += time;
|
|
|
|
Player.playtimeSinceLastBitnode += time;
|
|
|
|
|
|
|
|
Player.lastUpdate = Engine._lastUpdate;
|
|
|
|
Engine.start(); // Run main game loop and Scripts loop
|
|
|
|
removeLoadingScreen();
|
|
|
|
const timeOfflineString = convertTimeMsToTimeElapsedString(time);
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
2021-09-09 05:47:34 +02:00
|
|
|
Offline for {timeOfflineString}. While you were offline, your scripts generated{" "}
|
|
|
|
<Money money={offlineHackingIncome} />, your Hacknet Nodes generated {hacknetProdInfo} and you gained{" "}
|
2021-09-05 01:09:30 +02:00
|
|
|
{Reputation(offlineReputation)} divided amongst your factions.
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// No save found, start new game
|
|
|
|
initBitNodeMultipliers(Player);
|
|
|
|
initSpecialServerIps();
|
|
|
|
Engine.setDisplayElements(); // Sets variables for important DOM elements
|
|
|
|
Engine.start(); // Run main game loop and Scripts loop
|
|
|
|
Player.init();
|
|
|
|
initForeignServers(Player.getHomeComputer());
|
|
|
|
initCompanies();
|
|
|
|
initFactions();
|
|
|
|
initAugmentations();
|
|
|
|
initMessages();
|
|
|
|
updateSourceFileFlags(Player);
|
|
|
|
|
|
|
|
// Start interactive tutorial
|
|
|
|
iTutorialStart();
|
|
|
|
removeLoadingScreen();
|
|
|
|
}
|
2021-09-11 07:54:19 +02:00
|
|
|
|
2021-09-17 01:23:03 +02:00
|
|
|
ReactDOM.render(
|
|
|
|
<Theme>
|
2021-09-17 08:04:44 +02:00
|
|
|
<GameRoot terminal={Terminal} engine={this} player={Player} />
|
2021-09-17 01:23:03 +02:00
|
|
|
</Theme>,
|
2021-09-17 08:04:44 +02:00
|
|
|
document.getElementById("mainmenu-container"),
|
2021-09-17 01:23:03 +02:00
|
|
|
);
|
2021-09-05 01:09:30 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setDisplayElements: function () {
|
2021-09-09 05:47:34 +02:00
|
|
|
Engine.Display.missionContent = document.getElementById("mission-container");
|
2021-09-05 01:09:30 +02:00
|
|
|
Engine.Display.missionContent.style.display = "none";
|
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
start: function () {
|
|
|
|
// Get time difference
|
|
|
|
const _thisUpdate = new Date().getTime();
|
|
|
|
let diff = _thisUpdate - Engine._lastUpdate;
|
|
|
|
const offset = diff % CONSTANTS._idleSpeed;
|
2021-09-17 01:42:55 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
// Divide this by cycle time to determine how many cycles have elapsed since last update
|
|
|
|
diff = Math.floor(diff / CONSTANTS._idleSpeed);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
if (diff > 0) {
|
|
|
|
// Update the game engine by the calculated number of cycles
|
|
|
|
Engine._lastUpdate = _thisUpdate - offset;
|
|
|
|
Player.lastUpdate = _thisUpdate - offset;
|
|
|
|
Engine.updateGame(diff);
|
2021-09-16 23:30:47 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
window.requestAnimationFrame(Engine.start);
|
2021-09-05 01:09:30 +02:00
|
|
|
},
|
2016-10-17 10:24:39 +02:00
|
|
|
};
|
|
|
|
|
2021-05-11 19:27:02 +02:00
|
|
|
var indexedDbRequest;
|
2021-09-05 01:09:30 +02:00
|
|
|
window.onload = function () {
|
|
|
|
if (!window.indexedDB) {
|
|
|
|
return Engine.load(null); // Will try to load from localstorage
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DB is called bitburnerSave
|
|
|
|
* Object store is called savestring
|
|
|
|
* key for the Object store is called save
|
|
|
|
*/
|
|
|
|
indexedDbRequest = window.indexedDB.open("bitburnerSave", 1);
|
|
|
|
|
|
|
|
indexedDbRequest.onerror = function (e) {
|
|
|
|
console.error("Error opening indexedDB: ");
|
|
|
|
console.error(e);
|
|
|
|
return Engine.load(null); // Try to load from localstorage
|
|
|
|
};
|
|
|
|
|
|
|
|
indexedDbRequest.onsuccess = function (e) {
|
|
|
|
Engine.indexedDb = e.target.result;
|
|
|
|
var transaction = Engine.indexedDb.transaction(["savestring"]);
|
|
|
|
var objectStore = transaction.objectStore("savestring");
|
|
|
|
var request = objectStore.get("save");
|
|
|
|
request.onerror = function (e) {
|
|
|
|
console.error("Error in Database request to get savestring: " + e);
|
|
|
|
return Engine.load(null); // Try to load from localstorage
|
2017-10-12 04:00:22 +02:00
|
|
|
};
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
request.onsuccess = function () {
|
|
|
|
Engine.load(request.result);
|
2017-10-12 04:00:22 +02:00
|
|
|
};
|
2021-09-05 01:09:30 +02:00
|
|
|
};
|
2017-10-12 04:00:22 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
indexedDbRequest.onupgradeneeded = function (e) {
|
|
|
|
const db = e.target.result;
|
|
|
|
db.createObjectStore("savestring");
|
|
|
|
};
|
2016-10-17 10:24:39 +02:00
|
|
|
};
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
export { Engine };
|