diff --git a/modules/pegasus-actor-sheet.js b/modules/pegasus-actor-sheet.js index 9699ff4..e5afece 100644 --- a/modules/pegasus-actor-sheet.js +++ b/modules/pegasus-actor-sheet.js @@ -44,7 +44,7 @@ export class PegasusActorSheet extends ActorSheet { optionsDiceList: PegasusUtility.getOptionsDiceList(), optionsLevel: PegasusUtility.getOptionsLevel(), weapons: this.actor.checkAndPrepareWeapons( duplicate(this.actor.getWeapons()) ), - armors: duplicate(this.actor.getArmors()), + armors: this.actor.checkAndPrepareArmors( duplicate(this.actor.getArmors())), shields: duplicate(this.actor.getShields()), equipments: duplicate(this.actor.getEquipments()), perks: duplicate(this.actor.getPerks()), @@ -150,12 +150,22 @@ export class PegasusActorSheet extends ActorSheet { const specId = li.data("item-id"); this.actor.rollSpec(specId); }); - + html.find('.power-roll').click((event) => { + const li = $(event.currentTarget).parents(".item"); + const powerId = li.data("item-id"); + this.actor.rollPower(powerId); + }); html.find('.weapon-roll').click((event) => { const li = $(event.currentTarget).parents(".item"); const weaponId = li.data("item-id"); this.actor.rollWeapon(weaponId); }); + html.find('.armor-roll').click((event) => { + const li = $(event.currentTarget).parents(".item"); + const armorId = li.data("item-id"); + this.actor.rollArmor(armorId); + }); + html.find('.weapon-damage-roll').click((event) => { const li = $(event.currentTarget).parents(".item"); const weaponId = li.data("item-id"); diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 47c5f8f..90bb11f 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -111,7 +111,7 @@ export class PegasusActor extends Actor { } /* -------------------------------------------- */ getArmors() { - let comp = this.data.items.filter(item => item.type == 'armor'); + let comp = duplicate(this.data.items.filter(item => item.type == 'armor') || []); return comp; } /* -------------------------------------------- */ @@ -127,12 +127,22 @@ export class PegasusActor extends Actor { let role = this.data.items.filter(item => item.type == 'role'); return role[0] ?? []; } + /* -------------------------------------------- */ + checkAndPrepareArmor(armor) { + armor.data.resistanceDice = PegasusUtility.getDiceFromLevel(armor.data.resistance); + } + /* -------------------------------------------- */ + checkAndPrepareArmors(armors) { + for (let item of armors) { + this.checkAndPrepareArmor(item); + } + return armors; + } /* -------------------------------------------- */ checkAndPrepareWeapon(weapon) { weapon.data.damageDice = PegasusUtility.getDiceFromLevel(weapon.data.damage); } - /* -------------------------------------------- */ checkAndPrepareWeapons(weapons) { for (let item of weapons) { @@ -436,37 +446,6 @@ export class PegasusActor extends Actor { } } - /* -------------------------------------------- */ - async rollMR() { - let mr = duplicate(this.data.data.mr); - if (mr) { - mr.dice = PegasusUtility.getDiceFromLevel(mr.value); - let rollData = { - rollId: randomID(16), - mode: "MR", - alias: this.name, - actorImg: this.img, - actorId: this.id, - img: this.img, - rollMode: game.settings.get("core", "rollMode"), - title: `${mr.label} `, - stat: mr, - activePerks: duplicate(this.getActivePerks()), - optionsDiceList: PegasusUtility.getOptionsDiceList(), - bonusDicesLevel: 0, - hindranceDicesLevel: 0, - otherDicesLevel: 0, - } - - this.syncRoll(rollData); - let rollDialog = await PegasusRollDialog.create(this, rollData); - console.log(rollDialog); - rollDialog.render(true); - } else { - ui.notifications.warn("MR not found !"); - } - } - /* -------------------------------------------- */ getCommonRollData() { let rollData = { @@ -530,6 +509,7 @@ export class PegasusActor extends Actor { let stat = this.getStat(statKey); if (stat) { let rollData = this.getCommonRollData() + rollData.specList = this.getRelevantSpec(armor.data.statistic) rollData.mode = "stat" rollData.title = `Stat ${stat.label}`; rollData.stat = stat; @@ -556,6 +536,24 @@ export class PegasusActor extends Actor { } } + /* -------------------------------------------- */ + async rollMR() { + let mr = duplicate(this.data.data.mr); + if (mr) { + mr.dice = PegasusUtility.getDiceFromLevel(mr.value); + + let rollData = this.getCommonRollData() + rollData.mode = "MR" + rollData.stat = mr + rollData.activePerks = duplicate(this.getActivePerks()), + rollData.specList = this.getRelevantSpec(armor.data.statistic), + + this.startRoll(rollData); + } else { + ui.notifications.warn("MR not found !"); + } + } + /* -------------------------------------------- */ async deleteAllItemsByType(itemType) { let items = this.data.items.filter(item => item.type == itemType); @@ -738,7 +736,7 @@ export class PegasusActor extends Actor { ui.notifications.warn("Technique not found !"); } } - + /* -------------------------------------------- */ updateWithTarget(rollData) { let objectDefender @@ -755,9 +753,35 @@ export class PegasusActor extends Actor { //console.log("ROLLDATA DEFENDER !!!", rollData); } } + /* -------------------------------------------- */ + async rollArmor(armorId) { + let armor = this.data.items.get(armorId) + + if (armor) { + let rollData = this.getCommonRollData() + + armor = duplicate(armor); + this.checkAndPrepareArmor(armor); + + rollData.mode = "armor" + rollData.img = armor.img + rollData.armor = armor + rollData.title = `Armor : ${armor.name}` + rollData.stat = this.getStat(armor.data.statistic) + rollData.specList = this.getRelevantSpec(armor.data.statistic) + rollData.activePerks = duplicate(this.getActivePerks()) + rollData.isResistance = true; + rollData.otherDicesLevel = armor.data.resistance + + //this.updateWithTarget(rollData); + this.startRoll(rollData); + } else { + ui.notifications.warn("Armor not found !", weaponId); + } + } /* -------------------------------------------- */ - async rollWeapon(weaponId, damage=false) { + async rollWeapon(weaponId, damage = false) { let weapon = this.data.items.get(weaponId) if (weapon) { @@ -773,7 +797,7 @@ export class PegasusActor extends Actor { rollData.stat = this.getStat(weapon.data.statistic) rollData.specList = this.getRelevantSpec(weapon.data.statistic) rollData.activePerks = duplicate(this.getActivePerks()) - if (damage) { + if (damage) { rollData.isDamage = true; rollData.otherDicesLevel = weapon.data.damage } @@ -785,4 +809,25 @@ export class PegasusActor extends Actor { } } + /* -------------------------------------------- */ + async rollPower(powerId) { + let power = this.data.items.get(powerId) + + if (power) { + let rollData = this.getCommonRollData() + power = duplicate(power); + + rollData.mode = "power" + rollData.img = power.img + rollData.power = power + rollData.title = `Power : ${power.name}` + rollData.stat = this.getStat(power.data.statistic) + rollData.specList = this.getRelevantSpec(power.data.statistic) + rollData.activePerks = duplicate(this.getActivePerks()) + this.startRoll(rollData); + } else { + ui.notifications.warn("Power not found !", powerId); + } + } + } diff --git a/modules/pegasus-roll-dialog.js b/modules/pegasus-roll-dialog.js index b283079..58ae288 100644 --- a/modules/pegasus-roll-dialog.js +++ b/modules/pegasus-roll-dialog.js @@ -16,7 +16,7 @@ export class PegasusRollDialog extends Dialog { } else if (rollData.mode == "spec") { html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-spec.html', rollData); options.height = 360; - } else if (rollData.mode == "weapon") { + } else if (rollData.mode == "weapon" || rollData.mode == "armor" || rollData.mode == "power") { html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-weapon.html', rollData); options.height = 320; } else { diff --git a/system.json b/system.json index 102c18c..e76699d 100644 --- a/system.json +++ b/system.json @@ -163,6 +163,6 @@ "templateVersion": 57, "title": "Pegasus RPG", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", - "version": "0.1.1", + "version": "0.1.2", "background" : "./images/ui/pegasus_welcome_page.webp" } diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 8a11258..a32c46e 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -259,8 +259,6 @@