Ajout fenetre de roll + gestion de base des rolls

This commit is contained in:
2022-06-03 08:15:39 +02:00
parent cca4383c33
commit eda51dec7f
10 changed files with 253 additions and 565 deletions

View File

@ -22,23 +22,38 @@ export class MournbladeUtility {
Handlebars.registerHelper('count', function (list) {
return list.length;
});
})
Handlebars.registerHelper('includes', function (array, val) {
return array.includes(val);
});
})
Handlebars.registerHelper('upper', function (text) {
return text.toUpperCase();
});
})
Handlebars.registerHelper('lower', function (text) {
return text.toLowerCase()
})
Handlebars.registerHelper('upperFirst', function (text) {
if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase() + text.slice(1)
});
})
Handlebars.registerHelper('notEmpty', function (list) {
return list.length > 0;
});
})
Handlebars.registerHelper('mul', function (a, b) {
return parseInt(a) * parseInt(b);
})
}
/* -------------------------------------------- */
static getModificateurOptions() {
let opt = []
for (let i = -15; i <= 15; i++) {
opt.push( `<option value="${i}">${i}</option>` )
}
return opt.concat("\n")
}
/* -------------------------------------------- */
static getAttributs() {
return { adr: "Adresse", pui: "Puissance", cla: "Clairvoyance", pre: "Présence", tre: "Trempe"}
@ -247,8 +262,43 @@ export class MournbladeUtility {
/* -------------------------------------------- */
static async rollMournblade(rollData) {
rollData.diceFormula = rollData.mainDice
if (rollData.competence) {
rollData.diceFormula += `+${rollData.attr.value}+${rollData.competence.data.niveau}+${rollData.modificateur}`
} else {
rollData.diceFormula += `+${rollData.attr.value}*2+${rollData.modificateur}`
}
let myRoll = rollData.roll
if (!myRoll) { // New rolls only of no rerolls
myRoll = new Roll(rollData.diceFormula).roll({ async: false });
console.log("ROLL : ", rollData.diceFormula)
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"));
rollData.roll = myRoll
}
console.log(">>>> ", myRoll)
rollData.finalResult = myRoll.total
if ( rollData.mainDice == "1d20") {
let diceValue = myRoll.terms[0].results[0].result
console.log("PAIR/IMP", diceValue)
if ( diceValue % 2 == 1) {
console.log("PAIR/IMP2", diceValue)
rollData.finalResult -= myRoll.terms[0].results[0].result // Substract value
if (diceValue == 1 || diceValue == 11) {
rollData.isDramatique = true
rollData.isSuccess = false
}
}
}
if (rollData.difficulte > 0 && !rollData.isDramatique) {
rollData.isSuccess = (myRoll.finalResult >= rollData.difficulte)
rollData.isHeroique = ((myRoll.finalResult - rollData.difficulte) >= 10)
rollData.isDramatique = ((myRoll.finalResult - rollData.difficulte) <= -10)
}
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-Mournblade-rpg/templates/chat-generic-result.html`, rollData)
content: await renderTemplate(`systems/fvtt-mournblade/templates/chat-generic-result.html`, rollData)
});
// And save the roll
@ -291,7 +341,7 @@ export class MournbladeUtility {
} else {
item = game.items.get(dataItem.id)
}
return item;
return item
}
/* -------------------------------------------- */
@ -338,6 +388,9 @@ export class MournbladeUtility {
let rollData = {
rollId: randomID(16),
rollMode: game.settings.get("core", "rollMode"),
modificateursOptions : this.getModificateurOptions(),
difficulte: 0,
modificateur: 0,
}
MournbladeUtility.updateWithTarget(rollData)
return rollData