Gestion des armes dans hotbar

This commit is contained in:
2023-10-04 09:33:24 +02:00
parent 76a02d60ca
commit de5d32f88f
2 changed files with 33 additions and 13 deletions

View File

@ -1,8 +1,8 @@
export class RdDHotbar {
static async addToHotbar(item, slot) {
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}");`;
static async createItemMacro(item, slot, armeCompetence = undefined) {
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}"` + ((armeCompetence) ? `, "${armeCompetence}");` : `);`);
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
@ -15,6 +15,25 @@ export class RdDHotbar {
await game.user.assignHotbarMacro(macro, slot);
}
static async addToHotbar(item, slot) {
if (item?.type == "arme") { // Used to manage weapons with multiple skills
if (item.system.competence != "") {
await this.createItemMacro(item, slot, "competence")
slot++
}
if (item.system.lancer != "") {
await this.createItemMacro(item, slot, "lancer")
slot++
}
if (item.system.tir != "") {
await this.createItemMacro(item, slot, "lancer")
slot++
}
} else {
await this.createItemMacro(item, slot)
}
}
/**
* Create a macro when dropping an entity on the hotbar
* Item - open roll dialog for item
@ -44,7 +63,7 @@ export class RdDHotbar {
}
/** Roll macro */
static rollMacro(itemName, itemType, bypassData) {
static rollMacro(itemName, itemType, competenceName) {
const speaker = ChatMessage.getSpeaker();
let actor;
if (speaker.token) actor = game.actors.tokens[speaker.token];
@ -58,7 +77,7 @@ export class RdDHotbar {
// Trigger the item roll
switch (item.type) {
case "arme":
return actor.rollArme(item);
return actor.rollArme(item, competenceName);
case "competence":
return actor.rollCompetence(itemName);
}