Gestion des points d'XP en voie

This commit is contained in:
sladecraven 2020-12-05 00:04:40 +01:00
parent 92d186a4a1
commit 45690c6e7e
4 changed files with 75 additions and 15 deletions

View File

@ -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);
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) });
});
/* -------------------------------------------- */

View File

@ -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()

51
module/rdd-token-hud.js Normal file
View File

@ -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 = '<div class="tokenhudext right">';
html.find('.control-icon.combat').wrap(divTokenHudExt);
let armesList = RdDUtility.buildArmeList( combatant );
let htmlList = "";
for (let arme of armesList) {
htmlList += '<div class="control-icon tokenhudicon right" title="'+ arme.name +'">';
htmlList += '<label class="hud-text-small" data-combatant-id="'+combatant._id+'" data-arme-id="'+arme._id+'"></i>'+arme.name+'</label>';
}
let hudInitiative = $(htmlList);
//let hudInitiative = $('<div class="control-icon tokenhudicon right" title="' + TooltipInitiative + '"><i class="fas fa-spinner"></i> ' + Dague + '</div>');
//let hudInitiative = $('<div class="control-icon tokenhudicon right" title="Dague"><i class="fas fa-spinner"></i>Dague</div>');
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 );
});
}
}
}

View File

@ -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 = [];