Skip to content

Commit

Permalink
Fix consuming lockon
Browse files Browse the repository at this point in the history
Targeting data contained the uuid, but was being compared to the plain
id, so the comparison was always false.

Fixes: #801
  • Loading branch information
BoltsJ committed Dec 2, 2024
1 parent 841a43f commit 7649dd8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/module/flows/attack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type AttackFlag = {
attackerItemUuid?: string; // Item UUID used for the attack, if applicable
invade?: boolean;
targets: {
id: string;
uuid: string;
setConditions?: object; // keys are statusEffect ids, values are boolean to indicate whether to apply or remove
total: string;
hit: boolean;
Expand Down Expand Up @@ -464,7 +464,8 @@ export async function printAttackCard(
attackerItemUuid: state.item?.uuid,
targets: state.data.hit_results.map(hr => {
return {
id: hr.target.document.uuid,
id: hr.target.document.id,
uuid: hr.target.document.uuid,
setConditions: !!hr.usedLockOn ? { lockon: !hr.usedLockOn } : undefined,
total: hr.total,
hit: hr.hit,
Expand Down Expand Up @@ -494,24 +495,25 @@ export async function printAttackCard(

// If user is GM, apply status changes to attacked tokens
Hooks.on("createChatMessage", async (cm: ChatMessage, options: any, id: string) => {
// Consume lock-on if we are a GM
if (!game.user?.isGM) return;
// Consume lock-on if we are the primary GM
// @ts-expect-error Types user collection missing activeGM
if (!game.users?.activeGM?.isSelf) return;
const atkData: AttackFlag = cm.getFlag(game.system.id, "attackData") as any;
if (!atkData || !atkData.targets) return;
atkData.targets.forEach(target => {
// Find the target in this scene
const tokenActor = game.canvas.scene?.tokens.find(token => token.id === target.id)?.actor;
const tokenActor = game.canvas.scene?.tokens.find(token => token.uuid === target.uuid)?.actor;
if (!tokenActor) return;
const statusToApply = [];
const statusToRemove = [];
for (const [stat, val] of Object.entries(target.setConditions || {})) {
if (val) {
// Apply status
console.log(`(Not) Applying ${stat} to Token ${target.id}`);
console.log(`(Not) Applying ${stat} to Token ${target.uuid}`);
// TODO
} else {
// Remove status
console.log(`Removing ${stat} from Token ${target.id}`);
console.log(`Removing ${stat} from Token ${target.uuid}`);
statusToRemove.push(stat);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/module/flows/damage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export async function rollDamageCallback(event: JQuery.ClickEvent) {
}
const hit_results: LancerFlowState.HitResult[] = [];
for (const t of attackData.targets) {
const target = (await fromUuid(t.id)) as LancerToken | null;
const target = (await fromUuid(t.uuid)) as LancerToken | null;
// @ts-expect-error v11 types
if (!target || target.documentName !== "Token") {
ui.notifications?.error("Invalid target for damage roll");
Expand Down
3 changes: 2 additions & 1 deletion src/module/flows/tech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export async function printTechAttackCard(
invade: state.data.invade,
targets: state.data.hit_results.map(hr => {
return {
id: hr.target.actor?.uuid || "",
id: hr.target.actor?.id || "",
uuid: hr.target.actor?.uuid || "",
setConditions: !!hr.usedLockOn ? { lockon: !hr.usedLockOn } : undefined,
total: hr.total,
hit: hr.hit,
Expand Down

0 comments on commit 7649dd8

Please sign in to comment.