From 798b0fdf0383dffa52caaf39c2b5fffeeac3272d Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sun, 31 Jul 2022 17:53:07 +0200 Subject: [PATCH] Fixed Initiative DP for all cases --- CHANGELOG.md | 2 +- system/scripts/combat.js | 55 +++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb45ac5..f7286e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Date format : day/month/year ## 1.9.0 - ??/??/2022 - Foundry v10 Compatibility __! Be certain to carefully back up any critical user data before installing this update !__ - Updated the System to FoundryVTT v10. -- Updated the initiative behaviour, he now open the DicePicker for connected players. +- Updated the initiative behaviour, he now open the DicePicker for PC and Adversaries locally or remotely. - Added a `game.user.isFirstGM` property for some traitements (socket and migration) to prevent multiple executions with multiple GM connected. - Added socket API `openDicePicker` to remotely open the DicePicker (see usage below). - Added chat distinction for roll using target (`@T:`) with `min` or `max` for non disclose the target to players. diff --git a/system/scripts/combat.js b/system/scripts/combat.js index 7200a39..5dfab6d 100644 --- a/system/scripts/combat.js +++ b/system/scripts/combat.js @@ -52,37 +52,10 @@ export class CombatL5r5e extends Combat { continue; } - // Shortcut to system - const actorSystem = combatant.actor.system; - - // DicePicker management - // formula is empty on the fist call (combat tab buttons) - // only select if a player is active for this actor - if ( - !formula && - !combatant.initiative && - combatant.hasPlayerOwner && - combatant.players.some((u) => u.active && !u.isGM) - ) { - if (game.user.isGM) { - // Open the DP on player side - networkActors.push(combatant.actor); - } else { - // Open the DP locally - new game.l5r5e.DicePickerDialog({ - actor: combatant.actor, - skillId: skillId, - difficulty: cfg.difficulty, - difficultyHidden: cfg.difficultyHidden, - isInitiativeRoll: true, - }).render(true); - } - continue; - } - // Prepared is a boolean or if null we get the info in the actor sheet const isPc = combatant.actor.type === "character"; const isPrepared = combatant.actor.isPrepared; + const actorSystem = combatant.actor.system; // A character’s initiative value is based on their state of preparedness when the conflict began. // If the character was ready for the conflict, their base initiative value is their focus attribute. @@ -93,6 +66,30 @@ export class CombatL5r5e extends Combat { // Roll only for PC and Adversary if (isPc || actorSystem.type === "adversary") { + // DicePicker management + // formula is empty on the fist call (combat tab buttons) + if (!formula && !combatant.initiative) { + // if a player is currently active for this actor + const havePlayer = combatant.players.some((u) => u.active); + const isMyCharacter = combatant.players.some((u) => u._id === game.user.id); + + if (game.user.isGM && havePlayer && !isMyCharacter) { + // Open the DP on player side + networkActors.push(combatant.actor); + continue; + } else if (isMyCharacter || (game.user.isGM && !havePlayer)) { + // Open the DP locally + new game.l5r5e.DicePickerDialog({ + actor: combatant.actor, + skillId: skillId, + difficulty: cfg.difficulty, + difficultyHidden: cfg.difficultyHidden, + isInitiativeRoll: true, + }).render(true); + continue; + } + } + // Roll formula const createFormula = []; if (!formula) { @@ -137,7 +134,7 @@ export class CombatL5r5e extends Combat { rnkMessage = await roll.toMessage({ flavor }); } - // Ugly but work... i need the new message + // Ugly but work... I need the new message if (ids.length === 1) { messageOptions.rnkMessage = rnkMessage; }