From 5dde9ac72fbed35bd748376b2e3406d8982647c5 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Sat, 3 Dec 2022 23:57:30 +0100 Subject: [PATCH] Gestion des quantites et de l'argent --- modules/hawkmoon-actor-sheet.js | 18 ++++----- modules/hawkmoon-actor.js | 32 +++++++++++++++- modules/hawkmoon-utility.js | 10 +++++ styles/simple.css | 3 ++ system.json | 4 +- template.json | 1 + templates/actor-sheet.html | 61 +++++++++++++++++++++++++++++++ templates/item-monnaie-sheet.html | 13 ++++++- templates/partial-item-prix.html | 6 +++ 9 files changed, 134 insertions(+), 14 deletions(-) diff --git a/modules/hawkmoon-actor-sheet.js b/modules/hawkmoon-actor-sheet.js index 3003edd..9d73418 100644 --- a/modules/hawkmoon-actor-sheet.js +++ b/modules/hawkmoon-actor-sheet.js @@ -48,6 +48,9 @@ export class HawkmoonActorSheet extends ActorSheet { profils: duplicate(this.actor.getProfils() || {}), combat: this.actor.getCombatValues(), equipements: duplicate(this.actor.getEquipments()), + monnaies: duplicate(this.actor.getMonnaies()), + richesse: this.actor.computeRichesse(), + valeurEquipement: this.actor.computeValeurEquipement(), initiative: this.actor.getFlag("world", "last-initiative") || -1, description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}), habitat: await TextEditor.enrichHTML(this.object.system.biodata.habitat, {async: true}), @@ -112,15 +115,12 @@ export class HawkmoonActorSheet extends ActorSheet { let value = Number($(event.currentTarget).data("adversite-value")) this.actor.incDecAdversite(adv, value) }) - - html.find('.quantity-minus').click(event => { - const li = $(event.currentTarget).parents(".item"); - this.actor.incDecQuantity( li.data("item-id"), -1 ); - } ); - html.find('.quantity-plus').click(event => { - const li = $(event.currentTarget).parents(".item"); - this.actor.incDecQuantity( li.data("item-id"), +1 ); - } ); + + html.find('.quantity-modify').click(event => { + const li = $(event.currentTarget).parents(".item") + const value = Number($(event.currentTarget).data("quantite-value")) + this.actor.incDecQuantity( li.data("item-id"), value ); + }) html.find('.roll-initiative').click((event) => { this.actor.rollAttribut("pre", true) diff --git a/modules/hawkmoon-actor.js b/modules/hawkmoon-actor.js index 0ce7beb..72a109c 100644 --- a/modules/hawkmoon-actor.js +++ b/modules/hawkmoon-actor.js @@ -116,6 +116,10 @@ export class HawkmoonActor extends Actor { getEquipments() { return this.items.filter(item => item.type == "equipement") } + /* ----------------------- --------------------- */ + getMonnaies() { + return this.items.filter(item => item.type == "monnaie") + } /* -------------------------------------------- */ getArmors() { return this.items.filter(item => item.type == "protection") @@ -427,12 +431,36 @@ export class HawkmoonActor extends Actor { async incDecQuantity(objetId, incDec = 0) { let objetQ = this.items.get(objetId) if (objetQ) { - let newQ = objetQ.system.quantity + incDec + let newQ = objetQ.system.quantite + incDec newQ = Math.max(newQ, 0) - const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]); // pdates one EmbeddedEntity + const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantite': newQ }]); // pdates one EmbeddedEntity } } + /* -------------------------------------------- */ + computeRichesse() { + let valueSC = 0 + for(let monnaie of this.items) { + if (monnaie.type == "monnaie") { + valueSC += Number(monnaie.system.prixsc) * Number(monnaie.system.quantite) + } + } + return HawkmoonUtility.computeMonnaieDetails( valueSC) + } + + /* -------------------------------------------- */ + computeValeurEquipement() { + let valueSC = 0 + for(let equip of this.items) { + if (equip.type == "equipement" || equip.type == "arme" || equip.type == "protection") { + valueSC += Number(equip.system.prixsc) * Number(equip.system.quantite ?? 1) + valueSC += (Number(equip.system.prixca) * Number(equip.system.quantite ?? 1)) * 20 + valueSC += (Number(equip.system.prixpo) * Number(equip.system.quantite ?? 1)) * 400 + } + } + return HawkmoonUtility.computeMonnaieDetails( valueSC) + } + /* -------------------------------------------- */ getCompetence(compId) { return this.items.get(compId) diff --git a/modules/hawkmoon-utility.js b/modules/hawkmoon-utility.js index ed6276b..f170822 100644 --- a/modules/hawkmoon-utility.js +++ b/modules/hawkmoon-utility.js @@ -305,6 +305,16 @@ export class HawkmoonUtility { } } + /* -------------------------------------------- */ + static computeMonnaieDetails(valueSC) { + let po = Math.floor(valueSC / 400) + let pa = Math.floor((valueSC - (po*400)) / 20) + let sc = valueSC - (po*400) - (pa*20) + return { + po: po, pa: pa, sc: sc, valueSC: valueSC + } + } + /* -------------------------------------------- */ static computeResult(rollData) { rollData.diceResult = rollData.roll.terms[0].results[0].result diff --git a/styles/simple.css b/styles/simple.css index e3795fb..0911d16 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1436,4 +1436,7 @@ ul, li { } .adversite-modify { margin-top: 12px; +} +.argent-total-text { + margin-left: 4px; } \ No newline at end of file diff --git a/system.json b/system.json index d5875cd..bb57ebc 100644 --- a/system.json +++ b/system.json @@ -1,7 +1,7 @@ { "id": "fvtt-hawkmoon-cyd", "description": "Hawmoon RPG for FoundryVTT (CYD system - French)", - "version": "10.1.2", + "version": "10.1.4", "authors": [ { "name": "Uberwald/LeRatierBretonnien", @@ -35,7 +35,7 @@ "gridUnits": "m", "license": "LICENSE.txt", "manifest": "https://www.uberwald.me/gitea/public/fvtt-hawkmoon-cyd/raw/branch/master/system.json", - "download": "https://www.uberwald.me/gitea/public/fvtt-hawkmoon-cyd/archive/fvtt-hawkmoon-cyd-10.1.2.zip", + "download": "https://www.uberwald.me/gitea/public/fvtt-hawkmoon-cyd/archive/fvtt-hawkmoon-cyd-10.1.4.zip", "packs": [ { "type": "Item", diff --git a/template.json b/template.json index 1f1151a..456bc7f 100644 --- a/template.json +++ b/template.json @@ -124,6 +124,7 @@ "prixca": 0, "prixsc": 0, "rarete": 0, + "quantite": 0, "equipped": false }, "automation": { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 1421dac..2122ae4 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -340,6 +340,58 @@
+ +
+
+

+ +

+
+ +
+
    +
  • + +

    +
    + + + + +
     
    +
    + +
    +
  • + {{#each monnaies as |monnaie key|}} +
  • + + {{monnaie.name}} + {{monnaie.system.quantite}} + - + + + +
     
    +
    + + +
    +
  • + {{/each}} +
+
+ +
+
+

+ +

+
    @@ -347,6 +399,11 @@

    + + + + +
     
    {{equipement.name}} + {{equipement.system.quantite}} + - + + +
     
    diff --git a/templates/item-monnaie-sheet.html b/templates/item-monnaie-sheet.html index d1e0a70..a195519 100644 --- a/templates/item-monnaie-sheet.html +++ b/templates/item-monnaie-sheet.html @@ -13,8 +13,19 @@
      - {{> systems/fvtt-hawkmoon-cyd/templates/partial-item-prix.html}} +
    • + + +
    • +
    • + + +
    • + +
    diff --git a/templates/partial-item-prix.html b/templates/partial-item-prix.html index 2b5fc8c..2d993b2 100644 --- a/templates/partial-item-prix.html +++ b/templates/partial-item-prix.html @@ -9,6 +9,12 @@ +
  • + + +
  • +