From 2637f698ad14184e9c949c61930db56587e7f467 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Fri, 20 May 2022 21:50:18 +0200 Subject: [PATCH] Start adv generator --- module/bol.js | 9 +-- module/system/bol-adventure-generator.js | 81 ++++++++++++++++++++++-- system.json | 2 +- 3 files changed, 80 insertions(+), 12 deletions(-) diff --git a/module/bol.js b/module/bol.js index de9fca3..5774af6 100644 --- a/module/bol.js +++ b/module/bol.js @@ -14,6 +14,7 @@ import { BoLCombatManager } from "./system/bol-combat.js" import { BoLTokenHud } from "./system/bol-action-hud.js" import { BoLHotbar } from "./system/bol-hotbar.js" import { BoLAdventureGenerator } from "./system/bol-adventure-generator.js" +import { BoLCommands} from "./system/bol-commands.js" /* -------------------------------------------- */ Hooks.once('init', async function () { @@ -29,7 +30,7 @@ Hooks.once('init', async function () { // Game socket game.socket.on("system.bol", sockmsg => { BoLUtility.onSocketMessage(sockmsg); - }); + }) /** @@ -56,6 +57,8 @@ Hooks.once('init', async function () { BoLUtility.init() BoLTokenHud.init() BoLHotbar.init() + BoLCommands.init() + BoLAdventureGenerator.init() // Preload Handlebars Templates await preloadHandlebarsTemplates(); @@ -109,8 +112,6 @@ Hooks.once('ready', async function () { registerUsageCount('bol') welcomeMessage() - - BoLAdventureGenerator.init() -}); +}) diff --git a/module/system/bol-adventure-generator.js b/module/system/bol-adventure-generator.js index 2e40a53..2221685 100644 --- a/module/system/bol-adventure-generator.js +++ b/module/system/bol-adventure-generator.js @@ -1,19 +1,86 @@ /* -------------------------------------------- */ -import { BoLRoll } from "../controllers/bol-rolls.js"; +import { BoLUtility } from "./bol-utility.js"; /* -------------------------------------------- */ export class BoLAdventureGenerator { + /* -------------------------------------------- */ static async init() { this.adventureData = await fetchJsonWithTimeout("systems/bol/module/system/adventure_data.json") + } - let roll1 = new Roll("1d"+this.adventureData.titre1.length).evaluate( {async: false}) - let roll2 = new Roll("1d"+this.adventureData.titre2.length).evaluate( {async: false}) + /* -------------------------------------------- */ + static async createAdventure() { + let roll1 = new Roll("1d" + this.adventureData.titre1.length).evaluate({ async: false }) + let roll2 = new Roll("1d" + this.adventureData.titre2.length).evaluate({ async: false }) - let p1 = this.adventureData.titre1[roll1.result-1] - let p2 = this.adventureData.titre2[roll2.result-1] + let p1 = this.adventureData.titre1[roll1.result - 1] + let p2 = this.adventureData.titre2[roll2.result - 1] + + let story = {} + story.title = "Krongar et " + p1.prefix + " " + p1.name + " " + p2.prefix + " " + p2.name + + let rollM = new Roll("1d" + this.adventureData.mission.length).evaluate({ async: false }) + story.mission = "La mission de Krongar est de " + this.adventureData.mission[rollM.result - 1].name + + if (!p1.isCarriere && !p2.isCarriere) { + let rollC = new Roll("1d" + this.adventureData.carriere.length).evaluate({ async: false }) + story.carriere = "Une carrière : " + this.adventureData.carriere[rollC.result - 1] + } + + if (!p1.isLieu && !p2.isLieu) { + let rollL1 = new Roll("1d" + this.adventureData.lieux1.length).evaluate({ async: false }) + let rollL2 = new Roll("1d" + this.adventureData.lieux2.length).evaluate({ async: false }) + story.lieu = "Un lieu : " + this.adventureData.lieux1[rollL1.result - 1] + " " + this.adventureData.lieux2[rollL2.result - 1] + } + + if (!p1.isObjet && !p2.isObjet) { + let rollO1 = new Roll("1d" + this.adventureData.objets1.length).evaluate({ async: false }) + let rollO2 = new Roll("1d" + this.adventureData.objets2.length).evaluate({ async: false }) + story.objet = "Un objet : " + this.adventureData.objets1[rollO1.result - 1] + " " + this.adventureData.objets2[rollO2.result - 1] + } + + let rollMOT = new Roll("1d" + this.adventureData.motivation.length).evaluate({ async: false }) + story.motivation = "Krongar entreprend cette mission parce que " + this.adventureData.motivation[rollMOT.result - 1] + + if (!p1.isEnnemi && !p2.isEnnemi) { + let rollE = new Roll("1d" + this.adventureData.rival.length).evaluate({ async: false }) + story.rival = "Un rival : " + this.adventureData.rival[rollE.result - 1] + } + + let rollDieu = new Roll("1d6").evaluate({ async: false }) + if (rollDieu.result == 6) { + rollDieu = new Roll("1d" + this.adventureData.dieu.length).evaluate({ async: false }) + story.dieu = "Un Dieu est impliqué : " + this.adventureData.dieu[rollDieu.result - 1] + } + + let rollComp = new Roll("1d6").evaluate({ async: false }) + if (rollComp.result >= 5) { + rollComp = new Roll("1d" + this.adventureData.complique1.length).evaluate({ async: false }) + story.complication = "Une complication : " + this.adventureData.complique1[rollComp.result - 1] + } + + let rollObs = new Roll("1d6").evaluate({ async: false }) + if (rollObs.result >= 5) { + rollObs = new Roll("1d" + this.adventureData.obstacle.length).evaluate({ async: false }) + story.obstacle = "Un obstacle : " + this.adventureData.obstacle[rollObs.result - 1] + } + + let rollRet = new Roll("1d6").evaluate({ async: false }) + if (rollRet.result == 6) { + rollRet = new Roll("1d" + this.adventureData.retournement.length).evaluate({ async: false }) + story.retournement = "Un retournement : " + this.adventureData.retournement[rollRet.result - 1] + } + + let rollRec = new Roll("1d" + this.adventureData.recompense.length).evaluate({ async: false }) + story.recompense = "Pour sa peine, Krongar reçoit " + this.adventureData.recompense[rollRec.result - 1] + + ChatMessage.create({ + alias: this.name, + whisper: BoLUtility.getUsers(user => user.isGM), + content: await renderTemplate('systems/bol/templates/chat/chat-adventure-result.hbs', + { name: "Aventure !", img: "", story : story}) + }) - let str = "Krongar et " + p1.prefix + " " + p1.name + " " + p2.prefix + " " + p2.name - //ui.notifications.info("Titre :" + str) } } diff --git a/system.json b/system.json index 0b727a3..ee1fb3e 100644 --- a/system.json +++ b/system.json @@ -14,7 +14,7 @@ "url": "https://github.com/ZigmundKreud/bol", "license": "LICENSE.txt", "flags": {}, - "version": "1.3.16", + "version": "1.3.17", "templateVersion": 10, "minimumCoreVersion": "0.8.6", "compatibleCoreVersion": "9",