Empêcher doublons sur tête/souffle #175
Lors de l'ajout de la tête présents des cités, le présent de chaque cité était ajouté par tous les joueurs connectés qui traitaient le hook
This commit is contained in:
parent
6fc8906d67
commit
f05a166d5b
@ -55,27 +55,21 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static remoteActorCall(actorId, method, ...args) {
|
static remoteActorCall(options) {
|
||||||
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
console.log("remoteActorCall ", options)
|
||||||
msg: "msg_remote_actor_call",
|
options.userId = options.userId ?? Misc.connectedGMOrUser();
|
||||||
data: {
|
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: options });
|
||||||
gmId: Misc.connectedGM(),
|
|
||||||
toActorId: actorId,
|
|
||||||
method: method,
|
|
||||||
args: args
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static onRemoteActorCall(data) {
|
static onRemoteActorCall(data) {
|
||||||
if (game.user.id == data.gmId) { // Seul le GM connecté choisi effectue l'appel
|
if (game.user.id == data.userId) { // Seul le joueur choisi effectue l'appel
|
||||||
const actor = game.actors.get(data?.toActorId);
|
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);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const args = data.args;
|
const args = data.args;
|
||||||
console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${data.toActorId}, appel de RdDActor.${data.method}(`, ...args, ')');
|
console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${data.actorId}, appel de RdDActor.${data.method}(`, ...args, ')');
|
||||||
actor[data.method](...args);
|
actor[data.method](...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3185,7 +3179,7 @@ export class RdDActor extends Actor {
|
|||||||
|
|
||||||
async ajouterDeniers(gain, fromActorId = undefined) {
|
async ajouterDeniers(gain, fromActorId = undefined) {
|
||||||
if (fromActorId && !game.user.isGM) {
|
if (fromActorId && !game.user.isGM) {
|
||||||
RdDActor.remoteActorCall(this.id, 'ajouterDeniers', gain, fromActorId);
|
RdDActor.remoteActorCall({ userId: Misc.connectedGMOrUser(), actorId: this.id, method: 'ajouterDeniers', args: [gain, fromActorId] });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const fromActor = game.actors.get(fromActorId)
|
const fromActor = game.actors.get(fromActorId)
|
||||||
@ -3616,6 +3610,14 @@ export class RdDActor extends Actor {
|
|||||||
await this.createEmbeddedDocuments('ActiveEffect', [effet]);
|
await this.createEmbeddedDocuments('ActiveEffect', [effet]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
async onPreUpdateItem(item, change, options, id) {
|
||||||
|
const itemData = Misc.data(item);
|
||||||
|
if (itemData.type == 'competence' && itemData.data.defaut_carac && itemData.data.xp) {
|
||||||
|
await this.checkCompetenceXP(itemData.name, itemData.data.xp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async onCreateItem(item, options, id) {
|
async onCreateItem(item, options, id) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
@ -3628,13 +3630,6 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPreUpdateItem(item, change, options, id) {
|
|
||||||
const itemData = Misc.data(item);
|
|
||||||
if (itemData.type == 'competence' && itemData.data.defaut_carac && itemData.data.xp) {
|
|
||||||
await this.checkCompetenceXP(itemData.name, itemData.data.xp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async onDeleteItem(item, options, id) {
|
async onDeleteItem(item, options, id) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'tete':
|
case 'tete':
|
||||||
@ -3650,27 +3645,30 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onCreateOwnedDraconique(item, options, id) {
|
async onCreateOwnedDraconique(item, options, id) {
|
||||||
|
if (Misc.isElectedUser()) {
|
||||||
let draconique = Draconique.all().find(it => it.match(item));
|
let draconique = Draconique.all().find(it => it.match(item));
|
||||||
if (draconique) {
|
if (draconique) {
|
||||||
draconique.onActorCreateOwned(this, item)
|
draconique.onActorCreateOwned(this, item)
|
||||||
|
this.notifyGestionTeteSouffleQueue(item, draconique.manualMessage());
|
||||||
this.notifyGestionTeteSouffleQueue(item, draconique.manualMessage());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onDeleteOwnedDraconique(item, options, id) {
|
async onDeleteOwnedDraconique(item, options, id) {
|
||||||
|
if (Misc.isElectedUser()) {
|
||||||
let draconique = Draconique.all().find(it => it.match(item));
|
let draconique = Draconique.all().find(it => it.match(item));
|
||||||
if (draconique) {
|
if (draconique) {
|
||||||
draconique.onActorDeleteOwned(this, item)
|
draconique.onActorDeleteOwned(this, item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onDeleteOwnedCaseTmr(item, options, id) {
|
async onDeleteOwnedCaseTmr(item, options, id) {
|
||||||
let draconique = Draconique.all().find(it => it.isCase(item));
|
if (Misc.isElectedUser()) {
|
||||||
if (draconique) {
|
let draconique = Draconique.all().find(it => it.isCase(item));
|
||||||
draconique.onActorDeleteCaseTmr(this, item)
|
if (draconique) {
|
||||||
|
draconique.onActorDeleteCaseTmr(this, item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ export class ChatUtility {
|
|||||||
static removeChatMessageContaining(part) {
|
static removeChatMessageContaining(part) {
|
||||||
const removeMessageData = {
|
const removeMessageData = {
|
||||||
part: part,
|
part: part,
|
||||||
gmId: Misc.connectedGM()
|
gmId: Misc.connectedGMOrUser()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (game.user.isGM) {
|
if (game.user.isGM) {
|
||||||
@ -41,7 +41,7 @@ export class ChatUtility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static removeChatMessageId(messageId) {
|
static removeChatMessageId(messageId) {
|
||||||
const removeMessageData = { messageId: messageId, gmId: Misc.connectedGM() };
|
const removeMessageData = { messageId: messageId, gmId: Misc.connectedGMOrUser() };
|
||||||
if (game.user.isGM) {
|
if (game.user.isGM) {
|
||||||
ChatUtility.onRemoveMessages(removeMessageData);
|
ChatUtility.onRemoveMessages(removeMessageData);
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,13 @@ export class Misc {
|
|||||||
return Misc.data(it)?.data ?? {}
|
return Misc.data(it)?.data ?? {}
|
||||||
}
|
}
|
||||||
|
|
||||||
static connectedGM() {
|
static connectedGMOrUser(ownerId = undefined) {
|
||||||
return game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id;
|
if (ownerId && game.user.id == ownerId){
|
||||||
|
return ownerId;
|
||||||
|
}
|
||||||
|
return (game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id) ?? game.user.id;
|
||||||
|
}
|
||||||
|
static isElectedUser() {
|
||||||
|
return game.user.id == Misc.connectedGMOrUser();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1211,7 +1211,7 @@ export class RdDCombat {
|
|||||||
attackerId: this.attackerId,
|
attackerId: this.attackerId,
|
||||||
defenderTokenId: defenderTokenId,
|
defenderTokenId: defenderTokenId,
|
||||||
attackerRoll: attackerRoll,
|
attackerRoll: attackerRoll,
|
||||||
gmId: Misc.connectedGM(),
|
gmId: Misc.connectedGMOrUser(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user