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:
@@ -5,6 +5,7 @@ import { M5Character } from "./module/actors/M5Character";
|
||||
import { M5ModOperation, M5TimeUnit } from "./module/M5Base";
|
||||
import { M5ItemSheet } from "./module/sheets/M5ItemSheet";
|
||||
import { M5Item } from "./module/items/M5Item";
|
||||
import { reroll } from "./module/rolls/reroll";
|
||||
import { loadHelpers } from "./helpers";
|
||||
import { loadSettings } from "./settings";
|
||||
|
||||
@@ -79,6 +80,17 @@ Hooks.on("getChatLogEntryContext", function (html, options) {
|
||||
return (game["user"].character || game["canvas"].tokens.controlled) && damageRolls > 0;
|
||||
},
|
||||
callback: (li) => applyDamage(li, -2),
|
||||
},
|
||||
{
|
||||
name: "Redo",
|
||||
icon: '<i class="far fa-arrow-rotate-left"></i>',
|
||||
condition: (li) => {
|
||||
const message = (game as Game).messages.get(li.attr("data-message-id"));
|
||||
|
||||
// All must be true to show the reroll dialogue
|
||||
return (game["user"].isGM || game["user"].character?.id === (game as Game).actors.get(message["speaker"].actor)?.id) && !message["flags"].rerolled;
|
||||
},
|
||||
callback: (li) => reroll(li),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface M5Attribute {
|
||||
export interface M5RollData {
|
||||
c: any;
|
||||
i: any;
|
||||
b: any;
|
||||
iType: string;
|
||||
rolls: any;
|
||||
res: {
|
||||
@@ -172,6 +173,7 @@ export interface M5CharacterCalculatedData {
|
||||
pa: M5AttributeCalculated;
|
||||
wk: M5AttributeCalculated;
|
||||
};
|
||||
|
||||
stats: {
|
||||
lp: M5ModResult;
|
||||
ap: M5ModResult;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
@@ -77,7 +77,6 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
let target = event.target.closest("[data-attribute]") as HTMLElement;
|
||||
let attributeValue = target ? parseInt(target.dataset.value) : null;
|
||||
let attributeStr = target ? target.dataset.attribute : null;
|
||||
|
||||
const roll = M5Roll.fromAttributeValue(this.actor, attributeStr, attributeValue);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user