bitburner-src/src/Augmentation/AugmentationHelpers.tsx

202 lines
6.6 KiB
TypeScript
Raw Normal View History

import { Augmentation } from "./Augmentation";
import { Augmentations } from "./Augmentations";
2021-09-24 22:02:38 +02:00
import { PlayerOwnedAugmentation, IPlayerOwnedAugmentation } from "./PlayerOwnedAugmentation";
import { AugmentationNames } from "./data/AugmentationNames";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../Constants";
import { Factions, factionExists } from "../Faction/Factions";
import { Player } from "../Player";
import { prestigeAugmentation } from "../Prestige";
2021-08-15 08:14:07 +02:00
import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
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 {
bladeburnerAugmentations,
churchOfTheMachineGodAugmentations,
generalAugmentations,
initNeuroFluxGovernor,
initUnstableCircadianModulator,
} from "./AugmentationCreator";
export function AddToAugmentations(aug: Augmentation): void {
2021-09-24 22:02:38 +02:00
const name = aug.name;
2021-09-05 01:09:30 +02:00
Augmentations[name] = aug;
2016-12-22 16:56:15 +01:00
}
export function getNextNeuroFluxLevel(): number {
// Get current Neuroflux level based on Player's augmentations
2021-09-05 01:09:30 +02:00
let currLevel = 0;
for (let i = 0; i < Player.augmentations.length; ++i) {
if (Player.augmentations[i].name === AugmentationNames.NeuroFluxGovernor) {
currLevel = Player.augmentations[i].level;
}
}
// Account for purchased but uninstalled Augmentations
2021-09-05 01:09:30 +02:00
for (let i = 0; i < Player.queuedAugmentations.length; ++i) {
if (Player.queuedAugmentations[i].name == AugmentationNames.NeuroFluxGovernor) {
++currLevel;
2021-09-05 01:09:30 +02:00
}
}
return currLevel + 1;
}
2021-09-05 01:09:30 +02:00
function createAugmentations(): void {
[
initNeuroFluxGovernor(),
initUnstableCircadianModulator(),
...generalAugmentations,
...(factionExists(FactionNames.Bladeburners) ? bladeburnerAugmentations : []),
...(factionExists(FactionNames.ChurchOfTheMachineGod) ? churchOfTheMachineGodAugmentations : []),
].map(resetAugmentation);
}
2022-03-19 19:29:20 +01:00
function resetFactionAugmentations(): void {
for (const name of Object.keys(Factions)) {
if (Factions.hasOwnProperty(name)) {
Factions[name].augmentations = [];
}
2021-09-05 01:09:30 +02:00
}
}
2021-09-05 01:09:30 +02:00
function initAugmentations(): void {
resetFactionAugmentations();
clearObject(Augmentations);
createAugmentations();
updateAugmentationCosts();
Player.reapplyAllAugmentations();
}
2021-09-25 23:21:50 +02:00
function getBaseAugmentationPriceMultiplier(): number {
return CONSTANTS.MultipleAugMultiplier * [1, 0.96, 0.94, 0.93][SourceFileFlags[11]];
}
export function getGenericAugmentationPriceMultiplier(): number {
return Math.pow(getBaseAugmentationPriceMultiplier(), Player.queuedAugmentations.length);
}
2022-03-19 19:29:20 +01:00
function updateNeuroFluxGovernorCosts(neuroFluxGovernorAugmentation: Augmentation): void {
let nextLevel = getNextNeuroFluxLevel();
--nextLevel;
const multiplier = Math.pow(CONSTANTS.NeuroFluxGovernorLevelMult, nextLevel);
neuroFluxGovernorAugmentation.baseRepRequirement *= multiplier * BitNodeMultipliers.AugmentationRepCost;
neuroFluxGovernorAugmentation.baseCost *= multiplier * BitNodeMultipliers.AugmentationMoneyCost;
for (let i = 0; i < Player.queuedAugmentations.length - 1; ++i) {
neuroFluxGovernorAugmentation.baseCost *= getBaseAugmentationPriceMultiplier();
}
}
export function updateAugmentationCosts(): void {
2022-01-16 01:45:03 +01:00
for (const name of Object.keys(Augmentations)) {
2021-09-05 01:09:30 +02:00
if (Augmentations.hasOwnProperty(name)) {
const augmentationToUpdate = Augmentations[name];
if (augmentationToUpdate.name === AugmentationNames.NeuroFluxGovernor) {
updateNeuroFluxGovernorCosts(augmentationToUpdate);
} else {
2022-03-31 16:45:52 +02:00
augmentationToUpdate.baseCost =
augmentationToUpdate.startingCost *
getGenericAugmentationPriceMultiplier() *
BitNodeMultipliers.AugmentationMoneyCost;
}
2021-09-05 01:09:30 +02:00
}
}
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 Augmentations[name];
}
2022-03-19 05:15:24 +01:00
AddToAugmentations(aug);
2016-12-22 16:56:15 +01:00
}
2021-09-24 22:02:38 +02:00
function applyAugmentation(aug: IPlayerOwnedAugmentation, reapply = false): void {
2021-09-05 01:09:30 +02:00
Augmentations[aug.name].owned = true;
2021-09-05 01:09:30 +02:00
const augObj = Augmentations[aug.name];
2019-01-17 06:15:00 +01:00
2021-09-05 01:09:30 +02:00
// Apply multipliers
2022-01-16 01:45:03 +01:00
for (const mult of Object.keys(augObj.mults)) {
2021-09-24 22:02:38 +02:00
const v = Player.getMult(mult) * augObj.mults[mult];
Player.setMult(mult, v);
2021-09-05 01:09:30 +02:00
}
2021-09-05 01:09:30 +02:00
// Special logic for NeuroFlux Governor
if (aug.name === AugmentationNames.NeuroFluxGovernor) {
if (!reapply) {
Augmentations[aug.name].level = aug.level;
for (let i = 0; i < Player.augmentations.length; ++i) {
2021-09-09 05:47:34 +02:00
if (Player.augmentations[i].name == AugmentationNames.NeuroFluxGovernor) {
2021-09-05 01:09:30 +02:00
Player.augmentations[i].level = aug.level;
return;
// break;
}
2021-09-05 01:09:30 +02:00
}
}
2021-09-05 01:09:30 +02:00
}
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);
2021-09-05 01:09:30 +02:00
Player.augmentations.push(ownedAug);
}
}
2021-09-25 08:36:49 +02:00
function installAugmentations(): boolean {
2021-09-05 01:09:30 +02:00
if (Player.queuedAugmentations.length == 0) {
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 = Augmentations[ownedAug.name];
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 = [];
dialogBoxCreate(
"You slowly drift to sleep as scientists put you under in order " +
2022-03-21 05:30:11 +01:00
"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();
2021-09-25 08:36:49 +02:00
return true;
}
2021-09-25 08:36:49 +02:00
function augmentationExists(name: string): boolean {
2021-09-05 01:09:30 +02:00
return Augmentations.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 };