consumables chat data

@Zhell
So that's odd. How come consumables work different and all other item types get a non-functional save button when they no longer exist on the actor?
This is interesting and worth being in the history here. Only consumables have the assumption that they will need functional chat buttons after the item has been destroyed. As such they automatically put the item data into the chat message flags, and use that information when the buttons are interacted with.
35 Replies
Calego
Calego•3y ago
Normally, it's expected that the item still exists on the actor that rolled the item. But since consumables have the "Destroy when empty" logic built in, they have the special handling built in.
Zhell
Zhell•3y ago
And this is only consumables, and I'm guessing modifying a different item's chat message to contain the itemData as well will do nothing?
Calego
Calego•3y ago
not actually sure about that
Calego
Calego•3y ago
GitLab
module/item/entity.js · master · Foundry Network / Foundry VTT 5th ...
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com). This work is permitted under the Open...
Calego
Calego•3y ago
innnnteresting so looks like if there is itemData in the flags, it'll prefer that always
const item = storedData ? new this(storedData, {parent: actor}) : actor.items.get(card.dataset.itemId);
const item = storedData ? new this(storedData, {parent: actor}) : actor.items.get(card.dataset.itemId);
Calego
Calego•3y ago
So in my wee concentration module, I could not use consumable for the card displayed to prompt for checks. I would need to create the chatcard myself though? Think so. the displayCard method only populates the itemData automatically for consumables. https://gitlab.com/foundrynet/dnd5e/-/blob/master/module/item/entity.js#L745
GitLab
module/item/entity.js · master · Foundry Network / Foundry VTT 5th ...
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com). This work is permitted under the Open...
Zhell
Zhell•3y ago
Just tried slapping a weapon (toObject()) into the same flag. It works.
Calego
Calego•3y ago
veeeerry interesting
Zhell
Zhell•3y ago
I.e., weapon with con save, roll it, update the message.content with 'flags.dnd5e.itemData': weapon.toObject(), then delete the weapon from the actor. Con save still works
Calego
Calego•3y ago
creating and then deleting the item does feel kinda bad though
Zhell
Zhell•3y ago
(and after refresh as well, just to make sure)
Calego
Calego•3y ago
like why cause 3 database updates for something that should take 1 - create weapon - create chat card - delete weapon
Zhell
Zhell•3y ago
This could be interesting for magic items with spells. 🤔
Calego
Calego•3y ago
for that I honestly think a new preparation mode "item" would solve like all the problems
Zhell
Zhell•3y ago
True but some don't like the clutter. Anyway, can't one just manually edit the message with the appropriate data before creating a chat card, no item needed?
Calego
Calego•3y ago
Yeah true. I guess you could make a temporary item, call displayCard with createMessage: false in the args, then modify the output to include the data of the temporary item I remember Item5e#roll had issues with rolling an ephemeral item, but displayCard didn't
Zhell
Zhell•3y ago
ephemeral?
Calego
Calego•3y ago
temporary i.e. a Document that doesn't exist in the database
Zhell
Zhell•3y ago
Right
Calego
Calego•3y ago
Could change the DOM output too to remove the extra stuff like the chat card footer with item details. Hmmm. I might do this in concentration5e. thanks @Zhell 🙂
Leo The League Lion
Leo The League Lion•3y ago
@calego gave vote LeaguePoints™ to @Zhell (#217 • 2)
Zhell
Zhell•3y ago
Something like ChatMessage.create(msg.toObject()) does work. 🤔 and that's not a lot of data tbh.
Calego
Calego•3y ago
is msg the output of displayCard?
Zhell
Zhell•3y ago
(where msg is a message that works...)
Calego
Calego•3y ago
gotchya the output of displayCard({createMessage: false}) is all the data you'd need to pass into ChatMessage.create() so I envision something like this:
const fakeItem = new Item5e(someItemData, {temporary: true, parent: someActor});

const messageData = fakeItem.displayCard({createMessage: false});

messageData.flags['dnd5e.itemData'] = fakeItem.toObject();

ChatMessage.create(message);
const fakeItem = new Item5e(someItemData, {temporary: true, parent: someActor});

const messageData = fakeItem.displayCard({createMessage: false});

messageData.flags['dnd5e.itemData'] = fakeItem.toObject();

ChatMessage.create(message);
Zhell
Zhell•3y ago
I wonder just how little data you need to do this. I'm gonna strip it down until it breaks.
Calego
Calego•3y ago
I think it depends on the action present, refer to the _onChatCardAction method in Item5e for example if you're rolling an attack, the chatmessage needs all the data to make an item with an attack roll for a save though, it really only needs enough to make a valid item (name and type), since all the rest comes from the chat message DOM (for better or worse... bleh)
Zhell
Zhell•3y ago
Item5e is undefined, and just Item doesn't have a displayCard function. >_>
const itemData = {data: {actionType: "save", save: {ability: 'con', dc: 20, scaling: 'flat'}}, name: "Steve", type: "loot"};
let fakeItem = new Item.implementation(itemData, {temporary: true, parent: token.actor});
let messageData = await fakeItem.displayCard({createMessage: false});
messageData.flags['dnd5e.itemData'] = fakeItem.toObject();
messageData.content = `<div class="dnd5e chat-card item-card" data-actor-id="stSaie8MWAdB4hUG">
<header class="card-header flexrow">
<img src="icons/svg/item-bag.svg" title="Steve" width="36" height="36"/>
<h3 class="item-name">Steve</h3>
</header>
<div class="card-content">
Text goes here.
</div>
<div class="card-buttons">
<button data-action="save" data-ability="con">
Saving Throw
</button>
</div>`;
ChatMessage.create(messageData);
const itemData = {data: {actionType: "save", save: {ability: 'con', dc: 20, scaling: 'flat'}}, name: "Steve", type: "loot"};
let fakeItem = new Item.implementation(itemData, {temporary: true, parent: token.actor});
let messageData = await fakeItem.displayCard({createMessage: false});
messageData.flags['dnd5e.itemData'] = fakeItem.toObject();
messageData.content = `<div class="dnd5e chat-card item-card" data-actor-id="stSaie8MWAdB4hUG">
<header class="card-header flexrow">
<img src="icons/svg/item-bag.svg" title="Steve" width="36" height="36"/>
<h3 class="item-name">Steve</h3>
</header>
<div class="card-content">
Text goes here.
</div>
<div class="card-buttons">
<button data-action="save" data-ability="con">
Saving Throw
</button>
</div>`;
ChatMessage.create(messageData);
🥳 Got rid of the footer in a messy way but eh
Zhell
Zhell•3y ago
No description
kaelad
kaelad•3y ago
Man, are we all writing our own concentrators? I do the same trick with mine, creating a temporary item then adding it to the chat message's flag so the saving throw button works. https://github.com/kaelad02/concentrator/blob/main/src/concentrator.js#L252
GitHub
concentrator/concentrator.js at main · kaelad02/concentrator
Foundry module to manage concentration. Contribute to kaelad02/concentrator development by creating an account on GitHub.
Calego
Calego•3y ago
Lol amazing Next thing you'll tell me that both of you have made little modules to check if an attack roll his
kaelad
kaelad•3y ago
Not yet
kaelad
kaelad•3y ago
The only other unpublished module I have adds two features onto Convenient Effects: 1. Auto apply Dead, Unconscious, and Wounded status 2. Add a button on item cards to "Add Convenient Effect" if you use a feature that has a matching convenient effect https://github.com/kaelad02/convenient-effects-ext
GitHub
GitHub - kaelad02/convenient-effects-ext: Foundry module that adds ...
Foundry module that adds some extensions to the CE module - GitHub - kaelad02/convenient-effects-ext: Foundry module that adds some extensions to the CE module
Zhell
Zhell•3y ago
I'm told this means we have to duel at noon...? 🤔 I have thought about it... 😬 Definitely just a DM-only script though.
kaelad
kaelad•3y ago
I immediately started humming this: https://youtu.be/PYI09PMNazw
Cinema Hotel Studios
YouTube
The Ecstasy of Gold - Ennio Morricone ( The Good, the Bad and the U...
"The Ecstasy of Gold" (Italian title "L' Estasi dell'Oro"), is one of the Western compositions that most represent the genius of Ennio Morricone. Composed for the movie: "The Good, The Bad and The Ugly", directed by Sergio Leone, the Western theme simply became one of the most iconic music masterpiece in Cinema's history. The legendary music of ...