diff --git a/module/actor.js b/module/actor.js index c13ff17e..90b15898 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1514,12 +1514,28 @@ export class RdDActor extends Actor { // selon l'heure de naissance... return game.system.rdd.calendrier.getAjustementAstrologique(this.data.data.heure); } + + /* -------------------------------------------- */ + async ajouteNombreAstral( data ) { + // Ajout du nombre astral + 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 this.createEmbeddedEntity("OwnedItem", item); + + // Suppression des anciens nombres astraux + let toDelete = this.data.items.filter( (item) => item.data.jourindex < game.system.rdd.calendrier.getCurrentDayIndex() ); + const deletions = toDelete.map(i => i._id); + await this.deleteEmbeddedEntity("OwnedItem", deletions); + + // Affichage Dialog + this.astrologieNombresAstraux(); + } /* -------------------------------------------- */ async astrologieNombresAstraux( ) { // Afficher l'interface spéciale - const myDialog = await RdDAstrologieJoueur.create( this, {} ); - myDialog.render(true); + const astrologieDialog = await RdDAstrologieJoueur.create( this, {} ); + astrologieDialog.render(true); } /* -------------------------------------------- */ diff --git a/module/rdd-astrologie-joueur.js b/module/rdd-astrologie-joueur.js index e1c41f6d..3f9205e2 100644 --- a/module/rdd-astrologie-joueur.js +++ b/module/rdd-astrologie-joueur.js @@ -11,12 +11,12 @@ export class RdDAstrologieJoueur extends Dialog { /* -------------------------------------------- */ static async create(actor, dialogConfig) { - let data = { nombres: actor.data.items.filter( (item) => item.type == 'nombreastral') , + let data = { nombres: this.organizeNombres( actor), dates: game.system.rdd.calendrier.getJoursSuivants( 10 ), + etat: actor.data.data.compteurs.etat.value, 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) { @@ -42,10 +42,28 @@ export class RdDAstrologieJoueur extends Dialog { this.dataNombreAstral = duplicate(data); } + /* -------------------------------------------- */ + static organizeNombres(actor) { + let itemNombres = actor.data.items.filter( (item) => item.type == 'nombreastral'); + let itemFiltered = {}; + for ( let item of itemNombres) { + if ( itemFiltered[item.data.jourindex] ) { + itemFiltered[item.data.jourindex].listValues.push(item.data.value); + } else { + itemFiltered[item.data.jourindex] = { + listValues: [ item.data.value ], + jourlabel: item.data.jourlabel + } + } + } + return itemFiltered; + } + /* -------------------------------------------- */ requestJetAstrologie( ) { let data = { id: this.actor.data._id, carac_vue: this.actor.data.data.carac['vue'].value, + etat: this.dataNombreAstral.etat, astrologie: this.dataNombreAstral.astrologie, conditions: $("#diffConditions").val(), date: $("#joursAstrologie").val() @@ -58,6 +76,7 @@ export class RdDAstrologieJoueur extends Dialog { data: data } ); } + this.close(); } /* -------------------------------------------- */ @@ -69,6 +88,10 @@ export class RdDAstrologieJoueur extends Dialog { activateListeners(html) { super.activateListeners(html); + $(function () { + $("#diffConditions").val(0); + }); + html.find('#jet-astrologie').click((event) => { this.requestJetAstrologie(); }); diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index c7e7a45d..a8e66c93 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -233,7 +233,7 @@ export class RdDCalendrier extends Application { 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 niveau = Number(request.astrologie.data.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat); let rolled = await RdDResolutionTable.roll(request.carac_vue, niveau, undefined, false); let nbAstral = this.getNombreAstral( request.date ); @@ -356,6 +356,11 @@ export class RdDCalendrier extends Application { let astrologieArray = []; for (let astralData of this.listeNombreAstral ) { astralData.humanDate = this.getDateFromIndex( astralData.index ); + for (let vf of astralData.valeursFausses) { + let actor = game.actors.get( vf.actorId); + console.log(vf.actorId, actor ); + vf.actorName = (actor) ? actor.name : "Inconnu"; + } astrologieArray.push( duplicate(astralData ) ); } //console.log("ASTRO", astrologieArray); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index e2ecab5a..d702a77a 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -719,11 +719,9 @@ export class RdDUtility { } /* -------------------------------------------- */ - static async responseNombreAstral( data ) { + 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); + actor.ajouteNombreAstral(data); } /* -------------------------------------------- */ diff --git a/styles/simple.css b/styles/simple.css index f3cdc4fd..d8a58b7e 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -635,6 +635,17 @@ ul, li { margin-left: 4px; } +/* ======================================== */ +.table-nombres-astraux { + border:1; + font-size: 0.75rem; +} +.table-nombres-astraux td { + border: 1px solid black; + text-align: center; + vertical-align: top; +} + /* ======================================== */ .tokenhudext { display: flex; diff --git a/templates/calendar-astrologie-template.html b/templates/calendar-astrologie-template.html index 65fdccda..250cd644 100644 --- a/templates/calendar-astrologie-template.html +++ b/templates/calendar-astrologie-template.html @@ -8,20 +8,21 @@ {{!-- Sheet Body --}}
- - - +
+ {{#each astrologieData as |nombreData key|}} - + {{/each}} - + {{#each astrologieData as |nombreData key|}} - {{/each}} diff --git a/templates/dialog-astrologie-joueur.html b/templates/dialog-astrologie-joueur.html index af13e6d4..67eb084b 100644 --- a/templates/dialog-astrologie-joueur.html +++ b/templates/dialog-astrologie-joueur.html @@ -21,21 +21,28 @@ {{/each}} {{/select}} + {{!-- Sheet Body --}}
-
{{nombreData.humanDate}}{{nombreData.humanDate}}
- {{nombreData.nombreAstral}} + +
    + {{nombreData.nombreAstral}} {{#each nombreData.valeursFausses as |fausseVal key|}} -
  1. {{fausseVal.actorId}} - {{fausseVal.nombreAstral}}
  2. +
  3. {{fausseVal.actorName}} - {{fausseVal.nombreAstral}}
  4. {{/each}} +
- +
+ {{#each nombres as |nombreData key|}} - + {{/each}} - + {{#each nombres as |nombreData key|}} - + {{/each}}
{{nombreData.data.jourlabel}}{{nombreData.jourlabel}}
{{nombreData.data.value}} +
    + {{#each nombreData.listValues as |nombreAstral key|}} +
  1. {{nombreAstral}}
  2. + {{/each}} +
+