A repository for a FoundryVTT plugin for Kingmaker homebrew.

Added functionality to applyEffect buttons

+44 -12
+28 -3
src/kingdom-desc.ts
··· 1 1 import type { KingdomActor } from "./global"; 2 2 import { kmLocalize } from "./utils"; 3 3 import { socket } from "./socket"; 4 - import type { EmptyObject } from "@league-of-foundry-developers/foundry-vtt-types/src/utils/index.mjs"; 4 + import { data } from "./data"; 5 5 6 6 function getThreshold(actor: KingdomActor, key: string): number | null { 7 7 if (key.includes("commodities")) { ··· 229 229 ui.notifications.warn("gainEvent not implemented yet"); 230 230 }, 231 231 "applyEffect": (actor: KingdomActor, event: Event): void => { 232 - ui.notifications.warn("applyEffect not implemented yet"); 232 + const target: HTMLButtonElement = event.target as HTMLButtonElement; 233 + const skillEl: HTMLSpanElement = target.parentElement?.querySelector("span.rollSkill")!; 234 + const skill = skillEl.dataset.skill!; 235 + const leaderEl: HTMLSpanElement = target.parentElement?.querySelector("span.rollLeader")!; 236 + const leader = leaderEl.dataset.id!; 237 + const effect = data.effects.filter((ke: Record<string, any>): boolean => ke.id === parseEffect(target.dataset.effect!))[0]; 238 + 239 + effect.effects.forEach((efEffect: Record<string, any>): void => { 240 + if (efEffect.appliesTo.skill === null) { 241 + efEffect.appliesTo.skill = skill; 242 + } 243 + 244 + if (efEffect.appliesTo.leader === null) { 245 + efEffect.appliesTo.leader = leader; 246 + } 247 + 248 + // need to add groups and events once I get those down 249 + }); 250 + 251 + const currentEffects = actor.getFlag("kingdom-homebrew", "effects") as Record<string, any>[]; 252 + currentEffects.push(effect); 253 + actor.setFlag("kingdom-homebrew", "effects", currentEffects); 233 254 } 234 - }; 255 + }; 256 + 257 + function parseEffect(effect: string): string { 258 + return effect.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); 259 + }
+15 -8
src/socket.ts
··· 261 261 } 262 262 }); 263 263 }); 264 - 265 - return leaderActor.skills[skill].check.roll({ 266 - dc, 267 - label: (game as foundry.Game).i18n!.localize("PF2E.SkillCheckWithName").replace("{skillName}", kmLocalize("skillRollLabel") + kmLocalize(`attribute.${kingdomAttribute}`)), 268 - modifiers 264 + 265 + return new Promise((resolve: (val: {result: any, skill: string}) => void, _reject: (reason: any) => void): void => { 266 + leaderActor.skills[skill].check.roll({ 267 + dc, 268 + label: (game as foundry.Game).i18n!.localize("PF2E.SkillCheckWithName").replace("{skillName}", kmLocalize("skillRollLabel") + kmLocalize(`attribute.${kingdomAttribute}`)), 269 + modifiers 270 + }).then((res: any): void => { 271 + resolve({ 272 + result: res, 273 + skill 274 + }); 275 + }); 269 276 }); 270 - }).then(async (result: any): Promise<string> => { 277 + }).then(async (val: {result: any, skill: string}): Promise<string> => { 271 278 const keys = [ 272 279 "CritFailure", 273 280 "Failure", ··· 275 282 "CritSuccess" 276 283 ]; 277 284 278 - const msg = await ealWithActor(true, actor, "activities", activityId, "results", result.degreeOfSuccess.toString(), "msg"); 285 + const msg = await ealWithActor(true, actor, "activities", activityId, "results", val.result.degreeOfSuccess.toString(), "msg"); 279 286 280 - return `<b>${(game as foundry.Game).i18n!.localize(`PF2E.${keys[result.degreeOfSuccess]}`)}</b> ${msg}`; 287 + return `<b>${(game as foundry.Game).i18n!.localize(`PF2E.${keys[val.result.degreeOfSuccess]}`)}</b> ${msg}<span class="rollSkill" data-skill="${val.skill}" style="display:none;"></span><span class="rollLeader" data-id="${leaderActor.id}" style="display:none;"></span>`; 281 288 }).then((msg: string): void => { 282 289 foundry.documents.ChatMessage.create({ 283 290 user: (game as foundry.Game).users.activeGM.id,
+1 -1
src/utils.ts
··· 30 30 return (game as foundry.Game).i18n!.localize(`kingdom-homebrew.${args.join(".")}`); 31 31 } 32 32 33 - export async function enrichText(raw: string, markdown: boolean, actor: KingdomActor | null = null, enrichedOptions: object = {}): Promise<string> { 33 + export async function enrichText(raw: string, markdown: boolean, actor: KingdomActor | null = null, rollObject: Record<string, any> = {}, enrichedOptions: object = {}): Promise<string> { 34 34 let text = raw; 35 35 36 36 if (markdown) {