From 2fd5f818914f52f3847cf60084bc6d5b31638b13 Mon Sep 17 00:00:00 2001 From: kyamsil Date: Tue, 3 Aug 2021 00:42:26 +0100 Subject: [PATCH] Adding management of actions and strikes --- src/systems/pf2e.js | 26 ++++++++++++++++---------- src/systems/tokenHelper.js | 5 ----- src/token.js | 4 +++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/systems/pf2e.js b/src/systems/pf2e.js index 45ae7ca..6cf531d 100644 --- a/src/systems/pf2e.js +++ b/src/systems/pf2e.js @@ -143,7 +143,7 @@ export class pf2e{ if (effect == undefined) { const Condition = condition.charAt(0).toUpperCase() + condition.slice(1); const newCondition = game.pf2e.ConditionManager.getCondition(Condition); - // newCondition.data.sources.hud = !0, + newCondition.data.sources.hud = !0, await game.pf2e.ConditionManager.addConditionToToken(newCondition, token); } else { @@ -194,7 +194,21 @@ export class pf2e{ getFeatures(token,featureType) { if (featureType == undefined) featureType = 'any'; const allItems = token.actor.items; - if (featureType == 'any') return allItems.filter(i => i.type == 'class' || i.type == 'feat' || i.type == 'melee' || i.type == 'action') + if (featureType == 'any') return allItems.filter(i => i.type == 'ancestry' || i.type == 'background' || i.type == 'class' || i.type == 'feat' || i.type == 'action'); + if (featureType == 'action-any') return allItems.filter(i => i.type == 'action'); + if (featureType == 'action-def') return allItems.filter(i => i.type == 'action' && i.data.data.actionCategory?.value == 'defensive'); + if (featureType == 'action-int') return allItems.filter(i => i.type == 'action' && i.data.data.actionCategory?.value == 'interaction'); + if (featureType == 'action-off') return allItems.filter(i => i.type == 'action' && i.data.data.actionCategory?.value == 'offensive'); + if (featureType == 'strike') { //Strikes are not in the actor.items collection + let actions = token.actor.data.data.actions.filter(a=>a.type == 'strike'); + for (let a of actions) { + a.img = a.imageUrl; + a.data = { + sort: 1 + }; + } + return actions; + } else return allItems.filter(i => i.type == featureType) } @@ -225,14 +239,6 @@ export class pf2e{ } } - /** - * Actions - */ - getActions(token) { - const allActions = token.actor.data.data.actions; - return allActions.filter(a=>a.type==='strike'); - } - rollItem(item) { let variant = 0; if (otherControls.rollOption == 'map1') variant = 1; diff --git a/src/systems/tokenHelper.js b/src/systems/tokenHelper.js index f37a3d3..028dd0c 100644 --- a/src/systems/tokenHelper.js +++ b/src/systems/tokenHelper.js @@ -221,11 +221,6 @@ export class TokenHelper{ return this.system.getResilience(token) } - // /* PF2E */ - // getStrikes(token) { - // return this.system.getStrikes(token); - // } - /** * Conditions */ diff --git a/src/token.js b/src/token.js index b1e7ecc..2472940 100644 --- a/src/token.js +++ b/src/token.js @@ -290,7 +290,9 @@ export class TokenControl{ } else if (mode == 'features') { items = tokenHelper.getFeatures(token,settings.featureType); - items = this.sortItems(items); + if (items != undefined && items[0]?.data?.sort != undefined) { //TODO: Handle Strikes as a separate entity so this hack is not needed... also icons dont work + items = this.sortItems(items); + } item = items[itemNr]; if (item != undefined && displayUses) uses = tokenHelper.getFeatureUses(item); }