tangled
alpha
login
or
join now
cass.cityboundforest.com
/
kingdom-homebrew
0
fork
atom
A repository for a FoundryVTT plugin for Kingmaker homebrew.
0
fork
atom
overview
issues
pulls
pipelines
Added functionality to applyEffect buttons
cass.cityboundforest.com
1 month ago
4025f5aa
f02f9da5
+44
-12
3 changed files
expand all
collapse all
unified
split
src
kingdom-desc.ts
socket.ts
utils.ts
+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
4
-
import type { EmptyObject } from "@league-of-foundry-developers/foundry-vtt-types/src/utils/index.mjs";
4
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
232
-
ui.notifications.warn("applyEffect not implemented yet");
232
232
+
const target: HTMLButtonElement = event.target as HTMLButtonElement;
233
233
+
const skillEl: HTMLSpanElement = target.parentElement?.querySelector("span.rollSkill")!;
234
234
+
const skill = skillEl.dataset.skill!;
235
235
+
const leaderEl: HTMLSpanElement = target.parentElement?.querySelector("span.rollLeader")!;
236
236
+
const leader = leaderEl.dataset.id!;
237
237
+
const effect = data.effects.filter((ke: Record<string, any>): boolean => ke.id === parseEffect(target.dataset.effect!))[0];
238
238
+
239
239
+
effect.effects.forEach((efEffect: Record<string, any>): void => {
240
240
+
if (efEffect.appliesTo.skill === null) {
241
241
+
efEffect.appliesTo.skill = skill;
242
242
+
}
243
243
+
244
244
+
if (efEffect.appliesTo.leader === null) {
245
245
+
efEffect.appliesTo.leader = leader;
246
246
+
}
247
247
+
248
248
+
// need to add groups and events once I get those down
249
249
+
});
250
250
+
251
251
+
const currentEffects = actor.getFlag("kingdom-homebrew", "effects") as Record<string, any>[];
252
252
+
currentEffects.push(effect);
253
253
+
actor.setFlag("kingdom-homebrew", "effects", currentEffects);
233
254
}
234
234
-
};
255
255
+
};
256
256
+
257
257
+
function parseEffect(effect: string): string {
258
258
+
return effect.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
259
259
+
}
+15
-8
src/socket.ts
···
261
261
}
262
262
});
263
263
});
264
264
-
265
265
-
return leaderActor.skills[skill].check.roll({
266
266
-
dc,
267
267
-
label: (game as foundry.Game).i18n!.localize("PF2E.SkillCheckWithName").replace("{skillName}", kmLocalize("skillRollLabel") + kmLocalize(`attribute.${kingdomAttribute}`)),
268
268
-
modifiers
264
264
+
265
265
+
return new Promise((resolve: (val: {result: any, skill: string}) => void, _reject: (reason: any) => void): void => {
266
266
+
leaderActor.skills[skill].check.roll({
267
267
+
dc,
268
268
+
label: (game as foundry.Game).i18n!.localize("PF2E.SkillCheckWithName").replace("{skillName}", kmLocalize("skillRollLabel") + kmLocalize(`attribute.${kingdomAttribute}`)),
269
269
+
modifiers
270
270
+
}).then((res: any): void => {
271
271
+
resolve({
272
272
+
result: res,
273
273
+
skill
274
274
+
});
275
275
+
});
269
276
});
270
270
-
}).then(async (result: any): Promise<string> => {
277
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
278
-
const msg = await ealWithActor(true, actor, "activities", activityId, "results", result.degreeOfSuccess.toString(), "msg");
285
285
+
const msg = await ealWithActor(true, actor, "activities", activityId, "results", val.result.degreeOfSuccess.toString(), "msg");
279
286
280
280
-
return `<b>${(game as foundry.Game).i18n!.localize(`PF2E.${keys[result.degreeOfSuccess]}`)}</b> ${msg}`;
287
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
33
-
export async function enrichText(raw: string, markdown: boolean, actor: KingdomActor | null = null, enrichedOptions: object = {}): Promise<string> {
33
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) {