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

Empêcher doublons sur tête/souffle #175

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!204
This commit is contained in:
Leratier Bretonnien 2021-04-16 21:39:57 +00:00
commit afe8e5067a
4 changed files with 64 additions and 60 deletions

View File

@ -55,27 +55,21 @@ export class RdDActor extends Actor {
}
}
static remoteActorCall(actorId, method, ...args) {
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_remote_actor_call",
data: {
gmId: Misc.connectedGM(),
toActorId: actorId,
method: method,
args: args
}
});
static remoteActorCall(options) {
console.log("remoteActorCall ", options)
options.userId = options.userId ?? Misc.connectedGMOrUser();
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: options });
}
static onRemoteActorCall(data) {
if (game.user.id == data.gmId) { // Seul le GM connecté choisi effectue l'appel
const actor = game.actors.get(data?.toActorId);
if (game.user.id == data.userId) { // Seul le joueur choisi effectue l'appel
const actor = game.actors.get(data?.actorId);
if (!actor) {
console.info("RdDActor.onRemoteActorCall: Pas d'Actor disponible ", data);
}
else {
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);
}
}
@ -3185,7 +3179,7 @@ export class RdDActor extends Actor {
async ajouterDeniers(gain, fromActorId = undefined) {
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 {
const fromActor = game.actors.get(fromActorId)
@ -3616,6 +3610,14 @@ export class RdDActor extends Actor {
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) {
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) {
switch (item.type) {
case 'tete':
@ -3650,29 +3645,32 @@ export class RdDActor extends Actor {
}
async onCreateOwnedDraconique(item, options, id) {
if (Misc.isElectedUser()) {
let draconique = Draconique.all().find(it => it.match(item));
if (draconique) {
draconique.onActorCreateOwned(this, item)
this.notifyGestionTeteSouffleQueue(item, draconique.manualMessage());
}
}
}
async onDeleteOwnedDraconique(item, options, id) {
if (Misc.isElectedUser()) {
let draconique = Draconique.all().find(it => it.match(item));
if (draconique) {
draconique.onActorDeleteOwned(this, item)
}
}
}
async onDeleteOwnedCaseTmr(item, options, id) {
if (Misc.isElectedUser()) {
let draconique = Draconique.all().find(it => it.isCase(item));
if (draconique) {
draconique.onActorDeleteCaseTmr(this, item)
}
}
}
notifyGestionTeteSouffleQueue(item, manualMessage = true) {
ChatMessage.create({

View File

@ -29,7 +29,7 @@ export class ChatUtility {
static removeChatMessageContaining(part) {
const removeMessageData = {
part: part,
gmId: Misc.connectedGM()
gmId: Misc.connectedGMOrUser()
};
if (game.user.isGM) {
@ -41,7 +41,7 @@ export class ChatUtility {
}
static removeChatMessageId(messageId) {
const removeMessageData = { messageId: messageId, gmId: Misc.connectedGM() };
const removeMessageData = { messageId: messageId, gmId: Misc.connectedGMOrUser() };
if (game.user.isGM) {
ChatUtility.onRemoveMessages(removeMessageData);
}

View File

@ -114,7 +114,13 @@ export class Misc {
return Misc.data(it)?.data ?? {}
}
static connectedGM() {
return game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id;
static connectedGMOrUser(ownerId = undefined) {
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();
}
}

View File

@ -75,36 +75,36 @@ export class RdDCombatManager extends Combat {
const currentId = this.combatant._id;
// calculate initiative
for (let cId = 0; cId < ids.length; cId++) {
const c = this.getCombatant(ids[cId]);
const combatant = this.getCombatant(ids[cId]);
//if (!c) return results;
let rollFormula = formula; // Init per default
if (!rollFormula) {
let armeCombat, competence;
if (c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
for (const competenceItemData of c.actor.data.items) {
if (combatant.actor.data.type == 'creature' || combatant.actor.data.type == 'entite') {
for (const competenceItemData of combatant.actor.data.items) {
if (competenceItemData.data.iscombat) {
competence = duplicate(competenceItemData);
}
}
rollFormula = "2+( (" + RdDCombatManager.calculInitiative(competence.data.niveau, competence.data.carac_value) + ")/100)";
} else {
for (const itemData of c.actor.data.items) {
for (const itemData of combatant.actor.data.items) {
if (itemData.type == "arme" && itemData.data.equipe) {
armeCombat = duplicate(itemData);
}
}
let compName = (armeCombat == undefined) ? "Corps à corps" : armeCombat.data.competence;
competence = RdDItemCompetence.findCompetence(c.actor.data.items, compName);
competence = RdDItemCompetence.findCompetence(combatant.actor.data.items, compName);
let bonusEcaille = (armeCombat && armeCombat.data.magique) ? armeCombat.data.ecaille_efficacite : 0;
rollFormula = "2+( (" + RdDCombatManager.calculInitiative(competence.data.niveau, Misc.data(c.actor).data.carac[competence.data.defaut_carac].value, bonusEcaille) + ")/100)";
rollFormula = "2+( (" + RdDCombatManager.calculInitiative(competence.data.niveau, Misc.data(combatant.actor).data.carac[competence.data.defaut_carac].value, bonusEcaille) + ")/100)";
}
}
//console.log("Combatat", c);
const roll = super._getInitiativeRoll(c, rollFormula);
const roll = combatant.getInitiativeRoll(rollFormula);
if (roll.total <= 0) roll.total = 0.00;
console.log("Compute init for", rollFormula, roll.total);
await this.updateEmbeddedDocuments("Combatant", [{ _id: c._id, initiative: roll.total }]);
await this.updateEmbeddedDocuments("Combatant", [{ _id: combatant._id, initiative: roll.total }]);
// Send a chat message
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
@ -112,12 +112,12 @@ export class RdDCombatManager extends Combat {
{
speaker: {
scene: canvas.scene._id,
actor: c.actor ? c.actor._id : null,
token: c.token._id,
alias: c.token.name,
actor: combatant.actor ? combatant.actor._id : null,
token: combatant.token._id,
alias: combatant.token.name,
sound: CONFIG.sounds.dice,
},
flavor: `${c.token.name} a fait son jet d'Initiative (${messageOptions.initInfo})
flavor: `${combatant.token.name} a fait son jet d'Initiative (${messageOptions.initInfo})
<br>
`,
},
@ -266,7 +266,7 @@ export class RdDCombatManager extends Combat {
let initOffset = 0;
let caracForInit = 0;
let compNiveau = 0;
let competence = { name: "Aucune" };
let compData = { name: "Aucune" };
if (combatant.actor.getSurprise() == "totale") {
initOffset = -1; // To force 0
initInfo = "Surprise Totale"
@ -281,24 +281,24 @@ export class RdDCombatManager extends Combat {
initInfo = "Draconic"
} else {
initOffset = 3; // Melée = 3.XX
competence = RdDItemCompetence.findCompetence(combatant.actor.data.items, arme.data.competence);
compNiveau = competence.data.niveau;
compData = Misc.data(RdDItemCompetence.findCompetence(combatant.actor.data.items, arme.data.competence));
compNiveau = compData.data.niveau;
initInfo = arme.name + " / " + arme.data.competence;
if (combatant.actor.data.type == 'creature' || combatant.actor.data.type == 'entite') {
caracForInit = competence.data.carac_value;
if (competence.data.categorie == "lancer") {
caracForInit = compData.data.carac_value;
if (compData.data.categorie == "lancer") {
initOffset = 5;
}
} else {
caracForInit = Misc.data(combatant.actor).data.carac[competence.data.defaut_carac].value;
if (competence.data.categorie == "lancer") { // Offset de principe pour les armes de jet
caracForInit = Misc.data(combatant.actor).data.carac[compData.data.defaut_carac].value;
if (compData.data.categorie == "lancer") { // Offset de principe pour les armes de jet
initOffset = 4;
}
if (competence.data.categorie == "tir") { // Offset de principe pour les armes de jet
if (compData.data.categorie == "tir") { // Offset de principe pour les armes de jet
initOffset = 5;
}
if (competence.data.categorie == "melee") { // Offset de principe pour les armes de jet
if (compData.data.categorie == "melee") { // Offset de principe pour les armes de jet
initOffset = 3;
}
}
@ -1211,7 +1211,7 @@ export class RdDCombat {
attackerId: this.attackerId,
defenderTokenId: defenderTokenId,
attackerRoll: attackerRoll,
gmId: Misc.connectedGM(),
gmId: Misc.connectedGMOrUser(),
}
});
}