From 4b41e15ca3d0bfdfc9b7c1a1024d74d4a5cc519a Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Tue, 3 Jan 2023 02:13:01 -0500 Subject: [PATCH] Fix broken HP --- src/PersonObjects/PersonMethods.ts | 7 +++---- src/PersonObjects/Player/PlayerObject.ts | 1 + src/PersonObjects/Sleeve/Sleeve.ts | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/PersonObjects/PersonMethods.ts b/src/PersonObjects/PersonMethods.ts index e19d0bb27..562fe5c37 100644 --- a/src/PersonObjects/PersonMethods.ts +++ b/src/PersonObjects/PersonMethods.ts @@ -193,10 +193,9 @@ export function updateSkillLevels(this: Person): void { ), ); - const ratio: number = this.hp.current / this.hp.max; - this.hp = { - max: Math.floor(10 + this.skills.defense / 10), - current: Math.round(this.hp.max * ratio), + const ratio: number = Math.max(this.hp.current / this.hp.max, 1); + this.hp.max = Math.floor(10 + this.skills.defense / 10); + this.hp.current = Math.round(this.hp.max * ratio); }; } diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts index 3c0a19e34..067eaf5b4 100644 --- a/src/PersonObjects/Player/PlayerObject.ts +++ b/src/PersonObjects/Player/PlayerObject.ts @@ -165,6 +165,7 @@ export class PlayerObject extends Person implements IPlayer { /** Initializes a PlayerObject object from a JSON save state. */ static fromJSON(value: IReviverValue): PlayerObject { + if (!value.data.hp?.current || !value.data.hp?.max) value.data.hp = { current: 10, max: 10 }; const player = Generic_fromJSON(PlayerObject, value.data); if (player.money === null) player.money = 0; return player; diff --git a/src/PersonObjects/Sleeve/Sleeve.ts b/src/PersonObjects/Sleeve/Sleeve.ts index 36a0a185e..f399be09a 100644 --- a/src/PersonObjects/Sleeve/Sleeve.ts +++ b/src/PersonObjects/Sleeve/Sleeve.ts @@ -133,6 +133,10 @@ export class Sleeve extends Person implements SleevePerson { /** Called on every sleeve for a Source File Prestige */ prestige(): void { + // Reset augs and multipliers + this.augmentations = []; + this.resetMultipliers(); + // Reset exp this.exp.hacking = 0; this.exp.strength = 0; @@ -147,12 +151,7 @@ export class Sleeve extends Person implements SleevePerson { this.stopWork(); this.shockRecovery(); - // Reset augs and multipliers - this.augmentations = []; - this.resetMultipliers(); - // Reset Location - this.city = CityName.Sector12; // Reset sleeve-related stats @@ -470,6 +469,7 @@ 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); } }