Mod applies to roll not total

Changes:
 + modifier wird auf den wurf gerechnet und nicht auf das gesamt ergebniss (Wichtig für d100 würfe
 + Zeig modifier hinter dem wurf label an
This commit is contained in:
Byroks 2024-03-28 17:05:28 +01:00
parent 05bed77ce5
commit 4ce31a97df
5 changed files with 10 additions and 9 deletions

View File

@ -416,7 +416,7 @@
"chat": { "chat": {
"luckPoint": "Glückspunkt", "luckPoint": "Glückspunkt",
"destiny": "Schicksalsgunst", "destiny": "Schicksalsgunst",
"modify": "Nachträglich +2", "modify": "Nachträglich",
"cancel": "Abbrechen", "cancel": "Abbrechen",
"roll": "Würfeln", "roll": "Würfeln",
"reroll": "Neuwürfeln", "reroll": "Neuwürfeln",

View File

@ -181,7 +181,7 @@ Hooks.on("getChatLogEntryContext", function (html, options) {
const message = (game as Game).messages.get(li.attr("data-message-id")); const message = (game as Game).messages.get(li.attr("data-message-id"));
// All must be true to show the reroll dialogue // All must be true to show the reroll dialogue
return game["user"].character.id === (game as Game).actors.get(message["speaker"].actor).id && !message["flags"].rerolled; return (game["user"].isGM || game["user"].character?.id === (game as Game).actors.get(message["speaker"].actor)?.id) && !message["flags"].rerolled;
}, },
callback: (li) => reroll(li), callback: (li) => reroll(li),
} }

View File

@ -26,11 +26,11 @@ export class M5Roll {
.map((rollName, index) => { .map((rollName, index) => {
indexMap.set(index, rollName); indexMap.set(index, rollName);
const formula = this.data.rolls[rollName]; const formula = this.data.rolls[rollName];
formula.formula = index === 0 ? formula.formula + " + " + this.data.b.modifier : formula.formula; formula.formula = index === 0 ? formula.formula.replace(/(\d*d\d*)/, `{$1 + ${this.data.b.modifier}}`) : formula.formula;
const roll = new Roll(formula.formula, this.data); const roll = new Roll(formula.formula, this.data);
return roll; return roll;
}); });
console.log(rolls);
this.pool = PoolTerm.fromRolls(rolls); this.pool = PoolTerm.fromRolls(rolls);
console.log("evaluate", this._evaluated, this.pool); console.log("evaluate", this._evaluated, this.pool);
return this.pool.evaluate({ async: true }).then((results) => { return this.pool.evaluate({ async: true }).then((results) => {
@ -110,14 +110,13 @@ export class M5Roll {
if (!this._evaluated) await this.evaluate(); if (!this._evaluated) await this.evaluate();
const rMode = checkOptions["rollMode"] || (game as Game).settings.get("core", "rollMode"); const rMode = checkOptions["rollMode"] || (game as Game).settings.get("core", "rollMode");
const chatData = { const chatData = {
type: CONST.CHAT_MESSAGE_TYPES.ROLL, type: CONST.CHAT_MESSAGE_TYPES.ROLL,
content: await this.render(), content: await this.render(),
speaker: ChatMessage.getSpeaker({ actor: this.actor }), speaker: ChatMessage.getSpeaker({ actor: this.actor }),
sound: CONFIG.sounds.dice, sound: CONFIG.sounds.dice,
roll: Roll.fromTerms([this.pool]), roll: Roll.fromTerms([this.pool]),
flags: { data: this.data }, flags: { data: this.data, rerolled: false, faces: this.pool.dice.map((x) => x.faces) },
}; };
let foo = ChatMessage.applyRollMode(chatData, rMode); let foo = ChatMessage.applyRollMode(chatData, rMode);

View File

@ -4,9 +4,11 @@ import { M5Roll } from "./M5Roll";
export const reroll = async (roll) => { export const reroll = async (roll) => {
const message = (game as Game).messages.get(roll.attr("data-message-id")); const message = (game as Game).messages.get(roll.attr("data-message-id"));
const actor = (game as Game).actors.get(message["speaker"].actor); const actor = (game as Game).actors.get(message["speaker"].actor);
// const die
const template = "systems/midgard5/templates/chat/reroll-dialog.hbs"; const template = "systems/midgard5/templates/chat/reroll-dialog.hbs";
const html = await renderTemplate(template, { sg: actor.system.sg, gp: actor.system.gp }); const html = await renderTemplate(template, { sg: actor.system.sg, gp: actor.system.gp });
console.log(message["flags"].faces[0]);
// Button defining // Button defining
let buttons = {}; let buttons = {};
buttons = { buttons = {
@ -22,7 +24,7 @@ export const reroll = async (roll) => {
}, },
modify: { modify: {
icon: '<i class="fas fa-plus"></i>', icon: '<i class="fas fa-plus"></i>',
label: (game as Game).i18n.localize("midgard5.chat.modify"), label: (game as Game).i18n.localize("midgard5.chat.modify") + " +" + (message["flags"].faces[0] === 100 ? 10 : 2),
callback: () => rerollDie("modify", "gp"), callback: () => rerollDie("modify", "gp"),
}, },
cancel: { cancel: {
@ -77,7 +79,7 @@ export const reroll = async (roll) => {
for (var key in flagData.rolls) { for (var key in flagData.rolls) {
if (!!flagData.rolls[key]) { if (!!flagData.rolls[key]) {
rollData.rolls[key] = { rollData.rolls[key] = {
formula: key === "0" ? flagData.rolls[key]?.result + " + 2" : flagData.rolls[key]?.result, formula: key === "0" ? flagData.rolls[key]?.result + " + " + (message["flags"].faces[0] === 100 ? 10 : 2) : flagData.rolls[key]?.result,
enabled: flagData.rolls[key]?.enabled, enabled: flagData.rolls[key]?.enabled,
label: flagData.rolls[key]?.label, label: flagData.rolls[key]?.label,
result: "", result: "",

View File

@ -125,7 +125,7 @@
{{#each rolls as |roll index|}} {{#each rolls as |roll index|}}
{{#if roll.enabled}} {{#if roll.enabled}}
<tr class="roll-row {{roll.css}}"> <tr class="roll-row {{roll.css}}">
<td>{{roll.label}}</td> <td>{{roll.label}} {{#if (eq index '0')}} {{#if (gt ../b.modifier 0)}}+{{../b.modifier}}{{/if}}{{#if (gt 0 ../b.modifier)}}{{../b.modifier}}{{/if}}{{/if}}</td>
<td class="roll-result"> <td class="roll-result">
<span class="roll-total {{#if (contains roll.label "Schaden")}}apply damage{{/if}}{{#if (contains roll.label "Heilung")}}apply heal{{/if}}">{{roll.totalStr}}</span> <span class="roll-total {{#if (contains roll.label "Schaden")}}apply damage{{/if}}{{#if (contains roll.label "Heilung")}}apply heal{{/if}}">{{roll.totalStr}}</span>
<span class="roll-detail">{{roll.result}}</span> <span class="roll-detail">{{roll.result}}</span>