#193: utiliser isElectedUser pour les défenses #467

Merged
vincent.vandeme merged 1 commits from v1.4-fix-193 into v1.4 2021-05-22 08:39:26 +02:00
2 changed files with 23 additions and 40 deletions

View File

@ -14,40 +14,28 @@ export class ChatUtility {
/* -------------------------------------------- */
static onRemoveMessages(data) {
if (game.user.isGM || game.user.id == data.gmId) {
if (data.part){
if (Misc.isElectedUser()) {
if (data.part) {
const toDelete = game.messages.filter(it => it.data.content.includes(data.part));
toDelete.forEach(it => it.delete());
}
if (data.messageId){
if (data.messageId) {
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

@ -146,7 +146,7 @@ export class RdDCombatManager extends Combat {
let armeData = Misc.data(arme);
if (armeData.data.equipe) {
let compData = competences.map(c => Misc.data(c)).find(c => c.name == armeData.data.competence);
armesEquipe.push(armeData);
armeData.data.initiative = RdDCombatManager.calculInitiative(armeData.data.niveau, carac[compData.data.defaut_carac].value);
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
@ -189,8 +189,8 @@ export class RdDCombatManager extends Combat {
let competences = items.filter(it => it.type == 'competence');
actions = actions.concat(RdDCombatManager.finalizeArmeList(armes, competences, actorData.data.carac));
if (actorData.data.attributs.hautrevant.value){
if (actorData.data.attributs.hautrevant.value) {
actions.push({ name: "Draconic", data: { initOnly: true, competence: "Draconic" } });
}
}
@ -390,9 +390,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??
}
@ -477,17 +476,16 @@ 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);
}
/* -------------------------------------------- */
@ -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: {