Fix token HUD

Utilisation de Misc.data pour:
- combattants
- armes
- competences d'armes
This commit is contained in:
Vincent Vandemeulebrouck 2021-03-31 01:15:55 +02:00
parent e0eb04d829
commit 036456e5df
4 changed files with 18 additions and 27 deletions

View File

@ -2542,8 +2542,8 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async equiperObjet(itemID) {
let item = this.getEmbeddedDocument('Item', itemID);
if (item?.data?.data) {
let itemData = Misc.itemData(item);
let itemData = Misc.data(item);
if (itemData?.data) {
const isEquipe = !itemData.data.equipe;
let update = { _id: item._id, "data.equipe": isEquipe };
await this.updateEmbeddedDocuments('Item', [update]);

View File

@ -97,19 +97,8 @@ export class Misc {
return [...new Set(array)];
}
static actorData(actor) {
return Misc.data(actor);
}
static itemData(item) {
return Misc.data(item);
}
static data(it) {
if (it instanceof Item) {
return it.data;
}
if (it instanceof Actor) {
if (it instanceof Actor || it instanceof Item || it instanceof Combatant) {
return it.data;
}
return it;

View File

@ -143,18 +143,20 @@ export class RdDCombatManager extends Combat {
// Gestion des armes 1/2 mains
let armesEquipe = [];
for (const arme of armes) {
if (arme.data.equipe) {
armesEquipe.push(arme);
let comp = competences.find(c => c.name == arme.data.competence);
arme.data.initiative = RdDCombatManager.calculInitiative(arme.data.niveau, carac[comp.data.defaut_carac].value);
let armeData = Misc.data(arme);
if (armeData.data.equipe) {
let compData = competences.map(c => Misc.data(c)).find(c => c.name == armeData.data.competence);
armesEquipe.push(armeData);
armeData.data.initiative = RdDCombatManager.calculInitiative(armeData.data.niveau, carac[compData.data.defaut_carac].value);
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
if (arme.data.unemain && !arme.data.deuxmains) {
arme.data.mainInfo = "(1m)";
} else if (!arme.data.unemain && arme.data.deuxmains) {
arme.data.mainInfo = "(2m)";
} else if (arme.data.unemain && arme.data.deuxmains) {
arme.data.mainInfo = "(1m)";
let arme2main = duplicate(arme);
if (armeData.data.unemain && !armeData.data.deuxmains) {
armeData.data.mainInfo = "(1m)";
} else if (!armeData.data.unemain && armeData.data.deuxmains) {
armeData.data.mainInfo = "(2m)";
} else if (armeData.data.unemain && armeData.data.deuxmains) {
armeData.data.mainInfo = "(1m)";
let arme2main = duplicate(armeData);
arme2main.data.mainInfo = "(2m)";
arme2main.data.dommages = arme2main.data.dommages.split("/")[1]; // Existence temporaire uniquement dans la liste des armes, donc OK
arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace !
@ -182,7 +184,6 @@ export class RdDCombatManager extends Combat {
} else {
// Recupération des items 'arme'
let armes = items.filter(it => RdDItemArme.isArmeUtilisable(it))
.map(arme => duplicate(arme)) /* pas de changements aux armes d'origine */
.concat(RdDItemArme.mainsNues());
let competences = items.filter(it => it.type == 'competence');

View File

@ -1,5 +1,6 @@
/* -------------------------------------------- */
import { HtmlUtility } from "./html-utility.js";
import { Misc } from "./misc.js";
import { RdDCombatManager } from "./rdd-combat.js";
import { RdDUtility } from "./rdd-utility.js";
@ -24,7 +25,7 @@ export class RdDTokenHud {
let token = canvas.tokens.get(tokenId);
let actor = token.actor;
let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id);
let combatant = game.combat.combatants.find(c => Misc.data(c).tokenId == tokenId);
app.hasExtension = true;
let armesList = RdDCombatManager.buildListeActionsCombat(combatant) ;