From 6a46faadc2a6d1f4339ccdcdbfca59f359b8ee78 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Sat, 8 Apr 2023 18:49:54 +0200 Subject: [PATCH] Rework combat --- modules/heritiers-actor.js | 26 ++++++++- modules/heritiers-config.js | 2 +- modules/heritiers-roll-dialog.js | 71 +++++++++++++++-------- modules/heritiers-utility.js | 93 ++++++++++++++++++++---------- templates/actor-pnj-sheet.html | 10 ++++ templates/chat-cc-result.html | 34 +++++++++++ templates/chat-degats-result.html | 28 --------- templates/chat-generic-result.html | 4 +- templates/roll-dialog-generic.html | 14 ----- 9 files changed, 178 insertions(+), 104 deletions(-) create mode 100644 templates/chat-cc-result.html delete mode 100644 templates/chat-degats-result.html diff --git a/modules/heritiers-actor.js b/modules/heritiers-actor.js index d9b686c..cf0001e 100644 --- a/modules/heritiers-actor.js +++ b/modules/heritiers-actor.js @@ -160,7 +160,7 @@ export class HeritiersActor extends Actor { /* -------------------------------------------- */ prepareUtileSkill(item) { let specList = [] - if (item.system.categorie == "utile") { + if (item && item.system.categorie && item.system.categorie == "utile") { for (let spec of item.system.specialites) { specList.push(spec.name) } @@ -480,6 +480,20 @@ export class HeritiersActor extends Actor { } return talents } + /* -------------------------------------------- */ + getCurrentParade() { + if ( this.system.statutmasque == "masque") { + return this.system.combat.parade.masquee + } + return this.system.combat.parade.demasquee + } + /* -------------------------------------------- */ + getCurrentEsquive() { + if ( this.system.statutmasque == "masque") { + return this.system.combat.esquive.masquee + } + return this.system.combat.esquive.demasquee + } /* -------------------------------------------- */ getTricherie() { @@ -522,9 +536,15 @@ export class HeritiersActor extends Actor { } if (compName) { rollData.competence = duplicate(this.items.find(item => item.name.toLowerCase() == compName.toLowerCase()) || {}) - this.prepareUtileSkill(rollData.competence) - rollData.actionImg = rollData.competence?.img + if (rollData.competence && rollData.competence.name) { + this.prepareUtileSkill(rollData.competence) + rollData.actionImg = rollData.competence?.img + } else { + rollData.competence = undefined + } } + HeritiersUtility.updateWithTarget(rollData) + return rollData } /* -------------------------------------------- */ diff --git a/modules/heritiers-config.js b/modules/heritiers-config.js index 819fc28..5c97969 100644 --- a/modules/heritiers-config.js +++ b/modules/heritiers-config.js @@ -64,7 +64,7 @@ export const HERITIERS_CONFIG = { "demasque": "Démasqué" }, seuilsDifficulte: { - "0": "Aucun/Non applicable", + "-1": "Aucun/Non applicable", "5": "Enfantine", "6": "Triviale", "7": "Moins Triviale", diff --git a/modules/heritiers-roll-dialog.js b/modules/heritiers-roll-dialog.js index 2c1d034..d4555dc 100644 --- a/modules/heritiers-roll-dialog.js +++ b/modules/heritiers-roll-dialog.js @@ -13,32 +13,46 @@ export class HeritiersRollDialog extends Dialog { /* -------------------------------------------- */ constructor(actor, rollData, html, options, close = undefined) { + let buttons = { + rolld8: { + icon: '', + label: "Lancer 1d8", + callback: () => { this.roll("d8") } + }, + rolld10: { + icon: '', + label: "Lancer 1d10", + callback: () => { this.roll("d10") } + }, + rolld12: { + icon: '', + label: "Lancer 1d12", + callback: () => { this.roll("d12") } + } + } + if (rollData.tricherie) { + buttons["rollTricherie"] = { + icon: '', + label: "Lancer avec 1 Point de Tricherie", + callback: () => { this.roll("tricherie") } + } + } + if (rollData.heritage) { + buttons["rollHeritage"] = { + icon: '', + label: "Lancer avec 1 Point d'Héritage", + callback: () => { this.roll("heritage") } + } + } + buttons["Cancel"] = { + icon: '', + label: "Annuler", + callback: () => { this.close() } + } let conf = { title: "Test de Capacité", content: html, - buttons: - { - rolld8: { - icon: '', - label: "Lancer 1d8", - callback: () => { this.roll("d8") } - }, - rolld10: { - icon: '', - label: "Lancer 1d10", - callback: () => { this.roll("d10") } - }, - rolld12: { - icon: '', - label: "Lancer 1d12", - callback: () => { this.roll("d12") } - }, - cancel: { - icon: '', - label: "Annuler", - callback: () => { this.close() } - } - }, + buttons: buttons, close: close } // Overwrite in case of carac only -> 1d10 @@ -64,7 +78,16 @@ export class HeritiersRollDialog extends Dialog { /* -------------------------------------------- */ roll(dice) { - this.rollData.mainDice = dice + if (dice == "heritage") { + this.rollData.useHeritage = true + } + else { + if (dice == "tricherie") { + this.rollData.useTricherie = true + } else { + this.rollData.mainDice = dice + } + } HeritiersUtility.rollHeritiers(this.rollData) } diff --git a/modules/heritiers-utility.js b/modules/heritiers-utility.js index bc5bf2c..d4e18e0 100644 --- a/modules/heritiers-utility.js +++ b/modules/heritiers-utility.js @@ -288,14 +288,14 @@ export class HeritiersUtility { rollData.marge = 0 if (isTricherieHeritage) { - let resTab = [ rollData.roll.terms[0].results[0].result, rollData.roll.terms[0].results[1].result, rollData.roll.terms[0].results[2].result ] + let resTab = [rollData.roll.terms[0].results[0].result, rollData.roll.terms[0].results[1].result, rollData.roll.terms[0].results[2].result] rollData.diceResult = resTab[0] + "," + resTab[1] + "," + resTab[2] - let subResult = Math.max(Math.max(resTab[0], resTab[1]), resTab[2]) + let subResult = Math.max(Math.max(resTab[0], resTab[1]), resTab[2]) if (resTab[1] == 1) { resTab[1] -= 4 } if (resTab[2] == 1) { resTab[2] -= 6 } if (resTab[2] == 2) { resTab[2] -= 7 } rollData.finalResult = rollData.roll.total - subResult + Math.max(Math.max(resTab[0], resTab[1]), resTab[2]) - + // Gestion des résultats spéciaux resTab = resTab.sort() if ((resTab[0] == resTab[1]) && (resTab[1] == resTab[2])) { @@ -316,29 +316,59 @@ export class HeritiersUtility { if (rollData.useHeritage) { this.incDecHeritage() } - + } else { rollData.finalResult = rollData.roll.total + let rollValue = rollData.roll.terms[0].results[0].result + rollData.diceResult = rollData.roll.terms[0].results[0].result if (rollData.mainDice.includes("d10")) { - if (rollData.diceResult == 1) { - rollData.finalResult -= 3 + rollData.diceResult // substract 3 and the 1 value that has been added + if (rollValue == 1) { + rollData.finalResult -= 3 + rollValue // substract 3 and the 1 value that has been added } } if (rollData.mainDice.includes("d12")) { - if (rollData.diceResult == 1 || rollData.diceResult == 2) { - rollData.finalResult -= 5 + rollData.diceResult // Remove also the dice result has it has been added already + if (rollValue == 1 || rollValue == 2) { + rollData.finalResult -= 5 + rollValue // Remove also the dice result has it has been added already } } } - //rollData.finalResult = Math.max(rollData.finalResult, 0) - //console.log("Result : ", rollData) - if (rollData.marge == 0 && rollData.sdValue > 0) { - rollData.marge = rollData.finalResult - rollData.sdValue - rollData.isSuccess = (rollData.finalResult >= rollData.sdValue) - rollData.isCriticalSuccess = ((rollData.finalResult - rollData.sdValue) >= 7) - rollData.isCriticalFailure = ((rollData.finalResult - rollData.sdValue) <= -7) + } + + /* -------------------------------------------- */ + static computeArmeDegats(rollData, actor) { + rollData.degatsArme = rollData.arme.system.degats + rollData.marge + if (rollData.arme.system.categorie == "lourde") { + rollData.degatsArme += actor.system.caracteristiques.for.value } + if (rollData.arme.system.categorie == "blanche" || rollData.arme.system.categorie == "improvise") { + rollData.degatsArme += Math.max(0, actor.system.caracteristiques.for.value - 2) + } + } + + /* -------------------------------------------- */ + static computeMarge(rollData, seuil) { + if (rollData.marge == 0 && seuil >= 0) { + rollData.marge = rollData.finalResult - seuil + rollData.isSuccess = (rollData.finalResult >= seuil) + rollData.isCriticalSuccess = ((rollData.finalResult - seuil) >= 7) + rollData.isCriticalFailure = ((rollData.finalResult - seuil) <= -7) + } + } + + /* -------------------------------------------- */ + static async displayUneDefense(rollData, actor, nomDefense, valeurDefense) { + rollData.defenderMode = nomDefense + rollData.defenderValue = valeurDefense + rollData.marge = 0 + this.computeMarge(rollData, valeurDefense) + if (rollData.isSuccess) { + this.computeArmeDegats(rollData, actor) + } + this.createChatWithRollMode(rollData.alias, { + content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-cc-result.html`, rollData) + }, rollData, "selfroll") + } /* -------------------------------------------- */ @@ -380,26 +410,26 @@ export class HeritiersUtility { rollData.roll = myRoll console.log(">>>> ", myRoll) this.computeResult(actor, rollData) - + this.computeMarge(rollData, rollData.sdValue) // Calcul de la marge si seuil présent + if (rollData.mode == "init") { actor.setFlag("world", "last-initiative", rollData.finalResult) } // Compute damages, cf p 187 if (rollData.arme && rollData.isSuccess) { - rollData.degatsArme = rollData.arme.system.degats + rollData.marge - if (rollData.arme.system.categorie == "lourde") { - rollData.degatsArme += actor.system.caracteristiques.for.value - } - if (rollData.arme.system.categorie == "blanche" || rollData.arme.system.categorie == "improvise") { - rollData.degatsArme += Math.max(0, actor.system.caracteristiques.for.value - 2) - } + this.computeArmeDegats(rollData, actor) } this.createChatWithRollMode(rollData.alias, { content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-generic-result.html`, rollData) }, rollData) + if (rollData.defenderTokenId && rollData.arme && rollData.arme.system.categorie != "trait") { + await this.displayUneDefense(rollData, actor, "Parade", rollData.defenderParade) + await this.displayUneDefense(rollData, actor, "Esquive", rollData.defenderEsquive) + } + } /* -------------------------------------------- */ @@ -509,7 +539,7 @@ export class HeritiersUtility { rollId: randomID(16), rollMode: game.settings.get("core", "rollMode"), sdList: game.system.lesheritiers.config.seuilsDifficulte, - sdValue: 0, + sdValue: -1, bonusMalusContext: 0 } return rollData @@ -521,18 +551,17 @@ export class HeritiersUtility { if (target) { rollData.defenderTokenId = target.id let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor - rollData.armeDefense = defender.getBestDefenseValue() - rollData.targetVigueur = defender.getVigueur() - if (rollData.armeDefense) { - rollData.difficulte = rollData.armeDefense.system.totalDefensif - } else { - ui.notifications.warn("Aucune arme de défense équipée, difficulté manuelle à positionner.") - } + rollData.defenderName = defender.name + rollData.defenderParade = defender.getCurrentParade() + rollData.defenderEsquive = defender.getCurrentEsquive() } } /* -------------------------------------------- */ - static createChatWithRollMode(name, chatOptions, rollData = undefined) { + static createChatWithRollMode(name, chatOptions, rollData = undefined, rollMode = undefined) { + if ( rollMode == undefined) { + rollMode = game.settings.get("core", "rollMode") + } this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions, rollData) } diff --git a/templates/actor-pnj-sheet.html b/templates/actor-pnj-sheet.html index 42a2fd0..03ca258 100644 --- a/templates/actor-pnj-sheet.html +++ b/templates/actor-pnj-sheet.html @@ -50,6 +50,16 @@    + + + +    diff --git a/templates/chat-cc-result.html b/templates/chat-cc-result.html new file mode 100644 index 0000000..54e8202 --- /dev/null +++ b/templates/chat-cc-result.html @@ -0,0 +1,34 @@ +
+ {{#if actorImg}} + {{alias}} + {{/if}} +

{{alias}}

+
+ +
+ +{{#if actionImg}} +
+ {{name}} +
+{{/if}} + +
+
+ +
+ +
diff --git a/templates/chat-degats-result.html b/templates/chat-degats-result.html deleted file mode 100644 index 131bf71..0000000 --- a/templates/chat-degats-result.html +++ /dev/null @@ -1,28 +0,0 @@ -
- {{#if actorImg}} - {{alias}} - {{/if}} -

{{alias}}

-
- -
- -{{#if actionImg}} -
- {{name}} -
-{{/if}} - -
-
- -
- -
diff --git a/templates/chat-generic-result.html b/templates/chat-generic-result.html index eedea7a..96d1292 100644 --- a/templates/chat-generic-result.html +++ b/templates/chat-generic-result.html @@ -42,9 +42,9 @@
  • Formule : {{diceFormula}}
  • Résultat du dé : {{diceResult}}
  • -
  • Total : {{finalResult}} (Marge : {{marge}})
  • +
  • Total : {{finalResult}} {{#if (gt sdValue "-1")}}(Marge : {{marge}}){{/if}}
  • - {{#if sdValue}} + {{#if (gt sdValue "-1")}} {{#if isSuccess}}
  • Succès... {{#if arme}} diff --git a/templates/roll-dialog-generic.html b/templates/roll-dialog-generic.html index c99fa61..1fbb0d0 100644 --- a/templates/roll-dialog-generic.html +++ b/templates/roll-dialog-generic.html @@ -71,20 +71,6 @@ {{pvMalus}} - {{#if tricherie}} -
    - Utiliser 1 point de Tricherie ({{tricherie}}) ? - -
    - {{/if}} - - {{#if heritage}} -
    - Utiliser 1 point d'Heritage ? ({{heritage}}) - -
    - {{/if}} -
    Bonus/Malus