Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust negative damage rolls #17521

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 11 additions & 2 deletions src/module/system/damage/iwr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ function applyIWR(actor: ActorPF2e, roll: Rolled<DamageRoll>, rollOptions: Set<s
const formalDescription = new Set([...instance.formalDescription, ...rollOptions]);

// If the roll's total was increased to a minimum of 1, treat the first instance as having a total of 1
const wasIncreased = instance.total <= 0 && typeof roll.options.increasedFrom === "number";
const wasIncreased = instance.total <= 0 && typeof instance.options.increasedFrom === "number";
const isFirst = instances.indexOf(instance) === 0;
const instanceTotal = wasIncreased && isFirst ? 1 : Math.max(instance.total, 0);
const instanceApplications: IWRApplication[] = [];

// Step 0: Inapplicable damage outside the IWR framework
if (!actor.isAffectedBy(instance.type)) {
return [{ category: "unaffected", type: instance.type, adjustment: -1 * instanceTotal }];
}
// Step 0.5: adjust for 0 damage rolls
if (wasIncreased && isFirst){
instanceApplications.push({
category: "weakness",
type: "adjusment",
adjustment: 1,
});
}

// Step 1: Immunities

Expand All @@ -71,7 +80,7 @@ function applyIWR(actor: ActorPF2e, roll: Rolled<DamageRoll>, rollOptions: Set<s
return [{ category: "immunity", type: appliedImmunity.label, adjustment: -1 * instanceTotal }];
}

const instanceApplications: IWRApplication[] = [];


let redirectedFromImmunity: DamageType | null = null;
for (const immunity of applicableImmunities) {
Expand Down
11 changes: 8 additions & 3 deletions src/module/system/damage/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,14 @@ class DamageInstance extends AbstractDamageRoll {
return DAMAGE_TYPE_ICONS[this.type];
}

/** Return 0 for persistent damage */
/** Return 0 for persistent damage and if damage is below 0 */
protected override _evaluateTotal(): number {
return this.persistent && !this.options.evaluatePersistent ? 0 : super._evaluateTotal();
const total = super._evaluateTotal();
if (!this.persistent && total <= 0){
this.options.increasedFrom = total;
return 0;
}
else return this.persistent && !this.options.evaluatePersistent ? 0 : total;
}

override async render({ tooltips = true }: InstanceRenderOptions = {}): Promise<string> {
Expand Down Expand Up @@ -610,7 +615,7 @@ class DamageInstance extends AbstractDamageRoll {
result.hidden = true;
}
}

this._total = this._evaluateTotal();
return this as Rolled<this>;
}
}
Expand Down