diff --git a/src/module/rollHelpers.js b/src/module/rollHelpers.js index 051239a..f6916bb 100644 --- a/src/module/rollHelpers.js +++ b/src/module/rollHelpers.js @@ -1,18 +1,37 @@ import { log } from './globals.js'; +function hasDeflection(target, type) { + return ( + target.actor.effects.filter( + (e) => !e.disabled && e.name.toLowerCase().includes('deflection') && e.name.toLowerCase().includes(type), + ).length > 0 + ); +} + export async function preTraitRollModifiers(actor, trait, roll, modifiers, options) { const targets = Array.from(game.user.targets); const token = game.canvas.tokens.controlled.length > 0 ? game.canvas.tokens.controlled[0] : null; if (targets.some((target) => target.actor.system.status.isVulnerable)) { modifiers.push({ label: 'Target is Vulnerable', value: '+2', ignore: false }); } - if ( - targets.some( - (target) => - target.actor.effects.filter((e) => !e.disabled && e.name.toLowerCase().includes('deflection')).length > 0, - ) - ) { - modifiers.push({ label: 'Target has Deflection', value: '-2', ignore: false }); + if (targets.some((target) => hasDeflection(target, 'melee'))) { + const ignore = trait?.type !== 'skill' || trait?.system?.swid !== 'fighting'; + modifiers.push({ label: 'Target has Melee Deflection', value: '-2', ignore: ignore }); + } + if (targets.some((target) => hasDeflection(target, 'range'))) { + const ignore = + trait?.type !== 'skill' || !(trait?.system?.swid === 'shooting' || trait?.system?.swid === 'athletics'); + modifiers.push({ label: 'Target has Ranged Deflection', value: '-2', ignore: ignore }); + } + if (targets.some((target) => hasDeflection(target, 'all'))) { + const ignore = + trait?.type !== 'skill' || + !( + trait?.system?.swid === 'fighting' || + trait?.system?.swid === 'shooting' || + trait?.system?.swid === 'athletics' + ); + modifiers.push({ label: 'Target has Deflection', value: '-2', ignore: ignore }); } if ( targets.some(