2022-07-10 07:37:36 +02:00
|
|
|
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";
|
2022-07-12 07:54:19 +02:00
|
|
|
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
|
2022-07-10 07:37:36 +02:00
|
|
|
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;
|
|
|
|
player: IPlayer;
|
2022-07-12 07:54:19 +02:00
|
|
|
singularity: boolean;
|
2022-07-10 07:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class GraftingWork extends Work {
|
|
|
|
augmentation: string;
|
|
|
|
unitCompleted: number;
|
|
|
|
|
|
|
|
constructor(params?: GraftingWorkParams) {
|
2022-07-12 07:54:19 +02:00
|
|
|
super(WorkType.GRAFTING, params?.singularity ?? true);
|
2022-07-10 07:37:36 +02:00
|
|
|
this.unitCompleted = 0;
|
|
|
|
this.augmentation = params?.augmentation ?? AugmentationNames.Targeting1;
|
2022-07-12 07:54:19 +02:00
|
|
|
|
2022-07-10 07:37:36 +02:00
|
|
|
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.
|
|
|
|
*/
|
2022-07-12 07:54:19 +02:00
|
|
|
toJSON(): IReviverValue {
|
2022-07-10 07:37:36 +02:00
|
|
|
return Generic_toJSON("GraftingWork", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiatizes a GraftingWork object from a JSON save state.
|
|
|
|
*/
|
2022-07-12 07:54:19 +02:00
|
|
|
static fromJSON(value: IReviverValue): GraftingWork {
|
2022-07-10 07:37:36 +02:00
|
|
|
return Generic_fromJSON(GraftingWork, value.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.GraftingWork = GraftingWork;
|