From 268ac0a25a151cf379609f49590de610a906f015 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Mon, 1 May 2023 18:50:32 +0200 Subject: [PATCH] Review initiative --- lang/de.json | 1 + lang/en.json | 1 + lang/fr.json | 1 + module/actor/actor.js | 18 ++++++++++++------ module/controllers/bol-rolls.js | 6 ++++-- module/system/bol-combat.js | 13 ++++++++----- system.json | 4 ++-- templates/dialogs/aptitude-roll-dialog.hbs | 9 +++++++-- 8 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lang/de.json b/lang/de.json index 344e2ec..56ad020 100644 --- a/lang/de.json +++ b/lang/de.json @@ -156,6 +156,7 @@ "BOL.ui.armorAgiMalus": "Rüschtung+Schild-Malus (Geschick)", "BOL.ui.armorInitMalus": "Rüstungsmalus (Init)", "BOL.ui.attackValue": "Angriffswert", + "BOL.ui.initMalus": "Init malus", "BOL.featureCategory.origins": "Herkünfte", "BOL.featureCategory.races": "Rassen", diff --git a/lang/en.json b/lang/en.json index 46b6453..308aa80 100644 --- a/lang/en.json +++ b/lang/en.json @@ -154,6 +154,7 @@ "BOL.ui.armorInitMalus": "Armor Modifier (Init)", "BOL.ui.attackValue": "Attack Value", "BOL.ui.weaponbonus": "Cette arme bénéficie déja d'un Dé de Bonus (Arme Favorite prise en compte, par exemple)", + "BOL.ui.initMalus": "Init malus", "BOL.featureCategory.origins": "Origins", "BOL.featureCategory.races": "Races", diff --git a/lang/fr.json b/lang/fr.json index 4c0ea3e..0011832 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -132,6 +132,7 @@ "BOL.ui.concentrate": "Concentration à maintenir ?", "BOL.ui.aggressive": "Sort aggressif ?", "BOL.ui.registerInit": "Enregistrer comme Init. de combat", + "BOL.ui.initMalus": "Malus d'initiative", "BOL.ui.magicnewrules": "Règles supplémentaires (cf. supplément fan-made Sorcellerie!)", "BOL.ui.isSorcerer": "Carrière de Sorcier ?", diff --git a/module/actor/actor.js b/module/actor/actor.js index 1c23155..c976a33 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -48,7 +48,13 @@ export class BoLActor extends Actor { } return false } - + /* -------------------------------------------- */ + getInitiativeMalus() { + if ( this.type === 'encounter' && (this.chartype == "adversary" || this.chartype == "tough")) { + return this.system.aptitudes.init.value + } + return 0 + } /* -------------------------------------------- */ getBougette() { if (this.type == "character") { @@ -871,17 +877,17 @@ export class BoLActor extends Actor { /*-------------------------------------------- */ getInitiativeRank(rollData = undefined, isCombat = false, combatData) { - if (!rollData) { - rollData = this.getFlag("world", "last-initiative") - } let fvttInit = 4 // Pietaille par defaut if (this.type == 'character') { fvttInit = 5 - fvttInit = -1 if (!rollData) { if (isCombat) { if (game.user.isGM ) { - game.socket.emit("system.bol", { name: "msg_request_init_roll", data: { actorId: this.id, combatData : combatData } }) + if (this.hasPlayerOwner) { + game.socket.emit("system.bol", { name: "msg_request_init_roll", data: { actorId: this.id, combatData } }) + } else { + BoLRoll.aptitudeCheck(this, "init", undefined, combatData); + } } } } else { diff --git a/module/controllers/bol-rolls.js b/module/controllers/bol-rolls.js index 2aaa2fb..cf25d7e 100644 --- a/module/controllers/bol-rolls.js +++ b/module/controllers/bol-rolls.js @@ -584,7 +584,8 @@ export class BoLRoll { } let diceData = BoLUtility.getDiceData() - const modifiers = rollbase + rollData.careerBonus + rollData.mod + rollData.weaponModifier - rollData.defence - rollData.modArmorMalus + rollData.shieldMalus + rollData.attackModifier + rollData.appliedArmorMalus + rollData.effectModifier + let malusInit = rollData.combatData?.malusInit || 0 + const modifiers = rollbase + rollData.careerBonus + rollData.mod + rollData.weaponModifier - rollData.defence - rollData.modArmorMalus + rollData.shieldMalus + rollData.attackModifier + rollData.appliedArmorMalus + rollData.effectModifier - malusInit const formula = (isMalus) ? rollData.nbDice + "d" + diceData.diceFormula + "kl2 + " + modifiers : rollData.nbDice + "d" + diceData.diceFormula + "kh2 + " + modifiers rollData.formula = formula rollData.modifiers = modifiers @@ -647,10 +648,11 @@ export class BoLDefaultRoll { this.rollData.reroll = actor.heroReroll() } if (this.rollData.registerInit) { - actor.registerInit(this.rollData) + await actor.registerInit(this.rollData) this.rollData.initiativeRank = actor.getInitiativeRank(this.rollData) if (this.rollData.combatData) { // If combatData present let combat = game.combats.get(this.rollData.combatData.combatId) + console.log("SET INIT!!!!!", this.rollData.initiativeRank) combat.setInitiative(this.rollData.combatData.combatantId, this.rollData.initiativeRank) } } diff --git a/module/system/bol-combat.js b/module/system/bol-combat.js index 2e12f8e..fe37e33 100644 --- a/module/system/bol-combat.js +++ b/module/system/bol-combat.js @@ -20,12 +20,15 @@ export class BoLCombatManager extends Combat { console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions); // Structure input data ids = typeof ids === "string" ? [ids] : ids; - //const currentId = this.combatant.id; - + // Get initiative malus from tough/adversary + let malusInit = 0 + for (let combatant of this.combatants) { + malusInit = Math.max(malusInit, combatant.actor.getInitiativeMalus()) + } // calculate initiative - for (let cId = 0; cId < ids.length; cId++) { + for (let cId = 0; cId < ids.length; cId++) { const combatant = this.combatants.get(ids[cId]) - let fvttInit = combatant.actor.getInitiativeRank(false, true, { combatId: this.id, combatantId: combatant.id }) + let fvttInit = combatant.actor.getInitiativeRank(false, true, { combatId: this.id, combatantId: combatant.id, malusInit }) fvttInit += (cId / 100) await this.updateEmbeddedDocuments("Combatant", [{ _id: ids[cId], initiative: fvttInit }]); } @@ -64,7 +67,7 @@ export class BoLCombatManager extends Combat { return super.startCombat() } - /************************************************************************************/ + /*-***********************************************************************************/ _onDelete() { if (game.user.isGM) { let combatants = this.combatants.contents diff --git a/system.json b/system.json index f590a7f..a9b03c5 100644 --- a/system.json +++ b/system.json @@ -14,7 +14,7 @@ ], "url": "https://www.uberwald.me/gitea/public/bol", "license": "LICENSE.txt", - "version": "10.5.15", + "version": "10.5.16", "compatibility": { "minimum": "10", "verified": "10" @@ -202,7 +202,7 @@ ], "socket": true, "manifest": "https://www.uberwald.me/gitea/public/bol/raw/v10/system.json", - "download": "https://www.uberwald.me/gitea/public/bol/archive/bol-v10.5.15.zip", + "download": "https://www.uberwald.me/gitea/public/bol/archive/bol-v10.5.16.zip", "background": "systems/bol/ui/page_accueil.webp", "gridDistance": 1.5, "gridUnits": "m", diff --git a/templates/dialogs/aptitude-roll-dialog.hbs b/templates/dialogs/aptitude-roll-dialog.hbs index 345e857..0c129ff 100644 --- a/templates/dialogs/aptitude-roll-dialog.hbs +++ b/templates/dialogs/aptitude-roll-dialog.hbs @@ -22,8 +22,13 @@ - - + +
+
+ +
+
{{combatData.malusInit}}
+
{{/if}} {{> "systems/bol/templates/dialogs/career-roll-part.hbs"}}