forked from public/foundryvtt-reve-de-dragon
Pas de dialogue pour boire une potion
This commit is contained in:
@ -1609,8 +1609,18 @@ export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
async actionItem(item) {
|
||||
if (!item.getActionPrincipale()) return;
|
||||
switch (Misc.data(item).type) {
|
||||
case 'nourritureboisson': return await this.actionNourritureboisson(item);
|
||||
case 'potion': return await this.actionPotion(item);
|
||||
}
|
||||
}
|
||||
|
||||
async actionNourritureboisson(item) {
|
||||
const dialog = await DialogConsommer.create(this, item);
|
||||
dialog.render(true)
|
||||
dialog.render(true);
|
||||
}
|
||||
async actionPotion(item) {
|
||||
return await this.consommerPotion(item)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -1653,7 +1663,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
await item.diminuerQuantite(doses, options);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async boire(item, doses, options = { diminuerQuantite: true }) {
|
||||
if (!item.getActionPrincipale()) return;
|
||||
@ -3274,6 +3284,7 @@ export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
async consommerPotionSoin(potionData) {
|
||||
potionData.alias = this.name;
|
||||
potionData.supprimer = true;
|
||||
|
||||
if (potionData.data.isEnchante) {
|
||||
ChatMessage.create({
|
||||
@ -3305,6 +3316,7 @@ export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
async consommerPotionRepos(potionData) {
|
||||
potionData.alias = this.name;
|
||||
potionData.supprimer = true;
|
||||
|
||||
if (potionData.data.isEnchante) {
|
||||
ChatMessage.create({
|
||||
@ -3373,7 +3385,8 @@ export class RdDActor extends Actor {
|
||||
nbBrinsPotion: herbeData.nbBrins,
|
||||
nbBrinsReste: newQuantite
|
||||
}
|
||||
this.getObjet(herbeData._id).diminuerQuantite(herbeData.nbBrins);
|
||||
this.diminuerQuantiteObjet(herbeData._id, herbeData.nbBrins);
|
||||
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html`, messageData)
|
||||
@ -3381,6 +3394,13 @@ export class RdDActor extends Actor {
|
||||
|
||||
}
|
||||
|
||||
async diminuerQuantiteObjet(id, nb, options = { supprimerSiZero: false }) {
|
||||
const item = this.getObjet(id);
|
||||
if (item){
|
||||
await item.diminuerQuantite(nb, options);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async consommerPotionGenerique(potionData) {
|
||||
potionData.alias = this.name;
|
||||
@ -3402,7 +3422,7 @@ export class RdDActor extends Actor {
|
||||
} else {
|
||||
this.consommerPotionGenerique(potionData);
|
||||
}
|
||||
await this.deleteEmbeddedDocuments('Item', [potion.id]);
|
||||
this.diminuerQuantiteObjet(potion.id, 1, { supprimerSiZero: potionData.supprimer });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@ -85,16 +85,23 @@ export class RdDItem extends Item {
|
||||
return itemData.type == 'nourritureboisson' && itemData.data.boisson && itemData.data.alcoolise;
|
||||
}
|
||||
|
||||
async diminuerQuantite(nombre, options = { diminuerQuantite: true }) {
|
||||
if (!options.diminuerQuantite) return;
|
||||
async diminuerQuantite(nombre, options = { diminuerQuantite: true, supprimerSiZero: false }) {
|
||||
if (options.diminuerQuantite == false) return;
|
||||
const itemData = Misc.data(this);
|
||||
const quantite = itemData.data.quantite;
|
||||
if (quantite != undefined) {
|
||||
const reste = Math.max(quantite - nombre, 0);
|
||||
ui.notifications.notify(`Quantité de ${itemData.name} réduite de ${nombre}.${reste == 0
|
||||
? "Il ne vous en reste plus, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer."
|
||||
: ""}`);
|
||||
await this.update({ "data.quantite": reste });
|
||||
|
||||
if (options.supprimerSiZero && reste == 0) {
|
||||
ui.notifications.notify(`${itemData.name} supprimé de votre équipement`);
|
||||
await this.delete();
|
||||
}
|
||||
else {
|
||||
ui.notifications.notify(`Quantité de ${itemData.name} réduite de ${nombre}.${reste == 0
|
||||
? "Il ne vous en reste plus, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer."
|
||||
: ""}`);
|
||||
await this.update({ "data.quantite": reste });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user