From 3eaebc6631ca788cd2dbf2ac8fe7e761b7ae5749 Mon Sep 17 00:00:00 2001 From: Samuel Lopez Date: Tue, 30 Sep 2025 10:25:11 +0200 Subject: [PATCH] feat #245 - calc bonus dmg for NPCs --- CHANGELOG.md | 1 + module/actor/actor.js | 83 ++++++++++--------------------- module/item/item-sheet.js | 2 +- module/sheets/base-actor-sheet.js | 2 +- 4 files changed, 28 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3207f0e..0d2776e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### **Features:** - [#258](https://github.com/deltagreen-foundryvtt/delta-green-foundry-vtt-system/issues/258) - Added a keybind option for hovering tooltips and option to hide all. +- [#245](https://github.com/deltagreen-foundryvtt/delta-green-foundry-vtt-system/issues/245) - Automate damage from STR score to melee and unarmed attacks for NPCs. Agents were already doing it. ### **Bug Fixes:** diff --git a/module/actor/actor.js b/module/actor/actor.js index 5a86091..299b862 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -54,7 +54,7 @@ export default class DeltaGreenActor extends Actor { const { system } = actor; // Loop through ability scores, and add their modifiers to our sheet output. - for (const [key, statistic] of Object.entries(system.statistics)) { + for (const statistic of Object.values(system.statistics)) { // the x5 is just whatever the raw statistic is x 5 to turn it into a d100 percentile statistic.x5 = statistic.value * 5; } @@ -74,25 +74,13 @@ export default class DeltaGreenActor extends Actor { system.health.max = Math.ceil( (system.statistics.con.value + system.statistics.str.value) / 2, ); - } catch (ex) { + } catch { system.health.max = 10; } - /* - system.skills.ritual = { - label: "Ritual", - proficiency: 99 - system.sanity.value, - cannotBeImprovedByFailure: true, - failure: false, - }; - - if (system.skills.ritual.proficiency > 99) { - system.skills.ritual.proficiency = 99; - } else if (system.skills.ritual.proficiency < 1) { - system.skills.ritual.proficiency = 1; - } - - */ + const strength = system.statistics.str; + system.statistics.str.meleeDamageBonusFormula = + this._calculateMeleeDamageBonusFormula(strength.value); try { delete system.skills.ritual; // try to remove legacy skill for ritual if it exists @@ -120,7 +108,7 @@ export default class DeltaGreenActor extends Actor { system.health.protection = protection; - for (const [_key, skill] of Object.entries(system.skills)) { + for (const skill of Object.values(system.skills)) { skill.targetProficiency = skill.proficiency; } } @@ -164,29 +152,11 @@ export default class DeltaGreenActor extends Actor { // Make modifications to data here. For example: // Loop through ability scores, and add their modifiers to our sheet output. - for (const [key, statistic] of Object.entries(system.statistics)) { + for (const statistic of Object.values(system.statistics)) { // the x5 is just whatever the raw statistic is x 5 to turn it into a d100 percentile statistic.x5 = statistic.value * 5; } - // The ritual skill is from the Handler's Guide, it is for activating a ritual and is always equal to 99 - current sanity. - // The rules can be found on page 166, under 'Ritual Activation'. - /* - system.skills.ritual = { - label: "Ritual", - proficiency: 99 - system.sanity.value, - cannotBeImprovedByFailure: true, - failure: false, - }; - - if (system.skills.ritual.proficiency > 99) { - system.skills.ritual.proficiency = 99; - } else if (system.skills.ritual.proficiency < 1) { - system.skills.ritual.proficiency = 1; - } - - */ - try { delete system.skills.ritual; // try to remove legacy skill for ritual if it exists } catch { @@ -282,34 +252,31 @@ export default class DeltaGreenActor extends Actor { system.health.protection = protection; - // Damage Bonus/Malus From Strength in Hand-to-hand Combat (melee/unarmed) - let bonus = 0; - let sbonus = ""; const strength = system.statistics.str; - - if (strength.value < 5) { - sbonus = "-2"; - bonus = -2; - } else if (strength.value < 9) { - sbonus = "-1"; - bonus = -1; - } else if (strength.value > 12 && strength.value < 17) { - sbonus = "+1"; - bonus = 1; - } else if (strength.value > 16) { - sbonus = "+2"; - bonus = 2; - } - - system.statistics.str.meleeDamageBonus = bonus; - system.statistics.str.meleeDamageBonusFormula = sbonus; + system.statistics.str.meleeDamageBonusFormula = + this._calculateMeleeDamageBonusFormula(strength.value); if (system.physical.exhaustedPenalty > 0) { system.physical.exhaustedPenalty = -1 * Math.abs(system.physical.exhaustedPenalty); } + } - // console.log(agent); + // Returns Bonus From Strength in Hand-to-hand Combat (melee/unarmed) + _calculateMeleeDamageBonusFormula(strengthValue) { + if (strengthValue < 5) { + return "-2"; + } + if (strengthValue < 9) { + return "-1"; + } + if (strengthValue > 12 && strengthValue < 17) { + return "+1"; + } + if (strengthValue > 16) { + return "+2"; + } + return ""; } /** @override */ diff --git a/module/item/item-sheet.js b/module/item/item-sheet.js index 2bcec8e..5313fbf 100644 --- a/module/item/item-sheet.js +++ b/module/item/item-sheet.js @@ -136,7 +136,7 @@ export default class DeltaGreenItemSheet extends foundry.appv1.sheets let diceFormula = this.item.system.damage; const { skill } = this.item.system; if ( - this.actor.type === "agent" && + (this.actor.type === "agent" || this.actor.type === "npc") && (skill === "unarmed_combat" || skill === "melee_weapons") ) { diceFormula += diff --git a/module/sheets/base-actor-sheet.js b/module/sheets/base-actor-sheet.js index a849e1e..470a4fe 100644 --- a/module/sheets/base-actor-sheet.js +++ b/module/sheets/base-actor-sheet.js @@ -1211,7 +1211,7 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { let diceFormula = item.system.damage; const { skill } = item.system; if ( - this.actor.type === "agent" && + (this.actor.type === "agent" || this.actor.type === "npc") && (skill === "unarmed_combat" || skill === "melee_weapons") ) { diceFormula +=