2022-07-07 23:28:23 +02:00
|
|
|
import React from "react";
|
2022-07-12 07:54:19 +02:00
|
|
|
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
|
2022-07-07 23:28:23 +02:00
|
|
|
import { CONSTANTS } from "../Constants";
|
2022-12-30 02:28:53 +01:00
|
|
|
import { LocationName } from "../Enums";
|
2022-07-07 23:28:23 +02:00
|
|
|
import { numeralWrapper } from "../ui/numeralFormat";
|
|
|
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
|
|
|
import { Money } from "../ui/React/Money";
|
|
|
|
import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
|
2022-10-10 00:42:14 +02:00
|
|
|
import { Player } from "@player";
|
2022-11-06 23:27:04 +01:00
|
|
|
import { calculateClassEarnings as calculateClassEarningsRate } from "./Formulas";
|
2022-07-07 23:28:23 +02:00
|
|
|
import { Work, WorkType } from "./Work";
|
|
|
|
import { applyWorkStats, newWorkStats, sumWorkStats, WorkStats } from "./WorkStats";
|
2022-12-30 02:28:53 +01:00
|
|
|
import { GymType, UniversityClassType } from "../Enums";
|
2022-11-20 14:37:11 +01:00
|
|
|
import { checkEnum, findEnumMember } from "../utils/helpers/enum";
|
2022-07-07 23:28:23 +02:00
|
|
|
|
2022-11-20 14:37:11 +01:00
|
|
|
export type ClassType = UniversityClassType | GymType;
|
2022-07-07 23:28:23 +02:00
|
|
|
|
|
|
|
export interface Class {
|
|
|
|
type: ClassType;
|
2022-11-20 14:37:11 +01:00
|
|
|
youAreCurrently: string;
|
2022-07-07 23:28:23 +02:00
|
|
|
earnings: WorkStats;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Classes: Record<ClassType, Class> = {
|
2022-11-20 14:37:11 +01:00
|
|
|
[UniversityClassType.computerScience]: {
|
|
|
|
type: UniversityClassType.computerScience,
|
|
|
|
youAreCurrently: `studying Computer Science`,
|
2022-07-07 23:28:23 +02:00
|
|
|
earnings: newWorkStats({ hackExp: 0.5, intExp: 0.01 }),
|
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[UniversityClassType.dataStructures]: {
|
|
|
|
type: UniversityClassType.dataStructures,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "taking a Data Structures course",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -40, hackExp: 1, intExp: 0.01 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[UniversityClassType.networks]: {
|
|
|
|
type: UniversityClassType.networks,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "taking a Networks course",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -80, hackExp: 2, intExp: 0.01 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[UniversityClassType.algorithms]: {
|
|
|
|
type: UniversityClassType.algorithms,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "taking an Algorithms course",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -320, hackExp: 4, intExp: 0.01 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[UniversityClassType.management]: {
|
|
|
|
type: UniversityClassType.management,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "taking a Management course",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -160, chaExp: 2, intExp: 0.01 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[UniversityClassType.leadership]: {
|
|
|
|
type: UniversityClassType.leadership,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "taking a Leadership course",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -320, chaExp: 4, intExp: 0.01 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[GymType.strength]: {
|
|
|
|
type: GymType.strength,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "training your strength at a gym",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -120, strExp: 1 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[GymType.defense]: {
|
|
|
|
type: GymType.defense,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "training your defense at a gym",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -120, defExp: 1 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[GymType.dexterity]: {
|
|
|
|
type: GymType.dexterity,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "training your dexterity at a gym",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -120, dexExp: 1 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
2022-11-20 14:37:11 +01:00
|
|
|
[GymType.agility]: {
|
|
|
|
type: GymType.agility,
|
2022-07-07 23:28:23 +02:00
|
|
|
youAreCurrently: "training your agility at a gym",
|
2022-11-20 14:37:11 +01:00
|
|
|
earnings: newWorkStats({ money: -120, agiExp: 1 }),
|
2022-07-07 23:28:23 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ClassWorkParams {
|
|
|
|
classType: ClassType;
|
|
|
|
location: LocationName;
|
|
|
|
singularity: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const isClassWork = (w: Work | null): w is ClassWork => w !== null && w.type === WorkType.CLASS;
|
|
|
|
|
|
|
|
export class ClassWork extends Work {
|
|
|
|
classType: ClassType;
|
|
|
|
location: LocationName;
|
|
|
|
earnings = newWorkStats();
|
|
|
|
|
|
|
|
constructor(params?: ClassWorkParams) {
|
2022-07-12 07:54:19 +02:00
|
|
|
super(WorkType.CLASS, params?.singularity ?? true);
|
2022-11-20 14:37:11 +01:00
|
|
|
this.classType = params?.classType ?? UniversityClassType.computerScience;
|
2022-07-07 23:28:23 +02:00
|
|
|
this.location = params?.location ?? LocationName.Sector12RothmanUniversity;
|
|
|
|
}
|
|
|
|
|
|
|
|
isGym(): boolean {
|
2022-11-20 14:37:11 +01:00
|
|
|
return checkEnum(GymType, this.classType);
|
2022-07-07 23:28:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getClass(): Class {
|
|
|
|
return Classes[this.classType];
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
calculateRates(): WorkStats {
|
|
|
|
return calculateClassEarningsRate(Player, this.classType, this.location);
|
2022-07-07 23:28:23 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
process(cycles: number): boolean {
|
2022-07-07 23:28:23 +02:00
|
|
|
this.cyclesWorked += cycles;
|
2022-09-06 15:07:12 +02:00
|
|
|
const rate = this.calculateRates();
|
|
|
|
const earnings = applyWorkStats(Player, rate, cycles, "class");
|
2022-07-07 23:28:23 +02:00
|
|
|
this.earnings = sumWorkStats(this.earnings, earnings);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
finish(): void {
|
|
|
|
if (!this.singularity) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
|
|
|
After {this.getClass().youAreCurrently} for{" "}
|
|
|
|
{convertTimeMsToTimeElapsedString(this.cyclesWorked * CONSTANTS._idleSpeed)}, <br />
|
|
|
|
you spent a total of <Money money={-this.earnings.money} />. <br />
|
|
|
|
<br />
|
|
|
|
You earned a total of: <br />
|
|
|
|
{numeralWrapper.formatExp(this.earnings.hackExp)} hacking exp <br />
|
|
|
|
{numeralWrapper.formatExp(this.earnings.strExp)} strength exp <br />
|
|
|
|
{numeralWrapper.formatExp(this.earnings.defExp)} defense exp <br />
|
|
|
|
{numeralWrapper.formatExp(this.earnings.dexExp)} dexterity exp <br />
|
|
|
|
{numeralWrapper.formatExp(this.earnings.agiExp)} agility exp <br />
|
|
|
|
{numeralWrapper.formatExp(this.earnings.chaExp)} charisma exp
|
|
|
|
<br />
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 21:30:12 +02:00
|
|
|
APICopy(): Record<string, unknown> {
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
cyclesWorked: this.cyclesWorked,
|
|
|
|
classType: this.classType,
|
|
|
|
location: this.location,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Serialize the current object to a JSON save state. */
|
2022-07-12 07:54:19 +02:00
|
|
|
toJSON(): IReviverValue {
|
2022-07-07 23:28:23 +02:00
|
|
|
return Generic_toJSON("ClassWork", this);
|
|
|
|
}
|
|
|
|
|
2022-10-09 07:25:31 +02:00
|
|
|
/** Initializes a ClassWork object from a JSON save state. */
|
2022-07-12 07:54:19 +02:00
|
|
|
static fromJSON(value: IReviverValue): ClassWork {
|
2022-11-20 14:37:11 +01:00
|
|
|
const classWork = Generic_fromJSON(ClassWork, value.data);
|
|
|
|
classWork.classType =
|
|
|
|
findEnumMember(UniversityClassType, classWork.classType) ??
|
|
|
|
findEnumMember(GymType, classWork.classType) ??
|
|
|
|
UniversityClassType.computerScience;
|
|
|
|
return classWork;
|
2022-07-07 23:28:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.ClassWork = ClassWork;
|