#181 Gestion potions (fabrication)
This commit is contained in:
@@ -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 ) {
|
||||
|
@@ -63,6 +63,7 @@ export class DialogConsommer extends Dialog {
|
||||
this.consommerData = consommerData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
|
@@ -65,6 +65,11 @@ export class RdDItemSheet extends ItemSheet {
|
||||
isSoins: false,
|
||||
isEnchante: false
|
||||
}
|
||||
if ( this.actor ) {
|
||||
formData.isOwned = true;
|
||||
formData.actorId = this.actor.id;
|
||||
}
|
||||
|
||||
formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences();
|
||||
if ( formData.type == 'tache' || formData.type == 'livre' || formData.type == 'meditation' || formData.type == 'oeuvre') {
|
||||
formData.caracList = duplicate(game.system.model.Actor.personnage.carac);
|
||||
@@ -83,11 +88,9 @@ export class RdDItemSheet extends ItemSheet {
|
||||
this.dateUpdated = undefined;
|
||||
}
|
||||
RdDHerbes.updatePotionData(formData);
|
||||
}
|
||||
|
||||
if ( this.actor ) {
|
||||
formData.isOwned = true;
|
||||
formData.actorId = this.actor.id;
|
||||
}
|
||||
if ( formData.isOwned && formData.type == 'herbe' && (formData.data.categorie == 'Soin' || formData.data.categorie == 'Repos') ) {
|
||||
formData.isIngredientPotionBase = true;
|
||||
}
|
||||
formData.bonusCaseList = RdDItemSort.getBonusCaseList(formData, true);
|
||||
|
||||
@@ -128,7 +131,12 @@ export class RdDItemSheet extends ItemSheet {
|
||||
let actor = game.actors.get( actorId );
|
||||
actor.consommerPotion( this.item );
|
||||
});
|
||||
|
||||
html.find('.creer-potion-base').click((event) => {
|
||||
let actorId = event.currentTarget.attributes['data-actor-id'].value;
|
||||
let actor = game.actors.get( actorId );
|
||||
actor.dialogFabriquerPotion( this.item );
|
||||
});
|
||||
|
||||
html.find('.alchimie-tache a').click((event) => {
|
||||
let actorId = event.currentTarget.attributes['data-actor-id'].value;
|
||||
let recetteId = event.currentTarget.attributes['data-recette-id'].value;
|
||||
|
@@ -139,6 +139,7 @@ export class RdDUtility {
|
||||
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-vehicule.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/enum-competence.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/enum-herbesoin-ingredient.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-potion.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/enum-initpremierround.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/enum-rarete.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/sort-draconic.html',
|
||||
@@ -188,7 +189,8 @@ export class RdDUtility {
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html'
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html'
|
||||
];
|
||||
|
||||
Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null'));
|
||||
@@ -201,6 +203,14 @@ export class RdDUtility {
|
||||
return loadTemplates(templatePaths);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildListOptions( min, max ) {
|
||||
let options = ""
|
||||
for(let i=min; i<= max; i++) {
|
||||
options += `<option value="${i}">${i}</option>`
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static checkNull(items) {
|
||||
@@ -533,9 +543,6 @@ export class RdDUtility {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async chatListeners(html) {
|
||||
RdDCombat.registerChatCallbacks(html);
|
||||
|
Reference in New Issue
Block a user