bitburner-src/src/Company/Company.ts

129 lines
3.6 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";
2022-01-15 23:52:50 +01:00
import { favorToRep, repToFavor } from "../Faction/formulas/favor";
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../utils/JSONReviver";
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;
favor = 0;
2021-09-05 01:09:30 +02:00
2023-07-11 15:23:17 +02:00
constructor(p?: CompanyCtorParams) {
if (!p) return;
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
}
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
}
hasAgentPositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.agent0);
2021-09-05 01:09:30 +02:00
}
hasBusinessConsultantPositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.businessConsult0);
2021-09-05 01:09:30 +02:00
}
hasBusinessPositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.business0);
2021-09-05 01:09:30 +02:00
}
hasEmployeePositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.employee);
2021-09-05 01:09:30 +02:00
}
hasITPositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.IT0);
2021-09-05 01:09:30 +02:00
}
hasSecurityPositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.security0);
2021-09-05 01:09:30 +02:00
}
hasSoftwareConsultantPositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.softwareConsult0);
2021-09-05 01:09:30 +02:00
}
hasSoftwarePositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.software0);
2021-09-05 01:09:30 +02:00
}
hasWaiterPositions(): boolean {
2023-07-11 15:23:17 +02:00
return this.companyPositions.has(JobName.waiter);
2021-09-05 01:09:30 +02:00
}
2023-07-11 15:23:17 +02:00
prestigeAugmentation(): void {
if (this.favor == null) this.favor = 0;
2022-01-10 21:08:17 +01:00
this.favor += this.getFavorGain();
2023-07-11 15:23:17 +02:00
this.playerReputation = 0;
}
prestigeSourceFile() {
this.favor = 0;
this.playerReputation = 0;
2021-09-05 01:09:30 +02:00
}
2022-01-10 21:08:17 +01:00
getFavorGain(): number {
2023-07-11 15:23:17 +02:00
if (this.favor == null) this.favor = 0;
2022-01-10 21:08:17 +01:00
const storedRep = Math.max(0, favorToRep(this.favor));
const totalRep = storedRep + this.playerReputation;
const newFavor = repToFavor(totalRep);
return newFavor - this.favor;
2021-09-05 01:09:30 +02:00
}
/** Serialize the current object to a JSON save state. */
2022-07-15 01:00:10 +02:00
toJSON(): IReviverValue {
2023-07-11 15:23:17 +02:00
return Generic_toJSON("Company", this, Company.includedKeys);
2021-09-05 01:09:30 +02:00
}
2022-10-09 07:25:31 +02:00
/** Initializes a Company from a JSON save state. */
2022-07-15 01:00:10 +02:00
static fromJSON(value: IReviverValue): Company {
2023-07-11 15:23:17 +02:00
return Generic_fromJSON(Company, value.data, Company.includedKeys);
2021-09-05 01:09:30 +02:00
}
2023-07-11 15:23:17 +02:00
// Only these 3 keys are relevant to the save file
static includedKeys = ["favor", "playerReputation"] as const;
}
constructorsForReviver.Company = Company;