Fix: regression combat

Notifier tous les postes clients des données de passe d'arme
This commit is contained in:
Vincent Vandemeulebrouck 2021-06-01 00:07:31 +02:00
parent 87a0bece5e
commit 21d6f14b68

View File

@ -196,8 +196,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" } });
}
}
@ -364,6 +364,8 @@ export class RdDCombat {
return RdDCombat.onMsgEncaisser(sockmsg.data);
case "msg_defense":
return RdDCombat.onMsgDefense(sockmsg.data);
case "msg_combat_passearme":
return RdDCombat.onMsgPasseArme(sockmsg.data);
}
}
@ -434,9 +436,31 @@ export class RdDCombat {
return undefined;
}
static messagePasseArme(data) {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_combat_passearme", data: data });
RdDCombat.onMsgPasseArme(data);
}
static onMsgPasseArme(data) {
switch (data.actionPasseArme) {
case "store-attaque":
game.system.rdd.combatStore.attaques[data.id] = data.rollData;
break;
case "store-defense":
game.system.rdd.combatStore.defenses[data.id] = data.rollData;
break;
case "delete-attaque":
delete game.system.rdd.combatStore.attaques[data.id];
break;
case "delete-defense":
delete game.system.rdd.combatStore.defenses[data.id];
break;
}
}
/* -------------------------------------------- */
static _storeAttaque(attackerId, attackerRoll) {
game.system.rdd.combatStore.attaques[attackerId] = duplicate(attackerRoll);
RdDCombat.messagePasseArme({ actionPasseArme: "store-attaque", id: attackerId, rollData: attackerRoll });
}
/* -------------------------------------------- */
@ -446,12 +470,12 @@ export class RdDCombat {
/* -------------------------------------------- */
static _deleteAttaque(attackerId) {
delete game.system.rdd.combatStore.attaques[attackerId];
RdDCombat.messagePasseArme({ actionPasseArme: "delete-attaque", id: attackerId });
}
/* -------------------------------------------- */
static _storeDefense(defenderRoll) {
game.system.rdd.combatStore.defenses[defenderRoll.passeArme] = duplicate(defenderRoll);
static _storeDefense(passeArme, defenderRoll) {
RdDCombat.messagePasseArme({ actionPasseArme: "store-defense", id: passeArme, rollData: defenderRoll });
}
/* -------------------------------------------- */
@ -461,7 +485,7 @@ export class RdDCombat {
/* -------------------------------------------- */
static _deleteDefense(passeArme) {
delete game.system.rdd.combatStore.defenses[passeArme];
RdDCombat.messagePasseArme({ actionPasseArme: "delete-defense", id: passeArme });
}
/* -------------------------------------------- */
@ -497,20 +521,18 @@ export class RdDCombat {
/* -------------------------------------------- */
static onMsgDefense(msg) {
let defenderToken = canvas.tokens.get(msg.defenderTokenId);
if (defenderToken) {
if (!game.user.isGM && !game.user.character) { // vérification / sanity check
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
return;
}
if (Misc.isElectedUser()) {
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
if (rddCombat) {
const defenderRoll = msg.defenderRoll;
RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
RdDCombat._storeDefense(defenderRoll);
rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
rddCombat._chatMessageDefense(msg.paramChatDefense);
}
if (!game.user.isGM && !game.user.character) { // vérification / sanity check
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
return;
}
if (defenderToken && Misc.isElectedUser()) {
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
if (rddCombat) {
const defenderRoll = msg.defenderRoll;
RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll);
rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
rddCombat._chatMessageDefense(msg.paramChatDefense);
}
}
}
@ -773,7 +795,7 @@ export class RdDCombat {
let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} }
// Save rollData for defender
RdDCombat._storeAttaque(this.attackerId, attackerRoll);
RdDCombat._storeDefense(defenderRoll)
RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll);
attackerRoll.show = {
cible: this.target ? this.defender.data.name : 'la cible',
@ -1009,7 +1031,7 @@ export class RdDCombat {
this.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
this._sendMessageDefense(defenderRoll.attackerRoll, defenderRoll, { defense: true });
RdDCombat._storeDefense(defenderRoll);
RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll);
}
/* -------------------------------------------- */
@ -1081,7 +1103,7 @@ export class RdDCombat {
this.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
this._sendMessageDefense(defenderRoll.attackerRoll, defenderRoll, { defense: true })
RdDCombat._storeDefense(defenderRoll);
RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll);
}
/* -------------------------------------------- */