diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 97519218..c4bccc6c 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -94,7 +94,8 @@ export class RdDActorSheet extends ActorSheet { data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste ); data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste ); data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste ); - + console.log( data.data.compteurs ); + // low is normal, this the base used to compute the grid. data.data.fatigueHTML = "" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "
"; data.data.materiel = this._checkNull(data.itemsByType['objet']); @@ -234,6 +235,17 @@ export class RdDActorSheet extends ActorSheet { let compName = event.currentTarget.attributes.compname.value; this.actor.updateCompetenceXP( compName, parseInt(event.target.value) ); } ); + + // On stress change + html.find('.compteur-edit').change((event) => { + let fieldName = event.currentTarget.attributes.name.value; + this.actor.updateCompteurValue( fieldName, parseInt(event.target.value) ); + } ); + + html.find('#stress-test').click((event) => { + this.actor.stressTest(); + this.render(true); + }); html.find('#vie-plus').click((event) => { this.actor.santeIncDec("vie", 1); diff --git a/module/actor.js b/module/actor.js index 41a95f66..24fdbcd5 100644 --- a/module/actor.js +++ b/module/actor.js @@ -333,6 +333,16 @@ export class RdDActor extends Actor { } } + /* -------------------------------------------- */ + async updateCompteurValue( fieldName, fieldValue ) + { + //console.log("Update", fieldName, fieldValue); + let content; + let compteurs = duplicate(this.data.data.compteurs); + compteurs[fieldName].value = fieldValue; + await this.update( {"data.compteurs": compteurs } ); + } + /* -------------------------------------------- */ computeEtatGeneral( ) { @@ -426,6 +436,7 @@ export class RdDActor extends Actor { } return nbB; } + /* -------------------------------------------- */ async santeIncDec(name, inc ) { const sante = duplicate(this.data.data.sante); @@ -467,6 +478,7 @@ export class RdDActor extends Actor { await this.update( {"data.sante": sante } ); } + /* -------------------------------------------- */ async manageBlessureFromSheet( bType, index, active ) { let bList = duplicate(this.data.data.blessures); @@ -545,6 +557,59 @@ export class RdDActor extends Actor { } } + /* -------------------------------------------- */ + async stressTest( ) { + let compteurs = duplicate(this.data.data.compteurs); + let stress = compteurs.stress; + let xp = compteurs.experience; + + let scoreTarget = RdDUtility.getResolutionField( this.data.data.carac.reve.value, 0 ); + scoreTarget.sig = Math.floor(scoreTarget.score / 2); + + let scoreValue = new Roll("d100").roll().total; + let newXP = xp.value; + let factor = 0; + let comment = "Echec Total (0%)" + + if (scoreValue <= scoreTarget.part ) { + scoreValue = new Roll("d100").roll().total; + if (scoreValue <= scoreTarget.sig) { + factor = 1.5; + comment = "Double Particulière (150%)" + } else { + factor = 1; + comment = "Particulière (100%)" + } + } else { + if ( scoreValue <= scoreTarget.sig ) { + factor = 0.75; + comment = "Significative (75%)" + } else { + if ( scoreValue <= scoreTarget.score ) { + factor = 0.5; + comment = "Normale (50%)" + } else if (scoreValue <= scoreTarget.epart) { + factor = 0.2; + comment = "Echec (20%)" + } else if (scoreValue <= scoreTarget.etotal) { + factor = 0.1; + comment = "Echec (10%)" + } + } + } + + let xpValue = Math.floor(stress.value * factor); + stress.value -= xpValue; + stress.value -= 1; + if (stress.value < 0 ) stress.value = 0; + + ChatMessage.create( { title: "Jet de Stress", content: "Vous avez transformé "+ xpValue + " points de Stress en Expérience avec une réussite " + comment , + whisper: ChatMessage.getWhisperRecipients(game.user.name) } ); + + xp.value += xpValue; + await this.update( { "data.compteurs": compteurs } ); + } + /* -------------------------------------------- */ async rollUnSort( coord ) { let draconicList = this.getDraconicList(); @@ -675,9 +740,7 @@ export class RdDActor extends Actor { for (const item of this.data.items) { if (item.type == "armure" && item.data.equipe) { let update = duplicate(item); - let myroll = new Roll(update.data.protection.toString()); - myroll.roll(); - protection += myroll.total; + protection += new Roll(update.data.protection.toString()).roll().total; update.data.deterioration += domArmePlusDom; domArmePlusDom = 0; // Reset it if ( update.data.deterioration >= 10) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index a55a7bd2..7866d57a 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -329,7 +329,7 @@ export class RdDUtility { /* -------------------------------------------- */ // Build the nice (?) html table used to manage fatigue. - // max should be the endurance max value + // max should Mbe the endurance max value static makeHTMLfatigueMatrix( value, max ) { max = (max < 16) ? 16 : max; @@ -442,8 +442,7 @@ export class RdDUtility { return -7; // This is the max ! } - /* -------------------------------------------- */ - + /* -------------------------------------------- */ static findCompetence(compList, compName) { for (const item of compList) { diff --git a/styles/simple.css b/styles/simple.css index baab96da..8d52ceb7 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -125,7 +125,6 @@ align-items: center; text-align: center; padding: 5px; - border: 1px solid #999; } .flex-group-left { @@ -375,6 +374,12 @@ button { margin-right: 4px; margin-left: 4px; } +.stress-style { + flex-grow: 0; + flex-basis: 64px; + margin-right: 4px; + margin-left: 4px; +} /* ======================================== */ .item-checkbox { diff --git a/system.json b/system.json index d4359e02..86a2eac9 100644 --- a/system.json +++ b/system.json @@ -2,10 +2,10 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "L'implémentation de Rêve de Dragon pour FoundryVTT", - "version": "0.8.5", + "version": "0.8.9", "minimumCoreVersion": "0.6.0", "compatibleCoreVersion": "0.6.2", - "templateVersion": 23, + "templateVersion": 28, "author": "LeRatierBretonnien", "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "styles": ["styles/simple.css"], diff --git a/template.json b/template.json index 70fdb594..129b2be8 100644 --- a/template.json +++ b/template.json @@ -253,36 +253,39 @@ "compteurs": { "sust": { "value": 0, - "label": "Sust." + "label": "Sust.", + "isInput": true }, "eau": { "value": 0, - "label": "Eau" + "label": "Eau", + "isInput": true }, "moral": { "value": 0, - "label": "Moral" + "label": "Moral", + "isInput": true }, "exaltation": { "value": 0, - "label": "Exaltation" + "label": "Exaltation", + "isInput": true }, "dissolution": { "value": 0, - "label": "Dissolution" + "label": "Dissolution", + "isInput": true }, "chance": { "value": 0, "max": 0, - "label": "Chance" + "label": "Chance", + "isInput": true }, "destinee": { "value": 0, - "label": "Destinée" - }, - "stress": { - "value": 0, - "label": "Stress" + "label": "Destinée", + "isInput": true }, "etat": { "value": 0, @@ -290,8 +293,20 @@ }, "ethylisme": { "value": 0, - "label": "Ethylisme" - } + "label": "Ethylisme", + "isInput": true + }, + "stress": { + "value": 0, + "label": "Stress", + "isStress": true, + "isInput": true + }, + "experience": { + "value": 0, + "label": "Experience", + "isInput": true + } }, "argent": { "deniers": { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 01d37531..73367b3f 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -280,11 +280,21 @@ {{#each data.compteurs as |compteur key|}}
  • {{compteur.label}} + {{#if compteur.isInput}} + + {{#if compteur.isStress}} + Faire un jet de Stress + {{else}} + + {{/if}} + + {{else}} {{compteur.value}} + {{/if}}
  • {{/each}} + - {{!-- blessures Tab --}}
    @@ -434,10 +444,11 @@ {{!-- Biography Tab --}}
    +
    {{editor content=data.biographie target="data.biographie" button=true owner=owner editable=editable}} +
    -