Utilise RdDRoll pour les caracs

ajout d'un callback dédié à l'expérience
limite de la table de résolution à 60 (rêve actuel jusqu'à 3x limite)
This commit is contained in:
Vincent Vandemeulebrouck 2020-12-06 23:31:23 +01:00
parent 9275f61a08
commit d081dbf230
5 changed files with 109 additions and 72 deletions

View File

@ -268,7 +268,7 @@ export class RdDActorSheet extends ActorSheet {
}); });
html.find('#chance-appel').click((event) => { html.find('#chance-appel').click((event) => {
this.actor.appelChance(); this.actor.rollAppelChance();
}); });
// Roll Skill // Roll Skill

View File

@ -1355,61 +1355,90 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollCarac( caracName ) _createCallbackExperience() {
{ return {
let carac = this.getCaracByName(caracName); condition: r => r.rolled.isPart && r.finalLevel < 0 && game.settings.get("core", "rollMode") != 'selfroll',
let rollData = { action: r => this._appliquerAjoutExperience(r)
selectedCarac: carac, };
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
difficultesLibres: CONFIG.RDD.difficultesLibres,
etat: this.data.data.compteurs.etat.value,
finalLevel: 0,
diffConditions: 0,
diffLibre: 0,
malusArmureValue: (this.data.data.attributs) ? this.data.data.attributs.malusarmure.value : 0,
surencMalusFlag: (this.data.data.compteurs.surenc.value < 0),
surencMalusValue: this.data.data.compteurs.surenc.value,
surencMalusApply: false,
isNatation: false,
useEncForNatation: false
} }
console.log(caracName, rollData);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', rollData); async _appliquerAjoutExperience(rollData) {
new RdDRollDialog("carac", html, rollData, this ).render(true); // TODO: si pas de compétence, minimum 1 pour carac
// TODO: appliquer l'expérience automatiquement
let xpmsg = RdDResolutionTable.buildXpMessage(rollData.rolled, rollData.finalLevel);
let message = ChatUtility.prepareChatMessage('gmroll', this.name);
message.content = "<strong>" + rollData.selectedCarac.label + "</strong>"
+ xpmsg;
ChatMessage.create(message);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async appelChance( ) async rollCarac( caracName )
{ {
let rollData = { let rollData = { selectedCarac: this.getCaracByName(caracName) };
selectedCarac: this.getCaracByName('chance-actuelle'),
diffConditions: this.ajustementAstrologique()
}
const dialog = await RdDRoll.create( const dialog = await RdDRoll.create(this, rollData,
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', {html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html'},
this,
rollData,
{ {
name: 'appelChance', name: 'jet-'+caracName,
label: 'Appel à la chance', label: 'Lancer : '+rollData.selectedCarac.label,
callbacks: [ callbacks: [
{ action: rollData => this._appelChanceResultat(rollData) } this._createCallbackExperience(),
{ action: this._rollCaracResult }
] ]
} }
); );
dialog.render(true); dialog.render(true);
} }
async _rollCaracResult(rollData) {
let rolled = rollData.rolled;
let resumeCompetence = (rollData.diffLibre + rollData.diffConditions);
let explications = "<br>Points de taches : " + rolled.ptTache;
// Final chat message
let chatOptions = {
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + resumeCompetence + "</strong>"
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat
+ RdDResolutionTable.explain(rolled)
+ explications
}
ChatUtility.chatWithRollMode(chatOptions, this.name)
}
/* -------------------------------------------- */ /* -------------------------------------------- */
_appelChanceResultat(rollData) { async rollAppelChance( )
{
let rollData = {
selectedCarac: this.getCaracByName('chance-actuelle'),
diffConditions: this.ajustementAstrologique()
}
const dialog = await RdDRoll.create(this, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html'},
{
name: 'appelChance',
label: 'Appel à la chance',
callbacks: [
this._createCallbackExperience(),
{ action: this._appelChanceResult }
]
}
);
dialog.render(true);
}
_appelChanceResult(rollData) {
const message = { const message = {
user: game.user._id, user: game.user._id,
alias: this.name, alias: this.name,
content: this.name + " fait appel à la chance" + RdDResolutionTable.explain(rollData.rolled) content: this.name + " fait appel à la chance" + RdDResolutionTable.explain(rollData.rolled)
}; };
if (rollData.rolled.isSuccess) { if (rollData.rolled.isSuccess) {
message.content += "<br>Dépense d'un point de chance, l'action peut être retentée" message.content += "<br>Un point de chance est dépensée, l'action peut être retentée"
this.chanceActuelleIncDec(-1) this.chanceActuelleIncDec(-1)
} }
ChatMessage.create(message); ChatMessage.create(message);

View File

@ -6,7 +6,10 @@ export class ChatUtility {
static chatWithRollMode(chatOptions, name) { static chatWithRollMode(chatOptions, name) {
let rollMode = game.settings.get("core", "rollMode"); let rollMode = game.settings.get("core", "rollMode");
chatOptions.user = game.user._id; ChatUtility.createChatMessage(chatOptions, rollMode, name);
}
static createChatMessage( chatOptions, rollMode, name) {
switch (rollMode) { switch (rollMode) {
case "blindroll": // GM only case "blindroll": // GM only
if (!game.user.isGM) { if (!game.user.isGM) {
@ -19,24 +22,29 @@ export class ChatUtility {
chatOptions.whisper = ChatUtility.getUsers(user => user.isGM); chatOptions.whisper = ChatUtility.getUsers(user => user.isGM);
} }
break; break;
case "gmroll": // GM + rolling player
chatOptions.user = game.user._id;
chatOptions.whisper = ChatUtility.getWhisperRecipientsAndGMs(name);
break;
case "selfroll": // only the user
chatOptions.user = game.user._id;
chatOptions.whisper = [game.user._id];
break;
default: default:
case "roll": // everybody chatOptions.whisper = ChatUtility.getWhisperRecipients(rollMode, name);
chatOptions.whisper = undefined;
break; break;
} }
console.log("roll message", chatOptions);
ChatMessage.create(chatOptions); ChatMessage.create(chatOptions);
} }
static prepareChatMessage( rollMode, name) {
return {
user: game.user._id,
whisper: ChatUtility.getWhisperRecipients(rollMode, name)
}
}
static getWhisperRecipients( rollMode, name) {
switch (rollMode) {
case "blindroll": return ChatUtility.getUsers(user => user.isGM);
case "gmroll": return ChatUtility.getWhisperRecipientsAndGMs(name);
case "selfroll": return [game.user._id];
}
return undefined;
}
static getWhisperRecipientsAndGMs(name) { static getWhisperRecipientsAndGMs(name) {
return ChatMessage.getWhisperRecipients(name) return ChatMessage.getWhisperRecipients(name)
.concat(this.getUsers(user => user.isGM)); .concat(this.getUsers(user => user.isGM));

View File

@ -55,7 +55,7 @@ const reussites = [
const reussiteSignificative = reussites.find(r => r.code == "sign"); const reussiteSignificative = reussites.find(r => r.code == "sign");
const reussiteNormale = reussites.find(r => r.code == "norm"); const reussiteNormale = reussites.find(r => r.code == "norm");
const echecNormal = reussites.find(r => r.code == "echec"); const echecNormal = reussites.find(r => r.code == "echec");
const caracMaximumResolution = 60;
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDResolutionTable { export class RdDResolutionTable {
static resolutionTable = this.build() static resolutionTable = this.build()
@ -63,7 +63,7 @@ export class RdDResolutionTable {
/* -------------------------------------------- */ /* -------------------------------------------- */
static build() { static build() {
let table = [] let table = []
for (var caracValue = 0; caracValue <= 60; caracValue++) { for (var caracValue = 0; caracValue <= caracMaximumResolution; caracValue++) {
table[caracValue] = this._computeRow(caracValue); table[caracValue] = this._computeRow(caracValue);
} }
return table; return table;
@ -84,7 +84,7 @@ export class RdDResolutionTable {
if (rolled.caracValue != null && rolled.finalLevel!= null) { if (rolled.caracValue != null && rolled.finalLevel!= null) {
message += "(" + rolled.caracValue + " à " + Misc.toSignedString(rolled.finalLevel) + ") "; message += "(" + rolled.caracValue + " à " + Misc.toSignedString(rolled.finalLevel) + ") ";
} }
message += rolled.quality message += '<strong>' + rolled.quality + '</strong>'
return message; return message;
} }
@ -147,7 +147,6 @@ export class RdDResolutionTable {
return ""; return "";
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static _computeReussite(chances, roll) { static _computeReussite(chances, roll) {
const reussite = reussites.find(x => x.condition(chances, roll)); const reussite = reussites.find(x => x.condition(chances, roll));
@ -219,7 +218,7 @@ export class RdDResolutionTable {
static _buildHTMLTable(caracValue, levelValue, minCarac, maxCarac, minLevel, maxLevel) { static _buildHTMLTable(caracValue, levelValue, minCarac, maxCarac, minLevel, maxLevel) {
let countColonnes = maxLevel - minLevel; let countColonnes = maxLevel - minLevel;
minCarac = Math.max(minCarac, 1); minCarac = Math.max(minCarac, 1);
maxCarac = Math.min(maxCarac, 30); maxCarac = Math.min(maxCarac, caracMaximumResolution);
minLevel = Math.max(minLevel, -10); minLevel = Math.max(minLevel, -10);
maxLevel = Math.max(Math.min(maxLevel, 22), minLevel + countColonnes); maxLevel = Math.max(Math.min(maxLevel, 22), minLevel + countColonnes);

View File

@ -10,17 +10,18 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
export class RdDRoll extends Dialog { export class RdDRoll extends Dialog {
static async create(htmlTemplate, actor, rollData, ...actions) { static async create(actor, rollData, dialogConfig, ...actions) {
RdDRoll._ensureCorrectActions(actions);
RdDRoll._ensureCorrectActions(actions);
RdDRoll._setDefaultOptions(actor, rollData); RdDRoll._setDefaultOptions(actor, rollData);
const html = await renderTemplate(htmlTemplate, rollData); const html = await renderTemplate(dialogConfig.html, rollData);
return new RdDRoll(actor, rollData, html, { let options = { classes: ["rdddialog"], width: 600, height: 500, 'z-index': 99999 };
classes: ["rdddialog"], if (dialogConfig.options) {
width: 600, height: 500, 'z-index': 99999 mergeObject(options, dialogConfig.options, { overwrite: true })
}, actions); }
return new RdDRoll(actor, rollData, html, options, actions);
} }
static _setDefaultOptions(actor, rollData) { static _setDefaultOptions(actor, rollData) {
@ -75,7 +76,7 @@ export class RdDRoll extends Dialog {
await RdDResolutionTable.rollData(this.rollData); await RdDResolutionTable.rollData(this.rollData);
if (action.callbacks) if (action.callbacks)
for (let callback of action.callbacks) { for (let callback of action.callbacks) {
if (callback.condition == undefined || callback.condition(this.rollData.rolled)) { if (callback.condition == undefined || callback.condition(this.rollData)) {
callback.action(this.rollData); callback.action(this.rollData);
} }
} }