adds macro support to skills/talents
parent
39a408fb3d
commit
5275a59b70
41
src/main.mjs
41
src/main.mjs
|
|
@ -190,39 +190,44 @@ Hooks.on('dropActorSheetData', (actor, sheet, data) => {
|
||||||
|
|
||||||
Hooks.once("ready", async function () {
|
Hooks.once("ready", async function () {
|
||||||
// Wait to register hotbar drop hook on ready so that modules could register earlier if they want to
|
// 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)
|
console.log(data, slot)
|
||||||
if (data.type !== "Item") return;
|
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
|
// Create the macro command
|
||||||
const command = `game.DSA41.rollItemMacro("${item.name}");`;
|
const command = `game.DSA41.rollItemMacro("${data.uuid}");`;
|
||||||
let macro = game.macros.entities.find(m => (m.name === item.name) && (m.command === command));
|
|
||||||
if (!macro) {
|
const macro = await Macro.create({
|
||||||
macro = await Macro.create({
|
|
||||||
name: item.name,
|
name: item.name,
|
||||||
type: "script",
|
type: "script",
|
||||||
img: item.img,
|
img: item.img,
|
||||||
command: command,
|
command: command,
|
||||||
flags: {"dsa41.itemMacro": true}
|
flags: {"dsa41.skillMacro": true}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
game.user.assignHotbarMacro(macro, slot);
|
game.user.assignHotbarMacro(macro, slot);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function rollItemMacro(itemName) {
|
function rollItemMacro(_uuid) {
|
||||||
const speaker = ChatMessage.getSpeaker();
|
const speaker = ChatMessage.getSpeaker();
|
||||||
let actor;
|
const uuid = foundry.utils.parseUuid(_uuid)
|
||||||
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
const itemId = uuid.id;
|
||||||
if (!actor) actor = game.actors.get(speaker.actor);
|
const actorId = uuid.primaryId;
|
||||||
const item = actor ? actor.items.find(i => i.name === itemName) : null;
|
let actor = game.actors.get(actorId);
|
||||||
if (!item) return ui.notifications.warn(`Your controlled Actor does not have an item named ${itemName}`);
|
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.system.roll();
|
||||||
return item.roll();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,25 +41,25 @@ export class SkillDataModel extends BaseItem {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async roll() {
|
async roll() {
|
||||||
console.log(this.parent)
|
const owner = this.parent.parent
|
||||||
let roll1 = new Roll("3d20", this.actor.getRollData());
|
let roll1 = new Roll("3d20", owner.getRollData());
|
||||||
|
|
||||||
let evaluated1 = (await roll1.evaluate())
|
let evaluated1 = (await roll1.evaluate())
|
||||||
|
|
||||||
const dsaDieRollEvaluated = this._evaluateRoll(evaluated1.terms[0].results, {
|
const dsaDieRollEvaluated = this._evaluateRoll(evaluated1.terms[0].results, {
|
||||||
taw: dataset.taw,
|
taw: this.taw,
|
||||||
werte: [this.system.probe[0], this.system.probe[1], this.system.probe[2]],
|
werte: [this.probe[0], this.probe[1], this.probe[2]],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (dsaDieRollEvaluated.tap >= 0) { // erfolg
|
if (dsaDieRollEvaluated.tap >= 0) { // erfolg
|
||||||
evaluated1.toMessage({
|
evaluated1.toMessage({
|
||||||
speaker: ChatMessage.getSpeaker({actor: this.actor}),
|
speaker: ChatMessage.getSpeaker({actor: owner}),
|
||||||
flavor: ` ${dsaDieRollEvaluated.meisterlich ? 'Meisterlich geschafft' : 'Geschafft'} mit ${dsaDieRollEvaluated.tap} Punkten übrig`,
|
flavor: ` ${dsaDieRollEvaluated.meisterlich ? 'Meisterlich geschafft' : 'Geschafft'} mit ${dsaDieRollEvaluated.tap} Punkten übrig`,
|
||||||
rollMode: game.settings.get('core', 'rollMode'),
|
rollMode: game.settings.get('core', 'rollMode'),
|
||||||
})
|
})
|
||||||
} else { // misserfolg
|
} else { // misserfolg
|
||||||
evaluated1.toMessage({
|
evaluated1.toMessage({
|
||||||
speaker: ChatMessage.getSpeaker({actor: this.actor}),
|
speaker: ChatMessage.getSpeaker({actor: owner}),
|
||||||
flavor: ` ${dsaDieRollEvaluated.meisterlich ? 'Gepatzt' : ''} mit ${Math.abs(dsaDieRollEvaluated.tap)} Punkten daneben`,
|
flavor: ` ${dsaDieRollEvaluated.meisterlich ? 'Gepatzt' : ''} mit ${Math.abs(dsaDieRollEvaluated.tap)} Punkten daneben`,
|
||||||
rollMode: game.settings.get('core', 'rollMode'),
|
rollMode: game.settings.get('core', 'rollMode'),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Find all items on the character sheet.
|
||||||
html.find('.talent.rollable').each((i, li) => {
|
html.find('.talent.rollable').each((i, li) => {
|
||||||
// Add draggable attribute and dragstart listener.
|
// Add draggable attribute and dragstart listener.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<div class="block rollable {{this.type}} {{this.gruppe}}" data-id="{{this.id}}" data-taw="{{this.taw}}"
|
<div class="block rollable {{this.type}} {{this.gruppe}}" data-item-id="{{this.id}}" data-id="{{this.id}}"
|
||||||
|
data-taw="{{this.taw}}"
|
||||||
data-name="{{this.name}}" data-eigenschaft1="{{this.eigenschaft1}}" data-eigenschaft2="{{this.eigenschaft2}}"
|
data-name="{{this.name}}" data-eigenschaft1="{{this.eigenschaft1}}" data-eigenschaft2="{{this.eigenschaft2}}"
|
||||||
data-eigenschaft3="{{this.eigenschaft3}}" data-rollEigenschaft1="{{this.rollEigenschaft1}}"
|
data-eigenschaft3="{{this.eigenschaft3}}" data-rollEigenschaft1="{{this.rollEigenschaft1}}"
|
||||||
data-rollEigenschaft2="{{this.rollEigenschaft2}}" data-rollEigenschaft3="{{this.rollEigenschaft3}}">
|
data-rollEigenschaft2="{{this.rollEigenschaft2}}" data-rollEigenschaft3="{{this.rollEigenschaft3}}">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue