added prepared statut and it's sync

This commit is contained in:
Vlyan
2021-08-19 10:31:42 +02:00
parent a8b2460b21
commit 80319cfb65
12 changed files with 74 additions and 36 deletions

View File

@@ -99,12 +99,7 @@ export class ActorL5r5e extends Actor {
return Actor.updateDocuments([data], context).then(() => {
// Notify the "Gm Monitor" if this actor is watched
if (game.settings.get("l5r5e", "gm-monitor-actors").find((e) => e === this.id)) {
game.l5r5e.sockets.refreshAppId("l5r5e-gm-monitor");
if (game.user.isGM) {
Object.values(ui.windows)
.find((e) => e.id === "l5r5e-gm-monitor")
?.refresh();
}
game.l5r5e.HelpersL5r5e.refreshLocalAndSocket("l5r5e-gm-monitor");
}
});
}
@@ -216,7 +211,7 @@ export class ActorL5r5e extends Actor {
* Return true if a weapon is equipped
* @return {boolean}
*/
haveWeaponEquipped() {
get haveWeaponEquipped() {
return this.items.some((e) => e.type === "weapon" && !!e.data.data.equipped);
}
@@ -224,7 +219,7 @@ export class ActorL5r5e extends Actor {
* Return true if a weapon is readied
* @return {boolean}
*/
haveWeaponReadied() {
get haveWeaponReadied() {
return this.items.some((e) => e.type === "weapon" && !!e.data.data.equipped && !!e.data.data.readied);
}
@@ -232,7 +227,27 @@ export class ActorL5r5e extends Actor {
* Return true if a armor is equipped
* @return {boolean}
*/
haveArmorEquipped() {
get haveArmorEquipped() {
return this.items.some((e) => e.type === "armor" && !!e.data.data.equipped);
}
/**
* Return true if this actor is prepared (overridden by global)
* @return {boolean}
*/
get isPrepared() {
const cfg = {
character: game.settings.get("l5r5e", "initiative-prepared-character"),
adversary: game.settings.get("l5r5e", "initiative-prepared-adversary"),
minion: game.settings.get("l5r5e", "initiative-prepared-minion"),
};
// Prepared is a boolean or if null we get the info in the actor
let isPrepared = this.data.type === "character" ? cfg.character : cfg[this.data.data.type];
if (isPrepared === "null") {
isPrepared = this.data.data.prepared ? "true" : "false";
}
return isPrepared;
}
}

View File

@@ -26,11 +26,6 @@ export class CombatL5r5e extends Combat {
const cfg = {
difficulty: game.settings.get("l5r5e", "initiative-difficulty-value"),
difficultyHidden: game.settings.get("l5r5e", "initiative-difficulty-hidden"),
prepared: {
character: game.settings.get("l5r5e", "initiative-prepared-character"),
adversary: game.settings.get("l5r5e", "initiative-prepared-adversary"),
minion: game.settings.get("l5r5e", "initiative-prepared-minion"),
},
};
// SkillId from DicePicker or global
@@ -54,10 +49,7 @@ export class CombatL5r5e extends Combat {
// Prepared is a boolean or if null we get the info in the actor sheet
const isPc = combatant.actor.data.type === "character";
let isPrepared = isPc ? cfg.prepared.character : cfg.prepared[data.type];
if (isPrepared === "null") {
isPrepared = data.prepared ? "true" : "false";
}
const isPrepared = combatant.isPrepared;
// A characters initiative value is based on their state of preparedness when the conflict began.
// If the character was ready for the conflict, their base initiative value is their focus attribute.

View File

@@ -20,7 +20,7 @@ export class GmMonitor extends FormApplication {
classes: ["l5r5e", "gm-monitor"],
template: CONFIG.l5r5e.paths.templates + "gm/gm-monitor.html",
title: game.i18n.localize("l5r5e.gm_monitor.title"),
width: 700,
width: 800,
height: 300,
resizable: true,
closeOnSubmit: false,
@@ -175,8 +175,7 @@ export class GmMonitor extends FormApplication {
this.object.actors.push(actor[0]);
await this._saveActorsIds();
return this.refresh();
return this._saveActorsIds();
}
/**
@@ -227,8 +226,7 @@ export class GmMonitor extends FormApplication {
this.object.actors = this.object.actors.filter((e) => e.id !== id);
await this._saveActorsIds();
return this.refresh();
return this._saveActorsIds();
}
/**

View File

@@ -353,6 +353,17 @@ export class HelpersL5r5e {
});
}
/**
* Send a refresh to socket, and on local windows app
* @param {String} appId Application name
*/
static refreshLocalAndSocket(appId) {
game.l5r5e.sockets.refreshAppId(appId);
Object.values(ui.windows)
.find((e) => e.id === appId)
?.refresh();
}
/**
* Compute the Xp cost for cursus and total
* @param {ItemL5r5e|ItemL5r5e[]} itemsList Item Data

View File

@@ -85,6 +85,7 @@ export const RegisterSettings = function () {
config: false,
type: String,
default: "null",
onChange: () => game.l5r5e.HelpersL5r5e.refreshLocalAndSocket("l5r5e-gm-monitor"),
});
game.settings.register("l5r5e", "initiative-prepared-adversary", {
name: "Initiative NPC adversary are prepared or not",
@@ -92,6 +93,7 @@ export const RegisterSettings = function () {
config: false,
type: String,
default: "null",
onChange: () => game.l5r5e.HelpersL5r5e.refreshLocalAndSocket("l5r5e-gm-monitor"),
});
game.settings.register("l5r5e", "initiative-prepared-minion", {
name: "Initiative NPC minion are prepared or not",
@@ -99,6 +101,7 @@ export const RegisterSettings = function () {
config: false,
type: String,
default: "null",
onChange: () => game.l5r5e.HelpersL5r5e.refreshLocalAndSocket("l5r5e-gm-monitor"),
});
/* ------------------------------------ */
@@ -106,10 +109,10 @@ export const RegisterSettings = function () {
/* ------------------------------------ */
game.settings.register("l5r5e", "gm-monitor-actors", {
name: "Gm Monitor",
scope: "world", // for sync between gm
scope: "world",
config: false,
type: Array,
default: [],
onChange: () => game.l5r5e.sockets.refreshAppId("l5r5e-gm-monitor"),
onChange: () => game.l5r5e.HelpersL5r5e.refreshLocalAndSocket("l5r5e-gm-monitor"),
});
};