TYPESAFETY: Strict internal typing for AugmentationName (#608)

This commit is contained in:
Snarling
2023-06-16 17:52:42 -04:00
committed by GitHub
parent 12b5c00d14
commit a4b826683e
70 changed files with 2649 additions and 3221 deletions
+18 -8
View File
@@ -7,14 +7,16 @@
* Sleeves are unlocked in BitNode-10.
*/
import type { SleevePerson } from "@nsdefs";
import type { Augmentation } from "../../Augmentation/Augmentation";
import type { Company } from "../../Company/Company";
import type { CompanyPosition } from "../../Company/CompanyPosition";
import type { SleeveWork } from "./Work/Work";
import { Player } from "@player";
import { Person } from "../Person";
import { Augmentation } from "../../Augmentation/Augmentation";
import { Companies } from "../../Company/Companies";
import { Company } from "../../Company/Company";
import { CompanyPosition } from "../../Company/CompanyPosition";
import { CompanyPositions } from "../../Company/CompanyPositions";
import { Contracts } from "../../Bladeburner/data/Contracts";
import { CONSTANTS } from "../../Constants";
@@ -24,7 +26,6 @@ import { Factions } from "../../Faction/Factions";
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../../utils/JSONReviver";
import { formatPercent } from "../../ui/formatNumber";
import { SleeveWork } from "./Work/Work";
import { SleeveClassWork } from "./Work/SleeveClassWork";
import { SleeveSynchroWork } from "./Work/SleeveSynchroWork";
import { SleeveRecoveryWork } from "./Work/SleeveRecoveryWork";
@@ -35,8 +36,8 @@ import { SleeveSupportWork } from "./Work/SleeveSupportWork";
import { SleeveBladeburnerWork } from "./Work/SleeveBladeburnerWork";
import { SleeveCrimeWork } from "./Work/SleeveCrimeWork";
import * as sleeveMethods from "./SleeveMethods";
import { SleevePerson } from "@nsdefs";
import { calculateIntelligenceBonus } from "../formulas/intelligence";
import { getEnumHelper } from "../../utils/EnumHelper";
export class Sleeve extends Person implements SleevePerson {
currentWork: SleeveWork | null = null;
@@ -475,8 +476,17 @@ export class Sleeve extends Person implements SleevePerson {
/** Initializes a Sleeve object from a JSON save state. */
static fromJSON(value: IReviverValue): Sleeve {
if (!value.data.hp?.current || !value.data.hp?.max) value.data.hp = { current: 10, max: 10 };
return Generic_fromJSON(Sleeve, value.data);
const sleeve = Generic_fromJSON(Sleeve, value.data);
if (!sleeve.hp?.current || !sleeve.hp?.max) sleeve.hp = { current: 10, max: 10 };
// Remove any invalid aug names on game load
sleeve.augmentations = sleeve.augmentations.filter((ownedAug) =>
getEnumHelper("AugmentationName").isMember(ownedAug.name),
);
sleeve.queuedAugmentations = sleeve.queuedAugmentations.filter((ownedAug) =>
getEnumHelper("AugmentationName").isMember(ownedAug.name),
);
return sleeve;
}
}
+7 -6
View File
@@ -2,10 +2,11 @@ import { Player } from "@player";
import { AugmentationName, FactionName } from "@enums";
import { Sleeve } from "./Sleeve";
import { Augmentation } from "../../Augmentation/Augmentation";
import { StaticAugmentations } from "../../Augmentation/StaticAugmentations";
import { Augmentations } from "../../Augmentation/Augmentations";
import { Factions } from "../../Faction/Factions";
import { mergeMultipliers, Multipliers } from "../Multipliers";
import { getFactionAugmentationsFiltered } from "../../Faction/FactionHelpers";
import { getAugCost } from "../../Augmentation/AugmentationHelpers";
/** Updates this object's multipliers for the given augmentation */
export function applyAugmentation(this: Sleeve, aug: Augmentation): void {
@@ -61,10 +62,10 @@ export function findPurchasableAugs(this: Sleeve): Augmentation[] {
const gangAugs = getFactionAugmentationsFiltered(fac);
for (const augName of gangAugs) {
const aug = StaticAugmentations[augName];
const aug = Augmentations[augName];
if (!isAvailableForSleeve(aug)) continue;
if (fac.playerReputation > aug.getCost().repCost) {
if (fac.playerReputation > getAugCost(aug).repCost) {
availableAugs.push(aug);
}
}
@@ -77,10 +78,10 @@ export function findPurchasableAugs(this: Sleeve): Augmentation[] {
if (!fac) continue;
for (const augName of fac.augmentations) {
const aug = StaticAugmentations[augName];
const aug = Augmentations[augName];
if (!isAvailableForSleeve(aug)) continue;
if (fac.playerReputation > aug.getCost().repCost) {
if (fac.playerReputation > getAugCost(aug).repCost) {
availableAugs.push(aug);
}
}
@@ -88,7 +89,7 @@ export function findPurchasableAugs(this: Sleeve): Augmentation[] {
// Add the stanek sleeve aug
if (!ownedAugNames.includes(AugmentationName.ZOE) && Player.factions.includes(FactionName.ChurchOfTheMachineGod)) {
const aug = StaticAugmentations[AugmentationName.ZOE];
const aug = Augmentations[AugmentationName.ZOE];
availableAugs.push(aug);
}