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

@ -48,7 +48,7 @@ export const TEDEUM_CONFIG = {
11: { valeur: 11, qualite: "Excellent", dice: "d12", negativeDice: "d6", savoir: "Docte", sensibilite: "Subtil", entregent: "Galant", puissance: "Musculeux", complexion: "Sanguin", adresse: "Preste" },
12: { valeur: 12, qualite: "Admirable", dice: "d20", negativeDice: "d4", savoir: "Humaniste", sensibilite: "Spirituel", entregent: "Sémillant", puissance: "Hercule", complexion: "Aguerri", adresse: "Alerte" },
},
diceValeur: [ "d4", "d6", "d8", "d10", "d12", "d20" ],
degatsArmure : {
sansarmure : { label: "Sans armure"},
cuir : { label: "Cuir"},
@ -110,5 +110,21 @@ export const TEDEUM_CONFIG = {
domesticite: { label: "Domesticité", id: "domesticite", value: 8 },
paysannerie: { label: "Paysannerie", id: "paysannerie", value: 9 },
gueux: { label: "Gueux", id: "gueux", value: 10 },
}
},
bonusMalus: [
{ value: "-2", label: "-2 niveaux" },
{ value: "-1", label: "-1 niveau" },
{ value: "0", label: "Aucun" },
{ value: "1", label: "+1 niveau" },
{ value: "2", label: "+2 niveaux" }
],
blessures: [
{ value: 0, label: "Indemne", degatsMax: -1, count: 0, modifier: 0 },
{ value: 1, label: "Estafilade/Contusion", degatsMax: 2, count: 1, modifier: 0 },
{ value: 2, label: "Plaie", degatsMax: 4, count: 1, modifier: -1 },
{ value: 3, label: "Plaie béante", degatsMax: 6, count: 1, modifier: -2 },
{ value: 4, label: "Plaie atroce", degatsMax: 6, count: 1, horsCombat: true, modifier: -12 },
{ value: 5, label: "Tué net", degatsMax: 100, count: 1, horsCombat: true, mort: true, modifier: -12 }
]
}

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)