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) {
let comp = arme.system.competence
getArmeCompetence(arme, competenceName) {
let comp = arme.system[competenceName]
if (!comp || comp.name == "") {
comp = arme.system.lancer
comp = arme.system[competenceName]
}
if ( !comp || comp.name == "") {
comp = arme.system.tir
comp = arme.system[competenceName]
}
return comp
}
/* -------------------------------------------- */
rollArme(arme) {
rollArme(arme, competenceName = "competence") {
let compToUse = this.getArmeCompetence(arme, competenceName)
if (!Targets.hasTargets()) {
RdDConfirm.confirmer({
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
</p>`,
title: 'Ne pas utiliser les automatisation de combat',
buttonLabel: "Pas d'automatisation",
onAction: async () => {
this.rollCompetence(this.getArmeCompetence(arme), { tryTarget: false })
this.rollCompetence(compToUse, { tryTarget: false })
}
});
return;
@ -3105,8 +3106,8 @@ export class RdDActor extends RdDBaseActor {
return;
}
const competence = this.getCompetence(this.getArmeCompetence(arme))
console.log("RollArme", competence, arme)
const competence = this.getCompetence(compToUse)
//console.log("RollArme", competence, arme)
if (competence.isCompetencePossession()) {
return RdDPossession.onAttaquePossession(target, this, competence);
}

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);
}