Commande /voyage

Ajout de la commande /voyage pour gérer la fatigue en voyage
This commit is contained in:
Vincent Vandemeulebrouck 2023-12-26 19:05:41 +01:00
parent 4274bce7d5
commit 3f098cab31
8 changed files with 291 additions and 9 deletions

View File

@ -16,6 +16,7 @@ import { RdDRollTables } from "./rdd-rolltables.js";
import { RdDUtility } from "./rdd-utility.js";
import { FenetreRechercheTirage } from "./tirage/fenetre-recherche-tirage.js";
import { TMRUtility } from "./tmr-utility.js";
import { DialogFatigueVoyage } from "./voyage/dialog-fatigue-voyage.js";
const rddRollNumeric = /^(\d+)\s*([\+\-]?\d+)?\s*(s)?/;
@ -76,6 +77,7 @@ export class RdDCommands {
this.registerCommand({ path: ["/tirer", "desir"], func: (content, msg, params) => RdDRollTables.getDesirLancinant('chat'), descr: "Tire un Désir Lancinant" });
this.registerCommand({ path: ["/tirer", "rencontre"], func: (content, msg, params) => this.getRencontreTMR(params), descr: `Détermine une rencontre dans les TMR (synonyme de "/tmrr")` });
this.registerCommand({ path: ["/tirage"], func: (content, msg, params) => this.tirage(), descr: "Ouvre la fenêtre de recherche et tirage" });
this.registerCommand({ path: ["/voyage"], func: (content, msg, params) => this.voyage(msg, params), descr: "Gérer le voyage" });
this.registerCommand({ path: ["/sommeil"], func: (content, msg, params) => this.sommeil(msg, params), descr: "Prépare le passage de journée pour chateau dormant" });
this.registerCommand({ path: ["/meteo"], func: (content, msg, params) => this.getMeteo(msg, params), descr: "Propose une météo marine" });
@ -485,10 +487,13 @@ export class RdDCommands {
}
async tirage() {
FenetreRechercheTirage.create();
FenetreRechercheTirage.create()
}
async voyage() {
DialogFatigueVoyage.create()
}
async sommeil() {
DialogChateauDormant.create();
DialogChateauDormant.create()
}
}

View File

@ -63,12 +63,6 @@ const cumulFatigueMatrix = _cumulSegmentsFatigue(fatigueMatrix);
const fatigueMalus = [0, 0, 0, -1, -1, -1, -2, -3, -4, -5, -6, -7]; // Provides the malus for each segment of fatigue
const fatigueLineSize = [3, 6, 7, 8, 9, 10, 11, 12];
const fatigueLineMalus = [0, -1, -2, -3, -4, -5, -6, -7];
const fatigueMarche = {
"aise": { "4": 1, "6": 2, "8": 3, "10": 4, "12": 6 },
"malaise": { "4": 2, "6": 3, "8": 4, "10": 6 },
"difficile": { "4": 3, "6": 4, "8": 6 },
"tresdifficile": { "4": 4, "6": 6 }
}
/* -------------------------------------------- */
const nomEthylisme = ["Emeché", "Gris", "Pinté", "Pas frais", "Ivre", "Bu", "Complètement fait", "Ivre mort"];
@ -208,6 +202,8 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/coeur/afficher-coeur.hbs',
'systems/foundryvtt-reve-de-dragon/templates/tirage/liste-resultats-recherche.hbs',
'systems/foundryvtt-reve-de-dragon/templates/time/horloge.hbs',
'systems/foundryvtt-reve-de-dragon/templates/voyage/fatigue-actor.hbs',
'systems/foundryvtt-reve-de-dragon/templates/voyage/option-vitesse-fatigue.hbs',
'systems/foundryvtt-reve-de-dragon/templates/common/timestamp.hbs',
'systems/foundryvtt-reve-de-dragon/templates/common/periodicite.hbs',
'systems/foundryvtt-reve-de-dragon/templates/common/enum-duree.hbs',
@ -288,6 +284,7 @@ export class RdDUtility {
Handlebars.registerHelper('timestamp-formulesDuree', () => RdDTimestamp.formulesDuree());
Handlebars.registerHelper('timestamp-formulesPeriode', () => RdDTimestamp.formulesPeriode());
Handlebars.registerHelper('array-includes', (array, value) => array.includes(value));
Handlebars.registerHelper('min', (...args) => Math.min(...args.slice(0, -1)));
Handlebars.registerHelper('regle-optionnelle', (option) => ReglesOptionnelles.isUsing(option));
Handlebars.registerHelper('trier', list => list.sort((a, b) => a.name.localeCompare(b.name)));

View File

@ -0,0 +1,182 @@
import { TYPES } from "../item.js"
import { RdDItemCompetence } from "../item-competence.js"
import { ChatUtility } from "../chat-utility.js"
const CODES_COMPETENCES_VOYAGE = ['Extérieur', 'Forêt', 'Montagne', 'Marais', 'Glace', 'Equitation']
const TABLEAU_FATIGUE_MARCHE = [
{
code: "aise", label: "Aisé", description: "Route ou chemin",
survies: ['Extérieur', 'Equitation'],
vitesses: [{ vitesse: 4, fatigue: 1 }, { vitesse: 6, fatigue: 2 }, { vitesse: 8, fatigue: 3 }, { vitesse: 10, fatigue: 4 }, { vitesse: 12, fatigue: 6 }],
},
{
code: "malaise", label: "Malaisé", description: "Hors piste (herbes et buissons)",
survies: ['Extérieur', 'Equitation'],
vitesses: [{ vitesse: 4, fatigue: 2 }, { vitesse: 6, fatigue: 3 }, { vitesse: 8, fatigue: 4 }, { vitesse: 10, fatigue: 6 }],
},
{
code: "difficile", label: "Difficile", description: "Hors piste (collines, forêt)",
survies: ['Extérieur', 'Forêt', 'Glace', 'Equitation'],
vitesses: [{ vitesse: 4, fatigue: 3 }, { vitesse: 6, fatigue: 4 }, { vitesse: 8, fatigue: 6 }],
},
{
code: "tresdifficile", label: "Très difficile", description: "Hors piste (montagne, jungle, marais)",
survies: ['Forêt', 'Montagne', 'Marais', 'Glace'],
vitesses: [{ vitesse: 4, fatigue: 4 }, { vitesse: 6, fatigue: 6 }],
},
]
export class DialogFatigueVoyage extends Dialog {
static dialog = undefined
static async create() {
if (!game.user.isGM) {
return
}
if (!DialogFatigueVoyage.dialog) {
const playerActors = game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage())
.map(actor => DialogFatigueVoyage.prepareActor(actor))
const parameters = {
tableauFatigueMarche: TABLEAU_FATIGUE_MARCHE,
playerActors: playerActors,
nombreHeures: 1,
}
DialogFatigueVoyage.setModeDeplacement(parameters, undefined, undefined)
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/voyage/dialog-fatigue-voyage.hbs", parameters);
DialogFatigueVoyage.dialog = new DialogFatigueVoyage(html, parameters);
}
DialogFatigueVoyage.dialog.render(true);
}
static setModeDeplacement(parameters, code, vitesse) {
const ligneFatigueMarche = TABLEAU_FATIGUE_MARCHE.find(it => it.code == code) ?? TABLEAU_FATIGUE_MARCHE[0]
const rythme = ligneFatigueMarche.vitesses.find(it => it.vitesse == vitesse) ?? ligneFatigueMarche.vitesses[0]
parameters.typeTerrain = ligneFatigueMarche
parameters.vitesseDeplacement = rythme.vitesse
parameters.fatigueHoraire = rythme.fatigue
}
static prepareActor(actor) {
const competencesVoyage = {}
CODES_COMPETENCES_VOYAGE.forEach(codeSurvie =>
competencesVoyage[codeSurvie] = RdDItemCompetence.findCompetence(actor.itemTypes[TYPES.competence], codeSurvie, { onMessage: () => { } })
)
return {
actor: actor,
selected: true,
ajustementFatigue: 0,
competencesVoyage: competencesVoyage
}
}
constructor(html, parameters) {
const options = {
classes: ["dialog-fatigue-voyage"],
width: 600,
height: 'fit-content',
'max-height': 900,
'z-index': 99999
}
const conf = {
title: "Fatigue de voyage",
content: html,
buttons: {}
}
super(conf, options);
this.parameters = parameters
this.controls = {}
}
activateListeners(html) {
if (this.html == undefined) {
html.find('select[name="code-terrain"]').trigger("focus")
}
this.html = html;
super.activateListeners(html);
this.html.find('select[name="code-terrain"]').change(event => this.changeParameters())
this.html.find('select[name="vitesse-deplacement"]').change(event => this.changeParameters())
this.html.find('input[name="nombre-heures"]').change(event => this.changeParameters())
this.html.find('button[name="appliquer-fatigue"]').click(event => this.appliquerFatigue())
}
changeParameters() {
this.changeTerrain(this.html.find('select[name="code-terrain"]').val())
this.changeVitesse(this.html.find('select[name="vitesse-deplacement"]').val())
this.changeNombreHeures(this.html.find('input[name="nombre-heures"]').val())
this.setFatigue()
}
async changeTerrain(codeTerrain) {
if (this.parameters.typeTerrain.code != codeTerrain) {
const selectVitesseDeplacement = this.html.find('select[name="vitesse-deplacement"]')
const vitesse = selectVitesseDeplacement.val()
selectVitesseDeplacement.empty()
DialogFatigueVoyage.setModeDeplacement(this.parameters, codeTerrain, vitesse)
this.parameters.typeTerrain.vitesses.forEach(async rythme => {
selectVitesseDeplacement.append(await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/voyage/option-vitesse-fatigue.hbs', rythme))
})
selectVitesseDeplacement.val(this.parameters.vitesseDeplacement).change()
}
}
async changeVitesse(vitesse) {
if (this.parameters.vitesseDeplacement != vitesse) {
DialogFatigueVoyage.setModeDeplacement(this.parameters, this.parameters.typeTerrain.code, vitesse)
}
}
async changeNombreHeures(nombreHeures) {
this.parameters.nombreHeures = parseInt(nombreHeures)
}
async setFatigue() {
this.html.find('input[name="base-fatigue"]').val(this.parameters.nombreHeures * this.parameters.fatigueHoraire)
}
async appliquerFatigue() {
const fatigueBase = parseInt(this.html.find('input[name="base-fatigue"]').val() ?? 0)
const actors = jQuery.map(
this.html.find('div.fatigue-actors-list li.list-item'),
it => this.$extractActor(this.html.find(it))
)
actors.filter(it => it.selected)
.forEach(async it => {
const perteFatigue = fatigueBase + it.ajustement
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(it.actor.name),
content: await renderTemplate(
'systems/foundryvtt-reve-de-dragon/templates/voyage/chat-fatigue_voyage.hbs', mergeObject(it,
{
parameters: this.parameters,
fatigueBase: fatigueBase,
perteFatigue: perteFatigue,
isVoyage: fatigueBase == this.parameters.nombreHeures * this.parameters.fatigueHoraire
})
),
})
await it.actor.santeIncDec("fatigue", perteFatigue)
})
}
$extractActor(actorRow) {
const actor = game.actors.get(actorRow.data('actor-id'))
if (!actor) {
ui.notifications.warn(`Acteur ${it.actorId} introuvable`)
}
return {
actor: actor,
ajustement: parseInt(actorRow.find('input[name="ajustement-fatigue"]').val() ?? 0),
selected: actor && actorRow.find('input[name="selectionner-acteur"]').is(':checked')
}
}
async close() {
DialogFatigueVoyage.dialog = undefined
await super.close()
}
}

View File

@ -440,7 +440,13 @@ table {border: 1px solid #7a7971;}
.flex-grow-2 {
flex-grow: 2;
}
.voyage-liste-survies {
max-width: 12rem;
}
/* Styles limited to foundryvtt-reve-de-dragon sheets */
.texte-dans-liste {
text-align: left;
}
.equipement-nom {
flex-grow : 4;
margin: 0;
@ -1168,7 +1174,7 @@ ul.chat-list li:nth-child(odd) {
border-radius: 0.25rem;
padding: 0.1rem;
flex: 1 1 1.5rem;
display: flex !important;
display: flex;
align-items: center !important;
}

View File

@ -0,0 +1,10 @@
<img class="chat-icon" src="{{actor.img}}" data-tooltip="{{actor.name}}" />
<p>{{actor.name}} s'est fatigué de {{perteFatigue}}
{{#if (and isVoyage (gt parameters.nombreHeures 0))}}
après {{parameters.nombreHeures}} heure{{#if (gt parameters.nombreHeures 1)}}s{{/if}}
de voyage {{lowerFirst parameters.typeTerrain.label}}
à {{parameters.vitesseDeplacement}} km/h<sup>dr</sup> (Fatigue par heure: {{parameters.fatigueHoraire}})
</p>
<p>{{parameters.typeTerrain.description}}
{{/if}}
</p>

View File

@ -0,0 +1,58 @@
<form class="dialog-fatigue-voyage">
<div class="flexcol">
<div class="flexrow">
<label for="code-terrain" class="flex-shrink">Type de terrain</label>
<div>
<select type="text" name="code-terrain" value="{{typeTerrain.code}}" data-dtype="String">
{{#select typeTerrain.code}}
{{#each tableauFatigueMarche as |ligne|}}
<option value="{{ligne.code}}">{{ligne.label}} - {{ligne.description}}</option>
{{/each}}
{{/select}}
</select>
</div>
</div>
<div class="flexrow">
<label for="vitesse-deplacement" class="flex-shrink">Vitesse de marche</label>
<div>
<select type="text" name="vitesse-deplacement" value="{{vitesseDeplacement}}" data-dtype="String">
{{#select vitesseDeplacement}}
{{#each typeTerrain.vitesses as |rythme|}}
{{> 'systems/foundryvtt-reve-de-dragon/templates/voyage/option-vitesse-fatigue.hbs' vitesse=rythme.vitesse fatigue=rythme.fatigue}}
{{/each}}
{{/select}}
</select>
</div>
</div>
<div class="flexrow">
<label for="nombre-heures" class="flex-shrink">Nombre d'heures</label>
<div>
<input type="number" name="nombre-heures" class="number-x2 nombre-heures" data-dtype="Number" value="{{nombreHeures}}" min="1" max="8"/> heures
</div>
</div>
<div class="flexrow">
<label for="base-fatigue" class="flex-shrink">Fatigue à appliquer</label>
<div>
<input type="number" name="base-fatigue" class="number-x2 base-fatigue" data-dtype="Number" value="{{nombreHeures}}" min="1" max="60"/>
</div>
</div>
<div><hr></div>
<div class="flexrow fatigue-actors-list">
<ul class="item-list alterne-list scrollable-list">
<li class="competence-header flexrow">
<span class="flex-grow-2">Personnage</span>
<span class="flex-grow-2">Survies</span>
<span class="flex-grow-1" data-tooltip="Ajustements à appliquer pour les personnages se reposant (par exemple, à cheval)">Ajustements</span>
</li>
{{#each playerActors as |selected|}}
{{>'systems/foundryvtt-reve-de-dragon/templates/voyage/fatigue-actor.hbs' voyageur=selected survies=@root.typeTerrain.survies}}
{{/each}}
</ul>
</div>
<hr>
<div class="flexrow">
<span class="flex-shrink"></span>
<button name="appliquer-fatigue">Appliquer la fatigue</button>
</div>
</div>
</form>

View File

@ -0,0 +1,23 @@
<li class="item flexrow list-item texte-dans-liste" data-actor-id="{{voyageur.actor.id}}">
<span class="flex-grow-2 flexrow">
<input type="checkbox" name="selectionner-acteur" {{#if voyageur.selected}}checked{{/if}}/>
<label>
<img class="chat-icon" src="{{voyageur.actor.img}}" data-tooltip="{{voyageur.actor.name}}" />
<span>{{voyageur.actor.name}}</span>
</label>
</span>
<span class="flex-grow-2">
<div class="flexcol ">
<label class="voyage-liste-survies">
{{#each voyageur.competencesVoyage as |comp key|}}
{{#if (array-includes ../survies key)}}
{{key}} {{comp.system.niveau}},
{{/if}}
{{/each}}
</label>
</div>
</span>
<span class="flex-grow-1">
<input type="number" name="ajustement-fatigue" class="number-x2 ajustement-fatigue" data-dtype="Number" value="{{voyageur.ajustementFatigue}}" min="-6" max="6"/>
</span>
</li>

View File

@ -0,0 +1 @@
<option value="{{vitesse}}">{{vitesse}} km/h<sup>dr</sup> (Fatigue: {{fatigue}})</option>