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

Extend bulk ItemAlteration to allow for further modes #18163

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion src/module/rules/rule-element/item-alteration/alteration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ class ItemAlteration extends foundry.abstract.DataModel<RuleElementPF2e, ItemAlt
const validator = ITEM_ALTERATION_VALIDATORS[this.property];
data.alteration.value = Number(data.alteration.value) || 0;
if (!validator.isValid(data)) return;
data.item.system.bulk.value = data.alteration.value;
const newValue = AELikeRuleElement.getNewValue(
this.mode,
data.item.system.bulk.value,
data.alteration.value,
);
data.item.system.bulk.value = Math.round(Math.max(newValue, 0) * 10) / 10;
if (data.item instanceof foundry.abstract.DataModel) {
data.item.system.bulk = prepareBulkData(data.item);
}
Expand Down
10 changes: 7 additions & 3 deletions src/module/rules/rule-element/item-alteration/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ const ITEM_ALTERATION_VALIDATORS = {
),
bulk: new ItemAlterationValidator({
itemType: new fields.StringField({ required: true, choices: Array.from(PHYSICAL_ITEM_TYPES) }),
mode: new fields.StringField({ required: true, choices: ["override"] }),
value: new StrictNumberField<number, number, true, false, false>({
mode: new fields.StringField({
required: true,
choices: () => ["add", "downgrade", "multiply", "override", "remove", "subtract", "upgrade"],
}),
value: new StrictNumberField({
required: true,
nullable: false,
choices: [0, 0.1, ...Array.fromRange(100, 1)],
Copy link
Collaborator

@stwlam stwlam Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll an additional check here to ensure the resulting value is valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already round the resulting value to 1/10ths, but I can add a check for it to be nonnegative, at least.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.1 (L) is also the only valid non-integer value since Light bulk isn't a countable unit of measurement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically correct, in practice, the system can actually handle values like "9L" or "3; 4L".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

min: 0,
integer: false,
initial: undefined,
} as const),
}),
Expand Down