mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-10-23 10:13:13 +02:00
107 lines
3.5 KiB
TypeScript
107 lines
3.5 KiB
TypeScript
|
import React from "react";
|
||
|
import { CONSTANTS } from "../Constants";
|
||
|
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
||
|
import { GraftableAugmentations } from "../PersonObjects/Grafting/ui/GraftingRoot";
|
||
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
||
|
import { Work, WorkType } from "./Work";
|
||
|
import { graftingIntBonus } from "../PersonObjects/Grafting/GraftingHelpers";
|
||
|
import { applyAugmentation } from "../Augmentation/AugmentationHelpers";
|
||
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
||
|
import { Reviver, Generic_toJSON, Generic_fromJSON } from "../utils/JSONReviver";
|
||
|
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
|
||
|
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
|
||
|
|
||
|
export const isGraftingWork = (w: Work | null): w is GraftingWork => w !== null && w.type === WorkType.GRAFTING;
|
||
|
|
||
|
interface GraftingWorkParams {
|
||
|
augmentation: string;
|
||
|
singularity: boolean;
|
||
|
player: IPlayer;
|
||
|
}
|
||
|
|
||
|
export class GraftingWork extends Work {
|
||
|
augmentation: string;
|
||
|
singularity: boolean;
|
||
|
cyclesWorked: number;
|
||
|
unitCompleted: number;
|
||
|
|
||
|
constructor(params?: GraftingWorkParams) {
|
||
|
super(WorkType.GRAFTING);
|
||
|
this.cyclesWorked = 0;
|
||
|
this.unitCompleted = 0;
|
||
|
this.augmentation = params?.augmentation ?? AugmentationNames.Targeting1;
|
||
|
this.singularity = params?.singularity ?? false;
|
||
|
if (params?.player) params.player.loseMoney(GraftableAugmentations[this.augmentation].cost, "augmentations");
|
||
|
}
|
||
|
|
||
|
unitNeeded(): number {
|
||
|
return new GraftableAugmentation(StaticAugmentations[this.augmentation]).time;
|
||
|
}
|
||
|
|
||
|
process(player: IPlayer, cycles: number): boolean {
|
||
|
let focusBonus = 1;
|
||
|
if (!player.hasAugmentation(AugmentationNames.NeuroreceptorManager)) {
|
||
|
focusBonus = player.focus ? 1 : CONSTANTS.BaseFocusBonus;
|
||
|
}
|
||
|
|
||
|
this.cyclesWorked += cycles;
|
||
|
this.unitCompleted += CONSTANTS._idleSpeed * cycles * graftingIntBonus(player) * focusBonus;
|
||
|
|
||
|
return this.unitCompleted >= this.unitNeeded();
|
||
|
}
|
||
|
|
||
|
finish(player: IPlayer, cancelled: boolean): void {
|
||
|
const augName = this.augmentation;
|
||
|
if (!cancelled) {
|
||
|
applyAugmentation({ name: augName, level: 1 });
|
||
|
|
||
|
if (!player.hasAugmentation(AugmentationNames.CongruityImplant)) {
|
||
|
player.entropy += 1;
|
||
|
player.applyEntropy(player.entropy);
|
||
|
}
|
||
|
|
||
|
if (!this.singularity) {
|
||
|
dialogBoxCreate(
|
||
|
<>
|
||
|
You've finished grafting {augName}.<br />
|
||
|
The augmentation has been applied to your body{" "}
|
||
|
{player.hasAugmentation(AugmentationNames.CongruityImplant) ? "." : ", but you feel a bit off."}
|
||
|
</>,
|
||
|
);
|
||
|
}
|
||
|
} else if (cancelled && !this.singularity) {
|
||
|
dialogBoxCreate(
|
||
|
<>
|
||
|
You cancelled the grafting of {augName}.
|
||
|
<br />
|
||
|
Your money was not returned to you.
|
||
|
</>,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
// Intelligence gain
|
||
|
if (!cancelled) {
|
||
|
player.gainIntelligenceExp(
|
||
|
(CONSTANTS.IntelligenceGraftBaseExpGain * this.cyclesWorked * CONSTANTS._idleSpeed) / 10000,
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Serialize the current object to a JSON save state.
|
||
|
*/
|
||
|
toJSON(): any {
|
||
|
return Generic_toJSON("GraftingWork", this);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Initiatizes a GraftingWork object from a JSON save state.
|
||
|
*/
|
||
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||
|
static fromJSON(value: any): GraftingWork {
|
||
|
return Generic_fromJSON(GraftingWork, value.data);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Reviver.constructors.GraftingWork = GraftingWork;
|