Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix consuming lockon #803

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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