Implement basic crafting functionality

This commit is contained in:
nickofolas 2022-03-19 09:31:48 -05:00
parent 78f962318c
commit 4789455b9c
7 changed files with 118 additions and 1 deletions

@ -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",

@ -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 => {
<Typography variant="h6" sx={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap' }}>
<Construction sx={{ mr: 1 }} /> {selectedAug}
</Typography>
<Button sx={{ width: '100%' }}>
<Button
onClick={event => {
if (!event.isTrusted) return;
player.startCraftAugmentationWork(selectedAug, 15000);
player.startFocusing();
router.toWork();
}}
sx={{ width: '100%' }}
>
Craft Augmentation (<Typography color={Settings.theme.money}>$foo</Typography>)
</Button>
<Typography color={Settings.theme.info}>

@ -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;
}

@ -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;

@ -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}.<br>The augmentation has been grafted to you, but you feel slightly lightheaded.`)
applyAugmentation(Augmentations[augName]);
} else {
dialogBoxCreate(`You cancelled the crafting of ${augName}.<br>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();

@ -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);
}

@ -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 (
<Grid container direction="column" justifyContent="center" alignItems="center" style={{ minHeight: "100vh" }}>
<Grid item>
<Typography>
You are currently working on crafting {player.craftAugmentationName}.
<br /><br />
You have been working for {convertTimeMsToTimeElapsedString(player.timeWorked)}
<br /><br />
The augumentation if {((player.timeWorkedCraftAugmentation / player.timeNeededToCompleteWork) * 100).toFixed(2)}
% complete. <br />
If you cancel, your work will <b>not</b> be saved, and the money you spent will <b>not</b> be returned.
</Typography>
</Grid>
<Grid item>
<Button sx={{ mx: 2 }} onClick={cancel}>
Cancel work on creating program
</Button>
<Button onClick={unfocus}>Do something else simultaneously</Button>
</Grid>
</Grid>
)
}
if (!player.workType) router.toTerminal();
return <></>;