From 45e856a30b4e4a21f75a1057f1c31063b82a026f Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sat, 26 Nov 2022 21:00:40 +0100 Subject: [PATCH] Char creation process finalized --- modules/pegasus-actor.js | 33 ++++- modules/pegasus-create-char.js | 203 +++++++++++++++++++++++++++++-- templates/chat-create-actor.html | 56 ++++++++- 3 files changed, 277 insertions(+), 15 deletions(-) diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 26bdcd2..9860247 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -282,9 +282,9 @@ export class PegasusActor extends Actor { } /* -------------------------------------------- */ getStatus(statusKey) { - if ( statusKey == "nrg") { + if (statusKey == "nrg") { return duplicate(this.system.nrg) - } + } return duplicate(this.system.secondary[statusKey]) } @@ -479,6 +479,29 @@ export class PegasusActor extends Actor { let update = { _id: item.id, "data.activated": !item.system.activated } await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity } + } + /* -------------------------------------------- */ + setHandInformation( info) { + this.update( {'system.biodata.preferredhand': info} ) + } + + /* -------------------------------------------- */ + increaseRoleAbility() { + + } + + /* -------------------------------------------- */ + addCDP( value) { + let cdp = this.system.biodata.cdp + cdp += value + this.update( {'system.biodata.cdp': cdp}) + } + + /* -------------------------------------------- */ + addPPP(value) { + let ppp = duplicate(this.system.ppp) + ppp.availablePPP += value + this.update({ 'system.ppp': ppp }) } /* -------------------------------------------- */ @@ -1558,14 +1581,14 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ async modStatus(key, inc = 1) { - if ( key == "nrg") { + if (key == "nrg") { let nrg = duplicate(this.system.nrg) nrg.mod += parseInt(inc) - await this.update({ [`data.nrg`]: nrg }) + await this.update({ [`data.nrg`]: nrg }) } else { let status = duplicate(this.system.secondary[key]) status.bonus += parseInt(inc) - await this.update({ [`data.secondary.${key}`]: status }) + await this.update({ [`data.secondary.${key}`]: status }) } } diff --git a/modules/pegasus-create-char.js b/modules/pegasus-create-char.js index 438fc0e..31afc60 100644 --- a/modules/pegasus-create-char.js +++ b/modules/pegasus-create-char.js @@ -23,6 +23,10 @@ export class PegasusActorCreate { this.perks = perksPack.map(i => i.toObject()) const specPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.specialisations") this.specs = specPack.map(i => i.toObject()) + const virtuePack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.virtues") + this.virtues = virtuePack.map(i => i.toObject()) + const vicePack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.vices") + this.vices = vicePack.map(i => i.toObject()) this.showRaces() } @@ -64,7 +68,7 @@ export class PegasusActorCreate { } /* -------------------------------------------- */ - processChatEvent(event) { + async processChatEvent(event) { const step = $(event.currentTarget).data("step-name"); const itemId = $(event.currentTarget).data("item-id"); @@ -199,7 +203,11 @@ export class PegasusActorCreate { this.nbPerks--; if (this.nbPerks == 0 || this.rolePerks.length == 0) { this.nbGlobalSpec = 5 - this.showGlobalSpec() + if (this.forceVirtue) { + this.showVirtue() + } else { + this.showGlobalSpec() + } } else { this.showRolePerks() } @@ -212,8 +220,11 @@ export class PegasusActorCreate { this.nbGlobalSpec--; if (this.nbGlobalSpec == 0) { this.nbGlobalStat = 5 - this.showGlobalStat() - //this.showCharacterEnd() + if (this.forceVirtue) { + this.showVirtue() + } else { + this.showGlobalStat() + } } else { this.showGlobalSpec() } @@ -226,8 +237,11 @@ export class PegasusActorCreate { this.nbGlobalStat-- if (this.nbGlobalStat == 0) { this.nbGlobalPerk = 1 - this.showGlobalPerk() - //this.showCharacterEnd() + if (this.forceVirtue) { + this.showVirtue() + } else { + this.showGlobalPerk() + } } else { this.showGlobalStat() } @@ -240,8 +254,11 @@ export class PegasusActorCreate { this.nbGlobalPerk--; if (this.nbGlobalPerk == 0) { this.nbGlobalStatus = 1 - this.showGlobalStatus() - //this.showCharacterEnd() + if (this.forceVirtue) { + this.showVirtue() + } else { + this.showGlobalStatus() + } } else { this.showGlobalPerk() } @@ -253,13 +270,102 @@ export class PegasusActorCreate { this.actor.addStatusBonus(statusKey, 1) this.nbGlobalStatus--; if (this.nbGlobalStatus == 0) { - this.showCharacterEnd() + this.nbBonusSelection = 1 + if (this.forceVirtue) { + this.showVirtue() + } else { + this.showBonusSelection() + } } else { this.showGlobalStatus() } } + if (step == 'select-bonus-selection') { + PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget)) + let nextStep = $(event.currentTarget).data("bonus-key") + this.forceVirtue = true + if (nextStep == "bonus-statistic") { + this.nbGlobalStat = 2 + this.showGlobalStat() + } + if (nextStep == "bonus-specialisation") { + this.nbGlobalSpec = 4 + this.showGlobalSpec() + } + if (nextStep == "bonus-perk") { + this.nbGlobalPerk = 2 + this.showGlobalPerk() + } + if (nextStep == "bonus-status") { + this.nbGlobalStatus = 5 + this.showGlobalStatus() + } + if (nextStep == "bonus-roleability") { + this.actor.increaseRoleAbility() + } + if (nextStep == "bonus-ppp5") { + this.actor.addPPP(5) + } + if (nextStep == "bonus-wealthy") { + ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with x2 Starting Funds" }) + this.showVirtue() + } + if (nextStep == "bonus-heirloom") { + ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with an item of choice (GM Must approve). This item provides a Level 1 Bonus Dice to a Stat of choice" }) + this.showVirtue() + } + if (nextStep == "bonus-vehicle") { + ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with a Vehicle of Choice (GM Must approve)." }) + this.showVirtue() + } + if (nextStep == "bonus-mount") { + ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with a Mount of Choice (GM Must approve)." }) + this.showVirtue() + } + if (nextStep == "bonus-sidekick") { + ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with a Sidekick of Choice (GM Must approve)." }) + this.showVirtue() + } + if (nextStep == "bonus-ambidextrious") { + this.actor.setHandInformation("Ambidextrious") + this.showVirtue() + } + } + if (step == 'select-global-virtue') { + PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget)); + let virtue = this.virtues.find(item => item._id == itemId); + await this.actor.createEmbeddedDocuments('Item', [virtue]) + this.showVice() + } + + if (step == 'select-global-vice') { + PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget)); + let vice = this.vices.find(item => item._id == itemId); + await this.actor.createEmbeddedDocuments('Item', [vice]); + if(this.forceEnd) { + this.showCharacterEnd() + } else { + this.showViceQuestion() + } + } + + if (step == "select-vice-question") { + PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget)) + let nextStep = $(event.currentTarget).data("question-key") + this.forceEnd = true + if (nextStep == "vice-next-step") { + this.showCharacterEnd() + } + if (nextStep == "vice-5-cdp") { + this.actor.addCDP(5) + this.showVice() + } + if (nextStep == "vice-vertue") { + this.showVirtue() + } + } } /* -------------------------------------------- */ @@ -515,6 +621,85 @@ export class PegasusActorCreate { this.renderChatMessage(formData) } + /* -------------------------------------------- */ + async showBonusSelection() { + let formData = this.createFormData("select-bonus-selection") + formData.bonuses = { + "bonus-statistic": { name: "Increase 2 Stats" }, + "bonus-specialisation": { name: "Increase 4 Specialisations" }, + "bonus-perk": { name: "Choose/Upgrade 2 Perks" }, + "bonus-status": { name: "Upgrade 5 status" }, + "bonus-roleability": { name: "Role Ability +1" }, + "bonus-ppp5": { name: "Gain +5 PPP" }, + "bonus-wealthy": { name: "Wealthy (money x 2)" }, + "bonus-heirloom": { name: "Family Heirloom (Special Item)" }, + "bonus-vehicle": { name: "Starting Vehicle" }, + "bonus-sidekick": { name: "Starting Sidekick" }, + "bonus-ambidextrious": { name: "Ambidextrious" } + } + this.renderChatMessage(formData) + } + + /* -------------------------------------------- */ + async showVirtue() { + let formData = this.createFormData("select-global-virtue") + let virtues = this.actor.items.filter(it => it.type == "virtue") + formData.virtues = [] + for ( let virtue1 of this.virtues) { // Filter existing virtues + let isOK = true + for(let virtue2 of virtues) { + if (virtue1.name == virtue2.name) { + isOK = false + break + } + } + if (isOK) { + formData.virtues.push(virtue1) + } + } + formData.virtues.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } }) + this.renderChatMessage(formData) + } + /* -------------------------------------------- */ + async showVice() { + let formData = this.createFormData("select-global-vice") + let virtues = this.actor.items.filter(it => it.type == "virtue") + let vices = this.actor.items.filter(it => it.type == "vice") + formData.vices = [] + for (let vice of this.vices) { + let isOK = true + for ( let virtue of virtues) { + for (let nonVice of virtue.system.unavailablevice) { + if(nonVice.name == vice.name) { + isOK = false + break + } + } + } + for ( let vice2 of vices) { + if(vice2.name == vice.name) { + isOK = false + break + } + } + if (isOK) { + formData.vices.push( vice) + } + } + formData.vices.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } }) + this.renderChatMessage(formData) + } + + /* -------------------------------------------- */ + showViceQuestion() { + let formData = this.createFormData("select-vice-question") + formData.questions = { + "vice-next-step": { name: "Go to next step" }, + "vice-5-cdp": { name: "Gain +5 CDP and choose a Vice" }, + "vice-vertue": { name: "Choose a Virtue and a Vice" } + } + this.renderChatMessage(formData) + } /* -------------------------------------------- */ async showCharacterEnd() { diff --git a/templates/chat-create-actor.html b/templates/chat-create-actor.html index d39ebbb..5aa3237 100644 --- a/templates/chat-create-actor.html +++ b/templates/chat-create-actor.html @@ -186,8 +186,62 @@ {{/if}} + {{#if (eq step "select-bonus-selection")}} +
Select a bonus +
+ + {{#each bonuses as |bonus key|}} + + + + + {{/each}} +
{{bonus.name}}Select it !
+ {{/if}} + + {{#if (eq step "select-global-virtue")}} +
Choose a Virtue. +
+ + {{#each virtues as |virtue index|}} + + + + + {{/each}} +
{{virtue.name}}Select it !
+ {{/if}} + + {{#if (eq step "select-global-vice")}} +
Choose an available Vice. +
+ + {{#each vices as |vice index|}} + + + + + {{/each}} +
{{vice.name}}Select it !
+ {{/if}} + + {{#if (eq step "select-vice-question")}} +
Would you like to skip, to choose a second Vice for 5 CDP or to choose 1 Virtue and 1 Vice? +
+ + {{#each questions as |question key|}} + + + + + {{/each}} +
{{question.name}}Select it !
+ {{/if}} + {{#if (eq step "character-end")}} -
Follow the next steps from the rulebook page 50 !. You can now spend 150 CDPs to customise your character. +
Choose Starting Gear, Worst Fear, Desires, Catchphrase & Catchphrase Trigger + and fill in the empty fields in the Bio Tab.
+ Automated character creation is over.
{{/if}}