From ae03fabd9e85b053fc38baba9b9530517edc9eb3 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Thu, 4 Feb 2021 16:35:22 +0100 Subject: [PATCH] #87 - Init du premier round --- module/rdd-combat.js | 1 + module/rdd-main.js | 2 + module/rdd-utility.js | 55 +++++++++++++++++++- system.json | 2 +- templates/chat-initiative-premier-round.html | 5 ++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 templates/chat-initiative-premier-round.html diff --git a/module/rdd-combat.js b/module/rdd-combat.js index e1808d6a..6e313123 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -9,6 +9,7 @@ import { RdDRoll } from "./rdd-roll.js"; import { RdDRollTables } from "./rdd-rolltables.js"; import { ReglesOptionelles } from "./regles-optionelles.js"; +/* -------------------------------------------- */ export class RdDCombat { static init() { diff --git a/module/rdd-main.js b/module/rdd-main.js index aa5c25b5..aab4d527 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -97,6 +97,8 @@ const _patch_initiative = () => { messageOptions ); roll.toMessage(messageData, { rollMode, create: true }); + + RdDUtility.processPremierRoundInit( ); } return this; }; diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 868ee8d4..aecf6742 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -63,6 +63,26 @@ const tableCaracDerivee = { 32: { xp: 180, poids: "1501-2000", plusdom:+11, sconst: 10, sust: 17 } } + /* -------------------------------------------- */ + const premierRoundInit = [ + { type: 'competence', pattern: 'hast', init: 3.90}, + { type: 'competence', pattern: 'lance', init: 3.85}, + { type: 'arme', pattern: 'bâton', init: 3.80}, + { type: 'arme', pattern: 'double dragonne', init: 3.75}, + { type: 'arme', pattern: 'esparlongue', init: 3.70}, + { type: 'arme', pattern: 'pée dragonne', init: 3.65}, + { type: 'arme', pattern: 'bâtarde', init: 3.60}, + { type: 'arme', pattern: 'cyane', init: 3.55}, + { type: 'arme', pattern: 'sorde', init: 3.50}, + { type: 'arme', pattern: 'grande hache', init: 3.45}, + { type: 'arme', pattern: 'bataille', init: 3.40}, + { type: 'arme', pattern: 'gnome', init: 3.35}, + { type: 'arme', pattern: 'masse', init: 3.30}, + { type: 'arme', pattern: 'gourdin', init: 3.25}, + { type: 'competence', pattern: 'fléau', init: 3.20}, + { type: 'arme', pattern: 'dague', init: 3.15}, + ]; + /* -------------------------------------------- */ function _buildAllSegmentsFatigue(max) { const cycle = [5, 2, 4, 1, 3, 0]; @@ -665,6 +685,37 @@ export class RdDUtility { } } + /* -------------------------------------------- */ + static processPremierRoundInit() { + // Check if we have the whole init ! + if ( game.user.isGM) { + let initDone = true; + for( let combatant of game.combat.data.combatants) { + if ( !combatant.initiative ) initDone = false; + } + if (initDone && game.combat.current.round == 1) { // Premier round ! + for( let combatant of game.combat.data.combatants) { + let arme = combatant.initiativeData.arme; + //console.log("Parsed !!!", combatant, initDone, game.combat.current, arme); + if ( arme && arme.type == "arme" ) { + for (let initData of premierRoundInit) { + if ( ( initData == 'competence' && arme.data.competence.toLowerCase().includes(initData.pattern)) || + (arme.name.toLowerCase().includes(initData.pattern)) ) { + let msg = `

L'initiative de ${combatant.actor.name} a été modifiée !

+
+
+ Etant donné son ${arme.name}, son initative pour ce premier round est désormais de ${initData.init}. +
` + ChatMessage.create( { content: msg } ); + game.combat.setInitiative(combatant._id, initData.init); + } + } + } + } + } + } + } + /* -------------------------------------------- */ static rollInitiativeCompetence(combatantId, arme) { const combatant = game.combat.getCombatant(combatantId); @@ -706,7 +757,9 @@ export class RdDUtility { } let malus = actor.getEtatGeneral(); // Prise en compte état général // Cas des créatures et entités vs personnages - let rollFormula = initOffset + "+ ( (" + RdDUtility.calculInitiative(compNiveau, caracForInit) + " + " + malus + ") /100)"; + let rollFormula = initOffset + "+ ( (" + RdDUtility.calculInitiative(compNiveau, caracForInit) + " + " + malus + ") /100)"; + // Garder la trace de l'arme/compétence utilisée pour l'iniative + combatant.initiativeData = { arme: arme } // pour reclasser l'init au round 0 game.combat.rollInitiative(combatantId, rollFormula); } diff --git a/system.json b/system.json index 43964d90..4627eaaa 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": "1.3.13", + "version": "1.3.14", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", diff --git a/templates/chat-initiative-premier-round.html b/templates/chat-initiative-premier-round.html new file mode 100644 index 00000000..291563f8 --- /dev/null +++ b/templates/chat-initiative-premier-round.html @@ -0,0 +1,5 @@ +

L'initiative de {{alias}} a été modifiée !

+
+
+ Etant donné son {{armeName}}, son initative pour ce premier round est désormais de {{initValue}}. +