2022-07-12 07:54:19 +02:00
|
|
|
import React from "react";
|
|
|
|
import { Work, WorkType } from "./Work";
|
|
|
|
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
|
2022-10-10 00:42:14 +02:00
|
|
|
import { Player } from "@player";
|
2022-07-12 07:54:19 +02:00
|
|
|
import { FactionNames } from "../Faction/data/FactionNames";
|
|
|
|
import { Factions } from "../Faction/Factions";
|
|
|
|
import { Faction } from "../Faction/Faction";
|
2022-07-28 02:37:32 +02:00
|
|
|
import { applyWorkStats, scaleWorkStats, WorkStats } from "./WorkStats";
|
2022-07-12 07:54:19 +02:00
|
|
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
|
|
|
import { Reputation } from "../ui/React/Reputation";
|
|
|
|
import { CONSTANTS } from "../Constants";
|
|
|
|
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
2022-11-06 23:27:04 +01:00
|
|
|
import { calculateFactionExp, calculateFactionRep } from "./Formulas";
|
2022-07-12 07:54:19 +02:00
|
|
|
import { FactionWorkType } from "./data/FactionWorkType";
|
|
|
|
|
|
|
|
interface FactionWorkParams {
|
|
|
|
singularity: boolean;
|
|
|
|
factionWorkType: FactionWorkType;
|
|
|
|
faction: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const isFactionWork = (w: Work | null): w is FactionWork => w !== null && w.type === WorkType.FACTION;
|
|
|
|
|
|
|
|
export class FactionWork extends Work {
|
|
|
|
factionWorkType: FactionWorkType;
|
|
|
|
factionName: string;
|
|
|
|
|
|
|
|
constructor(params?: FactionWorkParams) {
|
|
|
|
super(WorkType.FACTION, params?.singularity ?? true);
|
|
|
|
this.factionWorkType = params?.factionWorkType ?? FactionWorkType.HACKING;
|
|
|
|
this.factionName = params?.faction ?? FactionNames.Sector12;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFaction(): Faction {
|
|
|
|
const f = Factions[this.factionName];
|
|
|
|
if (!f) throw new Error(`Faction work started with invalid / unknown faction: '${this.factionName}'`);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
getReputationRate(): number {
|
2022-07-12 07:54:19 +02:00
|
|
|
let focusBonus = 1;
|
2022-09-06 15:07:12 +02:00
|
|
|
if (!Player.hasAugmentation(AugmentationNames.NeuroreceptorManager, true)) {
|
|
|
|
focusBonus = Player.focus ? 1 : CONSTANTS.BaseFocusBonus;
|
2022-07-12 07:54:19 +02:00
|
|
|
}
|
2022-09-06 15:07:12 +02:00
|
|
|
return calculateFactionRep(Player, this.factionWorkType, this.getFaction().favor) * focusBonus;
|
2022-07-12 07:54:19 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
getExpRates(): WorkStats {
|
2022-07-28 02:37:32 +02:00
|
|
|
let focusBonus = 1;
|
2022-09-06 15:07:12 +02:00
|
|
|
if (!Player.hasAugmentation(AugmentationNames.NeuroreceptorManager, true)) {
|
|
|
|
focusBonus = Player.focus ? 1 : CONSTANTS.BaseFocusBonus;
|
2022-07-28 02:37:32 +02:00
|
|
|
}
|
2022-09-06 15:07:12 +02:00
|
|
|
const rate = calculateFactionExp(Player, this.factionWorkType);
|
2022-07-28 02:37:32 +02:00
|
|
|
return scaleWorkStats(rate, focusBonus, false);
|
2022-07-12 07:54:19 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
process(cycles: number): boolean {
|
2022-07-12 07:54:19 +02:00
|
|
|
this.cyclesWorked += cycles;
|
2022-09-06 15:07:12 +02:00
|
|
|
this.getFaction().playerReputation += this.getReputationRate() * cycles;
|
2022-07-12 07:54:19 +02:00
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
const rate = this.getExpRates();
|
|
|
|
applyWorkStats(Player, rate, cycles, "class");
|
2022-07-12 07:54:19 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
finish(): void {
|
|
|
|
if (!this.singularity) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
|
|
|
You worked for {this.getFaction().name}.
|
|
|
|
<br />
|
|
|
|
They now have a total of <Reputation reputation={this.getFaction().playerReputation} /> reputation.
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 21:30:12 +02:00
|
|
|
APICopy(): Record<string, unknown> {
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
cyclesWorked: this.cyclesWorked,
|
|
|
|
factionWorkType: this.factionWorkType,
|
|
|
|
factionName: this.factionName,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return Generic_toJSON("FactionWork", this);
|
|
|
|
}
|
|
|
|
|
2022-10-09 07:25:31 +02:00
|
|
|
/** Initializes a FactionWork object from a JSON save state. */
|
2022-07-12 07:54:19 +02:00
|
|
|
static fromJSON(value: IReviverValue): FactionWork {
|
|
|
|
return Generic_fromJSON(FactionWork, value.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.FactionWork = FactionWork;
|