diff --git a/modules/imperium5-actor.js b/modules/imperium5-actor.js index 87233a3..70c8369 100644 --- a/modules/imperium5-actor.js +++ b/modules/imperium5-actor.js @@ -124,10 +124,21 @@ export class Imperium5Actor extends Actor { } /* -------------------------------------------- */ - incDecKarma( value ) { + transferToSource( nbSuccess) { let karma = duplicate(this.system.karma) - karma.value += value + karma.source += Number(nbSuccess) + let nbKarma = Math.floor(karma.source / 3) + karma.value += nbKarma + karma.source -= nbKarma*3 + this.update( { 'system.karma': karma}) + } + + /* -------------------------------------------- */ + decOneKarma( ) { + let karma = duplicate(this.system.karma) + karma.value-- karma.value = Math.max(karma.value, 0) + karma.xp++ this.update( { 'system.karma': karma}) } diff --git a/modules/imperium5-utility.js b/modules/imperium5-utility.js index 014404e..669cac8 100644 --- a/modules/imperium5-utility.js +++ b/modules/imperium5-utility.js @@ -48,6 +48,18 @@ export class Imperium5Utility { Handlebars.registerHelper('exists', function (val) { return val != null && val != undefined; }) + Handlebars.registerHelper('for', function (from, to, incr, block) { + var accum = ''; + for (var i = from; i < to; i += incr) + accum += block.fn(i); + return accum; + }) + Handlebars.registerHelper('times', function(n, block) { + var accum = ''; + for(var i = 1; i <= n; ++i) + accum += block.fn(i); + return accum; + }) } /* -------------------------------------------- */ @@ -123,6 +135,14 @@ export class Imperium5Utility { rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget) this.applySingularite(rollData, resultIndex) }) + + html.on("change", '.transfer-success', event => { + let nbSuccess = event.currentTarget.value + let rollData = this.getRollDataFromMessage(event) + rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget) + this.applySuccessTransfer(rollData, nbSuccess) + }) + } /* -------------------------------------------- */ @@ -341,11 +361,11 @@ export class Imperium5Utility { let actor = game.actors.get(rollData.actorId) rollData.nbKarma = 0 if (rollData.useKarma) { - actor.incDecKarma(-1) + actor.decOneKarma() rollData.nbKarma++ } if (rollData.usedCapacite != "none") { - actor.incDecKarma(-1) + actor.decOneKarma() rollData.nbKarma++ } @@ -365,6 +385,7 @@ export class Imperium5Utility { rollData.resultsPC = duplicate(myRoll.terms[0].results) // Calcul réussites this.computeReussites(rollData) + rollData.realSuccessPC = rollData.successPC // To manage source transfer let msg = await this.createChatWithRollMode(rollData.alias, { content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) @@ -401,6 +422,21 @@ export class Imperium5Utility { content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) }) msg.setFlag("world", "imperium5-roll-data", rollData) + this.removeChatMessageId(rollData.previousMessageId) + } + + /* ------------------------- ------------------- */ + static async applySuccessTransfer(rollData, nbSuccess) { + let actor = game.actors.get(rollData.actorId) + actor.transferToSource( nbSuccess) + rollData.realSuccessPC -= nbSuccess + rollData.sourceTransfer = nbSuccess + rollData.nbUnitesNarration = Math.max(rollData.realSuccessPC - 1, 0) + let msg = await this.createChatWithRollMode(rollData.alias, { + content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) + }) + msg.setFlag("world", "imperium5-roll-data", rollData) + this.removeChatMessageId(rollData.previousMessageId) } /* ------------------------- ------------------- */ @@ -530,6 +566,7 @@ export class Imperium5Utility { useKarma: false, usedCapacite: "none", seuil: 2, + nbSuccessSource: 0, useSingularites: game.settings.get("fvtt-imperium5", "use-singularite"), useEntropieReussite: game.settings.get("fvtt-imperium5", "use-entropie-reussite") } diff --git a/system.json b/system.json index 2b70688..abd786d 100644 --- a/system.json +++ b/system.json @@ -7,7 +7,7 @@ "flags": {} } ], - "version": "10.0.5", + "version": "10.0.6", "compatibility": { "minimum": "10", "verified": "10", @@ -67,5 +67,5 @@ "background": "images/ui/imperium5_welcome_page.webp", "url": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5", "manifest": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/raw/branch/master/system.json", - "download": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/archive/fvtt-imperium5-v10.0.5.zip" + "download": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/archive/fvtt-imperium5-v10.0.6.zip" } \ No newline at end of file diff --git a/templates/chat-generic-result.html b/templates/chat-generic-result.html index b87a6f1..fb5388b 100644 --- a/templates/chat-generic-result.html +++ b/templates/chat-generic-result.html @@ -46,18 +46,33 @@
  • Seuil : {{seuil}} {{#if (count paradigmes)}} {{/if}}
  • -
  • Succés : {{successPC}}
  • +
  • Succés : {{realSuccessPC}} + {{#if realSuccessPC}} + + {{/if}} +
  • + {{#if sourceTransfer}} +
  • Succés transférés à la Source : {{sourceTransfer}}
  • + {{/if}} +
  • Succés de Réalité : {{successGM}}
  • Unités de narration : {{nbUnitesNarration}}