foundryvtt / dnd5e

An implementation of the 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com).
MIT License
337 stars 224 forks source link

[4.1] Bug: Actors and Containers - `_onDropStackConsumables` only stacks Potions of Healing (specifically, `Compendium.dnd5e.items.Item.ytlsBjYsZ7OBSEBs`) #4685

Closed kgar closed 2 days ago

kgar commented 2 days ago

On actors and containers, when you drop a consumable item onto the sheet, it no longer stacks, unless it is the item with source UUID "Compendium.dnd5e.items.Item.ytlsBjYsZ7OBSEBs", i.e. a Potion of Healing.

https://github.com/foundryvtt/dnd5e/blob/a1d6aa99d377f18654755455ad313585c57a25b1/module/applications/actor/sheet-mixin.mjs#L44

The code in question:

  _onDropStackConsumables(itemData, { container=null }={}) {
    const droppedSourceId = itemData._stats?.compendiumSource ?? itemData.flags.core?.sourceId;
    if ( itemData.type !== "consumable" || !droppedSourceId ) return null;
                                                                              // 👇 That's a potion of healing from the SRD
    const similarItem = this.actor.sourcedItems.get("Compendium.dnd5e.items.Item.ytlsBjYsZ7OBSEBs", { legacy: false })
      ?.filter(i => (i.system.container === container) && (i.name === itemData.name))?.first();
    if ( !similarItem ) return null;
    return similarItem.update({
      "system.quantity": similarItem.system.quantity + Math.max(itemData.system.quantity, 1)
    });
  }
krbz999 commented 2 days ago

4.1.1 will remove system.quantity entirely and introduce the potionOfHealing item type, the only type able to stack.