2021-12-02 07:38:59 +01:00
|
|
|
import { PegasusUtility } from "./pegasus-utility.js";
|
|
|
|
|
|
|
|
export class PegasusRollDialog extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async create(actor, rollData ) {
|
|
|
|
|
2022-01-28 10:05:54 +01:00
|
|
|
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);
|
|
|
|
|
2021-12-02 07:38:59 +01:00
|
|
|
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: '<i class="fas fa-check"></i>',
|
|
|
|
label: "Roll !",
|
|
|
|
callback: () => { this.roll() }
|
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
icon: '<i class="fas fa-times"></i>',
|
|
|
|
label: "Cancel",
|
|
|
|
callback: () => { this.close() }
|
|
|
|
} },
|
|
|
|
close: close
|
|
|
|
}
|
|
|
|
|
|
|
|
super(conf, options);
|
|
|
|
|
|
|
|
this.actor = actor;
|
|
|
|
this.rollData = rollData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
roll () {
|
2021-12-02 20:18:21 +01:00
|
|
|
PegasusUtility.rollPegasus( this.rollData )
|
2021-12-02 07:38:59 +01:00
|
|
|
}
|
|
|
|
|
2022-01-28 10:05:54 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
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
|
|
|
|
if (effectData.data.bonusdice) {
|
|
|
|
idVal = "#bonusDicesLevel"
|
|
|
|
}
|
2022-01-28 17:27:01 +01:00
|
|
|
if (effectData.data.reducedicevalue || effectData.data.statdice) {
|
2022-01-28 10:05:54 +01:00
|
|
|
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') {
|
2022-01-29 18:22:27 +01:00
|
|
|
newLevel += Number(level)
|
2022-01-28 10:05:54 +01:00
|
|
|
}else {
|
2022-01-29 18:22:27 +01:00
|
|
|
newLevel -= Number(level)
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
|
|
|
}else {
|
|
|
|
if ( genre == 'positive') {
|
2022-01-29 18:22:27 +01:00
|
|
|
newLevel -= Number(level)
|
2022-01-28 10:05:54 +01:00
|
|
|
}else {
|
2022-01-29 18:22:27 +01:00
|
|
|
newLevel += Number(level)
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
newLevel = (newLevel<0) ? 0 : newLevel
|
|
|
|
$(idVal).val(newLevel)
|
|
|
|
}
|
|
|
|
//console.log("Effect", effect, toggled)
|
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())
|
|
|
|
this.rollData.otherDicesLevel = Number($('#otherDicesLevel').val())
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
manageArmors( armorIdx, toggled) {
|
|
|
|
let armor = this.rollData.armorsList[armorIdx]
|
|
|
|
if (armor) {
|
|
|
|
armor.applied = toggled
|
|
|
|
if (armor.type == 'other' ) {
|
|
|
|
if (toggled) {
|
2022-01-29 18:22:27 +01:00
|
|
|
this.rollData.otherDicesLevel += Number(armor.value)
|
2022-01-28 10:05:54 +01:00
|
|
|
} else {
|
2022-01-29 18:22:27 +01:00
|
|
|
this.rollData.otherDicesLevel -= Number(armor.value)
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.otherDicesLevel = (this.rollData.otherDicesLevel<0) ? 0 : this.rollData.otherDicesLevel
|
|
|
|
}
|
|
|
|
$("#otherDicesLevel").val(this.rollData.otherDicesLevel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("Armor", armorIdx, toggled)
|
|
|
|
}
|
|
|
|
|
2022-01-28 17:27:01 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
manageWeapons( weaponIdx, toggled) {
|
|
|
|
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-01-28 18:15:28 +01:00
|
|
|
if (weapon.type == 'damage' || weapon.type == 'enhanced' ) {
|
2022-01-28 17:27:01 +01:00
|
|
|
if (toggled) {
|
|
|
|
this.rollData.otherDicesLevel += Number(weapon.value)
|
|
|
|
} else {
|
2022-01-28 22:14:13 +01:00
|
|
|
this.rollData.weaponName = undefined
|
2022-01-28 17:27:01 +01:00
|
|
|
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
|
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())
|
|
|
|
this.rollData.otherDicesLevel = Number($('#otherDicesLevel').val())
|
2022-01-28 17:27:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 07:38:59 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
var dialog = this;
|
|
|
|
function onLoad() {
|
|
|
|
}
|
|
|
|
$(function () { onLoad(); });
|
2022-01-11 23:35:23 +01:00
|
|
|
|
|
|
|
html.find('#specList').change((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)
|
|
|
|
if ( spec) {
|
|
|
|
this.rollData.specDiceLevel = spec.data.level
|
|
|
|
$('#specDicesLevel').val(this.rollData.specDiceLevel)
|
2022-01-28 11:41:19 +01:00
|
|
|
} else {
|
|
|
|
$('#specDicesLevel').val(0)
|
2022-01-28 10:05:54 +01:00
|
|
|
}
|
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
|
|
|
});
|
|
|
|
html.find('#specDicesLevel').change((event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.specDicesLevel = Number(event.currentTarget.value)
|
2022-01-13 16:13:00 +01:00
|
|
|
});
|
2021-12-02 20:18:21 +01:00
|
|
|
html.find('#bonusDicesLevel').change((event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.bonusDicesLevel = Number(event.currentTarget.value)
|
2021-12-02 07:38:59 +01:00
|
|
|
});
|
2021-12-02 20:18:21 +01:00
|
|
|
html.find('#hindranceDicesLevel').change((event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.hindranceDicesLevel = Number(event.currentTarget.value)
|
2021-12-02 07:38:59 +01:00
|
|
|
});
|
2021-12-02 20:18:21 +01:00
|
|
|
html.find('#otherDicesLevel').change((event) => {
|
2022-01-28 10:05:54 +01:00
|
|
|
this.rollData.otherDicesLevel = Number(event.currentTarget.value)
|
2021-12-02 07:38:59 +01:00
|
|
|
});
|
2022-01-28 10:05:54 +01:00
|
|
|
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)
|
|
|
|
});
|
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")
|
|
|
|
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)
|
|
|
|
});
|
2022-01-28 10:05:54 +01:00
|
|
|
|
|
|
|
|
2021-12-02 07:38:59 +01:00
|
|
|
}
|
|
|
|
}
|