From 09cfdf922e774b2ddb670da127dc302da2cb08dc Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sat, 14 Nov 2020 21:22:29 +0100 Subject: [PATCH] #16 Gestion des critiques en combat --- module/actor.js | 45 +++++++++++++++++++++++++++------------ module/rdd-roll-dialog.js | 2 +- module/rdd-utility.js | 13 ++++++++--- system.json | 2 +- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/module/actor.js b/module/actor.js index 3ee84914..3b48a36d 100644 --- a/module/actor.js +++ b/module/actor.js @@ -124,6 +124,29 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async performRoll(rollData) { + // Perform the roll + let rolled = RdDResolutionTable.rollChances(rollData.rollTarget); + //rolled.isPart = true; // Pour tester le particulières + rollData.rolled = rolled; // garder le résultat + this.currentRollData = rollData; + if (rolled.isPart && rollData.arme && !rollData.attackerRoll) { // Réussite particulière avec attaque -> choix ! + let message = "Réussite particulière en attaque"; + message = message + "
Attaquer en Force"; + message = message + "
Attaquer en Rapidité"; + message = message + "
Attaquer en Finesse"; + ChatMessage.create( {content : message, whisper: ChatMessage.getWhisperRecipients( this.name ) } ); + } else { + this.continueRoll(rollData); + } + } + + /* -------------------------------------------- */ + async continueRoll(rollData) { + + let rolled = rollData.rolled; + let result = rolled.roll; + let quality = rolled.quality + // Manage weapon categories when parrying (cf. page 115 ) let need_resist = false; // Do we need to make resistance roll for defender ? if (rollData.arme && rollData.attackerRoll) { // Manage parade depeding on weapon type, and change roll results @@ -136,15 +159,10 @@ export class RdDActor extends Actor { if (attCategory.match("epee") && (defCategory == "hache" || defCategory == "lance")) need_resist = true; } - if (this.data.data.sante.sonne.value) - { + if (this.data.data.sante.sonne.value || rollData.particuliereAttaque == "finesse") { rollData.needSignificative = true; } - let rolled = RdDResolutionTable.rollChances(rollData.rollTarget); - let result = rolled.roll; - let quality = rolled.quality - console.log(">>> ROLL", rollData, rolled); let xpmsg = RdDResolutionTable.buildXpMessage(rolled, rollData.finalLevel); @@ -158,18 +176,17 @@ export class RdDActor extends Actor { explications = "" // In case of fight, replace the message per dommages + localization. it indicates if result is OK or not if (rollData.attackerRoll) { // Defense case ! - if (rolled.isSuccess) { + if (rollData.needSignificative && rolled.isSign ) { explications += "
Attaque parée/esquivée !"; - } else { + } else if ( !rollData.needSignificative && rolled.isSuccess) { + explications += "
Attaque parée/esquivée !"; + } else { explications += "
Esquive/Parade échouée, encaissement !"; encaisser = true; } } else { // This is the attack roll! if (rolled.isSuccess) { - if (rolled.isPart) { // Particulière ! - console.log("TODO Gérer critique!"); - } - rollData.domArmePlusDom = this._calculBonusDommages(rollData.selectedCarac, rollData.arme); + rollData.domArmePlusDom = this._calculBonusDommages(rollData.selectedCarac, rollData.arme, rollData.particuliereAttaque == "force" ); rollData.degats = new Roll("2d10").roll().total + rollData.domArmePlusDom; rollData.loc = RdDUtility.getLocalisation(); for (let target of game.user.targets) { @@ -223,8 +240,8 @@ export class RdDActor extends Actor { } } - _calculBonusDommages(carac, arme) { - const dmgArme = parseInt(arme.data.dommages); + _calculBonusDommages(carac, arme, isForce=false) { + const dmgArme = parseInt(arme.data.dommages) + (isForce)? 5 : 0; const dmgPerso = parseInt(this.data.data.attributs.plusdom.value); if (carac.label == "Tir") { return dmgArme; diff --git a/module/rdd-roll-dialog.js b/module/rdd-roll-dialog.js index be5a5223..07578790 100644 --- a/module/rdd-roll-dialog.js +++ b/module/rdd-roll-dialog.js @@ -99,7 +99,7 @@ export class RdDRollDialog extends Dialog { $("#carac").val(rollData.competence.data.defaut_carac); } // Si sort, for les points de reve à 1 - if (!rollData.selectedSort.data.ptreve_reel) + if (rollData.selectedSort && !rollData.selectedSort.data.ptreve_reel) rollData.selectedSort.data.ptreve_reel = 1; $("#bonusmalus").val(rollData.bmValue); updateRollResult(rollData); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index a3c96125..972a737d 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -539,7 +539,6 @@ export class RdDUtility { html.on("click", '#parer-button', event => { event.preventDefault(); - //let attackerActor = game.actors.get(event.currentTarget.attributes['data-attackerid'].value ); let defenderActor = game.actors.get(event.currentTarget.attributes['data-defenderid'].value ); let armeId = event.currentTarget.attributes['data-armeid'].value; let rollData = defenderActor.currentRollData; @@ -548,13 +547,21 @@ export class RdDUtility { html.on("click", '#esquiver-button', event => { event.preventDefault(); - //let attackerActor = game.actors.get(event.currentTarget.attributes['data-attackerid'].value ); let defenderActor = game.actors.get(event.currentTarget.attributes['data-defenderid'].value ); let rollData = defenderActor.currentRollData; console.log("Esquive !", rollData, defenderActor); defenderActor.esquiverAttaque( rollData ); }); - + + html.on("click", '#particuliere-attaque', event => { + event.preventDefault(); + let attackerActor = game.actors.get(event.currentTarget.attributes['data-attackerid'].value ); + let rollData = attackerActor.currentRollData; + rollData.particuliereAttaque = game.actors.get(event.currentTarget.attributes['data-mode'].value ); + console.log("Particulère !", rollData); + attackerActor.continueRoll( rollData ); + }); + } /* -------------------------------------------- */ diff --git a/system.json b/system.json index 14896a5c..0c10cbfa 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "0.9.40", + "version": "0.9.41", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.6", "templateVersion": 44,