forked from public/foundryvtt-reve-de-dragon
		
	
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { DialogItemAchat } from "../achat-vente/dialog-item-achat.js";
 | |
| import { Misc } from "../misc.js";
 | |
| import { RdDUtility } from "../rdd-utility.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";
 | |
|   }
 | |
| 
 | |
|   canReceive(item) {
 | |
|     return item.isInventaire('all');
 | |
|   }
 | |
| 
 | |
|   getQuantiteDisponible(item) {
 | |
|     return (this.system.illimite || item?.isService()) ? undefined : item.getQuantite();
 | |
|   }
 | |
| 
 | |
|   verifierFortune(cout) {
 | |
|     return this.system.illimite || super.verifierFortune(cout);
 | |
|   }
 | |
| 
 | |
|   async depenserSols(cout) {
 | |
|     if (this.system.illimite) {
 | |
|       return
 | |
|     }
 | |
|     await super.depenserSols(cout)
 | |
|   }
 | |
| 
 | |
|   async decrementerQuantiteItem(item, quantite) {
 | |
|     if (this.system.illimite) {
 | |
|       return;
 | |
|     }
 | |
|     await super.decrementerQuantiteItem(item, quantite, { supprimerSiZero: false });
 | |
|   }
 | |
| 
 | |
|   calculerPrix(item) {
 | |
|     const pourcentage = this.system.pourcentage ?? 100;
 | |
|     return Misc.keepDecimals(Math.ceil(item.system.cout * pourcentage) / 100, 2);
 | |
|   }
 | |
|   async vente(item) {
 | |
|     const acheteur = RdDUtility.getSelectedActor();
 | |
|     if (!acheteur) {
 | |
|       ui.notifications.warn(`Pas d'acheteur sélectionné`);
 | |
|       return;
 | |
|     }
 | |
|     const disponible = this.getQuantiteDisponible(item)
 | |
|     if (disponible == 0) {
 | |
|       ui.notifications.warn(`${this.getAlias()} n'a plus de ${item.name} en vente`);
 | |
|       return;
 | |
|     }
 | |
| 
 | |
|     await DialogItemAchat.onAcheter({
 | |
|       item,
 | |
|       vendeur: this,
 | |
|       acheteur,
 | |
|       quantiteIllimite: disponible == undefined,
 | |
|       nbLots: disponible ?? 1,
 | |
|       tailleLot: 1,
 | |
|       prixLot: item.calculerPrixCommercant()
 | |
|     });
 | |
|   }
 | |
|   
 | |
| } |