Table d'astrologie avec toutes les heures

This commit is contained in:
2023-01-09 23:20:51 +01:00
parent 7e75715d88
commit f4f2db68e0
3 changed files with 92 additions and 68 deletions

View File

@ -210,15 +210,10 @@ export class RdDCalendrier extends Application {
}
}
/* -------------------------------------------- */
getCurrentNombreAstral() {
return this.getNombreAstral(this.timestamp.indexDate);
}
/* -------------------------------------------- */
resetNombreAstral() {
this.listeNombreAstral = [];
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", []);
game.socket.emit(SYSTEM_SOCKET_ID, {
msg: "msg_reset_nombre_astral",
@ -227,10 +222,19 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
getNombreAstral(indexDate) {
/**
*
* @param {*} indexDate la date pour laquelle obtenir le nombre astral. Si undefined, on prend la date du jour
* @returns le nombre astral pour la date, ou pour la date du jour si la date n'est pas fournie.
* Si aucun nombre astral n'est trouvé, retourne 0 (cas où l'on demanderait un nombre astral en dehors des 12 jours courant et à venir)
*/
getNombreAstral(indexDate = undefined) {
if (indexDate == undefined) {
indexDate = this.timestamp.indexDate;
}
const listNombreAstral = this.getListeNombreAstral();
let astralData = listNombreAstral.find((nombreAstral, i) => nombreAstral.index == indexDate);
return astralData?.nombreAstral;
return astralData?.nombreAstral ?? 0;
}
/* -------------------------------------------- */
@ -289,8 +293,9 @@ export class RdDCalendrier extends Application {
const indexDate = this.timestamp.indexDate;
const addDay = this.timestamp.heure < heure ? 0 : 1;
await this.setNewTimestamp(new RdDTimestamp({
indexDate: indexDate + addDay, indexHeure: 0 })
.addHeures(heure))
indexDate: indexDate + addDay, indexHeure: 0
})
.addHeures(heure))
}
/* -------------------------------------------- */
@ -358,38 +363,15 @@ export class RdDCalendrier extends Application {
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
}
getHeureChance(heure) {
return heure + (this.getCurrentNombreAstral() ?? 0);
}
/* -------------------------------------------- */
getHeuresChanceMalchance(heureNaissance) {
let defHeure = RdDTimestamp.findHeure(heureNaissance);
if (defHeure) {
const signe = h => h % RDD_HEURES_PAR_JOUR;
const chance = this.getHeureChance(defHeure.heure);
return [
{ ajustement: "+4", heures: [signe(chance)] },
{ ajustement: "+2", heures: [signe(chance + 4), signe(chance + 8)] },
{ ajustement: "-4", heures: [signe(chance + 6)] },
{ ajustement: "-2", heures: [signe(chance + 3), signe(chance + 9)] }
];
}
return [];
static ecartHeureChance(heureNaissance, nombreAstral, heure) {
return (heureNaissance + nombreAstral - heure) % RDD_HEURES_PAR_JOUR;
}
/* -------------------------------------------- */
getAjustementAstrologique(heureNaissance, name = undefined) {
let defHeure = RdDTimestamp.findHeure(heureNaissance);
if (defHeure) {
const chance = this.getHeureChance(defHeure.heure);
const ecartChance = (chance - this.timestamp.heure) % RDD_HEURES_PAR_JOUR;
switch (ecartChance) {
case 0: return 4;
case 4: case 8: return 2;
case 6: return -4;
case 3: case 9: return -2;
}
return RdDCalendrier.ajustementAstrologiqueHeure(defHeure.heure, this.getNombreAstral(), this.timestamp.heure);
}
else if (name) {
ui.notifications.warn(name + " n'a pas d'heure de naissance, ou elle est incorrecte : " + heureNaissance);
@ -400,6 +382,16 @@ export class RdDCalendrier extends Application {
return 0;
}
static ajustementAstrologiqueHeure(hn, nbAstral, heure) {
switch (RdDCalendrier.ecartHeureChance(hn, nbAstral, heure)) {
case 0: return 4;
case 4: case 8: return 2;
case 6: return -4;
case 3: case 9: return -2;
}
return 0;
}
/* -------------------------------------------- */
getData() {
let formData = super.getData();
@ -434,7 +426,7 @@ export class RdDCalendrier extends Application {
// Rebuild text du calendrier
let dateHTML = `${calendrier.jourDuMois} ${calendrier.mois.label} (${calendrier.mois.saison}) de l'année ${calendrier.annee}`
if (game.user.isGM) {
dateHTML = dateHTML + "<br>Nombre Astral: " + (this.getCurrentNombreAstral() ?? "?");
dateHTML = dateHTML + "<br>Nombre Astral: " + (this.getNombreAstral() ?? "?");
}
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
handle.innerHTML = dateHTML;
@ -490,13 +482,21 @@ export class RdDCalendrier extends Application {
return astro;
});
calendrierData.heuresParActeur = {};
game.actors.filter(it => it.isPersonnage() && it.hasPlayerOwner).forEach(actor => {
let heureNaissance = actor.getHeureNaissance();
if (heureNaissance) {
calendrierData.heuresParActeur[actor.name] = this.getHeuresChanceMalchance(heureNaissance);
const nbAstral = this.getNombreAstral()
calendrierData.heures = Array.from(Array(RDD_HEURES_PAR_JOUR).keys());
calendrierData.ajustementsActeur = game.actors.filter(it => it.isPersonnage() && it.hasPlayerOwner).map(actor => {
return {
actor,
ajustements: calendrierData.heures.map(heure => {
const hn = RdDTimestamp.findHeure(actor.getHeureNaissance())?.heure;
return {
heure,
ajustement: RdDCalendrier.ajustementAstrologiqueHeure(hn, nbAstral, heure)
}
})
}
})
});
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-astrologie-template.html', calendrierData);
let astrologieEditeur = new RdDAstrologieEditeur(html, this, calendrierData)
astrologieEditeur.updateData(calendrierData);