bitburner-src/src/Augmentation/AugmentationHelpers.tsx

157 lines
5.1 KiB
TypeScript
Raw Normal View History

import { Augmentation } from "./Augmentation";
import { StaticAugmentations } from "./StaticAugmentations";
2021-09-24 22:02:38 +02:00
import { PlayerOwnedAugmentation, IPlayerOwnedAugmentation } from "./PlayerOwnedAugmentation";
import { AugmentationNames } from "./data/AugmentationNames";
import { CONSTANTS } from "../Constants";
import { Factions, factionExists } from "../Faction/Factions";
import { Player } from "../Player";
import { prestigeAugmentation } from "../Prestige";
2021-09-25 20:42:57 +02:00
import { dialogBoxCreate } from "../ui/React/DialogBox";
import { clearObject } from "../utils/helpers/clearObject";
import { FactionNames } from "../Faction/data/FactionNames";
import {
2022-04-04 13:50:01 +02:00
initBladeburnerAugmentations,
initChurchOfTheMachineGodAugmentations,
initGeneralAugmentations,
2022-04-22 21:30:49 +02:00
initSoAAugmentations,
initNeuroFluxGovernor,
initUnstableCircadianModulator,
} from "./data/AugmentationCreator";
import { Router } from "../ui/GameRoot";
2016-12-22 16:56:15 +01:00
export function AddToStaticAugmentations(aug: Augmentation): void {
2022-03-30 13:17:24 +02:00
const name = aug.name;
StaticAugmentations[name] = aug;
}
2021-09-05 01:09:30 +02:00
function createAugmentations(): void {
[
initNeuroFluxGovernor(),
initUnstableCircadianModulator(),
2022-04-04 13:50:01 +02:00
...initGeneralAugmentations(),
2022-04-22 21:30:49 +02:00
...initSoAAugmentations(),
2022-04-04 13:50:01 +02:00
...(factionExists(FactionNames.Bladeburners) ? initBladeburnerAugmentations() : []),
...(factionExists(FactionNames.ChurchOfTheMachineGod) ? initChurchOfTheMachineGodAugmentations() : []),
].map(resetAugmentation);
2021-09-05 01:09:30 +02:00
}
2017-08-13 07:01:33 +02:00
function resetFactionAugmentations(): void {
2022-01-16 01:45:03 +01:00
for (const name of Object.keys(Factions)) {
2021-09-05 01:09:30 +02:00
if (Factions.hasOwnProperty(name)) {
Factions[name].augmentations = [];
}
}
}
2021-09-05 01:09:30 +02:00
function initAugmentations(): void {
resetFactionAugmentations();
clearObject(StaticAugmentations);
createAugmentations();
Player.reapplyAllAugmentations();
}
2022-03-19 05:15:24 +01:00
export function getBaseAugmentationPriceMultiplier(): number {
2022-04-14 07:22:50 +02:00
return CONSTANTS.MultipleAugMultiplier * [1, 0.96, 0.94, 0.93][Player.sourceFileLvl(11)];
2022-03-22 16:02:15 +01:00
}
export function getGenericAugmentationPriceMultiplier(): number {
return Math.pow(getBaseAugmentationPriceMultiplier(), Player.queuedAugmentations.length);
}
2018-05-02 19:38:11 +02:00
//Resets an Augmentation during (re-initizliation)
2022-03-19 05:15:24 +01:00
function resetAugmentation(aug: Augmentation): void {
aug.addToFactions(aug.factions);
const name = aug.name;
2021-09-05 01:09:30 +02:00
if (augmentationExists(name)) {
delete StaticAugmentations[name];
2021-09-05 01:09:30 +02:00
}
AddToStaticAugmentations(aug);
2016-12-22 16:56:15 +01:00
}
2021-09-24 22:02:38 +02:00
function applyAugmentation(aug: IPlayerOwnedAugmentation, reapply = false): void {
const staticAugmentation = StaticAugmentations[aug.name];
2019-01-17 06:15:00 +01:00
2021-09-05 01:09:30 +02:00
// Apply multipliers
for (const mult of Object.keys(staticAugmentation.mults)) {
const v = Player.getMult(mult) * staticAugmentation.mults[mult];
2021-09-24 22:02:38 +02:00
Player.setMult(mult, v);
2021-09-05 01:09:30 +02:00
}
2022-04-07 07:48:39 +02:00
// Special logic for Congruity Implant
2022-04-07 18:25:12 +02:00
if (aug.name === AugmentationNames.CongruityImplant && !reapply) {
2022-04-07 07:48:39 +02:00
Player.entropy = 0;
2022-04-07 18:45:21 +02:00
Player.applyEntropy(Player.entropy);
2022-04-07 07:48:39 +02:00
}
2022-05-05 03:07:12 +02:00
// Special logic for NeuroFlux Governor
const ownedNfg = Player.augmentations.find((pAug) => pAug.name === AugmentationNames.NeuroFluxGovernor);
if (aug.name === AugmentationNames.NeuroFluxGovernor && !reapply && ownedNfg) {
ownedNfg.level = aug.level;
return;
}
2021-09-05 01:09:30 +02:00
// Push onto Player's Augmentation list
if (!reapply) {
2021-09-25 07:26:03 +02:00
const ownedAug = new PlayerOwnedAugmentation(aug.name);
2022-05-05 03:07:12 +02:00
2021-09-05 01:09:30 +02:00
Player.augmentations.push(ownedAug);
}
}
function installAugmentations(force?: boolean): boolean {
if (Player.queuedAugmentations.length == 0 && !force) {
2021-09-05 01:09:30 +02:00
dialogBoxCreate("You have not purchased any Augmentations to install!");
return false;
}
let augmentationList = "";
let nfgIndex = -1;
for (let i = Player.queuedAugmentations.length - 1; i >= 0; i--) {
2021-09-09 05:47:34 +02:00
if (Player.queuedAugmentations[i].name === AugmentationNames.NeuroFluxGovernor) {
2021-09-05 01:09:30 +02:00
nfgIndex = i;
break;
}
}
for (let i = 0; i < Player.queuedAugmentations.length; ++i) {
const ownedAug = Player.queuedAugmentations[i];
const aug = StaticAugmentations[ownedAug.name];
2021-09-05 01:09:30 +02:00
if (aug == null) {
console.error(`Invalid augmentation: ${ownedAug.name}`);
continue;
}
applyAugmentation(Player.queuedAugmentations[i]);
2021-09-09 05:47:34 +02:00
if (ownedAug.name === AugmentationNames.NeuroFluxGovernor && i !== nfgIndex) continue;
2021-09-05 01:09:30 +02:00
let level = "";
if (ownedAug.name === AugmentationNames.NeuroFluxGovernor) {
level = ` - ${ownedAug.level}`;
}
augmentationList += aug.name + level + "<br>";
}
Player.queuedAugmentations = [];
if (!force) {
dialogBoxCreate(
"You slowly drift to sleep as scientists put you under in order " +
"to install the following Augmentations:<br>" +
augmentationList +
"<br>You wake up in your home...you feel different...",
);
}
2021-09-05 01:09:30 +02:00
prestigeAugmentation();
Router.toTerminal();
2021-09-25 08:36:49 +02:00
return true;
}
2021-09-25 08:36:49 +02:00
function augmentationExists(name: string): boolean {
return StaticAugmentations.hasOwnProperty(name);
}
2021-09-24 22:02:38 +02:00
export function isRepeatableAug(aug: Augmentation): boolean {
2021-09-05 01:09:30 +02:00
const augName = aug instanceof Augmentation ? aug.name : aug;
2022-03-01 20:37:47 +01:00
return augName === AugmentationNames.NeuroFluxGovernor;
}
2018-03-27 02:46:21 +02:00
2021-09-09 05:47:34 +02:00
export { installAugmentations, initAugmentations, applyAugmentation, augmentationExists };