Add reaction engine and action skeletons
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
export function randomPointInCircle(origin, radiusPx) {
|
||||
const angle = Math.random() * Math.PI * 2;
|
||||
const distance = Math.sqrt(Math.random()) * radiusPx;
|
||||
|
||||
return {
|
||||
x: origin.x + Math.cos(angle) * distance,
|
||||
y: origin.y + Math.sin(angle) * distance
|
||||
};
|
||||
}
|
||||
|
||||
export function isWithinTeleportRadius(originCenter, candidateCenter, radiusPx) {
|
||||
const dx = candidateCenter.x - originCenter.x;
|
||||
const dy = candidateCenter.y - originCenter.y;
|
||||
return Math.hypot(dx, dy) <= radiusPx;
|
||||
}
|
||||
|
||||
export function sceneDistanceToPixels(distance) {
|
||||
const gridSize = canvas.scene.grid.size;
|
||||
const distancePerGrid = canvas.scene.grid.distance || 5;
|
||||
return distance / distancePerGrid * gridSize;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
export function getBestTokenDocumentForActor(actor) {
|
||||
if (!actor) return null;
|
||||
|
||||
const controlled = canvas?.tokens?.controlled?.find(token => token.actor?.uuid === actor.uuid || token.actor?.id === actor.id);
|
||||
if (controlled) return controlled.document;
|
||||
|
||||
const activeTokens = actor.getActiveTokens?.(true, true) ?? [];
|
||||
if (activeTokens.length === 1) return activeTokens[0].document;
|
||||
|
||||
const combatant = game.combat?.combatants?.find(c => c.actor?.uuid === actor.uuid || c.actor?.id === actor.id);
|
||||
if (combatant?.token) return combatant.token;
|
||||
|
||||
return activeTokens[0]?.document ?? null;
|
||||
}
|
||||
|
||||
export function getPrimaryOwner(actor) {
|
||||
if (!actor) return null;
|
||||
return game.users.find(user => user.active && !user.isGM && actor.testUserPermission(user, "OWNER")) ?? null;
|
||||
}
|
||||
|
||||
export function isTokenSpaceOccupied(token, targetPosition) {
|
||||
const targetRect = new PIXI.Rectangle(targetPosition.x, targetPosition.y, token.w, token.h);
|
||||
|
||||
return canvas.tokens.placeables.some(other => {
|
||||
if (other.id === token.id) return false;
|
||||
if (other.document.hidden) return false;
|
||||
|
||||
const otherRect = new PIXI.Rectangle(other.document.x, other.document.y, other.w, other.h);
|
||||
return rectanglesOverlap(targetRect, otherRect);
|
||||
});
|
||||
}
|
||||
|
||||
function rectanglesOverlap(a, b) {
|
||||
return a.x < b.x + b.width &&
|
||||
a.x + a.width > b.x &&
|
||||
a.y < b.y + b.height &&
|
||||
a.y + a.height > b.y;
|
||||
}
|
||||
Reference in New Issue
Block a user