Better use of tokens/actors

This commit is contained in:
sladecraven 2022-11-30 12:22:40 +01:00
parent a26af23c9c
commit a63ec19362
5 changed files with 28 additions and 23 deletions

View File

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

View File

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

View File

@ -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
}

View File

@ -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",

View File

@ -1,8 +1,7 @@
{
"Actor": {
"types": [
"personnage",
"pnj"
"personnage"
],
"templates": {
"biodata": {