Skip to content

Commit

Permalink
Add support for AdjustStrike adding/removing weapon property runes (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam authored Jan 26, 2023
1 parent 644fc0c commit cb4526e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
30 changes: 28 additions & 2 deletions packs/data/feats.db/ghost-hunter.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,36 @@
},
"rules": [
{
"definition": [],
"domain": "all",
"key": "RollOption",
"label": "PF2E.SpecificRule.TOTMToggle.Incorporeal",
"option": "target:trait:incorporeal",
"toggleable": "totm"
},
{
"definition": [
"item:magical"
],
"key": "AdjustStrike",
"mode": "add",
"predicate": [
"target:trait:incorporeal"
],
"property": "property-runes",
"value": "ghost-touch"
},
{
"definition": [
{
"not": "item:magical"
}
],
"key": "AdjustStrike",
"mode": "add",
"property": "traits",
"predicate": [
"target:trait:incorporeal"
],
"property": "weapon-traits",
"value": "magical"
}
],
Expand Down
5 changes: 4 additions & 1 deletion src/module/actor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,10 @@ class ActorPF2e extends Actor<TokenDocumentPF2e, ItemTypeMap> {
selfOptions.push("self:flanking");
}

const selfActor = params.viewOnly ? this : this.getContextualClone(selfOptions);
const selfActor =
params.viewOnly || !targetToken?.actor
? this
: this.getContextualClone([...selfOptions, ...targetToken.actor.getSelfRollOptions("target")]);
const actions: StrikeData[] = selfActor.system.actions?.flatMap((a) => [a, a.altUsages ?? []].flat()) ?? [];

const selfItem: AttackItem =
Expand Down
35 changes: 33 additions & 2 deletions src/module/rules/rule-element/adjust-strike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import { ActionTrait } from "@item/action/data";
import { WeaponRangeIncrement } from "@item/weapon/types";
import { MaterialDamageEffect } from "@system/damage";
import { PredicatePF2e } from "@system/predication";
import { ErrorPF2e, objectHasKey, setHasElement } from "@util";
import { ErrorPF2e, objectHasKey, setHasElement, sluggify } from "@util";
import { StrikeAdjustment } from "../synthetics";
import { AELikeData, AELikeRuleElement, AELikeSource } from "./ae-like";
import { RuleElementOptions } from "./base";

class AdjustStrikeRuleElement extends AELikeRuleElement {
protected static override validActorTypes: ActorType[] = ["character", "familiar", "npc"];

private static VALID_PROPERTIES = new Set(["materials", "range-increment", "traits", "weapon-traits"] as const);
private static VALID_PROPERTIES = new Set([
"materials",
"property-runes",
"range-increment",
"traits",
"weapon-traits",
] as const);

/** The property of the strike to adjust */
private property: SetElement<typeof AdjustStrikeRuleElement["VALID_PROPERTIES"]> | null;
Expand Down Expand Up @@ -171,6 +177,31 @@ class AdjustStrikeRuleElement extends AELikeRuleElement {
}
},
};
case "property-runes":
return {
adjustWeapon: (weapon: Embedded<WeaponPF2e>): void => {
if (!["add", "subtract", "remove"].includes(this.mode)) {
return this.failValidation(
'A strike adjustment of weapon property runes must be used with the "add", "subtract", or "remove" mode.'
);
}
const runeSlug = sluggify(String(change), { camel: "dromedary" });
if (!objectHasKey(CONFIG.PF2E.weaponPropertyRunes, runeSlug)) {
return this.failValidation(`"${change} is not a recognized weapon property rune.`);
}
if (!definition.test(weapon.getRollOptions("item"))) {
return;
}

const propertyRunes = weapon.system.runes.property;

if (this.mode === "add" && !propertyRunes.includes(runeSlug)) {
propertyRunes.push(runeSlug);
} else if (propertyRunes.includes(runeSlug)) {
propertyRunes.splice(propertyRunes.indexOf(runeSlug), 1);
}
},
};
}
})();

Expand Down
1 change: 1 addition & 0 deletions static/lang/re-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,7 @@
"TOTMToggle": {
"FirstRangeIncrement": "Enable abilities that require a target within the first range increment.",
"FlatFooted": "Enable abilities that require a flat-footed target",
"Incorporal": "Enable abilities that require an incorporeal target",
"Vampire": "Enable abilities that require a vampire target",
"Undead": "Enable abilities that require an undead target"
},
Expand Down

0 comments on commit cb4526e

Please sign in to comment.