From 3fa4c2f4c58677eabe010ef53f1824d103aa7e88 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 24 Oct 2024 12:27:06 +0100 Subject: [PATCH] Expanded offraid healing to remove effects based on healing item used Made it also heal damage taken --- project/src/callbacks/HealthCallbacks.ts | 12 ------- project/src/controllers/HealthController.ts | 40 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/project/src/callbacks/HealthCallbacks.ts b/project/src/callbacks/HealthCallbacks.ts index f473cdc0..e974aa55 100644 --- a/project/src/callbacks/HealthCallbacks.ts +++ b/project/src/callbacks/HealthCallbacks.ts @@ -19,18 +19,6 @@ export class HealthCallbacks { @inject("HealthController") protected healthController: HealthController, ) {} - /** - * Custom spt server request found in modules/HealthSynchronizer.cs - * @param url - * @param info HealthListener.Instance.CurrentHealth class - * @param sessionID session id - * @returns empty response, no data sent back to client - */ - public syncHealth(url: string, info: ISyncHealthRequestData, sessionID: string): IGetBodyResponseData { - this.healthController.saveVitality(this.profileHelper.getPmcProfile(sessionID), info, sessionID); - return this.httpResponse.emptyResponse(); - } - /** * Custom spt server request found in modules/QTEPatch.cs * @param url diff --git a/project/src/controllers/HealthController.ts b/project/src/controllers/HealthController.ts index 7e7e9196..268eff66 100644 --- a/project/src/controllers/HealthController.ts +++ b/project/src/controllers/HealthController.ts @@ -74,6 +74,46 @@ export class HealthController { this.inventoryHelper.removeItem(pmcData, request.item, sessionID, output); } + const healingItemDbDetails = this.itemHelper.getItem(healingItemToUse._tpl); + + const healItemEffectDetails = healingItemDbDetails[1]._props.effects_damage; + const bodyPartToHeal: IBodyPartHealth = pmcData.Health.BodyParts[request.part]; + if (!bodyPartToHeal) { + this.logger.warning(`Tried to heal a non-existent body part: ${request.part}`); + + return output; + } + + // Adjust body part hp value + bodyPartToHeal.Health.Current += request.count; + + // Ensure we've not healed beyond the limbs max hp + if (bodyPartToHeal.Health.Current > bodyPartToHeal.Health.Maximum) { + bodyPartToHeal.Health.Current = bodyPartToHeal.Health.Maximum; + } + + // Check if healing item removes negative effects + const itemRemovesEffects = Object.keys(healingItemDbDetails[1]._props.effects_damage).length > 0; + if (itemRemovesEffects) { + // Check body parts effects against what the healing item can remove + const effectsOnBodyPart = Object.keys(bodyPartToHeal.Effects); + if (!effectsOnBodyPart) { + this.logger.warning(`Tried to remove effects from body part: ${request.part} without effects`); + + return output; + } + + for (const effectKey of effectsOnBodyPart) { + const matchingEffectFromHealingItem = healItemEffectDetails[effectKey]; + if (!matchingEffectFromHealingItem) { + // Healing item doesnt have matching effect, it doesnt remove the effect + continue; + } + + delete bodyPartToHeal.Effects[effectKey]; + } + } + return output; }