From e0026adfcdc693dc4c78a4ee5d5f70b9caf673c8 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Tue, 20 Dec 2022 17:47:46 +0100 Subject: [PATCH] Various spell stuff enhancements --- modules/avd12-actor.js | 52 +++++++++++++++++------ modules/avd12-utility.js | 4 ++ template.json | 4 +- templates/actors/actor-sheet.hbs | 8 ++-- templates/chat/chat-generic-result.hbs | 7 +++ templates/chat/chat-utility-spell.hbs | 28 ++++++++++++ templates/dialogs/roll-dialog-generic.hbs | 4 ++ templates/items/item-spell-sheet.hbs | 14 ++++++ 8 files changed, 103 insertions(+), 18 deletions(-) create mode 100644 templates/chat/chat-utility-spell.hbs diff --git a/modules/avd12-actor.js b/modules/avd12-actor.js index a3cb97a..54a7aca 100644 --- a/modules/avd12-actor.js +++ b/modules/avd12-actor.js @@ -373,14 +373,24 @@ export class Avd12Actor extends Actor { let focusBonus = this.items.filter( it => it.system.focuspointsbonus > 0).reduce((sum, item2) => sum = item2.system.focuspointsbonus, 0) let focusregenbonus = this.items.filter( it => it.system.focusregenbonus > 0).reduce((sum, item2) => sum = item2.system.focusregenbonus, 0) let burnchancebonus = this.items.filter( it => it.system.burnchancebonus > 0).reduce((sum, item2) => sum = item2.system.burnchancebonus, 0) - console.log("FINAL BONUS", focusBonus, focusregenbonus, burnchancebonus) + + let focusPoints = focusData.focusPoints + focusBonus + let focusRegen = focusData.focusRegen + focusregenbonus + //console.log("Update focus", focusPoints, focusRegen) + if ( focusPoints != this.system.focus.focuspoints || focusRegen != this.system.focus.focusregen) { + let focusData = duplicate(this.system.focus) + focusData.focuspoints = focusPoints + focusData.focusregen = focusRegen + this.update( {'system.focus': focusData}) + } + //console.log("FINAL BONUS", focusBonus, focusregenbonus, burnchancebonus) return { - focusPoints : focusData.focusPoints + focusBonus, + focusPoints : focusPoints, burnChance: focusData.burnChance + burnchancebonus, - focusRegen: focusData.focusRegen + focusregenbonus, + focusRegen: focusRegen, spellAttackBonus: focusData.spellAttackBonus, spellDamageBonus: focusData.spellDamageBonus, - currentFocusPoints: this.system.focus.currentFocusPoints + currentFocusPoints: this.system.focus.currentfocuspoints } } return { @@ -581,26 +591,42 @@ export class Avd12Actor extends Actor { } /* -------------------------------------------- */ - rollSpell(spellId) { + async rollSpell(spellId) { let spell = this.items.get(spellId) if (spell) { spell = duplicate(spell) + let rollData = this.getCommonRollData() + rollData.mode = "spell" + rollData.spell = spell + rollData.spellAttack = this.system.bonus.spell.attack + rollData.spellDamage = this.system.bonus.spell.damage + rollData.spellCost = Avd12Utility.getSpellCost(spell) + rollData.title = "Roll Spell " + spell.name + rollData.img = spell.img if (spell.system.spelltype != "utility") { - let rollData = this.getCommonRollData() - rollData.mode = "spell" - rollData.spell = spell - rollData.spellAttack = this.system.bonus.spell.attack - rollData.spellDamage = this.system.bonus.spell.damage - rollData.spellCost = Avd12Utility.getSpellCost(spell) - rollData.title = "Roll Spell " + spell.name - rollData.img = spell.img this.startRoll(rollData) + } else { + this.spentFocusPoints( spell ) + let msg = await Avd12Utility.createChatWithRollMode(rollData.alias, { + content: await renderTemplate(`systems/fvtt-avd12/templates/chat/chat-utility-spell.hbs`, rollData) + }) + msg.setFlag("world", "rolldata", rollData) } } else { ui.notifications.warn("Unable to find the relevant spell.") } } + /* -------------------------------------------- */ + spentFocusPoints( spell) { + let spellCost = Avd12Utility.getSpellCost(spell) + let focusData = duplicate(this.system.focus) + focusData.currentfocuspoints -= spellCost + focusData.currentfocuspoints = Math.max(focusData.currentfocuspoints, 0) + console.log("New fovcus", this.system, focusData) + this.update({'system.focus': focusData}) + } + /* -------------------------------------------- */ rollWeapon(weaponId) { let weapon = this.items.get(weaponId) diff --git a/modules/avd12-utility.js b/modules/avd12-utility.js index bfc6688..16485df 100644 --- a/modules/avd12-utility.js +++ b/modules/avd12-utility.js @@ -541,6 +541,10 @@ export class Avd12Utility { } } + if (rollData.spell) { + actor.spentFocusPoints(rollData.spell) + } + let msg = await this.createChatWithRollMode(rollData.alias, { content: await renderTemplate(`systems/fvtt-avd12/templates/chat/chat-generic-result.hbs`, rollData) }) diff --git a/template.json b/template.json index a9d6775..0aeb99a 100644 --- a/template.json +++ b/template.json @@ -191,7 +191,7 @@ "focus": { "focuspoints": 0, "focusregen": 0, - "currentFocusPoints": 0 + "currentfocuspoints": 0 }, "lifeline": { "value": 0, @@ -438,6 +438,8 @@ "school": "", "damage": "", "damagetype": "", + "damagesecondary": "", + "damagesecondarytype": "", "range": 0, "components": "", "reaction": false, diff --git a/templates/actors/actor-sheet.hbs b/templates/actors/actor-sheet.hbs index a6868f1..bb6d625 100644 --- a/templates/actors/actor-sheet.hbs +++ b/templates/actors/actor-sheet.hbs @@ -64,7 +64,7 @@ Health / - +   @@ -72,14 +72,14 @@
  • Focus Regen - +   Focus Points - / - + / +  
  • diff --git a/templates/chat/chat-generic-result.hbs b/templates/chat/chat-generic-result.hbs index 695250b..236ae8e 100644 --- a/templates/chat/chat-generic-result.hbs +++ b/templates/chat/chat-generic-result.hbs @@ -23,6 +23,13 @@ {{/if}} + {{#if spell}} +
  • Spell : {{spell.name}} ({{spell.system.level}}) +
  • +
  • Focus Points Spent : {{spellCost}} +
  • + {{/if}} +
  • Dice Formula {{diceFormula}}
  • Result {{roll.total}}
  • diff --git a/templates/chat/chat-utility-spell.hbs b/templates/chat/chat-utility-spell.hbs new file mode 100644 index 0000000..e570265 --- /dev/null +++ b/templates/chat/chat-utility-spell.hbs @@ -0,0 +1,28 @@ +
    + {{#if actorImg}} + {{alias}} + {{/if}} +

    {{alias}}

    +
    + +
    + + {{#if img}} +
    + {{name}} +
    + {{/if}} + +
    +
    + +
    + +
    + + diff --git a/templates/dialogs/roll-dialog-generic.hbs b/templates/dialogs/roll-dialog-generic.hbs index e9c0c5f..81da80a 100644 --- a/templates/dialogs/roll-dialog-generic.hbs +++ b/templates/dialogs/roll-dialog-generic.hbs @@ -47,6 +47,9 @@ + {{#if spell}} + + {{else}}
    Target check :
    + {{/if}} diff --git a/templates/items/item-spell-sheet.hbs b/templates/items/item-spell-sheet.hbs index 542fe38..0c9c004 100644 --- a/templates/items/item-spell-sheet.hbs +++ b/templates/items/item-spell-sheet.hbs @@ -69,6 +69,20 @@ +
  • + + +
  • + +
  • + + +
  • +