From e6ef2cd34e827c2a0b2ae96dfe1d2959aa6ef0fc Mon Sep 17 00:00:00 2001 From: TheLastScrub <67403321+TheLastScrub@users.noreply.github.com> Date: Sun, 21 Mar 2021 00:04:13 -0700 Subject: [PATCH] added total armor calculation --- module/actor/actor-sheet.js | 5 ++++- module/actor/actor.js | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index bef3e75..4d61e79 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -56,6 +56,9 @@ export class DeltaGreenActorSheet extends ActorSheet { const armor = []; const weapons = []; + // total armor rating + let armorRating = 0; + // Iterate through items, allocating to containers // let totalWeight = 0; for (let i of sheetData.items) { @@ -65,7 +68,7 @@ export class DeltaGreenActorSheet extends ActorSheet { if (i.type === 'armor') { armor.push(i); } - // Append to features. + // Append to weapons. else if (i.type === 'weapon') { weapons.push(i); } diff --git a/module/actor/actor.js b/module/actor/actor.js index 9edab27..52d12c1 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -16,20 +16,21 @@ export class DeltaGreenActor extends Actor { // Make separate methods for each Actor type (character, npc, etc.) to keep // things organized. - if (actorData.type === 'agent') this._prepareAgentData(actorData); + if (actorData.type === 'agent') this._prepareAgentData(this); } /** * Prepare Agent type specific data */ - _prepareAgentData(actorData) { + _prepareAgentData(agent) { + + let actorData = agent.data; const data = actorData.data; // Make modifications to data here. For example: // Loop through ability scores, and add their modifiers to our sheet output. for (let [key, statistic] of Object.entries(data.statistics)) { - // the x5 is just whatever the raw statistic is x 5 to turn it into a d100 percentile statistic.x5 = statistic.value * 5; } @@ -105,8 +106,20 @@ export class DeltaGreenActor extends Actor { else{ actorData.data.sanity.adaptations.helplessness.isAdapted = false; } + + // calculate total armor rating + let protection = 0; + for (let i of agent.items) { + if (i.type === 'armor') { + if(i.data.data.equipped === true){ + protection += i.data.data.protection; + } + } + } + + actorData.data.health.protection = protection; - console.log(actorData); + console.log(agent); } /** @override */