diff --git a/module/actor.js b/module/actor.js
index d4d3d0fb..34ad3486 100644
--- a/module/actor.js
+++ b/module/actor.js
@@ -310,6 +310,30 @@ export class RdDActor extends Actor {
getDemiReve() {
return Misc.templateData(this).reve.tmrpos.coord;
}
+
+ /* -------------------------------------------- */
+ async verifierPotionsEnchantees() {
+ let potionsEnchantees = this.filterItemsData( it => it.type == 'potion' && it.data.categorie.toLowerCase().includes('enchante'));
+ for ( let potion of potionsEnchantees) {
+ if ( !potion.prpermanent) {
+ console.log(potion);
+ let newPr = (potion.data.pr > 0) ? potion.data.pr - 1 : 0;
+ let update = { _id: potion._id, 'data.pr': newPr};
+ const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
+
+ let messageData = {
+ pr : newPr,
+ alias : this.name,
+ potionName : potion.name,
+ potionImg : potion.img
+ }
+ ChatMessage.create({
+ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
+ content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html`, messageData)
+ });
+ }
+ }
+ }
/* -------------------------------------------- */
async deleteSortReserve(sortReserve) {
@@ -358,6 +382,7 @@ export class RdDActor extends Actor {
await this.retourSeuilDeReve(message);
this.bonusRecuperationPotion= 0; // Reset potion
await this.retourSust(message);
+ await this.verifierPotionsEnchantees();
message.content = `A la fin Chateau Dormant, ${message.content}
Un nouveau jour se lève`;
ChatMessage.create(message);
}
@@ -3202,7 +3227,7 @@ export class RdDActor extends Actor {
return guerisonData;
}
- /* -------------------------------------------- */
+ /* -------------------------------------------- */
async consommerPotionSoin(potionData) {
potionData.alias = this.name;
@@ -3216,22 +3241,17 @@ export class RdDActor extends Actor {
});
// Gestion de la résistance:
let rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8 );
+ potionData.reussiteReve = false;
if (!rolled.isSuccess) {
await this.reveActuelIncDec(-1);
potionData.guerisonData = await this.buildPotionGuerisonList(potionData.pointsGuerison);
- potionData.guerisonMinutes = potionData.guerisonData.pointsConsommes * 5;
+ potionData.guerisonMinutes = potionData.guerisonData.pointsConsommes * 5;
potionData.reussiteReve = true;
- ChatMessage.create({
- whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
- content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData )
- });
- } else {
- potionData.reussiteReve = false;
- ChatMessage.create({
- whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
- content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData )
- });
}
+ ChatMessage.create({
+ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
+ content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData )
+ });
} else {
potionData.enchanteTexte = "";
potionData.isEnchante = false;
@@ -3243,17 +3263,64 @@ 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;
+ ChatMessage.create({
+ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
+ content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-repos.html`, potionData )
+ });
+ // Gestion de la résistance:
+ let rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8 );
+ potionData.reussiteReve = false;
+ if (!rolled.isSuccess) {
+ await this.reveActuelIncDec(-1);
+ let fatigueActuelle = this.getFatigueActuelle();
+ potionData.caseFatigueReel = (fatigueActuelle >= potionData.casesRepos) ? potionData.casesRepos : fatigueActuelle;
+ potionData.guerisonDureeUnite = (potionData.data.reposalchimique) ? "rounds" : "minutes";
+ potionData.guerisonDureeValue = (potionData.data.reposalchimique) ? potionData.caseFatigueReel : potionData.caseFatigueReel*5;
+ potionData.reussiteReve = true;
+ potionData.aphasiePermanente = false;
+ if ( potionData.data.reposalchimique ) {
+ let chanceAphasie = new Roll("1d100").evaluate({async : false} ).total;
+ if ( chanceAphasie <= potionData.data.pr ) {
+ potionData.aphasiePermanente = true;
+ }
+ }
+ await this.santeIncDec("fatigue", -potionData.caseFatigueReel);
+ }
+ ChatMessage.create({
+ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
+ 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 )
+ });
+ this.bonusRepos = potionData.data.herbeBonus;
+ }
+ }
+
/* -------------------------------------------- */
async consommerPotion( potion ) {
const potionData = Misc.data(potion);
if ( potionData.data.categorie.includes('Soin')) {
this.consommerPotionSoin( potionData);
- } else if( potion.data.categorie.includes('Repos')) {
- //TODO
+ } else if( potionData.data.categorie.includes('Repos')) {
+ this.consommerPotionRepos(potionData);
} else {
//TODO
}
+ await this.deleteEmbeddedDocuments('Item', [ potion._id ] );
}
/* -------------------------------------------- */
diff --git a/module/rdd-herbes.js b/module/rdd-herbes.js
index df915c7e..cded07e6 100644
--- a/module/rdd-herbes.js
+++ b/module/rdd-herbes.js
@@ -60,6 +60,11 @@ export class RdDHerbes extends Item {
}
}
+ /* -------------------------------------------- */
+ static calculePointsRepos( data ) {
+ return data.herbebonus * data.pr;
+ }
+
/* -------------------------------------------- */
static calculePointsGuerison( data ){
return data.herbebonus * data.pr;
diff --git a/module/rdd-utility.js b/module/rdd-utility.js
index 4265bb8f..310330c1 100644
--- a/module/rdd-utility.js
+++ b/module/rdd-utility.js
@@ -187,7 +187,8 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-alchimie.html',
'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-actor-carac-xp.html',
+ 'systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html'
];
Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null'));
diff --git a/templates/chat-appliquer-potion-repos.html b/templates/chat-appliquer-potion-repos.html
new file mode 100644
index 00000000..a42b2c91
--- /dev/null
+++ b/templates/chat-appliquer-potion-repos.html
@@ -0,0 +1,22 @@
+
+