bitburner-src/src/Work/CompanyWork.tsx

89 lines
2.8 KiB
TypeScript
Raw Normal View History

import React from "react";
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
2022-09-06 15:07:12 +02:00
import { Player } from "../Player";
import { Work, WorkType } from "./Work";
import { influenceStockThroughCompanyWork } from "../StockMarket/PlayerInfluencing";
import { LocationName } from "../Locations/data/LocationNames";
import { calculateCompanyWorkStats } from "./formulas/Company";
import { Companies } from "../Company/Companies";
2022-07-28 20:35:55 +02:00
import { applyWorkStats, scaleWorkStats, WorkStats } from "./WorkStats";
import { Company } from "../Company/Company";
import { dialogBoxCreate } from "../ui/React/DialogBox";
import { Reputation } from "../ui/React/Reputation";
2022-07-28 02:37:32 +02:00
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { CONSTANTS } from "../Constants";
interface CompanyWorkParams {
companyName: string;
singularity: boolean;
}
export const isCompanyWork = (w: Work | null): w is CompanyWork => w !== null && w.type === WorkType.COMPANY;
export class CompanyWork extends Work {
companyName: string;
constructor(params?: CompanyWorkParams) {
super(WorkType.COMPANY, params?.singularity ?? false);
this.companyName = params?.companyName ?? LocationName.NewTokyoNoodleBar;
}
getCompany(): Company {
const c = Companies[this.companyName];
if (!c) throw new Error(`Company not found: '${this.companyName}'`);
return c;
}
2022-09-06 15:07:12 +02:00
getGainRates(): WorkStats {
2022-07-28 02:37:32 +02:00
let focusBonus = 1;
2022-09-06 15:07:12 +02:00
if (!Player.hasAugmentation(AugmentationNames.NeuroreceptorManager, true)) {
focusBonus = Player.focus ? 1 : CONSTANTS.BaseFocusBonus;
2022-07-28 02:37:32 +02:00
}
2022-09-06 15:07:12 +02:00
return scaleWorkStats(calculateCompanyWorkStats(Player, this.getCompany()), focusBonus);
}
2022-09-06 15:07:12 +02:00
process(cycles: number): boolean {
this.cyclesWorked += cycles;
const company = this.getCompany();
2022-09-06 15:07:12 +02:00
const gains = this.getGainRates();
applyWorkStats(Player, gains, cycles, "work");
company.playerReputation += gains.reputation * cycles;
influenceStockThroughCompanyWork(company, gains.reputation, cycles);
return false;
}
finish(): void {
if (!this.singularity) {
dialogBoxCreate(
<>
You finished working for {this.companyName}
<br />
You have <Reputation reputation={this.getCompany().playerReputation} /> reputation with them.
</>,
);
}
}
2022-07-26 21:30:12 +02:00
APICopy(): Record<string, unknown> {
return {
type: this.type,
cyclesWorked: this.cyclesWorked,
companyName: this.companyName,
};
}
/**
* Serialize the current object to a JSON save state.
*/
toJSON(): IReviverValue {
return Generic_toJSON("CompanyWork", this);
}
/**
* Initiatizes a CompanyWork object from a JSON save state.
*/
static fromJSON(value: IReviverValue): CompanyWork {
return Generic_fromJSON(CompanyWork, value.data);
}
}
Reviver.constructors.CompanyWork = CompanyWork;