fvtt-pegasus-rpg/modules/pegasus-create-char.js

744 lines
26 KiB
JavaScript
Raw Permalink Normal View History

2022-01-06 18:22:05 +01:00
import { PegasusUtility } from "./pegasus-utility.js";
import { PegasusActor } from "./pegasus-actor.js";
import { PegasusActorSheet } from "./pegasus-actor-sheet.js";
2022-01-13 21:05:55 +01:00
import { PegasusItemSheet } from "./pegasus-item-sheet.js";
2022-01-06 18:22:05 +01:00
export class PegasusActorCreate {
/* -------------------------------------------- */
async start() {
this.actor = await Actor.create({
name: "New Actor",
type: "character"
});
2022-02-16 12:14:34 +01:00
this.actor.sheet.render(true)
2022-11-26 11:20:47 +01:00
2022-02-16 12:14:34 +01:00
this.actor.computeValue = true // To force value computation
2022-11-26 11:20:47 +01:00
2022-02-16 12:14:34 +01:00
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())
2022-11-26 09:49:59 +01:00
const perksPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.perks")
2022-02-16 12:14:34 +01:00
this.perks = perksPack.map(i => i.toObject())
2022-09-26 20:57:55 +02:00
const specPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.specialisations")
this.specs = specPack.map(i => i.toObject())
2022-11-26 21:00:40 +01:00
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())
2022-01-06 18:22:05 +01:00
this.showRaces()
}
/* -------------------------------------------- */
createFormData(step) {
let formData = {
name: this.actor.name,
img: this.actor.img,
step: step,
races: this.races,
2022-01-07 20:40:40 +01:00
roles: this.roles,
2022-11-26 11:20:47 +01:00
nboptionnal: this.raceOptionnalAbilities?.nboptionnal ?? 0,
optionnalabilities: this.raceOptionnalAbilities?.optionnalabilities ?? [],
2022-01-07 20:40:40 +01:00
}
2022-11-26 11:20:47 +01:00
if (this.raceSelectableStats) {
2022-01-07 20:40:40 +01:00
formData.numberstats = this.raceSelectableStats.numberstats;
formData.statsonlyonce = this.raceSelectableStats.statsonlyonce;
formData.stats = this.raceSelectableStats.stats;
2022-01-06 18:22:05 +01:00
}
return formData;
}
2022-09-26 20:57:55 +02:00
/* -------------------------------------------- */
2022-11-26 11:20:47 +01:00
getSpecFromRoleStat(role) {
2022-09-26 20:57:55 +02:00
let specList = []
2022-11-26 11:20:47 +01:00
for (let stat of role.system.statincreasechoice) {
2022-09-26 20:57:55 +02:00
if (stat.flag) {
2022-11-26 11:20:47 +01:00
specList = specList.concat(this.specs.filter(spec => spec.system.statistic.toLowerCase() == stat.name.toLowerCase()))
2022-09-26 20:57:55 +02:00
}
}
return specList
}
/* -------------------------------------------- */
2022-11-26 11:20:47 +01:00
getPerksFromRole(role) {
let perks = this.perks.filter(perk => perk.system.category.toLowerCase() == role.system.perksrole.toLowerCase())
2022-09-26 20:57:55 +02:00
return perks
}
2022-01-06 18:22:05 +01:00
/* -------------------------------------------- */
2022-11-26 21:00:40 +01:00
async processChatEvent(event) {
2022-01-06 18:22:05 +01:00
const step = $(event.currentTarget).data("step-name");
const itemId = $(event.currentTarget).data("item-id");
2022-01-08 18:28:01 +01:00
2022-11-26 11:20:47 +01:00
if (step == "select-race") {
let race = this.races.find(item => item._id == itemId);
2022-01-08 18:28:01 +01:00
this.currentRace = race;
2022-11-27 18:54:52 +01:00
await this.actor.applyRace(race);
2022-01-07 20:40:40 +01:00
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-26 11:20:47 +01:00
if (race.system.nboptionnal > 0 && race.system.optionnalabilities.length > 0) {
2022-01-07 20:40:40 +01:00
this.manageOptionnalAbilities(race);
} else {
2022-11-26 11:20:47 +01:00
if (race.system.selectablestats) {
2022-01-07 20:40:40 +01:00
this.manageSelectableStats(race);
2022-11-26 11:20:47 +01:00
} else if (race.system.perksgained) {
2022-01-12 16:25:55 +01:00
this.manageRacePerks(race);
2022-01-07 20:40:40 +01:00
} else {
this.showRoles()
}
}
}
2022-11-26 11:20:47 +01:00
if (step == 'select-race-optionnal') {
let ability = this.raceOptionnalAbilities.optionnalabilities.find(item => item._id == itemId);
2023-09-13 17:37:30 +02:00
let update = {}
2022-11-27 18:54:52 +01:00
await this.actor.applyAbility(ability, update);
2023-09-13 17:37:30 +02:00
if (!jQuery.isEmptyObject(update)) {
this.actor.update(update)
}
2022-11-26 11:20:47 +01:00
this.actor.createEmbeddedDocuments('Item', [ability]);
2022-01-07 20:40:40 +01:00
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-26 11:20:47 +01:00
this.raceOptionnalAbilities.optionnalabilities = this.raceOptionnalAbilities.optionnalabilities.filter(item => item._id != itemId);
2022-01-07 20:40:40 +01:00
this.raceOptionnalAbilities.nboptionnal -= 1;
this.processOptionnalAbilitiesStep();
}
if (step == 'select-race-stats') {
let statKey = $(event.currentTarget).data("stat-key");
2022-11-27 18:54:52 +01:00
await this.actor.modStat(statKey, 1);
2022-01-07 20:40:40 +01:00
this.raceSelectableStats.stats[statKey].used = true;
2022-11-26 11:20:47 +01:00
this.raceSelectableStats.numberstats -= 1;
2022-01-07 20:40:40 +01:00
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
this.processSelectableStats();
}
2022-01-12 16:25:55 +01:00
if (step == 'select-race-perks') {
2022-01-08 18:28:01 +01:00
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-26 11:20:47 +01:00
let perk = this.racePerks.find(item => item._id == itemId);
2022-11-27 18:54:52 +01:00
await this.actor.createEmbeddedDocuments('Item', [perk]);
2022-11-26 11:20:47 +01:00
this.racePerks = this.racePerks.filter(item => item._id != itemId);
2022-01-12 16:25:55 +01:00
this.nbRacePerks -= 1;
2022-11-26 11:20:47 +01:00
if (this.nbRacePerks == 0 || this.racePerks.length == 0) {
2022-01-08 18:28:01 +01:00
this.showRoles()
2022-11-26 11:20:47 +01:00
} else {
2022-01-12 16:25:55 +01:00
this.manageRacePerks()
2022-11-26 11:20:47 +01:00
}
2022-01-08 18:28:01 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-role') {
let role = this.roles.find(item => item._id == itemId);
2022-01-08 10:49:08 +01:00
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-27 18:54:52 +01:00
await this.actor.applyRole(role);
2022-01-08 10:49:08 +01:00
this.currentRole = role;
this.nbRoleStat = 2;
2022-09-26 20:57:55 +02:00
this.roleStats = duplicate(role.system.statincreasechoice)
2022-11-26 11:20:47 +01:00
this.showRoleStartSpec();
2022-01-10 08:00:27 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-role-start-spec') {
2022-01-10 08:00:27 +01:00
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-26 11:20:47 +01:00
let spec = this.roleSpecStart.find(item => item._id == itemId);
2022-11-27 18:54:52 +01:00
await this.actor.addIncSpec(spec, 1);
2022-01-10 08:00:27 +01:00
this.nbRoleSpecStart--;
2022-11-26 11:20:47 +01:00
this.roleSpecStart = this.roleSpecStart.filter(item => item._id != itemId);//Remove selected spec
if (this.nbRoleSpecStart == 0) {
this.showRoleStat();
2022-01-10 08:00:27 +01:00
} else {
2022-11-26 11:20:47 +01:00
this.showRoleStartSpec();
2022-01-10 08:00:27 +01:00
}
2022-01-08 10:49:08 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-role-stat') {
2022-01-08 10:49:08 +01:00
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
let statKey = $(event.currentTarget).data("stat-key");
2022-11-27 18:54:52 +01:00
await this.actor.valueStat(statKey, 1);
2022-01-08 10:49:08 +01:00
2022-11-26 11:20:47 +01:00
for (let stat of this.roleStats) {
if (stat.name.toLowerCase() == statKey.toLowerCase()) {
2022-01-08 10:49:08 +01:00
stat.flag = false
}
}
this.nbRoleStat--;
2022-11-26 11:20:47 +01:00
if (this.nbRoleStat == 0 || this.roleStats.length == 0) {
this.roleSpec = this.getSpecFromRoleStat(this.currentRole)
2022-01-08 10:49:08 +01:00
this.nbDT2 = 1;
this.nbDT1 = 2;
this.showRoleSpecialisations()
2022-11-26 11:20:47 +01:00
} else {
this.showRoleStat();
2022-01-08 10:49:08 +01:00
}
}
if (step == 'select-role-spec') {
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-26 11:20:47 +01:00
let spec = this.roleSpec.find(item => item._id == itemId);
2022-01-08 10:49:08 +01:00
if (this.nbDT2 > 0) {
2022-11-27 18:54:52 +01:00
await this.actor.addIncSpec(spec, 2)
2022-01-08 10:49:08 +01:00
this.nbDT2--;
} else {
2022-11-27 18:54:52 +01:00
await this.actor.addIncSpec(spec, 1)
2022-01-08 10:49:08 +01:00
this.nbDT1--;
}
2022-11-26 11:20:47 +01:00
this.roleSpec = this.roleSpec.filter(item => item._id != itemId);//Remove selected spec
if (this.nbDT1 == 0 || this.roleSpec.length == 0) {
2022-11-27 18:54:52 +01:00
this.rolePerks = this.getPerksFromRole(this.currentRole)
2022-01-08 10:49:08 +01:00
this.nbPerks = 2;
this.showRolePerks()
} else {
this.showRoleSpecialisations()
}
}
if (step == 'select-role-perk') {
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-26 11:20:47 +01:00
let perk = this.rolePerks.find(item => item._id == itemId);
2022-11-27 18:54:52 +01:00
await this.actor.addIncPerk(perk, 1)
2022-11-26 12:44:22 +01:00
let excludedPerks = this.actor.items.filter(it => it.type == "perk" && !it.system.upgradable)
this.rolePerks = []
for (let perk of this.rolePerks) {
2022-11-26 16:03:11 +01:00
if (!excludedPerks.find(it => it.name == perk.name)) {
2022-11-26 12:44:22 +01:00
this.rolePerks.push(perk)
}
}
2022-11-27 16:12:44 +01:00
this.rolePerks.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } })
2022-01-08 10:49:08 +01:00
this.nbPerks--;
if (this.nbPerks == 0 || this.rolePerks.length == 0) {
2022-11-26 11:05:41 +01:00
this.nbGlobalSpec = 5
2022-11-26 21:00:40 +01:00
if (this.forceVirtue) {
this.showVirtue()
} else {
this.showGlobalSpec()
}
2022-01-08 10:49:08 +01:00
} else {
this.showRolePerks()
}
2022-01-06 18:22:05 +01:00
}
2022-11-26 11:05:41 +01:00
if (step == 'select-global-spec') {
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
2022-11-26 11:20:47 +01:00
let spec = this.specs.find(item => item._id == itemId);
2022-11-27 18:54:52 +01:00
await this.actor.addIncSpec(spec, 1)
2022-11-26 11:05:41 +01:00
this.nbGlobalSpec--;
2022-11-26 11:20:47 +01:00
if (this.nbGlobalSpec == 0) {
this.nbGlobalStat = 5
2022-11-26 21:00:40 +01:00
if (this.forceVirtue) {
this.showVirtue()
} else {
this.showGlobalStat()
}
2022-11-26 11:05:41 +01:00
} else {
this.showGlobalSpec()
}
}
2022-11-26 11:20:47 +01:00
if (step == 'select-global-stat') {
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget))
let statKey = $(event.currentTarget).data("stat-key")
2022-11-27 18:54:52 +01:00
await this.actor.valueStat(statKey, 1)
2022-11-26 11:20:47 +01:00
this.nbGlobalStat--
if (this.nbGlobalStat == 0) {
2022-11-26 12:44:22 +01:00
this.nbGlobalPerk = 1
2022-11-26 21:00:40 +01:00
if (this.forceVirtue) {
this.showVirtue()
} else {
this.showGlobalPerk()
}
2022-11-26 11:20:47 +01:00
} else {
this.showGlobalStat()
}
}
2022-11-26 12:44:22 +01:00
if (step == 'select-global-perk') {
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget))
let perk = this.perks.find(item => item._id == itemId);
2022-11-27 18:54:52 +01:00
await this.actor.addIncPerk(perk, 1)
2022-11-26 12:44:22 +01:00
this.nbGlobalPerk--;
if (this.nbGlobalPerk == 0) {
2022-11-26 16:03:11 +01:00
this.nbGlobalStatus = 1
2022-11-26 21:00:40 +01:00
if (this.forceVirtue) {
this.showVirtue()
} else {
2022-11-27 18:54:52 +01:00
this.statusCount = {}
2022-11-26 21:00:40 +01:00
this.showGlobalStatus()
}
2022-11-26 12:44:22 +01:00
} else {
this.showGlobalPerk()
}
}
2022-11-26 16:03:11 +01:00
if (step == 'select-global-status') {
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget))
let statusKey = $(event.currentTarget).data("status-key")
2022-11-27 18:54:52 +01:00
await this.actor.addStatusBonus(statusKey, 1)
this.statusCount[statusKey] = (this.statusCount[statusKey]) ? this.statusCount[statusKey]+1 : 1;
2022-11-26 16:03:11 +01:00
this.nbGlobalStatus--;
if (this.nbGlobalStatus == 0) {
2022-11-26 21:00:40 +01:00
this.nbBonusSelection = 1
if (this.forceVirtue) {
this.showVirtue()
} else {
this.showBonusSelection()
}
2022-11-26 16:03:11 +01:00
} else {
this.showGlobalStatus()
}
}
2022-11-26 21:00:40 +01:00
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") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Stats Increased")
2022-11-26 21:00:40 +01:00
this.nbGlobalStat = 2
this.showGlobalStat()
}
if (nextStep == "bonus-specialisation") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Specialisations Increased")
2022-11-26 21:00:40 +01:00
this.nbGlobalSpec = 4
this.showGlobalSpec()
}
if (nextStep == "bonus-perk") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Perks - Check Effects & Perk Details.")
2022-11-26 21:00:40 +01:00
this.nbGlobalPerk = 2
this.showGlobalPerk()
}
if (nextStep == "bonus-status") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Status Modifiers")
2022-11-26 21:00:40 +01:00
this.nbGlobalStatus = 5
2022-11-27 18:54:52 +01:00
this.statusCount = {}
2022-11-26 21:00:40 +01:00
this.showGlobalStatus()
}
if (nextStep == "bonus-roleability") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Role Ability Level Increased")
2022-11-26 21:00:40 +01:00
this.actor.increaseRoleAbility()
2022-11-27 18:54:52 +01:00
this.showVirtue()
2022-11-26 21:00:40 +01:00
}
if (nextStep == "bonus-ppp5") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Power Purchase Points")
2022-11-26 21:00:40 +01:00
this.actor.addPPP(5)
2022-11-27 18:54:52 +01:00
this.showVirtue()
2022-11-26 21:00:40 +01:00
}
if (nextStep == "bonus-wealthy") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("x2 Starting Funds")
2022-11-26 21:00:40 +01:00
ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with x2 Starting Funds" })
this.showVirtue()
}
if (nextStep == "bonus-heirloom") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Family Heirloom (Level 1 Bonus Dice Item)")
2022-11-26 21:00:40 +01:00
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") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Vehicle")
2022-11-26 21:00:40 +01:00
ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with a Vehicle of Choice (GM Must approve)." })
this.showVirtue()
}
if (nextStep == "bonus-mount") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Mount")
2022-11-26 21:00:40 +01:00
ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with a Mount of Choice (GM Must approve)." })
this.showVirtue()
}
if (nextStep == "bonus-sidekick") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Sidekick")
2022-11-26 21:00:40 +01:00
ChatMessage.create({ content: "NOT AUTOMATED! Your character starts with a Sidekick of Choice (GM Must approve)." })
this.showVirtue()
}
if (nextStep == "bonus-ambidextrious") {
2022-11-27 18:54:52 +01:00
this.actor.setBonusInformation("Ambidextrious")
2022-11-26 21:00:40 +01:00
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()
}
2022-11-26 11:20:47 +01:00
2022-11-26 21:00:40 +01:00
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()
}
}
2022-01-06 18:22:05 +01:00
}
2022-11-26 11:20:47 +01:00
/* -------------------------------------------- */
async openItemView(event) {
2022-01-13 21:05:55 +01:00
let step = $(event.currentTarget).data("step");
let itemId = $(event.currentTarget).data("item-id");
let itemData
2022-11-26 11:20:47 +01:00
if (step == 'select-race') {
itemData = this.races.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-race-optionnal') {
itemData = this.raceOptionnalAbilities.optionnalabilities.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-race-perks') {
itemData = this.perks.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-race-perks') {
itemData = this.racePerks.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-role') {
itemData = this.roles.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
2022-11-26 11:20:47 +01:00
if (step == 'select-role-start-spec') {
itemData = this.roleSpecStart.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
if (step == 'select-role-spec') {
2022-11-26 11:20:47 +01:00
itemData = this.roleSpec.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
if (step == 'select-role-perk') {
2022-11-26 11:20:47 +01:00
itemData = this.rolePerks.find(item => item._id == itemId);
}
if (step == 'select-global-spec') {
itemData = this.specs.find(item => item._id == itemId);
2022-01-13 21:05:55 +01:00
}
if (itemData) {
2022-11-26 11:20:47 +01:00
let item = await Item.create(itemData, { temporary: true });
2022-01-13 21:05:55 +01:00
new PegasusItemSheet(item).render(true);
}
}
2022-11-26 11:20:47 +01:00
2022-01-07 20:40:40 +01:00
/* -------------------------------------------- */
2022-11-26 11:20:47 +01:00
manageSelectableStats(race) {
this.raceSelectableStats = {
2022-01-07 20:40:40 +01:00
"race": race,
2022-11-27 18:54:52 +01:00
"statsonlyonce": race.system.statsonlyonce,
"numberstats": race.system.numberstats,
"stats": duplicate(this.actor.system.statistics)
2022-01-07 20:40:40 +01:00
}
this.processSelectableStats()
}
2022-01-08 18:28:01 +01:00
/* -------------------------------------------- */
2022-11-26 11:20:47 +01:00
async renderChatMessage(formData) {
2022-01-08 18:28:01 +01:00
let chatData = {
user: game.user.id,
2022-11-26 11:20:47 +01:00
alias: this.actor.name,
2022-01-08 18:28:01 +01:00
rollMode: game.settings.get("core", "rollMode"),
2022-11-26 11:20:47 +01:00
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
2022-01-08 18:28:01 +01:00
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
2022-11-26 11:20:47 +01:00
};
2022-01-08 18:28:01 +01:00
//console.log("Apply damage chat", chatData );
2022-11-26 11:20:47 +01:00
await ChatMessage.create(chatData);
2022-01-08 18:28:01 +01:00
}
/* --------------- -------------------- --------- */
manageRacePerks(race) {
2022-11-27 18:54:52 +01:00
if (!this.currentRace.system.perksgained) {
2022-01-12 16:25:55 +01:00
this.showRoles()
return;
2022-01-08 18:28:01 +01:00
}
2022-11-26 11:20:47 +01:00
if (!this.racePerks) { // First init
2022-11-27 18:54:52 +01:00
if (this.currentRace.system.perksall) {
2022-01-12 16:25:55 +01:00
this.racePerks = duplicate(this.perks)
} else {
2022-11-27 18:54:52 +01:00
this.racePerks = duplicate(this.currentRace.system.perks)
2022-11-26 11:20:47 +01:00
}
2022-11-27 18:54:52 +01:00
this.nbRacePerks = this.currentRace.system.perksnumber;
2022-01-08 18:28:01 +01:00
}
2022-01-12 16:25:55 +01:00
let formData = this.createFormData("select-race-perks")
2022-11-26 11:20:47 +01:00
formData.raceperks = this.racePerks;
2022-11-27 16:12:44 +01:00
formData.raceperks.sort( function compare(a, b) { if (a.name<b.name){ return -1}else{return 1}} )
2022-11-26 11:20:47 +01:00
formData.nbraceperks = this.nbRacePerks;
2022-01-08 18:28:01 +01:00
this.renderChatMessage(formData)
}
/* --------------- -------------------- --------- */
2022-01-07 20:40:40 +01:00
async processSelectableStats() {
// End of race options choice
2022-11-26 11:20:47 +01:00
if (this.raceSelectableStats.numberstats == 0) {
2022-01-12 16:25:55 +01:00
this.manageRacePerks();
2022-01-07 20:40:40 +01:00
return;
}
let formData = this.createFormData("select-race-stats")
let chatData = {
user: game.user.id,
2022-11-26 11:20:47 +01:00
alias: this.actor.name,
2022-01-07 20:40:40 +01:00
rollMode: game.settings.get("core", "rollMode"),
2022-11-26 11:20:47 +01:00
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
2022-01-07 20:40:40 +01:00
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
2022-11-26 11:20:47 +01:00
};
2022-01-07 20:40:40 +01:00
//console.log("Apply damage chat", chatData );
2022-11-26 11:20:47 +01:00
await ChatMessage.create(chatData);
2022-01-07 20:40:40 +01:00
}
/* --------------- ----------------------------- */
2022-11-26 11:20:47 +01:00
manageOptionnalAbilities(race) {
this.raceOptionnalAbilities = {
2022-11-27 18:54:52 +01:00
"nboptionnal": race.system.nboptionnal,
"optionnalabilities": duplicate(race.system.optionnalabilities),
2022-01-07 20:40:40 +01:00
}
this.processOptionnalAbilitiesStep()
}
/* -------------------------------------------- */
async processOptionnalAbilitiesStep() {
// End of race options choice
2022-11-26 11:20:47 +01:00
if (this.raceOptionnalAbilities.nboptionnal == 0) {
if (this.raceSelectableStats) {
2022-01-08 18:28:01 +01:00
this.manageSelectableStats(this.currentrace);
2022-11-26 11:20:47 +01:00
} else if (this.currentRace.system.perksgained) {
2022-01-08 18:28:01 +01:00
this.manageRacePerks(this.currentRace);
2022-01-07 20:40:40 +01:00
} else {
this.showRoles()
}
2022-01-08 18:28:01 +01:00
} else {
let formData = this.createFormData("select-race-optionnal")
2022-11-26 11:20:47 +01:00
this.renderChatMessage(formData)
2022-01-07 20:40:40 +01:00
}
}
2022-01-06 18:22:05 +01:00
/* -------------------------------------------- */
async showRaces() {
let formData = this.createFormData("select-race")
2022-11-26 11:20:47 +01:00
this.renderChatMessage(formData)
2022-01-06 18:22:05 +01:00
}
/* -------------------------------------------- */
async showRoles() {
2022-01-07 20:40:40 +01:00
let formData = this.createFormData("select-role")
2022-11-26 11:20:47 +01:00
this.renderChatMessage(formData)
2022-01-06 18:22:05 +01:00
}
2022-01-08 10:49:08 +01:00
2022-01-10 08:00:27 +01:00
/* ------------------------------- ------------- */
async showRoleStartSpec() {
2022-11-26 11:20:47 +01:00
if (!this.roleSpecStart) {
this.roleSpecStart = this.specs.filter(spec => spec.system.statistic.toUpperCase() == this.currentRole.system.statincrease1.toUpperCase() || spec.system.statistic.toUpperCase() == this.currentRole.system.statincrease2.toUpperCase())
2022-01-10 08:00:27 +01:00
this.nbRoleSpecStart = 2;
}
let formData = this.createFormData("select-role-start-spec")
2022-11-26 11:20:47 +01:00
formData.rolestartspec = this.roleSpecStart
2022-11-26 12:03:21 +01:00
formData.rolestartspec.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } })
2022-01-10 08:00:27 +01:00
formData.nbrolespecstart = this.nbRoleSpecStart;
2022-11-26 11:20:47 +01:00
this.renderChatMessage(formData)
2022-01-10 08:00:27 +01:00
}
/* ------------------------------- ------------- */
2022-11-26 11:20:47 +01:00
async showRoleStat() {
2022-01-08 10:49:08 +01:00
let formData = this.createFormData("select-role-stat")
formData.rolestats = []
2022-11-26 11:20:47 +01:00
for (let stat of this.roleStats) {
2022-01-08 10:49:08 +01:00
if (stat.flag) {
2022-11-27 16:17:51 +01:00
let actorStat = this.actor.system.statistics[stat.name.toLowerCase()]
if ( actorStat.value < 5) { // Only below D12
formData.rolestats.push(duplicate(actorStat))
}
2022-01-08 10:49:08 +01:00
}
2022-11-26 11:20:47 +01:00
}
2022-02-16 12:14:34 +01:00
//console.log("STAT", this.roleStats, formData)
2022-11-26 11:20:47 +01:00
this.renderChatMessage(formData)
2022-01-08 10:49:08 +01:00
}
/* -------------------------------------------- */
async showRoleSpecialisations() {
let formData = this.createFormData("select-role-spec")
formData.rolespec = duplicate(this.roleSpec)
2022-11-26 12:03:21 +01:00
formData.rolespec.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } })
2022-01-08 10:49:08 +01:00
formData.dt = 1
2022-11-26 11:20:47 +01:00
if (this.nbDT2 > 0) {
2022-01-08 10:49:08 +01:00
formData.dt = 2
2022-11-26 11:20:47 +01:00
}
this.renderChatMessage(formData)
2022-01-08 10:49:08 +01:00
}
2022-11-26 11:05:41 +01:00
2022-01-08 10:49:08 +01:00
/* -------------------------------------------- */
async showRolePerks() {
let formData = this.createFormData("select-role-perk")
formData.roleperks = duplicate(this.rolePerks)
2022-11-26 12:03:21 +01:00
formData.roleperks.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } })
2022-01-08 10:49:08 +01:00
formData.nbperks = this.nbPerks
2022-11-26 11:20:47 +01:00
this.renderChatMessage(formData)
2022-01-08 10:49:08 +01:00
}
2022-11-26 11:05:41 +01:00
/* -------------------------------------------- */
async showGlobalSpec() {
let formData = this.createFormData("select-global-spec")
2022-11-28 13:58:04 +01:00
let excludedSpecs = this.actor.items.filter(it => it.type == "specialisation" && it.system.level >= 5)
2022-11-26 11:05:41 +01:00
formData.specs = []
2022-11-26 11:20:47 +01:00
for (let spec of this.specs) {
2022-11-26 11:05:41 +01:00
let isOK = true
for (let excluded of excludedSpecs) {
if (excluded.name == spec.name) {
isOK = false
break
}
}
if (isOK) {
formData.specs.push(spec)
}
2022-11-26 11:20:47 +01:00
}
formData.specs.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } })
this.renderChatMessage(formData)
}
/* -------------------------------------------- */
async showGlobalStat() {
let formData = this.createFormData("select-global-stat")
formData.stats = {}
for (let key in this.actor.system.statistics) {
let stat = this.actor.system.statistics[key]
2022-11-27 18:54:52 +01:00
if (stat.value < 5) {
2022-11-26 11:20:47 +01:00
formData.stats[key] = duplicate(stat)
}
}
this.renderChatMessage(formData)
2022-11-26 11:05:41 +01:00
}
2022-11-26 11:20:47 +01:00
2022-11-26 12:44:22 +01:00
/* -------------------------------------------- */
async showGlobalPerk() {
let formData = this.createFormData("select-global-perk")
let excludedPerks = this.actor.items.filter(it => it.type == "perk" && !it.system.upgradable)
formData.perks = []
for (let perk of this.perks) {
let isOK = true
for (let excluded of excludedPerks) {
if (excluded.name == perk.name) {
isOK = false
break
}
}
if (isOK) {
formData.perks.push(perk)
}
}
formData.perks.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } })
this.renderChatMessage(formData)
}
2022-11-26 16:03:11 +01:00
/* -------------------------------------------- */
async showGlobalStatus() {
let formData = this.createFormData("select-global-status")
2022-11-27 18:54:52 +01:00
formData.status = {}
for(let statusKey in this.actor.system.secondary) {
if ( this.statusCount[statusKey] == undefined) {
this.statusCount[statusKey] = 0
}
if ( this.statusCount[statusKey] < 3) {
formData.status[statusKey] = duplicate(this.actor.system.secondary[statusKey])
}
}
if ( this.statusCount["nrg"] < 3) {
formData.status["nrg"] = duplicate(this.actor.system.nrg)
}
2022-11-26 16:03:11 +01:00
this.renderChatMessage(formData)
}
2022-11-26 21:00:40 +01:00
/* -------------------------------------------- */
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)
}
2022-11-26 16:03:11 +01:00
2022-01-08 10:49:08 +01:00
/* -------------------------------------------- */
async showCharacterEnd() {
2022-02-16 12:14:34 +01:00
await this.actor.computeNRGHealth()
this.actor.computeValue = false // To force value computation
2022-01-08 10:49:08 +01:00
let formData = this.createFormData("character-end")
2022-11-26 11:20:47 +01:00
this.renderChatMessage(formData)
2022-01-08 10:49:08 +01:00
}
2022-11-26 11:20:47 +01:00
2022-01-06 18:22:05 +01:00
}