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

@ -70,15 +70,15 @@ export class TeDeumActorPJSheet extends ActorSheet {
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item")
const li = $(ev.currentTarget).parents(".item-id")
let itemId = li.data("item-id")
const item = this.actor.items.get( itemId );
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item")
EcrymeUtility.confirmDelete(this, li).catch("Error : No deletion confirmed")
const li = $(ev.currentTarget).parents(".item-id")
TeDeumUtility.confirmDelete(this, li).catch("Error : No deletion confirmed")
})
html.find('.item-add').click(ev => {
let dataType = $(ev.currentTarget).data("type")
@ -107,9 +107,8 @@ export class TeDeumActorPJSheet extends ActorSheet {
} );
html.find('.roll-competence').click((event) => {
let categKey = $(event.currentTarget).data("category-key")
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollSkill(categKey, skillKey)
let compId = $(event.currentTarget).data("comp-id")
this.actor.rollCompetence(compId)
});
html.find('.roll-arme').click((event) => {
const armeId = $(event.currentTarget).data("arme-id")

View File

@ -1,5 +1,6 @@
/* -------------------------------------------- */
import { TeDeumUtility } from "../common/tedeum-utility.js";
import { TeDeumRollDialog } from "../dialogs/tedeum-roll-dialog.js";
/* -------------------------------------------- */
/* -------------------------------------------- */
@ -98,8 +99,28 @@ export class TeDeumActor extends Actor {
return comp;
}
/* -------------------------------------------- */
calculMalusBlessures() {
let modifierBlessures = 0
let nbBlessures = 0
// Cumul des malus de blessures
for (let locKey in this.system.localisation) {
let loc = this.system.localisation[locKey]
let bDef = game.system.tedeum.config.blessures[loc.blessures]
modifierBlessures += bDef.modifier
nbBlessures += bDef.count
}
// Si le nombre de blessures est supérieur au score d'endurance, alors malus supplémentaire
let endurance = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "endurance")
if ( nbBlessures > endurance.system.score) {
modifierBlessures += -1
}
return modifierBlessures
}
/* -------------------------------------------- */
updateCarac(c, key) {
c.key = key
c.name = game.system.tedeum.config.caracteristiques[key].label
c.generalqualite = game.system.tedeum.config.descriptionValeur[c.value].qualite
c.qualite = game.system.tedeum.config.descriptionValeur[c.value][key]
@ -124,6 +145,19 @@ export class TeDeumActor extends Actor {
providence.dice = game.system.tedeum.config.providence[providence.value].diceValue
return providence
}
/* -------------------------------------------- */
modifyProvidence(value) {
let providence = foundry.utils.duplicate(this.system.providence)
providence.value = Math.min(Math.max(providence.value + value, 0), 6)
this.update( { "system.providence": providence } )
}
/* -------------------------------------------- */
modifyXP(key, value) {
let xp = this.system.caracteristiques[key].experience
xp = Math.max(xp + value, 0)
this.update( { [`system.caracteristiques.${key}.experience`]: xp } )
}
/* -------------------------------------------- */
filterCompetencesByCarac(key) {
@ -132,6 +166,8 @@ export class TeDeumActor extends Actor {
if (c.system.isBase) {
c.system.score = this.system.caracteristiques[c.system.caracteristique].value
}
let caracDice = game.system.tedeum.config.descriptionValeur[this.system.caracteristiques[c.system.caracteristique].value].dice
c.system.formula = caracDice + "+" + c.system.score
})
return foundry.utils.deepClone( comp || {} )
}
@ -275,26 +311,30 @@ export class TeDeumActor extends Actor {
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
rollData.isReroll = false
rollData.providence = this.prepareProvidence()
rollData.malusBlessures = this.calculMalusBlessures()
return rollData
}
/* -------------------------------------------- */
getCommonCompetence(skillid) {
getCommonCompetence(compId) {
let rollData = this.getCommonRollData()
let competence = duplicate(this.items.find(it => it.type =="competence" && it.id == skillid))
let competence = duplicate(this.items.find(it => it.type =="competence" && it.id == compId))
rollData.competence = competence
let c = foundry.utils.duplicate(this.system.caracteristiques[competence.system.caracteristique])
this.updateCarac( c, competence.system.caracteristique)
rollData.carac = c
rollData.img = competence.img
return rollData
}
/* -------------------------------------------- */
rollCompetence(skillId) {
let rollData = this.getCommonCompetence(skillId)
rollCompetence(compId) {
let rollData = this.getCommonCompetence(compId)
rollData.mode = "competence"
rollData.title = rollData.competence.name
this.startRoll(rollData).catch("Error on startRoll")
@ -319,7 +359,8 @@ export class TeDeumActor extends Actor {
/* -------------------------------------------- */
async startRoll(rollData) {
let rollDialog = await EcrymeRollDialog.create(this, rollData)
console.log("startRoll", rollData)
let rollDialog = await TeDeumRollDialog.create(this, rollData)
rollDialog.render(true)
}

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)

View File

@ -6,7 +6,7 @@ export class TeDeumRollDialog extends Dialog {
static async create(actor, rollData) {
let options = { classes: ["tedeum-roll-dialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
let html = await renderTemplate('systems/fvtt-tedeum/templates/dialogs/roll-dialog-generic.hbs', rollData);
let html = await renderTemplate('systems/fvtt-te-deum/templates/dialogs/roll-dialog-generic.hbs', rollData);
return new TeDeumRollDialog(actor, rollData, html, options);
}
@ -38,12 +38,12 @@ export class TeDeumRollDialog extends Dialog {
/* -------------------------------------------- */
roll() {
EcrymeUtility.rollEcryme(this.rollData)
TeDeumUtility.rollTeDeum(this.rollData)
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-tedeum/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
const content = await renderTemplate("systems/fvtt-te-deum/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
this.data.content = content
this.render(true)
}
@ -61,8 +61,15 @@ export class TeDeumRollDialog extends Dialog {
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
})
html.find('#roll-difficulty').change((event) => {
this.rollData.difficulty = Number(event.currentTarget.value) || 0
this.rollData.difficulty = String(event.currentTarget.value) || "pardefaut"
})
html.find('#roll-bonus-malus').change((event) => {
this.rollData.bonusMalus = event.currentTarget.value || "0"
})
html.find('#roll-enable-providence').change((event) => {
this.rollData.enableProvidence = event.currentTarget.checked
})
}
}