From 8b6bfeb36c0f55c1d35e27c6914e22562952574c Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 19 Jul 2022 21:56:59 +0200 Subject: [PATCH] Update with minor fixes/updates --- modules/pegasus-actor.js | 1 + modules/pegasus-utility.js | 85 +++++++++++++----------------- templates/chat-generic-result.html | 2 - 3 files changed, 37 insertions(+), 51 deletions(-) diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index ab563de..dbf8ec7 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -952,6 +952,7 @@ export class PegasusActor extends Actor { let biodata = duplicate(this.data.data.biodata) biodata.currentlevelremaining = Math.max(biodata.currentlevelremaining + incDec, 0) this.update({ "data.biodata": biodata }) + ChatMessage.create({ content: `${this.name} has used a Hero Level to reroll !` }) return biodata.currentlevelremaining } diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 19278d8..f2e4e13 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -100,9 +100,9 @@ export class PegasusUtility { /* -------------------------------------------- */ static updateArmorDicePool(rollData) { - let newDicePool = rollData.dicePool.filter(dice => dice.name != "armor-shield" ) + let newDicePool = rollData.dicePool.filter(dice => dice.name != "armor-shield") for (let armor of rollData.armorsList) { - if (armor.applied ) { + if (armor.applied) { let diceKey = PegasusUtility.getDiceFromLevel(armor.value) let diceList = diceKey.split(" ") for (let myDice of diceList) { @@ -314,6 +314,31 @@ export class PegasusUtility { defender.processNoDefense(attackRollData); } + /* -------------------------------------------- */ + static rerollHeroRemaining(userId, rollId) { + if (game.user.isGM) { + let user = game.users.get(userId) + let character = user.character + if (!character) { + ui.notifications.warn(`No character linked to the player : reroll not allowed.`) + return + } + let rollData = this.getRollData(rollId) + if (character.getLevelRemaining() > 0) { + rollData.rerollHero = true + this.rollPegasus(rollData) + character.modifyHeroLevelRemaining(-1) + } else { + ui.notifications.warn(`No more Hero Level for ${actor.name} ! Unable to reroll.`) + } + } + } + + /* -------------------------------------------- */ + static sendRerollHeroRemaining(userId, rollId) { + game.socket.emit("system.fvtt-pegasus-rpg", { name: "msg_reroll_hero", data: { userId: userId, rollId: rollId } }) + } + /* -------------------------------------------- */ static async chatListeners(html) { @@ -325,9 +350,11 @@ export class PegasusUtility { }) html.on("click", '.reroll-level-remaining', event => { let rollId = $(event.currentTarget).data("roll-id") - let rollData = this.getRollData(rollId) - rollData.reroll = true - this.rollPegasus(rollData) + if (game.user.isGM) { + PegasusUtility.rerollHeroRemaining(game.user.id, rollId) + } else { + PegasusUtility.sendRerollHeroRemaining(game.user.id, rollId) + } }) } @@ -527,6 +554,9 @@ export class PegasusUtility { } this.addItemDropToActor(actor, item) } + if (msg.name == "msg_reroll_hero") { + this.rerollHeroRemaining(msg.data.userId, msg.data.rollId) + } } /* -------------------------------------------- */ @@ -657,46 +687,6 @@ export class PegasusUtility { /* -------------------------------------------- */ static async rollPegasus(rollData) { - /* - let dicePool = [{ name: "stat", level: 0, statmod: 0 }, { name: "spec", level: 0 }, { name: "bonus", level: 0 }, { name: "hindrance", level: 0 }, { name: "other", level: 0 }]; - if (rollData.stat) { - dicePool[0].level += Number(rollData.stat.value) - dicePool[0].statmod = Number(rollData.stat.mod) - } - if (rollData.statDicesLevel) { - dicePool[0].level = rollData.statDicesLevel - } - if (rollData.selectedSpec && rollData.selectedSpec != "0") { - rollData.spec = rollData.specList.find(item => item._id == rollData.selectedSpec) - rollData.spec.data.dice = PegasusUtility.getDiceFromLevel(rollData.spec.data.level) - } - if (rollData.spec) { - dicePool[1].level += Number(rollData.spec.data.level) - } - if (rollData.specDicesLevel) { - dicePool[1].level = rollData.specDicesLevel - } - if (rollData.traumaState == "none") { - if (rollData.bonusDicesLevel) { - dicePool[2].level += Number(rollData.bonusDicesLevel) - } - } - if (!rollData.isInit) { // No Hindrance dice for Init - if (rollData.hindranceDicesLevel) { - dicePool[3].level += Number(rollData.hindranceDicesLevel) - } - } - if (rollData.otherDicesLevel) { - dicePool[4].level += Number(rollData.otherDicesLevel) - } - - let diceFormulaTab = []; - for (let diceGroup of dicePool) { - diceFormulaTab.push(this.getFoundryDiceFromLevel(diceGroup.level)) - } - let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh'; - */ - let actor = game.actors.get(rollData.actorId) let diceFormulaTab = [] @@ -711,14 +701,11 @@ export class PegasusUtility { // Performs roll let myRoll = rollData.roll - if (!myRoll || rollData.reroll || rollData.rerollMomentum) { // New rolls only of no rerolls + if (!myRoll || rollData.rerollHero || rollData.rerollMomentum) { // New rolls only of no rerolls myRoll = new Roll(diceFormula).roll({ async: false }) await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode")) rollData.roll = myRoll } - if (rollData.reroll) { - rollData.levelRemaining = actor.modifyHeroLevelRemaining(-1) - } // Final score and keep data rollData.finalScore = myRoll.total diff --git a/templates/chat-generic-result.html b/templates/chat-generic-result.html index 26bb4ed..ac0f288 100644 --- a/templates/chat-generic-result.html +++ b/templates/chat-generic-result.html @@ -48,9 +48,7 @@ {{/if}} {{/if}} - {{#if levelRemaining}} - {{/if}}