Fix linting errors and cleanup.
This commit is contained in:
@@ -18,7 +18,7 @@ function hasActiveStimulantEffect(actor) {
|
||||
* @param {Actor} actor
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function getEffectiveSuppressExhaustion(actor) {
|
||||
export default function getEffectiveSuppressExhaustion(actor) {
|
||||
const persisted =
|
||||
actor._source?.system?.physical?.suppressExhaustion ?? false;
|
||||
return Boolean(persisted) || hasActiveStimulantEffect(actor);
|
||||
|
||||
@@ -77,8 +77,8 @@ function attachRollTargetDisplay(entry, modifier) {
|
||||
export function prepareAgentRollTargetDisplay(actor) {
|
||||
if (actor.type !== "agent") return;
|
||||
|
||||
const system = actor.system;
|
||||
const rollTarget = system.rollTarget;
|
||||
const { system } = actor;
|
||||
const { rollTarget } = system;
|
||||
if (!rollTarget) return;
|
||||
|
||||
const allSkillsMod = Number(rollTarget.allSkills) || 0;
|
||||
@@ -108,7 +108,7 @@ export function prepareAgentRollTargetDisplay(actor) {
|
||||
export function prepareAgentActiveEffectDisplay(actor) {
|
||||
if (actor.type !== "agent") return;
|
||||
|
||||
const system = actor.system;
|
||||
const { system } = actor;
|
||||
const source = actor._source?.system;
|
||||
if (!source) return;
|
||||
|
||||
@@ -128,7 +128,9 @@ export function prepareAgentActiveEffectDisplay(actor) {
|
||||
const healthFormulaMax = calculateHealthMax(persistedStats, persistedStats);
|
||||
const wpFormulaMax = persistedStats.pow?.value ?? 0;
|
||||
const persistedUnnatural =
|
||||
source.skills?.unnatural?.proficiency ?? system.skills?.unnatural?.proficiency ?? 0;
|
||||
source.skills?.unnatural?.proficiency ??
|
||||
system.skills?.unnatural?.proficiency ??
|
||||
0;
|
||||
const sanityFormulaMax = 99 - persistedUnnatural;
|
||||
|
||||
const healthBaseMax = healthFormulaMax + (source.health?.maxBonus ?? 0);
|
||||
@@ -159,7 +161,7 @@ export function prepareAgentActiveEffectDisplay(actor) {
|
||||
export function refreshDerivedAfterActiveEffects(actor) {
|
||||
if (actor.type !== "agent") return;
|
||||
|
||||
const system = actor.system;
|
||||
const { system } = actor;
|
||||
|
||||
const sourceStatistics = actor._source?.system?.statistics;
|
||||
prepareStatisticsX5(system.statistics, sourceStatistics);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import DG from "../../config/index.js";
|
||||
import { ROLL_TARGET_FIELD_KEYS } from "../effect-fields.js";
|
||||
import { getEffectiveSuppressExhaustion } from "./agent-condition-sync.js";
|
||||
import getEffectiveSuppressExhaustion from "./agent-condition-sync.js";
|
||||
|
||||
/** @type {WeakMap<Actor, Promise<void>>} */
|
||||
const syncLocks = new WeakMap();
|
||||
@@ -10,7 +10,9 @@ const syncLocks = new WeakMap();
|
||||
* @returns {ActiveEffect[]}
|
||||
*/
|
||||
function getExhaustionEffects(actor) {
|
||||
return actor.effects?.filter((effect) => effect.getFlag(DG.ID, "exhaustion")) ?? [];
|
||||
return (
|
||||
actor.effects?.filter((effect) => effect.getFlag(DG.ID, "exhaustion")) ?? []
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,9 +79,7 @@ async function syncExhaustionEffectInner(actor) {
|
||||
const { exhausted, exhaustedPenalty } = actor.system.physical;
|
||||
const suppressExhaustion = getEffectiveSuppressExhaustion(actor);
|
||||
const effect = getExhaustionEffect(actor);
|
||||
const penalty = exhausted
|
||||
? -1 * Math.abs(Number(exhaustedPenalty) || 0)
|
||||
: 0;
|
||||
const penalty = exhausted ? -1 * Math.abs(Number(exhaustedPenalty) || 0) : 0;
|
||||
|
||||
if (!exhausted) {
|
||||
if (effect) await effect.delete();
|
||||
@@ -95,7 +95,7 @@ async function syncExhaustionEffectInner(actor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const documentClass = getDocumentClass("ActiveEffect");
|
||||
const documentClass = foundry.utils.getDocumentClass("ActiveEffect");
|
||||
await documentClass.create(
|
||||
{
|
||||
name: game.i18n.localize("DG.Physical.ExhaustionEffectName"),
|
||||
|
||||
@@ -51,7 +51,7 @@ function getStimulantRemainingHours(effect) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
export { getEffectiveSuppressExhaustion } from "./agent-condition-sync.js";
|
||||
export { default as getEffectiveSuppressExhaustion } from "./agent-condition-sync.js";
|
||||
|
||||
/**
|
||||
* @param {number} hours
|
||||
@@ -99,7 +99,7 @@ export async function applyStimulantEffect(actor, newHours) {
|
||||
return hours;
|
||||
}
|
||||
|
||||
const documentClass = getDocumentClass("ActiveEffect");
|
||||
const documentClass = foundry.utils.getDocumentClass("ActiveEffect");
|
||||
await documentClass.create(data, { parent: actor });
|
||||
return hours;
|
||||
}
|
||||
@@ -150,8 +150,9 @@ export async function clearStimulantEffects(actor) {
|
||||
export async function pruneAllAgentsExpiredStimulants() {
|
||||
if (!game.user.isActiveGM) return;
|
||||
for (const actor of game.actors) {
|
||||
if (actor.type !== "agent") continue;
|
||||
await pruneExpiredStimulantEffects(actor);
|
||||
await syncExhaustionEffect(actor);
|
||||
if (actor.type === "agent") {
|
||||
await pruneExpiredStimulantEffects(actor);
|
||||
await syncExhaustionEffect(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,6 @@
|
||||
import DG from "../../config/index.js";
|
||||
import { getStatisticEffectiveValue } from "../../data/derived/actor-derived.js";
|
||||
|
||||
/**
|
||||
* Strip form values that match post–AE prepared numbers so persisted data stays at base values.
|
||||
* @param {Actor} actor
|
||||
* @param {object} data Update payload (mutated in place).
|
||||
* @returns {object}
|
||||
*/
|
||||
export function sanitizeActiveEffectBackedUpdateData(actor, data) {
|
||||
if (!data?.system) return data;
|
||||
|
||||
const source = actor._source?.system;
|
||||
if (!source) return data;
|
||||
|
||||
sanitizeStatisticValues(actor, data, source);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Actor} actor
|
||||
* @param {object} data
|
||||
@@ -29,17 +12,38 @@ function sanitizeStatisticValues(actor, data, source) {
|
||||
data,
|
||||
`system.statistics.${key}.value`,
|
||||
);
|
||||
if (submitted === undefined) continue;
|
||||
if (submitted !== undefined) {
|
||||
const sourceStat = source.statistics?.[key];
|
||||
const preparedStat = actor.system.statistics?.[key];
|
||||
if (sourceStat && preparedStat) {
|
||||
const base = sourceStat.value;
|
||||
const effective = getStatisticEffectiveValue(preparedStat, sourceStat);
|
||||
|
||||
const sourceStat = source.statistics?.[key];
|
||||
const preparedStat = actor.system.statistics?.[key];
|
||||
if (!sourceStat || !preparedStat) continue;
|
||||
|
||||
const base = sourceStat.value;
|
||||
const effective = getStatisticEffectiveValue(preparedStat, sourceStat);
|
||||
|
||||
if (submitted === effective && submitted !== base) {
|
||||
foundry.utils.setProperty(data, `system.statistics.${key}.value`, base);
|
||||
if (submitted === effective && submitted !== base) {
|
||||
foundry.utils.setProperty(
|
||||
data,
|
||||
`system.statistics.${key}.value`,
|
||||
base,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip form values that match post–AE prepared numbers so persisted data stays at base values.
|
||||
* @param {Actor} actor
|
||||
* @param {object} data Update payload (mutated in place).
|
||||
* @returns {object}
|
||||
*/
|
||||
export default function sanitizeActiveEffectBackedUpdateData(actor, data) {
|
||||
if (!data?.system) return data;
|
||||
|
||||
const source = actor._source?.system;
|
||||
if (!source) return data;
|
||||
|
||||
sanitizeStatisticValues(actor, data, source);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user