bitburner-src/src/RedPill.tsx

78 lines
2.4 KiB
TypeScript
Raw Normal View History

/** Implementation for what happens when you destroy a BitNode */
2021-09-30 23:02:07 +02:00
import React from "react";
import { Player } from "@player";
2021-09-13 00:03:07 +02:00
import { PlayerOwnedSourceFile } from "./SourceFile/PlayerOwnedSourceFile";
import { SourceFiles } from "./SourceFile/SourceFiles";
2021-09-25 20:42:57 +02:00
import { dialogBoxCreate } from "./ui/React/DialogBox";
2022-09-13 00:00:09 +02:00
import { Router } from "./ui/GameRoot";
2022-12-04 09:14:06 +01:00
import { Page } from "./ui/Router";
import { Engine } from "./engine";
2021-09-13 00:03:07 +02:00
2021-09-24 22:37:42 +02:00
function giveSourceFile(bitNodeNumber: number): void {
2021-09-25 07:26:03 +02:00
const sourceFileKey = "SourceFile" + bitNodeNumber.toString();
const sourceFile = SourceFiles[sourceFileKey];
2021-09-13 00:03:07 +02:00
if (sourceFile == null) {
console.error(`Could not find source file for Bit node: ${bitNodeNumber}`);
return;
}
// Check if player already has this source file
const ownedSourceFile = Player.sourceFiles.find((sourceFile) => sourceFile.n === bitNodeNumber);
2021-09-13 00:03:07 +02:00
if (ownedSourceFile) {
2021-09-13 00:03:07 +02:00
if (ownedSourceFile.lvl >= 3 && ownedSourceFile.n !== 12) {
dialogBoxCreate(
`The Source-File for the BitNode you just destroyed, ${sourceFile.name}, is already at max level!`,
2021-09-13 00:03:07 +02:00
);
} else {
++ownedSourceFile.lvl;
dialogBoxCreate(
sourceFile.name +
" was upgraded to level " +
ownedSourceFile.lvl +
" for " +
"destroying its corresponding BitNode!",
);
}
} else {
const newSrcFile = new PlayerOwnedSourceFile(bitNodeNumber, 1);
Player.sourceFiles.push(newSrcFile);
if (bitNodeNumber === 5 && Player.skills.intelligence === 0) {
Player.skills.intelligence = 1;
2021-09-13 00:03:07 +02:00
}
dialogBoxCreate(
2021-09-30 23:02:07 +02:00
<>
You received a Source-File for destroying a BitNode!
<br />
<br />
{sourceFile.name}
<br />
<br />
{sourceFile.info}
</>,
2021-09-13 00:03:07 +02:00
);
}
}
2022-09-13 00:00:09 +02:00
export function enterBitNode(flume: boolean, destroyedBitNode: number, newBitNode: number): void {
2021-09-13 00:03:07 +02:00
if (!flume) {
giveSourceFile(destroyedBitNode);
2022-04-14 07:22:50 +02:00
} else if (Player.sourceFileLvl(5) === 0 && newBitNode !== 5) {
Player.skills.intelligence = 0;
Player.exp.intelligence = 0;
2022-04-07 01:30:08 +02:00
}
if (newBitNode === 5 && Player.skills.intelligence === 0) {
Player.skills.intelligence = 1;
2021-09-13 00:03:07 +02:00
}
// Set new Bit Node
Player.bitNodeN = newBitNode;
2021-09-18 01:43:08 +02:00
if (newBitNode === 6) {
2022-12-04 09:14:06 +01:00
Router.toPage(Page.BladeburnerCinematic);
2021-09-18 01:43:08 +02:00
} else {
2022-12-04 09:14:06 +01:00
Router.toPage(Page.Terminal);
2021-09-18 01:43:08 +02:00
}
Engine.nodeTransfer = flume;
2021-09-13 00:03:07 +02:00
}