First full step for character creation
This commit is contained in:
366
modules/app/tedeum-character-creator.js
Normal file
366
modules/app/tedeum-character-creator.js
Normal file
@ -0,0 +1,366 @@
|
||||
import { TeDeumUtility } from "../common/tedeum-utility.js";
|
||||
|
||||
export class TeDeumCharacterCreator {
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async init() {
|
||||
this.stages = {}
|
||||
this.currentStage = "origineSociale"
|
||||
this.sex = undefined
|
||||
this.origineSociale = undefined
|
||||
this.religion = undefined
|
||||
this.caracBonus = {}
|
||||
this.competenceBonus = {}
|
||||
this.competences = TeDeumUtility.getCompetencesForDropDown()
|
||||
|
||||
for (let k in game.system.tedeum.config.caracteristiques) {
|
||||
this.caracBonus[k] = { value: 0 }
|
||||
}
|
||||
|
||||
for (let stage in game.system.tedeum.config.etapesEducation) {
|
||||
this.stages[stage] = { selectedItem: null, items: [] }
|
||||
}
|
||||
console.log(this.stages, game.system.tedeum.etapesEducation)
|
||||
|
||||
const educations = await TeDeumUtility.loadCompendium("fvtt-te-deum.education")
|
||||
for (let edu of educations) {
|
||||
this.stages[edu.system.etape].items.push(edu)
|
||||
}
|
||||
|
||||
this.processStage()
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
increaseCompetence(compName) {
|
||||
compName = compName.toLowerCase()
|
||||
if (!this.competenceBonus[compName]) {
|
||||
this.competenceBonus[compName] = { value: 1 }
|
||||
} else {
|
||||
this.competenceBonus[compName].value += 1
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
processReponses(question) {
|
||||
let fullResponses = []
|
||||
for (let key in question.reponses) {
|
||||
let response = question.reponses[key]
|
||||
fullResponses.push({ id: key, label: `${response.reponse} (${response.compName} +1)` })
|
||||
}
|
||||
return fullResponses
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
processReponsesRadio(question) {
|
||||
let fullResponses = {}
|
||||
for (let key in question.reponses) {
|
||||
let response = question.reponses[key]
|
||||
fullResponses[key] = `${response.reponse} (${response.compName} +1)`
|
||||
}
|
||||
return fullResponses
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async askStageName(context) {
|
||||
const content = await renderTemplate("systems/fvtt-te-deum/templates/dialogs/character-creator-select-stage-name.hbs", context)
|
||||
const choiceResult = await foundry.applications.api.DialogV2.wait({
|
||||
window: { title: context.title },
|
||||
classes: ["fvtt-te-deum"],
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
label: context.label,
|
||||
callback: (event, button, dialog) => {
|
||||
const output = Array.from(button.form.elements).reduce((obj, input) => {
|
||||
if (input.name) obj[input.name] = input.value
|
||||
return obj
|
||||
}, {})
|
||||
return output
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: {
|
||||
},
|
||||
rejectClose: false, // Click on Close button will not launch an error
|
||||
render: (event, dialog) => {
|
||||
}
|
||||
})
|
||||
return choiceResult
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
processCompetences(stage) {
|
||||
for (let compKey in stage.system.competences) {
|
||||
let comp = stage.system.competences[compKey]
|
||||
if (comp.valid && comp.compName !== "") {
|
||||
this.increaseCompetence(comp.compName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async askQuestionnaire(stage, context) {
|
||||
for (let key in stage.system.questionnaire) {
|
||||
let question = stage.system.questionnaire[key]
|
||||
if (question.question === "") { break }
|
||||
|
||||
context.question = question.question
|
||||
context.responses = this.processReponses(question)
|
||||
context.responsesRadio = this.processReponsesRadio(question)
|
||||
|
||||
const content = await renderTemplate("systems/fvtt-te-deum/templates/dialogs/character-creator-select-questions.hbs", context)
|
||||
const choiceResult = await foundry.applications.api.DialogV2.wait({
|
||||
window: { title: context.title },
|
||||
classes: ["fvtt-te-deum"],
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
label: context.label,
|
||||
callback: (event, button, dialog) => {
|
||||
const output = Array.from(button.form.elements).reduce((obj, input) => {
|
||||
if (input.name) obj[input.name] = input.value
|
||||
return obj
|
||||
}, {})
|
||||
return output
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: {
|
||||
},
|
||||
rejectClose: false, // Click on Close button will not launch an error
|
||||
render: (event, dialog) => {
|
||||
}
|
||||
})
|
||||
if (choiceResult == null) { return }
|
||||
let selectedResponse = question.reponses[choiceResult.responseKey]
|
||||
console.log(choiceResult, selectedResponse, question)
|
||||
this.increaseCompetence(selectedResponse.compName)
|
||||
}
|
||||
}
|
||||
|
||||
/*------------- -------------------------------*/
|
||||
async askCarac(stage, context) {
|
||||
for (let i = 0; i < stage.system.nbChoixCarac; i++) {
|
||||
context.caracList = []
|
||||
for (let caracKey in stage.system.caracteristiques) {
|
||||
let carac = stage.system.caracteristiques[caracKey]
|
||||
context.caracList.push(game.system.tedeum.config.caracteristiques[carac.caracId])
|
||||
}
|
||||
context.competences = stage.system.competences
|
||||
|
||||
const content = await renderTemplate("systems/fvtt-te-deum/templates/dialogs/character-creator-select-carac.hbs", context)
|
||||
const choiceResult = await foundry.applications.api.DialogV2.wait({
|
||||
window: { title: context.title },
|
||||
classes: ["fvtt-te-deum"],
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
label: context.label,
|
||||
callback: (event, button, dialog) => {
|
||||
const output = Array.from(button.form.elements).reduce((obj, input) => {
|
||||
if (input.name) obj[input.name] = input.value
|
||||
return obj
|
||||
}, {})
|
||||
return output
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: {
|
||||
},
|
||||
rejectClose: false, // Click on Close button will not launch an error
|
||||
render: (event, dialog) => {
|
||||
}
|
||||
})
|
||||
if (choiceResult == null) { return }
|
||||
this.caracBonus[choiceResult.carac].value += 1
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async renderOrigineSociale(stage) {
|
||||
let context = {
|
||||
title: "Création de personnage - Origine Sociale",
|
||||
sexeChoice: { "homme": "Homme", "femme": "Femme" },
|
||||
religionChoice: { "catholique": "Catholique", "protestante": "Protestante" },
|
||||
origineChoice: game.system.tedeum.config.origineSociale
|
||||
}
|
||||
const content = await renderTemplate("systems/fvtt-te-deum/templates/dialogs/character-creator-origine.hbs", context)
|
||||
|
||||
const label = "Valider le choix de l'Origine Sociale"
|
||||
const choiceResult = await foundry.applications.api.DialogV2.wait({
|
||||
window: { title: context.title },
|
||||
classes: ["fvtt-te-deum"],
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
label: label,
|
||||
callback: (event, button, dialog) => {
|
||||
const output = Array.from(button.form.elements).reduce((obj, input) => {
|
||||
if (input.name) obj[input.name] = input.value
|
||||
return obj
|
||||
}, {})
|
||||
return output
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: {
|
||||
},
|
||||
rejectClose: false, // Click on Close button will not launch an error
|
||||
render: (event, dialog) => { }
|
||||
})
|
||||
|
||||
if (choiceResult == null) { return }
|
||||
|
||||
console.log(choiceResult)
|
||||
|
||||
this.sexe = choiceResult.sexe
|
||||
this.religion = choiceResult.religion
|
||||
this.origineSociale = foundry.utils.duplicate(game.system.tedeum.config.origineSociale[choiceResult.origineSociale])
|
||||
this.currentStage = "pouponniere"
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async renderPouponniere(stage) {
|
||||
|
||||
// Filter available pouponniere from origineSociale
|
||||
let pouponniereItems = stage.items.filter(item => item.system.accessible[this.origineSociale.id].isaccessible)
|
||||
|
||||
let context = {
|
||||
title: "Création de personnage - La Pouponnière",
|
||||
label: "Valider le choix de la Pouponnière",
|
||||
choices: pouponniereItems
|
||||
}
|
||||
let choiceResult = await this.askStageName(context)
|
||||
if (choiceResult == null) { return }
|
||||
|
||||
this.pouponniere = foundry.utils.duplicate(stage.items.find(item => item.id === choiceResult.selectedItem))
|
||||
TeDeumUtility.prepareEducationContent(this.pouponniere);
|
||||
console.log(choiceResult, this.pouponniere)
|
||||
|
||||
context.label = "Valider l'augmentation de caracteristique"
|
||||
await this.askCarac(this.pouponniere, context)
|
||||
|
||||
this.processCompetences(this.pouponniere)
|
||||
|
||||
context.title = "Création de personnage - La Pouponnière - Questions"
|
||||
context.label = "Valider cette réponse"
|
||||
await this.askQuestionnaire(this.pouponniere, context)
|
||||
|
||||
this.currentStage = "petitsgrimauds"
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async renderPetitsGrimauds(stage) {
|
||||
// Filter available pouponniere from origineSociale
|
||||
let grimaudsItems = stage.items.filter(item => item.system.accessible[this.origineSociale.id].isaccessible)
|
||||
|
||||
let context = {
|
||||
title: "Création de personnage - Les Petits Grimauds",
|
||||
label: "Valider le choix des Petits Grimauds",
|
||||
choices: grimaudsItems
|
||||
}
|
||||
|
||||
let choiceResult = await this.askStageName(context)
|
||||
if (choiceResult == null) { return }
|
||||
|
||||
this.grimauds = foundry.utils.duplicate(stage.items.find(item => item.id === choiceResult.selectedItem))
|
||||
TeDeumUtility.prepareEducationContent(this.grimauds);
|
||||
console.log(choiceResult, this.grimauds)
|
||||
|
||||
context.label = "Valider l'augmentation de caracteristique"
|
||||
await this.askCarac(this.grimauds, context)
|
||||
|
||||
this.processCompetences(this.grimauds)
|
||||
|
||||
context.title = "Création de personnage - Les Petits Grimauds - Questions"
|
||||
context.label = "Valider cette réponse"
|
||||
await this.askQuestionnaire(this.grimauds, context)
|
||||
|
||||
this.currentStage = "rosevie"
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async renderRosesDeLaVie(stage) {
|
||||
// Filter available pouponniere from origineSociale
|
||||
let rosesItems = stage.items.filter(item => item.system.accessible[this.origineSociale.id].isaccessible)
|
||||
|
||||
let context = {
|
||||
title: "Création de personnage - Les Roses de la Vie",
|
||||
label: "Valider le choix des Roses de la Vie",
|
||||
choices: rosesItems
|
||||
}
|
||||
|
||||
let choiceResult = await this.askStageName(context)
|
||||
if (choiceResult == null) { return }
|
||||
|
||||
this.roses = foundry.utils.duplicate(stage.items.find(item => item.id === choiceResult.selectedItem))
|
||||
TeDeumUtility.prepareEducationContent(this.roses);
|
||||
console.log(choiceResult, this.roses)
|
||||
|
||||
context.label = "Valider l'augmentation de caracteristique"
|
||||
await this.askCarac(this.roses, context)
|
||||
|
||||
this.processCompetences(this.roses)
|
||||
|
||||
context.title = "Création de personnage - Les Roses de la Vie - Questions"
|
||||
context.label = "Valider cette réponse"
|
||||
await this.askQuestionnaire(this.roses, context)
|
||||
|
||||
this.currentStage = "ageviril"
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async renderAgeViril(stage) {
|
||||
// Filter available pouponniere from origineSociale
|
||||
let ageVirilItems = stage.items.filter(item => item.system.accessible[this.origineSociale.id].isaccessible)
|
||||
|
||||
let context = {
|
||||
title: "Création de personnage - L'Age Viril",
|
||||
label: "Valider le choix de l'Age Viril",
|
||||
choices: ageVirilItems
|
||||
}
|
||||
|
||||
let choiceResult = await this.askStageName(context)
|
||||
if (choiceResult == null) { return }
|
||||
|
||||
this.ageViril = foundry.utils.duplicate(stage.items.find(item => item.id === choiceResult.selectedItem))
|
||||
TeDeumUtility.prepareEducationContent(this.ageViril);
|
||||
console.log(choiceResult, this.ageViril)
|
||||
|
||||
context.label = "Valider l'augmentation de caracteristique"
|
||||
await this.askCarac(this.ageViril, context)
|
||||
|
||||
this.processCompetences(this.ageViril)
|
||||
|
||||
this.currentStage = "finished"
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
async processStage() {
|
||||
while (this.currentStage !== "finished") {
|
||||
let stage = this.stages[this.currentStage]
|
||||
switch (this.currentStage) {
|
||||
case "origineSociale":
|
||||
await this.renderOrigineSociale(stage)
|
||||
break
|
||||
case "pouponniere":
|
||||
await this.renderPouponniere(stage)
|
||||
break
|
||||
case "petitsgrimauds":
|
||||
await this.renderPetitsGrimauds(stage)
|
||||
break
|
||||
case "rosevie":
|
||||
await this.renderRosesDeLaVie(stage)
|
||||
break
|
||||
case "ageviril":
|
||||
await this.renderAgeViril(stage)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Carac Bonus", this.caracBonus)
|
||||
console.log("Competence Bonus", this.competenceBonus)
|
||||
}
|
||||
|
||||
}
|
@ -152,16 +152,16 @@ export const TEDEUM_CONFIG = {
|
||||
ageviril: { label: "L'Age Viril", value: "ageviril", agemin: 17, agemax: 17, nbCompetences: 9, nbCaracteristiques: 2, hasQuestionnaire: false, hasMultiplier: true },
|
||||
},
|
||||
origineSociale: {
|
||||
noblesseepee: { label: "Noblesse d'épée", id: "noblesseepee", value: 1 },
|
||||
noblessecloche: { label: "Noblesse de cloche", id: "noblessecloche", value: 2 },
|
||||
hautenoblesse: { label: "Haute noblesse (Illégitime)", id: "hautenoblesse", value: 3 },
|
||||
hautebourgeoisie: { label: "Haute bourgeoisie", id: "hautebourgeoisie", value: 4 },
|
||||
petitebourgeoisie: { label: "Petite bourgeoisie (Marchands)", id: "petitebourgeoisie", value: 5 },
|
||||
artisan: { label: "Artisans", id: "artisan", value: 6 },
|
||||
laboureur: { label: "Laboureurs", id: "laboureur", value: 7 },
|
||||
domesticite: { label: "Domesticité", id: "domesticite", value: 8 },
|
||||
paysannerie: { label: "Paysannerie", id: "paysannerie", value: 9 },
|
||||
gueux: { label: "Gueux", id: "gueux", value: 10 },
|
||||
noblesseepee: { label: "Noblesse d'épée", id: "noblesseepee", caracteristiques: {entregent: 1, puissance: 1}, cagnotte: 10, cagnotteUnit: "livre", value: 1 },
|
||||
noblessecloche: { label: "Noblesse de cloche", id: "noblessecloche", caracteristiques: {entregent: 1, savoir: 1}, cagnotte: 50, cagnotteUnit: "livre", value: 2 },
|
||||
hautenoblesse: { label: "Haute noblesse (Illégitime)", id: "hautenoblesse", caracteristiques: {complexion: 1, puissance: 1}, cagnotte: 20, cagnotteUnit: "livre", value: 3 },
|
||||
hautebourgeoisie: { label: "Haute bourgeoisie", id: "hautebourgeoisie", caracteristiques: {savoir: 1, sensibilite: 1}, cagnotte: 60, cagnotteUnit: "livre",value: 4 },
|
||||
petitebourgeoisie: { label: "Petite bourgeoisie (Marchands)", caracteristiques: {entregent: 1, sensibilite: 1}, cagnotte: 20, cagnotteUnit: "livre",id: "petitebourgeoisie", value: 5 },
|
||||
artisan: { label: "Artisans", id: "artisan", caracteristiques: {adresse: 1, sensibilite: 1}, cagnotte: 10, cagnotteUnit: "livre",value: 6 },
|
||||
laboureur: { label: "Laboureurs", id: "laboureur", caracteristiques: {entregent: 1, complexion: 1}, cagnotte: 10, cagnotteUnit: "livre",value: 7 },
|
||||
domesticite: { label: "Domesticité", id: "domesticite", caracteristiques: {entregent: 1, adresse: 1}, cagnotte: 2, cagnotteUnit: "sol",value: 8 },
|
||||
paysannerie: { label: "Paysannerie", id: "paysannerie", caracteristiques: {puissance: 1, complexion: 1}, cagnotte: 1, cagnotteUnit: "sol", value: 9 },
|
||||
gueux: { label: "Gueux", id: "gueux", caracteristiques: {adresse: 1, complexion: 1}, cagnotte: 4, cagnotteUnit: "denier", value: 10 },
|
||||
},
|
||||
bonusMalus: [
|
||||
{ value: "-2", label: "-2 niveaux" },
|
||||
|
@ -43,8 +43,8 @@ export class TeDeumItemSheet extends ItemSheet {
|
||||
name: this.object.name,
|
||||
editable: this.isEditable,
|
||||
cssClass: this.isEditable ? "editable" : "locked",
|
||||
system: duplicate(this.object.system),
|
||||
config: duplicate(game.system.tedeum.config),
|
||||
system: foundry.utils.duplicate(this.object.system),
|
||||
config: foundry.utils.duplicate(game.system.tedeum.config),
|
||||
competences: TeDeumUtility.getCompetencesForDropDown(),
|
||||
limited: this.object.limited,
|
||||
options: this.options,
|
||||
|
@ -27,6 +27,7 @@ import { TeDeumItemSheet } from "./items/tedeum-item-sheet.js";
|
||||
|
||||
import { TeDeumHotbar } from "./app/tedeum-hotbar.js"
|
||||
import { TeDeumCombat } from "./app/tedeum-combat.js";
|
||||
import { TeDeumCharacterCreator } from "./app/tedeum-character-creator.js"
|
||||
|
||||
import { TeDeumUtility } from "./common/tedeum-utility.js";
|
||||
import { TEDEUM_CONFIG } from "./common/tedeum-config.js";
|
||||
@ -42,6 +43,7 @@ Hooks.once("init", async function () {
|
||||
|
||||
game.system.tedeum = {
|
||||
config: TEDEUM_CONFIG,
|
||||
TeDeumCharacterCreator,
|
||||
TeDeumHotbar
|
||||
}
|
||||
console.log(`Initializing TeDeum RPG 2`);
|
||||
|
Reference in New Issue
Block a user