foundryvtt-reve-de-dragon/module/rdd-main.js

341 lines
13 KiB
JavaScript
Raw Normal View History

2022-01-29 22:49:34 +01:00
import { SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js";
2020-06-07 23:16:50 +02:00
import { RdDActor } from "./actor.js";
import { RdDItem } from "./item.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";
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-02-09 09:18:52 +01:00
import { RdDCombatManager, RdDCombat } from "./rdd-combat.js";
import { ChatUtility } from "./chat-utility.js";
2022-11-06 21:39:03 +01:00
import { StatusEffects } from "./settings/status-effects.js";
2021-01-26 00:25:41 +01:00
import { RddCompendiumOrganiser } from "./rdd-compendium-organiser.js";
2022-11-06 21:39:03 +01:00
import { ReglesOptionelles } from "./settings/regles-optionelles.js";
import { RdDHotbar } from "./rdd-hotbar-drop.js"
import { EffetsDraconiques } from "./tmr/effets-draconiques.js";
2021-04-04 18:37:16 +02:00
import { RdDHerbes } from "./rdd-herbes.js";
2021-04-29 02:57:56 +02:00
import { RdDDice } from "./rdd-dice.js";
2021-11-11 09:18:25 +01:00
import { RdDPossession } from "./rdd-possession.js";
import { Misc } from "./misc.js";
2022-09-17 16:07:38 +02:00
import { Migrations } from './migrations.js';
2022-11-04 20:41:16 +01:00
import { DialogChronologie } from "./dialog-chronologie.js";
2022-11-06 21:39:47 +01:00
import { SystemCompendiums } from "./settings/system-compendiums.js";
import { Environnement } from "./environnement.js";
import { RdDItemService } from "./item/item-service.js";
2022-12-28 23:36:48 +01:00
import { RdDBaseActor } from "./actor/base-actor.js";
2023-01-01 22:21:30 +01:00
import { RdDCommerceSheet } from "./actor/commerce-sheet.js";
import { RdDCommerce } from "./actor/commerce.js";
import { RdDTimestamp } from "./rdd-timestamp.js";
import { RdDItemMaladie } from "./item/maladie.js";
import { RdDItemPoison } from "./item/poison.js";
import { RdDItemSigneDraconique } from "./item/item-signedraconique.js";
import { RdDItemQueue } from "./item/queue.js";
import { RdDItemOmbre } from "./item/ombre.js";
import { RdDItemSouffle } from "./item/souffle.js";
import { RdDRencontre } from "./item/item-rencontre.js";
import { RdDActorSheet } from "./actor-sheet.js";
import { RdDActorCreatureSheet } from "./actor-creature-sheet.js";
import { RdDActorVehiculeSheet } from "./actor-vehicule-sheet.js";
import { RdDActorEntiteSheet } from "./actor-entite-sheet.js";
import { RdDItemSheet } from "./item-sheet.js";
import { RdDServiceItemSheet } from "./item-service-sheet.js";
import { RdDHerbeItemSheet } from "./item-herbe-sheet.js";
import { RdDRencontreItemSheet } from "./item-rencontre-sheet.js";
2023-01-14 01:15:15 +01:00
import { RdDPlanteItemSheet } from "./item-plante-sheet.js";
import { RdDIngredientItemSheet } from "./item-ingredient-sheet.js";
import { RdDFauneItemSheet } from "./item-faune-sheet.js";
import { RdDConteneurItemSheet } from "./item-conteneur-sheet.js";
import { RdDSigneDraconiqueItemSheet } from "./item-signedraconique-sheet.js";
import { TMRRencontres } from "./tmr-rencontres.js";
import { FenetreRechercheTirage } from "./tirage/fenetre-recherche-tirage.js";
2020-06-07 23:16:50 +02:00
/**
* RdD system
* Author: LeRatierBretonnien
* Software License: GNU GPLv3
*/
export class SystemReveDeDragon {
static start() {
const system = new SystemReveDeDragon();
Hooks.once('init', async () => await system.onInit());
Hooks.once('diceSoNiceReady', (dice3d) => RdDDice.diceSoNiceReady(dice3d));
}
2020-12-08 21:40:41 +01:00
constructor() {
this.RdDUtility = RdDUtility;
this.RdDHotbar = RdDHotbar;
2022-12-23 00:22:13 +01:00
this.itemClasses = {
service: RdDItemService,
maladie: RdDItemMaladie,
poison: RdDItemPoison,
queue: RdDItemQueue,
ombre: RdDItemOmbre,
souffle: RdDItemSouffle,
signedraconique: RdDItemSigneDraconique,
rencontre: RdDRencontre
2022-12-23 00:22:13 +01:00
}
this.actorClasses = {
2022-12-28 23:36:48 +01:00
creature: RdDActor,
entite: RdDActor,
personnage: RdDActor,
vehicule: RdDActor,
2023-01-01 22:21:30 +01:00
commerce: RdDCommerce,
2022-12-23 00:22:13 +01:00
}
}
2022-11-04 20:41:16 +01:00
/* -------------------------------------------- */
/* Foundry VTT Initialization */
2021-01-12 20:58:30 +01:00
/* -------------------------------------------- */
async onInit() {
game.system.rdd = this;
console.log(`Initializing Reve de Dragon System`);
// preload handlebars templates
RdDUtility.preloadHandlebarsTemplates();
2020-06-07 23:16:50 +02:00
/* -------------------------------------------- */
this.initSystemSettings();
2022-01-30 16:11:20 +01:00
/* -------------------------------------------- */
// Set an initiative formula for the system
CONFIG.Combat.initiative = {
formula: "1+(1d6/10)",
decimals: 2
};
2022-01-30 16:11:20 +01:00
/* -------------------------------------------- */
game.socket.on(SYSTEM_SOCKET_ID, async (sockmsg) => {
console.log(">>>>> MSG RECV", sockmsg);
try {
RdDUtility.onSocketMessage(sockmsg);
RdDCombat.onSocketMessage(sockmsg);
ChatUtility.onSocketMessage(sockmsg);
2022-12-28 23:36:48 +01:00
RdDBaseActor.onSocketMessage(sockmsg);
} catch (e) {
console.error('game.socket.on(SYSTEM_SOCKET_ID) Exception: ', sockmsg, ' => ', e)
}
});
/* -------------------------------------------- */
// Define custom Entity classes
CONFIG.Actor.documentClass = RdDBaseActor;
CONFIG.Item.documentClass = RdDItem;
CONFIG.RDD = {
resolutionTable: RdDResolutionTable.resolutionTable,
carac_array: RdDUtility.getCaracArray(),
ajustementsConditions: RdDUtility.getAjustementsConditions(),
difficultesLibres: RdDUtility.getDifficultesLibres()
}
2020-12-08 21:40:41 +01:00
/* -------------------------------------------- */
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
2023-01-01 22:21:30 +01:00
Actors.registerSheet(SYSTEM_RDD, RdDCommerceSheet, { types: ["commerce"], makeDefault: true });
Actors.registerSheet(SYSTEM_RDD, RdDActorSheet, { types: ["personnage"], makeDefault: true });
Actors.registerSheet(SYSTEM_RDD, RdDActorCreatureSheet, { types: ["creature"], makeDefault: true });
Actors.registerSheet(SYSTEM_RDD, RdDActorVehiculeSheet, { types: ["vehicule"], makeDefault: true });
Actors.registerSheet(SYSTEM_RDD, RdDActorEntiteSheet, { types: ["entite"], makeDefault: true });
Items.unregisterSheet("core", ItemSheet);
RdDItemSheet.register(RdDSigneDraconiqueItemSheet);
RdDItemSheet.register(RdDRencontreItemSheet);
RdDItemSheet.register(RdDConteneurItemSheet);
RdDItemSheet.register(RdDHerbeItemSheet);
RdDItemSheet.register(RdDFauneItemSheet);
2023-01-14 01:15:15 +01:00
RdDItemSheet.register(RdDPlanteItemSheet);
RdDItemSheet.register(RdDIngredientItemSheet);
RdDItemSheet.register(RdDServiceItemSheet);
Items.registerSheet(SYSTEM_RDD, RdDItemSheet, {
types: [
"competence", "competencecreature",
"recettealchimique", "musique", "chant", "danse", "jeu", "recettecuisine", "oeuvre",
"objet", "arme", "armure", "livre", "potion", "munition",
"monnaie", "nourritureboisson", "gemme",
"meditation", "queue", "ombre", "souffle", "tete", "casetmr", "sort", "sortreserve",
"nombreastral", "tache", "maladie", "poison", "possession",
"tarot", "extraitpoetique"
], makeDefault: true
});
CONFIG.Combat.documentClass = RdDCombatManager;
// préparation des différents modules
RdDTimestamp.init();
SystemCompendiums.init();
DialogChronologie.init();
ReglesOptionelles.init();
RdDUtility.init();
RdDDice.init();
RdDCommands.init();
RdDCombat.init();
RdDCombatManager.init();
RdDTokenHud.init();
2022-12-28 23:36:48 +01:00
RdDBaseActor.init();
RddCompendiumOrganiser.init();
EffetsDraconiques.init()
TMRUtility.init();
RdDHotbar.initDropbar();
RdDPossession.init();
TMRRencontres.init();
Environnement.init();
Hooks.once('ready', () => this.onReady());
}
2020-07-24 10:51:11 +02:00
initSystemSettings() {
game.settings.register(SYSTEM_RDD, "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: {
"avant-attaque": "Avant l'attaque",
"avant-defense": "Avant la défense",
"avant-encaissement": "Avant l'encaissement",
},
default: "avant-encaissement"
});
/* -------------------------------------------- */
game.settings.register(SYSTEM_RDD, "liste-nombre-astral", {
name: "liste-nombre-astral",
scope: "world",
config: false,
default: [],
type: Object
});
/* -------------------------------------------- */
game.settings.register(SYSTEM_RDD, "calendrier-pos", {
name: "calendrierPos",
scope: "client",
config: false,
default: RdDCalendrier.createCalendrierPos(),
type: Object
});
/* -------------------------------------------- */
game.settings.register(SYSTEM_RDD, "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
});
/* -------------------------------------------- */
game.settings.register(SYSTEM_RDD, "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
});
/* -------------------------------------------- */
game.settings.register(SYSTEM_RDD, "appliquer-famine-soif", {
name: "Notifier de la famine et la soif pour",
hint: "Indique si les cas de famine et de soif seront indiqués durant Château Dormant",
scope: "world",
config: true,
type: String,
choices: {
"aucun": "ni la famine, ni la soif",
"famine": "seulement la famine",
"famine-soif": "la famine et la soif",
},
default: "aucun"
});
}
async onReady() {
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
// CSS patch for v9
if (game.version) {
let sidebar = document.getElementById("sidebar");
sidebar.style.width = "min-content";
2021-11-11 02:43:01 +01:00
}
if (Misc.isUniqueConnectedGM()) {
new Migrations().migrate();
2021-11-11 02:43:01 +01:00
}
StatusEffects.onReady();
RdDHerbes.initializeHerbes();
RdDDice.onReady();
/* -------------------------------------------- */
/* Affiche/Init le calendrier */
let calendrier = new RdDCalendrier();
let templatePath = "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html";
let templateData = {};
renderTemplate(templatePath, templateData).then(html => {
calendrier.render(true);
2021-11-11 02:43:01 +01:00
});
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
});
}
if (Misc.isUniqueConnectedGM()) {
this.messageDeBienvenue();
this.registerUsageCount(SYSTEM_RDD);
}
}
/* -------------------------------------------- */
messageDeBienvenue() {
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>
` });
}
2021-11-11 02:43:01 +01:00
}
2021-12-20 10:18:28 +01:00
/* -------------------------------------------- */
// Register world usage statistics
async registerUsageCount(registerKey) {
if (game.user.isGM) {
game.settings.register("world", "world-key", {
name: "Unique world key",
scope: "world",
config: false,
default: "NONE",
type: String
});
let worldKey = game.settings.get("world", "world-key")
if (worldKey == undefined || worldKey == "") {
worldKey = randomID(32)
game.settings.set("world", "world-key", worldKey)
}
let regURL = `https://www.uberwald.me/fvtt_appcount/count.php?name="${registerKey}"&worldKey="${worldKey}"&version="${game.release.generation}.${game.release.build}"&system="${game.system.id}"&systemversion="${game.system.version}"`
$.ajax(regURL)
/* -------------------------------------------- */
}
2021-12-20 10:18:28 +01:00
}
2022-01-30 16:11:20 +01:00
2021-11-11 02:43:01 +01:00
}
SystemReveDeDragon.start();
2021-04-29 02:57:56 +02:00