#181 Gestion potions (fabrication)

This commit is contained in:
2021-04-10 21:07:53 +02:00
parent 1cea9753a9
commit 1b3c5f524d
9 changed files with 82 additions and 23 deletions

View File

@ -29,7 +29,7 @@ import { RdDCarac } from "./rdd-carac.js";
import { Monnaie } from "./item-monnaie.js";
import { RdDHerbes } from "./rdd-herbes.js";
import { DialogConsommer } from "./dialog-consommer.js";
import { RdDItem } from "./item.js";
import { DialogFabriquerPotion } from "./dialog-fabriquer-potion.js";
/* -------------------------------------------- */
@ -3308,6 +3308,47 @@ export class RdDActor extends Actor {
this.bonusRepos = potionData.data.herbeBonus;
}
}
/* -------------------------------------------- */
dialogFabriquerPotion( herbe ) {
DialogFabriquerPotion.create(this, herbe, {
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-fabriquer-potion-base.html',
}, []);
}
/* -------------------------------------------- */
async fabriquerPotion( potionData ) {
let newPotion = {
name: `Potion de ${potionData.data.categorie} (${potionData.name})`, type: 'potion',
img: "systems/foundryvtt-reve-de-dragon/icons/objets/fiole_verre.webp",
data: { quantite: 1, valeur_deniers: 1, encombrement: 0.01,
categorie: potionData.data.categorie,
herbe: potionData.name,
rarete: potionData.data.rarete,
herbebrins: potionData.nbBrins,
description: "" }
}
await this.createEmbeddedDocuments('Item', [newPotion], { renderSheet: true });
let newQuantite = potionData.data.quantite - potionData.nbBrins;
let messageData = {
alias: this.name,
categorie: potionData.data.categorie,
herbe: potionData.name,
nbBrinsPotion: potionData.nbBrins,
nbBrinsReste: newQuantite
}
if (newQuantite == 0 ) {
await this.deleteEmbeddedDocuments('Item', [ potionData._id ] );
} else {
let update = { _id: potionData._id, 'data.quantite': newQuantite};
const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html`, messageData )
});
}
/* -------------------------------------------- */
async consommerPotionGenerique( potionData ) {