From a100da7cd99d6cccddb057bbc63dda9ef8695fe9 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Fri, 21 Oct 2022 09:38:43 +0200 Subject: [PATCH] Gestion des singularites --- modules/imperium5-actor-sheet.js | 2 +- modules/imperium5-main.js | 2 +- modules/imperium5-utility.js | 105 +++++++++++++++++++++-------- styles/simple.css | 7 +- system.json | 4 +- templates/chat-generic-result.html | 39 ++++++++--- templates/roll-dialog-generic.html | 5 +- 7 files changed, 115 insertions(+), 49 deletions(-) diff --git a/modules/imperium5-actor-sheet.js b/modules/imperium5-actor-sheet.js index a6f25e0..5d20d75 100644 --- a/modules/imperium5-actor-sheet.js +++ b/modules/imperium5-actor-sheet.js @@ -154,7 +154,7 @@ export class Imperium5ActorSheet extends ActorSheet { this.render(true); }); html.find('.item-link a').click((event) => { - const itemId = $(event.currentTarget).data("item-id"); + const itemId = $(event.currentTarget).data("item-id") const item = this.actor.getOwnedItem(itemId); item.sheet.render(true); }); diff --git a/modules/imperium5-main.js b/modules/imperium5-main.js index ff9996e..7e46813 100644 --- a/modules/imperium5-main.js +++ b/modules/imperium5-main.js @@ -88,7 +88,7 @@ Hooks.once("ready", function () { let sidebar = document.getElementById("sidebar") sidebar.style.width = "min-content" } - + welcomeMessage() }) diff --git a/modules/imperium5-utility.js b/modules/imperium5-utility.js index 87b6b3a..014404e 100644 --- a/modules/imperium5-utility.js +++ b/modules/imperium5-utility.js @@ -50,13 +50,33 @@ export class Imperium5Utility { }) } + /* -------------------------------------------- */ + static registerSettings() { + game.settings.register("fvtt-imperium5", "use-entropie-reussite", { + name: "Utilisation du dé d'Entropie dans les réussites", + hint: "Si coché, ajoute 1 succès au joueur sur un 2, et 1 succés au MJ sur un 7.", + scope: "world", + config: true, + default: false, + type: Boolean + }) + game.settings.register("fvtt-imperium5", "use-singularite", { + name: "Utilisation complémentaire des Singularités", + hint: "Si coché, les Singularités peuvent permettre de réduire de 1 la valeur d'un dé", + scope: "world", + config: true, + default: false, + type: Boolean + }) + } + /* -------------------------------------------- */ static pushInitiativeOptions(html, options) { } /* -------------------------------------------- */ static async ready() { - + this.registerSettings() } /* -------------------------------------------- */ @@ -90,14 +110,19 @@ export class Imperium5Utility { /* -------------------------------------------- */ static async chatListeners(html) { - - html.on("click", '.button-apply-paradigme', event => { - let paraKey = $(event.currentTarget).data("para-key") + html.on("change", '.select-apply-paradigme', event => { + let paraKey = event.currentTarget.value let rollData = this.getRollDataFromMessage(event) rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget) this.applyParadigme(rollData, paraKey) }) - + + html.on("click", '.apply-singularite', event => { + let resultIndex = $(event.currentTarget).data("result-index") + let rollData = this.getRollDataFromMessage(event) + rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget) + this.applySingularite(rollData, resultIndex) + }) } /* -------------------------------------------- */ @@ -292,29 +317,39 @@ export class Imperium5Utility { /* -------------------------------------------- */ static computeReussites(rollData) { let myRoll = rollData.roll - rollData.successPC = myRoll.terms[0].results.filter(res => res.result <= rollData.seuil).length - rollData.successGM = myRoll.terms[4].results.filter(res => res.result <= rollData.seuil).length + // Calcul des réussites sur les 2 pools + rollData.successPC = rollData.resultsPC.filter(res => res.result <= rollData.seuil).length + rollData.successGM = myRoll.terms[4].results.filter(res => res.result <= 2).length + // Calcul du présage rollData.bonPresage = myRoll.terms[2].results[0].result == 1 rollData.mauvaisPresage = myRoll.terms[2].results[0].result == 8 - rollData.nbUnitesNarration = Math.max( rollData.successPC-1, 0) + // gestion règle optionnelle de l'Entropie + if (rollData.useEntropieReussite && myRoll.terms[2].results[0].result == 2) { + rollData.successPC++ + } + if (rollData.useEntropieReussite && myRoll.terms[2].results[0].result == 7) { + rollData.successGM++ + } + // Calcul unité de narration + rollData.nbUnitesNarration = Math.max(rollData.successPC - 1, 0) } /* -------------------------------------------- */ - static async rollImperium5(rollData) { + static async rollImperium5(rollData) { // Karma management - let actor = game.actors.get(rollData.actorId) - rollData.nbKarma = 0 - if ( rollData.useKarma ) { + let actor = game.actors.get(rollData.actorId) + rollData.nbKarma = 0 + if (rollData.useKarma) { actor.incDecKarma(-1) rollData.nbKarma++ } - if ( rollData.usedCapacite != "none" ) { + if (rollData.usedCapacite != "none") { actor.incDecKarma(-1) rollData.nbKarma++ } - let nbAmeDice = this.computeDiceReserve( rollData ) + let nbAmeDice = this.computeDiceReserve(rollData) let diceFormula = `${nbAmeDice}d8[green] + 1d8[blue] + ${rollData.realiteDice}d8[red]` let humanFormula = `${nbAmeDice}d8, 1d8, ${rollData.realiteDice}d8` // Performs roll @@ -326,7 +361,8 @@ export class Imperium5Utility { rollData.diceFormula = diceFormula rollData.humanFormula = humanFormula } - + // local copy of results to allow changes + rollData.resultsPC = duplicate(myRoll.terms[0].results) // Calcul réussites this.computeReussites(rollData) @@ -334,20 +370,39 @@ export class Imperium5Utility { content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) }) msg.setFlag("world", "imperium5-roll-data", rollData) + console.log("Final rollData", rollData) } - /* ------------------------- ------------------- */ - static async processParadigmeRoll(rollData) { + /* -------------------------------------------- */ + static async applyParadigme(rollData, paraKey) { + let actor = game.actors.get(rollData.actorId) + let para = actor.system.paradigmes[paraKey] + rollData.seuil = para.value + rollData.usedParadigme = para.label + actor.setParadigmeUsed(paraKey) + this.computeReussites(rollData) rollData.paradigmes = [] let msg = await this.createChatWithRollMode(rollData.alias, { content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) }) msg.setFlag("world", "imperium5-roll-data", rollData) - this.removeChatMessageId(rollData.previousMessageId) } + /* -------------------------------------------- */ + static async applySingularite(rollData, resultIndex) { + let res = rollData.resultsPC[resultIndex] + res.result = (res.result > 1) ? res.result-1 : res.result + this.computeReussites(rollData) + rollData.useSingularites = false + rollData.singulariteApplied = true + let msg = await this.createChatWithRollMode(rollData.alias, { + content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) + }) + msg.setFlag("world", "imperium5-roll-data", rollData) + } + /* ------------------------- ------------------- */ static async updateRoll(rollData) { @@ -474,22 +529,14 @@ export class Imperium5Utility { useAide: false, useKarma: false, usedCapacite: "none", - seuil: 2 + seuil: 2, + useSingularites: game.settings.get("fvtt-imperium5", "use-singularite"), + useEntropieReussite: game.settings.get("fvtt-imperium5", "use-entropie-reussite") } Imperium5Utility.updateWithTarget(rollData) return rollData } - /* -------------------------------------------- */ - static applyParadigme(rollData, paraKey) { - let actor = game.actors.get(rollData.actorId) - let para = actor.system.paradigmes[paraKey] - rollData.seuil = para.value - rollData.usedParadigme = para.label - actor.setParadigmeUsed(paraKey) - - this.processParadigmeRoll(rollData) - } /* -------------------------------------------- */ static updateWithTarget(rollData) { diff --git a/styles/simple.css b/styles/simple.css index 8f21492..38ec26a 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1165,7 +1165,7 @@ ul, li { .common-button { box-shadow: inset 0px 1px 0px 0px #a6827e; background: linear-gradient(to bottom, #B8A799F0 5%, #80624af0 100%); - background-color: #B8A799F0; /*#7d5d3b00;*/ + background-color: #80624af0; /*#7d5d3b00;*/ border-radius: 4px; opacity: 60%; border: 2px ridge #846109; @@ -1177,6 +1177,11 @@ ul, li { position: relative; } +.common-button option { + background: linear-gradient(to bottom, #B8A799F0 5%, #80624af0 100%); + background-color: #80624af0; /*#7d5d3b00;*/ +} + .common-button:hover { background: linear-gradient(to bottom, #97B5AEFF 5%, rgb(101, 167, 151) 100%); background-color: #97B5AEFF; diff --git a/system.json b/system.json index 2617a9e..2b70688 100644 --- a/system.json +++ b/system.json @@ -7,7 +7,7 @@ "flags": {} } ], - "version": "10.0.4", + "version": "10.0.5", "compatibility": { "minimum": "10", "verified": "10", @@ -67,5 +67,5 @@ "background": "images/ui/imperium5_welcome_page.webp", "url": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5", "manifest": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/raw/branch/master/system.json", - "download": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/archive/fvtt-imperium5-v10.0.4.zip" + "download": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/archive/fvtt-imperium5-v10.0.5.zip" } \ No newline at end of file diff --git a/templates/chat-generic-result.html b/templates/chat-generic-result.html index 74ac37a..b87a6f1 100644 --- a/templates/chat-generic-result.html +++ b/templates/chat-generic-result.html @@ -15,8 +15,12 @@
  • Réserve : {{humanFormula}}
  • Score : ( - {{#each roll.terms.0.results as |r k|}} - {{r.result}} + {{#each resultsPC as |r k|}} + {{#if @root.useSingularites}} + {{r.result}} + {{else}} + {{r.result}} + {{/if}} {{/each}} ) ( @@ -30,13 +34,34 @@ {{/each}} )
  • + + {{#if singulariteApplied}} +
  • Une Singularité a réduit de 1 le résultat du dé
  • + {{/if}} + {{#if usedParadigme}}
  • Paradigme utilisé : {{usedParadigme}}
  • {{/if}} -
  • Seuil : {{seuil}}
  • + +
  • Seuil : {{seuil}} + {{#if (count paradigmes)}} + + {{/if}} +
  • +
  • Succés : {{successPC}}
  • +
  • Succés de Réalité : {{successGM}}
  • +
  • Unités de narration : {{nbUnitesNarration}}
  • + {{#if nbKarma}}
  • Points de Karma utilisés : {{nbKarma}}
  • {{/if}} @@ -48,14 +73,6 @@
  • Mauvais Présage !
  • {{/if}} - {{#if (count paradigmes)}} -
  • - {{#each paradigmes as |para key|}} - - {{/each}} -
  • - {{/if}} - diff --git a/templates/roll-dialog-generic.html b/templates/roll-dialog-generic.html index c2ba10f..0dda622 100644 --- a/templates/roll-dialog-generic.html +++ b/templates/roll-dialog-generic.html @@ -3,14 +3,11 @@ {{#if img}} {{/if}} -

    {{title}}

    +

    {{ame.label}} ({{ame.value}})

    -
    - Ame : {{ame.label}} ({{ame.value}}) -
    Malus : {{ameMalus}}