Skip to content

Instantly share code, notes, and snippets.

@7H3LaughingMan
Created December 5, 2024 20:01
Show Gist options
  • Select an option

  • Save 7H3LaughingMan/89e0e0cf400713a509998f88965e3dee to your computer and use it in GitHub Desktop.

Select an option

Save 7H3LaughingMan/89e0e0cf400713a509998f88965e3dee to your computer and use it in GitHub Desktop.
Alchemist - Treat Wounds
/* Get DamageRoll */
const DamageRoll = CONFIG.Dice.rolls.find((R) => R.name === "DamageRoll");
async function applyChanges(token, $html) {
const mod = parseInt($html.find('[name="modifier"]').val()) || 0;
const requestedProf = parseInt($html.find('[name="dc-type"]')[0].value) || 1;
const skill = token.actor.skills["crafting"];
if (!skill?.proficient) {
ui.notifications.warn(`${token.actor.name} is not trained in Crafting.`);
return;
}
const maxTargets = 2 ** (skill.rank - 1);
if (game.user.targets.size > maxTargets) {
ui.notifications.warn(`Too many targets for Treat Wounds. You can select a maximum of ${maxTargets} targets.`);
return;
}
const rank = skill.rank ?? 1;
const usedProf = requestedProf <= rank ? requestedProf : rank;
const dcValue = [15, 20, 30, 40][usedProf - 1] + mod;
const bonus = [0, 10, 30, 50][usedProf - 1];
const rollOptions = token.actor.getRollOptions(["all", "skill-check", "crafting"]);
rollOptions.push("action:treat-wounds");
rollOptions.push("right-hand-blood");
const dc = { value: dcValue, visible: true };
await skill.roll({
dc,
skipDialog: false,
extraRollOptions: rollOptions,
callback: async (roll, outcome, message) => {
let successLabel = "";
let healFormula = null;
switch (outcome) {
case "criticalSuccess":
successLabel = "Critical Success";
healFormula = `4d8${bonus > 0 ? `+ ${bonus}` : ``}`;
break;
case "success":
successLabel = "Success";
healFormula = `2d8${bonus > 0 ? `+ ${bonus}` : ``}`;
break;
case "criticalFailure":
successLabel = "Critical Failure";
healFormula = `1d8`;
break;
}
const speaker = ChatMessage.getSpeaker({ token });
const flags = foundry.utils.mergeObject(message.toObject().flags, { pf2e: { origin: { messageId: message.id } } });
ChatMessage.create({
flags: foundry.utils.mergeObject(JSON.parse(JSON.stringify(flags)), { "pf2e-toolbelt": { targetHelper: { targets: [token.document.uuid] } } }),
flavor: `<strong>Damage Roll: Right-Hand Blood</strong>`,
rolls: [(await new DamageRoll("{2d8}").roll()).toJSON()],
speaker
})
if (healFormula) {
const formulaModifier = outcome === "criticalFailure" ? "" : "[healing]";
const healRoll = await new DamageRoll(`{(${healFormula})${formulaModifier}}`).roll();
const rollType = outcome !== "criticalFailure" ? "Healing Roll: Treat Wounds" : "Damage Roll: Treat Wounds";
ChatMessage.create({
flags,
flavor: `<strong>${rollType}</strong> (${successLabel})`,
rolls: [healRoll.toJSON()],
speaker,
});
}
}
});
}
if (canvas.tokens.controlled.length !== 1) {
ui.notifications.warn('You need to select exactly one token as the healer.');
} else if (game.user.targets.size < 1) {
ui.notifications.warn("You must target at least one token.");
} else {
const dialog = new Dialog({
title: "Treat Wounds (Jackal)",
content:
`<form>
<div class="form-group">
<label>Crafting DC</label>
<select id="dc-type" name="dc-type">
<option value="1" selected>Trained DC 15</option>
<option value="2">Expert DC 20, +10 Healing</option>
<option value="3">Master DC 30, +30 Healing</option>
<option value="4">Legendary DC 40, +50 Healing</option>
</select>
</div>
</form>
<form>
<div class="form-group">
<label>DC Modifier</label>
<input id="modifier" name="modifier" type="number"/>
</div>
</form>`,
buttons: {
yes: {
icon: `<i class="fas fa-hand-holding-medical"></i>`,
label: "Treat Wounds",
callback: ($html) => applyChanges(token, $html),
},
no: {
icon: `<i class="fas fa-times"></i>`,
label: "Cancel",
},
},
default: "yes",
});
dialog.render(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment