Skip to content

Commit

Permalink
Add range-increment and range-max to ItemAlteration (#17898)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaitoKuroba authored Jan 29, 2025
1 parent ee6dbe0 commit 0b8e739
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/module/rules/rule-element/item-alteration/alteration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AELikeChangeMode, AELikeRuleElement } from "../ae-like.ts";
import type { RuleElementPF2e } from "../base.ts";
import { ResolvableValueField } from "../data.ts";
import { ITEM_ALTERATION_VALIDATORS } from "./schemas.ts";
import { WeaponRangeIncrement } from "@item/weapon/types.ts";

class ItemAlteration extends foundry.abstract.DataModel<RuleElementPF2e, ItemAlterationSchema> {
static VALID_PROPERTIES = [
Expand All @@ -39,6 +40,8 @@ class ItemAlteration extends foundry.abstract.DataModel<RuleElementPF2e, ItemAlt
"other-tags",
"pd-recovery-dc",
"persistent-damage",
"range-increment",
"range-max",
"rarity",
"speed-penalty",
"strength",
Expand Down Expand Up @@ -403,6 +406,24 @@ class ItemAlteration extends foundry.abstract.DataModel<RuleElementPF2e, ItemAlt
}
return;
}
case "range-increment": {
const validator = ITEM_ALTERATION_VALIDATORS[this.property];
if (!validator.isValid(data)) return;
if (!data.item.system.range) return;
const rangeIncrement = data.item.system.range;
const newValue = AELikeRuleElement.getNewValue(this.mode, rangeIncrement, data.alteration.value);
data.item.system.range = newValue as WeaponRangeIncrement;
return;
}
case "range-max": {
const validator = ITEM_ALTERATION_VALIDATORS[this.property];
if (!validator.isValid(data)) return;
if (!data.item.system.maxRange) return;
const maxRange = data.item.system.maxRange;
const newValue = AELikeRuleElement.getNewValue(this.mode, maxRange, data.alteration.value);
data.item.system.maxRange = newValue;
return;
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/module/rules/rule-element/item-alteration/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,30 @@ const ITEM_ALTERATION_VALIDATORS = {
choices: RARITIES,
} as const),
}),
"range-increment": new ItemAlterationValidator({
itemType: new fields.StringField({ required: true, choices: ["weapon"] }),
mode: new fields.StringField({
required: true,
choices: ["add", "multiply", "override", "remove", "subtract"],
}),
value: new fields.NumberField({
required: true,
nullable: false,
initial: undefined,
} as const),
}),
"range-max": new ItemAlterationValidator({
itemType: new fields.StringField({ required: true, choices: ["weapon"] }),
mode: new fields.StringField({
required: true,
choices: ["add", "multiply", "override", "remove", "subtract"],
}),
value: new fields.NumberField({
required: true,
nullable: false,
initial: undefined,
} as const),
}),
"frequency-max": new ItemAlterationValidator({
itemType: new fields.StringField({ required: true, choices: ["action", "feat"] }),
mode: new fields.StringField({
Expand Down

0 comments on commit 0b8e739

Please sign in to comment.