Gestion des armes dans hotbar

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

View File

@ -3071,29 +3071,30 @@ export class RdDActor extends RdDBaseActor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getArmeCompetence(arme) { getArmeCompetence(arme, competenceName) {
let comp = arme.system.competence let comp = arme.system[competenceName]
if (!comp || comp.name == "") { if (!comp || comp.name == "") {
comp = arme.system.lancer comp = arme.system[competenceName]
} }
if ( !comp || comp.name == "") { if ( !comp || comp.name == "") {
comp = arme.system.tir comp = arme.system[competenceName]
} }
return comp return comp
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
rollArme(arme) { rollArme(arme, competenceName = "competence") {
let compToUse = this.getArmeCompetence(arme, competenceName)
if (!Targets.hasTargets()) { if (!Targets.hasTargets()) {
RdDConfirm.confirmer({ RdDConfirm.confirmer({
settingConfirmer: "confirmer-combat-sans-cible", settingConfirmer: "confirmer-combat-sans-cible",
content: `<p>Voulez vous faire un jet de compétence ${arme.system.competence} sans choisir de cible valide? content: `<p>Voulez vous faire un jet de compétence ${competenceName} sans choisir de cible valide?
<br>Tous les jets de combats devront être gérés à la main <br>Tous les jets de combats devront être gérés à la main
</p>`, </p>`,
title: 'Ne pas utiliser les automatisation de combat', title: 'Ne pas utiliser les automatisation de combat',
buttonLabel: "Pas d'automatisation", buttonLabel: "Pas d'automatisation",
onAction: async () => { onAction: async () => {
this.rollCompetence(this.getArmeCompetence(arme), { tryTarget: false }) this.rollCompetence(compToUse, { tryTarget: false })
} }
}); });
return; return;
@ -3105,8 +3106,8 @@ export class RdDActor extends RdDBaseActor {
return; return;
} }
const competence = this.getCompetence(this.getArmeCompetence(arme)) const competence = this.getCompetence(compToUse)
console.log("RollArme", competence, arme) //console.log("RollArme", competence, arme)
if (competence.isCompetencePossession()) { if (competence.isCompetencePossession()) {
return RdDPossession.onAttaquePossession(target, this, competence); return RdDPossession.onAttaquePossession(target, this, competence);
} }

View File

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