Petits fixes mineurs #505

Merged
vincent.vandeme merged 1 commits from v1.5-fixes into v1.5 2021-10-08 17:05:09 +02:00
3 changed files with 44 additions and 2 deletions

View File

@ -3589,7 +3589,7 @@ export class RdDActor extends Actor {
if (acheteur) {
let resteAcheteur = await acheteur.depenser(coutDeniers);
if (resteAcheteur < 0) {
ui.notifications.warn(`Vous n'avez pas assez d'argent pour payer ${vente.prixTotal} sols !`);
ChatUtility.notifyUser(achat.userId, 'warn', `Vous n'avez pas assez d'argent pour payer ${Math.ceil(coutDeniers/100)} sols !`);
return;
}
}
@ -3598,7 +3598,7 @@ export class RdDActor extends Actor {
let itemVenduData = Misc.data(itemVendu);
if ("quantite" in itemVenduData.data ? itemVenduData.data.quantite < achat.quantiteTotal : achat.choix.nombreLots != 1) {
await acheteur?.ajouterDeniers(coutDeniers);
ui.notifications.warn(`Le vendeur n'a plus assez de ${vente.item.name} !`);
ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a plus assez de ${vente.item.name} !`);
return;
}
vendeur.ajouterDeniers(coutDeniers);
@ -3630,6 +3630,7 @@ export class RdDActor extends Actor {
const chatAchatItem = duplicate(vente);
chatAchatItem.quantiteTotal = achat.quantiteTotal;
ChatMessage.create({
speaker: {alias: (acheteur ?? vendeur).name} ,
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name),
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-achat-item.html', chatAchatItem)
});

View File

@ -9,6 +9,33 @@ export class ChatUtility {
static onSocketMessage(sockmsg) {
switch (sockmsg.msg) {
case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.data);
case "msg_user_ui_notifications": return ChatUtility.onNotifyUser(sockmsg.data);
}
}
/* -------------------------------------------- */
static notifyUser(userId, level = 'info', message) {
const data = {
userId: userId, level: level, message: message
};
if (game.user.id == userId) {
ChatUtility.onNotifyUser(data);
}
else {
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_user_ui_notifications", data: data
});
}
}
static onNotifyUser(data) {
if (game.user.id == data.userId) {
switch (data.level) {
case 'warn': ui.notifications.warn(data.message); break;
case 'error': ui.notifications.error(data.message); break;
default: ui.notifications.info(data.message); break;
}
}
}
@ -25,6 +52,19 @@ export class ChatUtility {
}
}
static onRemoveMessages(data) {
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) {
game.messages.get(data.messageId)?.delete();
}
}
}
/* -------------------------------------------- */
static removeMessages(data) {
if (Misc.isElectedUser()){
ChatUtility.onRemoveMessages(data);

View File

@ -79,6 +79,7 @@ export class DialogItemAchat extends Dialog {
async onAchat() {
await $(".nombreLots").change();
(this.vendeur ?? this.acheteur).achatVente({
userId: game.user.id,
vendeurId: this.vendeur?.id,
acheteurId: this.acheteur?.id,
prixTotal: this.venteData.prixTotal,