Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packs/pf2e/conditions/drained.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,21 @@
},
{
"key": "LoseHitPoints",
"predicate": [
{
"not": "drained-hp-effective-minus-one"
}
],
"reevaluateOnUpdate": true,
"value": "max(1,@actor.level) * @item.badge.value"
},
{
"key": "LoseHitPoints",
"predicate": [
"drained-hp-effective-minus-one"
],
"reevaluateOnUpdate": true,
"value": "max(1,@actor.level) * max(0,@item.badge.value - 1)"
}
],
"traits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,38 @@
"value": 1
},
{
"key": "AdjustModifier",
"mode": "add",
"selector": "fortitude",
"slug": "drained",
"value": 1
"key": "RollOption",
"option": "svetocher"
},
{
"key": "RollOption",
"option": "drained-hp-effective-minus-one"
},
{
"key": "FlatModifier",
"predicate": [
"self:condition:drained"
"self:condition:drained",
{
"not": "sanguine-tenacity"
}
],
"selector": "hp",
"value": "@actor.level"
},
{
"key": "AdjustModifier",
"mode": "add",
"predicate": [
"self:condition:drained",
{
"not": "sanguine-tenacity"
}
],
"selectors": [
"fortitude"
],
"slug": "drained",
"value": 1
}
],
"traits": {
Expand Down
24 changes: 16 additions & 8 deletions packs/pf2e/feats/general/level-11/sanguine-tenacity.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@
"title": "Pathfinder #213: Thirst for Blood"
},
"rules": [
{
"key": "RollOption",
"option": "sanguine-tenacity"
},
{
"key": "RollOption",
"option": "drained-hp-effective-minus-one"
},
{
"key": "FlatModifier",
"predicate": [
"self:condition:drained"
],
"selector": "hp",
"value": "@actor.level"
},
{
"key": "Resistance",
"type": "bleed",
Expand Down Expand Up @@ -62,14 +78,6 @@
"str-damage"
],
"value": 1
},
{
"key": "FlatModifier",
"predicate": [
"self:condition:drained"
],
"selector": "hp",
"value": "@actor.level"
}
],
"traits": {
Expand Down
17 changes: 12 additions & 5 deletions src/module/rules/rule-element/lose-hit-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class LoseHitPointsRuleElement extends RuleElement<LoseHitPointsRuleSchema> {
}

override onCreate(actorUpdates: Record<string, unknown>): void {
if (this.ignored) return;
if (this.ignored || !this.test()) return;
const value = Math.trunc(Math.abs(Number(this.resolveValue(this.value)) || 0));
const currentHP = this.actor._source.system.attributes.hp.value;
actorUpdates["system.attributes.hp.value"] = Math.max(currentHP - value, 0);
}

override beforePrepareData(): void {
if (this.ignored) return;
if (this.ignored || !this.test()) return;

const { actor } = this;
if (!this.recoverable) {
Expand All @@ -35,12 +35,19 @@ class LoseHitPointsRuleElement extends RuleElement<LoseHitPointsRuleSchema> {
}

override async preUpdate(changes: DeepPartial<ItemSourcePF2e>): Promise<void> {
if (!this.reevaluateOnUpdate || this.ignored) return;
if (!this.reevaluateOnUpdate || this.ignored || !this.test()) return;
const previousValue = Math.trunc(Math.abs(Number(this.resolveValue(this.value)) || 0));
const newItem = this.item.clone(changes);
const rule = newItem.system.rules.find((r): r is LoseHitPointsSource => r.key === this.key);
const ruleSource = typeof this.sourceIndex === "number" ? newItem.system.rules[this.sourceIndex] : undefined;
if (!ruleSource || ruleSource.key !== "LoseHitPoints") return;
const newValue = Math.trunc(
Math.abs(Number(this.resolveValue(String(rule?.value), 0, { resolvables: { item: newItem } }))),
Math.abs(
Number(
this.resolveValue(String((ruleSource as LoseHitPointsSource).value), 0, {
resolvables: { item: newItem },
}),
) || 0,
),
);
const valueChange = newValue - previousValue;
if (valueChange > 0) {
Expand Down
Loading