From 915b89a8c4979c3dbbba04c553e1529ff6495165 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sun, 9 Jan 2022 13:23:20 +0100 Subject: [PATCH] Sync attempt --- module/actor/actor.js | 11 +++++ module/controllers/bol-rolls.js | 51 ++++++++++++---------- module/system/bol-utility.js | 9 +++- templates/chat/rolls/default-roll-card.hbs | 5 ++- 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/module/actor/actor.js b/module/actor/actor.js index 7ddc704..e02dcb8 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -133,6 +133,17 @@ export class BoLActor extends Actor { get misc() { return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && (i.data.subtype === "other" ||i.data.subtype === "container" ||i.data.subtype === "scroll" || i.data.subtype === "jewel")); } + + heroReroll( ) { + if (this.type == 'character') { + return this.data.data.resources.hero.value > 0; + } else { + if (this.data.data.type == 'adversary') { + return this.data.data.resources.hero.value > 0; + } + } + return false + } getResourcesFromType() { let resources = {}; diff --git a/module/controllers/bol-rolls.js b/module/controllers/bol-rolls.js index 6aded19..b1ae5c6 100644 --- a/module/controllers/bol-rolls.js +++ b/module/controllers/bol-rolls.js @@ -89,7 +89,7 @@ export class BoLRoll { const adv = html.find('#adv').val(); const mod = html.find('#mod').val(); let careers = html.find('#career').val(); - const career = (careers && careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); + const career = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); const isMalus = adv < 0; const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv); const attrValue = eval(`actor.data.data.attributes.${attr}.value`); @@ -158,7 +158,7 @@ export class BoLRoll { } let careers = html.find('#career').val(); - const career = (careers && careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); + const career = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); const isMalus = adv < 0; const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv); const attrValue = eval(`attackDef.attacker.data.data.attributes.${attr}.value`); @@ -206,7 +206,7 @@ export class BoLRoll { const adv = html.find('#adv').val(); const mod = html.find('#mod').val(); let careers = html.find('#career').val(); - const career = (careers && careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); + const career = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); const isMalus = adv < 0; const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv); const aptValue = eval(`actor.data.data.aptitudes.${apt}.value`); @@ -261,6 +261,7 @@ export class BoLDefaultRoll { const tplData = { actor: actor, label: this._label, + reroll: actor.heroReroll(), isSuccess: this._isSuccess, isFailure: !this._isSuccess, isCritical: this._isCritical, @@ -285,7 +286,7 @@ export class BoLAttackRoll { console.log("Attack def",this.attackDef.formula ) const r = new Roll(this.attackDef.formula); await r.roll({ "async": false }); - //await BoLUtility.showDiceSoNice(r); + await BoLUtility.showDiceSoNice(r); const activeDice = r.terms[0].results.filter(r => r.active); const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b); this._isSuccess = (r.total >= 9); @@ -297,16 +298,36 @@ export class BoLAttackRoll { flavor: msgFlavor, speaker: ChatMessage.getSpeaker({ actor: this.attackDef.attacker }), flags: { msgType: "default" } - }); + }).then( this.processResult() ); }); + } + async processDefense() { + if (this._isCritical) { + ChatMessage.create({ + alias: this.attackDef.attacker.name, + whisper: BoLUtility.getWhisperRecipientsAndGMs(this.attackDef.attacker.name), + content: await renderTemplate('systems/bol/templates/chat/rolls/attack-heroic-card.hbs', { + attackId: attackDef.id, + attacker: attackDef.attacker, + defender: attackDef.defender, + defenderWeapons: defenderWeapons, + damageTotal: attackDef.damageRoll.total + }) + }) + } else { + BoLUtility.sendAttackSuccess( this.attackDef); + } + } + + async processResult( ) { if (this._isSuccess) { let attrDamage = this.attackDef.weapon.data.data.properties.damageAttribute; let weaponFormula = BoLUtility.getDamageFormula(this.attackDef.weapon.data.data.properties.damage) let damageFormula = weaponFormula + "+" + this.attackDef.attacker.data.data.attributes[attrDamage].value; this.damageRoll = new Roll(damageFormula); await this.damageRoll.roll({ "async": false }); - //await BoLUtility.showDiceSoNice(this.damageRoll); + await BoLUtility.showDiceSoNice(this.damageRoll); // Update attackDef object this.attackDef.damageFormula = damageFormula; this.attackDef.damageRoll = this.damageRoll; @@ -317,23 +338,8 @@ export class BoLAttackRoll { flavor: msgFlavor, speaker: ChatMessage.getSpeaker({ actor: this.attackDef.attacker }), flags: { msgType: "default" } - }); + }).then( this.processDefense() ); }); - if (this._isCritical) { - ChatMessage.create({ - alias: this.attackDef.attacker.name, - whisper: BoLUtility.getWhisperRecipientsAndGMs(this.attackDef.attacker.name), - content: await renderTemplate('systems/bol/templates/chat/rolls/attack-heroic-card.hbs', { - attackId: attackDef.id, - attacker: attackDef.attacker, - defender: attackDef.defender, - defenderWeapons: defenderWeapons, - damageTotal: attackDef.damageRoll.total - }) - }) - } else { - BoLUtility.sendAttackSuccess( this.attackDef); - } } } @@ -354,6 +360,7 @@ export class BoLAttackRoll { const tplData = { actor: actor, label: this._label, + reroll: actor.heroReroll(), isSuccess: this._isSuccess, isFailure: !this._isSuccess, isCritical: this._isCritical, diff --git a/module/system/bol-utility.js b/module/system/bol-utility.js index 8037a87..fa364ac 100644 --- a/module/system/bol-utility.js +++ b/module/system/bol-utility.js @@ -111,6 +111,7 @@ export class BoLUtility { static async chatListeners(html) { // Damage handling html.on("click", '.damage-increase', event => { + event.preventDefault(); let attackId = event.currentTarget.attributes['data-attack-id'].value; let damageMode = event.currentTarget.attributes['data-damage-mode'].value; if ( game.user.isGM) { @@ -120,7 +121,13 @@ export class BoLUtility { } }); + html.on("click", '.hero-reroll', event => { + event.preventDefault(); + ui.notifications.warn("Not implemented up to now"); + } ); + html.on("click", '.damage-handling', event => { + event.preventDefault(); let attackId = event.currentTarget.attributes['data-attack-id'].value; let defenseMode = event.currentTarget.attributes['data-defense-mode'].value; let weaponId = (event.currentTarget.attributes['data-weapon-id']) ? event.currentTarget.attributes['data-weapon-id'].value : -1 @@ -172,7 +179,7 @@ export class BoLUtility { if (attackDef.defenseDone) return; // ?? Why ??? attackDef.defenseDone = true attackDef.defenseMode = defenseMode; - + if (defenseMode == 'damage-with-armor') { let armorFormula = attackDef.defender.getArmorFormula(); attackDef.rollArmor = new Roll(armorFormula) diff --git a/templates/chat/rolls/default-roll-card.hbs b/templates/chat/rolls/default-roll-card.hbs index 4d8e0d2..2cee17f 100644 --- a/templates/chat/rolls/default-roll-card.hbs +++ b/templates/chat/rolls/default-roll-card.hbs @@ -13,7 +13,10 @@

 {{localize "BOL.ui.failure"}}...

{{/if}} {{/if}} -

{{description}} +

{{description}}

+{{#if reroll}} +Relancer! +{{/if}} {{!#if hasDescription}}