From 4789455b9c96d93401555f714a35cba386283cc6 Mon Sep 17 00:00:00 2001 From: nickofolas Date: Sat, 19 Mar 2022 09:31:48 -0500 Subject: [PATCH] Implement basic crafting functionality --- src/Constants.ts | 2 + .../Grafting/ui/GraftingRoot.tsx | 11 +++- src/PersonObjects/IPlayer.ts | 5 ++ src/PersonObjects/Player/PlayerObject.ts | 11 ++++ .../Player/PlayerObjectGeneralMethods.tsx | 56 +++++++++++++++++++ src/engine.tsx | 2 + src/ui/WorkInProgressRoot.tsx | 32 +++++++++++ 7 files changed, 118 insertions(+), 1 deletion(-) diff --git a/src/Constants.ts b/src/Constants.ts index febc03e46..9688f0416 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -71,6 +71,7 @@ export const CONSTANTS: { WorkTypeCreateProgram: string; WorkTypeStudyClass: string; WorkTypeCrime: string; + WorkTypeCraftAugmentation: string; ClassStudyComputerScience: string; ClassDataStructures: string; ClassNetworks: string; @@ -224,6 +225,7 @@ export const CONSTANTS: { WorkTypeCreateProgram: "Working on Create a Program", WorkTypeStudyClass: "Studying or Taking a class at university", WorkTypeCrime: "Committing a crime", + WorkTypeCraftAugmentation: "Crafting an Augmentation", ClassStudyComputerScience: "studying Computer Science", ClassDataStructures: "taking a Data Structures course", diff --git a/src/PersonObjects/Grafting/ui/GraftingRoot.tsx b/src/PersonObjects/Grafting/ui/GraftingRoot.tsx index 123098804..1f58b43d5 100644 --- a/src/PersonObjects/Grafting/ui/GraftingRoot.tsx +++ b/src/PersonObjects/Grafting/ui/GraftingRoot.tsx @@ -17,6 +17,7 @@ import { use } from "../../../ui/Context"; import { Augmentations } from "../../../Augmentation/Augmentations"; import { AugmentationNames } from "../../../Augmentation/data/AugmentationNames" import { Settings } from "../../../Settings/Settings"; +import { CONSTANTS } from "../../../Constants"; import { IPlayer } from "../../IPlayer"; @@ -74,7 +75,15 @@ export const GraftingRoot = (): React.ReactElement => { {selectedAug} - diff --git a/src/PersonObjects/IPlayer.ts b/src/PersonObjects/IPlayer.ts index 24470271e..1a9e41762 100644 --- a/src/PersonObjects/IPlayer.ts +++ b/src/PersonObjects/IPlayer.ts @@ -130,6 +130,8 @@ export interface IPlayer { factionWorkType: string; createProgramName: string; timeWorkedCreateProgram: number; + craftAugmentationName: string; + timeWorkedCraftAugmentation: number; crimeType: string; committingCrimeThruSingFn: boolean; singFnCrimeWorkerScript: WorkerScript | null; @@ -286,4 +288,7 @@ export interface IPlayer { setMult(name: string, mult: number): void; canAccessCotMG(): boolean; sourceFileLvl(n: number): number; + startCraftAugmentationWork(augmentationName: string, time: number): void; + craftAugmentationWork(numCycles: number): boolean; + finishCraftAugmentationWork(cancelled: boolean): string; } diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts index 4d1500ef1..dd5dbfc29 100644 --- a/src/PersonObjects/Player/PlayerObject.ts +++ b/src/PersonObjects/Player/PlayerObject.ts @@ -139,6 +139,8 @@ export class PlayerObject implements IPlayer { factionWorkType: string; createProgramName: string; timeWorkedCreateProgram: number; + craftAugmentationName: string; + timeWorkedCraftAugmentation: number; crimeType: string; committingCrimeThruSingFn: boolean; singFnCrimeWorkerScript: WorkerScript | null; @@ -296,6 +298,9 @@ export class PlayerObject implements IPlayer { setMult: (name: string, mult: number) => void; canAccessCotMG: () => boolean; sourceFileLvl: (n: number) => number; + startCraftAugmentationWork: (augmentationName: string, time: number) => void; + craftAugmentationWork: (numCycles: number) => boolean; + finishCraftAugmentationWork: (cancelled: boolean) => string; constructor() { //Skills and stats @@ -419,6 +424,9 @@ export class PlayerObject implements IPlayer { this.createProgramName = ""; this.createProgramReqLvl = 0; + this.craftAugmentationName = ""; + this.timeWorkedCraftAugmentation = 0; + this.className = ""; this.crimeType = ""; @@ -541,6 +549,9 @@ export class PlayerObject implements IPlayer { this.startCreateProgramWork = generalMethods.startCreateProgramWork; this.createProgramWork = generalMethods.createProgramWork; this.finishCreateProgramWork = generalMethods.finishCreateProgramWork; + this.startCraftAugmentationWork = generalMethods.startCraftAugmentationWork; + this.craftAugmentationWork = generalMethods.craftAugmentationWork; + this.finishCraftAugmentationWork = generalMethods.finishCraftAugmentationWork; this.startClass = generalMethods.startClass; this.takeClass = generalMethods.takeClass; this.finishClass = generalMethods.finishClass; diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx index 238e2893f..bc90bcac1 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx @@ -528,10 +528,12 @@ export function resetWorkStatus(this: IPlayer, generalType?: string, group?: str this.timeWorked = 0; this.timeWorkedCreateProgram = 0; + this.timeWorkedCraftAugmentation = 0; this.currentWorkFactionName = ""; this.currentWorkFactionDescription = ""; this.createProgramName = ""; + this.craftAugmentationName = ""; this.className = ""; this.workType = ""; } @@ -608,6 +610,10 @@ export function process(this: IPlayer, router: IRouter, numCycles = 1): void { if (this.workPartTime(numCycles)) { router.toCity(); } + } else if (this.workType === CONSTANTS.WorkTypeCraftAugmentation) { + if (this.craftAugmentationWork(numCycles)) { + router.toGrafting(); + } } else if (this.work(numCycles)) { router.toCity(); } @@ -1331,6 +1337,56 @@ export function finishCreateProgramWork(this: IPlayer, cancelled: boolean): stri this.resetWorkStatus(); return "You've finished creating " + programName + "! The new program can be found on your home computer."; } + +export function startCraftAugmentationWork( + this: IPlayer, + augmentationName: string, + time: number, +): void { + this.resetWorkStatus() + this.isWorking = true; + this.workType = CONSTANTS.WorkTypeCraftAugmentation; + + this.timeNeededToCompleteWork = time; + this.craftAugmentationName = augmentationName; +} + +export function craftAugmentationWork(this: IPlayer, numCycles: number): boolean { + let focusBonus = 1; + if (!this.hasAugmentation(AugmentationNames.NeuroreceptorManager)) { + focusBonus = this.focus ? 1 : CONSTANTS.BaseFocusBonus; + } + + // TODO: formula logic here (focus bonus and stuff) + let skillMult = 1; + skillMult *= focusBonus; + + this.timeWorked += CONSTANTS._idleSpeed * numCycles; + this.timeWorkedCraftAugmentation += CONSTANTS._idleSpeed * numCycles * skillMult; + + if (this.timeWorkedCraftAugmentation >= this.timeNeededToCompleteWork) { + this.finishCraftAugmentationWork(false); + return true; + } + return false; +} + +export function finishCraftAugmentationWork(this: IPlayer, cancelled: boolean): string { + const augName = this.craftAugmentationName; + if (cancelled === false) { + dialogBoxCreate(`You've finished crafting ${augName}.
The augmentation has been grafted to you, but you feel slightly lightheaded.`) + + applyAugmentation(Augmentations[augName]); + } else { + dialogBoxCreate(`You cancelled the crafting of ${augName}.
Your money was not returned to you.`) + } + + // TODO: intelligence EXP stuff here later + this.isWorking = false; + this.resetWorkStatus(); + return `Crafting of ${augName} has ended.` +} + /* Studying/Taking Classes */ export function startClass(this: IPlayer, costMult: number, expMult: number, className: string): void { this.resetWorkStatus(); diff --git a/src/engine.tsx b/src/engine.tsx index 18689a08f..6464d3309 100644 --- a/src/engine.tsx +++ b/src/engine.tsx @@ -298,6 +298,8 @@ const Engine: { Player.commitCrime(numCyclesOffline); } else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) { Player.workPartTime(numCyclesOffline); + } else if (Player.workType === CONSTANTS.WorkTypeCraftAugmentation) { + Player.craftAugmentationWork(numCyclesOffline); } else { Player.work(numCyclesOffline); } diff --git a/src/ui/WorkInProgressRoot.tsx b/src/ui/WorkInProgressRoot.tsx index 7a4c1802a..810815ff1 100644 --- a/src/ui/WorkInProgressRoot.tsx +++ b/src/ui/WorkInProgressRoot.tsx @@ -494,6 +494,38 @@ export function WorkInProgressRoot(): React.ReactElement { ); } + if (player.craftAugmentationName !== "") { + function cancel(): void { + player.finishCraftAugmentationWork(true); + router.toTerminal(); + } + function unfocus(): void { + router.toTerminal(); + player.stopFocusing(); + } + return ( + + + + You are currently working on crafting {player.craftAugmentationName}. +

+ You have been working for {convertTimeMsToTimeElapsedString(player.timeWorked)} +

+ The augumentation if {((player.timeWorkedCraftAugmentation / player.timeNeededToCompleteWork) * 100).toFixed(2)} + % complete.
+ If you cancel, your work will not be saved, and the money you spent will not be returned. +
+
+ + + + +
+ ) + } + if (!player.workType) router.toTerminal(); return <>;