From 5bddc548de3a503aec57eb64c630925a601be7a7 Mon Sep 17 00:00:00 2001
From: Vincent Vandemeulebrouck <vincent.vandemeulebrouck@itiviti.com>
Date: Tue, 3 Jan 2023 13:26:44 +0100
Subject: [PATCH 1/2] Le GR a toujours le droit de voir

Change-Id: I3b58fddc3ce6765e6dcf59dc20d81cdadf381761
---
 module/actor/base-actor-sheet.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js
index 6cfc9e7e..389bbf54 100644
--- a/module/actor/base-actor-sheet.js
+++ b/module/actor/base-actor-sheet.js
@@ -31,7 +31,7 @@ export class RdDBaseActorSheet extends ActorSheet {
     Monnaie.validerMonnaies(this.actor.itemTypes['monnaie']);
 
     this.actor.recompute();
-    const userRightLevel = this.actor.getUserLevel(game.user)
+    const userRightLevel = game.user.isGM ? CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER : this.actor.getUserLevel(game.user)
     const options = duplicate(this.options);
     mergeObject(options, {
       isGM: game.user.isGM,

From 2e0abaa2843171b850d078ed29dbcbcd1e0af102 Mon Sep 17 00:00:00 2001
From: Vincent Vandemeulebrouck <vincent.vandemeulebrouck@itiviti.com>
Date: Tue, 3 Jan 2023 13:38:04 +0100
Subject: [PATCH 2/2] Les services sont inquantifiables
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Ne pas décrémenter leur quantité, et leur quantite disponible est
undefined (ie: infinie)
---
 module/actor/base-actor.js |  5 ++++-
 module/actor/commerce.js   | 12 ++++++------
 module/item.js             |  8 +++++---
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js
index 8db83fb0..b62ac03d 100644
--- a/module/actor/base-actor.js
+++ b/module/actor/base-actor.js
@@ -220,7 +220,7 @@ export class RdDBaseActor extends Actor {
   /* -------------------------------------------- */
 
   getQuantiteDisponible(item) {
-    return item?.getQuantite();
+    return item?.isService() ? undefined : item?.getQuantite();
   }
 
   /* -------------------------------------------- */
@@ -310,6 +310,9 @@ export class RdDBaseActor extends Actor {
 
 
   async decrementerQuantiteItem(item, quantite, options = { supprimerSiZero: true }) {
+    if (itemVendu.isService()) {
+      return;
+    }
     let resteQuantite = (item.system.quantite ?? 1) - quantite;
     if (resteQuantite <= 0) {
       if (options.supprimerSiZero) {
diff --git a/module/actor/commerce.js b/module/actor/commerce.js
index 2735ac5e..0288dd99 100644
--- a/module/actor/commerce.js
+++ b/module/actor/commerce.js
@@ -2,7 +2,7 @@ import { Misc } from "../misc.js";
 import { RdDBaseActor } from "./base-actor.js";
 
 export class RdDCommerce extends RdDBaseActor {
-  
+
   static get defaultIcon() {
     return "systems/foundryvtt-reve-de-dragon/icons/services/commerce.webp";
   }
@@ -15,16 +15,16 @@ export class RdDCommerce extends RdDBaseActor {
   }
 
   canReceive(item) {
-    if (item.isInventaire('all'))  {
+    if (item.isInventaire('all')) {
       return true;
     }
     return super.canReceive(item);
   }
 
   getQuantiteDisponible(item) {
-    return this.system.illimite ? undefined : item.getQuantite();
+    return this.system.illimite || item.isService() ? undefined : item.getQuantite();
   }
-  
+
   verifierFortune(cout) {
     return this.system.illimite || super.verifierFortune(cout);
   }
@@ -43,11 +43,11 @@ export class RdDCommerce extends RdDBaseActor {
     if (this.system.illimite) {
       return;
     }
-    await super.decrementerQuantiteItem(itemVendu, quantite, {supprimerSiZero: false});
+    await super.decrementerQuantiteItem(itemVendu, quantite, { supprimerSiZero: false });
   }
 
   calculerPrix(item) {
     const pourcentage = this.system.pourcentage ?? 100;
-    return Misc.keepDecimals(Math.ceil(item.system.cout * pourcentage)/100, 2);
+    return Misc.keepDecimals(Math.ceil(item.system.cout * pourcentage) / 100, 2);
   }
 }
\ No newline at end of file
diff --git a/module/item.js b/module/item.js
index 5e9944bc..a36bb4cb 100644
--- a/module/item.js
+++ b/module/item.js
@@ -223,15 +223,17 @@ export class RdDItem extends Item {
   }
 
   getQuantite() {
-    return Math.round(this.system.quantite ?? 0)
+    return this.isService() ? undefined : Math.round(this.system.quantite ?? 0)
   }
 
   getEncTotal() {
-    return this.getEnc() * this.getQuantite();
+    return (this.isService() ? 0 : this.getQuantite()) * this.getEnc();
   }
 
   getEnc() {
     switch (this.type) {
+      case 'service':
+        return 0;
       case 'herbe':
         return this.getEncHerbe();
       case 'gemme':
@@ -250,7 +252,7 @@ export class RdDItem extends Item {
   }
 
   valeurTotale() {
-    return this.getQuantite() * this.valeur()
+    return (this.isService() ? 1 : this.getQuantite()) * this.valeur()
   }
 
   valeur() {