From 9e70a12b98557a4600666f3820d885995a9d9492 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Mon, 28 Nov 2022 13:58:04 +0100 Subject: [PATCH] Minor various fixes --- modules/pegasus-actor.js | 91 ++++++++++++++++++------------- modules/pegasus-create-char.js | 2 +- template.json | 1 + templates/item-ability-sheet.html | 22 ++++---- templates/item-race-sheet.html | 12 ++-- 5 files changed, 75 insertions(+), 53 deletions(-) diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 391b5f6..b1d234f 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -137,12 +137,12 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ getMT() { let modifier = 0 - for(let effect of this.items) { - if (effect.type =="effect" && effect.system.affectstatus && effect.system.affectedstatus =="mt") { - if ( effect.system.genre == "positive") { + for (let effect of this.items) { + if (effect.type == "effect" && effect.system.affectstatus && effect.system.affectedstatus == "mt") { + if (effect.system.genre == "positive") { modifier += effect.system.effectlevel } - if ( effect.system.genre == "negative") { + if (effect.system.genre == "negative") { modifier -= effect.system.effectlevel } } @@ -153,12 +153,12 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ getKBV() { let modifier = 0 - for(let effect of this.items) { - if (effect.type =="effect" && effect.system.affectstatus && effect.system.affectedstatus == "kbv") { - if ( effect.system.genre == "positive") { + for (let effect of this.items) { + if (effect.type == "effect" && effect.system.affectstatus && effect.system.affectedstatus == "kbv") { + if (effect.system.genre == "positive") { modifier += effect.system.effectlevel } - if ( effect.system.genre == "negative") { + if (effect.system.genre == "negative") { modifier -= effect.system.effectlevel } } @@ -509,28 +509,28 @@ export class PegasusActor extends Actor { let update = { _id: item.id, "system.activated": !item.system.activated } await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity } - } + } /* -------------------------------------------- */ - setHandInformation( info) { - this.update( {'system.biodata.preferredhand': info} ) + setHandInformation(info) { + this.update({ 'system.biodata.preferredhand': info }) } /* -------------------------------------------- */ increaseRoleAbility() { let role = this.getRole() let level = role.system.rolelevel + 1 - this.updateEmbeddedDocuments('Item', [ {_id: role.id, 'system.rolelevel': level} ]) + this.updateEmbeddedDocuments('Item', [{ _id: role.id, 'system.rolelevel': level }]) } /* -------------------------------------------- */ - setBonusInformation( info) { - this.update( {'system.biodata.bonusselection': info}) + setBonusInformation(info) { + this.update({ 'system.biodata.bonusselection': info }) } /* -------------------------------------------- */ - addCDP( value) { + addCDP(value) { let cdp = this.system.biodata.cdp cdp += value - this.update( {'system.biodata.cdp': cdp}) + this.update({ 'system.biodata.cdp': cdp }) } /* -------------------------------------------- */ @@ -904,11 +904,11 @@ export class PegasusActor extends Actor { } } - if (item.type == 'race') { + if (item.type == "race") { this.applyRace(item) - } else if (item.type == 'role') { + } else if (item.type == "role") { this.applyRole(item) - } else if (item.type == 'ability') { + } else if (item.type == "ability") { this.applyAbility(item, [], true) if (!onDrop) { await this.createEmbeddedDocuments('Item', [item]) @@ -1311,7 +1311,8 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ async deleteAllItemsByType(itemType) { - let items = this.items.filter(item => item.type == itemType); + let items = this.items.filter(item => item.type == itemType).map(item => item.id) + console.log("Dele....", items) await this.deleteEmbeddedDocuments('Item', items); } @@ -1493,10 +1494,8 @@ export class PegasusActor extends Actor { updates['system.biodata.moralitythreshold'] = moralitythreshold } if (!this.isToken) { - if (this.warnMorality != this.system.biodata.morality && this.system.biodata.morality < 0) { + if (this.warnMorality != this.system.biodata.morality && this.system.biodata.morality <= 0) { ChatMessage.create({ content: "WARNING: Your character is dangerously close to becoming corrupted and defeated. Start on a path of redemption!" }) - } - if (this.warnMorality != this.system.biodata.morality && this.system.biodata.morality == 0) { ChatMessage.create({ content: "This character can no longer spend CDP until their Morality has reached 1 or higher" }) } if (this.warnMorality != this.system.biodata.morality) { @@ -1533,8 +1532,8 @@ export class PegasusActor extends Actor { this.system.combat.hindrancedice = hindrance this.getTraumaState() this.cleanupPerksIfTrauma() - this.parseStatEffects() - this.parseStatusEffects() + await this.parseStatEffects() + await this.parseStatusEffects() } } @@ -1570,11 +1569,13 @@ export class PegasusActor extends Actor { } /* -------------------------------------------- */ - parseStatusEffects() { + async parseStatusEffects() { if (this.system.biodata.noautobonus) { // If we are in "no-bonus mode return } let effects = this.items.filter(effect => effect.type == "effect" && effect.system.affectstatus && (Number(effect.system.effectlevel) > 0)) + let abilities = this.items.filter(ability => ability.type == "ability" && ability.system.statusaffected != "notapplicable") + for (let statusKey in this.system.secondary) { let status = duplicate(this.system.secondary[statusKey]) let bonus = 0 @@ -1583,12 +1584,18 @@ export class PegasusActor extends Actor { bonus += Number(effect.system.effectlevel) } } + for (let ability of abilities) { + if (ability.system.statusaffected && ability.system.statusaffected == statusKey) { + bonus += Number(effect.system.statusmodifier) + } + } if (bonus != status.bonus) { status.bonus = bonus - this.update({ [`system.secondary.${statusKey}`]: status }) + await this.update({ [`system.secondary.${statusKey}`]: status }) } } + console.log("Ablities", this.name, abilities) let nrg = duplicate(this.system.nrg) let bonus = 0 for (let effect of effects) { @@ -1596,11 +1603,15 @@ export class PegasusActor extends Actor { bonus += Number(effect.system.effectlevel) } } + for (let ability of abilities) { + if (ability.system.statusaffected && ability.system.statusaffected == "nrg") { + bonus += Number(ability.system.statusmodifier) + } + } if (bonus != nrg.mod) { nrg.mod = bonus - this.update({ [`system.nrg`]: nrg }) + await this.update({ [`system.nrg`]: nrg }) } - } /* -------------------------------------------- */ @@ -1688,9 +1699,15 @@ export class PegasusActor extends Actor { ability.system = ability.data } if (ability.system.affectedstat != "notapplicable") { - let stat = duplicate(this.system.statistics[ability.system.affectedstat]) - stat.mod += Number(ability.system.statmodifier) - updates[`system.statistics.${ability.system.affectedstat}`] = stat + if ( ability.system.affectedstat == "mr") { + let stat = duplicate(this.system.mr) + stat.mod += Number(ability.system.statmodifier) + updates[`system.mr`] = stat + } else { + let stat = duplicate(this.system.statistics[ability.system.affectedstat]) + stat.mod += Number(ability.system.statmodifier) + updates[`system.statistics.${ability.system.affectedstat}`] = stat + } } // manage status bonus if (ability.system.statusaffected != "notapplicable") { @@ -1751,11 +1768,11 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ async applyRace(race) { let updates = { 'system.biodata.racename': race.name } + updates['system.biodata.sizenum'] = race.system.size let newItems = [] - await this.deleteAllItemsByType('race') - newItems.push(race); + await this.deleteAllItemsByType("race") + newItems.push(race) - console.log("DROPPED RACE", race) for (let ability of race.system.abilities) { if (!ability.system) ability.system = ability.data newItems.push(ability) @@ -1896,11 +1913,11 @@ export class PegasusActor extends Actor { } if (role.name.toLowerCase() == "defender" && subKey == "defence") { rollData.effectsList.push({ label: "Defender Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() }) - rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0,"Defender Role Bonus")) + rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Defender Role Bonus")) } if (role.name.toLowerCase() == "scrapper" && statKey == "com") { rollData.effectsList.push({ label: "Scrapper Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() }) - rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0,"Scrapper Role Bonus")) + rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Scrapper Role Bonus")) } } diff --git a/modules/pegasus-create-char.js b/modules/pegasus-create-char.js index cfda9d3..ceb5640 100644 --- a/modules/pegasus-create-char.js +++ b/modules/pegasus-create-char.js @@ -580,7 +580,7 @@ export class PegasusActorCreate { /* -------------------------------------------- */ async showGlobalSpec() { let formData = this.createFormData("select-global-spec") - let excludedSpecs = this.actor.items.filter(it => it.type == "specialisation" && it.system.level >= 4) + let excludedSpecs = this.actor.items.filter(it => it.type == "specialisation" && it.system.level >= 5) formData.specs = [] for (let spec of this.specs) { let isOK = true diff --git a/template.json b/template.json index 16f3f1e..000e3f9 100644 --- a/template.json +++ b/template.json @@ -446,6 +446,7 @@ "perksgained": false, "perksall": false, "perksnumber": 0, + "size": 0, "perks": [], "perksrole": "", "statistics": "" diff --git a/templates/item-ability-sheet.html b/templates/item-ability-sheet.html index 16d59ed..fee290f 100644 --- a/templates/item-ability-sheet.html +++ b/templates/item-ability-sheet.html @@ -16,25 +16,25 @@
@@ -52,6 +52,10 @@