Merge branch 'master-fix-defense-193' into 'master'

#193: utiliser isElectedUser pour les défenses

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!249
This commit is contained in:
Leratier Bretonnien 2021-05-22 06:39:14 +00:00
commit 82e8954d5c
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
@ -7,31 +8,27 @@ export class ChatUtility {
/* -------------------------------------------- */
static onSocketMessage(sockmsg) {
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) {
if (game.user._id == gmId) {
static onRemoveMessages(part) {
if (Misc.isElectedUser()) {
const toDelete = game.messages.filter(it => it.data.content.includes(part));
toDelete.forEach(it => it.delete());
}
}
/* -------------------------------------------- */
static removeChatMessageContaining(part) {
const gmId = game.user.isGM ? game.user._id : game.users.entities.find(u => u.isGM && u.active)?.id;
if (!gmId || game.user.isGM) {
ChatUtility.onRemoveMessages(part, game.user._id);
if (Misc.isElectedUser()) {
ChatUtility.onRemoveMessages(part);
}
else {
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_delete_chat_message", data: {
part:part,
gmId: gmId,
}});
msg: "msg_delete_chat_message", data: { part: part }
});
}
}
@ -108,5 +105,5 @@ export class ChatUtility {
ChatMessage.create(data);
}
}
}

View File

@ -395,9 +395,8 @@ export class RdDCombat {
/* -------------------------------------------- */
static combatNouveauTour(combat) {
let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId);
if (game.user.isGM) {
// seul le GM notifie le status
if (Misc.isElectedUser()) {
let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId);
this.displayActorCombatStatus(combat, turn.actor);
// TODO Playaudio for player??
}
@ -482,17 +481,15 @@ export class RdDCombat {
/* -------------------------------------------- */
static onMsgEncaisser(data) {
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
if (Misc.isElectedUser()) {
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;
defender.encaisserDommages(attackerRoll, attacker);
RdDCombat._deleteDefense(attackerRoll.passeArme);
RdDCombat._deleteAttaque(data.attackerId);
}
RdDCombat._deleteDefense(attackerRoll.passeArme);
RdDCombat._deleteAttaque(data.attackerId);
}
/* -------------------------------------------- */
@ -503,7 +500,7 @@ export class RdDCombat {
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
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);
if (rddCombat) {
const defenderRoll = msg.defenderRoll;
@ -825,8 +822,7 @@ export class RdDCombat {
dmg: attackerRoll.dmg,
};
const selfMessage = essaisPrecedents != undefined;
if (!selfMessage && (!game.user.isGM || this.defender.hasPlayerOwner)) {
if (!Misc.isElectedUser()) {
this._socketSendMessageDefense(paramChatDefense, defenderRoll);
}
else {
@ -1203,7 +1199,7 @@ export class RdDCombat {
this._onEchecTotal(defenderRoll);
}
if (game.user.isGM) { // Current user is the GM -> direct access
if (Misc.isElectedUser()) {
attackerRoll.attackerId = this.attackerId;
attackerRoll.defenderTokenId = defenderTokenId;