import { PegasusUtility } from "./pegasus-utility.js"; export class PegasusRollDialog extends Dialog { /* -------------------------------------------- */ static async create(actor, rollData ) { let options = { classes: ["WotGdialog"], width: 620, height: 380, 'z-index': 99999 }; let html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-generic.html', rollData); return new PegasusRollDialog(actor, rollData, html, options ); } /* -------------------------------------------- */ constructor(actor, rollData, html, options, close = undefined) { let conf = { title: (rollData.mode == "skill") ? "Skill" : "Roll", content: html, buttons: { roll: { icon: '', label: "Roll !", callback: () => { this.roll() } }, cancel: { icon: '', label: "Cancel", callback: () => { this.close() } } }, close: close } super(conf, options); this.actor = actor; this.rollData = rollData; } /* -------------------------------------------- */ roll () { PegasusUtility.rollPegasus( this.rollData ) } /* -------------------------------------------- */ manageEffects( effectIdx, toggled) { let effect = this.rollData.effectsList[effectIdx] if (effect) { effect.applied = toggled let level, genre, idVal if (effect.type == 'hindrance' ) { level = effect.value genre = 'positive' idVal = "#hindranceDicesLevel" } if (effect.type == 'effect' ) { let effectData = effect.effect level = effectData.data.effectlevel genre = effectData.data.genre effectData.data.isUsed = toggled if (effectData.data.bonusdice) { idVal = "#bonusDicesLevel" } if (effectData.data.reducedicevalue || effectData.data.statdice) { idVal = "#statDicesLevel" } if (effectData.data.otherdice) { idVal = "#otherDicesLevel" } if (effectData.data.hindrance) { idVal = "#hindranceDicesLevel" genre = 'positive' // Dynamic fix } } // Now process the dice level update let newLevel = Number($(idVal).val()) console.log("Ongoing", newLevel, toggled, idVal ) if (toggled) { if ( genre == 'positive') { newLevel += Number(level) }else { newLevel -= Number(level) } }else { if ( genre == 'positive') { newLevel -= Number(level) }else { newLevel += Number(level) } } newLevel = (newLevel<0) ? 0 : newLevel $(idVal).val(newLevel) } //console.log("Effect", effect, toggled) this.rollData.statDicesLevel = Number($('#statDicesLevel').val()) this.rollData.specDicesLevel = Number($('#specDicesLevel').val()) this.rollData.bonusDicesLevel = Number($('#bonusDicesLevel').val()) this.rollData.hindranceDicesLevel = Number($('#hindranceDicesLevel').val()) this.rollData.otherDicesLevel = Number($('#otherDicesLevel').val()) } /* -------------------------------------------- */ manageArmors( armorIdx, toggled) { let armor = this.rollData.armorsList[armorIdx] if (armor) { armor.applied = toggled if (armor.type == 'other' ) { if (toggled) { this.rollData.otherDicesLevel += Number(armor.value) } else { this.rollData.otherDicesLevel -= Number(armor.value) this.rollData.otherDicesLevel = (this.rollData.otherDicesLevel<0) ? 0 : this.rollData.otherDicesLevel } $("#otherDicesLevel").val(this.rollData.otherDicesLevel) } } console.log("Armor", armorIdx, toggled) } /* -------------------------------------------- */ manageWeapons( weaponIdx, toggled) { let weapon = this.rollData.weaponsList[weaponIdx] if (weapon) { if (toggled) { this.rollData.weaponName = weapon.weapon.name } else { this.rollData.weaponName = undefined } weapon.applied = toggled if (weapon.type == 'damage' || weapon.type == 'enhanced' ) { if (toggled) { this.rollData.otherDicesLevel += Number(weapon.value) } else { this.rollData.weaponName = undefined this.rollData.otherDicesLevel -= Number(weapon.value) this.rollData.otherDicesLevel = (this.rollData.otherDicesLevel<0) ? 0 : this.rollData.otherDicesLevel } $("#otherDicesLevel").val(this.rollData.otherDicesLevel) } } console.log("Weapon", weaponIdx, toggled, this.rollData.otherDicesLevel, weapon) } /* -------------------------------------------- */ manageEquip( equipIdx, toggled) { let equip = this.rollData.equipmentsList[equipIdx] if (equip) { equip.applied = toggled let idVal = "#otherDicesLevel" // Default if (equip.equip.data.bonusdice) { idVal = "#bonusDicesLevel" } if (equip.equip.data.statdice) { idVal = "#statDicesLevel" } if (equip.equip.data.otherdice) { idVal = "#otherDicesLevel" } let newLevel = Number($(idVal).val()) if (toggled) { newLevel += Number(equip.value) } else { newLevel -= Number(equip.value) } newLevel = (newLevel <0) ? 0 : newLevel $(idVal).val(newLevel) // Then refresh this.rollData.statDicesLevel = Number($('#statDicesLevel').val()) this.rollData.specDicesLevel = Number($('#specDicesLevel').val()) this.rollData.bonusDicesLevel = Number($('#bonusDicesLevel').val()) this.rollData.hindranceDicesLevel = Number($('#hindranceDicesLevel').val()) this.rollData.otherDicesLevel = Number($('#otherDicesLevel').val()) } } /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); var dialog = this; function onLoad() { } $(function () { onLoad(); }); html.find('#specList').change(async (event) => { this.rollData.selectedSpec = event.currentTarget.value let spec = this.rollData.specList.find(item => item._id == this.rollData.selectedSpec) if ( spec) { this.rollData.specDiceLevel = spec.data.level this.rollData.specName = spec.name $('#specDicesLevel').val(this.rollData.specDiceLevel) } else { this.rollData.specName = undefined $('#specDicesLevel').val(0) } const content = await renderTemplate("systems/fvtt-pegasus-rpg/templates/roll-dialog-generic.html", this.rollData) this.data.content = content this.render(true) }); html.find('#statDicesLevel').change((event) => { this.rollData.statDicesLevel = Number(event.currentTarget.value) }); html.find('#specDicesLevel').change((event) => { this.rollData.specDicesLevel = Number(event.currentTarget.value) }); html.find('#bonusDicesLevel').change((event) => { this.rollData.bonusDicesLevel = Number(event.currentTarget.value) }); html.find('#hindranceDicesLevel').change((event) => { this.rollData.hindranceDicesLevel = Number(event.currentTarget.value) }); html.find('#otherDicesLevel').change((event) => { this.rollData.otherDicesLevel = Number(event.currentTarget.value) }); html.find('.effect-clicked').change((event) => { let toggled = event.currentTarget.checked let effectIdx = $(event.currentTarget).data("effect-idx") this.manageEffects( effectIdx, toggled) }); html.find('.armor-clicked').change((event) => { let toggled = event.currentTarget.checked let armorIdx = $(event.currentTarget).data("armor-idx") this.manageArmors( armorIdx, toggled) }); html.find('.weapon-clicked').change((event) => { let toggled = event.currentTarget.checked let weaponIdx = $(event.currentTarget).data("weapon-idx") this.manageWeapons( weaponIdx, toggled) }); html.find('.equip-clicked').change((event) => { let toggled = event.currentTarget.checked let equipIdx = $(event.currentTarget).data("equip-idx") this.manageEquip( equipIdx, toggled) }); } }