2023-07-11 15:23:17 +02:00
|
|
|
import type { CompanyPosition } from "./CompanyPosition";
|
|
|
|
|
2023-11-02 15:20:24 +01:00
|
|
|
import { CompanyName, JobName, FactionName } from "@enums";
|
2022-01-15 23:52:50 +01:00
|
|
|
import { favorToRep, repToFavor } from "../Faction/formulas/favor";
|
2019-03-29 08:12:41 +01:00
|
|
|
|
2023-04-07 06:33:51 +02:00
|
|
|
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../utils/JSONReviver";
|
2019-03-29 08:12:41 +01:00
|
|
|
|
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;
|
2023-11-02 15:20:24 +01:00
|
|
|
relatedFaction?: FactionName | undefined;
|
2018-11-16 02:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 = "";
|
2023-11-02 15:20:24 +01:00
|
|
|
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
|
|
|
|
2022-10-04 12:40:10 +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;
|
2023-11-02 15:20:24 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2019-03-29 08:12:41 +01: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
|
|
|
}
|
|
|
|
|
2022-10-04 12:40:10 +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
|
|
|
|
2023-12-18 13:23:47 +01:00
|
|
|
// Only these 2 keys are relevant to the save file
|
2023-07-11 15:23:17 +02:00
|
|
|
static includedKeys = ["favor", "playerReputation"] as const;
|
2018-11-16 02:28:23 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 06:33:51 +02:00
|
|
|
constructorsForReviver.Company = Company;
|