From 2ab1cbe24c13e8be65cf6b5e769e77c533ff8e1f Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 19 Jul 2022 00:18:46 +0200 Subject: [PATCH] v0.5 fixes --- modules/pegasus-actor-sheet.js | 9 +- modules/pegasus-actor.js | 64 ++++++++++++--- modules/pegasus-roll-dialog.js | 23 ++++-- modules/pegasus-utility.js | 81 ++++++++++++++---- styles/simple.css | 10 +++ system.json | 4 +- template.json | 2 + templates/actor-sheet.html | 96 +++++++++++++++++++--- templates/item-vice-sheet.html | 6 ++ templates/item-virtue-sheet.html | 6 ++ templates/partial-roll-select-effects.html | 2 +- templates/roll-dialog-generic.html | 4 +- 12 files changed, 255 insertions(+), 52 deletions(-) diff --git a/modules/pegasus-actor-sheet.js b/modules/pegasus-actor-sheet.js index bde790f..6f6fe23 100644 --- a/modules/pegasus-actor-sheet.js +++ b/modules/pegasus-actor-sheet.js @@ -57,6 +57,8 @@ export class PegasusActorSheet extends ActorSheet { role: duplicate(this.actor.getRole()), effects: duplicate(this.actor.getEffects()), moneys: duplicate(this.actor.getMoneys()), + virtues: duplicate(this.actor.getVirtues()), + vices: duplicate(this.actor.getVices()), encCapacity: this.actor.getEncumbranceCapacity(), levelRemainingList: this.actor.getLevelRemainingList(), containersTree: this.actor.containersTree, @@ -321,7 +323,12 @@ export class PegasusActorSheet extends ActorSheet { this.actor.activatePower( li.data("item-id") ); this.render(true); }); - + html.find('.vice-virtue-activate').click(ev => { + const li = $(ev.currentTarget).parents(".item") + this.actor.activateViceOrVirtue( li.data("item-id") ) + this.render(true); + }) + html.find('.change-worstfear').change(ev => { this.actor.manageWorstFear( ev.currentTarget.checked ) }); diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index f2999a0..0731212 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -110,6 +110,16 @@ export class PegasusActor extends Actor { return comp; } /* -------------------------------------------- */ + getVirtues() { + let comp = this.data.items.filter(item => item.type == 'virtue'); + return comp; + } + /* -------------------------------------------- */ + getVices() { + let comp = this.data.items.filter(item => item.type == 'vice'); + return comp; + } + /* -------------------------------------------- */ getArmors() { let comp = duplicate(this.data.items.filter(item => item.type == 'armor') || []); return comp; @@ -222,6 +232,37 @@ export class PegasusActor extends Actor { } } + /* -------------------------------------------- */ + async activateViceOrVirtue(itemId) { + let item = this.data.items.find(item => item.id == itemId) + if (item && item.data.data) { + let nrg = duplicate(this.data.data.nrg) + if (!item.data.data.activated) { // Current value + + let effects = [] + for (let effect of item.data.data.effectsgained) { + effect.data.powerId = itemId // Link to the perk, in order to dynamically remove them + effects.push(effect) + } + if (effects.length) { + await this.createEmbeddedDocuments('Item', effects) + } + } else { + let toRem = [] + for (let item of this.data.items) { + if (item.type == 'effect' && item.data.data.powerId == itemId) { + toRem.push(item.id) + } + } + if (toRem.length) { + await this.deleteEmbeddedDocuments('Item', toRem) + } + } + let update = { _id: item.id, "data.activated": !item.data.data.activated } + await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity + } + } + /* -------------------------------------------- */ async activatePower(itemId) { let item = this.data.items.find(item => item.id == itemId) @@ -444,6 +485,9 @@ export class PegasusActor extends Actor { chatData.content = `
${this.name} has used a Momentum${i}`) + for (let i = 0; i <= this.data.data.biodata.maxlevelremaining; i++) { + options.push(``) } return options.join("\n") } @@ -1262,10 +1307,9 @@ export class PegasusActor extends Actor { async startRoll(rollData) { this.syncRoll(rollData); //console.log("ROLL DATA", rollData) - let rollDialog = await PegasusRollDialog.create(this, rollData); - console.log(rollDialog); + let rollDialog = await PegasusRollDialog.create(this, rollData) + console.log(rollDialog) rollDialog.render(true); - } /* -------------------------------------------- */ diff --git a/modules/pegasus-roll-dialog.js b/modules/pegasus-roll-dialog.js index 95b24c4..8d5058e 100644 --- a/modules/pegasus-roll-dialog.js +++ b/modules/pegasus-roll-dialog.js @@ -48,7 +48,7 @@ export class PegasusRollDialog extends Dialog { if (effect) { effect.applied = toggled - let level, genre, idVal + let level, genre, idVal, key if (effect.type == 'hindrance') { level = effect.value genre = 'positive' @@ -61,30 +61,36 @@ export class PegasusRollDialog extends Dialog { effectData.data.isUsed = toggled if (effectData.data.reducedicevalue || effectData.data.statdice) { idVal = "#statDicesLevel" + key = "statLevelBonus" } if (effectData.data.otherdice) { idVal = "#damageDiceLevel" + key = "damageLevelBonus" } if (effectData.data.hindrance) { idVal = "#hindranceDicesLevel" genre = 'positive' // Dynamic fix + key = "hindranceLevelBonus" } } // Now process the dice level update if (idVal) { + let newLevel = Number($(idVal).val()) if (toggled) { - let newLevel = Number($(idVal).val()) - console.log("Ongoing", newLevel, toggled, idVal) - if (genre == 'positive') { + if (genre == 'positive') { newLevel += Number(level) + this.rollData[key] += Number(level) } else { newLevel -= Number(level) + this.rollData[key] -= Number(level) } } else { if (genre == 'positive') { newLevel -= Number(level) + this.rollData[key] -= Number(level) } else { newLevel += Number(level) + this.rollData[key] += Number(level) } } newLevel = (newLevel < 0) ? 0 : newLevel @@ -210,7 +216,7 @@ export class PegasusRollDialog extends Dialog { html.find('#statDicesLevel').change((event) => { this.rollData.statDicesLevel = Number(event.currentTarget.value) }); - html.find('#specDicesLevel').change( async (event) => { + html.find('#specDicesLevel').change(async (event) => { this.rollData.specDicesLevel = Number(event.currentTarget.value) PegasusUtility.updateSpecDicePool(this.rollData) this.refreshDialog() @@ -244,15 +250,16 @@ export class PegasusRollDialog extends Dialog { html.find('.pool-add-dice').click(async (event) => { let diceKey = $(event.currentTarget).data("dice-key") - PegasusUtility.addDicePool( this.rollData, diceKey) + let diceLevel = $(event.currentTarget).data("dice-level") + PegasusUtility.addDicePool(this.rollData, diceKey, diceLevel) this.refreshDialog() }) html.find('.pool-remove-dice').click(async (event) => { let idx = $(event.currentTarget).data("dice-idx") - PegasusUtility.removeFromDicePool( this.rollData, idx) + PegasusUtility.removeFromDicePool(this.rollData, idx) this.refreshDialog() }) - + } } \ No newline at end of file diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index e863357..47bfa56 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -60,9 +60,9 @@ export class PegasusUtility { /* -------------------------------------------- */ static getDiceList() { - return [{ key: "d4", img: "systems/fvtt-pegasus-rpg/images/dice/d4.webp" }, { key: "d6", img: "systems/fvtt-pegasus-rpg/images/dice/d6.webp" }, - { key: "d8", img: "systems/fvtt-pegasus-rpg/images/dice/d8.webp" }, { key: "d10", img: "systems/fvtt-pegasus-rpg/images/dice/d10.webp" }, - { key: "d12", img: "systems/fvtt-pegasus-rpg/images/dice/d12.webp" }] + return [{ key: "d4", level: 1, img: "systems/fvtt-pegasus-rpg/images/dice/d4.webp" }, { key: "d6", level: 2, img: "systems/fvtt-pegasus-rpg/images/dice/d6.webp" }, + { key: "d8", level: 3, img: "systems/fvtt-pegasus-rpg/images/dice/d8.webp" }, { key: "d10", level: 4, img: "systems/fvtt-pegasus-rpg/images/dice/d10.webp" }, + { key: "d12", level: 5, img: "systems/fvtt-pegasus-rpg/images/dice/d12.webp" }] } /* -------------------------------------------- */ @@ -72,7 +72,7 @@ export class PegasusUtility { if (effect && effect.applied && effect.effect.data.bonusdice) { let diceKey = PegasusUtility.getDiceFromLevel(effect.effect.data.effectlevel) let newDice = { - name: "effect-bonus-dice", key: diceKey, effect: effect.effect.name, + name: "effect-bonus-dice", key: diceKey, level: effect.effect.data.effectlevel, effect: effect.effect.name, img: `systems/fvtt-pegasus-rpg/images/dice/${diceKey}.webp` } newDicePool.push(newDice) @@ -90,7 +90,7 @@ export class PegasusUtility { let diceList = diceKey.split(" ") for(let myDice of diceList) { let newDice = { - name: "damage", key: myDice, + name: "damage", key: myDice, level: rollData.damageDiceLevel, img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp` } newDicePool.push(newDice) @@ -108,7 +108,7 @@ export class PegasusUtility { let diceList = diceKey.split(" ") for(let myDice of diceList) { let newDice = { - name: "spec", key: myDice, + name: "spec", key: myDice, level: rollData.specDicesLevel, img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp` } newDicePool.push(newDice) @@ -118,9 +118,9 @@ export class PegasusUtility { } /* -------------------------------------------- */ - static addDicePool(rollData, diceKey) { + static addDicePool(rollData, diceKey, level) { let newDice = { - name: "dice-click", key: diceKey, + name: "dice-click", key: diceKey, level: level, img: `systems/fvtt-pegasus-rpg/images/dice/${diceKey}.webp` } rollData.dicePool.push(newDice) @@ -451,22 +451,22 @@ export class PegasusUtility { /* -------------------------------------------- */ static updateRollData(rollData) { - let id = rollData.rollId; - let oldRollData = this.rollDataStore[id] || {}; - let newRollData = mergeObject(oldRollData, rollData); - this.rollDataStore[id] = newRollData; + let id = rollData.rollId + let oldRollData = this.rollDataStore[id] || {} + let newRollData = mergeObject(oldRollData, rollData) + this.rollDataStore[id] = newRollData } /* -------------------------------------------- */ static saveRollData(rollData) { game.socket.emit("system.pegasus-rpg", { name: "msg_update_roll", data: rollData }); // Notify all other clients of the roll - this.updateRollData(rollData); + this.updateRollData(rollData) } /* -------------------------------------------- */ static getRollData(id) { - return this.rollDataStore[id]; + return this.rollDataStore[id] } /* -------------------------------------------- */ @@ -570,15 +570,51 @@ export class PegasusUtility { for (let effect of rollData.effectsList) { if (effect.effect.data.isUsed && effect.effect.data.oneuse) { toRem.push(effect.effect._id) + ChatMessage.create({content: `One used effect ${effect.effect.name} has been auto-deleted.`}) } } if (toRem.length > 0) { - console.log("Going to remove one use effects", toRem) + //console.log("Going to remove one use effects", toRem) let actor = game.actors.get(rollData.actorId) actor.deleteEmbeddedDocuments('Item', toRem) } } + /* -------------------------------------------- */ + static async momentumReroll(actorId) { + let actor = game.actors.get(actorId) + let rollData = actor.lastRoll + if (rollData) { + rollData.rerollMomentum = true + PegasusUtility.rollPegasus(rollData) + this.actor.lastRoll = undefined + } else { + ui.notifications.warn("No last roll registered....") + } + } + + /* -------------------------------------------- */ + static async showMomentumDialog( actorId) { + let d = new Dialog({ + title: "Momentum reroll", + content: "

Do you want to re-roll your last roll ?

", + buttons: { + one: { + icon: '', + label: "Cancel", + callback: () => this.close() + }, + two: { + icon: '', + label: "Reroll", + callback: () => PegasusUtility.momentumReroll(actorId) + } + }, + default: "Reroll", + }) + d.render(true) + } + /* -------------------------------------------- */ static async rollPegasus(rollData) { @@ -626,13 +662,17 @@ export class PegasusUtility { let diceFormulaTab = [] for (let dice of rollData.dicePool) { - diceFormulaTab.push(dice.key) + let level = dice.level + if (dice.name == "stat" ) { + level += rollData.statLevelBonus + } + diceFormulaTab.push( this.getFoundryDiceFromLevel(level) ) } let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh + ' + (rollData.stat?.mod || 0) // Performs roll let myRoll = rollData.roll - if (!myRoll || rollData.reroll) { // New rolls only of no rerolls + if (!myRoll || rollData.reroll || 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 @@ -669,7 +709,8 @@ export class PegasusUtility { this.removeOneUseEffects(rollData) // Unused for now // And save the roll - this.saveRollData(rollData); + this.saveRollData(rollData) + actor.lastRoll = rollData } /* -------------------------------------------- */ @@ -812,6 +853,10 @@ export class PegasusUtility { rollId: randomID(16), rollMode: game.settings.get("core", "rollMode"), bonusDicesLevel: 0, + statLevelBonus: 0, + damageLevelBonus: 0, + specLevelBonus: 0, + hindranceLevelBonus: 0, hindranceDicesLevel: 0, otherDicesLevel: 0, statDicesLevel: 0, diff --git a/styles/simple.css b/styles/simple.css index 9755a57..ed8cf0d 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1412,6 +1412,11 @@ Focus FOC: #ff0084 max-width: 14rem; min-width: 14rem; } +.item-name-label-header-long2 { + flex-grow:2; + max-width: 24rem; + min-width: 24rem; +} .item-name-label { flex-grow:2; max-width: 10rem; @@ -1422,6 +1427,11 @@ Focus FOC: #ff0084 max-width: 12rem; min-width: 12rem; } +.item-name-label-long2 { + flex-grow:2; + max-width: 22rem; + min-width: 22rem; +} .item-name-label-level2 { flex-grow:2; max-width: 9rem; diff --git a/system.json b/system.json index a208faf..869e3a8 100644 --- a/system.json +++ b/system.json @@ -180,9 +180,9 @@ "styles": [ "styles/simple.css" ], - "templateVersion": 94, + "templateVersion": 95, "title": "Pegasus RPG", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", - "version": "0.5.15", + "version": "0.6.0", "background" : "./images/ui/pegasus_welcome_page.webp" } diff --git a/template.json b/template.json index 1c31c11..86e8946 100644 --- a/template.json +++ b/template.json @@ -271,12 +271,14 @@ "unavailablevice": [], "effectsgained": [], "threatlevel": 0, + "activated": false, "description": "" }, "vice": { "unavailablevirtue": [], "effectsgained": [], "threatlevel": 0, + "activated": false, "description": "" }, "specialisation": { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 96f02ca..ce52805 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -175,14 +175,14 @@

- - - + + + @@ -208,9 +208,9 @@ {{perk.data.level}} {{#if perk.data.features.range.flag}} - {{perk.data.features.range.value}} + {{perk.data.features.range.value}} {{else}} -  -  +  -  {{/if}} {{#if perk.data.features.nbtargets.flag}} @@ -219,6 +219,7 @@  -  {{/if}} + -

Development :

    +
  • + +

    +
    +
  • +
  • + + +
  • +
  • diff --git a/templates/item-virtue-sheet.html b/templates/item-virtue-sheet.html index b748e7c..60aeefe 100644 --- a/templates/item-virtue-sheet.html +++ b/templates/item-virtue-sheet.html @@ -31,6 +31,12 @@
+
  • + + +
  • +
  • diff --git a/templates/partial-roll-select-effects.html b/templates/partial-roll-select-effects.html index 118993e..5fd8a3d 100644 --- a/templates/partial-roll-select-effects.html +++ b/templates/partial-roll-select-effects.html @@ -17,7 +17,7 @@
  • {{else}} {{#if (count effect.effect.data.specaffected)}} - {{#each effect.effect.data.specaffected as |spec idx|}} + {{#each effect.effect.data.specaffected as |spec idx2|}} {{#if (eq @root.specName spec.name)}}
  • diff --git a/templates/roll-dialog-generic.html b/templates/roll-dialog-generic.html index 623c754..9782476 100644 --- a/templates/roll-dialog-generic.html +++ b/templates/roll-dialog-generic.html @@ -71,7 +71,7 @@
    {{#each dicePool as |dice idx|}} - {{/each}}
    @@ -79,7 +79,7 @@
    {{#each diceList as |dice idx|}} - {{/each}}