diff --git a/module/actor.js b/module/actor.js index 43b908cc..c13ff17e 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1414,6 +1414,7 @@ export class RdDActor extends Actor { dialog.render(true); } + /* -------------------------------------------- */ async _rollCaracResult(rollData) { let rolled = rollData.rolled; @@ -1515,9 +1516,9 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - astrologieNombresAstraux( ) { + async astrologieNombresAstraux( ) { // Afficher l'interface spéciale - const myDialog = RdDAstrologieJoueur.create( this, {} ); + const myDialog = await RdDAstrologieJoueur.create( this, {} ); myDialog.render(true); } diff --git a/module/rdd-astrologie-joueur.js b/module/rdd-astrologie-joueur.js index 23aa4c7f..20794777 100644 --- a/module/rdd-astrologie-joueur.js +++ b/module/rdd-astrologie-joueur.js @@ -1,4 +1,6 @@ import { Misc } from "./misc.js"; +import { RdDCalendrier } from "./rdd-calendrier.js"; +import { RdDUtility } from "./rdd-utility.js"; /** * Extend the base Dialog entity by defining a custom window to perform roll. @@ -9,12 +11,16 @@ export class RdDAstrologieJoueur extends Dialog { /* -------------------------------------------- */ static async create(actor, dialogConfig) { - let data = { nombres: actor.data.items.filter( (item) => item.type == 'nombreastral') + let data = { nombres: actor.data.items.filter( (item) => item.type == 'nombreastral') , + dates: game.system.rdd.calendrier.getJoursSuivants( 10 ), + ajustementsConditions: CONFIG.RDD.ajustementsConditions, + astrologie: RdDUtility.findCompetence( actor.data.items, 'Astrologie') } + console.log("DATA", data); const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', data); let options = { classes: ["rdddialog"], width: 600, height: 500, 'z-index': 99999 }; if (dialogConfig.options) { - mergeObject(options, dialogConfig.options, { overwrite: true }) + mergeObject(options, dialogConfig.options, { overwrite: true }); } return new RdDAstrologieJoueur(html, actor, data); } @@ -23,7 +29,7 @@ export class RdDAstrologieJoueur extends Dialog { constructor(html, actor, data ) { let myButtons = { - saveButton: { label: "Fermer", callback: html => this.fillData() } + saveButton: { label: "Fermer", callback: html => this.fillData() } }; // Get all n @@ -35,6 +41,24 @@ export class RdDAstrologieJoueur extends Dialog { this.actor = actor; this.dataNombreAstral = duplicate(data); } + + /* -------------------------------------------- */ + requestJetAstrologie( ) { + let data = { id: this.actor.data._id, + carac_vue: this.actor.data.data.carac['vue'].value, + astrologie: this.dataNombreAstral.astrologie, + conditions: $("#diffConditions").val(), + date: $("#joursAstrologie").val() + } + if ( game.user.isGM) { + game.system.rdd.calendrier.requestNombreAstral( data ); + } else { + game.socket.emit("system.foundryvtt-reve-de-dragon", { + msg: "msg_request_nombre_astral", + data: data + } ); + } + } /* -------------------------------------------- */ fillData() { diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index 161b365e..81894f2f 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -2,6 +2,8 @@ import { RdDCalendrierEditeur } from "./rdd-calendrier-editeur.js"; import { RdDAstrologieEditeur } from "./rdd-astrologie-editeur.js"; import { HtmlUtility } from "./html-utility.js"; +import { RdDResolutionTable } from "./rdd-resolution-table.js"; +import { RdDUtility } from "./rdd-utility.js"; /* -------------------------------------------- */ const dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/' @@ -83,7 +85,18 @@ export class RdDCalendrier extends Application { getCurrentDayIndex( ) { return (this.calendrier.moisRdD * 28) + this.calendrier.jour; } - + + /* -------------------------------------------- */ + getJoursSuivants( num) { + let jours = []; + let index = this.getCurrentDayIndex(); + for (let i=0; i nombreAstral.index == index ); return astralData.nombreAstral || "N/A"; - } + /* -------------------------------------------- */ + getNombreAstral( index ) { + let astralData = this.listeNombreAstral.find( (nombreAstral, i) => nombreAstral.index == index ); + return astralData.nombreAstral || "N/A"; + } + /* -------------------------------------------- */ rebuildListeNombreAstral() { // Auto-create if needed @@ -203,6 +221,43 @@ export class RdDCalendrier extends Application { return data; } + /* -------------------------------------------- */ + getLectureAstrologieDifficulte( dateIndex ) { + let indexNow = this.getCurrentDayIndex(); + let diffDay = dateIndex - indexNow; + return - Math.floor(diffDay / 2); + } + + /* -------------------------------------------- */ + async requestNombreAstral( request) { + if ( game.user.isGM) { // Only GM + console.log( request ); + let jourDiff = this.getLectureAstrologieDifficulte( request.date); + let niveau = Number(request.astrologie.data.niveau) + Number(request.conditions) + Number(jourDiff); + let rolled = await RdDResolutionTable.roll(request.carac_vue, niveau, undefined, false); + + let nbAstral = this.getNombreAstral( request.date ); + let nbAstralFaux = nbAstral; + request.isValid = true; + if ( !rolled .isSuccess ) { + request.isValid = false; + while ( nbAstralFaux == nbAstral ) { + nbAstralFaux = new Roll("1d12").roll().total; + } + nbAstral = nbAstralFaux; + } + request.nbAstral = nbAstral; + if ( game.user.isGM) { + RdDUtility.responseNombreAstral( request ); + } else { + game.socket.emit("system.foundryvtt-reve-de-dragon", { + msg: "msg_response_nombre_astral", + data: request + } ); + } + } + } + /* -------------------------------------------- */ getAjustementAstrologique(heureNaissance) { diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 66f3a8f6..6cc2989d 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -103,9 +103,9 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static async roll(caracValue, finalLevel, bonus = undefined ) { + static async roll(caracValue, finalLevel, bonus = undefined, showDice = true ) { let chances = this.computeChances(caracValue, finalLevel); - chances.showDice = true; + chances.showDice = showDice; this.updateChancesWithBonus( chances, bonus); let rolled = await this.rollChances(chances); rolled.caracValue = caracValue; diff --git a/module/rdd-roll.js b/module/rdd-roll.js index e1a90558..c6b518a4 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -214,7 +214,6 @@ export class RdDRoll extends Dialog { $("#addon-message").text(""); } - let diffCompetence = 0; if (rollData.competence) { diffCompetence = Misc.toInt(rollData.competence.data.niveau); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index f6da7629..e2ecab5a 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -718,6 +718,14 @@ export class RdDUtility { return defenseMsg; } + /* -------------------------------------------- */ + static async responseNombreAstral( data ) { + let actor = game.actors.get( data.id); + const item = {name: "Nombre Astral", type: "nombreastral", data: + { value: data.nbAstral, istrue: data.isvalid, jourindex: Number(data.date), jourlabel: game.system.rdd.calendrier.getDateFromIndex( Number(data.date) ) } }; + await actor.createEmbeddedEntity("OwnedItem", item); + } + /* -------------------------------------------- */ static performSocketMesssage( sockmsg ) { @@ -731,6 +739,10 @@ export class RdDUtility { return ChatUtility.handleGMChatMessage(sockmsg.data); case "msg_sync_time": return game.system.rdd.calendrier.syncPlayerTime( sockmsg.data ); + case "msg_request_nombre_astral": + return game.system.rdd.calendrier.requestNombreAstral( sockmsg.data ); + case "msg_response_nombre_astral": + return RdDUtility.responseNombreAstral( sockmsg.data ); } } diff --git a/styles/simple.css b/styles/simple.css index d50d7bf7..f3cdc4fd 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -571,6 +571,7 @@ ul, li { .arme-label, .generic-label, .competence-label, +.astrologie-label, .description-label { flex-grow: 2; } diff --git a/system.json b/system.json index db46e76b..4ca9b6fd 100644 --- a/system.json +++ b/system.json @@ -2,10 +2,10 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "1.1.4", + "version": "1.1.7", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.8", - "templateVersion": 61, + "templateVersion": 66, "author": "LeRatierBretonnien", "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "styles": ["styles/simple.css"], diff --git a/template.json b/template.json index 54e4abd4..10bbbddb 100644 --- a/template.json +++ b/template.json @@ -531,7 +531,7 @@ } }, "Item": { - "types": ["objet", "arme", "armure", "conteneur", "competence", "sort", "herbe", "ingredient", "livre", "potion", "munition", "rencontresTMR", "queue", "ombre", "souffle", "tete", "competencecreature", "tarot", "monnaie"], + "types": ["objet", "arme", "armure", "conteneur", "competence", "sort", "herbe", "ingredient", "livre", "potion", "munition", "rencontresTMR", "queue", "ombre", "souffle", "tete", "competencecreature", "tarot", "monnaie", "nombreastral"], "objet": { "description": "", "quantite": 1, @@ -690,7 +690,8 @@ "nombreastral": { "value": 0, "istrue": false, - "jourindex": 1 + "jourindex": 1, + "jourlabel": "" }, "monnaie": { "quantite": "", diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index b05b9f15..1125bf73 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -541,7 +541,7 @@
  • - Astrologie : Nombres Astraux + Astrologie : Nombres Astraux
  • diff --git a/templates/dialog-astrologie-joueur.html b/templates/dialog-astrologie-joueur.html index 274da88b..af13e6d4 100644 --- a/templates/dialog-astrologie-joueur.html +++ b/templates/dialog-astrologie-joueur.html @@ -4,20 +4,38 @@

    Astrologie

    - + + + + + + + {{!-- Sheet Body --}}
    - {{#each astrologieData as |nombreData key|}} - + {{#each nombres as |nombreData key|}} + {{/each}} - {{#each astrologieData as |nombreData key|}} - + {{#each nombres as |nombreData key|}} + {{/each}}
    {{nombreData.humanDate}}{{nombreData.data.jourlabel}}
    {{nombreData.nombreAstral}}{{nombreData.data.value}}