2018-11-16 02:28:23 +01:00
|
|
|
import { CompanyPosition } from "./CompanyPosition";
|
2022-12-30 02:28:53 +01:00
|
|
|
import * as posNames from "./data/JobTracks";
|
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
|
|
|
|
2018-11-16 02:28:23 +01:00
|
|
|
export interface IConstructorParams {
|
2021-09-05 01:09:30 +02:00
|
|
|
name: string;
|
|
|
|
info: string;
|
2022-10-03 18:12:16 +02:00
|
|
|
companyPositions: Record<string, boolean>;
|
2021-09-05 01:09:30 +02:00
|
|
|
expMultiplier: number;
|
|
|
|
salaryMultiplier: number;
|
|
|
|
jobStatReqOffset: number;
|
2021-09-22 09:09:37 +02:00
|
|
|
isMegacorp?: boolean;
|
2018-11-16 02:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const DefaultConstructorParams: IConstructorParams = {
|
2021-09-05 01:09:30 +02:00
|
|
|
name: "",
|
|
|
|
info: "",
|
|
|
|
companyPositions: {},
|
|
|
|
expMultiplier: 1,
|
|
|
|
salaryMultiplier: 1,
|
|
|
|
jobStatReqOffset: 0,
|
|
|
|
};
|
2018-11-16 02:28:23 +01:00
|
|
|
|
|
|
|
export class Company {
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Company name */
|
2021-09-05 01:09:30 +02:00
|
|
|
name: string;
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Description and general information about company */
|
2021-09-05 01:09:30 +02:00
|
|
|
info: string;
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Has faction associated. */
|
2021-09-22 09:09:37 +02:00
|
|
|
isMegacorp: boolean;
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
/**
|
|
|
|
* Object that holds all available positions in this Company.
|
|
|
|
* Position names are held in keys.
|
|
|
|
* The values for the keys don't matter, but we'll make them booleans
|
|
|
|
*
|
|
|
|
* Must match names of Company Positions, defined in data/companypositionnames.ts
|
|
|
|
*/
|
2022-10-03 18:12:16 +02:00
|
|
|
companyPositions: Record<string, boolean>;
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Company-specific multiplier for earnings */
|
2021-09-05 01:09:30 +02:00
|
|
|
expMultiplier: number;
|
|
|
|
salaryMultiplier: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
jobStatReqOffset: number;
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Properties to track the player's progress in this company */
|
2021-09-05 01:09:30 +02:00
|
|
|
isPlayerEmployed: boolean;
|
|
|
|
playerReputation: number;
|
|
|
|
favor: number;
|
|
|
|
|
|
|
|
constructor(p: IConstructorParams = DefaultConstructorParams) {
|
|
|
|
this.name = p.name;
|
|
|
|
this.info = p.info;
|
|
|
|
this.companyPositions = p.companyPositions;
|
|
|
|
this.expMultiplier = p.expMultiplier;
|
|
|
|
this.salaryMultiplier = p.salaryMultiplier;
|
|
|
|
this.jobStatReqOffset = p.jobStatReqOffset;
|
|
|
|
|
|
|
|
this.isPlayerEmployed = false;
|
|
|
|
this.playerReputation = 1;
|
|
|
|
this.favor = 0;
|
2021-09-22 09:09:37 +02:00
|
|
|
this.isMegacorp = false;
|
|
|
|
if (p.isMegacorp) this.isMegacorp = true;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasPosition(pos: CompanyPosition | string): boolean {
|
2022-09-27 21:14:34 +02:00
|
|
|
return this.companyPositions[typeof pos === "string" ? pos : pos.name] != null;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasAgentPositions(): boolean {
|
|
|
|
return this.companyPositions[posNames.AgentCompanyPositions[0]] != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasBusinessConsultantPositions(): boolean {
|
2021-09-09 05:47:34 +02:00
|
|
|
return this.companyPositions[posNames.BusinessConsultantCompanyPositions[0]] != null;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasBusinessPositions(): boolean {
|
|
|
|
return this.companyPositions[posNames.BusinessCompanyPositions[0]] != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasEmployeePositions(): boolean {
|
|
|
|
return this.companyPositions[posNames.MiscCompanyPositions[1]] != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasITPositions(): boolean {
|
|
|
|
return this.companyPositions[posNames.ITCompanyPositions[0]] != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasSecurityPositions(): boolean {
|
|
|
|
return this.companyPositions[posNames.SecurityCompanyPositions[2]] != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasSoftwareConsultantPositions(): boolean {
|
2021-09-09 05:47:34 +02:00
|
|
|
return this.companyPositions[posNames.SoftwareConsultantCompanyPositions[0]] != null;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasSoftwarePositions(): boolean {
|
|
|
|
return this.companyPositions[posNames.SoftwareCompanyPositions[0]] != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasWaiterPositions(): boolean {
|
|
|
|
return this.companyPositions[posNames.MiscCompanyPositions[0]] != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
gainFavor(): void {
|
|
|
|
if (this.favor == null) {
|
|
|
|
this.favor = 0;
|
2019-03-29 08:12:41 +01:00
|
|
|
}
|
2022-01-10 21:08:17 +01:00
|
|
|
this.favor += this.getFavorGain();
|
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 {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (this.favor == null) {
|
|
|
|
this.favor = 0;
|
2018-11-16 02:28:23 +01:00
|
|
|
}
|
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 {
|
2021-09-05 01:09:30 +02:00
|
|
|
return Generic_toJSON("Company", this);
|
|
|
|
}
|
|
|
|
|
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 {
|
2021-09-05 01:09:30 +02:00
|
|
|
return Generic_fromJSON(Company, value.data);
|
|
|
|
}
|
2018-11-16 02:28:23 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 06:33:51 +02:00
|
|
|
constructorsForReviver.Company = Company;
|