2023-06-26 04:53:35 +02:00
|
|
|
import { AugmentationName, FactionName } from "@enums";
|
2021-09-05 01:09:30 +02:00
|
|
|
import { FactionInfo, FactionInfos } from "./FactionInfo";
|
2021-09-02 09:10:12 +02:00
|
|
|
import { favorToRep, repToFavor } from "./formulas/favor";
|
2023-04-07 06:33:51 +02:00
|
|
|
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../utils/JSONReviver";
|
2023-06-26 04:53:35 +02:00
|
|
|
import { getKeyList } from "../utils/helpers/getKeyList";
|
2018-12-07 11:54:26 +01:00
|
|
|
|
|
|
|
export class Faction {
|
2021-09-05 01:09:30 +02:00
|
|
|
/**
|
|
|
|
* Flag signalling whether the player has already received an invitation
|
|
|
|
* to this faction
|
|
|
|
*/
|
|
|
|
alreadyInvited = false;
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Holds names of all augmentations that this Faction offers */
|
2023-06-20 13:35:54 +02:00
|
|
|
augmentations: AugmentationName[] = [];
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Amount of favor the player has with this faction. */
|
2021-09-05 01:09:30 +02:00
|
|
|
favor = 0;
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Flag signalling whether player has been banned from this faction */
|
2021-09-05 01:09:30 +02:00
|
|
|
isBanned = false;
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Flag signalling whether player is a member of this faction */
|
2021-09-05 01:09:30 +02:00
|
|
|
isMember = false;
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Name of faction */
|
2023-06-26 04:53:35 +02:00
|
|
|
name: FactionName;
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Amount of reputation player has with this faction */
|
2021-09-05 01:09:30 +02:00
|
|
|
playerReputation = 0;
|
|
|
|
|
2023-06-26 04:53:35 +02:00
|
|
|
constructor(name = FactionName.Sector12) {
|
2021-09-05 01:09:30 +02:00
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
getInfo(): FactionInfo {
|
|
|
|
const info = FactionInfos[this.name];
|
|
|
|
if (info == null) {
|
|
|
|
throw new Error(
|
|
|
|
`Missing faction from FactionInfos: ${this.name} this probably means the faction got corrupted somehow`,
|
|
|
|
);
|
2018-12-07 11:54:26 +01:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return info;
|
|
|
|
}
|
2018-12-07 11:54:26 +01:00
|
|
|
|
2023-06-26 04:53:35 +02:00
|
|
|
prestigeSourceFile() {
|
|
|
|
// Reset favor, reputation, and flags
|
|
|
|
this.favor = 0;
|
|
|
|
this.playerReputation = 0;
|
|
|
|
this.alreadyInvited = false;
|
|
|
|
this.isMember = false;
|
|
|
|
this.isBanned = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
prestigeAugmentation(): void {
|
|
|
|
// Gain favor
|
|
|
|
if (this.favor == null) this.favor = 0;
|
2021-11-05 21:09:19 +01:00
|
|
|
this.favor += this.getFavorGain();
|
2023-06-26 04:53:35 +02:00
|
|
|
// Reset reputation and flags
|
|
|
|
this.playerReputation = 0;
|
|
|
|
this.alreadyInvited = false;
|
|
|
|
this.isMember = false;
|
|
|
|
this.isBanned = false;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Returns an array with [How much favor would be gained, how much rep would be left over]
|
2021-11-05 21:09:19 +01:00
|
|
|
getFavorGain(): number {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (this.favor == null) {
|
|
|
|
this.favor = 0;
|
2018-12-07 11:54:26 +01:00
|
|
|
}
|
2021-11-05 21:09:19 +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
|
|
|
}
|
|
|
|
|
2023-06-26 04:53:35 +02:00
|
|
|
static savedKeys = getKeyList(Faction, { removedKeys: ["augmentations", "name"] });
|
|
|
|
|
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-06-26 04:53:35 +02:00
|
|
|
return Generic_toJSON("Faction", this, Faction.savedKeys);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
2022-10-09 07:25:31 +02:00
|
|
|
/** Initializes a Faction object from a JSON save state. */
|
2022-07-15 01:00:10 +02:00
|
|
|
static fromJSON(value: IReviverValue): Faction {
|
2023-06-26 04:53:35 +02:00
|
|
|
return Generic_fromJSON(Faction, value.data, Faction.savedKeys);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2018-12-07 11:54:26 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 06:33:51 +02:00
|
|
|
constructorsForReviver.Faction = Faction;
|