Skip to content

Commit

Permalink
Merge pull request #3576 from foundryvtt/summoning/damage-bonus
Browse files Browse the repository at this point in the history
[#3444] Re-implement summoned item modifications using enchantments
  • Loading branch information
arbron authored May 17, 2024
2 parents 29f77e3 + 5371560 commit 9218e49
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
55 changes: 37 additions & 18 deletions module/data/item/fields/summons-field.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export class SummonsData extends foundry.abstract.DataModel {
const saveDamageBonus = Roll.replaceFormulaData(this.bonuses.saveDamage, rollData);
const healingBonus = Roll.replaceFormulaData(this.bonuses.healing, rollData);
for ( const item of actor.items ) {
const itemUpdates = {};
const changes = [];

// Match attacks
if ( this.match.attacks && item.hasAttack ) {
Expand All @@ -466,33 +466,52 @@ export class SummonsData extends foundry.abstract.DataModel {
prof,
rollData.bonuses?.[typeMapping[item.system.actionType] ?? item.system.actionType]?.attack
].filter(p => p);
itemUpdates["system.attack.bonus"] = parts.join(" + ");
itemUpdates["system.attack.flat"] = true;
changes.push({
key: "system.attack.bonus",
mode: CONST.ACTIVE_EFFECT_MODES.OVERRIDE,
value: parts.join(" + ")
}, {
key: "system.attack.flat",
mode: CONST.ACTIVE_EFFECT_MODES.OVERRIDE,
value: true
});
}

// Match saves
if ( this.match.saves && item.hasSave ) {
itemUpdates["system.save.dc"] = rollData.item.save.dc ?? rollData.attributes.spelldc;
itemUpdates["system.save.scaling"] = "flat";
}
if ( this.match.saves && item.hasSave ) changes.push({
key: "system.save.dc",
mode: CONST.ACTIVE_EFFECT_MODES.OVERRIDE,
value: rollData.item.save.dc ?? rollData.attributes.spelldc
}, {
key: "system.save.scaling",
mode: CONST.ACTIVE_EFFECT_MODES.OVERRIDE,
value: "flat"
});

// Damage bonus
let damageBonus;
if ( item.hasAttack ) damageBonus = attackDamageBonus;
else if ( item.system.actionType === "save" ) damageBonus = saveDamageBonus;
else if ( item.isHealing ) damageBonus = healingBonus;
if ( damageBonus && item.hasDamage ) {
const damage = foundry.utils.deepClone(item.system.damage.parts);
damage[0][0] = `${damage[0][0] ?? ""} + ${damageBonus}`;
itemUpdates["system.damage.parts"] = damage;
if ( item.system.damage.versatile ) {
itemUpdates["system.damage.versatile"] = `${item.system.damage.versatile} + ${damageBonus}`;
}
}
if ( damageBonus && item.hasDamage ) changes.push({
key: "system.damage.parts",
mode: CONST.ACTIVE_EFFECT_MODES.ADD,
value: JSON.stringify([[`${damageBonus}`, ""]])
});

if ( !foundry.utils.isEmpty(itemUpdates) ) {
itemUpdates._id = item.id;
actorUpdates.items.push(itemUpdates);
if ( changes.length ) {
const effect = (new ActiveEffect({
_id: staticID("dnd5eItemChanges"),
changes,
disabled: false,
icon: "icons/skills/melee/strike-slashes-orange.webp",
name: game.i18n.localize("DND5E.Summoning.ItemChanges.Label"),
origin: this.item.uuid,
flags: {
dnd5e: { type: "enchantment" }
}
})).toObject();
actorUpdates.items.push({ _id: item.id, effects: [effect] });
}
}

Expand Down
1 change: 0 additions & 1 deletion module/documents/active-effect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default class ActiveEffect5e extends ActiveEffect {
*/
get isAppliedEnchantment() {
return (this.getFlag("dnd5e", "type") === "enchantment")
&& (this.parent.system.metadata?.enchantable === true)
&& !!this.origin && (this.origin !== this.parent.uuid);
}

Expand Down
4 changes: 0 additions & 4 deletions module/documents/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,6 @@ export default class Item5e extends SystemDocumentMixin(Item) {
*/
applyActiveEffects() {
const overrides = {};
if ( !this.system?.metadata?.enchantable ) {
this.overrides = overrides;
return;
}

// Organize non-disabled effects by their application priority
const changes = [];
Expand Down

0 comments on commit 9218e49

Please sign in to comment.