This commit is contained in:
@@ -236,7 +236,6 @@ export class ConfigurableReactionsConfigApp extends HandlebarsApplicationMixin(A
|
||||
|
||||
if (dropZone.dataset.crDrop === "action-spell" && isSpellItem(droppedItem)) {
|
||||
await this.#setActionSpell(Number(dropZone.dataset.actionIndex), droppedItem);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -409,6 +408,7 @@ export class ConfigurableReactionsConfigApp extends HandlebarsApplicationMixin(A
|
||||
try {
|
||||
reaction = JSON.parse(textarea.value);
|
||||
} catch (error) {
|
||||
console.warn(`${MODULE_ID} | Invalid reaction JSON`, error);
|
||||
ui.notifications.error(game.i18n.localize("CONFIGURABLE_REACTIONS.Errors.InvalidJson"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,21 +10,30 @@ export async function handleTrigger(triggerType, context) {
|
||||
const assignedReactions = await getAssignedReactionsForContext(context);
|
||||
|
||||
for (const reaction of assignedReactions) {
|
||||
try {
|
||||
if (!reaction?.enabled) continue;
|
||||
if (reaction.trigger?.type !== triggerType) continue;
|
||||
if (!matchesTriggerSpellFilter(reaction.trigger, context)) continue;
|
||||
if (!await checkConsumptionAvailable(reaction, context)) continue;
|
||||
if (!await checkConditions(reaction, context)) continue;
|
||||
|
||||
const result = await executeReactionActions(reaction, context);
|
||||
if (result.shouldConsume) await consumeReactionUse(reaction, context);
|
||||
} catch (error) {
|
||||
console.error(`${MODULE_ID} | Failed to handle reaction`, reaction, error);
|
||||
}
|
||||
await handleAssignedReaction(triggerType, context, reaction);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAssignedReaction(triggerType, context, reaction) {
|
||||
try {
|
||||
if (!await shouldExecuteReaction(triggerType, context, reaction)) return;
|
||||
|
||||
const result = await executeReactionActions(reaction, context);
|
||||
if (result.shouldConsume) await consumeReactionUse(reaction, context);
|
||||
} catch (error) {
|
||||
console.error(`${MODULE_ID} | Failed to handle reaction`, reaction, error);
|
||||
}
|
||||
}
|
||||
|
||||
async function shouldExecuteReaction(triggerType, context, reaction) {
|
||||
if (!reaction?.enabled) return false;
|
||||
if (reaction.trigger?.type !== triggerType) return false;
|
||||
if (!matchesTriggerSpellFilter(reaction.trigger, context)) return false;
|
||||
if (!await checkConsumptionAvailable(reaction, context)) return false;
|
||||
|
||||
return checkConditions(reaction, context);
|
||||
}
|
||||
|
||||
function matchesTriggerSpellFilter(trigger, context) {
|
||||
const expectedName = trigger?.spell?.itemName;
|
||||
if (!expectedName) return true;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export function randomPointInCircle(origin, radiusPx) {
|
||||
const angle = Math.random() * Math.PI * 2;
|
||||
const distance = Math.sqrt(Math.random()) * radiusPx;
|
||||
const angle = randomUnitFloat() * Math.PI * 2;
|
||||
const distance = Math.sqrt(randomUnitFloat()) * radiusPx;
|
||||
|
||||
return {
|
||||
x: origin.x + Math.cos(angle) * distance,
|
||||
@@ -19,3 +19,14 @@ export function sceneDistanceToPixels(distance) {
|
||||
const distancePerGrid = canvas.scene.grid.distance || 5;
|
||||
return distance / distancePerGrid * gridSize;
|
||||
}
|
||||
|
||||
function randomUnitFloat() {
|
||||
const cryptoApi = globalThis.crypto;
|
||||
if (!cryptoApi?.getRandomValues) {
|
||||
throw new Error("A cryptographically secure random generator is not available.");
|
||||
}
|
||||
|
||||
const values = new Uint32Array(1);
|
||||
cryptoApi.getRandomValues(values);
|
||||
return values[0] / 0x100000000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user