112 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { RdDItem } from "../item.js";
 | |
| import { ACTION_ITEM_ENCHANTER } from "../enchantement/dialog-enchanter.js";
 | |
| 
 | |
| const tableGemmes = {
 | |
|   "almaze": { label: "Almaze", couleur: "Blanc" },
 | |
|   "aquafane": { label: "Aquafane", couleur: "Vert Profond" },
 | |
|   "asterite": { label: "Astérite", couleur: "Bleu, Violet ou Blanc" },
 | |
|   "cyanolithe": { label: "Cyanolithe", couleur: "Bleu Intense" },
 | |
|   "larmededragon": { label: "Larme de Dragon", couleur: "Rouge Intense" },
 | |
|   "muska": { label: "Muska", couleur: "Violet Profond" },
 | |
|   "nebuleuse": { label: "Nébuleuse", couleur: "Brouillard Intense" },
 | |
|   "nebuleuse": { label: "Nébuleuse", couleur: "Brouillard Intense, Rose, Vert ou Bleu Pâle" },
 | |
|   "oeildetigre": { label: "Oeil de Tigre", couleur: "Jaune" },
 | |
|   "scarlatine": { label: "Scarlatine", couleur: "Rouge Clair ou Orangé" },
 | |
|   "seliphane": { label: "Séliphane", couleur: "Vert Lumineux" },
 | |
|   "tournelune": { label: "Tournelune", couleur: "Violet ou Bleu" },
 | |
|   "zebraide": { label: "Zebraïde", couleur: "Bandes Bicolores, toutes couleurs" }
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * un pépin de gemme = 1/10 cm3 = 1/1000 l = 3.5/1000 kg = 7/2000 kg = 7/1000 enc
 | |
|  * densité 3.5 (~2.3 à 4, parfois plus) -- https://www.juwelo.fr/guide-des-pierres/faits-et-chiffres/ 
 | |
|  */
 | |
| const encPepin = 0.0007;
 | |
| 
 | |
| /**
 | |
|  * Item pour gérer les gemmes
 | |
|  */
 | |
| export class RdDItemGemme extends RdDItem {
 | |
| 
 | |
|   static getGemmeTypeOptionList() {
 | |
|     // TODO: look how to map object key-value pairs
 | |
|     let options = ""
 | |
|     for (let gemmeKey in tableGemmes) {
 | |
|       options += `<option value="${gemmeKey}">${tableGemmes[gemmeKey].label}</option>`
 | |
|     }
 | |
|     return options;
 | |
|   }
 | |
| 
 | |
|   static get defaultIcon() {
 | |
|     return "systems/foundryvtt-reve-de-dragon/icons/gemmes/almaze.webp"
 | |
|   }
 | |
| 
 | |
|   get isEnchantementPossible() {
 | |
|     return this.enchantabilite > 0
 | |
|   }
 | |
| 
 | |
|   get inertie() { return 7 - Number(this.system.purete) }
 | |
|   get enchantabilite() { return this.system.taille - this.inertie }
 | |
| 
 | |
|   getEnc() {
 | |
|     return encPepin * this.system.taille;
 | |
|   }
 | |
| 
 | |
|   itemSpecificActions() {
 | |
|     return [ACTION_ITEM_ENCHANTER]
 | |
|   }
 | |
| 
 | |
|   prepareDerivedData() {
 | |
|     super.prepareDerivedData()
 | |
|     this.system.cout = (this.system.taille * this.system.purete) + this.system.qualite
 | |
|     this.system.inertie = this.inertie
 | |
|     this.system.enchantabilite = this.enchantabilite
 | |
|   }
 | |
| 
 | |
|   getUtilisation() {
 | |
|     switch (this.system.categorie) {
 | |
|       case 'Alchimie': case 'Autre': case 'AlchimieAutre':
 | |
|         // TODO: distinguer les remèdes alchimiques enchantables/non
 | |
|         return 'alchimie'
 | |
|       case 'Cuisine':
 | |
|         return 'cuisine'
 | |
|       case 'Remede': case 'Repos': case 'Soin':
 | |
|         return 'soins'
 | |
|     }
 | |
|     return ''
 | |
|   }
 | |
| 
 | |
|   getProprietes() {
 | |
|     const proprietes = [
 | |
|       `<b>Taille</b>: ${this.system.taille}`,
 | |
|       `<b>Pureté</b>: ${this.system.purete}`,
 | |
|       `<b>Inertie</b>: ${this.system.inertie}`,
 | |
|       `<b>Enchantabilité</b>: ${this.system.enchantabilite}`
 | |
|     ]
 | |
|     const proprietesMagiques = this.system.magique ? [
 | |
|       `<b>Enchantée</b> <i class="fa-solid fa-sparkles"></i> ${this.system.purifie ? ', purifiée' : ''} ${this.system.prpermanent ? 'permanente' : ''} `,
 | |
|       `<b>Points de rêve</b>: ${this.system.pr}`,
 | |
|       `<b>Puissance</b>: ${this.system.puissance}`,
 | |
|     ] : []
 | |
|     return proprietes
 | |
|       .concat(proprietesMagiques)
 | |
|       .concat(this._inventaireTemplateChatData())
 | |
|       .filter(it => it != undefined)
 | |
|   }
 | |
| 
 | |
|   perteReveChateauDormant() {
 | |
|     if (this.system.magique && !this.system.prpermanent && this.system.pr > 0) {
 | |
|       const nouveauReve = Math.max(this.system.pr - 1, 0)
 | |
|       return {
 | |
|         alias: this.parent.getAlias(),
 | |
|         item: this,
 | |
|         update: {
 | |
|           _id: this.id,
 | |
|           'system.pr': nouveauReve,
 | |
|           'system.magique': nouveauReve > 0
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|     return undefined
 | |
|   }
 | |
| } |