bitburner-src/src/Company/Company.ts

87 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-07-11 15:23:17 +02:00
import type { CompanyPosition } from "./CompanyPosition";
import { CompanyName, JobName, FactionName } from "@enums";
2024-05-28 21:04:16 +02:00
import { MaxFavor, calculateFavorAfterResetting } from "../Faction/formulas/favor";
import { clampNumber } from "../utils/helpers/clampNumber";
2023-07-11 15:23:17 +02:00
export interface CompanyCtorParams {
name: CompanyName;
info?: string;
companyPositions: JobName[];
2021-09-05 01:09:30 +02:00
expMultiplier: number;
salaryMultiplier: number;
jobStatReqOffset: number;
relatedFaction?: FactionName | undefined;
}
export class Company {
2023-07-11 15:23:17 +02:00
// Static info, initialized once at game load.
2021-09-05 01:09:30 +02:00
2023-07-11 15:23:17 +02:00
name = CompanyName.NoodleBar;
info = "";
relatedFaction: FactionName | undefined;
2021-09-05 01:09:30 +02:00
2023-07-11 15:23:17 +02:00
companyPositions = new Set<JobName>();
2021-09-05 01:09:30 +02:00
/** Company-specific multiplier for earnings */
2023-07-11 15:23:17 +02:00
expMultiplier = 1;
salaryMultiplier = 1;
2021-09-05 01:09:30 +02:00
/**
* The additional levels of stats you need to quality for a job
* in this company.
*
* For example, the base stat requirement for an intern position is 1.
* But if a company has a offset of 200, then you would need stat(s) of 201
*/
2023-07-11 15:23:17 +02:00
jobStatReqOffset = 0;
2021-09-05 01:09:30 +02:00
2023-07-11 15:23:17 +02:00
// Dynamic info, loaded from save and updated during game.
playerReputation = 0;
2024-05-28 21:04:16 +02:00
#favor = 0;
2021-09-05 01:09:30 +02:00
constructor(p: CompanyCtorParams) {
2021-09-05 01:09:30 +02:00
this.name = p.name;
2023-07-11 15:23:17 +02:00
if (p.info) this.info = p.info;
p.companyPositions.forEach((jobName) => this.companyPositions.add(jobName));
2021-09-05 01:09:30 +02:00
this.expMultiplier = p.expMultiplier;
this.salaryMultiplier = p.salaryMultiplier;
this.jobStatReqOffset = p.jobStatReqOffset;
if (p.relatedFaction) this.relatedFaction = p.relatedFaction;
2021-09-05 01:09:30 +02:00
}
2024-05-28 21:04:16 +02:00
get favor() {
return this.#favor;
}
/**
* There is no setter for this.#favor. This is intentional. Performing arithmetic operations on `favor` may lead to
* the overflow error of `playerReputation`, so anything that wants to change `favor` must explicitly do that through
* `setFavor`.
*
* @param value
*/
setFavor(value: number) {
if (Number.isNaN(value)) {
this.#favor = 0;
return;
}
this.#favor = clampNumber(value, 0, MaxFavor);
}
2023-07-11 15:23:17 +02:00
hasPosition(pos: CompanyPosition | JobName): boolean {
return this.companyPositions.has(typeof pos === "string" ? pos : pos.name);
2021-09-05 01:09:30 +02:00
}
2023-07-11 15:23:17 +02:00
prestigeAugmentation(): void {
2024-05-28 21:04:16 +02:00
this.setFavor(calculateFavorAfterResetting(this.favor, this.playerReputation));
2023-07-11 15:23:17 +02:00
this.playerReputation = 0;
}
prestigeSourceFile() {
2024-05-28 21:04:16 +02:00
this.setFavor(0);
2023-07-11 15:23:17 +02:00
this.playerReputation = 0;
2021-09-05 01:09:30 +02:00
}
}