2020-06-07 23:16:50 +02:00
|
|
|
/**
|
|
|
|
* RdD system
|
|
|
|
* Author: LeRatierBretonnien
|
|
|
|
* Software License: GNU GPLv3
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
// Import Modules
|
|
|
|
import { RdDActor } from "./actor.js";
|
|
|
|
import { RdDItemSheet } from "./item-sheet.js";
|
|
|
|
import { RdDActorSheet } from "./actor-sheet.js";
|
2020-09-20 17:38:21 +02:00
|
|
|
import { RdDActorCreatureSheet } from "./actor-creature-sheet.js";
|
2021-01-10 22:12:07 +01:00
|
|
|
import { RdDActorVehiculeSheet } from "./actor-vehicule-sheet.js";
|
2020-11-14 23:24:01 +01:00
|
|
|
import { RdDActorEntiteSheet } from "./actor-entite-sheet.js";
|
2020-06-07 23:16:50 +02:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
2020-11-17 16:30:03 +01:00
|
|
|
import { TMRUtility } from "./tmr-utility.js";
|
2020-09-20 16:36:39 +02:00
|
|
|
import { RdDCalendrier } from "./rdd-calendrier.js";
|
2020-11-11 22:39:36 +01:00
|
|
|
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
2020-12-05 00:04:40 +01:00
|
|
|
import { RdDTokenHud } from "./rdd-token-hud.js";
|
2020-12-29 00:11:58 +01:00
|
|
|
import { RdDCommands } from "./rdd-commands.js";
|
2021-01-03 15:40:48 +01:00
|
|
|
import { RdDCombat } from "./rdd-combat.js";
|
2021-01-07 00:32:22 +01:00
|
|
|
import { ChatUtility } from "./chat-utility.js";
|
2021-01-08 22:23:50 +01:00
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
2021-01-13 03:42:13 +01:00
|
|
|
import { StatusEffects } from "./status-effects.js";
|
2020-06-07 23:16:50 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* Foundry VTT Initialization */
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2020-09-02 22:00:35 +02:00
|
|
|
/************************************************************************************/
|
|
|
|
const _patch_initiative = () => {
|
|
|
|
Combat.prototype.rollInitiative = async function (
|
|
|
|
ids,
|
2020-11-24 17:41:14 +01:00
|
|
|
formula = undefined,
|
2020-09-02 22:00:35 +02:00
|
|
|
messageOptions = {}
|
|
|
|
) {
|
|
|
|
console.log(
|
|
|
|
`${game.data.system.data.title} | Combat.rollInitiative()`,
|
|
|
|
ids,
|
|
|
|
formula,
|
|
|
|
messageOptions
|
|
|
|
);
|
|
|
|
// Structure input data
|
|
|
|
ids = typeof ids === "string" ? [ids] : ids;
|
|
|
|
const currentId = this.combatant._id;
|
|
|
|
// calculate initiative
|
2021-01-10 00:30:37 +01:00
|
|
|
for (let cId = 0; cId < ids.length; cId++) {
|
|
|
|
const c = this.getCombatant(ids[cId]);
|
2020-09-02 22:00:35 +02:00
|
|
|
//if (!c) return results;
|
2020-11-24 17:41:14 +01:00
|
|
|
|
|
|
|
let rollFormula = formula; // Init per default
|
2021-01-10 00:30:37 +01:00
|
|
|
if (!rollFormula) {
|
2020-11-24 17:41:14 +01:00
|
|
|
let armeCombat, competence;
|
2021-01-10 00:30:37 +01:00
|
|
|
if (c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
|
2020-11-24 17:41:14 +01:00
|
|
|
for (const competenceItem of c.actor.data.items) {
|
2021-01-10 00:30:37 +01:00
|
|
|
if (competenceItem.data.iscombat) {
|
2020-11-24 17:41:14 +01:00
|
|
|
competence = duplicate(competenceItem);
|
|
|
|
}
|
2020-11-16 21:18:18 +01:00
|
|
|
}
|
2021-01-13 11:35:36 +01:00
|
|
|
rollFormula = "2+( ("+RdDUtility.calculInitiative(competence.data.niveau, competence.data.carac_value)+")/100)";
|
2020-11-24 17:41:14 +01:00
|
|
|
} else {
|
|
|
|
for (const item of c.actor.data.items) {
|
|
|
|
if (item.type == "arme" && item.data.equipe) {
|
|
|
|
armeCombat = duplicate(item);
|
|
|
|
}
|
2020-11-16 21:18:18 +01:00
|
|
|
}
|
2021-01-10 00:30:37 +01:00
|
|
|
let compName = (armeCombat == undefined) ? "Corps à corps" : armeCombat.data.competence;
|
|
|
|
competence = RdDItemCompetence.findCompetence(c.actor.data.items, compName);
|
2021-01-13 11:35:36 +01:00
|
|
|
rollFormula = "2+( ("+RdDUtility.calculInitiative(competence.data.niveau, c.actor.data.data.carac[competence.data.defaut_carac].value) + ")/100)";
|
2020-11-16 21:18:18 +01:00
|
|
|
}
|
2020-09-02 22:00:35 +02:00
|
|
|
}
|
|
|
|
//console.log("Combatat", c);
|
|
|
|
const roll = this._getInitiativeRoll(c, rollFormula);
|
2021-01-13 11:35:36 +01:00
|
|
|
if (roll.total <= 0) roll.total = 0.00;
|
|
|
|
console.log("Compute init for", rollFormula, roll.total);
|
2021-01-10 00:30:37 +01:00
|
|
|
await this.updateEmbeddedEntity("Combatant", { _id: c._id, initiative: roll.total });
|
|
|
|
|
2020-09-02 22:00:35 +02:00
|
|
|
// Send a chat message
|
2020-12-05 00:04:40 +01:00
|
|
|
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
|
2020-09-02 22:00:35 +02:00
|
|
|
let messageData = mergeObject(
|
|
|
|
{
|
|
|
|
speaker: {
|
|
|
|
scene: canvas.scene._id,
|
|
|
|
actor: c.actor ? c.actor._id : null,
|
|
|
|
token: c.token._id,
|
|
|
|
alias: c.token.name,
|
|
|
|
sound: CONFIG.sounds.dice,
|
|
|
|
},
|
2020-11-24 17:41:14 +01:00
|
|
|
flavor: `${c.token.name} a fait son jet d'Initiative`,
|
2020-09-02 22:00:35 +02:00
|
|
|
},
|
|
|
|
messageOptions
|
|
|
|
);
|
|
|
|
roll.toMessage(messageData, { rollMode, create: true });
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************************/
|
2021-01-10 00:30:37 +01:00
|
|
|
Hooks.once("init", async function () {
|
2020-06-07 23:16:50 +02:00
|
|
|
console.log(`Initializing Reve de Dragon System`);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
2020-06-07 23:16:50 +02:00
|
|
|
// preload handlebars templates
|
|
|
|
RdDUtility.preloadHandlebarsTemplates();
|
2020-11-12 23:50:37 +01:00
|
|
|
// Create useful storage space
|
2021-01-13 03:42:13 +01:00
|
|
|
game.system.rdd = { TMRUtility: TMRUtility }
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2021-01-10 00:30:37 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-01 17:36:13 +01:00
|
|
|
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",
|
|
|
|
scope: "world",
|
|
|
|
config: true,
|
|
|
|
type: String,
|
|
|
|
choices: { // If choices are defined, the resulting setting will be a select menu
|
|
|
|
"avant-attaque": "Avant l'attaque",
|
|
|
|
"avant-defense": "Avant la défense",
|
|
|
|
"avant-encaissement": "Avant l'encaissement",
|
|
|
|
},
|
|
|
|
default: "avant-encaissement"
|
|
|
|
});
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "calendrier", {
|
2021-01-10 00:30:37 +01:00
|
|
|
name: "calendrier",
|
2020-12-12 21:58:44 +01:00
|
|
|
scope: "world",
|
|
|
|
config: false,
|
|
|
|
type: Object
|
|
|
|
});
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 23:12:43 +01:00
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "liste-nombre-astral", {
|
2021-01-10 00:30:37 +01:00
|
|
|
name: "liste-nombre-astral",
|
2020-12-08 23:12:43 +01:00
|
|
|
scope: "world",
|
|
|
|
config: false,
|
|
|
|
type: Object
|
2020-12-12 21:58:44 +01:00
|
|
|
});
|
|
|
|
|
2020-12-08 23:12:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 21:40:41 +01:00
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "calendrier-pos", {
|
2021-01-10 00:30:37 +01:00
|
|
|
name: "calendrierPos",
|
2020-12-08 21:40:41 +01:00
|
|
|
scope: "world",
|
|
|
|
config: false,
|
|
|
|
type: Object
|
2020-12-12 21:58:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-11-17 11:35:05 +01:00
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "dice-so-nice", {
|
|
|
|
name: "Montrer les dés pour toutes les jets",
|
|
|
|
hint: "Utilise Dice So Nice pour tous les jets de dés possibles. Décocher pour limiter à la table de résolution",
|
|
|
|
scope: "client",
|
|
|
|
config: true,
|
|
|
|
default: false,
|
|
|
|
type: Boolean
|
2021-01-10 00:30:37 +01:00
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat", {
|
|
|
|
name: "Supprimer les dialogues de combat",
|
|
|
|
hint: "Si désactivée, tous les dialogues de combat sont conservés dans la conversation",
|
|
|
|
scope: "world",
|
|
|
|
config: true,
|
|
|
|
default: true,
|
|
|
|
type: Boolean
|
2021-01-10 00:30:37 +01:00
|
|
|
});
|
2021-01-12 20:58:30 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "activer-sons-audio", {
|
|
|
|
name: "Activer les bruitages intégrés",
|
|
|
|
hint: "Si activé, certaines actions en jeu déclenchent un son d'ambiance",
|
|
|
|
scope: "world",
|
|
|
|
config: true,
|
|
|
|
default: true,
|
|
|
|
type: Boolean
|
|
|
|
});
|
2021-01-10 00:30:37 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-01-10 00:30:37 +01:00
|
|
|
// Set an initiative formula for the system
|
|
|
|
CONFIG.Combat.initiative = {
|
2021-01-13 11:35:36 +01:00
|
|
|
formula: "1+(1d6/10)",
|
|
|
|
decimals: 2
|
2020-06-07 23:16:50 +02:00
|
|
|
};
|
2021-01-10 00:30:37 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-06-17 20:31:43 +02:00
|
|
|
game.socket.on("system.foundryvtt-reve-de-dragon", data => {
|
2021-01-10 00:30:37 +01:00
|
|
|
RdDUtility.onSocketMesssage(data);
|
|
|
|
RdDCombat.onSocketMessage(data);
|
2021-01-20 00:44:19 +01:00
|
|
|
ChatUtility.onSocketMessage(data);
|
2020-06-17 20:31:43 +02:00
|
|
|
});
|
2020-06-07 23:16:50 +02:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-01-10 00:30:37 +01:00
|
|
|
// Define custom Entity classes
|
2020-06-07 23:16:50 +02:00
|
|
|
CONFIG.Actor.entityClass = RdDActor;
|
2021-01-10 00:30:37 +01:00
|
|
|
CONFIG.RDD = {
|
|
|
|
resolutionTable: RdDResolutionTable.resolutionTable,
|
|
|
|
carac_array: RdDUtility.getCaracArray(),
|
|
|
|
ajustementsConditions: RdDUtility.getAjustementsConditions(),
|
|
|
|
difficultesLibres: RdDUtility.getDifficultesLibres()
|
2020-11-11 22:39:36 +01:00
|
|
|
}
|
2021-01-10 00:30:37 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-06-07 23:16:50 +02:00
|
|
|
// Register sheet application classes
|
|
|
|
Actors.unregisterSheet("core", ActorSheet);
|
2021-01-13 03:42:13 +01:00
|
|
|
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorSheet, { types: ["personnage"], makeDefault: true });
|
|
|
|
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorCreatureSheet, { types: ["creature"], makeDefault: true });
|
|
|
|
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorVehiculeSheet, { types: ["vehicule"], makeDefault: true });
|
|
|
|
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorEntiteSheet, { types: ["entite"], makeDefault: true });
|
2020-06-07 23:16:50 +02:00
|
|
|
Items.unregisterSheet("core", ItemSheet);
|
2021-01-10 00:30:37 +01:00
|
|
|
Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, { makeDefault: true });
|
2020-09-02 22:00:35 +02:00
|
|
|
|
2020-11-12 14:43:08 +01:00
|
|
|
// Handlebar function pour container
|
|
|
|
Handlebars.registerHelper('buildConteneur', (objet) => { return RdDUtility.buildConteneur(objet); });
|
|
|
|
|
2020-09-02 22:00:35 +02:00
|
|
|
// Patch the initiative formula
|
|
|
|
_patch_initiative();
|
2021-01-10 00:30:37 +01:00
|
|
|
|
|
|
|
// préparation des différents modules
|
|
|
|
RdDCommands.init();
|
|
|
|
RdDCombat.init();
|
|
|
|
RdDTokenHud.init();
|
2021-01-13 03:42:13 +01:00
|
|
|
RdDActor.init();
|
|
|
|
StatusEffects.init();
|
2020-07-21 23:51:24 +02:00
|
|
|
});
|
|
|
|
|
2020-12-04 10:15:55 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-01-10 00:30:37 +01:00
|
|
|
function messageDeBienvenue() {
|
2021-01-20 00:44:19 +01:00
|
|
|
if (game.user.isGM) {
|
|
|
|
ChatUtility.removeChatMessageContaining('<div id="message-bienvenue-rdd">');
|
|
|
|
ChatMessage.create({
|
|
|
|
user: 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>
|
|
|
|
` });
|
|
|
|
}
|
2020-11-23 19:51:34 +01:00
|
|
|
}
|
|
|
|
|
2020-07-24 10:51:11 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* Foundry VTT Initialization */
|
|
|
|
/* -------------------------------------------- */
|
2021-01-10 00:30:37 +01:00
|
|
|
Hooks.once("ready", function () {
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* Affiche/Init le calendrier */
|
|
|
|
let calendrier = new RdDCalendrier();
|
|
|
|
calendrier.initCalendrier();
|
|
|
|
let templatePath = "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html";
|
|
|
|
let templateData = {};
|
|
|
|
renderTemplate(templatePath, templateData).then(html => {
|
2020-09-20 16:36:39 +02:00
|
|
|
calendrier.render(true);
|
2021-01-10 00:30:37 +01:00
|
|
|
});
|
2020-12-08 21:40:41 +01:00
|
|
|
game.system.rdd.calendrier = calendrier; // Reference;
|
|
|
|
|
2020-12-04 10:15:55 +01:00
|
|
|
// Avertissement si joueur sans personnage
|
2021-01-10 00:30:37 +01:00
|
|
|
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") ] } );
|
2020-12-04 10:15:55 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 00:30:37 +01:00
|
|
|
messageDeBienvenue();
|
2020-09-20 16:36:39 +02:00
|
|
|
});
|
2020-07-24 10:51:11 +02:00
|
|
|
|
2020-07-21 23:51:24 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* Foundry VTT Initialization */
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
Hooks.on("chatMessage", (html, content, msg) => {
|
2020-12-29 00:11:58 +01:00
|
|
|
if (content[0] == '/') {
|
|
|
|
let regExp = /(\S+)/g;
|
|
|
|
let commands = content.toLowerCase().match(regExp);
|
2021-01-10 00:30:37 +01:00
|
|
|
if (game.system.rdd.commands.processChatCommand(commands, content, msg)) {
|
2020-12-29 00:11:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2020-11-24 16:41:15 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
|
2021-01-10 00:30:37 +01:00
|
|
|
RdDUtility.pushInitiativeOptions(html, options);
|
2020-11-24 16:41:15 +01:00
|
|
|
})
|