From a63ec1936272ef93c03e8f152b7f11d19ecad6d3 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Wed, 30 Nov 2022 12:22:40 +0100 Subject: [PATCH] Better use of tokens/actors --- modules/mournblade-actor.js | 2 +- modules/mournblade-roll-dialog.js | 2 +- modules/mournblade-utility.js | 40 ++++++++++++++++++------------- system.json | 4 ++-- template.json | 3 +-- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/modules/mournblade-actor.js b/modules/mournblade-actor.js index 8bd6a06..de43528 100644 --- a/modules/mournblade-actor.js +++ b/modules/mournblade-actor.js @@ -407,6 +407,7 @@ export class MournbladeActor extends Actor { rollData.alias = this.name rollData.actorImg = this.img rollData.actorId = this.id + rollData.tokenId = this.token?.id rollData.img = this.img rollData.canEclatDoubleD20 = this.canEclatDoubleD20() rollData.doubleD20 = false @@ -433,7 +434,6 @@ export class MournbladeActor extends Actor { /* -------------------------------------------- */ async rollAttribut(attrKey) { let rollData = this.getCommonRollData(attrKey) - console.log("RollDatra", rollData) let rollDialog = await MournbladeRollDialog.create(this, rollData) rollDialog.render(true) } diff --git a/modules/mournblade-roll-dialog.js b/modules/mournblade-roll-dialog.js index 47c3768..50790dc 100644 --- a/modules/mournblade-roll-dialog.js +++ b/modules/mournblade-roll-dialog.js @@ -5,7 +5,7 @@ export class MournbladeRollDialog extends Dialog { /* -------------------------------------------- */ static async create(actor, rollData ) { - let options = { classes: ["MournbladeDialog"], width: 340, height: 420, 'z-index': 99999 }; + let options = { classes: ["MournbladeDialog"], width: 340, height: 'fit-content', 'z-index': 99999 }; let html = await renderTemplate('systems/fvtt-mournblade/templates/roll-dialog-generic.html', rollData); return new MournbladeRollDialog(actor, rollData, html, options ); diff --git a/modules/mournblade-utility.js b/modules/mournblade-utility.js index 665dff0..5480e32 100644 --- a/modules/mournblade-utility.js +++ b/modules/mournblade-utility.js @@ -46,6 +46,17 @@ export class MournbladeUtility { }) } + /* -------------------------------------------- */ + static getActorFromRollData(rollData) { + let actor = game.actors.get(rollData.actorId) + if (rollData.tokenId) { + let token = canvas.tokens.placeables.find(t => t.id == rollData.tokenId) + if (token) { + actor = token.actor + } + } + return actor + } /* -------------------------------------------- */ static getModificateurOptions() { @@ -108,7 +119,7 @@ export class MournbladeUtility { let messageId = MournbladeUtility.findChatMessageId(event.currentTarget) let message = game.messages.get(messageId) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) await actor.setPredilectionUsed(rollData.competence._id, predIdx) rollData.competence = duplicate(actor.getCompetence(rollData.competence._id)) MournbladeUtility.rollMournblade(rollData) @@ -183,11 +194,6 @@ export class MournbladeUtility { return undefined; } - /* -------------------------------------------- */ - static getDefenseState(actorId) { - return this.defenderStore[actorId]; - } - /* -------------------------------------------- */ static updateRollData(rollData) { @@ -292,7 +298,7 @@ export class MournbladeUtility { /* -------------------------------------------- */ static async rollMournblade(rollData) { - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) if (rollData.attrKey == "tochoose") { // No attr selected, force address rollData.attrKey = "adr" } @@ -473,7 +479,7 @@ export class MournbladeUtility { rollData.defenderTokenId = target.id let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor rollData.armeDefense = defender.getBestDefenseValue() - if ( rollData.armeDefense) { + if (rollData.armeDefense) { rollData.difficulte = rollData.armeDefense.system.totalDefensif } else { ui.notifications.warn("Aucune arme de défense équipée, difficulté manuelle à positionner.") @@ -492,7 +498,7 @@ export class MournbladeUtility { let msg = game.messages.get(msgId) if (msg) { let rollData = msg.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) actor.changeBonneAventure(changed) rollData.isReroll = true rollData.textBonus = "Bonus de Points d'Aventure" @@ -511,7 +517,7 @@ export class MournbladeUtility { let msg = game.messages.get(msgId) if (msg) { let rollData = msg.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) actor.changeEclat(changed) rollData.isReroll = true rollData.textBonus = "Bonus d'Eclat" @@ -526,37 +532,37 @@ export class MournbladeUtility { let canApplyBALoyal = function (li) { let message = game.messages.get(li.attr("data-message-id")) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) return (!rollData.isReroll && actor.getBonneAventure() > 0 && actor.getAlignement() == "loyal") } let canApplyPELoyal = function (li) { let message = game.messages.get(li.attr("data-message-id")) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) return (!rollData.isReroll && actor.getEclat() > 0 && actor.getAlignement() == "loyal") } let canApplyBAChaotique = function (li) { let message = game.messages.get(li.attr("data-message-id")) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) return (!rollData.isReroll && actor.getBonneAventure() > 0 && actor.getAlignement() == "chaotique") } let canApplyBAChaotique3 = function (li) { let message = game.messages.get(li.attr("data-message-id")) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) return (!rollData.isReroll && actor.getBonneAventure() > 2 && actor.getAlignement() == "chaotique") } let canApplyPEChaotique = function (li) { let message = game.messages.get(li.attr("data-message-id")) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) return (!rollData.isReroll && actor.getEclat() > 0 && actor.getAlignement() == "chaotique") } let hasPredilection = function (li) { let message = game.messages.get(li.attr("data-message-id")) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) if (rollData.competence) { let nbPred = rollData.competence.data.predilections.filter(pred => !pred.used).length return (!rollData.isReroll && rollData.competence && nbPred > 0) @@ -566,7 +572,7 @@ export class MournbladeUtility { let canCompetenceDouble = function (li) { let message = game.messages.get(li.attr("data-message-id")) let rollData = message.getFlag("world", "mournblade-roll") - let actor = game.actors.get(rollData.actorId) + let actor = MournbladeUtility.getActorFromRollData(rollData) if (rollData.competence) { return rollData.competence.data.doublebonus } diff --git a/system.json b/system.json index 86e23a1..40678e9 100644 --- a/system.json +++ b/system.json @@ -1,7 +1,7 @@ { "id": "fvtt-mournblade", "description": "Mournblade RPG for FoundryVTT", - "version": "10.0.11", + "version": "10.0.12", "authors": [ { "name": "Uberwald/LeRatierBretonnien", @@ -15,7 +15,7 @@ "gridUnits": "m", "license": "LICENSE.txt", "manifest": "https://www.uberwald.me/gitea/public/fvtt-mournblade/raw/branch/v10/system.json", - "download": "https://www.uberwald.me/gitea/public/fvtt-mournblade/archive/fvtt-mournblade-10.0.11.zip", + "download": "https://www.uberwald.me/gitea/public/fvtt-mournblade/archive/fvtt-mournblade-10.0.12.zip", "packs": [ { "type": "Item", diff --git a/template.json b/template.json index 947ed7a..53fe431 100644 --- a/template.json +++ b/template.json @@ -1,8 +1,7 @@ { "Actor": { "types": [ - "personnage", - "pnj" + "personnage" ], "templates": { "biodata": {