2023-03-08 02:02:40 +01:00
|
|
|
import { MAX_NOMBRE_ASTRAL, RdDTimestamp, WORLD_TIMESTAMP_SETTING } from "./rdd-timestamp.js";
|
2023-03-29 22:53:40 +02:00
|
|
|
import { RdDCalendrierEditor } from "./rdd-calendrier-editor.js";
|
|
|
|
import { RdDResolutionTable } from "../rdd-resolution-table.js";
|
|
|
|
import { RdDUtility } from "../rdd-utility.js";
|
|
|
|
import { RdDDice } from "../rdd-dice.js";
|
|
|
|
import { Misc } from "../misc.js";
|
|
|
|
import { DialogChronologie } from "../dialog-chronologie.js";
|
|
|
|
import { HIDE_DICE, SHOW_DICE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "../constants.js";
|
|
|
|
import { ReglesOptionelles } from "../settings/regles-optionelles.js";
|
|
|
|
import { DialogChateauDormant } from "../sommeil/dialog-chateau-dormant.js";
|
|
|
|
import { APP_ASTROLOGIE_REFRESH, AppAstrologie } from "../sommeil/app-astrologie.js";
|
|
|
|
|
|
|
|
const TEMPLATE_CALENDRIER = "systems/foundryvtt-reve-de-dragon/templates/time/calendar.hbs";
|
|
|
|
|
|
|
|
const INITIAL_CALENDAR_POS = { top: 200, left: 200, horlogeAnalogique: true };
|
2020-09-20 16:36:39 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class RdDCalendrier extends Application {
|
2023-03-29 22:53:40 +02:00
|
|
|
static init() {
|
|
|
|
game.settings.register(SYSTEM_RDD, "liste-nombre-astral", {
|
|
|
|
name: "liste-nombre-astral",
|
|
|
|
scope: "world",
|
|
|
|
config: false,
|
|
|
|
default: [],
|
|
|
|
type: Object
|
|
|
|
});
|
2020-12-08 21:40:41 +01:00
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
game.settings.register(SYSTEM_RDD, "calendrier-pos", {
|
|
|
|
name: "calendrierPos",
|
|
|
|
scope: "client",
|
|
|
|
config: false,
|
|
|
|
default: INITIAL_CALENDAR_POS,
|
|
|
|
type: Object
|
2022-12-09 02:00:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
title: "Calendrier",
|
|
|
|
template: TEMPLATE_CALENDRIER,
|
|
|
|
classes: ["calendar"],
|
|
|
|
popOut: true,
|
|
|
|
resizable: false,
|
|
|
|
width: 'fit-content',
|
|
|
|
height: 'fit-content',
|
|
|
|
});
|
2021-06-08 14:11:23 +02:00
|
|
|
}
|
2021-06-08 14:09:40 +02:00
|
|
|
|
2021-07-09 01:01:12 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2023-01-07 20:06:04 +01:00
|
|
|
this.timestamp = RdDTimestamp.getWorldTime();
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.isUniqueConnectedGM()) { // Uniquement si GM
|
2023-01-05 00:55:04 +01:00
|
|
|
RdDTimestamp.setWorldTime(this.timestamp);
|
2023-03-08 02:02:40 +01:00
|
|
|
this.nombresAstraux = this.getNombresAstraux();
|
|
|
|
this.rebuildNombresAstraux(HIDE_DICE); // Ensure always up-to-date
|
2020-12-08 23:12:43 +01:00
|
|
|
}
|
2023-01-07 20:06:04 +01:00
|
|
|
Hooks.on('updateSetting', async (setting, update, options, id) => this.onUpdateSetting(setting, update, options, id));
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
get title() {
|
|
|
|
const calendrier = this.timestamp.toCalendrier();
|
|
|
|
return `${calendrier.heure.label}, ${calendrier.jourDuMois} ${calendrier.mois.label} ${calendrier.annee} (${calendrier.mois.saison})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
savePosition() {
|
|
|
|
game.settings.set(SYSTEM_RDD, "calendrier-pos", {
|
|
|
|
top: this.position.top,
|
|
|
|
left: this.position.left,
|
|
|
|
horlogeAnalogique: this.horlogeAnalogique
|
2023-03-09 22:46:59 +01:00
|
|
|
});
|
2023-03-29 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getSavePosition() {
|
|
|
|
const pos = game.settings.get(SYSTEM_RDD, "calendrier-pos");
|
|
|
|
if (pos?.top == undefined) {
|
|
|
|
return INITIAL_CALENDAR_POS;
|
|
|
|
}
|
|
|
|
this.horlogeAnalogique = pos.horlogeAnalogique;
|
|
|
|
return pos
|
|
|
|
}
|
|
|
|
|
|
|
|
setPosition(position) {
|
|
|
|
super.setPosition(position)
|
|
|
|
this.savePosition()
|
|
|
|
}
|
|
|
|
|
|
|
|
display() {
|
|
|
|
const pos = this.getSavePosition()
|
2023-03-31 01:31:09 +02:00
|
|
|
this.render(true, { left: pos.left, top: pos.top });
|
2023-03-09 22:46:59 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
_getHeaderButtons() {
|
|
|
|
const buttons = [];
|
|
|
|
if (game.user.isGM) {
|
|
|
|
buttons.unshift({
|
|
|
|
class: "calendar-astrologie",
|
|
|
|
icon: "fa-solid fa-moon-over-sun",
|
|
|
|
onclick: ev => this.showAstrologieEditor()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
class: "calendar-set-datetime",
|
|
|
|
icon: "fa-solid fa-calendar-pen",
|
|
|
|
onclick: ev => this.showCalendarEditor()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return buttons
|
|
|
|
}
|
2023-05-25 13:17:16 +02:00
|
|
|
|
|
|
|
/*async maximize() {
|
2023-03-29 22:53:40 +02:00
|
|
|
await super.maximize()
|
|
|
|
this.render(true)
|
2023-05-25 13:17:16 +02:00
|
|
|
}*/
|
2023-03-29 22:53:40 +02:00
|
|
|
|
2023-03-31 00:51:05 +02:00
|
|
|
async close() { }
|
|
|
|
|
2023-01-07 20:06:04 +01:00
|
|
|
async onUpdateSetting(setting, update, options, id) {
|
|
|
|
if (setting.key == SYSTEM_RDD + '.' + WORLD_TIMESTAMP_SETTING) {
|
|
|
|
this.timestamp = RdDTimestamp.getWorldTime();
|
2023-03-31 01:31:09 +02:00
|
|
|
this.positionAiguilles()
|
2023-04-14 20:31:47 +02:00
|
|
|
this.render(false);
|
2023-03-08 22:33:23 +01:00
|
|
|
Hooks.callAll(APP_ASTROLOGIE_REFRESH);
|
2023-01-07 20:06:04 +01:00
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
getData() {
|
|
|
|
const formData = super.getData();
|
|
|
|
this.fillCalendrierData(formData);
|
|
|
|
return formData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
fillCalendrierData(formData = {}) {
|
|
|
|
mergeObject(formData, this.timestamp.toCalendrier());
|
|
|
|
formData.isGM = game.user.isGM;
|
|
|
|
formData.heures = RdDTimestamp.definitions()
|
|
|
|
formData.horlogeAnalogique = this.horlogeAnalogique;
|
|
|
|
return formData;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:14:49 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-12-09 02:00:31 +01:00
|
|
|
/** @override */
|
|
|
|
async activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
this.html = html;
|
|
|
|
this.html.find('.ajout-chronologie').click(ev => DialogChronologie.create());
|
2023-03-29 22:53:40 +02:00
|
|
|
this.html.find('.toggle-horloge-analogique').click(ev => this.onToggleHorlogeAnalogique())
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.calendar-btn').click(ev => this.onCalendarButton(ev));
|
2023-03-29 22:53:40 +02:00
|
|
|
this.html.find('.horloge-roue .horloge-heure').click(event => {
|
|
|
|
const h = this.html.find(event.currentTarget)?.data('heure');
|
|
|
|
this.positionnerHeure(Number(h));
|
|
|
|
})
|
2023-02-08 18:57:07 +01:00
|
|
|
this.html.find('.calendar-set-datetime').click(ev => {
|
2022-12-09 02:00:31 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
this.showCalendarEditor();
|
|
|
|
});
|
|
|
|
|
2023-02-08 18:57:07 +01:00
|
|
|
this.html.find('.calendar-astrologie').click(ev => {
|
2022-12-09 02:00:31 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
this.showAstrologieEditor();
|
2021-07-09 01:01:12 +02:00
|
|
|
});
|
2023-03-31 01:31:09 +02:00
|
|
|
this.positionAiguilles()
|
|
|
|
}
|
|
|
|
|
|
|
|
positionAiguilles() {
|
|
|
|
const timestamp = this.getTimestamp();
|
|
|
|
this.html.find(`div.horloge-roue div.horloge-aiguille-heure img`).css(Misc.cssRotation(timestamp.angleHeure));
|
|
|
|
this.html.find(`div.horloge-roue div.horloge-aiguille-minute img`).css(Misc.cssRotation(timestamp.angleMinute));
|
2023-03-29 22:53:40 +02:00
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
onToggleHorlogeAnalogique() {
|
|
|
|
this.horlogeAnalogique = !this.horlogeAnalogique;
|
|
|
|
this.savePosition()
|
2023-03-31 01:31:09 +02:00
|
|
|
this.display()
|
2022-12-09 02:00:31 +01:00
|
|
|
}
|
2023-03-29 22:53:40 +02:00
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-03-08 02:02:40 +01:00
|
|
|
getNombresAstraux() {
|
2022-12-09 02:00:31 +01:00
|
|
|
return game.settings.get(SYSTEM_RDD, "liste-nombre-astral") ?? [];
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2020-12-08 23:28:29 +01:00
|
|
|
|
2020-12-10 20:14:35 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
dateCourante() {
|
|
|
|
return this.timestamp.formatDate();
|
2020-12-10 20:14:35 +01:00
|
|
|
}
|
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
isAfterIndexDate(indexDate) {
|
2023-01-07 20:06:04 +01:00
|
|
|
// TODO: standardize
|
2023-01-05 00:55:04 +01:00
|
|
|
return indexDate < this.timestamp.indexDate;
|
2021-04-04 18:37:16 +02:00
|
|
|
}
|
|
|
|
|
2021-01-16 18:54:07 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
heureCourante() { return RdDTimestamp.definition(this.timestamp.heure); }
|
2021-01-16 18:54:07 +01:00
|
|
|
|
2020-12-09 00:01:02 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
getCurrentMinute() { return this.timestamp.indexMinute; }
|
|
|
|
|
2023-02-10 02:01:43 +01:00
|
|
|
getTimestamp() {
|
|
|
|
return this.timestamp;
|
|
|
|
}
|
2023-01-05 00:55:04 +01:00
|
|
|
getTimestampFinChateauDormant(nbJours = 0) {
|
2023-02-07 18:06:45 +01:00
|
|
|
return this.timestamp.nouveauJour().addJours(nbJours);
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getTimestampFinHeure(nbHeures = 0) {
|
|
|
|
return this.timestamp.nouvelleHeure().addHeures(nbHeures);
|
2020-12-09 00:01:02 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2021-04-04 18:37:16 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getIndexFromDate(jour, mois) {
|
2023-01-05 00:55:04 +01:00
|
|
|
const addYear = mois < this.timestamp.mois || (mois == this.timestamp.mois && jour < this.timestamp.jour)
|
|
|
|
const time = RdDTimestamp.timestamp(this.timestamp.annee + (addYear ? 1 : 0), mois, jour);
|
|
|
|
return time.indexDate;
|
2021-04-04 18:37:16 +02:00
|
|
|
}
|
2023-01-05 00:55:04 +01:00
|
|
|
|
2020-12-12 23:31:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
getJoursSuivants(count) {
|
2023-03-08 02:00:38 +01:00
|
|
|
return Misc.intArray(this.timestamp.indexDate, this.timestamp.indexDate + count)
|
|
|
|
.map(i => { return { label: RdDTimestamp.formatIndexDate(i), index: i } })
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
async ajouterNombreAstral(indexDate, showDice = SHOW_DICE) {
|
2021-12-03 22:53:38 +01:00
|
|
|
const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: showDice, rollMode: "selfroll" });
|
2023-01-05 00:55:04 +01:00
|
|
|
const dateFuture = RdDTimestamp.formatIndexDate(indexDate);
|
2021-12-03 22:53:38 +01:00
|
|
|
if (showDice != HIDE_DICE) {
|
2021-07-09 01:01:12 +02:00
|
|
|
ChatMessage.create({
|
2021-06-25 14:40:25 +02:00
|
|
|
whisper: ChatMessage.getWhisperRecipients("GM"),
|
|
|
|
content: `Le chiffre astrologique du ${dateFuture} sera le ${nombreAstral}`
|
|
|
|
});
|
|
|
|
}
|
2020-12-08 23:28:29 +01:00
|
|
|
return {
|
2021-05-19 23:04:34 +02:00
|
|
|
nombreAstral: nombreAstral,
|
2020-12-08 23:28:29 +01:00
|
|
|
valeursFausses: [],
|
2023-01-05 00:55:04 +01:00
|
|
|
index: indexDate
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-25 10:08:40 +02:00
|
|
|
/* -------------------------------------------- */
|
2023-03-08 02:02:40 +01:00
|
|
|
resetNombresAstraux() {
|
|
|
|
this.nombresAstraux = [];
|
2023-01-09 23:20:51 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", []);
|
2021-06-01 21:58:40 +02:00
|
|
|
|
2022-01-29 22:49:34 +01:00
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2021-06-01 21:58:40 +02:00
|
|
|
msg: "msg_reset_nombre_astral",
|
|
|
|
data: {}
|
|
|
|
});
|
2021-04-25 10:08:40 +02:00
|
|
|
}
|
|
|
|
|
2023-01-09 23:20:51 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
}
|
2023-03-08 02:02:40 +01:00
|
|
|
this.nombresAstraux = this.getNombresAstraux();
|
|
|
|
let astralData = this.nombresAstraux.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
2023-01-09 23:20:51 +01:00
|
|
|
return astralData?.nombreAstral ?? 0;
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
2021-02-04 01:00:17 +01:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-03-08 02:02:40 +01:00
|
|
|
async rebuildNombresAstraux(showDice = HIDE_DICE) {
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.isUniqueConnectedGM()) {
|
2023-05-25 13:17:16 +02:00
|
|
|
console.log("Astral rebuild")
|
2021-05-20 21:36:20 +02:00
|
|
|
let newList = [];
|
2021-06-09 00:00:15 +02:00
|
|
|
for (let i = 0; i < MAX_NOMBRE_ASTRAL; i++) {
|
2023-01-05 00:55:04 +01:00
|
|
|
let dayIndex = this.timestamp.indexDate + i;
|
2023-03-08 02:02:40 +01:00
|
|
|
let na = this.nombresAstraux.find(n => n.index == dayIndex);
|
2021-06-09 00:00:15 +02:00
|
|
|
if (na) {
|
2021-07-09 01:01:12 +02:00
|
|
|
newList[i] = na;
|
2021-06-07 22:52:42 +02:00
|
|
|
} else {
|
2021-07-09 01:01:12 +02:00
|
|
|
newList[i] = await this.ajouterNombreAstral(dayIndex, showDice);
|
2021-05-20 21:36:20 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 02:02:40 +01:00
|
|
|
this.nombresAstraux = newList;
|
2023-01-05 00:55:04 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", newList);
|
2023-03-08 02:02:40 +01:00
|
|
|
game.actors.filter(it => it.isPersonnage()).forEach(actor => actor.supprimerAnciensNombresAstraux());
|
|
|
|
this.notifyChangeNombresAstraux();
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
}
|
2021-06-09 16:38:52 +02:00
|
|
|
|
2023-03-08 02:02:40 +01:00
|
|
|
notifyChangeNombresAstraux() {
|
|
|
|
Hooks.callAll(APP_ASTROLOGIE_REFRESH);
|
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
|
|
|
msg: "msg_refresh_nombre_astral",
|
|
|
|
data: {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-14 16:02:31 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
async setNewTimestamp(newTimestamp) {
|
2023-02-07 18:06:45 +01:00
|
|
|
const oldTimestamp = this.timestamp;
|
2023-02-10 02:01:43 +01:00
|
|
|
await Promise.all(game.actors.map(async actor => await actor.onTimeChanging(oldTimestamp, newTimestamp)));
|
2023-01-05 00:55:04 +01:00
|
|
|
RdDTimestamp.setWorldTime(newTimestamp);
|
2023-02-07 18:06:45 +01:00
|
|
|
if (oldTimestamp.indexDate + 1 == newTimestamp.indexDate && ReglesOptionelles.isUsing("chateau-dormant-gardien")) {
|
|
|
|
await DialogChateauDormant.create();
|
|
|
|
}
|
2023-01-05 00:55:04 +01:00
|
|
|
this.timestamp = newTimestamp;
|
2023-03-08 02:02:40 +01:00
|
|
|
await this.rebuildNombresAstraux();
|
2023-03-31 01:31:09 +02:00
|
|
|
this.positionAiguilles()
|
2023-03-29 22:53:40 +02:00
|
|
|
this.display();
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
async onCalendarButton(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
|
|
|
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
|
|
|
if (calendarAvance) {
|
|
|
|
await this.incrementTime(Number(calendarAvance.value));
|
2022-12-29 02:31:29 +01:00
|
|
|
}
|
2023-01-05 00:55:04 +01:00
|
|
|
else if (calendarSet) {
|
|
|
|
this.positionnerHeure(Number(calendarSet.value));
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2023-03-31 01:31:09 +02:00
|
|
|
this.positionAiguilles()
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
2023-03-31 01:31:09 +02:00
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async incrementTime(minutes = 0) {
|
2023-03-29 22:53:40 +02:00
|
|
|
if (game.user.isGM) {
|
|
|
|
await this.setNewTimestamp(this.timestamp.addMinutes(minutes));
|
|
|
|
Hooks.callAll(APP_ASTROLOGIE_REFRESH);
|
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2023-03-31 01:31:09 +02:00
|
|
|
|
2020-12-08 23:28:29 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-07-09 01:01:12 +02:00
|
|
|
async incrementerJour() {
|
2023-01-05 00:55:04 +01:00
|
|
|
await this.setNewTimestamp(this.timestamp.nouveauJour());
|
2020-12-08 23:28:29 +01:00
|
|
|
}
|
2023-03-31 01:31:09 +02:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-08 23:20:54 +01:00
|
|
|
async positionnerHeure(heure) {
|
2023-03-29 22:53:40 +02:00
|
|
|
if (game.user.isGM) {
|
|
|
|
const indexDate = this.timestamp.indexDate;
|
|
|
|
const addDay = this.timestamp.heure < heure ? 0 : 1;
|
|
|
|
const newTimestamp = new RdDTimestamp({ indexDate: indexDate + addDay }).addHeures(heure);
|
|
|
|
await this.setNewTimestamp(newTimestamp)
|
|
|
|
Hooks.callAll(APP_ASTROLOGIE_REFRESH);
|
|
|
|
}
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2023-03-31 01:31:09 +02:00
|
|
|
|
2020-12-12 23:31:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
getLectureAstrologieDifficulte(dateIndex) {
|
2023-01-05 00:55:04 +01:00
|
|
|
let indexNow = this.timestamp.indexDate;
|
2020-12-12 23:31:19 +01:00
|
|
|
let diffDay = dateIndex - indexNow;
|
|
|
|
return - Math.floor(diffDay / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
async requestNombreAstral(request) {
|
2022-12-29 02:31:29 +01:00
|
|
|
const actor = game.actors.get(request.id);
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.isUniqueConnectedGM()) { // Only once
|
2021-03-14 16:02:31 +01:00
|
|
|
console.log(request);
|
|
|
|
let jourDiff = this.getLectureAstrologieDifficulte(request.date);
|
2022-06-12 12:14:55 +02:00
|
|
|
let niveau = Number(request.astrologie.system.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat);
|
2021-05-19 23:04:34 +02:00
|
|
|
let rollData = {
|
2020-12-17 00:05:32 +01:00
|
|
|
caracValue: request.carac_vue,
|
|
|
|
finalLevel: niveau,
|
2021-12-03 22:53:38 +01:00
|
|
|
showDice: HIDE_DICE,
|
2021-06-13 21:56:01 +02:00
|
|
|
rollMode: "blindroll"
|
2021-04-01 00:01:37 +02:00
|
|
|
};
|
|
|
|
await RdDResolutionTable.rollData(rollData);
|
|
|
|
request.rolled = rollData.rolled;
|
2022-12-29 02:31:29 +01:00
|
|
|
request.isValid = request.rolled.isSuccess;
|
|
|
|
request.nbAstral = this.getNombreAstral(request.date);
|
2023-01-05 00:55:04 +01:00
|
|
|
|
2022-12-29 02:31:29 +01:00
|
|
|
if (request.rolled.isSuccess) {
|
2023-01-05 00:55:04 +01:00
|
|
|
if (request.rolled.isPart) {
|
2022-12-29 02:31:29 +01:00
|
|
|
// Gestion expérience (si existante)
|
|
|
|
request.competence = actor.getCompetence("astrologie")
|
|
|
|
request.selectedCarac = actor.system.carac["vue"];
|
|
|
|
actor.appliquerAjoutExperience(request, 'hide');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
request.nbAstral = await RdDDice.rollTotal("1dhr" + request.nbAstral, {
|
|
|
|
rollMode: "selfroll", showDice: HIDE_DICE
|
|
|
|
});
|
2020-12-12 23:41:04 +01:00
|
|
|
// Mise à jour des nombres astraux du joueur
|
2022-12-29 02:31:29 +01:00
|
|
|
this.addNbAstralIncorect(request.id, request.date, request.nbAstral);
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
2022-12-29 02:31:29 +01:00
|
|
|
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.getActiveUser(request.userId)?.isGM) {
|
2021-03-14 16:02:31 +01:00
|
|
|
RdDUtility.responseNombreAstral(request);
|
|
|
|
} else {
|
2022-01-29 22:49:34 +01:00
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2020-12-12 23:31:19 +01:00
|
|
|
msg: "msg_response_nombre_astral",
|
2021-03-14 16:02:31 +01:00
|
|
|
data: request
|
|
|
|
});
|
2020-12-12 23:31:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 02:31:29 +01:00
|
|
|
addNbAstralIncorect(actorId, date, nbAstral) {
|
2023-03-29 22:53:40 +02:00
|
|
|
const astralData = this.nombresAstraux.find((nombreAstral, i) => nombreAstral.index == date);
|
2022-12-29 02:31:29 +01:00
|
|
|
astralData.valeursFausses.push({ actorId: actorId, nombreAstral: nbAstral });
|
2023-03-08 02:02:40 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.nombresAstraux);
|
2022-12-29 02:31:29 +01:00
|
|
|
}
|
|
|
|
|
2020-12-11 16:19:19 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-06-04 18:30:06 +02:00
|
|
|
getAjustementAstrologique(heureNaissance, name = undefined) {
|
2023-03-29 22:53:40 +02:00
|
|
|
const defHeure = RdDTimestamp.findHeure(heureNaissance);
|
2021-06-04 18:30:06 +02:00
|
|
|
if (defHeure) {
|
2023-03-08 02:02:40 +01:00
|
|
|
return RdDTimestamp.ajustementAstrologiqueHeure(defHeure.heure, this.getNombreAstral(), this.timestamp.heure);
|
2020-12-15 23:28:59 +01:00
|
|
|
}
|
2021-06-04 18:30:06 +02:00
|
|
|
else if (name) {
|
2021-01-16 18:54:07 +01:00
|
|
|
ui.notifications.warn(name + " n'a pas d'heure de naissance, ou elle est incorrecte : " + heureNaissance);
|
2020-12-11 03:23:34 +01:00
|
|
|
}
|
2021-06-09 00:00:15 +02:00
|
|
|
else {
|
|
|
|
ui.notifications.warn(heureNaissance + " ne correspond pas à une heure de naissance");
|
2021-06-04 18:30:06 +02:00
|
|
|
}
|
2020-12-11 03:23:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-05-19 23:04:34 +02:00
|
|
|
async saveEditeur(calendrierData) {
|
2023-01-05 00:55:04 +01:00
|
|
|
const newTimestamp = RdDTimestamp.timestamp(
|
|
|
|
Number.parseInt(calendrierData.annee),
|
2023-01-07 20:06:04 +01:00
|
|
|
calendrierData.mois.heure,
|
2023-01-05 00:55:04 +01:00
|
|
|
Number.parseInt(calendrierData.jourMois),
|
2023-01-07 20:06:04 +01:00
|
|
|
calendrierData.heure.heure,
|
|
|
|
Number.parseInt(calendrierData.minutes)
|
2023-01-05 00:55:04 +01:00
|
|
|
);
|
|
|
|
await this.setNewTimestamp(newTimestamp);
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-03-14 16:02:31 +01:00
|
|
|
async showCalendarEditor() {
|
2023-03-29 22:53:40 +02:00
|
|
|
const calendrierData = this.fillCalendrierData();
|
2021-03-14 16:02:31 +01:00
|
|
|
if (this.editeur == undefined) {
|
2023-03-29 22:53:40 +02:00
|
|
|
const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/time/calendar-editor.hbs', calendrierData);
|
|
|
|
this.editeur = new RdDCalendrierEditor(html, this, calendrierData)
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
2021-03-14 16:02:31 +01:00
|
|
|
this.editeur.updateData(calendrierData);
|
2020-12-08 21:40:41 +01:00
|
|
|
this.editeur.render(true);
|
|
|
|
}
|
|
|
|
|
2020-12-10 20:14:35 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async showAstrologieEditor() {
|
2023-03-08 02:02:40 +01:00
|
|
|
await AppAstrologie.create();
|
2020-12-10 20:14:35 +01:00
|
|
|
}
|
2023-03-29 22:53:40 +02:00
|
|
|
}
|