make deflection modifiers more descriptive

This commit is contained in:
Mike Bloy 2025-01-26 23:48:41 -06:00
parent cd8b5ac7eb
commit ba9eac716d

View File

@ -1,18 +1,37 @@
import { log } from './globals.js'; 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) { export async function preTraitRollModifiers(actor, trait, roll, modifiers, options) {
const targets = Array.from(game.user.targets); const targets = Array.from(game.user.targets);
const token = game.canvas.tokens.controlled.length > 0 ? game.canvas.tokens.controlled[0] : null; const token = game.canvas.tokens.controlled.length > 0 ? game.canvas.tokens.controlled[0] : null;
if (targets.some((target) => target.actor.system.status.isVulnerable)) { if (targets.some((target) => target.actor.system.status.isVulnerable)) {
modifiers.push({ label: 'Target is Vulnerable', value: '+2', ignore: false }); modifiers.push({ label: 'Target is Vulnerable', value: '+2', ignore: false });
} }
if ( if (targets.some((target) => hasDeflection(target, 'melee'))) {
targets.some( const ignore = trait?.type !== 'skill' || trait?.system?.swid !== 'fighting';
(target) => modifiers.push({ label: 'Target has Melee Deflection', value: '-2', ignore: ignore });
target.actor.effects.filter((e) => !e.disabled && e.name.toLowerCase().includes('deflection')).length > 0, }
) if (targets.some((target) => hasDeflection(target, 'range'))) {
) { const ignore =
modifiers.push({ label: 'Target has Deflection', value: '-2', ignore: false }); 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 ( if (
targets.some( targets.some(