From 4bd2c1c2b4f8b35619c51b10a9e9806915b124fd Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 28 Nov 2022 11:31:55 +0100 Subject: [PATCH] =?UTF-8?q?Notion=20d'=C3=A9quipement/inventaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 7 +- module/item-monnaie.js | 16 +- module/item.js | 4 +- module/migrations.js | 36 +- module/rdd-utility.js | 4 +- template.json | 477 ++++++++++++--------------- templates/actor/inventaire-item.html | 4 +- templates/item-monnaie-sheet.html | 4 +- templates/item-objet-sheet.html | 4 - 9 files changed, 272 insertions(+), 284 deletions(-) diff --git a/module/actor.js b/module/actor.js index a4bf7280..489d2968 100644 --- a/module/actor.js +++ b/module/actor.js @@ -3267,10 +3267,9 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async equiperObjet(itemID) { let item = this.getEmbeddedDocument('Item', itemID); - if (item?.system) { + if (item && ['arme', 'armure'].includes(item.type)) { const isEquipe = !item.system.equipe; - let update = { _id: item.id, "system.equipe": isEquipe }; - await this.updateEmbeddedDocuments('Item', [update]); + await this.updateEmbeddedDocuments('Item', [{ _id: item.id, "system.equipe": isEquipe }]); this.computeEncombrementTotalEtMalusArmure(); // Mise à jour encombrement if (isEquipe) this.verifierForceMin(item); @@ -3569,7 +3568,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getFortune() { return this.itemTypes['monnaie'] - .map(m => Number(m.system.valeur_deniers) * Number(m.system.quantite)) + .map(m => Number(m.system.cout) * Number(m.system.quantite)) .reduce(Misc.sum(), 0); } diff --git a/module/item-monnaie.js b/module/item-monnaie.js index 2d48004a..930b79d4 100644 --- a/module/item-monnaie.js +++ b/module/item-monnaie.js @@ -4,22 +4,22 @@ import { LOG_HEAD } from "./constants.js"; const MONNAIE_ETAIN = { name: "Etain (1 denier)", type: 'monnaie', img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp", - system: { quantite: 0, valeur_deniers: 1, encombrement: 0.001, description: "" } + system: { quantite: 0, cout: 1, encombrement: 0.001, description: "" } }; const MONNAIE_BRONZE = { name: "Bronze (10 deniers)", type: 'monnaie', img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp", - system: { quantite: 0, valeur_deniers: 10, encombrement: 0.002, description: "" } + system: { quantite: 0, cout: 10, encombrement: 0.002, description: "" } }; const MONNAIE_ARGENT = { name: "Argent (1 sol)", type: 'monnaie', img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp", - system: { quantite: 0, valeur_deniers: 100, encombrement: 0.003, description: "" } + system: { quantite: 0, cout: 100, encombrement: 0.003, description: "" } }; const MONNAIE_OR = { name: "Or (10 sols)", type: 'monnaie', img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp", - system: { quantite: 0, valeur_deniers: 1000, encombrement: 0.004, description: "" } + system: { quantite: 0, cout: 1000, encombrement: 0.004, description: "" } }; const MONNAIES_STANDARD = [MONNAIE_ETAIN, MONNAIE_BRONZE, MONNAIE_ARGENT, MONNAIE_OR]; @@ -32,7 +32,7 @@ export class Monnaie { static monnaiesManquantes(actor) { const disponibles = actor.itemTypes['monnaie']; - const manquantes = MONNAIES_STANDARD.filter(standard => !disponibles.find(disponible => Monnaie.deValeur(disponible, standard.system?.valeur_deniers))); + const manquantes = MONNAIES_STANDARD.filter(standard => !disponibles.find(disponible => Monnaie.deValeur(disponible, standard.system?.cout))); if (manquantes.length > 0) { console.error(`${LOG_HEAD} monnaiesManquantes pour ${actor.name}`, manquantes, ' avec monnaies', disponibles, MONNAIES_STANDARD); } @@ -40,7 +40,7 @@ export class Monnaie { } static deValeur(monnaie, valeur) { - return valeur == monnaie.system.valeur_deniers + return valeur == monnaie.system.cout } static arrondiDeniers(sols) { @@ -48,7 +48,7 @@ export class Monnaie { } static triValeurDenier() { - return Misc.ascending(item => item.system.valeur_deniers) + return Misc.ascending(item => item.system.cout) } static async creerMonnaiesStandard(actor) { @@ -69,7 +69,7 @@ export class Monnaie { let reste = fortune; let monnaies = actor.itemTypes['monnaie']; let updates = []; - let parValeur = Misc.classifyFirst(monnaies, it => it.system.valeur_deniers); + let parValeur = Misc.classifyFirst(monnaies, it => it.system.cout); for (let valeur of [1000, 100, 10, 1]) { const itemPiece = parValeur[valeur]; if (itemPiece) { diff --git a/module/item.js b/module/item.js index 29fb3281..8c8cda90 100644 --- a/module/item.js +++ b/module/item.js @@ -172,7 +172,7 @@ export class RdDItem extends Item { } valeurDeniers() { - return Math.max(Math.round(this.system.cout ? (this.system.cout * 100) : (this.system.valeur_deniers ?? 0)), 0) + return Math.max(Math.round(this.system.cout ? (this.system.cout * 100) : (this.system.cout ?? 0)), 0) } prepareDerivedData() { @@ -494,7 +494,7 @@ export class RdDItem extends Item { /* -------------------------------------------- */ _monnaieChatData() { return [ - `Valeur en Deniers: ${this.system.valeur_deniers}`, + `Valeur en Deniers: ${this.system.cout}`, `Encombrement: ${this.system.encombrement}` ] } diff --git a/module/migrations.js b/module/migrations.js index 886dfd5d..97e2ea31 100644 --- a/module/migrations.js +++ b/module/migrations.js @@ -195,7 +195,8 @@ class _10_2_10_DesirLancinant_IdeeFixe extends Migration { categorie = 'ideefixe'; name = it.name.replace('Idée fixe : ', '') } - return { _id: it.id, name: name, + return { + _id: it.id, name: name, 'system.ideefixe': undefined, 'system.lancinant': undefined, 'system.categorie': categorie @@ -206,8 +207,36 @@ class _10_2_10_DesirLancinant_IdeeFixe extends Migration { await this.applyItemsUpdates(items => items .filter(it => ['queue', 'ombre'].includes(it.type)) .map(it => this.migrateQueue(it)) - //.filter(it => it.system.categorie ) - ); + ); + } +} + +class _10_3_0_Inventaire extends Migration { + get code() { return "migration-equipement-inventaire"; } + get version() { return "10.3.0"; } + + async migrate() { + await this.applyItemsUpdates(items => { + return this._updatesMonnaies(items) + .concat(this._updatesNonEquipe(items)) + .concat(this._updatesObjets(items)) + }); + } + + _updatesNonEquipe(items) { + return items + .filter(it => ['munition'].includes(it.type)) + .map(it => { return { _id: it.id, 'system.equipe': undefined } }); + } + _updatesObjets(items) { + return items + .filter(it => ['objet'].includes(it.type)) + .map(it => { return { _id: it.id, 'system.resistance': undefined, 'system.equipe': undefined } }); + } + _updatesMonnaies(items) { + return items + .filter(it => ['monnaie'].includes(it.type)) + .map(it => { return { _id: it.id, 'system.cout': it.system.valeur_deniers, 'system.valeur_deniers': undefined } }); } } @@ -220,6 +249,7 @@ export class Migrations { new _10_0_33_MigrationNomsDraconic(), new _10_2_5_ArmesTirLancer(), new _10_2_10_DesirLancinant_IdeeFixe(), + new _10_3_0_Inventaire() ]; } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 1525b460..38033330 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -890,12 +890,12 @@ export class RdDUtility { } /* -------------------------------------------- */ - static createMonnaie(name, valeur_deniers, img = "", enc = 0.01) { + static createMonnaie(name, cout, img = "", enc = 0.01) { let piece = { name: name, type: 'monnaie', img: img, _id: randomID(16), dasystemta: { quantite: 0, - valeur_deniers: valeur_deniers, + cout: cout, encombrement: enc, description: "" } diff --git a/template.json b/template.json index 08566ec3..034f13c1 100644 --- a/template.json +++ b/template.json @@ -594,91 +594,17 @@ "description": { "description": "", "descriptionmj": "" + }, + "equipement": { + "equipe": false + }, + "inventaire": { + "encombrement": 0, + "quantite": 1, + "qualite": 0, + "cout": 0 } }, - "possession": { - "templates": [ "description" ], - "typepossession": "", - "possede": false, - "possessionid": "", - "possesseurid": "", - "possedeid": "", - "compteur": 0, - "date": 0 - }, - "objet": { - "templates": [ "description" ], - "quantite": 1, - "encombrement": 0, - "equipe": false, - "resistance": 0, - "qualite": 0, - "cout": 0 - }, - "gemme": { - "templates": [ "description" ], - "type": "", - "encombrement": 0, - "quantite": 1, - "cout": 0, - "taille": 0, - "purete": 0, - "inertie": 0, - "enchantabilite": 0, - "qualite": 0 - }, - "conteneur": { - "templates": [ "description" ], - "capacite": 0, - "encombrement": 0, - "equipe": false, - "qualite": 0, - "contenu": [], - "cout": 0 - }, - "arme": { - "templates": [ "description" ], - "categorie_parade": "", - "quantite": 1, - "encombrement": 0, - "equipe": false, - "dommages": "0", - "penetration": 0, - "force": "0", - "resistance": 0, - "competence": "", - "lancer": "", - "tir": "", - "cout": 0, - "portee_courte": 0, - "portee_moyenne": 0, - "portee_extreme": 0, - "magique": false, - "ecaille_efficacite": 0, - "resistance_magique": 0, - "rapide": false, - "deuxmains": false, - "unemain": false, - "initpremierround": "" - }, - "munition": { - "templates": [ "description" ], - "quantite": 1, - "encombrement": 0, - "equipe": false, - "qualite": 0, - "cout": 0 - }, - "armure": { - "templates": [ "description" ], - "quantite": 1, - "encombrement": 0, - "equipe": false, - "protection": 0, - "deterioration": 0, - "malus": 0, - "cout": 0 - }, "competence": { "templates": [ "description" ], "niveau": 0, @@ -702,6 +628,193 @@ "ispossession": false, "dommages": 0 }, + "possession": { + "templates": [ "description" ], + "typepossession": "", + "possede": false, + "possessionid": "", + "possesseurid": "", + "possedeid": "", + "compteur": 0, + "date": 0 + }, + "maladie": { + "templates": [ "description" ], + "identifie": false, + "malignite": 0, + "periodicite": "", + "remedesconnus": false, + "remedes": "", + "dommages":"" + }, + "poison": { + "templates": [ "description" ], + "identifie": false, + "malignite": 0, + "periodicite": "", + "remedesconnus": false, + "remedes": "", + "dommages":"", + "active": false + }, + "arme": { + "templates": [ "description", "equipement", "inventaire" ], + "resistance": 0, + "categorie_parade": "", + "dommages": "0", + "penetration": 0, + "force": "0", + "competence": "", + "lancer": "", + "tir": "", + "portee_courte": 0, + "portee_moyenne": 0, + "portee_extreme": 0, + "magique": false, + "ecaille_efficacite": 0, + "resistance_magique": 0, + "rapide": false, + "deuxmains": false, + "unemain": false, + "initpremierround": "" + }, + "armure": { + "templates": [ "description", "equipement", "inventaire" ], + "protection": 0, + "deterioration": 0, + "malus": 0 + }, + "conteneur": { + "templates": [ "description", "inventaire" ], + "contenu": [], + "capacite": 0 + }, + "objet": { + "templates": [ "description", "inventaire"] + }, + "monnaie": { + "templates": [ "description", "inventaire" ] + }, + "gemme": { + "templates": [ "description", "inventaire" ], + "type": "", + "taille": 0, + "purete": 0, + "inertie": 0, + "enchantabilite": 0 + }, + "munition": { + "templates": [ "description", "inventaire" ] + }, + "nourritureboisson": { + "templates": [ "description", "inventaire" ], + "sust": 0, + "boisson": false, + "desaltere": 0, + "alcoolise": false, + "force": 0, + "exotisme": 0 + }, + "herbe": { + "templates": [ "description", "inventaire" ], + "niveau": 0, + "base": 0, + "milieu": "", + "rarete": "", + "categorie": "" + }, + "ingredient": { + "templates": [ "description", "inventaire" ], + "niveau": 0, + "base": 0, + "milieu": "", + "rarete": "", + "categorie": "" + }, + "livre": { + "templates": [ "description", "inventaire" ], + "competence": "", + "auteur": "", + "difficulte": 0, + "points_de_tache": 0, + "xp": "", + "niveau_minimum": 0, + "niveau_maximum": 0 + }, + "potion": { + "templates": [ "description", "inventaire" ], + "rarete": "", + "categorie": "", + "herbe": "", + "herbebrins": 0, + "herbebonus": 0, + "reposalchimique": false, + "pr": 0, + "prpermanent": false, + "prdate": 0 + }, + "musique": { + "templates": [ "description" ], + "niveau": "", + "reference": "" + }, + "danse": { + "templates": [ "description" ], + "type": "", + "agilite": false, + "apparence": false, + "niveau": "", + "reference": "" + }, + "chant": { + "templates": [ "description" ], + "niveau": "", + "reference": "" + }, + "jeu": { + "templates": [ "description" ], + "type": "", + "base": "", + "caraccomp": "", + "reference": "" + }, + "recettecuisine": { + "templates": [ "description" ], + "niveau": "", + "ingredients": "", + "duree": "", + "sust": 0, + "exotisme": 0, + "reference": "" + }, + "oeuvre": { + "templates": [ "description" ], + "default_carac": "", + "competence": "", + "niveau": 0, + "reference": "" + }, + "recettealchimique": { + "templates": [ "description" ], + "but": "", + "utilisation": "", + "enchantement": "", + "sureffet": "", + "manipulation": "" + }, + "tache": { + "templates": [ "description" ], + "carac": "", + "competence": "", + "periodicite": "", + "fatigue": 1, + "difficulte": 0, + "points_de_tache": 4, + "points_de_tache_courant": 0, + "nb_jet_echec": 0, + "nb_jet_succes": 0, + "cacher_points_de_tache": false + }, "sort": { "templates": [ "description" ], "draconic": "", @@ -718,67 +831,13 @@ "isrituel": false, "coutseuil": 0 }, - "herbe": { - "templates": [ "description" ], - "niveau": 0, - "base": 0, - "quantite": 1, - "milieu": "", - "rarete": "", - "categorie": "", - "cout": 0 - }, - "ingredient": { - "templates": [ "description" ], - "niveau": 0, - "encombrement": 0, - "base": 0, - "quantite": 1, - "milieu": "", - "rarete": "", - "categorie": "", - "cout": 0 - }, - "tache": { - "templates": [ "description" ], - "carac": "", - "competence": "", - "periodicite": "", - "fatigue": 1, - "difficulte": 0, - "points_de_tache": 4, - "points_de_tache_courant": 0, - "nb_jet_echec": 0, - "nb_jet_succes": 0, - "cacher_points_de_tache": false - }, - "livre": { - "templates": [ "description" ], - "competence": "", - "auteur": "", - "quantite": 1, - "difficulte": 0, - "points_de_tache": 0, - "encombrement": 0, - "xp": "", - "niveau_minimum": 0, - "niveau_maximum": 0, - "cout": 0 - }, - "potion": { - "templates": [ "description" ], - "quantite": 1, - "encombrement": 0, - "rarete": "", - "categorie": "", - "herbe": "", - "herbebrins": 0, - "herbebonus": 0, - "reposalchimique": false, - "pr": 0, - "prpermanent": false, - "prdate": 0, - "cout": 0 + "sortreserve": { + "sortid" : "", + "draconic": "", + "coord": "", + "ptreve": 0, + "heurecible": "", + "echectotal": false }, "rencontre": { "templates": [ "description" ], @@ -852,23 +911,13 @@ "frequence": 0, "hautrevant": false }, - "tarot": { + "casetmr": { "templates": [ "description" ], - "concept":"", - "aspect":"", - "frequence": 1 - }, - "nombreastral": { - "value": 0, - "istrue": false, - "jourindex": 1, - "jourlabel": "" - }, - "monnaie": { - "templates": [ "description" ], - "quantite": "", - "valeur_deniers":0, - "encombrement":0 + "coord": "", + "type": "", + "label": "", + "specific": "", + "sourceid":"" }, "meditation": { "templates": [ "description" ], @@ -882,95 +931,6 @@ "tmr": "", "malus" : 0 }, - "casetmr": { - "templates": [ "description" ], - "coord": "", - "type": "", - "label": "", - "specific": "", - "sourceid":"" - }, - "recettealchimique": { - "templates": [ "description" ], - "but": "", - "utilisation": "", - "enchantement": "", - "sureffet": "", - "manipulation": "" - }, - "musique": { - "templates": [ "description" ], - "niveau": "", - "reference": "" - }, - "danse": { - "templates": [ "description" ], - "type": "", - "agilite": false, - "apparence": false, - "niveau": "", - "reference": "" - }, - "chant": { - "templates": [ "description" ], - "niveau": "", - "reference": "" - }, - "jeu": { - "templates": [ "description" ], - "type": "", - "base": "", - "caraccomp": "", - "reference": "" - }, - "recettecuisine": { - "templates": [ "description" ], - "niveau": "", - "ingredients": "", - "duree": "", - "sust": 0, - "exotisme": 0, - "reference": "" - }, - "oeuvre": { - "templates": [ "description" ], - "default_carac": "", - "competence": "", - "niveau": 0, - "reference": "" - }, - "maladie": { - "templates": [ "description" ], - "identifie": false, - "malignite": 0, - "periodicite": "", - "remedesconnus": false, - "remedes": "", - "dommages":"" - }, - "poison": { - "templates": [ "description" ], - "identifie": false, - "malignite": 0, - "periodicite": "", - "remedesconnus": false, - "remedes": "", - "dommages":"", - "active": false - }, - "nourritureboisson": { - "templates": [ "description" ], - "sust": 0, - "boisson": false, - "desaltere": 0, - "alcoolise": false, - "force": 0, - "qualite": 0, - "exotisme": 0, - "encombrement": 0, - "quantite": 1, - "cout": 0 - }, "signedraconique": { "templates": [ "description" ], "typesTMR": [], @@ -983,13 +943,17 @@ "part": 10 } }, - "sortreserve": { - "sortid" : "", - "draconic": "", - "coord": "", - "ptreve": 0, - "heurecible": "", - "echectotal": false + "tarot": { + "templates": [ "description" ], + "concept":"", + "aspect":"", + "frequence": 1 + }, + "nombreastral": { + "value": 0, + "istrue": false, + "jourindex": 1, + "jourlabel": "" }, "extraitpoetique": { "extrait": "", @@ -997,4 +961,3 @@ } } } - diff --git a/templates/actor/inventaire-item.html b/templates/actor/inventaire-item.html index 4b4010a2..29511c41 100644 --- a/templates/actor/inventaire-item.html +++ b/templates/actor/inventaire-item.html @@ -21,14 +21,14 @@ {{numberFormat item.system.encTotal decimals=2}} {{#unless item.estContenu}} - {{#if (ne item.type 'conteneur')}} + {{#if (or (eq item.type 'arme') (eq item.type 'armure') )}} {{#if item.system.equipe}}{{else}}{{/if}} {{/if}} {{/unless}}   - {{#if (or (eq item.type 'arme') (eq item.type 'conteneur') item.system.quantite)}} + {{#if (ne item.system.quantite 0)}} {{/if}} diff --git a/templates/item-monnaie-sheet.html b/templates/item-monnaie-sheet.html index a105d6c0..7e18ffb7 100644 --- a/templates/item-monnaie-sheet.html +++ b/templates/item-monnaie-sheet.html @@ -9,9 +9,9 @@
{{#if isGM}} - + {{else}} - + {{/if}}
diff --git a/templates/item-objet-sheet.html b/templates/item-objet-sheet.html index 2737332c..162f2a50 100644 --- a/templates/item-objet-sheet.html +++ b/templates/item-objet-sheet.html @@ -10,10 +10,6 @@
-
- - -