Pas de dialogue pour boire une potion

This commit is contained in:
Vincent Vandemeulebrouck 2021-04-12 01:03:37 +02:00
parent b1f0d54837
commit 99c58233ef
4 changed files with 38 additions and 25 deletions

View File

@ -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 });
}
/* -------------------------------------------- */

View File

@ -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 });
}
}
}

View File

@ -935,7 +935,7 @@ ul, li {
background: rgba(220,220,210,0.75);
border: 2px solid #545469;
}
.chat-message .chat-icon {
.chat-icon {
border: 0;
padding: 2px 6px 2px 2px;
float: left;

View File

@ -1,14 +0,0 @@
<form class="rdddialog">
<img class="chat-icon" src="{{item.img}}" alt="{{oeuvre.data.competence}}" />
<div class="form-group">
<label>Boire une dose de {{item.name}}</label>
</div>
<div>
{{#if (eq item.data.categorie 'SoinEnchante')}}
<p>C'est une potion enchantée de {{item.data.herbe}} de {{item.data.pr}} points de rêve,
sa puissance de guérison est de {{data.puissance}} </p>
{{/if}}
</div>
</form>