DEVMENU: Easier to add/remove sleeves (#908)

This commit is contained in:
Sphyxis
2023-12-04 12:36:00 -07:00
committed by GitHub
parent 76f0f3d6d3
commit 79b0f83b5f
7 changed files with 76 additions and 30 deletions
+13
View File
@@ -464,6 +464,19 @@ export class Sleeve extends Person implements SleevePerson {
}
}
static recalculateNumOwned() {
const numSleeves =
Math.min(3, Player.sourceFileLvl(10) + (Player.bitNodeN === 10 ? 1 : 0)) + Player.sleevesFromCovenant;
while (Player.sleeves.length > numSleeves) {
const destroyedSleeve = Player.sleeves.pop();
// This should not happen, but avoid an infinite loop in case sleevesFromCovenent or sf10 level are somehow negative
if (!destroyedSleeve) return;
// Stop work, to prevent destroyed sleeves from continuing their tasks in the void
destroyedSleeve.stopWork();
}
while (Player.sleeves.length < numSleeves) Player.sleeves.push(new Sleeve());
}
whoAmI(): string {
return "Sleeve";
}
@@ -47,7 +47,7 @@ export function CovenantPurchasesRoot(props: IProps): React.ReactElement {
if (Player.canAfford(purchaseCost())) {
Player.loseMoney(purchaseCost(), "sleeves");
Player.sleevesFromCovenant += 1;
Player.sleeves.push(new Sleeve());
Sleeve.recalculateNumOwned();
rerender();
} else {
dialogBoxCreate(`You cannot afford to purchase a Duplicate Sleeve`);