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..9427b454 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 ); } 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 = ` -