2024-05-16 17:30:42 +00:00
|
|
|
/**
|
|
|
|
* Extend the basic Item with some very simple modifications.
|
|
|
|
* @extends {Item}
|
|
|
|
*/
|
2024-05-16 17:51:39 +00:00
|
|
|
export class BoilerplateItem extends Item {
|
|
|
|
/**
|
|
|
|
* Augment the basic Item data model with additional dynamic data.
|
|
|
|
*/
|
|
|
|
prepareData() {
|
|
|
|
// As with the actor class, items are documents that can have their data
|
|
|
|
// preparation methods overridden (such as prepareBaseData()).
|
|
|
|
super.prepareData();
|
|
|
|
}
|
2024-05-16 17:30:42 +00:00
|
|
|
|
2024-05-16 17:51:39 +00:00
|
|
|
/**
|
|
|
|
* Prepare a data object which defines the data schema used by dice roll commands against this Item
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
getRollData() {
|
|
|
|
// Starts off by populating the roll data with `this.system`
|
|
|
|
const rollData = { ...super.getRollData() };
|
2024-05-16 17:30:42 +00:00
|
|
|
|
2024-05-16 17:51:39 +00:00
|
|
|
// Quit early if there's no parent actor
|
|
|
|
if (!this.actor) return rollData;
|
|
|
|
|
|
|
|
// If present, add the actor's roll data
|
|
|
|
rollData.actor = this.actor.getRollData();
|
2024-05-16 17:30:42 +00:00
|
|
|
|
2024-05-16 17:51:39 +00:00
|
|
|
return rollData;
|
|
|
|
}
|
2024-05-16 17:30:42 +00:00
|
|
|
|
2024-05-16 17:51:39 +00:00
|
|
|
/**
|
|
|
|
* Handle clickable rolls.
|
|
|
|
* @param {Event} event The originating click event
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async roll() {
|
|
|
|
const item = this;
|
2024-05-16 17:30:42 +00:00
|
|
|
|
2024-05-16 17:51:39 +00:00
|
|
|
// Initialize chat data.
|
|
|
|
const speaker = ChatMessage.getSpeaker({ actor: this.actor });
|
|
|
|
const rollMode = game.settings.get('core', 'rollMode');
|
|
|
|
const label = `[${item.type}] ${item.name}`;
|
|
|
|
|
|
|
|
// If there's no roll data, send a chat message.
|
|
|
|
if (!this.system.formula) {
|
|
|
|
ChatMessage.create({
|
|
|
|
speaker: speaker,
|
|
|
|
rollMode: rollMode,
|
|
|
|
flavor: label,
|
|
|
|
content: item.system.description ?? '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Otherwise, create a roll and send a chat message from it.
|
|
|
|
else {
|
|
|
|
// Retrieve roll data.
|
|
|
|
const rollData = this.getRollData();
|
2024-05-16 17:30:42 +00:00
|
|
|
|
2024-05-16 17:51:39 +00:00
|
|
|
// Invoke the roll and submit it to chat.
|
|
|
|
const roll = new Roll(rollData.formula, rollData);
|
|
|
|
// If you need to store the value first, uncomment the next line.
|
|
|
|
// const result = await roll.evaluate();
|
|
|
|
roll.toMessage({
|
|
|
|
speaker: speaker,
|
|
|
|
rollMode: rollMode,
|
|
|
|
flavor: label,
|
|
|
|
});
|
|
|
|
return roll;
|
2024-05-16 17:30:42 +00:00
|
|
|
}
|
2024-05-16 17:51:39 +00:00
|
|
|
}
|
2024-05-16 17:30:42 +00:00
|
|
|
}
|