diff --git a/module/actor-sheet.js b/module/actor-sheet.js index e2f6c4fe..10324999 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -5,6 +5,8 @@ import { RdDUtility } from "./rdd-utility.js"; import { HtmlUtility } from "./html-utility.js"; +import { RdDItem } from "./item.js"; +import { RdDItemArme } from "./item-arme.js"; /* -------------------------------------------- */ export class RdDActorSheet extends ActorSheet { @@ -34,7 +36,7 @@ export class RdDActorSheet extends ActorSheet { data.data.montrerArchetype = this.options.montrerArchetype; let compCategorieNiveau = RdDUtility.getLevelCategory(); // recup catégorie - data.itemsByType = RdDUtility.buildItemsClassification(data.items); + data.itemsByType = RdDItem.buildItemsClassification(data.items); // Competence per category data.competenceByCategory = {}; @@ -92,16 +94,16 @@ export class RdDActorSheet extends ActorSheet { // To avoid armour and so on... data.data.combat = duplicate( RdDUtility.checkNull(data.itemsByType['arme'])); - data.data.combat = RdDUtility.finalizeArmeList( data.data.combat, data.itemsByType.competence, data.data.carac ); + data.data.combat = RdDUtility._finalizeArmeList( data.data.combat, data.itemsByType.competence, data.data.carac ); if (data.competenceByCategory && data.competenceByCategory.melee) { //Specific case for Esquive and Corps à Corps for ( const melee of data.competenceByCategory.melee ) { if (melee.name == "Esquive") - data.data.combat.push( { name: "Esquive", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: "-", competence: "Esquive", dommages: 0} } ); + data.data.combat.push( { name: "Esquive", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: "", competence: "Esquive", dommages: 0} } ); if (melee.name == "Corps à corps") { let cc_init = RdDUtility.calculInitiative(melee.data.niveau, data.data.carac['melee'].value); - data.data.combat.push( { name: "Corps à corps", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: cc_init, competence: "Corps à corps", dommages: data.data.attributs.plusdom.value } } ); + data.data.combat.push( RdDItemArme.mainsNues({ niveau: melee.data.niveau, initiative: cc_init }) ); } } } diff --git a/module/actor.js b/module/actor.js index 5d08602a..8197574e 100644 --- a/module/actor.js +++ b/module/actor.js @@ -16,6 +16,7 @@ import { RdDCombat } from "./rdd-combat.js"; import { DeDraconique } from "./de-draconique.js"; import { RdDAudio } from "./rdd-audio.js"; import { RdDItemCompetence } from "./item-competence.js"; +import { RdDItemArme } from "./item-arme.js"; /* -------------------------------------------- */ /** @@ -1985,14 +1986,12 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - rollArme(compName, armeName = undefined) { - - let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName)); - if (armeItem && compName == undefined) compName = armeItem.data.competence; - let competence = this.getCompetence(compName == undefined? armeName : compName); + rollArme(compName, armeName = undefined) { + let arme = this.data.items.find( item => item.name == armeName && RdDItemArme.isArme(item)); + let competence = this.getCompetence(compName); - if (armeItem || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) { - RdDCombat.createUsingTarget(this).attaque(competence, armeItem); + if (arme || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) { + RdDCombat.createUsingTarget(this).attaque(competence, arme); } else { this.rollCompetence( competence.name ); } @@ -2113,7 +2112,7 @@ export class RdDActor extends Actor { } this.computeEtatGeneral(); - this.sheet.render(true); + this.sheet.render(false); } /* -------------------------------------------- */ diff --git a/module/item-arme.js b/module/item-arme.js index 4d01b10d..f3bec50e 100644 --- a/module/item-arme.js +++ b/module/item-arme.js @@ -1,4 +1,4 @@ - +import { RdDItemCompetenceCreature } from "./item-competencecreature.js" const nomCcategorieParade = { "sans-armes": "Sans arme / armes naturelles", @@ -13,34 +13,29 @@ const nomCcategorieParade = { "lances": "Lances", } - +/* -------------------------------------------- */ export class RdDItemArme extends Item { + static isArme(item) { + return (item.type == 'competencecreature' && item.data.iscombat) || item.type == 'arme'; + } + /* -------------------------------------------- */ static getArmeData(item) { switch (item ? item.data.type : '') { case 'arme': return item.data; case 'competencecreature': - return RdDItemArme._getArmeCompetenceCreature(item); + return RdDItemCompetenceCreature.toArme(item); } return RdDItemArme.mainsNues(); } - /* -------------------------------------------- */ - static _getArmeCompetenceCreature(competenceCreature) { - let armeData = duplicate(competenceCreature.data); - armeData.data.resistance = 100; - armeData.data.competence = armeData.name; - armeData.data.dommagesReels = armeData.data.dommagesReels || armeData.data.dommages; - return armeData; - } - /* -------------------------------------------- */ static getNomCategorieParade(it) { - const categorie = it.data? RdDItemArme.getCategorieParade(it) : it; + const categorie = it.data ? RdDItemArme.getCategorieParade(it) : it; return nomCcategorieParade[categorie]; } - + /* -------------------------------------------- */ static getCategorieParade(arme) { if (arme.data.categorie_parade) { @@ -134,11 +129,24 @@ export class RdDItemArme extends Item { return arme; } - static mainsNues() { + + static mainsNues(actorData={}) { const mainsNues = { name: 'Mains nues', - data: { unemain: true, deuxmains: false, dommages: 0, dommagesReels: 0, mortalite: 'non-mortel', competence: 'Corps à corps', categorie_parade: 'sans-armes' } + data: { + equipe: true, + rapide: true, + force: 0, + dommages: 0, + dommagesReels: 0, + mortalite: 'non-mortel', + competence: 'Corps à corps', + categorie_parade: 'sans-armes' + } }; + if (actorData) { + mergeObject( mainsNues.data, actorData, {overwrite:false}); + } return mainsNues } } diff --git a/module/item-competencecreature.js b/module/item-competencecreature.js new file mode 100644 index 00000000..0f2782b4 --- /dev/null +++ b/module/item-competencecreature.js @@ -0,0 +1,23 @@ +/* -------------------------------------------- */ +export class RdDItemCompetenceCreature extends Item { + + /* -------------------------------------------- */ + static toArme(item) { + if (item.type == 'competencecreature' && item.data.iscombat) { + let arme = { name: item.name, data: duplicate(item.data) }; + mergeObject(arme.data, + { + competence: item.name, + resistance: 100, + equipe: true, + penetration: 0, + force: 0, + rapide: true + }); + return arme; + } + console.error("RdDItem.toArme(", item, ") : impossible de transformer l'Item en arme"); + return undefined; + } + +} diff --git a/module/item.js b/module/item.js new file mode 100644 index 00000000..bdd2768f --- /dev/null +++ b/module/item.js @@ -0,0 +1,18 @@ + +/* -------------------------------------------- */ +export class RdDItem { + + /* -------------------------------------------- */ + static buildItemsClassification( items ) { + let itemsByType = {}; + for (const item of items) { + let list = itemsByType[item.type]; + if (!list) { + list = []; + itemsByType[item.type] = list; + } + list.push(item); + } + return itemsByType; + } +} \ No newline at end of file diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 0ffc6d09..8d9ea3f8 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -212,7 +212,7 @@ export class RdDCombat { } else { // sans armes: à mains nues - rollData.arme = RdDItemArme.mainsNues(); + rollData.arme = RdDItemArme.mainsNues({niveau: competence.data.niveau}); } return rollData; } @@ -221,15 +221,13 @@ export class RdDCombat { _onAttaqueParticuliere(rollData) { console.log("RdDCombat.onAttaqueParticuliere >>>", rollData); // Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum - let message = ` -

Réussite particulière en attaque

-
Attaquer en Force - `; + let message = '

Réussite particulière en attaque

'; + message += `
Attaquer en Force`; if (rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0) { - message += ` -
Attaquer en Rapidité -
Attaquer en Finesse - ` + if (rollData.arme.data.rapide) { + message += `
Attaquer en Rapidité`; + } + message += `
Attaquer en Finesse`; } game.system.rdd.rollDataHandler[this.attackerId] = rollData; // TODO: use a dialog? @@ -299,7 +297,7 @@ export class RdDCombat { /* -------------------------------------------- */ _filterArmesParade(items, competence) { - items = items.filter(item => item.data.equipe == true ); + items = items.filter(item => (item.type == 'arme' && item.data.equipe) || (item.type == 'competencecreature' && item.data.isparade)); switch (competence.data.categorie) { case 'tir': case 'lancer': diff --git a/module/rdd-token-hud.js b/module/rdd-token-hud.js index 490caba3..84cfe534 100644 --- a/module/rdd-token-hud.js +++ b/module/rdd-token-hud.js @@ -17,7 +17,7 @@ export class RdDTokenHud { if (!token.inCombat) return; if (!combatant) return; - let armesList = RdDTokenHud.buildListeActionsCombat(combatant) ; + let armesList = RdDUtility.buildListeActionsCombat(combatant) ; const hudData = { combatant: combatant, armes: armesList }; // initiative @@ -38,16 +38,6 @@ export class RdDTokenHud { }); } - /* -------------------------------------------- */ - static buildListeActionsCombat(combatant) { - let armesList = RdDUtility.buildArmeList(combatant); - for (let armeIndex = 0; armeIndex < armesList.length; armeIndex++) { - armesList[armeIndex] = duplicate(armesList[armeIndex]); - armesList[armeIndex].index = armeIndex; - } - return armesList; - } - /* -------------------------------------------- */ static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) { const hud = $(await renderTemplate(template, hudData)); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 69d65567..7487755a 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -5,6 +5,9 @@ import { ChatUtility } from "./chat-utility.js"; import { RdDItemCompetence } from "./item-competence.js"; import { RdDCombat } from "./rdd-combat.js"; import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js"; +import { RdDItem } from "./item.js"; +import { RdDItemCompetenceCreature } from "./item-competencecreature.js"; +import { RdDItemArme } from "./item-arme.js"; /* -------------------------------------------- */ const level_category = { @@ -464,11 +467,10 @@ export class RdDUtility { /* -------------------------------------------- */ /** Retourne une liste triée d'armes avec le split arme1 main / arme 2 main */ - static finalizeArmeList( armeList, competenceList, carac ) { + static _finalizeArmeList( armes, competenceList, carac ) { // Gestion des armes 1/2 mains - let arme2mains = []; // Tableau contenant la duplication des armes 1m/2m let armesEquipe = []; - for (const arme of armeList) { + for (const arme of armes) { if (arme.data.equipe) { armesEquipe.push( arme ); let comp = competenceList.find(c => c.name == arme.data.competence); @@ -491,9 +493,13 @@ export class RdDUtility { } } } - //armeList = armeList.concat(arme2mains); // Merge all cases - armesEquipe = armesEquipe.sort((a, b) => { if ( a.name > b.name) return 1; else return -1; } ); - return armesEquipe + return armesEquipe.sort((a, b) => { + const nameA = a.name + (a.data.mainInfo ?? ''); + const nameB = b.name + (b.data.mainInfo ?? ''); + if ( nameA > nameB) return 1; + if ( nameA < nameB) return -1; + return 0; + } ); } /* -------------------------------------------- */ @@ -796,20 +802,6 @@ export class RdDUtility { } } - /* -------------------------------------------- */ - static buildItemsClassification( items ) { - let itemsByType = {}; - for (const item of items) { - let list = itemsByType[item.type]; - if (!list) { - list = []; - itemsByType[item.type] = list; - } - list.push(item); - } - return itemsByType; - } - /* -------------------------------------------- */ static rollInitiativeCompetence( combatantId, arme ) { const combatant = game.combat.getCombatant(combatantId); @@ -843,33 +835,36 @@ export class RdDUtility { } /* -------------------------------------------- */ - static buildArmeList( combatant ) { + static buildListeActionsCombat( combatant ) { const actor = combatant.actor; // Easy access - let armesList = []; - if ( actor.data.type == 'creature' || actor.data.type == 'entite') { - for (const competenceItem of actor.data.items) { - if ( competenceItem.data.iscombat) { // Seul un item de type arme - armesList.push( { name: competenceItem.name, data: { niveau: competenceItem.data.niveau, competence: competenceItem.name } } ); - } - } + let items = actor.data.items; + let actions = [] + if ( actor.isCreature()) { + actions = actions.concat(items.filter(it => it.type =='competencecreature' && it.data.iscombat) + .map(competence => RdDItemCompetenceCreature.toArme(competence))); } else { // Recupération des items 'arme' - let itemsByType = RdDUtility.buildItemsClassification( combatant.actor.data.items ); - armesList = itemsByType['arme']; - armesList = this.finalizeArmeList( armesList, itemsByType['competence'], actor.data.data.carac ); - // Force corps à corps et Draconic - let cc = RdDUtility.findCompetence( combatant.actor.data.items, "Corps à corps"); - armesList.push( { name: "Corps à corps", data: { niveau: cc.data.niveau, description: "", force: 6, competence: "Corps à corps", dommages: combatant.actor.data.data.attributs.plusdom.value } } ); - armesList.push( { name: "Draconic", data: { initOnly: true, competence: "Draconic" } } ); + let armes = items.filter(it => it.type =='arme') + .map(arme => duplicate(arme)) /* pas de changements aux armes d'origine */ + .concat(RdDItemArme.mainsNues()); + + let competences = items.filter(it => it.type == 'competence'); + actions = actions.concat(this._finalizeArmeList( armes, competences, actor.data.data.carac )); + + actions.push( { name: "Draconic", data: { initOnly: true, competence: "Draconic" } } ); } - armesList.push( { name: "Autre action", data: { initOnly: true, competence: "Autre action" } } ); - return armesList; + + actions.push( { name: "Autre action", data: { initOnly: true, competence: "Autre action" } } ); + for (let index = 0; index < actions.length; index++) { + actions[index].index = index; + } + return actions; } /* -------------------------------------------- */ static displayInitiativeMenu( html, combatantId) { const combatant = game.combat.getCombatant(combatantId); - let armesList = this.buildArmeList( combatant ); + let armesList = this.buildListeActionsCombat( combatant ); // Build the relevant submenu if ( armesList ) { diff --git a/styles/simple.css b/styles/simple.css index 76ad3e7f..6e2f1cfd 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -245,18 +245,18 @@ table {border: 1px solid #7a7971;} height: 8%; border-width: 0; } + .small-button-container { height: 16px; + width: 16px; border: 0; + vertical-align: bottom; } -.small-button-container img { - max-height: 100%; - max-width: 100%; -} -.small-button-img { - max-height: 24; - border-width: 0; +.img-sonne { + vertical-align: baseline; + max-height: 16px; + border: 0; } .foundryvtt-reve-de-dragon .sheet-header .header-fields { @@ -734,7 +734,7 @@ ul, li { .control-icon.tokenhudicon.right { margin-left: 8px; } -.rdd-hud-menu { +.rdd-hud-menu label { font-size: 0.75rem; } /* ======================================== */ diff --git a/templates/actor-creature-sheet.html b/templates/actor-creature-sheet.html index 46aa3029..b81642a8 100644 --- a/templates/actor-creature-sheet.html +++ b/templates/actor-creature-sheet.html @@ -83,6 +83,7 @@ Sonné : +
  • Etat Général : diff --git a/templates/actor-humanoide-sheet.html b/templates/actor-humanoide-sheet.html index 5955ac19..d58d71ef 100644 --- a/templates/actor-humanoide-sheet.html +++ b/templates/actor-humanoide-sheet.html @@ -83,6 +83,7 @@ Sonné : +
  • Etat Général : diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 3d025293..a84a634b 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -41,6 +41,7 @@
  • diff --git a/templates/hud-actor-attaque.html b/templates/hud-actor-attaque.html index 5f657c1e..9d3a7926 100644 --- a/templates/hud-actor-attaque.html +++ b/templates/hud-actor-attaque.html @@ -4,7 +4,7 @@ {{#each armes as |arme key|}} {{#unless arme.data.initOnly}}
    - +
    {{/unless}} {{/each}} diff --git a/templates/hud-actor-init.html b/templates/hud-actor-init.html index 94ba2d57..22b73058 100644 --- a/templates/hud-actor-init.html +++ b/templates/hud-actor-init.html @@ -2,9 +2,9 @@
    {{#each armes as |arme key|}} -
    - -
    +
    + +
    {{/each}}