Executions une seule fois

Fix sur les actions à faire une seule fois en cas de plusieurs GM

Quand plusieurs GM ou assistant GM sont connectés, ils exécutaient
tous certaines actions.

Conséquence: ajout de casetmr en doublon, détermination de 2 chiffres
astraux, modification d'initiative de premier tour en double
This commit is contained in:
Vincent Vandemeulebrouck 2021-11-26 00:45:21 +01:00
parent a1972073d5
commit 4f91fab3d5
7 changed files with 40 additions and 30 deletions

View File

@ -63,7 +63,7 @@ export class RdDActor extends Actor {
}
static remoteActorCall(data) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueConnectedGM()) {
RdDActor.onRemoteActorCall(data);
}
else {
@ -72,7 +72,7 @@ export class RdDActor extends Actor {
}
static onRemoteActorCall(data) {
if (Misc.isElectedUser()) { // Seul le joueur choisi effectue l'appel
if (Misc.isUniqueConnectedGM()) { // Seul le joueur choisi effectue l'appel
const actor = game.actors.get(data?.actorId);
if (!actor) {
console.info("RdDActor.onRemoteActorCall: Pas d'Actor disponible ", data);
@ -3685,7 +3685,7 @@ export class RdDActor extends Actor {
ui.notifications.info("Inutile de se vendre à soi-même");
return;
}
if (!Misc.isElectedUser()) {
if (!Misc.isUniqueConnectedGM()) {
RdDActor.remoteActorCall({actorId: achat.vendeurId ?? achat.acheteurId, method: 'achatVente', args: [achat]});
return;
}
@ -4172,7 +4172,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async onCreateOwnedDraconique(item, options, id) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueConnectedGM()) {
let draconique = Draconique.all().find(it => it.match(item));
if (draconique) {
draconique.onActorCreateOwned(this, item)
@ -4183,7 +4183,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async onDeleteOwnedDraconique(item, options, id) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueConnectedGM()) {
let draconique = Draconique.all().find(it => it.match(item));
if (draconique) {
draconique.onActorDeleteOwned(this, item)
@ -4193,7 +4193,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async onDeleteOwnedCaseTmr(item, options, id) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueConnectedGM()) {
let draconique = Draconique.all().find(it => it.isCase(item));
if (draconique) {
draconique.onActorDeleteCaseTmr(this, Misc.data(item))

View File

@ -41,7 +41,7 @@ export class ChatUtility {
/* -------------------------------------------- */
static onRemoveMessages(data) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueConnectedGM()) {
if (data.part) {
const toDelete = game.messages.filter(it => it.data.content.includes(data.part));
toDelete.forEach(it => it.delete());
@ -53,7 +53,7 @@ export class ChatUtility {
}
static onRemoveMessages(data) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueConnectedGM()) {
if (data.part) {
const toDelete = game.messages.filter(it => it.data.content.includes(data.part));
toDelete.forEach(it => it.delete());
@ -66,7 +66,7 @@ export class ChatUtility {
/* -------------------------------------------- */
static removeMessages(data) {
if (Misc.isElectedUser()){
if (Misc.isUniqueConnectedGM()){
ChatUtility.onRemoveMessages(data);
}
else {

View File

@ -126,10 +126,22 @@ export class Misc {
if (ownerId && game.user.id == ownerId) {
return ownerId;
}
return (game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id) ?? game.user.id;
return Misc.firstConnectedGM()?.id ?? game.user.id;
}
static isElectedUser() {
return game.user.id == Misc.connectedGMOrUser();
static getActiveUser(id){
return game.users.entities.find(u => u.id == id && u.active);
}
static firstConnectedGM() {
return game.users.entities.sort(Misc.ascending(u => u.id)).find(u => u.isGM && u.active);
}
/**
* @returns true pour un seul utilisateur: le premier GM connecté par ordre d'id
*/
static isUniqueConnectedGM() {
return game.user.id == Misc.firstConnectedGM()?.id;
}
/* -------------------------------------------- */

View File

@ -68,9 +68,10 @@ export class RdDAstrologieJoueur extends Dialog {
etat: this.dataNombreAstral.etat,
astrologie: this.dataNombreAstral.astrologie,
conditions: $("#diffConditions").val(),
date: $("#joursAstrologie").val()
date: $("#joursAstrologie").val(),
userId: game.user.id
}
if (game.user.isGM) {
if (Misc.isUniqueConnectedGM()) {
game.system.rdd.calendrier.requestNombreAstral(data);
} else {
game.socket.emit("system.foundryvtt-reve-de-dragon", {
@ -83,7 +84,6 @@ export class RdDAstrologieJoueur extends Dialog {
/* -------------------------------------------- */
quitDialog() {
}
/* -------------------------------------------- */

View File

@ -82,12 +82,9 @@ export class RdDCalendrier extends Application {
this.calendrier.annee = this.calendrier.annee ?? Math.floor((this.calendrier.moisRdD ?? 0) / RDD_MOIS_PAR_AN);
this.calendrier.moisRdD = (this.calendrier.moisRdD ?? 0) % RDD_MOIS_PAR_AN;
if (game.user.isGM) { // Uniquement si GM
if (Misc.isUniqueConnectedGM()) { // Uniquement si GM
game.settings.set(SYSTEM_RDD, "calendrier", this.calendrier);
}
// nombre astral
if (game.user.isGM) {
this.listeNombreAstral = this.getListeNombreAstral();
this.rebuildListeNombreAstral(false); // Ensure always up-to-date
}
@ -189,7 +186,7 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
async rebuildListeNombreAstral(showDice = true) {
if (game.user.isGM) {
if (Misc.isUniqueConnectedGM()) {
console.log("rebuildListeNombreAstral", showDice);
let jourCourant = this.getCurrentDayIndex();
let newList = [];
@ -320,7 +317,7 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
async requestNombreAstral(request) {
if (game.user.isGM) { // Only GM
if (Misc.isUniqueConnectedGM()) { // Only once
console.log(request);
let jourDiff = this.getLectureAstrologieDifficulte(request.date);
let niveau = Number(request.astrologie.data.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat);
@ -343,7 +340,7 @@ export class RdDCalendrier extends Application {
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
}
request.nbAstral = nbAstral;
if (game.user.isGM) {
if (Misc.getActiveUser(request.userId)?.isGM) {
RdDUtility.responseNombreAstral(request);
} else {
game.socket.emit("system.foundryvtt-reve-de-dragon", {

View File

@ -227,7 +227,7 @@ export class RdDCombatManager extends Combat {
/* -------------------------------------------- */
static processPremierRoundInit() {
// Check if we have the whole init !
if (game.user.isGM && game.combat.current.round == 1) {
if (Misc.isUniqueConnectedGM() && game.combat.current.round == 1) {
let initMissing = game.combat.data.combatants.find(it => !it.initiative);
if (!initMissing) { // Premier round !
for (let combatant of game.combat.data.combatants) {
@ -422,7 +422,7 @@ export class RdDCombat {
/* -------------------------------------------- */
static combatNouveauTour(combat) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueSingleUser()) {
let turn = combat.turns.find(t => t.token?.id == combat.current.tokenId);
if (turn?.actor) {
RdDCombat.displayActorCombatStatus(combat, turn.actor);
@ -540,7 +540,7 @@ export class RdDCombat {
/* -------------------------------------------- */
static onMsgEncaisser(data) {
if (Misc.isElectedUser()) {
if (Misc.isUniqueSingleUser()) {
let attackerRoll = RdDCombat._getAttaque(data.attackerId); // Retrieve the rolldata from the store
let attacker = data.attackerId ? game.actors.get(data.attackerId) : null;
let defender = canvas.tokens.get(data.defenderTokenId).actor;
@ -555,7 +555,7 @@ export class RdDCombat {
/* -------------------------------------------- */
static onMsgDefense(msg) {
let defenderToken = canvas.tokens.get(msg.defenderTokenId);
if (defenderToken && Misc.isElectedUser()) {
if (defenderToken && Misc.isUniqueSingleUser()) {
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
if (rddCombat) {
const defenderRoll = msg.defenderRoll;
@ -913,7 +913,7 @@ export class RdDCombat {
dmg: attackerRoll.dmg,
};
if (!Misc.isElectedUser()) {
if (!Misc.isUniqueSingleUser()) {
this._socketSendMessageDefense(paramChatDefense, defenderRoll);
}
else {
@ -1286,7 +1286,7 @@ export class RdDCombat {
this._onEchecTotal(defenderRoll);
}
if (Misc.isElectedUser()) {
if (Misc.isUniqueSingleUser()) {
attackerRoll.attackerId = this.attackerId;
attackerRoll.defenderTokenId = defenderTokenId;

View File

@ -34,6 +34,7 @@ import { RdDItem } from "./item.js";
import { RdDDice } from "./rdd-dice.js";
import { RdDPossession } from "./rdd-possession.js";
import { RdDSigneDraconiqueItemSheet } from "./item-signedraconique-sheet.js";
import { Misc } from "./misc.js";
/* -------------------------------------------- */
/* Foundry VTT Initialization */
@ -254,7 +255,7 @@ Hooks.once("ready", async function () {
user: game.user.id
});
}
if (game.user.isGM) {
if (Misc.isUniqueConnectedGM()) {
messageDeBienvenue();
}
});