diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index bbb1a85..20d575f 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -477,7 +477,7 @@ export class PegasusActor extends Actor { effects.push(item.id) } } - if (effects.length) { + if (effects.length > 0) { await this.deleteEmbeddedDocuments('Item', effects) } } @@ -491,12 +491,18 @@ export class PegasusActor extends Actor { item = this.items.get(itemId) // Refresh if (item.data.data.nbuse == "next1action" && item.data.data.used1) { this.cleanPerkEffects(itemId) + await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false }, + { _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready } if (item.data.data.nbuse == "next2action" && item.data.data.used1 && item.data.data.used2) { this.cleanPerkEffects(itemId) + await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false }, + { _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready } if (item.data.data.nbuse == "next3action" && item.data.data.used1 && item.data.data.used2 && item.data.data.used3) { this.cleanPerkEffects(itemId) + await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false }, + { _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready } } } @@ -519,8 +525,10 @@ export class PegasusActor extends Actor { let updateOK = true if (status == "ready") { + console.log("Cleaning effects") this.cleanPerkEffects(itemId) - await this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.used1': false, 'data.used3': false, 'data.used3': false }] ) // Reset on Ready + await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false }, + { _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready if (item.data.data.features.nrgcost.flag) { let nrg = duplicate(this.data.data.nrg) nrg.activated -= item.data.data.features.nrgcost.value @@ -529,17 +537,20 @@ export class PegasusActor extends Actor { } if (item.data.data.features.bonushealth.flag) { let health = duplicate(this.data.data.secondary.health) - health.bonus -= Number(item.data.data.features.bonushealth.value) || 0 + health.value -= Number(item.data.data.features.bonushealth.value) || 0 + health.max -= Number(item.data.data.features.bonushealth.value) || 0 this.update({ 'data.secondary.health': health }) } if (item.data.data.features.bonusdelirium.flag) { let delirium = duplicate(this.data.data.secondary.delirium) - delirium.bonus -= Number(item.data.data.features.bonusdelirium.value) || 0 + delirium.value -= Number(item.data.data.features.bonusdelirium.value) || 0 + delirium.max -= Number(item.data.data.features.bonusdelirium.value) || 0 this.update({ 'data.secondary.delirium': delirium }) } if (item.data.data.features.bonusnrg.flag) { let nrg = duplicate(this.data.data.nrg) - nrg.mod -= Number(item.data.data.features.bonusnrg.value) || 0 + nrg.value -= Number(item.data.data.features.bonusnrg.value) || 0 + nrg.max -= Number(item.data.data.features.bonusnrg.value) || 0 this.update({ 'data.nrg': nrg }) } this.disableWeaverPerk(item) @@ -570,17 +581,20 @@ export class PegasusActor extends Actor { } if (item.data.data.features.bonushealth.flag) { let health = duplicate(this.data.data.secondary.health) - health.bonus += Number(item.data.data.features.bonushealth.value) || 0 + health.value += Number(item.data.data.features.bonushealth.value) || 0 + health.max += Number(item.data.data.features.bonushealth.value) || 0 this.update({ 'data.secondary.health': health }) } if (item.data.data.features.bonusdelirium.flag) { let delirium = duplicate(this.data.data.secondary.delirium) - delirium.bonus += Number(item.data.data.features.bonusdelirium.value) || 0 + delirium.value += Number(item.data.data.features.bonusdelirium.value) || 0 + delirium.max += Number(item.data.data.features.bonusdelirium.value) || 0 this.update({ 'data.secondary.delirium': delirium }) } if (item.data.data.features.bonusnrg.flag) { let nrg = duplicate(this.data.data.nrg) - nrg.mod += Number(item.data.data.features.bonusnrg.value) || 0 + nrg.value += Number(item.data.data.features.bonusnrg.value) || 0 + nrg.max += Number(item.data.data.features.bonusnrg.value) || 0 this.update({ 'data.nrg': nrg }) } this.enableWeaverPerk(item) @@ -606,35 +620,47 @@ export class PegasusActor extends Actor { } /* -------------------------------------------- */ - async computeNRGHealth() { + async computeNRGHealth( ) { if (this.isToken) return if (this.isOwner || game.user.isGM) { let updates = {} let phyDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.phy.value) + this.data.data.secondary.health.bonus + this.data.data.statistics.phy.mod; if (phyDiceValue != this.data.data.secondary.health.max) { updates['data.secondary.health.max'] = phyDiceValue - //updates['data.secondary.health.value'] = phyDiceValue + if (this.computeValue) { + updates['data.secondary.health.value'] = phyDiceValue + } } let mndDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.mnd.value) + this.data.data.secondary.delirium.bonus + this.data.data.statistics.mnd.mod; if (mndDiceValue != this.data.data.secondary.delirium.max) { updates['data.secondary.delirium.max'] = mndDiceValue - //updates['data.secondary.delirium.value'] = mndDiceValue + if (this.computeValue) { + updates['data.secondary.delirium.value'] = mndDiceValue + } } let stlDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.stl.value) + this.data.data.secondary.stealthhealth.bonus + this.data.data.statistics.stl.mod; if (stlDiceValue != this.data.data.secondary.stealthhealth.max) { updates['data.secondary.stealthhealth.max'] = stlDiceValue - //updates['data.secondary.stealthhealth.value'] = stlDiceValue + if (this.computeValue) { + updates['data.secondary.stealthhealth.value'] = stlDiceValue + } } let socDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.soc.value) + this.data.data.secondary.socialhealth.bonus + this.data.data.statistics.soc.mod; if (socDiceValue != this.data.data.secondary.socialhealth.max) { updates['data.secondary.socialhealth.max'] = socDiceValue - //updates['data.secondary.socialhealth.value'] = socDiceValue + if (this.computeValue) { + updates['data.secondary.socialhealth.value'] = socDiceValue + } } let nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.nrg.mod + this.data.data.statistics.foc.mod; if (nrgValue != this.data.data.nrg.absolutemax) { updates['data.nrg.absolutemax'] = nrgValue + if (this.computeValue) { + updates['data.nrg.max'] = nrgValue + updates['data.nrg.value'] = nrgValue + } } nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.statistics.foc.mod; if (nrgValue != this.data.data.combat.stunthreshold) { @@ -852,7 +878,10 @@ export class PegasusActor extends Actor { if (!effect.data.hindrance && effect.data.stataffected != "notapplicable" && effect.data.stataffected != "special") { - rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel }) + if ( effect.data.effectstatlevel && effect.data.effectstat == rollData.statKey) { + effect.data.effectlevel = rollData.statDicesLevel + } + rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel }) } } } @@ -982,6 +1011,7 @@ export class PegasusActor extends Actor { rollData.title = `Spec. : ${spec.name} ` rollData.specList = [spec] rollData.selectedSpec = spec._id + rollData.specName = spec.name rollData.specDicesLevel = spec.data.level this.startRoll(rollData) } else { diff --git a/modules/pegasus-create-char.js b/modules/pegasus-create-char.js index 90480cd..bea5153 100644 --- a/modules/pegasus-create-char.js +++ b/modules/pegasus-create-char.js @@ -11,14 +11,16 @@ export class PegasusActorCreate { name: "New Actor", type: "character" }); - this.actor.sheet.render(true); - - const racesPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.race"); - this.races = racesPack.map(i => i.toObject()); - const rolesPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.role"); - this.roles = rolesPack.map(i => i.toObject()); - const perksPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.perk"); - this.perks = perksPack.map(i => i.toObject()); + this.actor.sheet.render(true) + + this.actor.computeValue = true // To force value computation + + const racesPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.race") + this.races = racesPack.map(i => i.toObject()) + const rolesPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.role") + this.roles = rolesPack.map(i => i.toObject()) + const perksPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.perk") + this.perks = perksPack.map(i => i.toObject()) this.showRaces() } @@ -239,12 +241,10 @@ export class PegasusActorCreate { /* --------------- -------------------- --------- */ manageRacePerks(race) { - console.log("MANAG RACE PERKsS", this.currentRace) if ( !this.currentRace.data.perksgained ) { this.showRoles() return; } - console.log("MANAG RACE PERKsS 2", this.currentRace) if ( !this.racePerks) { // First init if ( this.currentRace.data.perksall) { this.racePerks = duplicate(this.perks) @@ -337,7 +337,7 @@ export class PegasusActorCreate { formData.rolestats.push( duplicate(this.actor.data.data.statistics[stat.name.toLowerCase()]) ) } } - console.log("STAT", this.roleStats, formData) + //console.log("STAT", this.roleStats, formData) this.renderChatMessage( formData) } @@ -362,7 +362,8 @@ export class PegasusActorCreate { /* -------------------------------------------- */ async showCharacterEnd() { - this.actor.computeNRGHealth() + await this.actor.computeNRGHealth() + this.actor.computeValue = false // To force value computation let formData = this.createFormData("character-end") this.renderChatMessage( formData) } diff --git a/modules/pegasus-roll-dialog.js b/modules/pegasus-roll-dialog.js index 28da81d..1ae0a04 100644 --- a/modules/pegasus-roll-dialog.js +++ b/modules/pegasus-roll-dialog.js @@ -41,6 +41,7 @@ export class PegasusRollDialog extends Dialog { PegasusUtility.rollPegasus( this.rollData ) } + /* -------------------------------------------- */ manageEffects( effectIdx, toggled) { let effect = this.rollData.effectsList[effectIdx] @@ -182,15 +183,20 @@ export class PegasusRollDialog extends Dialog { } $(function () { onLoad(); }); - html.find('#specList').change((event) => { + 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) diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 469458f..dd0e4ba 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -29,6 +29,12 @@ export class PegasusUtility { this.buildDiceLists(); PegasusCommands.init(); + Handlebars.registerHelper('count', function (list) { + return list.length; + }); + Handlebars.registerHelper('includes', function (array, val) { + return array.includes(val); + }); Handlebars.registerHelper('upper', function (text) { return text.toUpperCase(); }); diff --git a/system.json b/system.json index 0a11c0b..d28bc81 100644 --- a/system.json +++ b/system.json @@ -180,9 +180,9 @@ "styles": [ "styles/simple.css" ], - "templateVersion": 77, + "templateVersion": 78, "title": "Pegasus RPG", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", - "version": "0.4.12", + "version": "0.4.13", "background" : "./images/ui/pegasus_welcome_page.webp" } diff --git a/template.json b/template.json index 6df1ff0..35c56e7 100644 --- a/template.json +++ b/template.json @@ -200,6 +200,8 @@ "recoveryroll": false, "recoveryrollstat": "", "recoveryrollspec": [], + "effectstatlevel": false, + "effectstat": "", "description": "" }, "race": { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 9132e6b..fad599b 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -110,8 +110,6 @@ {{!-- Other Tab --}}