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