fvtt-pegasus-rpg/modules/pegasus-roll-dialog.js

287 lines
9.5 KiB
JavaScript
Raw Normal View History

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);
2022-08-14 15:27:54 +02:00
this.actor = actor
this.rollData = rollData
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
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-09-28 20:14:24 +02:00
if (effect.type == 'effect' && effect.effect) {
2022-07-10 10:22:04 +02:00
let effectData = effect.effect
2022-09-04 09:58:51 +02:00
level = effectData.system.effectlevel
genre = effectData.system.genre
effectData.system.isUsed = toggled
if (effectData.system.reducedicevalue || effectData.system.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-30 22:49:40 +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-10-05 09:58:07 +02:00
if ( effect.specList) {
this.rollData.specList = duplicate(effect.specList)
}
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-08-14 15:27:54 +02:00
this.rollData.weapon = duplicate(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-09-21 16:54:34 +02:00
/* -------------------------------------------- */
manageVehicleWeapon( weaponIdx, toggled) {
let weapon = this.rollData.vehicleWeapons[weaponIdx]
if (weapon) {
this.rollData.weapon = duplicate(weapon)
if (toggled) {
this.rollData.weaponName = weapon.weapon.name
} else {
this.rollData.weaponName = undefined
}
weapon.applied = toggled
}
PegasusUtility.updateDamageDicePool(this.rollData)
}
2022-09-25 09:26:12 +02:00
/* -------------------------------------------- */
manageVehicleShield( shieldIdx, toggled) {
let shield = this.rollData.vehicleShieldList[shieldIdx]
if (shield) {
this.rollData.shield = duplicate(shield)
if (toggled) {
this.rollData.shieldName = shield.name
} else {
this.rollData.shieldName = undefined
}
shield.applied = toggled
}
PegasusUtility.updateArmorDicePool(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-09-04 09:58:51 +02:00
if (equip.equip.system.bonusdice) {
2022-07-10 10:22:04 +02:00
idVal = "#bonusDicesLevel"
2022-01-28 17:27:01 +01:00
}
2022-09-04 09:58:51 +02:00
if (equip.equip.system.statdice) {
2022-07-10 10:22:04 +02:00
idVal = "#statDicesLevel"
2022-01-28 17:27:01 +01:00
}
2022-09-04 09:58:51 +02:00
if (equip.equip.system.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-09-04 09:58:51 +02:00
this.rollData.specDicesLevel = spec.system.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-07-28 18:45:04 +02:00
this.rollData.specDicesLevel = 0
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-07-28 18:45:04 +02:00
if (event.currentTarget.value == "none") {
this.rollData.specDicesLevel = 0
} else {
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)
})
2022-09-21 16:54:34 +02:00
html.find('.vehicle-weapon-clicked').change((event) => {
let toggled = event.currentTarget.checked
let weaponIdx = $(event.currentTarget).data("vehicle-weapon-idx")
this.manageVehicleWeapon(weaponIdx, toggled)
this.refreshDialog()
})
2022-09-25 09:26:12 +02:00
html.find('.vehicle-shield-clicked').change((event) => {
let toggled = event.currentTarget.checked
let shieldIdx = $(event.currentTarget).data("vehicle-shield-idx")
this.manageVehicleShield(shieldIdx, toggled)
this.refreshDialog()
})
2022-09-27 17:18:41 +02:00
html.find('#modifiers').change(async (event) => {
let diceKey = event.currentTarget.value
if ( !diceKey.includes("none")) {
let diceLevel = PegasusUtility.getLevelFromDice(diceKey)
PegasusUtility.addDicePool(this.rollData, diceKey, diceLevel)
this.refreshDialog()
}
})
2022-07-10 10:22:04 +02:00
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
}
}