Gestion des singularites

This commit is contained in:
sladecraven 2022-10-21 09:38:43 +02:00
parent 7ae5ce8d45
commit a100da7cd9
7 changed files with 115 additions and 49 deletions

View File

@ -154,7 +154,7 @@ export class Imperium5ActorSheet extends ActorSheet {
this.render(true); this.render(true);
}); });
html.find('.item-link a').click((event) => { html.find('.item-link a').click((event) => {
const itemId = $(event.currentTarget).data("item-id"); const itemId = $(event.currentTarget).data("item-id")
const item = this.actor.getOwnedItem(itemId); const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true); item.sheet.render(true);
}); });

View File

@ -50,13 +50,33 @@ export class Imperium5Utility {
}) })
} }
/* -------------------------------------------- */
static registerSettings() {
game.settings.register("fvtt-imperium5", "use-entropie-reussite", {
name: "Utilisation du dé d'Entropie dans les réussites",
hint: "Si coché, ajoute 1 succès au joueur sur un 2, et 1 succés au MJ sur un 7.",
scope: "world",
config: true,
default: false,
type: Boolean
})
game.settings.register("fvtt-imperium5", "use-singularite", {
name: "Utilisation complémentaire des Singularités",
hint: "Si coché, les Singularités peuvent permettre de réduire de 1 la valeur d'un dé",
scope: "world",
config: true,
default: false,
type: Boolean
})
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static pushInitiativeOptions(html, options) { static pushInitiativeOptions(html, options) {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async ready() { static async ready() {
this.registerSettings()
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -90,14 +110,19 @@ export class Imperium5Utility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async chatListeners(html) { static async chatListeners(html) {
html.on("change", '.select-apply-paradigme', event => {
html.on("click", '.button-apply-paradigme', event => { let paraKey = event.currentTarget.value
let paraKey = $(event.currentTarget).data("para-key")
let rollData = this.getRollDataFromMessage(event) let rollData = this.getRollDataFromMessage(event)
rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget) rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget)
this.applyParadigme(rollData, paraKey) this.applyParadigme(rollData, paraKey)
}) })
html.on("click", '.apply-singularite', event => {
let resultIndex = $(event.currentTarget).data("result-index")
let rollData = this.getRollDataFromMessage(event)
rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget)
this.applySingularite(rollData, resultIndex)
})
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -292,10 +317,20 @@ export class Imperium5Utility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeReussites(rollData) { static computeReussites(rollData) {
let myRoll = rollData.roll let myRoll = rollData.roll
rollData.successPC = myRoll.terms[0].results.filter(res => res.result <= rollData.seuil).length // Calcul des réussites sur les 2 pools
rollData.successGM = myRoll.terms[4].results.filter(res => res.result <= rollData.seuil).length rollData.successPC = rollData.resultsPC.filter(res => res.result <= rollData.seuil).length
rollData.successGM = myRoll.terms[4].results.filter(res => res.result <= 2).length
// Calcul du présage
rollData.bonPresage = myRoll.terms[2].results[0].result == 1 rollData.bonPresage = myRoll.terms[2].results[0].result == 1
rollData.mauvaisPresage = myRoll.terms[2].results[0].result == 8 rollData.mauvaisPresage = myRoll.terms[2].results[0].result == 8
// gestion règle optionnelle de l'Entropie
if (rollData.useEntropieReussite && myRoll.terms[2].results[0].result == 2) {
rollData.successPC++
}
if (rollData.useEntropieReussite && myRoll.terms[2].results[0].result == 7) {
rollData.successGM++
}
// Calcul unité de narration
rollData.nbUnitesNarration = Math.max(rollData.successPC - 1, 0) rollData.nbUnitesNarration = Math.max(rollData.successPC - 1, 0)
} }
@ -326,7 +361,8 @@ export class Imperium5Utility {
rollData.diceFormula = diceFormula rollData.diceFormula = diceFormula
rollData.humanFormula = humanFormula rollData.humanFormula = humanFormula
} }
// local copy of results to allow changes
rollData.resultsPC = duplicate(myRoll.terms[0].results)
// Calcul réussites // Calcul réussites
this.computeReussites(rollData) this.computeReussites(rollData)
@ -334,20 +370,39 @@ export class Imperium5Utility {
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
}) })
msg.setFlag("world", "imperium5-roll-data", rollData) msg.setFlag("world", "imperium5-roll-data", rollData)
console.log("Final rollData", rollData)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async processParadigmeRoll(rollData) { static async applyParadigme(rollData, paraKey) {
let actor = game.actors.get(rollData.actorId)
let para = actor.system.paradigmes[paraKey]
rollData.seuil = para.value
rollData.usedParadigme = para.label
actor.setParadigmeUsed(paraKey)
this.computeReussites(rollData) this.computeReussites(rollData)
rollData.paradigmes = [] rollData.paradigmes = []
let msg = await this.createChatWithRollMode(rollData.alias, { let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData) content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
}) })
msg.setFlag("world", "imperium5-roll-data", rollData) msg.setFlag("world", "imperium5-roll-data", rollData)
this.removeChatMessageId(rollData.previousMessageId) this.removeChatMessageId(rollData.previousMessageId)
} }
/* -------------------------------------------- */
static async applySingularite(rollData, resultIndex) {
let res = rollData.resultsPC[resultIndex]
res.result = (res.result > 1) ? res.result-1 : res.result
this.computeReussites(rollData)
rollData.useSingularites = false
rollData.singulariteApplied = true
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)
}
/* ------------------------- ------------------- */ /* ------------------------- ------------------- */
static async updateRoll(rollData) { static async updateRoll(rollData) {
@ -474,22 +529,14 @@ export class Imperium5Utility {
useAide: false, useAide: false,
useKarma: false, useKarma: false,
usedCapacite: "none", usedCapacite: "none",
seuil: 2 seuil: 2,
useSingularites: game.settings.get("fvtt-imperium5", "use-singularite"),
useEntropieReussite: game.settings.get("fvtt-imperium5", "use-entropie-reussite")
} }
Imperium5Utility.updateWithTarget(rollData) Imperium5Utility.updateWithTarget(rollData)
return rollData return rollData
} }
/* -------------------------------------------- */
static applyParadigme(rollData, paraKey) {
let actor = game.actors.get(rollData.actorId)
let para = actor.system.paradigmes[paraKey]
rollData.seuil = para.value
rollData.usedParadigme = para.label
actor.setParadigmeUsed(paraKey)
this.processParadigmeRoll(rollData)
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static updateWithTarget(rollData) { static updateWithTarget(rollData) {

View File

@ -1165,7 +1165,7 @@ ul, li {
.common-button { .common-button {
box-shadow: inset 0px 1px 0px 0px #a6827e; box-shadow: inset 0px 1px 0px 0px #a6827e;
background: linear-gradient(to bottom, #B8A799F0 5%, #80624af0 100%); background: linear-gradient(to bottom, #B8A799F0 5%, #80624af0 100%);
background-color: #B8A799F0; /*#7d5d3b00;*/ background-color: #80624af0; /*#7d5d3b00;*/
border-radius: 4px; border-radius: 4px;
opacity: 60%; opacity: 60%;
border: 2px ridge #846109; border: 2px ridge #846109;
@ -1177,6 +1177,11 @@ ul, li {
position: relative; position: relative;
} }
.common-button option {
background: linear-gradient(to bottom, #B8A799F0 5%, #80624af0 100%);
background-color: #80624af0; /*#7d5d3b00;*/
}
.common-button:hover { .common-button:hover {
background: linear-gradient(to bottom, #97B5AEFF 5%, rgb(101, 167, 151) 100%); background: linear-gradient(to bottom, #97B5AEFF 5%, rgb(101, 167, 151) 100%);
background-color: #97B5AEFF; background-color: #97B5AEFF;

View File

@ -7,7 +7,7 @@
"flags": {} "flags": {}
} }
], ],
"version": "10.0.4", "version": "10.0.5",
"compatibility": { "compatibility": {
"minimum": "10", "minimum": "10",
"verified": "10", "verified": "10",
@ -67,5 +67,5 @@
"background": "images/ui/imperium5_welcome_page.webp", "background": "images/ui/imperium5_welcome_page.webp",
"url": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5", "url": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5",
"manifest": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/raw/branch/master/system.json", "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.4.zip" "download": "https://www.uberwald.me/gitea/uberwald/fvtt-imperium5/archive/fvtt-imperium5-v10.0.5.zip"
} }

View File

@ -15,8 +15,12 @@
<li>Réserve : {{humanFormula}}</li> <li>Réserve : {{humanFormula}}</li>
<li>Score : <li>Score :
( (
{{#each roll.terms.0.results as |r k|}} {{#each resultsPC as |r k|}}
{{#if @root.useSingularites}}
<a class="apply-singularite common-button" data-result-index="{{k}}">{{r.result}}</a>
{{else}}
{{r.result}} {{r.result}}
{{/if}}
{{/each}} {{/each}}
) )
( (
@ -30,13 +34,34 @@
{{/each}} {{/each}}
) )
</li> </li>
{{#if singulariteApplied}}
<li>Une Singularité a réduit de 1 le résultat du dé</li>
{{/if}}
{{#if usedParadigme}} {{#if usedParadigme}}
<li>Paradigme utilisé : {{usedParadigme}}</li> <li>Paradigme utilisé : {{usedParadigme}}</li>
{{/if}} {{/if}}
<li>Seuil : {{seuil}}</li>
<li>Seuil : {{seuil}}
{{#if (count paradigmes)}}
<select class="common-button select-apply-paradigme" type="text" value="{{selectedParadigme}}" data-dtype="String">
{{#select selectedParadigme}}
<option value="none">Pas de paradigme</option>
{{#each paradigmes as |para key|}}
<option value="{{para.key}}">{{para.label}} ({{para.value}})</option>
{{/each}}
{{/select}}
</select>
{{/if}}
</li>
<li>Succés : {{successPC}}</li> <li>Succés : {{successPC}}</li>
<li>Succés de Réalité : {{successGM}}</li> <li>Succés de Réalité : {{successGM}}</li>
<li>Unités de narration : {{nbUnitesNarration}}</li> <li>Unités de narration : {{nbUnitesNarration}}</li>
{{#if nbKarma}} {{#if nbKarma}}
<li>Points de Karma utilisés : {{nbKarma}}</li> <li>Points de Karma utilisés : {{nbKarma}}</li>
{{/if}} {{/if}}
@ -48,14 +73,6 @@
<li>Mauvais Présage !</li> <li>Mauvais Présage !</li>
{{/if}} {{/if}}
{{#if (count paradigmes)}}
<li class="li-button-paradigme">
{{#each paradigmes as |para key|}}
<button class="common-button chat-card-button button-apply-paradigme" data-para-key="{{para.key}}">Utiliser {{para.label}} ({{para.value}})</button>
{{/each}}
</li>
{{/if}}
</ul> </ul>
</div> </div>

View File

@ -3,14 +3,11 @@
{{#if img}} {{#if img}}
<img class="actor-icon" src="{{img}}" data-edit="img" title="{{name}}" /> <img class="actor-icon" src="{{img}}" data-edit="img" title="{{name}}" />
{{/if}} {{/if}}
<h1 class="dialog-roll-title roll-dialog-header">{{title}}</h1> <h1 class="dialog-roll-title roll-dialog-header">{{ame.label}} ({{ame.value}})</h1>
</header> </header>
<div class="flexcol"> <div class="flexcol">
<div class="flexrow">
<span class="roll-dialog-label">Ame : {{ame.label}} ({{ame.value}})</span>
</div>
<div class="flexrow"> <div class="flexrow">
<span class="roll-dialog-label">Malus : {{ameMalus}}</span> <span class="roll-dialog-label">Malus : {{ameMalus}}</span>
</div> </div>