Skip to content

Commit

Permalink
release 0.11.2 include css classes and refactor condition creation
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed Jan 1, 2023
1 parent 2c02e54 commit b095f07
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Supe"
}
],
"version": "0.11.1",
"version": "0.11.2",
"compatibility": {
"minimum": "10",
"verified": "10.291"
Expand Down Expand Up @@ -52,5 +52,5 @@
],
"url": "https://github.com/CarlosFdez/pf2e-persistent-damage",
"manifest": "https://github.com/CarlosFdez/pf2e-persistent-damage/releases/latest/download/module.json",
"download": "https://github.com/CarlosFdez/pf2e-persistent-damage/releases/download/v0.11.1/module.zip"
"download": "https://github.com/CarlosFdez/pf2e-persistent-damage/releases/download/v0.11.2/module.zip"
}
22 changes: 2 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ConditionSource } from "@item/data";
import { ChatMessagePF2e } from "@module/chat-message";
import { DamageType } from "@module/system/damage";
import { PersistentDamagePF2e } from "./module/pf2e-persistent-damage";
Expand Down Expand Up @@ -41,26 +40,9 @@ Hooks.on("renderChatMessage", async (message: ChatMessagePF2e, $html: JQuery<HTM

$html.find(".pf2e-pd-card button").on("click", (evt) => {
evt.preventDefault();
const tokens = canvas.tokens.controlled.filter((token) => token.actor);
const instances = roll.instances.filter((i) => i.persistent);
const conditions = instances.map((instance): DeepPartial<ConditionSource> => {
const damageType = instance.type;
const formula = instance.head.expression;
const dc = 15; // from a message, the dc is always 15

return {
type: "condition",
name: "Persistent Damage",
system: {
slug: "persistent-damage",
removable: true,
persistent: {
damageType, formula, dc
}
}
}
});
const conditions = PF2EPersistentDamage.getPersistentDamageFromMessage(message);

const tokens = canvas.tokens.controlled.filter((token) => token.actor);
for (const token of tokens) {
token.actor?.createEmbeddedDocuments("Item", conditions);
}
Expand Down
25 changes: 25 additions & 0 deletions src/module/pf2e-persistent-damage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { ActorPF2e } from "@actor";
import { ConditionSource } from "@item/data";
import { TokenPF2e } from "@module/canvas";
import { ChatMessagePF2e } from "@module/chat-message";
import { TokenDocumentPF2e } from "@module/scene";
import { DamageType } from "@module/system/damage";
import { MODULE_NAME } from "./settings";
Expand Down Expand Up @@ -52,6 +54,29 @@ export class PersistentDamagePF2e {
await game.pf2e.gm.editPersistent({ actors });
}

/** Returns all conditions the message should apply involving persistent damage */
getPersistentDamageFromMessage(message: ChatMessagePF2e): DeepPartial<ConditionSource>[] {
const roll: any = message.rolls[0];
const instances = roll.instances.filter((i) => i.persistent);
return instances.map((instance) => {
const damageType = instance.type;
const formula = instance.head.expression;
const dc = 15; // from a message, the dc is always 15

return {
type: "condition",
name: "Persistent Damage",
system: {
slug: "persistent-damage",
removable: true,
persistent: {
damageType, formula, dc
}
}
}
});
}

/**
* Removes persistent damage effects of a certain type from an actor
* @param actor
Expand Down
6 changes: 3 additions & 3 deletions src/templates/chat/recover-persistent-button.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="pf2e-pd-card">
<hr/>
{{#if autoCheck}}
<div>
<div class="result degree-of-success">
DC {{data.dc}} {{{inlineCheck}}} -
{{#if success}}
<span class="flat-check-success">Success</span>
<span class="flat-check-success success">Success</span>
{{else}}
<span class="flat-check-failure">Failure</span>
<span class="flat-check-failure failure">Failure</span>
{{/if}}
</div>
{{else}}
Expand Down
6 changes: 3 additions & 3 deletions src/templates/chat/recover-persistent-card.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="pf2e-pd-card">
<strong>Recovery Check: Persistent {{typeName}} DC{{data.dc}}</strong>
<div>
<div class="result degree-of-success">
{{#if success}}
<span class="flat-check-success">Success</span>
<span class="flat-check-success success">Success</span>
{{else}}
<span class="flat-check-failure">Failure</span>
<span class="flat-check-failure failure">Failure</span>
{{/if}}
</div>
</div>

0 comments on commit b095f07

Please sign in to comment.