#193: utiliser isElectedUser pour les défenses

Misc.isElectedUser renvoit true pour un seul MJ connecté,
ou le joueur connecté s'il n'y a pas de MJ.

Ca veut dire que sans MJ, les messages de combat ne marcheront
peut-être pas, mais pour tous les autres cas, ça marchera correctement,
vu que ce sera toujours un MJ qui postera le message de défense au
joueur (connecté ou pas) et au MJ
This commit is contained in:
Vincent Vandemeulebrouck 2021-05-22 02:03:46 +02:00
parent 45b10f2c6b
commit 249850558b
2 changed files with 19 additions and 26 deletions

View File

@ -1,3 +1,4 @@
import { Misc } from "./misc";
/** /**
* Class providing helper methods to get the list of users, and * Class providing helper methods to get the list of users, and
@ -7,13 +8,13 @@ export class ChatUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onSocketMessage(sockmsg) { static onSocketMessage(sockmsg) {
switch (sockmsg.msg) { switch (sockmsg.msg) {
case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.part, sockmsg.gmId); case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.part);
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static onRemoveMessages(part, gmId) { static onRemoveMessages(part) {
if (game.user._id == gmId) { if (Misc.isElectedUser()) {
const toDelete = game.messages.filter(it => it.data.content.includes(part)); const toDelete = game.messages.filter(it => it.data.content.includes(part));
toDelete.forEach(it => it.delete()); toDelete.forEach(it => it.delete());
} }
@ -21,17 +22,13 @@ export class ChatUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static removeChatMessageContaining(part) { static removeChatMessageContaining(part) {
const gmId = game.user.isGM ? game.user._id : game.users.entities.find(u => u.isGM && u.active)?.id; if (Misc.isElectedUser()) {
ChatUtility.onRemoveMessages(part);
if (!gmId || game.user.isGM) {
ChatUtility.onRemoveMessages(part, game.user._id);
} }
else { else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_delete_chat_message", data: { msg: "msg_delete_chat_message", data: { part: part }
part:part, });
gmId: gmId,
}});
} }
} }

View File

@ -395,9 +395,8 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static combatNouveauTour(combat) { static combatNouveauTour(combat) {
if (Misc.isElectedUser()) {
let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId); let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId);
if (game.user.isGM) {
// seul le GM notifie le status
this.displayActorCombatStatus(combat, turn.actor); this.displayActorCombatStatus(combat, turn.actor);
// TODO Playaudio for player?? // TODO Playaudio for player??
} }
@ -482,18 +481,16 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onMsgEncaisser(data) { static onMsgEncaisser(data) {
if (Misc.isElectedUser()) {
let attackerRoll = RdDCombat._getAttaque(data.attackerId); // Retrieve the rolldata from the store let attackerRoll = RdDCombat._getAttaque(data.attackerId); // Retrieve the rolldata from the store
if (game.user.id === data.gmId) { // Seul le GM effectue l'encaissement sur la fiche
let attacker = data.attackerId ? game.actors.get(data.attackerId) : null; let attacker = data.attackerId ? game.actors.get(data.attackerId) : null;
let defender = canvas.tokens.get(data.defenderTokenId).actor; let defender = canvas.tokens.get(data.defenderTokenId).actor;
defender.encaisserDommages(attackerRoll, attacker); defender.encaisserDommages(attackerRoll, attacker);
}
RdDCombat._deleteDefense(attackerRoll.passeArme); RdDCombat._deleteDefense(attackerRoll.passeArme);
RdDCombat._deleteAttaque(data.attackerId); RdDCombat._deleteAttaque(data.attackerId);
} }
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static onMsgDefense(msg) { static onMsgDefense(msg) {
@ -503,7 +500,7 @@ export class RdDCombat {
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer."); ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
return; return;
} }
if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character?._id == defenderToken.actor.data._id))) { if (Misc.isElectedUser()) {
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId); const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
if (rddCombat) { if (rddCombat) {
const defenderRoll = msg.defenderRoll; const defenderRoll = msg.defenderRoll;
@ -825,8 +822,7 @@ export class RdDCombat {
dmg: attackerRoll.dmg, dmg: attackerRoll.dmg,
}; };
const selfMessage = essaisPrecedents != undefined; if (!Misc.isElectedUser()) {
if (!selfMessage && (!game.user.isGM || this.defender.hasPlayerOwner)) {
this._socketSendMessageDefense(paramChatDefense, defenderRoll); this._socketSendMessageDefense(paramChatDefense, defenderRoll);
} }
else { else {
@ -1203,7 +1199,7 @@ export class RdDCombat {
this._onEchecTotal(defenderRoll); this._onEchecTotal(defenderRoll);
} }
if (game.user.isGM) { // Current user is the GM -> direct access if (Misc.isElectedUser()) {
attackerRoll.attackerId = this.attackerId; attackerRoll.attackerId = this.attackerId;
attackerRoll.defenderTokenId = defenderTokenId; attackerRoll.defenderTokenId = defenderTokenId;