Merge branch 'v1.4-fix-193' into 'v1.4'

#193: utiliser isElectedUser pour les défenses

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!250
This commit is contained in:
Leratier Bretonnien 2021-05-22 06:39:26 +00:00
commit a22c435ca5
2 changed files with 23 additions and 40 deletions

View File

@ -14,7 +14,7 @@ export class ChatUtility {
/* -------------------------------------------- */
static onRemoveMessages(data) {
if (game.user.isGM || game.user.id == data.gmId) {
if (Misc.isElectedUser()) {
if (data.part) {
const toDelete = game.messages.filter(it => it.data.content.includes(data.part));
toDelete.forEach(it => it.delete());
@ -23,31 +23,19 @@ export class ChatUtility {
game.messages.get(data.messageId)?.delete();
}
}
else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: data });
}
}
/* -------------------------------------------- */
static removeChatMessageContaining(part) {
const removeMessageData = {
part: part,
gmId: Misc.connectedGMOrUser()
};
if (game.user.isGM) {
ChatUtility.onRemoveMessages(removeMessageData);
}
else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: removeMessageData });
}
ChatUtility.onRemoveMessages({ part: part });
}
static removeChatMessageId(messageId) {
const removeMessageData = { messageId: messageId, gmId: Misc.connectedGMOrUser() };
if (game.user.isGM) {
ChatUtility.onRemoveMessages(removeMessageData);
}
else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: removeMessageData });
}
ChatUtility.onRemoveMessages({ messageId: messageId });
}
/* -------------------------------------------- */

View File

@ -390,9 +390,8 @@ export class RdDCombat {
/* -------------------------------------------- */
static combatNouveauTour(combat) {
if (Misc.isElectedUser()) {
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);
// TODO Playaudio for player??
}
@ -477,19 +476,18 @@ export class RdDCombat {
/* -------------------------------------------- */
static onMsgEncaisser(data) {
if (Misc.isElectedUser()) {
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 defender = canvas.tokens.get(data.defenderTokenId).actor;
defender.encaisserDommages(attackerRoll, attacker);
}
RdDCombat._deleteDefense(attackerRoll.passeArme);
RdDCombat._deleteAttaque(data.attackerId);
}
}
/* -------------------------------------------- */
static onMsgDefense(msg) {
let defenderToken = canvas.tokens.get(msg.defenderTokenId);
@ -498,10 +496,7 @@ export class RdDCombat {
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
return;
}
const isDefenderConnectedPlayer = defenderToken.actor.hasPlayerOwner; // TODO: tester si le joueur est pas connecté
if (isDefenderConnectedPlayer
? game.user.character?._id == defenderToken.actor.data._id // TODO: vérifier le cas d'un joueur qui est owner de plusieurs personnages
: game.user.isGM) {
if (Misc.isElectedUser()) {
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
if (rddCombat) {
const defenderRoll = msg.defenderRoll;
@ -821,8 +816,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 {
@ -1200,13 +1194,14 @@ 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;
await this.computeRecul(defenderRoll);
this.defender.encaisserDommages(attackerRoll, this.attacker, defenderRoll);
} else { // envoi à un GM: les joueurs n'ont pas le droit de modifier les personnages qu'ils ne possèdent pas
}
else { // envoi à un GM: les joueurs n'ont pas le droit de modifier les personnages qu'ils ne possèdent pas
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_encaisser",
data: {