Améliorations du combat
- nettoyage des infos et messages de combat améliorés - message de status envoyé uniquement par le GM (pour éviter les doublons) - stockage des infos de passes d'armes géré par RdDCombat Déplacement des Hooks/notifications de messages socket: - liés au combat dans la méthode RdDCombat.init Convention de nommage: les méthodes de gestion de notification par hook/socket sont préfixées 'on' ex: onSocketMessage, onUpdateCombat, onPreDeleteCombat
This commit is contained in:
@ -45,16 +45,16 @@ const _patch_initiative = () => {
|
||||
ids = typeof ids === "string" ? [ids] : ids;
|
||||
const currentId = this.combatant._id;
|
||||
// calculate initiative
|
||||
for ( let cId = 0; cId < ids.length; cId++) {
|
||||
const c = this.getCombatant( ids[cId] );
|
||||
for (let cId = 0; cId < ids.length; cId++) {
|
||||
const c = this.getCombatant(ids[cId]);
|
||||
//if (!c) return results;
|
||||
|
||||
let rollFormula = formula; // Init per default
|
||||
if ( !rollFormula ) {
|
||||
if (!rollFormula) {
|
||||
let armeCombat, competence;
|
||||
if ( c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
|
||||
if (c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
|
||||
for (const competenceItem of c.actor.data.items) {
|
||||
if ( competenceItem.data.iscombat) {
|
||||
if (competenceItem.data.iscombat) {
|
||||
competence = duplicate(competenceItem);
|
||||
}
|
||||
}
|
||||
@ -65,17 +65,17 @@ const _patch_initiative = () => {
|
||||
armeCombat = duplicate(item);
|
||||
}
|
||||
}
|
||||
let compName = ( armeCombat == undefined ) ? "Corps à corps" : armeCombat.data.competence;
|
||||
competence = RdDItemCompetence.findCompetence( c.actor.data.items, compName );
|
||||
rollFormula = RdDUtility.calculInitiative(competence.data.niveau, c.actor.data.data.carac[competence.data.defaut_carac].value);
|
||||
let compName = (armeCombat == undefined) ? "Corps à corps" : armeCombat.data.competence;
|
||||
competence = RdDItemCompetence.findCompetence(c.actor.data.items, compName);
|
||||
rollFormula = RdDUtility.calculInitiative(competence.data.niveau, c.actor.data.data.carac[competence.data.defaut_carac].value);
|
||||
}
|
||||
}
|
||||
//console.log("Combatat", c);
|
||||
const roll = this._getInitiativeRoll(c, rollFormula);
|
||||
if ( roll.total <= 0 ) roll.total = 1;
|
||||
if (roll.total <= 0) roll.total = 1;
|
||||
//console.log("Compute init for", armeCombat, competence, rollFormula, roll.total);
|
||||
await this.updateEmbeddedEntity("Combatant", { _id: c._id, initiative: roll.total });
|
||||
|
||||
await this.updateEmbeddedEntity("Combatant", { _id: c._id, initiative: roll.total });
|
||||
|
||||
// Send a chat message
|
||||
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
|
||||
let messageData = mergeObject(
|
||||
@ -98,22 +98,17 @@ const _patch_initiative = () => {
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
Hooks.once("init", async function() {
|
||||
Hooks.once("init", async function () {
|
||||
console.log(`Initializing Reve de Dragon System`);
|
||||
|
||||
|
||||
// preload handlebars templates
|
||||
RdDUtility.preloadHandlebarsTemplates();
|
||||
|
||||
// Create useful storage space
|
||||
game.system.rdd = {
|
||||
rollDataHandler: {
|
||||
attaques: {},
|
||||
defenses: {}
|
||||
},
|
||||
TMRUtility: TMRUtility
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register("foundryvtt-reve-de-dragon", "accorder-entite-cauchemar", {
|
||||
name: "Accorder le rêve aux entités",
|
||||
hint: "A quel moment les personnages doivent accorder leur rêve aux entités de cauchemar",
|
||||
@ -130,7 +125,7 @@ Hooks.once("init", async function() {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register("foundryvtt-reve-de-dragon", "calendrier", {
|
||||
name: "calendrier",
|
||||
name: "calendrier",
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Object
|
||||
@ -138,7 +133,7 @@ Hooks.once("init", async function() {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register("foundryvtt-reve-de-dragon", "liste-nombre-astral", {
|
||||
name: "liste-nombre-astral",
|
||||
name: "liste-nombre-astral",
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Object
|
||||
@ -146,7 +141,7 @@ Hooks.once("init", async function() {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register("foundryvtt-reve-de-dragon", "calendrier-pos", {
|
||||
name: "calendrierPos",
|
||||
name: "calendrierPos",
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Object
|
||||
@ -160,7 +155,7 @@ Hooks.once("init", async function() {
|
||||
config: true,
|
||||
default: false,
|
||||
type: Boolean
|
||||
});
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat", {
|
||||
@ -170,7 +165,7 @@ Hooks.once("init", async function() {
|
||||
config: true,
|
||||
default: true,
|
||||
type: Boolean
|
||||
});
|
||||
});
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register("foundryvtt-reve-de-dragon", "activer-sons-audio", {
|
||||
name: "Activer les bruitages intégrés",
|
||||
@ -180,37 +175,39 @@ Hooks.once("init", async function() {
|
||||
default: true,
|
||||
type: Boolean
|
||||
});
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Set an initiative formula for the system
|
||||
CONFIG.Combat.initiative = {
|
||||
formula: "1d20",
|
||||
// Set an initiative formula for the system
|
||||
CONFIG.Combat.initiative = {
|
||||
formula: "1d20",
|
||||
decimals: 2
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.socket.on("system.foundryvtt-reve-de-dragon", data => {
|
||||
RdDUtility.performSocketMesssage( data );
|
||||
RdDUtility.onSocketMesssage(data);
|
||||
RdDCombat.onSocketMessage(data);
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Define custom Entity classes
|
||||
// Define custom Entity classes
|
||||
CONFIG.Actor.entityClass = RdDActor;
|
||||
CONFIG.RDD = {
|
||||
resolutionTable : RdDResolutionTable.resolutionTable,
|
||||
carac_array : RdDUtility.getCaracArray(),
|
||||
ajustementsConditions : RdDUtility.getAjustementsConditions(),
|
||||
difficultesLibres : RdDUtility.getDifficultesLibres()
|
||||
CONFIG.RDD = {
|
||||
resolutionTable: RdDResolutionTable.resolutionTable,
|
||||
carac_array: RdDUtility.getCaracArray(),
|
||||
ajustementsConditions: RdDUtility.getAjustementsConditions(),
|
||||
difficultesLibres: RdDUtility.getDifficultesLibres()
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Register sheet application classes
|
||||
Actors.unregisterSheet("core", ActorSheet);
|
||||
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorSheet, {
|
||||
types: ["personnage"],
|
||||
makeDefault: true }
|
||||
types: ["personnage"],
|
||||
makeDefault: true
|
||||
}
|
||||
);
|
||||
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorCreatureSheet, {
|
||||
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorCreatureSheet, {
|
||||
types: ["creature"],
|
||||
makeDefault: true
|
||||
});
|
||||
@ -218,44 +215,41 @@ Hooks.once("init", async function() {
|
||||
types: ["vehicule"],
|
||||
makeDefault: true
|
||||
});
|
||||
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorEntiteSheet, {
|
||||
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorEntiteSheet, {
|
||||
types: ["entite"],
|
||||
makeDefault: true
|
||||
});
|
||||
Items.unregisterSheet("core", ItemSheet);
|
||||
Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, {makeDefault: true});
|
||||
Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, { makeDefault: true });
|
||||
|
||||
// Handlebar function pour container
|
||||
Handlebars.registerHelper('buildConteneur', (objet) => { return RdDUtility.buildConteneur(objet); });
|
||||
|
||||
// Patch the initiative formula
|
||||
_patch_initiative();
|
||||
|
||||
// préparation des différents modules
|
||||
RdDCommands.init();
|
||||
RdDCombat.init();
|
||||
RdDTokenHud.init();
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
function messageDeBienvenue(){
|
||||
function messageDeBienvenue() {
|
||||
ChatUtility.removeMyChatMessageContaining('<div id="message-bienvenue-rdd">');
|
||||
ChatMessage.create( {
|
||||
ChatMessage.create({
|
||||
user: game.user._id,
|
||||
whisper: [game.user._id],
|
||||
content : `<div id="message-bienvenue-rdd"><span class="rdd-roll-part">Bienvenue dans le Rêve des Dragons !</span>
|
||||
whisper: [game.user._id],
|
||||
content: `<div id="message-bienvenue-rdd"><span class="rdd-roll-part">Bienvenue dans le Rêve des Dragons !</span>
|
||||
<br>Vous trouverez quelques informations pour démarrer dans ce document : @Compendium[foundryvtt-reve-de-dragon.rappel-des-regles.7uGrUHGdPu0EmIu2]{Documentation MJ/Joueurs}
|
||||
<br>La commande <code>/aide</code> dans le chat permet de voir les commandes spécifiques à Rêve de Dragon.</div>
|
||||
` });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
Hooks.once("renderApplication", () => {
|
||||
messageDeBienvenue();
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
/* -------------------------------------------- */
|
||||
Hooks.once("ready", function() {
|
||||
|
||||
// préparation des lignes de commandes
|
||||
RdDCommands.init();
|
||||
Hooks.once("ready", function () {
|
||||
/* -------------------------------------------- */
|
||||
/* Affiche/Init le calendrier */
|
||||
let calendrier = new RdDCalendrier();
|
||||
@ -264,20 +258,20 @@ Hooks.once("ready", function() {
|
||||
let templateData = {};
|
||||
renderTemplate(templatePath, templateData).then(html => {
|
||||
calendrier.render(true);
|
||||
} );
|
||||
});
|
||||
game.system.rdd.calendrier = calendrier; // Reference;
|
||||
|
||||
// Avertissement si joueur sans personnage
|
||||
if ( !game.user.isGM && game.user.character == undefined) {
|
||||
ui.notifications.info( "Attention ! Vous n'êtes connecté à aucun personnage !" );
|
||||
ChatMessage.create( { content:"<b>ATTENTION</b> Le joueur " + game.user.name + " n'est connecté à aucun personnage !",
|
||||
user: game.user._id } );
|
||||
//whisper: [ ChatMessage.getWhisperRecipients("GM") ] } );
|
||||
if (!game.user.isGM && game.user.character == undefined) {
|
||||
ui.notifications.info("Attention ! Vous n'êtes connecté à aucun personnage !");
|
||||
ChatMessage.create({
|
||||
content: "<b>ATTENTION</b> Le joueur " + game.user.name + " n'est connecté à aucun personnage !",
|
||||
user: game.user._id
|
||||
});
|
||||
//whisper: [ ChatMessage.getWhisperRecipients("GM") ] } );
|
||||
}
|
||||
|
||||
// Integration du TokenHUD
|
||||
Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data._id) });
|
||||
Hooks.on("updateCombat", (combat, data) => { RdDCombat.updateCombatRound(combat, data) } );
|
||||
messageDeBienvenue();
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -287,7 +281,7 @@ Hooks.on("chatMessage", (html, content, msg) => {
|
||||
if (content[0] == '/') {
|
||||
let regExp = /(\S+)/g;
|
||||
let commands = content.toLowerCase().match(regExp);
|
||||
if (game.system.rdd.commands.processChatCommand(commands, content, msg)){
|
||||
if (game.system.rdd.commands.processChatCommand(commands, content, msg)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -296,5 +290,5 @@ Hooks.on("chatMessage", (html, content, msg) => {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
|
||||
RdDUtility.pushInitiativeOptions( html, options );
|
||||
RdDUtility.pushInitiativeOptions(html, options);
|
||||
})
|
||||
|
Reference in New Issue
Block a user