10.0.2.1 #573
@ -65,7 +65,7 @@ export class RdDActor extends Actor {
|
|||||||
static onSocketMessage(sockmsg) {
|
static onSocketMessage(sockmsg) {
|
||||||
switch (sockmsg.msg) {
|
switch (sockmsg.msg) {
|
||||||
case "msg_remote_actor_call":
|
case "msg_remote_actor_call":
|
||||||
return RdDActor.onRemoteActorCall(sockmsg.data);
|
return RdDActor.onRemoteActorCall(sockmsg.data, sockmsg.userId);
|
||||||
case "msg_reset_nombre_astral":
|
case "msg_reset_nombre_astral":
|
||||||
console.log("RESET ASTRAL", game.user.character);
|
console.log("RESET ASTRAL", game.user.character);
|
||||||
game.user.character.resetNombreAstral();
|
game.user.character.resetNombreAstral();
|
||||||
@ -73,18 +73,20 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static remoteActorCall(callData, canExecuteLocally = () => Misc.isUniqueConnectedGM()) {
|
static remoteActorCall(callData, userId = undefined) {
|
||||||
if (canExecuteLocally()) {
|
userId = userId ?? Misc.firstConnectedGMId();
|
||||||
RdDActor.onRemoteActorCall(callData);
|
if (userId == game.user.id) {
|
||||||
|
RdDActor.onRemoteActorCall(callData, userId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData });
|
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData, userId: userId });
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static onRemoteActorCall(callData) {
|
static onRemoteActorCall(callData, userId) {
|
||||||
|
if (userId == game.user.id) {
|
||||||
const actor = game.actors.get(callData?.actorId);
|
const actor = game.actors.get(callData?.actorId);
|
||||||
if (Misc.isOwnerPlayerOrUniqueConnectedGM(actor)) { // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon
|
if (Misc.isOwnerPlayerOrUniqueConnectedGM(actor)) { // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon
|
||||||
const args = callData.args;
|
const args = callData.args;
|
||||||
@ -92,6 +94,7 @@ export class RdDActor extends Actor {
|
|||||||
actor[callData.method](...args);
|
actor[callData.method](...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static getParentActor(document) {
|
static getParentActor(document) {
|
||||||
@ -299,7 +302,7 @@ export class RdDActor extends Actor {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getObjet(id) {
|
getObjet(id) {
|
||||||
return id ? this.items.find(it => it.id == id) : undefined;
|
return this.getEmbeddedDocument('Item', id);
|
||||||
}
|
}
|
||||||
|
|
||||||
listItemsData(type) {
|
listItemsData(type) {
|
||||||
@ -1932,15 +1935,24 @@ export class RdDActor extends Actor {
|
|||||||
async consommer(item, choix) {
|
async consommer(item, choix) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'nourritureboisson':
|
case 'nourritureboisson':
|
||||||
return await this.consommerNourritureboisson(item, choix);
|
return await this.consommerNourritureboisson(item.id, choix);
|
||||||
case 'potion':
|
case 'potion':
|
||||||
return await this.consommerPotion(item)
|
return await this.consommerPotion(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async consommerNourritureboisson(item, choix = { doses: 1, seForcer: false, supprimerSiZero: false }) {
|
async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false}, userId = undefined) {
|
||||||
|
if (userId != undefined && userId != game.user.id) {
|
||||||
|
RdDActor.remoteActorCall({
|
||||||
|
actorId: this.id,
|
||||||
|
method: 'consommerNourritureboisson',
|
||||||
|
args: [itemId, choix, userId]
|
||||||
|
},
|
||||||
|
userId)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const item = this.getObjet(itemId)
|
||||||
if (item.type != 'nourritureboisson') {
|
if (item.type != 'nourritureboisson') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3649,10 +3661,7 @@ export class RdDActor extends Actor {
|
|||||||
|
|
||||||
const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
|
const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
|
||||||
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
|
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
|
||||||
const messageVente = game.messages.get(achat.chatMessageIdVente);
|
const vente = achat.vente;
|
||||||
const html = await messageVente.getHTML();
|
|
||||||
const button = html.find(".button-acheter")[0];
|
|
||||||
const vente = DialogItemAchat.venteData(button);
|
|
||||||
const itemId = vente.item._id;
|
const itemId = vente.item._id;
|
||||||
const isItemEmpilable = "quantite" in vente.item.system;
|
const isItemEmpilable = "quantite" in vente.item.system;
|
||||||
|
|
||||||
@ -3692,7 +3701,7 @@ export class RdDActor extends Actor {
|
|||||||
let items = await acheteur.createEmbeddedDocuments("Item", listeAchat);
|
let items = await acheteur.createEmbeddedDocuments("Item", listeAchat);
|
||||||
if (achat.choix.consommer && vente.item.type == 'nourritureboisson') {
|
if (achat.choix.consommer && vente.item.type == 'nourritureboisson') {
|
||||||
achat.choix.doses = achat.choix.nombreLots;
|
achat.choix.doses = achat.choix.nombreLots;
|
||||||
await acheteur.consommerNourritureboisson(items[0], achat.choix);
|
await acheteur.consommerNourritureboisson(items[0].id, achat.choix, vente.actingUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (coutDeniers > 0) {
|
if (coutDeniers > 0) {
|
||||||
|
@ -27,7 +27,8 @@ export class DialogChronologie extends Dialog {
|
|||||||
dateReel: DialogChronologie.getCurrentDateTime()
|
dateReel: DialogChronologie.getCurrentDateTime()
|
||||||
};
|
};
|
||||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-chronologie.html", dialogData);
|
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-chronologie.html", dialogData);
|
||||||
new DialogChronologie(html).render(true);
|
const dialog = new DialogChronologie(html);
|
||||||
|
dialog.render(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(html) {
|
constructor(html) {
|
||||||
|
@ -22,6 +22,7 @@ export class DialogItemAchat extends Dialog {
|
|||||||
const prixLot = Monnaie.arrondiDeniers(button.attributes['data-prixLot']?.value ?? 0);
|
const prixLot = Monnaie.arrondiDeniers(button.attributes['data-prixLot']?.value ?? 0);
|
||||||
return {
|
return {
|
||||||
item: json ? JSON.parse(json) : undefined,
|
item: json ? JSON.parse(json) : undefined,
|
||||||
|
actingUserId: game.user.id,
|
||||||
vendeurId: vendeurId,
|
vendeurId: vendeurId,
|
||||||
vendeur: vendeur,
|
vendeur: vendeur,
|
||||||
acheteur: acheteur,
|
acheteur: acheteur,
|
||||||
@ -39,6 +40,7 @@ export class DialogItemAchat extends Dialog {
|
|||||||
chatMessageIdVente: RdDUtility.findChatMessageId(button)
|
chatMessageIdVente: RdDUtility.findChatMessageId(button)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static async onAcheter(venteData) {
|
static async onAcheter(venteData) {
|
||||||
const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-achat.html`, venteData);
|
const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-achat.html`, venteData);
|
||||||
const dialog = new DialogItemAchat(html, venteData);
|
const dialog = new DialogItemAchat(html, venteData);
|
||||||
@ -52,7 +54,7 @@ export class DialogItemAchat extends Dialog {
|
|||||||
const actionAchat = venteData.prixLot > 0 ? "Acheter" : "Prendre";
|
const actionAchat = venteData.prixLot > 0 ? "Acheter" : "Prendre";
|
||||||
const buttons = {};
|
const buttons = {};
|
||||||
if (isConsommable) {
|
if (isConsommable) {
|
||||||
buttons["consommer"] = { label: venteData.item.system.boisson ? "Boire" : "Manger", callback: it => { this.onAchatConsommer(); } }
|
buttons["consommer"] = { label: venteData.item.system.boisson ? "Boire" : "Manger", callback: it => this.onAchatConsommer() }
|
||||||
}
|
}
|
||||||
buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } };
|
buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } };
|
||||||
buttons["decliner"] = { label: "Décliner", callback: it => { } };
|
buttons["decliner"] = { label: "Décliner", callback: it => { } };
|
||||||
@ -76,7 +78,8 @@ export class DialogItemAchat extends Dialog {
|
|||||||
acheteurId: this.venteData.acheteur?.id,
|
acheteurId: this.venteData.acheteur?.id,
|
||||||
prixTotal: this.venteData.prixTotal,
|
prixTotal: this.venteData.prixTotal,
|
||||||
chatMessageIdVente: this.venteData.chatMessageIdVente,
|
chatMessageIdVente: this.venteData.chatMessageIdVente,
|
||||||
choix: this.venteData.choix
|
choix: this.venteData.choix,
|
||||||
|
vente: this.venteData
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ import { Misc } from "./misc.js";
|
|||||||
export class DialogRepos extends Dialog {
|
export class DialogRepos extends Dialog {
|
||||||
|
|
||||||
static async create(actor) {
|
static async create(actor) {
|
||||||
let actorData = actor
|
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-repos.html", actor);
|
||||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-repos.html", actorData);
|
const dialog = new DialogRepos(html, actor);
|
||||||
new DialogRepos(html, actor).render(true);
|
dialog.render(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(html, actor) {
|
constructor(html, actor) {
|
||||||
|
@ -133,7 +133,11 @@ export class Misc {
|
|||||||
* @returns true pour un seul utilisateur: le premier GM connecté par ordre d'id
|
* @returns true pour un seul utilisateur: le premier GM connecté par ordre d'id
|
||||||
*/
|
*/
|
||||||
static isUniqueConnectedGM() {
|
static isUniqueConnectedGM() {
|
||||||
return game.user.id == Misc.firstConnectedGM()?.id;
|
return game.user.id == Misc.firstConnectedGMId();
|
||||||
|
}
|
||||||
|
|
||||||
|
static firstConnectedGMId() {
|
||||||
|
return Misc.firstConnectedGM()?.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user