Situationsbedingte-Boni/Mali-#41 (#95)

Changes:
 + Popup für Situationsbedinge Boni/Mali, Schwellenwert und RollMode (Sichtbarkeit)
 + neuwürfel/verändern des wurfes durch glückspunkte und schicksalsgunst
Co-authored-by: Ender <harald@drueppels.de>
Reviewed-on: #95
This commit was merged in pull request #95.
This commit is contained in:
2024-03-29 14:28:49 +01:00
parent a4cf10c5f1
commit 2a1262662f
9 changed files with 620 additions and 394 deletions
+54 -7
View File
@@ -26,10 +26,10 @@ export class M5Roll {
.map((rollName, index) => {
indexMap.set(index, rollName);
const formula = this.data.rolls[rollName];
formula.formula = index === 0 && this.id !== "-1" ? formula.formula.replace(/(\d*d\d*)/, `{$1 + ${this.data.b.modifier}}`) : formula.formula;
const roll = new Roll(formula.formula, this.data);
return roll;
});
this.pool = PoolTerm.fromRolls(rolls);
console.log("evaluate", this._evaluated, this.pool);
return this.pool.evaluate({ async: true }).then((results) => {
@@ -66,7 +66,7 @@ export class M5Roll {
const parseResult = M5Roll.parseDiceSides(rollResult.formula);
//console.log("evaluate roll", parseResult)
if (parseResult?.sides === 20) {
if (roll.total < 20) {
if (roll.total < this.data.b.difficulty) {
if (rowRes === M5EwResult.TBD || rowRes === M5EwResult.HIGH) rowRes = M5EwResult.FAIL;
} else {
if (rowRes === M5EwResult.TBD) rowRes = M5EwResult.PASS;
@@ -88,7 +88,6 @@ export class M5Roll {
});
this.data.res.label = this.label;
console.log(this.data);
if ((game as Game).settings.get("midgard5", "automatedPP") && this.data.iType !== null) {
if ((this.data.i.type === "language" || this.data.i.type === "general") && this.data.rolls[0].dice[0] >= 16) {
this.actor.items.get(this.id).update({
@@ -144,20 +143,28 @@ export class M5Roll {
}
async toMessage() {
let checkOptions = await this.popUp({ isPW: this.data.rolls[0].label === (game as Game).i18n.localize("midgard5.pw") });
if (checkOptions["cancelled"]) {
return;
} else {
this.data.b = checkOptions;
}
if (!this._evaluated) await this.evaluate();
const faces = this.pool.dice.map((x) => x.faces);
const rMode = (game as Game).settings.get("core", "rollMode");
const rMode = checkOptions["rollMode"] || (game as Game).settings.get("core", "rollMode");
const chatData = {
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
content: await this.render(),
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
sound: CONFIG.sounds.dice,
roll: Roll.fromTerms([this.pool]),
flags: { data: this.data, rerolled: false, faces: faces },
};
ChatMessage.applyRollMode(chatData, rMode);
return ChatMessage.create(chatData);
let foo = ChatMessage.applyRollMode(chatData, rMode);
return ChatMessage.implementation["create"](foo, { rollMode: rMode });
}
static fromAttributeValue(actor: any, attributeKey: string, attributeValue: number) {
@@ -392,6 +399,46 @@ export class M5Roll {
return null;
}
async popUp({
useFortune = false,
difficulty = 20,
modifier = 0,
rollModes = CONFIG.Dice.rollModes,
rollMode = "",
template = "systems/midgard5/templates/chat/task-check-dialog.hbs",
isPW = false,
} = {}) {
const html = await renderTemplate(template, { useFortune, difficulty, modifier, rollModes, rollMode, isPW });
return new Promise((resolve) => {
const data = {
title: (game as Game).i18n.localize("midgard5.chat.roll"),
content: html,
buttons: {
roll: {
label: (game as Game).i18n.localize("midgard5.chat.roll"),
callback: (html) => resolve(this._processTaskCheckOptions(html[0].querySelector("form"))),
},
cancel: {
label: (game as Game).i18n.localize("midgard5.chat.cancel"),
callback: (html) => resolve({ cancelled: true }),
},
},
default: "roll",
close: () => resolve({ cancelled: true }),
};
new Dialog(data, null).render(true);
});
}
_processTaskCheckOptions(form) {
return {
difficulty: parseInt(form.difficulty?.value),
modifier: parseInt(form.modifier?.value),
rollMode: form.rollMode?.value,
};
}
}
interface FormulaParseResult {
+108
View File
@@ -0,0 +1,108 @@
import { M5RollData, M5RollResult } from "../M5Base";
import { M5Roll } from "./M5Roll";
export const reroll = async (roll) => {
const message = (game as Game).messages.get(roll.attr("data-message-id"));
const actor = (game as Game).actors.get(message["speaker"].actor);
const template = "systems/midgard5/templates/chat/reroll-dialog.hbs";
const html = await renderTemplate(template, { sg: actor.system.sg, gp: actor.system.gp });
// Button defining
let buttons = {};
buttons = {
destiny: {
icon: '<i class="fas fa-rotate-left"></i>',
label: (game as Game).i18n.localize("midgard5.chat.destiny"),
callback: () => rerollDie("destiny", "sg"),
},
luckPoints: {
icon: '<i class="fas fa-rotate-left"></i>',
label: (game as Game).i18n.localize("midgard5.chat.luckPoint"),
callback: () => rerollDie("luckPoint", "gp"),
},
modify: {
icon: '<i class="fas fa-plus"></i>',
label: (game as Game).i18n.localize("midgard5.chat.modify") + " +" + (message["flags"].faces[0] === 100 ? 10 : 2),
callback: () => rerollDie("modify", "gp"),
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: (game as Game).i18n.localize("midgard5.chat.cancel"),
},
};
// Dialog object
new Dialog(
{
title: (game as Game).i18n.localize("midgard5.chat.reroll"),
content: html,
buttons,
render: function () {},
default: "luckPoints",
},
{
classes: ["midgard5"],
}
).render(true);
async function rerollDie(type, target) {
// Update the "content" field
let rollData = actor.getRollData() as M5RollData;
const flagData = message["flags"].data;
rollData.c = flagData.c;
rollData.i = flagData.i;
rollData.b = flagData.b;
rollData.iType = flagData.iType;
rollData.res.label = flagData.res.label + " (" + (game as Game).i18n.localize(`midgard5.chat.${type}`) + ")";
actor.update({
system: {
[target]: actor.system[target] - 1,
},
});
if (type !== "modify") {
for (var key in flagData.rolls) {
if (!!flagData.rolls[key]) {
rollData.rolls[key] = {
formula: flagData.rolls[key]?.formula,
enabled: flagData.rolls[key]?.enabled,
label: flagData.rolls[key]?.label,
result: "",
total: 0,
totalStr: "",
dice: {},
css: "",
} as M5RollResult;
}
}
} else {
for (var key in flagData.rolls) {
if (!!flagData.rolls[key]) {
rollData.rolls[key] = {
formula: key === "0" ? flagData.rolls[key]?.result + " + " + (message["flags"].faces[0] === 100 ? 10 : 2) : flagData.rolls[key]?.result,
enabled: flagData.rolls[key]?.enabled,
label: flagData.rolls[key]?.label,
result: "",
total: 0,
totalStr: "",
dice: {},
css: "",
} as M5RollResult;
}
}
}
const newRoll = new M5Roll(rollData, actor, rollData.res.label, "-1");
if (!newRoll._evaluated) await newRoll.evaluate();
const chatData = {
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
content: await newRoll.render(),
speaker: ChatMessage.getSpeaker({ actor: actor }),
sound: CONFIG.sounds.dice,
roll: Roll.fromTerms([newRoll.pool]),
flags: { rerolled: true },
};
message.update(chatData);
}
};