2021-12-02 07:38:59 +01:00
|
|
|
import { PegasusUtility } from "./pegasus-utility.js";
|
|
|
|
|
|
|
|
export class PegasusRollDialog extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-07-10 10:22:04 +02:00
|
|
|
static async create(actor, rollData) {
|
2021-12-02 07:38:59 +01:00
|
|
|
|
2022-07-13 22:47:07 +02:00
|
|
|
let options = { classes: ["PegasusDialog"], width: 620, height: 480, 'z-index': 99999 };
|
2022-01-28 10:05:54 +01:00
|
|
|
let html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-generic.html', rollData);
|
|
|
|
|
2022-07-10 10:22:04 +02:00
|
|
|
return new PegasusRollDialog(actor, rollData, html, options);
|
2021-12-02 07:38:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
constructor(actor, rollData, html, options, close = undefined) {
|
|
|
|
let conf = {
|
|
|
|
title: (rollData.mode == "skill") ? "Skill" : "Roll",
|
|
|
|
content: html,
|
2022-07-10 10:22:04 +02:00
|
|
|
buttons: {
|
2021-12-02 07:38:59 +01:00
|
|
|
roll: {
|
2022-07-10 10:22:04 +02:00
|
|
|
icon: '<i class="fas fa-check"></i>',
|
|
|
|
label: "Roll !",
|
|
|
|
callback: () => { this.roll() }
|
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
icon: '<i class="fas fa-times"></i>',
|
|
|
|
label: "Cancel",
|
|
|
|
callback: () => { this.close() }
|
|
|
|
}
|
|
|
|
},
|
2021-12-02 07:38:59 +01:00
|
|
|
close: close
|
|
|
|
}
|
|
|
|
|
|
|
|
super(conf, options);
|
|
|
|
|
|
|
|
this.actor = actor;
|
|
|
|
this.rollData = rollData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-07-10 10:22:04 +02:00
|
|
|
roll() {
|
|
|
|
PegasusUtility.rollPegasus(this.rollData)
|
2021-12-02 07:38:59 +01:00
|
|
|
}
|
|
|
|
|
2022-01-28 10:05:54 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-07-10 10:22:04 +02:00
|
|
|
manageEffects(effectIdx, toggled) {
|
2022-01-28 10:05:54 +01:00
|
|
|
let effect = this.rollData.effectsList[effectIdx]
|
|
|
|
if (effect) {
|
|
|
|
effect.applied = toggled
|
|
|
|
|
2022-07-19 00:18:46 +02:00
|
|
|
let level, genre, idVal, key
|
2022-07-10 10:22:04 +02:00
|
|
|
if (effect.type == 'effect') {
|
|
|
|
let effectData = effect.effect
|
2022-01-28 10:05:54 +01:00
|
|
|
level = effectData.data.effectlevel
|
|
|
|
genre = effectData.data.genre
|
2022-02-10 19:03:09 +01:00
|
|
|
effectData.data.isUsed = toggled
|
2022-01-28 17:27:01 +01:00
|
|
|
if (effectData.data.reducedicevalue || effectData.data.statdice) {
|
2022-07-10 10:22:04 +02:00
|
|
|
idVal = "#statDicesLevel"
|
2022-07-19 00:18:46 +02:00
|
|
|
key = "statLevelBonus"
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now process the dice level update
|
2022-07-10 10:22:04 +02:00
|
|
|
if (idVal) {
|
2022-07-19 00:18:46 +02:00
|
|
|
let newLevel = Number($(idVal).val())
|
2022-07-10 10:22:04 +02:00
|
|
|
if (toggled) {
|
2022-07-19 00:18:46 +02:00
|
|
|
if (genre == 'positive') {
|
2022-07-10 10:22:04 +02:00
|
|
|
newLevel += Number(level)
|
2022-07-19 00:18:46 +02:00
|
|
|
this.rollData[key] += Number(level)
|
2022-07-10 10:22:04 +02:00
|
|
|
} else {
|
|
|
|
newLevel -= Number(level)
|
2022-07-19 00:18:46 +02:00
|
|
|
this.rollData[key] -= Number(level)
|
2022-07-10 10:22:04 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (genre == 'positive') {
|
|
|
|
newLevel -= Number(level)
|
2022-07-19 00:18:46 +02:00
|
|
|
this.rollData[key] -= Number(level)
|
2022-07-10 10:22:04 +02:00
|
|
|
} else {
|
|
|
|
newLevel += Number(level)
|
2022-07-19 00:18:46 +02:00
|
|
|
this.rollData[key] += Number(level)
|
2022-07-10 10:22:04 +02:00
|
|
|
}
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
2022-07-10 10:22:04 +02:00
|
|
|
newLevel = (newLevel < 0) ? 0 : newLevel
|
|
|
|
$(idVal).val(newLevel)
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//console.log("Effect", effect, toggled)
|
2022-01-29 18:22:27 +01:00
|
|
|
this.rollData.statDicesLevel = Number($('#statDicesLevel').val())
|
2022-07-20 23:53:37 +02:00
|
|
|
PegasusUtility.updateStatDicePool(this.rollData)
|
2022-07-10 10:22:04 +02:00
|
|
|
PegasusUtility.updateSpecDicePool(this.rollData)
|
2022-07-13 22:47:07 +02:00
|
|
|
PegasusUtility.updateDamageDicePool(this.rollData)
|
2022-07-10 10:22:04 +02:00
|
|
|
PegasusUtility.updateEffectsBonusDice(this.rollData)
|
2022-07-19 20:51:48 +02:00
|
|
|
PegasusUtility.updateHindranceBonusDice(this.rollData)
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-07-10 10:22:04 +02:00
|
|
|
manageArmors(armorIdx, toggled) {
|
2022-01-28 10:05:54 +01:00
|
|
|
let armor = this.rollData.armorsList[armorIdx]
|
|
|
|
if (armor) {
|
|
|
|
armor.applied = toggled
|
|
|
|
}
|
2022-07-10 10:22:04 +02:00
|
|
|
console.log("Armor", armorIdx, toggled)
|
2022-07-19 20:51:48 +02:00
|
|
|
PegasusUtility.updateArmorDicePool(this.rollData)
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
|
|
|
|
2022-01-28 17:27:01 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-07-10 10:22:04 +02:00
|
|
|
manageWeapons(weaponIdx, toggled) {
|
2022-01-28 17:27:01 +01:00
|
|
|
let weapon = this.rollData.weaponsList[weaponIdx]
|
|
|
|
if (weapon) {
|
2022-01-28 22:14:13 +01:00
|
|
|
if (toggled) {
|
|
|
|
this.rollData.weaponName = weapon.weapon.name
|
|
|
|
} else {
|
|
|
|
this.rollData.weaponName = undefined
|
|
|
|
}
|
2022-01-28 17:27:01 +01:00
|
|
|
weapon.applied = toggled
|
|
|
|
}
|
2022-07-19 20:51:48 +02:00
|
|
|
console.log("Weapon", weaponIdx, toggled, weapon)
|
|
|
|
PegasusUtility.updateDamageDicePool(this.rollData)
|
2022-01-28 17:27:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-07-10 10:22:04 +02:00
|
|
|
manageEquip(equipIdx, toggled) {
|
2022-01-28 17:27:01 +01:00
|
|
|
let equip = this.rollData.equipmentsList[equipIdx]
|
|
|
|
if (equip) {
|
|
|
|
equip.applied = toggled
|
2022-07-13 22:47:07 +02:00
|
|
|
let idVal = "#damageDiceLevel" // Default
|
2022-01-28 17:27:01 +01:00
|
|
|
if (equip.equip.data.bonusdice) {
|
2022-07-10 10:22:04 +02:00
|
|
|
idVal = "#bonusDicesLevel"
|
2022-01-28 17:27:01 +01:00
|
|
|
}
|
|
|
|
if (equip.equip.data.statdice) {
|
2022-07-10 10:22:04 +02:00
|
|
|
idVal = "#statDicesLevel"
|
2022-01-28 17:27:01 +01:00
|
|
|
}
|
|
|
|
if (equip.equip.data.otherdice) {
|
2022-07-13 22:47:07 +02:00
|
|
|
idVal = "#damageDiceLevel"
|
2022-01-28 17:27:01 +01:00
|
|
|
}
|
|
|
|
let newLevel = Number($(idVal).val())
|
|
|
|
if (toggled) {
|
2022-07-10 10:22:04 +02:00
|
|
|
newLevel += Number(equip.value)
|
|
|
|
} else {
|
2022-01-28 17:27:01 +01:00
|
|
|
newLevel -= Number(equip.value)
|
|
|
|
}
|
2022-07-10 10:22:04 +02:00
|
|
|
newLevel = (newLevel < 0) ? 0 : newLevel
|
2022-01-28 17:27:01 +01:00
|
|
|
$(idVal).val(newLevel)
|
|
|
|
// Then refresh
|
2022-01-29 18:22:27 +01:00
|
|
|
this.rollData.statDicesLevel = Number($('#statDicesLevel').val())
|
|
|
|
this.rollData.specDicesLevel = Number($('#specDicesLevel').val())
|
|
|
|
this.rollData.bonusDicesLevel = Number($('#bonusDicesLevel').val())
|
|
|
|
this.rollData.hindranceDicesLevel = Number($('#hindranceDicesLevel').val())
|
2022-01-28 17:27:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-10 10:22:04 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async refreshDialog() {
|
|
|
|
PegasusUtility.updateSpecDicePool(this.rollData)
|
|
|
|
const content = await renderTemplate("systems/fvtt-pegasus-rpg/templates/roll-dialog-generic.html", this.rollData)
|
|
|
|
this.data.content = content
|
|
|
|
this.render(true)
|
|
|
|
}
|
|
|
|
|
2021-12-02 07:38:59 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
var dialog = this;
|
|
|
|
function onLoad() {
|
|
|
|
}
|
|
|
|
$(function () { onLoad(); });
|
2022-07-10 10:22:04 +02:00
|
|
|
|
|
|
|
html.find('#specList').change(async (event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.selectedSpec = event.currentTarget.value
|
|
|
|
let spec = this.rollData.specList.find(item => item._id == this.rollData.selectedSpec)
|
2022-07-10 10:22:04 +02:00
|
|
|
if (spec) {
|
2022-03-14 14:09:26 +01:00
|
|
|
this.rollData.specDicesLevel = spec.data.level
|
2022-02-16 12:14:34 +01:00
|
|
|
this.rollData.specName = spec.name
|
2022-03-14 14:09:26 +01:00
|
|
|
$('#specDicesLevel').val(this.rollData.specDicesLevel)
|
2022-01-28 11:41:19 +01:00
|
|
|
} else {
|
2022-02-16 12:14:34 +01:00
|
|
|
this.rollData.specName = undefined
|
2022-01-28 11:41:19 +01:00
|
|
|
$('#specDicesLevel').val(0)
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
2022-07-10 10:22:04 +02:00
|
|
|
PegasusUtility.updateSpecDicePool(this.rollData)
|
|
|
|
this.refreshDialog()
|
2022-01-11 23:35:23 +01:00
|
|
|
});
|
2022-01-13 16:13:00 +01:00
|
|
|
html.find('#statDicesLevel').change((event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.statDicesLevel = Number(event.currentTarget.value)
|
2022-01-13 16:13:00 +01:00
|
|
|
});
|
2022-07-19 00:18:46 +02:00
|
|
|
html.find('#specDicesLevel').change(async (event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.specDicesLevel = Number(event.currentTarget.value)
|
2022-07-10 10:22:04 +02:00
|
|
|
PegasusUtility.updateSpecDicePool(this.rollData)
|
|
|
|
this.refreshDialog()
|
2022-01-13 16:13:00 +01:00
|
|
|
});
|
2022-07-10 10:22:04 +02:00
|
|
|
html.find('.effect-clicked').change(async (event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
let toggled = event.currentTarget.checked
|
|
|
|
let effectIdx = $(event.currentTarget).data("effect-idx")
|
2022-07-10 10:22:04 +02:00
|
|
|
this.manageEffects(effectIdx, toggled)
|
|
|
|
this.refreshDialog()
|
2022-01-28 10:05:54 +01:00
|
|
|
});
|
|
|
|
html.find('.armor-clicked').change((event) => {
|
|
|
|
let toggled = event.currentTarget.checked
|
|
|
|
let armorIdx = $(event.currentTarget).data("armor-idx")
|
2022-07-10 10:22:04 +02:00
|
|
|
this.manageArmors(armorIdx, toggled)
|
2022-07-19 20:51:48 +02:00
|
|
|
this.refreshDialog()
|
2022-01-28 10:05:54 +01:00
|
|
|
});
|
2022-01-28 17:27:01 +01:00
|
|
|
html.find('.weapon-clicked').change((event) => {
|
|
|
|
let toggled = event.currentTarget.checked
|
|
|
|
let weaponIdx = $(event.currentTarget).data("weapon-idx")
|
2022-07-10 10:22:04 +02:00
|
|
|
this.manageWeapons(weaponIdx, toggled)
|
2022-07-19 20:51:48 +02:00
|
|
|
this.refreshDialog()
|
2022-01-28 17:27:01 +01:00
|
|
|
});
|
|
|
|
html.find('.equip-clicked').change((event) => {
|
|
|
|
let toggled = event.currentTarget.checked
|
|
|
|
let equipIdx = $(event.currentTarget).data("equip-idx")
|
2022-07-10 10:22:04 +02:00
|
|
|
this.manageEquip(equipIdx, toggled)
|
|
|
|
})
|
|
|
|
|
|
|
|
html.find('.pool-add-dice').click(async (event) => {
|
|
|
|
let diceKey = $(event.currentTarget).data("dice-key")
|
2022-07-19 00:18:46 +02:00
|
|
|
let diceLevel = $(event.currentTarget).data("dice-level")
|
|
|
|
PegasusUtility.addDicePool(this.rollData, diceKey, diceLevel)
|
2022-07-10 10:22:04 +02:00
|
|
|
this.refreshDialog()
|
|
|
|
})
|
|
|
|
html.find('.pool-remove-dice').click(async (event) => {
|
|
|
|
let idx = $(event.currentTarget).data("dice-idx")
|
2022-07-19 00:18:46 +02:00
|
|
|
PegasusUtility.removeFromDicePool(this.rollData, idx)
|
2022-07-10 10:22:04 +02:00
|
|
|
this.refreshDialog()
|
|
|
|
})
|
2022-07-19 00:18:46 +02:00
|
|
|
|
2022-07-10 10:22:04 +02:00
|
|
|
|
2021-12-02 07:38:59 +01:00
|
|
|
}
|
|
|
|
}
|