From 45690c6e7e0d79a73e82449de05905e98ed7b034 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sat, 5 Dec 2020 00:04:40 +0100 Subject: [PATCH] Gestion des points d'XP en voie --- module/rdd-main.js | 19 +++++++------ module/rdd-resolution-table.js | 2 ++ module/rdd-token-hud.js | 51 ++++++++++++++++++++++++++++++++++ module/rdd-utility.js | 18 +++++++----- 4 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 module/rdd-token-hud.js diff --git a/module/rdd-main.js b/module/rdd-main.js index 4ac24479..394afcfa 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -18,6 +18,7 @@ import { RdDUtility } from "./rdd-utility.js"; import { TMRUtility } from "./tmr-utility.js"; import { RdDCalendrier } from "./rdd-calendrier.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; +import { RdDTokenHud } from "./rdd-token-hud.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -67,13 +68,12 @@ const _patch_initiative = () => { } //console.log("Combatat", c); const roll = this._getInitiativeRoll(c, rollFormula); - //console.log("Compute init for", armeCombat, competence, rollFormula, roll.total); - + if ( roll.total <= 0 ) roll.total = 1; + //console.log("Compute init for", armeCombat, competence, rollFormula, roll.total); await this.updateEmbeddedEntity("Combatant", { _id: c._id, initiative: roll.total }); // Send a chat message - let rollMode = - messageOptions.rollMode || game.settings.get("core", "rollMode"); + let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode"); let messageData = mergeObject( { speaker: { @@ -187,10 +187,6 @@ Hooks.once("init", async function() { _patch_initiative(); }); -Hooks.once("renderApplication", () => { - messageDeBienvenue(); -}); - /* -------------------------------------------- */ function messageDeBienvenue(){ game.messages @@ -204,6 +200,11 @@ function messageDeBienvenue(){ ); } +/* -------------------------------------------- */ +Hooks.once("renderApplication", () => { + messageDeBienvenue(); +}); + /* -------------------------------------------- */ /* Foundry VTT Initialization */ /* -------------------------------------------- */ @@ -223,6 +224,8 @@ Hooks.once("ready", function() { //whisper: [ ChatMessage.getWhisperRecipients("GM") ] } ); } + // Integration du TokenHUD + Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data) }); }); /* -------------------------------------------- */ diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 43a8fa59..9edf47d3 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -51,10 +51,12 @@ const reussites = [ { code: "error", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: true, ptTache: 0, ptQualite: 0, quality: "Jet de dés invalide", condition: (target, roll) => (roll <= 0 || roll > 100) } ]; +/* -------------------------------------------- */ const reussiteSignificative = reussites.find(r => r.code == "sign"); const reussiteNormale = reussites.find(r => r.code == "norm"); const echecNormal = reussites.find(r => r.code == "echec"); +/* -------------------------------------------- */ export class RdDResolutionTable { static resolutionTable = this.build() diff --git a/module/rdd-token-hud.js b/module/rdd-token-hud.js new file mode 100644 index 00000000..c1206948 --- /dev/null +++ b/module/rdd-token-hud.js @@ -0,0 +1,51 @@ +/* -------------------------------------------- */ +import { RdDUtility } from "./rdd-utility.js"; + +/* -------------------------------------------- */ +export class RdDTokenHud { + + /* -------------------------------------------- */ + static addTokenHudExtensions( app, html, data ) { + let token = canvas.tokens.get(data._id); + + // Affichage seulement si le token est un combat + if ( token.inCombat) { + this.addInitiativeTokenTip(html, token); + } + } + + /* -------------------------------------------- */ + static async addInitiativeTokenTip(html, token ) { + // Helper actor and sanity check + let actor = token.actor; + if (actor === undefined) return; + + // Get combatant stuff + let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id ); + if ( combatant ) { + console.log("Token !!!", combatant); + // Create space for Hud Extensions next to combat icon + let divTokenHudExt = '
'; + html.find('.control-icon.combat').wrap(divTokenHudExt); + + let armesList = RdDUtility.buildArmeList( combatant ); + let htmlList = ""; + for (let arme of armesList) { + htmlList += '
'; + htmlList += ''; + } + let hudInitiative = $(htmlList); + //let hudInitiative = $('
' + Dague + '
'); + //let hudInitiative = $('
Dague
'); + html.find('.control-icon.combat').after(hudInitiative); // Add Initiative and Agility token tip + // Add interactions for Initiative and Agility + hudInitiative.find('label').click(async (event) => { + let armeId = event.currentTarget.attributes['data-arme-id'].value; + let combatantId = event.currentTarget.attributes['data-combatant-id'].value; + let arme = actor.getOwnedItem(armeId); + console.log("CLICKED !", actor, armeId, arme); + RdDUtility.rollInitiativeCompetence( combatantId, arme.data ); + }); + } + } +} \ No newline at end of file diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 56627a73..dec89e86 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -766,16 +766,12 @@ export class RdDUtility { } /* -------------------------------------------- */ - static displayInitiativeMenu( html, combatantId) { - // Recupération du combatant et de l'acteur associé - const combatant = game.combat.getCombatant(combatantId); - const actor = combatant.actor; - //console.log("Combattant : ", combatant); - + static buildArmeList( combatant ) { + const actor = combatant.actor; // Easy access let armesList = []; if ( actor.data.type == 'creature' || actor.data.type == 'entite') { for (const competenceItem of actor.data.items) { - if ( competenceItem.data.iscombat) { // Siule un item de type arme + if ( competenceItem.data.iscombat) { // Seul un item de type arme armesList.push( { name: competenceItem.name, data: { niveau: competenceItem.data.niveau, competence: competenceItem.name } } ); } } @@ -789,6 +785,14 @@ export class RdDUtility { armesList.push( { name: "Draconic", data: { competence: "Draconic" } } ); } armesList.push( { name: "Autre action", data: { competence: "Autre action" } } ); + return armesList; + } + + /* -------------------------------------------- */ + static displayInitiativeMenu( html, combatantId) { + const combatant = game.combat.getCombatant(combatantId); + let armesList = this.buildArmeList( combatant ); + // Build the relevant submenu if ( armesList ) { let menuItems = [];