mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 19:14:32 +02:00
Implement basic crafting functionality
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user