diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 790a6b8e..b1716797 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -81,9 +81,12 @@ export class RdDActorSheet extends RdDBaseActorSheet { }); // toujours avoir une liste d'armes (pour mettre esquive et corps à corps) - formData.combat = duplicate(formData.armes ?? []); + const actor = this.actor; + formData.combat = duplicate(formData.armes); RdDItemArme.computeNiveauArmes(formData.combat, formData.competences); - RdDItemArme.ajoutCorpsACorps(formData.combat, formData.competences, formData.system.carac); + formData.combat.push(RdDItemArme.mainsNues(actor)); + formData.combat.push(RdDItemArme.empoignade(actor)); + formData.esquives = this.actor.getCompetences("Esquive"); formData.combat = RdDCombatManager.listActionsArmes(formData.combat, formData.competences, formData.system.carac); formData.empoignades = this.actor.getEmpoignades(); diff --git a/module/actor.js b/module/actor.js index be0b90cf..b3f0e5f5 100644 --- a/module/actor.js +++ b/module/actor.js @@ -241,6 +241,12 @@ export class RdDActor extends RdDBaseActor { getCompetences(name) { return RdDItemCompetence.findCompetences(this.items, name) } + getCompetenceCorpsACorps(options = {}) { + return this.getCompetence("Corps à corps", options) + } + getCompetencesEsquive() { + return this.getCompetences("esquive") + } /* -------------------------------------------- */ getTache(id) { return this.findItemLike(id, 'tache'); @@ -3084,7 +3090,7 @@ export class RdDActor extends RdDBaseActor { switch (competenceName) { case 'competence': return arme.system.competence; case 'unemain': return RdDItemArme.competence1Mains(arme); - case 'deuxmains': return RdDItemArme.competence2Mains(arme); + case 'deuxmains': return RdDItemArme.competence2Mains(arme); case 'tir': return arme.system.tir; case 'lancer': return arme.system.lancer; } diff --git a/module/item-arme.js b/module/item-arme.js index f1fa40c7..bbc87102 100644 --- a/module/item-arme.js +++ b/module/item-arme.js @@ -169,19 +169,21 @@ export class RdDItemArme extends Item { return arme.type == 'arme' && arme.system.equipe && (arme.system.resistance > 0 || arme.system.portee_courte > 0); } - static ajoutCorpsACorps(armes, competences, carac) { - let corpsACorps = competences.find(it => it.name == 'Corps à corps') ?? { system: { niveau: -6 } }; - let init = RdDCombatManager.calculInitiative(corpsACorps.system.niveau, carac['melee'].value); - armes.push(RdDItemArme.mainsNues({ niveau: corpsACorps.system.niveau, initiative: init })); - armes.push(RdDItemArme.empoignade({ niveau: corpsACorps.system.niveau, initiative: init })); + static ajoutCorpsACorps(armes, actor) { + armes.push(RdDItemArme.mainsNues(actor)); + armes.push(RdDItemArme.empoignade(actor)); } - static corpsACorps(mainsNuesActor) { - const corpsACorps = { + static corpsACorps(actor) { + let competence = actor?.getCompetenceCorpsACorps() ?? { system: { niveau: -6 } }; + let melee = actor? actor.system.carac['melee'].value : 0 + return { + _id: competence?.id, name: 'Corps à corps', type: TYPES.arme, img: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp', system: { + initiative: RdDCombatManager.calculInitiative(competence.system.niveau, melee), equipe: true, rapide: true, force: 0, @@ -192,21 +194,19 @@ export class RdDItemArme extends Item { deuxmains: true, categorie_parade: 'sans-armes' } - }; - mergeObject(corpsACorps.system, mainsNuesActor ?? {}, { overwrite: false }); - return corpsACorps; + } } - static mainsNues(mainsNuesActor) { - const mainsNues = RdDItemArme.corpsACorps(mainsNuesActor) + static mainsNues(actor) { + const mainsNues = RdDItemArme.corpsACorps(actor) mainsNues.name = 'Mains nues' mainsNues.system.cac = 'pugilat' mainsNues.system.baseInit = 4 return mainsNues; } - static empoignade(mainsNuesActor) { - const empoignade = RdDItemArme.corpsACorps(mainsNuesActor) + static empoignade(actor) { + const empoignade = RdDItemArme.corpsACorps(actor) empoignade.name = 'Empoignade' empoignade.system.cac = 'empoignade' empoignade.system.baseInit = 3 diff --git a/module/item-competence.js b/module/item-competence.js index 665e7d0f..19692f35 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -79,10 +79,9 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static isCompetenceArme(competence) { - if (competence.isCompetence()) { + if (competence.isCompetence() && !competence.isCorpsACorps() && !competence.isEsquive()) { switch (competence.system.categorie) { case 'melee': - return !Grammar.toLowerCaseNoAccent(competence.name).includes('esquive'); case 'tir': case 'lancer': return true; @@ -93,10 +92,10 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static isArmeUneMain(competence) { - return RdDItemCompetence.isCompetenceArme(competence) && competence.name.toLowerCase().includes("1 main"); + return competence.isCompetenceArme() && competence.name.toLowerCase().includes("1 main"); } static isArme2Main(competence) { - return RdDItemCompetence.isCompetenceArme(competence) && competence.name.toLowerCase().includes("2 main"); + return competence.isCompetenceArme() && competence.name.toLowerCase().includes("2 main"); } static isThanatos(competence) { diff --git a/module/item-sheet.js b/module/item-sheet.js index e2f5bd7c..e8864c86 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -113,7 +113,7 @@ export class RdDItemSheet extends ItemSheet { formData.competences = competences; } if (this.item.type == 'arme') { - formData.competences = competences.filter(it => RdDItemCompetence.isCompetenceArme(it)) + formData.competences = competences.filter(it => it.isCompetenceArme()) } if (['sort', 'sortreserve'].includes(this.item.type)) { formData.competences = competences.filter(it => RdDItemCompetence.isDraconic(it)); diff --git a/module/item.js b/module/item.js index 946e0a3d..35c1b053 100644 --- a/module/item.js +++ b/module/item.js @@ -220,6 +220,32 @@ export class RdDItem extends Item { isService() { return this.type == TYPES.service; } isCompetence() { return typesObjetsCompetence.includes(this.type) } + isEsquive() { + return (this.isCompetence() + && this.system.categorie == 'melee' + && Grammar.includesLowerCaseNoAccent(this.name, 'Esquive')); + } + + isCorpsACorps() { + return (this.isCompetence() + && this.system.categorie == 'melee' + && Grammar.includesLowerCaseNoAccent(this.name, 'Corps à Corps')); + } + + isCompetenceArme() { + if (this.isCompetence()) { + switch (this.system.categorie) { + case 'melee': + return !this.isCorpsACorps() && !this.isEsquive() + case 'tir': + case 'lancer': + return true; + } + } + return false; + } + + isCompetencePossession() { return TYPES.competencecreature == this.type && this.system.categorie == "possession" } isTemporel() { return typesObjetsTemporels.includes(this.type) } isOeuvre() { return typesObjetsOeuvres.includes(this.type) } diff --git a/module/rdd-combat.js b/module/rdd-combat.js index ad434ba0..ee434acd 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -75,7 +75,7 @@ export class RdDCombatManager extends Combat { } } } - + /************************************************************************************/ async rollInitiative(ids, formula = undefined, messageOptions = {}) { console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions); @@ -257,11 +257,10 @@ export class RdDCombatManager extends Combat { actions = RdDCombatManager.listActionsCreature(actor.itemTypes['competencecreature']); } else if (actor.isPersonnage()) { // Recupération des items 'arme' - const armes = actor.itemTypes['arme'].filter(it => RdDItemArme.isArmeUtilisable(it)) - .concat(RdDItemArme.empoignade()) - .concat(RdDItemArme.mainsNues()); - const competences = actor.itemTypes['competence']; + const armes = actor.itemTypes['arme'].filter(it => RdDItemArme.isArmeUtilisable(it)) + .concat(RdDItemArme.empoignade(actor)) + .concat(RdDItemArme.mainsNues(actor)); actions = RdDCombatManager.listActionsArmes(armes, competences, actor.system.carac); if (actor.system.attributs.hautrevant.value) { @@ -884,8 +883,8 @@ export class RdDCombat { } // # utilisation esquive - const corpsACorps = this.defender.getCompetence("Corps à corps", { onMessage: it => console.info(it, this.defender) }); - const esquives = duplicate(this.defender.getCompetences("esquive", { onMessage: it => console.info(it, this.defender) })) + const corpsACorps = this.defender.getCompetenceCorpsACorps({ onMessage: it => console.info(it, this.defender) }); + const esquives = duplicate(this.defender.getCompetencesEsquive()) esquives.forEach(e => e.system.nbUsage = e?._id ? this.defender.getItemUse(e._id) : 0); const paramChatDefense = { diff --git a/module/rdd-empoignade.js b/module/rdd-empoignade.js index 0694dc79..3991dd0c 100644 --- a/module/rdd-empoignade.js +++ b/module/rdd-empoignade.js @@ -181,7 +181,7 @@ export class RdDEmpoignade { let rollData = { mode, empoignade, attacker, defender, isEmpoignade: true, - competence: attacker.getCompetence("Corps à corps"), + competence: attacker.getCompetenceCorpsACorps(), selectedCarac: attacker.system.carac.melee, malusTaille: RdDEmpoignade.getMalusTaille(empoignade, attacker, defender) } @@ -210,7 +210,7 @@ export class RdDEmpoignade { mode: "immobilise", empoignade, attacker, defender, isEmpoignade: true, - competence: attacker.getCompetence("Corps à corps") + competence: attacker.getCompetenceCorpsACorps() } const msg = await ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(attacker.name), diff --git a/module/rdd-hotbar-drop.js b/module/rdd-hotbar-drop.js index e00e435b..f7229155 100644 --- a/module/rdd-hotbar-drop.js +++ b/module/rdd-hotbar-drop.js @@ -1,4 +1,4 @@ -import { RdDItemCompetence } from "./item-competence.js"; +import { RdDItemArme } from "./item-arme.js"; import { RdDItemCompetenceCreature } from "./item-competencecreature.js"; import { TYPES } from "./item.js"; @@ -6,9 +6,9 @@ export class RdDHotbar { static async createItemMacro(item, slot, armeCompetence = undefined) { const itemName = item.name; + let macroName = itemName + RdDHotbar.$macroNameSuffix(armeCompetence); let command = `game.system.rdd.RdDHotbar.rollMacro("${itemName}", "${item.type}", "${armeCompetence}");` let macro = game.macros.contents.find(m => (m.name === itemName) && (m.command === command)); - let macroName = itemName + RdDHotbar.$macroNameSuffix(armeCompetence); if (!macro) { macro = await Macro.create({ name: macroName, @@ -20,12 +20,15 @@ export class RdDHotbar { await game.user.assignHotbarMacro(macro, slot); } - static $macroNameSuffix(armeCompetence){ - switch(armeCompetence) { + static $macroNameSuffix(armeCompetence) { + switch (armeCompetence) { case 'unemain': return ' (1 main)'; - case 'deuxmains': return ' (2 main)'; + case 'deuxmains': return ' (2 main)'; case 'tir': return ' (tir)'; case 'lancer': return ' (lancer)'; + case 'pugilat': return ' (pugilat)'; + case 'empoignade': return ' (empoignade)'; + } return '' } @@ -37,21 +40,17 @@ export class RdDHotbar { // Les armes peuvent avoir plusieurs usages if (item.system.competence != '') { if (item.system.unemain) { - await this.createItemMacro(item, slot, 'unemain') - slot++ + await this.createItemMacro(item, slot++, 'unemain') } if (item.system.deuxmains) { - await this.createItemMacro(item, slot, 'deuxmains') - slot++ + await this.createItemMacro(item, slot++, 'deuxmains') } } if (item.system.lancer != '') { - await this.createItemMacro(item, slot, 'lancer') - slot++ + await this.createItemMacro(item, slot++, 'lancer') } if (item.system.tir != '') { - await this.createItemMacro(item, slot, 'lancer') - slot++ + await this.createItemMacro(item, slot++, 'lancer') } } return @@ -61,10 +60,15 @@ export class RdDHotbar { return default: case TYPES.competence: - if (RdDItemCompetence.isCompetenceArme(item)) { - ui.notifications.info(`La compétence de ${item.name} est une compétence d'arme, choisissez plutôt de créer la macro depuis l'onglet combat`); + await this.createItemMacro(item, slot++, 'competence') + if (item.isCorpsACorps()) { + await this.createItemMacro(item, slot++, 'pugilat') + await this.createItemMacro(item, slot++, 'empoignade') + } + if (item.isCompetenceArme()) { + ui.notifications.info(`${item.name} est une compétence d'arme, la macro n'est pas liée à un arme.
+ Créez la macro depuis l'arme ou l'onglet combat pour garder les automatisations de combat.`); } - await this.createItemMacro(item, slot, 'competence') return } } @@ -115,6 +119,14 @@ export class RdDHotbar { case TYPES.arme: return actor.rollArme(item, categorieArme); case TYPES.competence: + if (item.isCorpsACorps()) { + switch (categorieArme) { + case 'pugilat': + return actor.rollArme(RdDItemArme.mainsNues(actor), 'competence'); + case 'empoignade': + return actor.rollArme(RdDItemArme.empoignade(actor), 'competence'); + } + } return actor.rollCompetence(item); case TYPES.competencecreature: return item.system.iscombat && !item.system.isparade