Commande météo
This commit is contained in:
parent
6873cf0d41
commit
5868bf16e0
@ -7,6 +7,7 @@ import { RdDItemCompetence } from "./item-competence.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDCarac } from "./rdd-carac.js";
|
||||
import { RdDDice } from "./rdd-dice.js";
|
||||
import { RdDMeteo } from "./rdd-meteo.js";
|
||||
import { RdDNameGen } from "./rdd-namegen.js";
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js";
|
||||
@ -34,6 +35,7 @@ export class RdDCommands {
|
||||
rddCommands.registerCommand({ path: ["/table", "souffle"], func: (content, msg, params) => RdDRollTables.getSouffle(true), descr: " Tire un Souffle de Dragon" });
|
||||
rddCommands.registerCommand({ path: ["/table", "comp"], func: (content, msg, params) => RdDRollTables.getCompetence(true), descr: "Tire une compétence au hasard" });
|
||||
rddCommands.registerCommand({ path: ["/table", "tarot"], func: (content, msg, params) => RdDRollTables.getTarot(true), descr: "Tire une carte du Tarot Draconique" });
|
||||
rddCommands.registerCommand({ path: ["/meteo"], func: (content, msg, params) => rddCommands.getMeteo(msg, params), descr: "Propose une météo marine" });
|
||||
rddCommands.registerCommand({ path: ["/nom"], func: (content, msg, params) => RdDNameGen.getName(msg, params), descr: "Génère un nom aléatoire" });
|
||||
|
||||
rddCommands.registerCommand({
|
||||
@ -398,5 +400,8 @@ export class RdDCommands {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
async getMeteo(msg, params) {
|
||||
return await RdDMeteo.getMeteo();
|
||||
}
|
||||
}
|
||||
|
||||
|
134
module/rdd-meteo.js
Normal file
134
module/rdd-meteo.js
Normal file
@ -0,0 +1,134 @@
|
||||
|
||||
const vents = [
|
||||
{ min: 0, max: 0, valeur: 'Calme' },
|
||||
{ min: 1, max: 1, valeur: 'Légère brise' },
|
||||
{ min: 2, max: 2, valeur: 'Jolie brise' },
|
||||
{ min: 3, max: 3, valeur: 'Bonne brise' },
|
||||
{ min: 4, max: 4, valeur: 'Vent frais' },
|
||||
{ min: 5, max: 5, valeur: 'Coup de vent' },
|
||||
{ min: 6, max: 6, valeur: 'Fort coup de vent' },
|
||||
{ min: 7, max: 9, valeur: 'Tempête' },
|
||||
{ min: 10, max: 13, valeur: 'Violente tempête' },
|
||||
{ min: 14, valeur: 'Ouragan' },
|
||||
]
|
||||
const mers = [
|
||||
{ min: 0, max: 0, valeur: 'Calme' },
|
||||
{ min: 1, max: 1, valeur: 'Belle' },
|
||||
{ min: 2, max: 2, valeur: 'Peu agitée' },
|
||||
{ min: 3, max: 3, valeur: 'Agitée' },
|
||||
{ min: 4, max: 4, valeur: 'Forte' },
|
||||
{ min: 5, max: 6, valeur: 'Très forte' },
|
||||
{ min: 7, max: 9, valeur: 'Grosse' },
|
||||
{ min: 10, max: 13, valeur: 'Très grosse' },
|
||||
{ min: 14, valeur: 'Énorme' },
|
||||
]
|
||||
|
||||
const nuages = [
|
||||
{ min: 0, max: 3, valeur: 'dégagé' },
|
||||
{ min: 4, max: 6, valeur: 'passages nuageux' },
|
||||
{ min: 7, max: 9, valeur: 'nuageux', },
|
||||
{ min: 10, max: 10, valeur: 'brouillard' },
|
||||
{ min: 11, max: 12, valeur: 'bruine' },
|
||||
{ min: 13, valeur: 'très nuageux' },
|
||||
]
|
||||
|
||||
const pluies = [
|
||||
{ min: 0, max: 4, valeur: 'aucune' },
|
||||
{ min: 5, max: 5, valeur: 'bruine, crachin, éparse' },
|
||||
{ min: 6, max: 7, valeur: 'averses' },
|
||||
{ min: 8, max: 10, valeur: 'pluvieux', },
|
||||
{ min: 11, max: 13, valeur: 'forte pluie' },
|
||||
{ min: 14, valeur: 'déluge' },
|
||||
]
|
||||
|
||||
const temperatures = [
|
||||
{ max: -14, valeur: 'glaciale' },
|
||||
{ min: -13, max: -10, valeur: 'Très froide' },
|
||||
{ min: -9, max: -7, valeur: 'froide' },
|
||||
{ min: -6, max: -4, valeur: 'fraîche' },
|
||||
{ min: -3, max: 3, valeur: 'de saison' },
|
||||
{ min: 4, max: 6, valeur: 'élevée' },
|
||||
{ min: 7, max: 9, valeur: 'chaude' },
|
||||
{ min: 10, max: 13, valeur: 'torride' },
|
||||
{ min: 14, valeur: 'caniculaire' },
|
||||
]
|
||||
|
||||
export class RdDMeteo {
|
||||
static async getForce() {
|
||||
const roll = new Roll(`1dr`);
|
||||
await roll.evaluate({ async: true });
|
||||
return roll.total;
|
||||
}
|
||||
|
||||
static async getPluie(nuage) {
|
||||
return nuage <= 3 ? 0 : await RdDMeteo.getForce();
|
||||
}
|
||||
|
||||
static async getTemperature() {
|
||||
const degre = await RdDMeteo.getForce();
|
||||
const rollChaudFroid = new Roll('1d2');
|
||||
await rollChaudFroid.evaluate({ async: true });
|
||||
const chaudFroid = rollChaudFroid.total == 1;
|
||||
return chaudFroid.total ? degre : -degre;
|
||||
}
|
||||
|
||||
static async getDirection(direction) {
|
||||
const roll = new Roll(`1d16`);
|
||||
await roll.evaluate({ async: true });
|
||||
switch (roll.total % 16) {
|
||||
case 0: return 'Nord';
|
||||
case 1: return 'Nord Nord Est';
|
||||
case 2: return 'Nord Est';
|
||||
case 3: return 'Est Nord Est';
|
||||
case 4: return 'Est';
|
||||
case 5: return 'Est Sud Est';
|
||||
case 6: return 'Sud Est';
|
||||
case 7: return 'Sud Sud Est';
|
||||
case 8: return 'Sud';
|
||||
case 9: return 'Sud Sud Ouest';
|
||||
case 10: return 'Sud Ouest';
|
||||
case 11: return 'Ouest Sud Ouest';
|
||||
case 12: return 'Ouest';
|
||||
case 13: return 'Ouest Nord Ouest';
|
||||
case 14: return 'Nord Ouest';
|
||||
case 15: return 'Nord Nord Ouest';
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
static async getMeteo() {
|
||||
const vent = await RdDMeteo.getForce();
|
||||
const mer = await RdDMeteo.getForce();
|
||||
const nuage = await RdDMeteo.getForce();
|
||||
const pluie = await RdDMeteo.getPluie(nuage);
|
||||
const temperature = await RdDMeteo.getTemperature();
|
||||
const meteo = {
|
||||
vent: { force: vent, direction: await RdDMeteo.getDirection(), },
|
||||
mer: { force: mer, direction: await RdDMeteo.getDirection(), },
|
||||
temperature: { force: temperature },
|
||||
nuage: { force: nuage, },
|
||||
pluie: { force: pluie },
|
||||
}
|
||||
meteo.vent.description = RdDMeteo.vent(meteo.vent.force);
|
||||
meteo.mer.description = RdDMeteo.mer(meteo.mer.force),
|
||||
meteo.temperature.description = RdDMeteo.temperature(meteo.temperature.force);
|
||||
meteo.nuage.description = RdDMeteo.nuage(meteo.nuage.force);
|
||||
meteo.pluie.description = RdDMeteo.pluie(meteo.pluie.force);
|
||||
|
||||
ChatMessage.create({
|
||||
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-resultat-meteo.html', meteo),
|
||||
whisper: ChatMessage.getWhisperRecipients('GM')
|
||||
});
|
||||
}
|
||||
|
||||
static description(liste, force, valeur = it => it.valeur) {
|
||||
let select = liste.find(it => (it.min == undefined || it.min <= force) && (it.max == undefined || force <= it.max));
|
||||
return valeur(select ?? liste[0]);
|
||||
}
|
||||
|
||||
static vent(force) { return this.description(vents, force); }
|
||||
static mer(force) { return this.description(mers, force); }
|
||||
static nuage(force) { return this.description(nuages, force); }
|
||||
static pluie(force) { return this.description(pluies, force); }
|
||||
static temperature(force) { return this.description(temperatures, force); }
|
||||
}
|
@ -221,8 +221,10 @@ export class RdDUtility {
|
||||
];
|
||||
|
||||
Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null'));
|
||||
Handlebars.registerHelper('lowerFirst', str => Misc.lowerFirst(str ?? 'Null'));
|
||||
Handlebars.registerHelper('upper', str => str?.toUpperCase() ?? 'NULL');
|
||||
Handlebars.registerHelper('le', str => Grammar.articleDetermine(str));
|
||||
Handlebars.registerHelper('apostrophe', (article, str) => Grammar.apostrophe(article, str));
|
||||
Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str));
|
||||
Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args));
|
||||
Handlebars.registerHelper('buildConteneur', (objet) => { return new Handlebars.SafeString(RdDUtility.buildConteneur(objet)); });
|
||||
|
9
templates/chat-resultat-meteo.html
Normal file
9
templates/chat-resultat-meteo.html
Normal file
@ -0,0 +1,9 @@
|
||||
<img class="chat-icon" src="icons/svg/lightning.svg" alt="Météo" />
|
||||
<h4>Météo aléatoire</h4>
|
||||
<ul>
|
||||
<li>Vent: {{lowerFirst vent.description}} {{apostrophe 'de' vent.direction}}, force {{vent.force}}</li>
|
||||
<li>Mer {{lowerFirst mer.description}}, {{apostrophe 'de' mer.direction}}, force {{mer.force}}</li>
|
||||
<li>Température {{lowerFirst temperature.description}} ({{numberFormat temperature.force decimals=0 sign=true}})</li>
|
||||
<li>Couverture nuageuse: {{lowerFirst nuage.description}}</li>
|
||||
<li>Pluie: {{lowerFirst pluie.description}}</li>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user