forked from public/foundryvtt-reve-de-dragon
Boire une potion de soin
This commit is contained in:
@ -257,11 +257,11 @@ export class RdDActorSheet extends ActorSheet {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
RdDUtility.confirmerSuppression(this, li);
|
||||
});
|
||||
html.find('.item-consommer').click(ev => {
|
||||
html.find('.item-action').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const itemId = li.data("item-id");
|
||||
const item = this.actor.getObjet(itemId);
|
||||
this.actor.consommerDialog(item);
|
||||
this.actor.actionItem(item);
|
||||
});
|
||||
html.find('.subacteur-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
|
@ -27,7 +27,6 @@ import { EffetsDraconiques } from "./tmr/effets-draconiques.js";
|
||||
import { Draconique } from "./tmr/draconique.js";
|
||||
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 { DialogFabriquerPotion } from "./dialog-fabriquer-potion.js";
|
||||
|
||||
@ -313,7 +312,7 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async verifierPotionsEnchantees() {
|
||||
let potionsEnchantees = this.filterItemsData(it => it.type == 'potion' && it.data.categorie.toLowerCase().includes('enchante'));
|
||||
let potionsEnchantees = this.filterItemsData(it => it.type == 'potion' && it.data.isEnchante);
|
||||
for (let potion of potionsEnchantees) {
|
||||
if (!potion.prpermanent) {
|
||||
console.log(potion);
|
||||
@ -743,7 +742,6 @@ export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
async updateCreatureCompetence(compName, fieldName, compValue) {
|
||||
let comp = this.getCompetence(compName);
|
||||
//console.log(comp);
|
||||
if (comp) {
|
||||
const update = { _id: comp.id }
|
||||
if (fieldName == "niveau")
|
||||
@ -752,7 +750,6 @@ export class RdDActor extends Actor {
|
||||
update['data.dommages'] = compValue;
|
||||
else
|
||||
update['data.carac_value'] = compValue;
|
||||
//console.log(update);
|
||||
const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
}
|
||||
}
|
||||
@ -1610,8 +1607,8 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async consommerDialog(item) {
|
||||
if (!item.isConsommable()) return;
|
||||
async actionItem(item) {
|
||||
if (!item.getActionPrincipale()) return;
|
||||
const dialog = await DialogConsommer.create(this, item);
|
||||
dialog.render(true)
|
||||
}
|
||||
@ -1648,7 +1645,7 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async manger(item, doses, options = { diminuerQuantite: true }) {
|
||||
if (!item.isConsommable()) return;
|
||||
if (!item.getActionPrincipale()) return;
|
||||
await this.apprecierCuisine(item);
|
||||
const sust = Misc.templateData(item).sust;
|
||||
if (sust > 0) {
|
||||
@ -1656,10 +1653,10 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
await item.diminuerQuantite(doses, options);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async boire(item, doses, options = { diminuerQuantite: true }) {
|
||||
if (!item.isConsommable()) return;
|
||||
if (!item.getActionPrincipale()) return;
|
||||
const tplData = Misc.templateData(item);
|
||||
const desaltere = tplData.desaltere;
|
||||
if (desaltere > 0) {
|
||||
@ -3278,10 +3275,7 @@ export class RdDActor extends Actor {
|
||||
async consommerPotionSoin(potionData) {
|
||||
potionData.alias = this.name;
|
||||
|
||||
if (potionData.data.categorie.includes('Enchante')) {
|
||||
potionData.pointsGuerison = RdDHerbes.calculePointsGuerison(potionData.data);
|
||||
potionData.enchanteTexte = "enchantée";
|
||||
potionData.isEnchante = true;
|
||||
if (potionData.data.isEnchante) {
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-soin.html`, potionData)
|
||||
@ -3291,7 +3285,7 @@ export class RdDActor extends Actor {
|
||||
potionData.reussiteReve = false;
|
||||
if (!rolled.isSuccess) {
|
||||
await this.reveActuelIncDec(-1);
|
||||
potionData.guerisonData = await this.buildPotionGuerisonList(potionData.pointsGuerison);
|
||||
potionData.guerisonData = await this.buildPotionGuerisonList(potionData.data.puissance);
|
||||
potionData.guerisonMinutes = potionData.guerisonData.pointsConsommes * 5;
|
||||
potionData.reussiteReve = true;
|
||||
}
|
||||
@ -3300,8 +3294,6 @@ export class RdDActor extends Actor {
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData)
|
||||
});
|
||||
} else {
|
||||
potionData.enchanteTexte = "";
|
||||
potionData.isEnchante = false;
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData)
|
||||
@ -3314,10 +3306,7 @@ export class RdDActor extends Actor {
|
||||
async consommerPotionRepos(potionData) {
|
||||
potionData.alias = this.name;
|
||||
|
||||
if (potionData.data.categorie.includes('Enchante')) {
|
||||
potionData.casesRepos = RdDHerbes.calculePointsRepos(potionData.data);
|
||||
potionData.enchanteTexte = "enchantée";
|
||||
potionData.isEnchante = true;
|
||||
if (potionData.data.isEnchante) {
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-repos.html`, potionData)
|
||||
@ -3328,7 +3317,7 @@ export class RdDActor extends Actor {
|
||||
if (!rolled.isSuccess) {
|
||||
await this.reveActuelIncDec(-1);
|
||||
let fatigueActuelle = this.getFatigueActuelle();
|
||||
potionData.caseFatigueReel = (fatigueActuelle >= potionData.casesRepos) ? potionData.casesRepos : fatigueActuelle;
|
||||
potionData.caseFatigueReel = Math.min(fatigueActuelle, potionData.data.puissance);
|
||||
potionData.guerisonDureeUnite = (potionData.data.reposalchimique) ? "rounds" : "minutes";
|
||||
potionData.guerisonDureeValue = (potionData.data.reposalchimique) ? potionData.caseFatigueReel : potionData.caseFatigueReel * 5;
|
||||
potionData.reussiteReve = true;
|
||||
@ -3346,8 +3335,6 @@ export class RdDActor extends Actor {
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-repos.html`, potionData)
|
||||
});
|
||||
} else {
|
||||
potionData.enchanteTexte = "";
|
||||
potionData.isEnchante = false;
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-repos.html`, potionData)
|
||||
@ -3386,13 +3373,7 @@ export class RdDActor extends Actor {
|
||||
nbBrinsPotion: herbeData.nbBrins,
|
||||
nbBrinsReste: newQuantite
|
||||
}
|
||||
// TODO:
|
||||
if (newQuantite == 0) {
|
||||
await this.deleteEmbeddedDocuments('Item', [herbeData._id]);
|
||||
} else {
|
||||
let update = { _id: herbeData._id, 'data.quantite': newQuantite };
|
||||
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
}
|
||||
this.getObjet(herbeData._id).diminuerQuantite(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)
|
||||
@ -3404,13 +3385,6 @@ export class RdDActor extends Actor {
|
||||
async consommerPotionGenerique(potionData) {
|
||||
potionData.alias = this.name;
|
||||
|
||||
if (potionData.data.categorie.includes('Enchante')) {
|
||||
potionData.enchanteTexte = "enchantée";
|
||||
potionData.isEnchante = true;
|
||||
} else {
|
||||
potionData.enchanteTexte = "";
|
||||
potionData.isEnchante = false;
|
||||
}
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-generique.html`, potionData)
|
||||
|
@ -48,7 +48,7 @@ export class DialogConsommer extends Dialog {
|
||||
consommerData.buttonName = itemData.data.boisson ? "Boire" : "Manger";
|
||||
break;
|
||||
case 'potion':
|
||||
buttonName.title = `${itemData.name}: boire la potion`;
|
||||
consommerData.title = `${itemData.name}: boire la potion`;
|
||||
consommerData.buttonName = "Boire";
|
||||
break;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { Grammar } from "./grammar.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
|
||||
@ -17,9 +18,26 @@ export class RdDItem extends Item {
|
||||
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData();
|
||||
if (RdDItem.getTypeObjetsEquipement().includes(Misc.data(this).type)) {
|
||||
const itemData = Misc.data(this);
|
||||
if (RdDItem.getTypeObjetsEquipement().includes(itemData.type)) {
|
||||
this._calculsEquipement();
|
||||
}
|
||||
if (itemData.type == 'potion') {
|
||||
this.prepareDataPotion()
|
||||
}
|
||||
itemData.data.actionPrincipale = this.getActionPrincipale({ warnIfNot: false });
|
||||
|
||||
}
|
||||
|
||||
prepareDataPotion() {
|
||||
const tplData = Misc.templateData(this);
|
||||
const categorie = Grammar.toLowerCaseNoAccent(tplData.categorie);
|
||||
tplData.isEnchante = categorie.includes('enchante');
|
||||
if (tplData.isEnchante) {
|
||||
if (categorie.includes('soin') || categorie.includes('repos')) {
|
||||
tplData.puissance = tplData.herbebonus * tplData.pr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_calculsEquipement() {
|
||||
@ -36,32 +54,30 @@ export class RdDItem extends Item {
|
||||
|
||||
getEnc() {
|
||||
const itemData = Misc.data(this);
|
||||
switch (itemData.type)
|
||||
{
|
||||
switch (itemData.type) {
|
||||
case 'herbe':
|
||||
return encBrin;
|
||||
}
|
||||
return itemData.data.encombrement
|
||||
}
|
||||
|
||||
isConsommable(options = { warnIfNot: true }) {
|
||||
getActionPrincipale(options = { warnIfNot: true }) {
|
||||
const itemData = Misc.data(this);
|
||||
if ((itemData.data.quantite ?? 0) <= 0) {
|
||||
if (options.warnIfNot) {
|
||||
ui.notifications.warn(`Vous n'avez plus de ${itemData.name}.`);
|
||||
}
|
||||
return false;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
switch (itemData.type) {
|
||||
case 'nourritureboisson':
|
||||
case 'potion':
|
||||
return true;
|
||||
case 'nourritureboisson': return itemData.data.boisson ? 'Boire' : 'Manger';
|
||||
case 'potion': return 'Boire';
|
||||
}
|
||||
if (options.warnIfNot) {
|
||||
ui.notifications.warn(`Impossible de consommer un ${itemData.name}, ce n'est pas commestible.`);
|
||||
ui.notifications.warn(`Impossible d'utilise un ${itemData.name}, aucune action associée définie.`);
|
||||
}
|
||||
return false;
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
isAlcool() {
|
||||
|
@ -48,16 +48,6 @@ export class RdDHerbes extends Item {
|
||||
formData.isRepos = true;
|
||||
this.computeHerbeBonus(formData, this.herbesRepos, 7);
|
||||
}
|
||||
|
||||
if (formData.data.categorie.includes('Enchante') ) {
|
||||
formData.isEnchante = true;
|
||||
if ( formData.isHerbe) {
|
||||
formData.pointsGuerison = this.calculePointsGuerison( formData.data );
|
||||
}
|
||||
if ( formData.isRepos) {
|
||||
formData.caseRepos = formData.data.herbebonus * formData.data.pr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user