few more bugfixes

This commit is contained in:
Olivier Gagnon
2021-11-11 23:28:08 -05:00
parent a54e613e42
commit 3112dc60c0
24 changed files with 72 additions and 86 deletions

View File

@@ -3,7 +3,7 @@ import { IMap } from "../types";
export const GeneralActions: IMap<Action> = {};
let actionNames : Array<string> = [
const actionNames : Array<string> = [
"Training",
"Field Analysis",
"Recruitment",
@@ -12,7 +12,7 @@ let actionNames : Array<string> = [
"Incite Violence"
];
for (let actionName of actionNames){
for (const actionName of actionNames){
GeneralActions[actionName] = new Action({
name: actionName,
});

View File

@@ -147,7 +147,7 @@ export class Corporation {
const cycleProfit = profit * CorporationConstants.SecsPerMarketCycle;
const totalDividends = (this.dividendPercentage / 100) * cycleProfit;
const dividendsPerShare = totalDividends / this.totalShares;
const dividends = this.numShares * dividendsPerShare * (1 - this.dividendTaxPercentage / 100);
const dividends = this.numShares * dividendsPerShare;
let upgrades = -0.15;
if (this.unlockUpgrades[5] === 1) {
upgrades += 0.05;

View File

@@ -78,7 +78,6 @@ interface IProps {
// Create a popup that lets the player use the Market TA research for Products
export function ProductMarketTaModal(props: IProps): React.ReactElement {
const division = useDivision();
const markupLimit = props.product.rat / props.product.mku;
const setRerender = useState(false)[1];
function rerender(): void {

View File

@@ -14,7 +14,6 @@ import { CONSTANTS } from "../../Constants";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { Faction } from "../../Faction/Faction";
import { SourceFileFlags } from "../../SourceFile/SourceFileFlags";
import { use } from "../../ui/Context";
import { CreateGangModal } from "./CreateGangModal";

View File

@@ -508,7 +508,6 @@ export function purchaseHashUpgrade(player: IPlayer, upgName: string, upgTarget:
}
if (!(target instanceof Server)) throw new Error(`'${upgTarget}' is not a normal server.`);
const old = target.moneyMax;
target.changeMaximumMoney(upg.value);
} catch (e) {
player.hashManager.refundUpgrade(upgName);

View File

@@ -136,7 +136,7 @@ function iTutorialPrevStep(): void {
function iTutorialEnd(): void {
ITutorial.isRunning = false;
ITutorial.currStep = iTutorialSteps.Start;
Player.getHomeComputer().messages.push(LiteratureNames.HackersStartingHandbook);
ITutorialEvents.emit();
}

View File

@@ -430,7 +430,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
const hacknet = NetscriptHacknet(Player, workerScript, helper);
const bladeburner = NetscriptBladeburner(Player, workerScript, helper);
const codingcontract = NetscriptCodingContract(Player, workerScript, helper);
const corporation = NetscriptCorporation(Player, workerScript, helper);
const corporation = NetscriptCorporation(Player);
const formulas = NetscriptFormulas(Player, workerScript, helper);
const singularity = NetscriptSingularity(Player, workerScript, helper);
const stockmarket = NetscriptStockMarket(Player, workerScript, helper);

View File

@@ -1,5 +1,3 @@
import { INetscriptHelper } from "./INetscriptHelper";
import { WorkerScript } from "../Netscript/WorkerScript";
import { IPlayer } from "../PersonObjects/IPlayer";
import { OfficeSpace } from "../Corporation/OfficeSpace";
@@ -88,11 +86,7 @@ export interface INetscriptCorporation {
getEmployee(divisionName: any, cityName: any, employeeName: any): any;
}
export function NetscriptCorporation(
player: IPlayer,
workerScript: WorkerScript,
helper: INetscriptHelper,
): INetscriptCorporation {
export function NetscriptCorporation(player: IPlayer): INetscriptCorporation {
function getDivision(divisionName: any): IIndustry {
const corporation = player.corporation;
if (corporation === null) throw new Error("cannot be called without a corporation");

View File

@@ -1,4 +1,3 @@
import { Corporation } from "./Corporation/Corporation";
import { PlayerObject } from "./PersonObjects/Player/PlayerObject";
import { sanitizeExploits } from "./Exploits/Exploit";

View File

@@ -75,24 +75,7 @@ class BitburnerSaveObject {
const epochTime = Math.round(Date.now() / 1000);
const bn = Player.bitNodeN;
const filename = `bitburnerSave_BN${bn}x${SourceFileFlags[bn]}_${epochTime}.json`;
const file = new Blob([saveString], { type: "text/plain" });
const navigator = window.navigator as any;
if (navigator.msSaveOrOpenBlob) {
// IE10+
navigator.msSaveOrOpenBlob(file, filename);
} else {
// Others
const a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
download(filename, saveString);
}
toJSON(): any {
@@ -372,8 +355,29 @@ function createBetaUpdateText(): void {
);
}
function download(filename: string, content: string): void {
const file = new Blob([content], { type: "text/plain" });
const navigator = window.navigator as any;
if (navigator.msSaveOrOpenBlob) {
// IE10+
navigator.msSaveOrOpenBlob(file, filename);
} else {
// Others
const a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
Reviver.constructors.BitburnerSaveObject = BitburnerSaveObject;
export { saveObject, loadGame };
export { saveObject, loadGame, download };
const saveObject = new BitburnerSaveObject();

View File

@@ -4,7 +4,6 @@ import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { BaseServer } from "../../Server/BaseServer";
import { getFirstParentDirectory, isValidDirectoryPath, evaluateDirectoryPath } from "../../Terminal/DirectoryHelpers";
import Typography from "@mui/material/Typography";
export function ls(
terminal: ITerminal,

View File

@@ -3,6 +3,7 @@ import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { BaseServer } from "../../Server/BaseServer";
import { isScriptFilename } from "../../Script/isScriptFilename";
import { CursorPositions } from "../../ScriptEditor/CursorPositions";
export function nano(
terminal: ITerminal,
@@ -24,13 +25,15 @@ export function nano(
if (script == null) {
let code = "";
if (filename.endsWith(".ns") || filename.endsWith(".js")) {
code = `/**
* @param {NS} ns
**/
code = `/** @param {NS} ns **/
export async function main(ns) {
}`;
}
CursorPositions.saveCursor(filename, {
row: 3,
column: 5,
});
router.toScriptEditor(filepath, code);
} else {
router.toScriptEditor(filepath, script.code);

View File

@@ -2,7 +2,6 @@ import { ITerminal } from "../ITerminal";
import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { BaseServer } from "../../Server/BaseServer";
import { Message } from "../../Message/Message";
import { GetServer } from "../../Server/AllServers";
import { isScriptFilename } from "../../Script/isScriptFilename";

View File

@@ -33,8 +33,8 @@ function getDB(): Promise<IDBObjectStore> {
}
export function load(): Promise<string> {
return new Promise(async (resolve, reject) => {
await getDB()
return new Promise((resolve, reject) => {
getDB()
.then((db) => {
return new Promise<string>((resolve, reject) => {
const request: IDBRequest<string> = db.get("save");

View File

@@ -480,7 +480,13 @@ export function GameOptionsRoot(props: IProps): React.ReactElement {
<TextField
InputProps={{
startAdornment: (
<Typography color={formatTime(timestampFormat) === "format error" ? "error" : "success"}>
<Typography
color={
formatTime(timestampFormat) === "format error" && timestampFormat !== ""
? "error"
: "success"
}
>
Timestamp&nbsp;format:&nbsp;
</Typography>
),

View File

@@ -3,8 +3,9 @@ import Typography from "@mui/material/Typography";
import Link from "@mui/material/Link";
import Button from "@mui/material/Button";
import { Settings } from "../../Settings/Settings";
import { saveObject } from "../../SaveObject";
import { load } from "../../db";
import { IRouter } from "../Router";
import { download } from "../../SaveObject";
export let RecoveryMode = false;
@@ -22,7 +23,9 @@ export function RecoveryRoot({ router }: IProps): React.ReactElement {
router.toTerminal();
}
Settings.AutosaveInterval = 0;
saveObject.exportGame();
load().then((content) => {
download("RECOVERY.json", content);
});
return (
<>
<Typography variant="h3">RECOVERY MODE ACTIVATED</Typography>

View File

@@ -1,21 +1,6 @@
/**
* Generic Event Emitter class following a subscribe/publish paradigm.
*/
type cbFn = (...args: any[]) => any;
interface ISubscriber {
/**
* Callback function that will be run when an event is emitted
*/
cb: cbFn;
/**
* Name/identifier for this subscriber
*/
id: string;
}
function uuidv4(): string {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,