2021-09-13 00:03:07 +02:00
|
|
|
/**
|
|
|
|
* Implementation for what happens when you destroy a BitNode
|
|
|
|
*/
|
2021-09-30 23:02:07 +02:00
|
|
|
import React from "react";
|
2021-09-13 00:03:07 +02:00
|
|
|
import { Player } from "./Player";
|
|
|
|
import { prestigeSourceFile } from "./Prestige";
|
|
|
|
import { PlayerOwnedSourceFile } from "./SourceFile/PlayerOwnedSourceFile";
|
|
|
|
import { SourceFiles } from "./SourceFile/SourceFiles";
|
|
|
|
|
2021-09-25 20:42:57 +02:00
|
|
|
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
2021-09-24 22:37:42 +02:00
|
|
|
import { IRouter } from "./ui/Router";
|
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
|
2021-09-25 07:26:03 +02:00
|
|
|
let alreadyOwned = false;
|
|
|
|
let ownedSourceFile = null;
|
|
|
|
for (let i = 0; i < Player.sourceFiles.length; ++i) {
|
2021-09-13 00:03:07 +02:00
|
|
|
if (Player.sourceFiles[i].n === bitNodeNumber) {
|
|
|
|
alreadyOwned = true;
|
|
|
|
ownedSourceFile = Player.sourceFiles[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alreadyOwned && ownedSourceFile) {
|
|
|
|
if (ownedSourceFile.lvl >= 3 && ownedSourceFile.n !== 12) {
|
|
|
|
dialogBoxCreate(
|
2022-03-16 20:43:04 +01:00
|
|
|
`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 {
|
2021-09-25 07:26:03 +02:00
|
|
|
const playerSrcFile = new PlayerOwnedSourceFile(bitNodeNumber, 1);
|
2021-09-13 00:03:07 +02:00
|
|
|
Player.sourceFiles.push(playerSrcFile);
|
|
|
|
if (bitNodeNumber === 5 && Player.intelligence === 0) {
|
|
|
|
// Artificial Intelligence
|
|
|
|
Player.intelligence = 1;
|
|
|
|
}
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 22:37:42 +02:00
|
|
|
export function enterBitNode(router: IRouter, 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) {
|
2022-04-07 01:30:08 +02:00
|
|
|
Player.intelligence = 0;
|
|
|
|
Player.intelligence_exp = 0;
|
|
|
|
}
|
2021-09-13 00:03:07 +02:00
|
|
|
if (newBitNode === 5 && Player.intelligence === 0) {
|
|
|
|
Player.intelligence = 1;
|
|
|
|
}
|
|
|
|
// Set new Bit Node
|
|
|
|
Player.bitNodeN = newBitNode;
|
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
if (newBitNode === 6) {
|
|
|
|
router.toBladeburnerCinematic();
|
|
|
|
} else {
|
|
|
|
router.toTerminal();
|
|
|
|
}
|
2021-09-13 00:03:07 +02:00
|
|
|
prestigeSourceFile(flume);
|
|
|
|
}
|