diff --git a/src/main.mjs b/src/main.mjs index 13cc781c..d2e4b714 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -190,39 +190,44 @@ Hooks.on('dropActorSheetData', (actor, sheet, data) => { Hooks.once("ready", async function () { // Wait to register hotbar drop hook on ready so that modules could register earlier if they want to - Hooks.on("hotbarDrop", (bar, data, slot) => createBoilerplateMacro(data, slot)); + Hooks.on("hotbarDrop", (bar, data, slot) => { + return createTalentMacro(data, slot) + }); }); -async function createBoilerplateMacro(data, slot) { +async function createTalentMacro(data, slot) { console.log(data, slot) if (data.type !== "Item") return; - if (!("data" in data)) return ui.notifications.warn("You can only create macro buttons for owned Items"); - const item = data.data; + + const uuid = foundry.utils.parseUuid(data.uuid) + + const itemId = uuid.id; + const actorId = uuid.primaryId; + const item = await game.actors.get(actorId).items.get(itemId); // Create the macro command - const command = `game.DSA41.rollItemMacro("${item.name}");`; - let macro = game.macros.entities.find(m => (m.name === item.name) && (m.command === command)); - if (!macro) { - macro = await Macro.create({ + const command = `game.DSA41.rollItemMacro("${data.uuid}");`; + + const macro = await Macro.create({ name: item.name, type: "script", img: item.img, command: command, - flags: {"dsa41.itemMacro": true} - }); - } + flags: {"dsa41.skillMacro": true} + }); + game.user.assignHotbarMacro(macro, slot); return false; } -function rollItemMacro(itemName) { +function rollItemMacro(_uuid) { const speaker = ChatMessage.getSpeaker(); - let actor; - if (speaker.token) actor = game.actors.tokens[speaker.token]; - if (!actor) actor = game.actors.get(speaker.actor); - const item = actor ? actor.items.find(i => i.name === itemName) : null; - if (!item) return ui.notifications.warn(`Your controlled Actor does not have an item named ${itemName}`); + const uuid = foundry.utils.parseUuid(_uuid) + const itemId = uuid.id; + const actorId = uuid.primaryId; + let actor = game.actors.get(actorId); + const item = actor ? actor.items.get(itemId) : null; + if (!item) return ui.notifications.warn(`Your controlled Actor does not have an item with id ${itemId}`); - // Trigger the item roll - return item.roll(); + return item.system.roll(); } diff --git a/src/module/data/skill.mjs b/src/module/data/skill.mjs index c07580c2..ca23862e 100644 --- a/src/module/data/skill.mjs +++ b/src/module/data/skill.mjs @@ -41,25 +41,25 @@ export class SkillDataModel extends BaseItem { * @private */ async roll() { - console.log(this.parent) - let roll1 = new Roll("3d20", this.actor.getRollData()); + const owner = this.parent.parent + let roll1 = new Roll("3d20", owner.getRollData()); let evaluated1 = (await roll1.evaluate()) const dsaDieRollEvaluated = this._evaluateRoll(evaluated1.terms[0].results, { - taw: dataset.taw, - werte: [this.system.probe[0], this.system.probe[1], this.system.probe[2]], + taw: this.taw, + werte: [this.probe[0], this.probe[1], this.probe[2]], }) if (dsaDieRollEvaluated.tap >= 0) { // erfolg evaluated1.toMessage({ - speaker: ChatMessage.getSpeaker({actor: this.actor}), + speaker: ChatMessage.getSpeaker({actor: owner}), flavor: ` ${dsaDieRollEvaluated.meisterlich ? 'Meisterlich geschafft' : 'Geschafft'} mit ${dsaDieRollEvaluated.tap} Punkten übrig`, rollMode: game.settings.get('core', 'rollMode'), }) } else { // misserfolg evaluated1.toMessage({ - speaker: ChatMessage.getSpeaker({actor: this.actor}), + speaker: ChatMessage.getSpeaker({actor: owner}), flavor: ` ${dsaDieRollEvaluated.meisterlich ? 'Gepatzt' : ''} mit ${Math.abs(dsaDieRollEvaluated.tap)} Punkten daneben`, rollMode: game.settings.get('core', 'rollMode'), }) diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs index 44958b23..da3f6dc4 100644 --- a/src/module/sheets/characterSheet.mjs +++ b/src/module/sheets/characterSheet.mjs @@ -932,7 +932,15 @@ export class CharacterSheet extends ActorSheet { } ]); - let handler = ev => this._onDragStart(ev); + let handler = evt => { + const talentId = evt.target.dataset.id + evt.dataTransfer.setData("application/json", JSON.stringify({ + talentId + })); + this._onDragStart(evt) + + } + // Find all items on the character sheet. html.find('.talent.rollable').each((i, li) => { // Add draggable attribute and dragstart listener. diff --git a/src/templates/ui/partial-rollable-button.hbs b/src/templates/ui/partial-rollable-button.hbs index 50ecbef6..535886b1 100644 --- a/src/templates/ui/partial-rollable-button.hbs +++ b/src/templates/ui/partial-rollable-button.hbs @@ -1,4 +1,5 @@ -