Gestion de jets de competences et modificateurs associés

This commit is contained in:
2024-05-31 09:23:01 +02:00
parent af65209d23
commit 6b47cd3f40
33 changed files with 326 additions and 485 deletions

View File

@ -131,14 +131,14 @@ export class TeDeumUtility {
html.on("click", '.button-select-confront', event => {
let messageId = TeDeumUtility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
let rollData = message.getFlag("world", "ecryme-rolldata")
let rollData = message.getFlag("world", "te-deum-rolldata")
ui.notifications.info( game.i18n.localize("ECRY.chat.confrontselect"))
TeDeumUtility.manageConfrontation(rollData)
})
html.on("click", '.button-apply-cephaly-difficulty', event => {
let messageId = TeDeumUtility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
let rollData = message.getFlag("world", "ecryme-rolldata")
let rollData = message.getFlag("world", "te-deum-rolldata")
let difficulty = $("#" + rollData.rollId + "-cephaly-difficulty").val()
TeDeumUtility.manageCephalyDifficulty(rollData, difficulty)
})
@ -317,22 +317,47 @@ export class TeDeumUtility {
}
/* -------------------------------------------- */
static computeResults(rollData) {
static async computeResults(rollData) {
rollData.isSuccess = false
rollData.isReussiteCritique = false
rollData.isEchecCritique = false
if (!rollData.difficulty || rollData.difficulty == "-") {
return
}
rollData.margin = rollData.total - rollData.difficulty
if (rollData.total > rollData.difficulty) {
if (rollData.total >= rollData.difficulty) {
rollData.isSuccess = true
let maxMargin = rollData.skill.value + ((rollData.spec) ? 2 : 0)
rollData.margin = Math.min(rollData.margin, maxMargin)
if (rollData.total >= 2 * rollData.difficulty) {
rollData.isReussiteCritique = true
}
}
if (rollData.diceSum == 1) {
let critiqueRoll = await new Roll(rollData.carac.negativeDice).roll()
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.critiqueRoll = foundry.utils.duplicate(critiqueRoll)
if (critiqueRoll.total > rollData.competence.score) {
rollData.isEchecCritique = true
}
}
}
/* -------------------------------------------- */
static modifyDice(dice, bonusMalus) {
let newIndex = game.system.tedeum.config.diceValeur.indexOf(dice) + Number(bonusMalus)
newIndex = Math.min(Math.max(newIndex, 0), game.system.tedeum.config.diceValeur.length - 1)
return game.system.tedeum.config.diceValeur[newIndex]
}
/* -------------------------------------------- */
static computeRollFormula(rollData, actor, isConfrontation = false) {
rollData.diceFormula = ""
let diceFormula = ""
if (rollData.competence) {
let diceBase = this.modifyDice(rollData.carac.dice, rollData.bonusMalus+rollData.malusBlessures)
diceFormula = diceBase + "x + " + rollData.competence.system.score
}
if (rollData.enableProvidence) {
diceFormula += " + " + rollData.providence.dice
}
return diceFormula
}
@ -342,26 +367,36 @@ export class TeDeumUtility {
let actor = game.actors.get(rollData.actorId)
// Fix difficulty
if (!rollData.difficulty || rollData.difficulty == "-") {
rollData.difficulty = 0
rollData.difficulty = 7
}
rollData.difficulty = Number(rollData.difficulty)
rollData.difficulty = game.system.tedeum.config.difficulte[rollData.difficulty].value
let diceFormula = this.computeRollFormula(rollData, actor)
// Performs roll
let myRoll = new Roll(diceFormula).roll({ async: false })
let myRoll = await new Roll(diceFormula).roll()
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = duplicate(myRoll)
rollData.roll = foundry.utils.duplicate(myRoll)
rollData.total = myRoll.total
rollData.diceSum = myRoll.terms[0].total
rollData.diceFormula = diceFormula
this.computeResults(rollData)
await this.computeResults(rollData)
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-te-deum/templates/chat/chat-generic-result.hbs`, rollData)
})
await msg.setFlag("world", "ecryme-rolldata", rollData)
await msg.setFlag("world", "te-deum-rolldata", rollData)
console.log("Rolldata result", rollData)
// Decrement providence if needed
if (rollData.enableProvidence) {
actor.modifyProvidence(-1)
}
// Manage XP
if (rollData.isReussiteCritique || rollData.isEchecCritique) {
actor.modifyXP(rollData.carac.key, 1)
}
}
/* -------------------------------------------- */
@ -454,6 +489,10 @@ export class TeDeumUtility {
type: "roll-data",
rollMode: game.settings.get("core", "rollMode"),
difficulty: "pardefaut",
bonusMalus : "0",
isReroll : false,
enableProvidence : false,
malusBlessures: 0,
config: duplicate(game.system.tedeum.config)
}
TeDeumUtility.updateWithTarget(rollData)