Skip to content

Commit

Permalink
Added Shared Warding support
Browse files Browse the repository at this point in the history
  • Loading branch information
mysurvive committed Mar 13, 2023
1 parent 2ec6500 commit 084ca59
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This project is a carryover until the pf2e system for Foundry VTT implements Tha
<li> Share Weakness: A dialog box with buttons to choose party members to share weakness with. It grabs all allied tokens on the scene, so if the token you are looking for isn't in the dialog box check its alliance status.
<li> Cursed Effigy: After clicking the action in the actor's sheet, the "Use Cursed Effigy" button will show on the chat card. Click this to apply the effect to the target.
<li> Twin Weakness: A toggleable roll option needs to be checked above the strikes in the actions tab on the character sheet for damage to apply.
<li> Shared Warding: A dialog asking to apply to nearby allies when Esoteric Warden is available. If chosen yes, all allies within 30 feet will have the Esoteric Warden effect applied to them.
</ul>

This is a work in progress.
Expand Down
48 changes: 41 additions & 7 deletions src/module/exploit-vulnerability.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
createEffectOnTarget,
deleteEVEffect,
applySWEffect,
sharedWarding,
} from "./socket.js";
import "./config.js";
import "./hooks.js";
Expand All @@ -43,6 +44,7 @@ export async function createEffectOnActor(sa, t, effect, rollDOS) {
"useEVAutomation"
);
const hasEsotericWarden = sa.items.some((i) => i.slug === "esoteric-warden");
const hasSharedWarding = sa.items.some((i) => i.slug === "shared-warding");
const hasSympatheticVulnerabilities = sa.items.some(
(i) => i.slug === "sympathetic-vulnerabilities"
);
Expand Down Expand Up @@ -134,10 +136,10 @@ export async function createEffectOnActor(sa, t, effect, rollDOS) {
await sa.setFlag("pf2e-thaum-vuln", "EVValue", exception?.exception);
}
let EWEffect;
if (hasEsotericWarden) {
if (hasEsotericWarden && rollDOS > 1) {
EWEffect = await fromUuid(ESOTERIC_WARDEN_EFFECT_UUID);
EWEffect = EWEffect.toObject();
const bonus = rollDOS === 2 ? 1 : 2;
const bonus = rollDOS === 3 ? 2 : rollDOS === 2 ? 1 : 0;
EWEffect.system.rules[0].value = bonus;
EWEffect.system.rules[1].value = bonus;
EWEffect.system.rules[0].predicate = [
Expand All @@ -152,6 +154,32 @@ export async function createEffectOnActor(sa, t, effect, rollDOS) {
!sa.getFlag("pf2e-thaum-vuln", "EWImmuneTargs")?.includes(t.actor.uuid)
) {
await sa.createEmbeddedDocuments("Item", [EWEffect]);

if (hasSharedWarding) {
let dg = new Dialog({
title: "Shared Warding",
content: () =>
"<p>You ward your allies from the attacks of your foes whenever you apply those protections to yourself. When you gain a status bonus to AC and saves from Esoteric Warden, you can choose to grant the same benefit to all allies within 30 feet. <br><br> Would you like to apply your Esoteric Warden effect to all allies within 30 ft.?</p>",
buttons: {
yes: {
label: "Yes",
callback: () => {
sharedWarding(EWEffect);
},
},
no: {
label: "No",
callback: () => {
return;
},
},
},
default: "yes",
render: () => {},
close: () => {},
});
await dg.render(true);
}
}
let EWImmuneTargs = new Array();
EWImmuneTargs = EWImmuneTargs.concat(
Expand Down Expand Up @@ -242,11 +270,17 @@ export async function exploitVuln() {

//deletes Exploit Vulnerability effect if it already exists on the actor
await deleteEVEffect(canvas.tokens.placeables, sa);
let EWEffect = sa.items.find(
(item) => item.name === "Esoteric Warden Effect"
);
if (EWEffect) {
EWEffect.delete();
for (let act of canvas.tokens.placeables) {
let EWEffect = act.actor?.items.find(
(item) => item.name === "Esoteric Warden Effect"
);
if (
EWEffect &&
(act.actor === sa ||
act.actor.getFlag("pf2e-thaum-vuln", "EWSourceActor") === sa.uuid)
) {
EWEffect.delete();
}
}

// From https://gist.github.com/stwlam/01c2506e93c298b01ad83c182b245144 by somebody, Supe, and stwlam
Expand Down
22 changes: 20 additions & 2 deletions src/module/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Hooks.once("socketlib.ready", () => {
socket.register("updateEVEffect", _socketUpdateEVEffect);
socket.register("deleteEVEffect", _socketDeleteEVEffect);
socket.register("applySWEffect", _socketApplySWEffect);
socket.register("sharedWarding", _socketSharedWarding);
});

export function createEffectOnTarget(a, t, effect, evTargets) {
Expand All @@ -34,6 +35,10 @@ export function createEffectOnTarget(a, t, effect, evTargets) {
);
}

export function sharedWarding(eff) {
return socket.executeAsGM(_socketSharedWarding, eff);
}

export async function applySWEffect(sa, selectedAlly, EVEffect) {
return socket.executeAsGM(_socketApplySWEffect, sa, selectedAlly, EVEffect);
}
Expand Down Expand Up @@ -275,8 +280,6 @@ async function _socketDeleteEVEffect(targ, actorID) {
for (let e of eff) {
await e.delete();
}

//TODO double check there's nothing else to delete
} else {
eff = getActorEVEffect(a, undefined);
eff.delete();
Expand All @@ -294,3 +297,18 @@ async function _socketApplySWEffect(saUuid, selectedAlly, EVEffect) {
ally.setFlag("pf2e-thaum-vuln", "EVValue", EVValue);
return;
}

async function _socketSharedWarding(eff) {
const a = canvas.tokens.controlled[0];
const allTokens = canvas.tokens.placeables;

const affectedTokens = allTokens.filter(
(token) => a.distanceTo(token) <= 30 && token.actor.alliance === "party"
);
for (let token of affectedTokens) {
if (token != a) {
await token.actor.createEmbeddedDocuments("Item", [eff]);
token.actor.setFlag("pf2e-thaum-vuln", "EWSourceActor", a.actor.uuid);
}
}
}
11 changes: 0 additions & 11 deletions src/module/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ export function getActorEVEffect(a, targetID) {
let effects = new Array();

for (let item of a.items) {
console.log(
"debug return values",
TargetEffectSourceIDs.includes(item.getFlag("core", "sourceId")),
item?.rules.find(
(rules) =>
rules.key === "RollOption" &&
rules.option === "origin:id:" + targetID.split(".").join("")
),
item,
a
);
if (
TargetEffectSourceIDs.includes(item.getFlag("core", "sourceId")) &&
item?.rules.find(
Expand Down

0 comments on commit 084ca59

Please sign in to comment.