Merge branch 'v1.4-fix-socket-loop' into 'v1.4'

Fix: boucle infinie de messages

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!254
This commit is contained in:
Leratier Bretonnien 2021-05-27 05:37:57 +00:00
commit 3793563a2c
11 changed files with 75 additions and 62 deletions

View File

@ -14,7 +14,7 @@
"TypeNombreastral": "Nombre astral", "TypeNombreastral": "Nombre astral",
"TypeTarot": "Carte de tarot", "TypeTarot": "Carte de tarot",
"TypeCasetmr": "TMR spéciale", "TypeCasetmr": "TMR spéciale",
"TypeRencontresTMR": "Rencontre TMR", "TypeRencontrestmr": "Rencontre TMR",
"TypeMunition": "Munition", "TypeMunition": "Munition",
"TypeMonnaie": "Monnaie", "TypeMonnaie": "Monnaie",
"TypeHerbe": "Herbe ou plante", "TypeHerbe": "Herbe ou plante",

View File

@ -56,14 +56,17 @@ export class RdDActor extends Actor {
} }
} }
static remoteActorCall(options) { static remoteActorCall(data) {
console.log("remoteActorCall ", options) if (Misc.isElectedUser()){
options.userId = options.userId ?? Misc.connectedGMOrUser(); RdDActor.onRemoteActorCall(data);
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: options }); }
else{
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: data });
}
} }
static onRemoteActorCall(data) { static onRemoteActorCall(data) {
if (game.user.id == data.userId) { // Seul le joueur choisi effectue l'appel if (Misc.isElectedUser()) { // Seul le joueur choisi effectue l'appel
const actor = game.actors.get(data?.actorId); const actor = game.actors.get(data?.actorId);
if (!actor) { if (!actor) {
console.info("RdDActor.onRemoteActorCall: Pas d'Actor disponible ", data); console.info("RdDActor.onRemoteActorCall: Pas d'Actor disponible ", data);
@ -2400,8 +2403,9 @@ export class RdDActor extends Actor {
let rollData = { let rollData = {
competence: compData, competence: compData,
tache: tacheData, tache: tacheData,
diffConditions: tacheData.data.difficulte, diffLibre: tacheData.data.difficulte,
use: { libre: false, conditions: false }, diffConditions: 0,
use: { libre: false, conditions: true },
carac: {} carac: {}
}; };
rollData.carac[tacheData.data.carac] = duplicate(actorData.data.carac[tacheData.data.carac]); // Single carac rollData.carac[tacheData.data.carac] = duplicate(actorData.data.carac[tacheData.data.carac]); // Single carac
@ -3425,8 +3429,7 @@ export class RdDActor extends Actor {
} }
if (!Misc.isElectedUser()) { if (!Misc.isElectedUser()) {
RdDActor.remoteActorCall({ RdDActor.remoteActorCall({
userId: Misc.connectedGMOrUser(), actorId: vendeurId ?? acheteurId,
actorId: this.vendeur?.id ?? this.acheteur?.id,
method: 'achatVente', args: [vendeurId, acheteurId, venteData, chatMessageIdVente] method: 'achatVente', args: [vendeurId, acheteurId, venteData, chatMessageIdVente]
}); });
return; return;

View File

@ -23,19 +23,24 @@ export class ChatUtility {
game.messages.get(data.messageId)?.delete(); game.messages.get(data.messageId)?.delete();
} }
} }
}
static removeMessages(data) {
if (Misc.isElectedUser()){
ChatUtility.onRemoveMessages(data);
}
else { else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: data }); game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: data });
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static removeChatMessageContaining(part) { static removeChatMessageContaining(part) {
ChatUtility.onRemoveMessages({ part: part }); ChatUtility.removeMessages({ part: part });
} }
static removeChatMessageId(messageId) { static removeChatMessageId(messageId) {
ChatUtility.onRemoveMessages({ messageId: messageId }); ChatUtility.removeMessages({ messageId: messageId });
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -37,17 +37,23 @@ const MAX_NOMBRE_ASTRAL = 12;
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDCalendrier extends Application { export class RdDCalendrier extends Application {
getCalendrier(index) {
let calendrier = {
heureRdD: 0, // Index dans heuresList
minutesRelative: 0,
moisRdD: Math.floor(index / 28) % 12,
jour: (index - (month * 28)) + 1
}
return calendrier;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async initCalendrier() { async initCalendrier() {
// Calendrier // Calendrier
this.calendrier = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier")); this.calendrier = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier"));
//console.log("CALENDRIER", this.calendrier); //console.log("CALENDRIER", this.calendrier);
if (this.calendrier == undefined || this.calendrier.moisRdD == undefined) { if (this.calendrier == undefined || this.calendrier.moisRdD == undefined) {
this.calendrier = {}; this.calendrier = this.getCalendrier(0);
this.calendrier.heureRdD = 0; // Index dans heuresList
this.calendrier.minutesRelative = 0;
this.calendrier.moisRdD = 0; // Index dans heuresList
this.calendrier.jour = 0;
if (game.user.isGM) { // Uniquement si GM if (game.user.isGM) { // Uniquement si GM
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier); game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier);
} }
@ -86,8 +92,8 @@ export class RdDCalendrier extends Application {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getDateFromIndex(index = undefined) { getDateFromIndex(index) {
if (!index) index = this.getCurrentDayIndex(); index = index ?? this.getCurrentDayIndex();
let month = Math.floor(index / 28); let month = Math.floor(index / 28);
let day = (index - (month * 28)) + 1; let day = (index - (month * 28)) + 1;
return day + " " + heuresList[month]; return day + " " + heuresList[month];
@ -131,6 +137,11 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */ /* -------------------------------------------- */
async ajouterNombreAstral(index) { async ajouterNombreAstral(index) {
const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: true, rollMode: "selfroll" }); const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: true, rollMode: "selfroll" });
const dateFuture = this.getDateFromIndex(index);
ChatMessage.create({
whisper: ChatMessage.getWhisperRecipients("GM"),
content: `Le chiffre astrologique du ${dateFuture} sera le ${nombreAstral}`
});
return { return {
nombreAstral: nombreAstral, nombreAstral: nombreAstral,
valeursFausses: [], valeursFausses: [],
@ -139,9 +150,9 @@ export class RdDCalendrier extends Application {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async getCurrentNombreAstral() { getCurrentNombreAstral() {
let indexDate = this.getCurrentDayIndex(); let indexDate = this.getCurrentDayIndex();
return await this.getNombreAstral(indexDate); return this.getNombreAstral(indexDate);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -151,14 +162,13 @@ export class RdDCalendrier extends Application {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async getNombreAstral(indexDate) { getNombreAstral(indexDate) {
const liste = this.listeNombreAstral ?? this._loadListNombreAstral(); const liste = this.listeNombreAstral ?? this._loadListNombreAstral();
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate); let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
if (!astralData?.nombreAstral) { if (!astralData?.nombreAstral) {
await this.rebuildListeNombreAstral(); this.rebuildListeNombreAstral();
astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
} }
return astralData?.nombreAstral ?? "N/A"; return astralData?.nombreAstral;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -217,7 +227,7 @@ export class RdDCalendrier extends Application {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async incrementerJour() { incrementerJour() {
this.calendrier.jour += 1; this.calendrier.jour += 1;
if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) { if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
this.calendrier.jour -= RDD_JOUR_PAR_MOIS; this.calendrier.jour -= RDD_JOUR_PAR_MOIS;
@ -226,13 +236,13 @@ export class RdDCalendrier extends Application {
this.calendrier.moisRdD += 1; this.calendrier.moisRdD += 1;
// Reconstruire les nombres astraux // Reconstruire les nombres astraux
} }
await this.rebuildListeNombreAstral(); this.rebuildListeNombreAstral();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async syncPlayerTime(calendrier) { syncPlayerTime(calendrier) {
this.calendrier = duplicate(calendrier); // Local copy update this.calendrier = duplicate(calendrier); // Local copy update
await this.updateDisplay(); this.updateDisplay();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -287,7 +297,7 @@ export class RdDCalendrier extends Application {
showDice: false showDice: false
}; };
await RdDResolutionTable.rollData(rollData); await RdDResolutionTable.rollData(rollData);
let nbAstral = await this.getNombreAstral(request.date); let nbAstral = this.getNombreAstral(request.date);
request.rolled = rollData.rolled; request.rolled = rollData.rolled;
request.isValid = true; request.isValid = true;
if (!request.rolled.isSuccess) { if (!request.rolled.isSuccess) {
@ -311,11 +321,11 @@ export class RdDCalendrier extends Application {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async getAjustementAstrologique(heureNaissance, name = 'inconnu') { getAjustementAstrologique(heureNaissance, name = 'inconnu') {
let heure = Grammar.toLowerCaseNoAccent(heureNaissance); let heure = Grammar.toLowerCaseNoAccent(heureNaissance);
if (heure && heuresDef[heure]) { if (heure && heuresDef[heure]) {
let hn = heuresDef[heure].heure; let hn = heuresDef[heure].heure;
let chiffreAstral = await this.getCurrentNombreAstral(); let chiffreAstral = this.getCurrentNombreAstral() ?? 0;
let heureCourante = this.calendrier.heureRdD; let heureCourante = this.calendrier.heureRdD;
let ecartChance = (hn + chiffreAstral - heureCourante) % 12; let ecartChance = (hn + chiffreAstral - heureCourante) % 12;
switch (ecartChance) { switch (ecartChance) {
@ -362,12 +372,12 @@ export class RdDCalendrier extends Application {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async updateDisplay() { updateDisplay() {
let data = this.fillCalendrierData(); let data = this.fillCalendrierData();
// Rebuild data // Rebuild data
let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`; let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`
if (game.user.isGM) { if (game.user.isGM) {
dateHTML = dateHTML + " - NA: " + await this.getCurrentNombreAstral(); dateHTML = dateHTML + " - NA: " + (this.getCurrentNombreAstral() ?? "indéterminé");
} }
for (let handle of document.getElementsByClassName("calendar-date-rdd")) { for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
handle.innerHTML = dateHTML; handle.innerHTML = dateHTML;
@ -393,7 +403,7 @@ export class RdDCalendrier extends Application {
await this.rebuildListeNombreAstral(); await this.rebuildListeNombreAstral();
await this.updateDisplay(); this.updateDisplay();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -491,20 +491,14 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onMsgDefense(msg) { static onMsgDefense(msg) {
let defenderToken = canvas.tokens.get(msg.defenderTokenId); let defenderToken = canvas.tokens.get(msg.defenderTokenId);
if (defenderToken) { if (defenderToken && Misc.isElectedUser()) {
if (!game.user.isGM && !game.user.character) { // vérification / sanity check const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer."); if (rddCombat) {
return; const defenderRoll = msg.defenderRoll;
} RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
if (Misc.isElectedUser()) { RdDCombat._storeDefense(defenderRoll);
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId); rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
if (rddCombat) { rddCombat._chatMessageDefense(msg.paramChatDefense);
const defenderRoll = msg.defenderRoll;
RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
RdDCombat._storeDefense(defenderRoll);
rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
rddCombat._chatMessageDefense(msg.paramChatDefense);
}
} }
} }
} }

View File

@ -143,6 +143,8 @@ Hooks.once("init", async function () {
/* -------------------------------------------- */ /* -------------------------------------------- */
game.socket.on("system.foundryvtt-reve-de-dragon", sockmsg => { game.socket.on("system.foundryvtt-reve-de-dragon", sockmsg => {
console.log(">>>>> MSG RECV", sockmsg);
RdDUtility.onSocketMesssage(sockmsg); RdDUtility.onSocketMesssage(sockmsg);
RdDCombat.onSocketMessage(sockmsg); RdDCombat.onSocketMessage(sockmsg);
ChatUtility.onSocketMessage(sockmsg); ChatUtility.onSocketMessage(sockmsg);

View File

@ -547,7 +547,6 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onSocketMesssage(sockmsg) { static onSocketMesssage(sockmsg) {
console.log(">>>>> MSG RECV", sockmsg);
switch (sockmsg.msg) { switch (sockmsg.msg) {
case "msg_gm_chat_message": case "msg_gm_chat_message":
return ChatUtility.handleGMChatMessage(sockmsg.data); return ChatUtility.handleGMChatMessage(sockmsg.data);
@ -602,9 +601,6 @@ export class RdDUtility {
let actor = RdDUtility.getSelectedActor("Pour effectuer le paiement:"); let actor = RdDUtility.getSelectedActor("Pour effectuer le paiement:");
if (actor) { if (actor) {
actor.depenserDeniers(sumdenier, objData, quantite, fromActorId); actor.depenserDeniers(sumdenier, objData, quantite, fromActorId);
// TODO: diminuer la quantité ou supprimer le message
// message: => document.querySelector("#chat-log > li:nth-child(61) > div > div > span > a")
// => ../../../..[@data-message-id]
let chatMessageId = RdDUtility.findChatMessageId(event.currentTarget); let chatMessageId = RdDUtility.findChatMessageId(event.currentTarget);
if (chatMessageId) { if (chatMessageId) {
ChatUtility.removeChatMessageId(chatMessageId); ChatUtility.removeChatMessageId(chatMessageId);

View File

@ -14,7 +14,9 @@
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span> <span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
<div class="item-controls flex-grow"> <div class="item-controls flex-grow">
{{#unless item.estContenu}} {{#unless item.estContenu}}
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-hand-rock"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a> {{#if (ne item.type 'conteneur')}}
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-hand-rock"></i>{{else}}<i class="far fa-hand-paper"></i>{{/if}}</a>
{{/if}}
{{/unless}} {{/unless}}
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>

View File

@ -610,13 +610,14 @@
</li> </li>
{{#each objets as |item id|}} {{#each objets as |item id|}}
{{#unless item.estContenu}} {{#unless item.estContenu}}
{{#if (eq item.type 'conteneur')}} {{#if (ne item.type 'conteneur')}}
{{buildConteneur this}}
{{else}}
{{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-conteneur.html" item=item }} {{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-conteneur.html" item=item }}
{{/if}} {{/if}}
{{/unless}} {{/unless}}
{{/each}} {{/each}}
{{#each conteneurs as |conteneur id|}}
{{buildConteneur this}}
{{/each}}
</ul> </ul>
<span class="item-name"><h4>Montures</h4></span> <span class="item-name"><h4>Montures</h4></span>

View File

@ -1,8 +1,8 @@
<div id="calendar-time-container"> <div id="calendar-time-container">
<div class="calendar"> <div class="calendar">
{{#if isGM}} {{#if isGM}}
<i class="calendar-btn-edit fas fa-cog" title="Editer"></i> <i class="calendar-btn calendar-btn-edit fas fa-cog" title="Editer"></i>
<i class="astrologie-btn-edit fas fa-cog" title="Astrologie"></i> <i class="calendar-btn astrologie-btn-edit fas fa-cog" title="Astrologie"></i>
{{/if}} {{/if}}
<div class="calendar-hdr"> <div class="calendar-hdr">
<p id="calendar-move-handle" class="calendar-date-rdd" title="Deplacer">Jour {{jourMois}} de {{nomMois}} ({{nomSaison}})</p> <p id="calendar-move-handle" class="calendar-date-rdd" title="Deplacer">Jour {{jourMois}} de {{nomMois}} ({{nomSaison}})</p>

View File

@ -1,5 +1,5 @@
<div class="post-item" data-transfer="{{transfer}}"> <div class="post-item" data-transfer="{{transfer}}">
<h3>{{#if alias}}{{alias}} propose:{{else}}Acheter {{/if}}{{item.name}}</h3> <h3>{{#if alias}}{{alias}} propose: {{else}}Acheter {{/if}}{{item.name}}</h3>
{{#if item.img}} {{#if item.img}}
<img src="{{item.img}}" title="{{item.name}}" /> <img src="{{item.img}}" title="{{item.name}}" />
{{/if}} {{/if}}