Implement Reroll
This commit is contained in:
@@ -5,6 +5,7 @@ import { M5Character } from "./module/actors/M5Character";
|
||||
import { M5ItemMod, M5ModOperation, M5Skill, M5TimeUnit } from "./module/M5Base";
|
||||
import { M5ItemSheet } from "./module/sheets/M5ItemSheet";
|
||||
import { M5Item } from "./module/items/M5Item";
|
||||
import { reroll } from "./module/rolls/reroll";
|
||||
|
||||
Hooks.once("init", async () => {
|
||||
Logger.log("M5 | Initialisierung Midgard 5");
|
||||
@@ -172,6 +173,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"].character.id === (game as Game).actors.get(message["speaker"].actor).id && !message["flags"].rerolled;
|
||||
},
|
||||
callback: (li) => reroll(li),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -109,7 +109,7 @@ export class M5Roll {
|
||||
|
||||
if (!this._evaluated) await this.evaluate();
|
||||
|
||||
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,
|
||||
@@ -117,10 +117,11 @@ export class M5Roll {
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
|
||||
sound: CONFIG.sounds.dice,
|
||||
roll: Roll.fromTerms([this.pool]),
|
||||
flags: { data: this.data },
|
||||
};
|
||||
|
||||
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) {
|
||||
@@ -323,31 +324,29 @@ export class M5Roll {
|
||||
}
|
||||
|
||||
async popUp({
|
||||
hasFortune = true,
|
||||
taskType = null,
|
||||
useFortune = false,
|
||||
difficulty = 20,
|
||||
modifier = 0,
|
||||
closedRoll = false,
|
||||
rollModes = CONFIG.Dice.rollModes,
|
||||
rollMode = "",
|
||||
template = "systems/midgard5/templates/chat/task-check-dialog.hbs",
|
||||
} = {}) {
|
||||
const html = await renderTemplate(template, { hasFortune, useFortune, difficulty, modifier, closedRoll });
|
||||
|
||||
const html = await renderTemplate(template, { useFortune, difficulty, modifier, rollModes, rollMode });
|
||||
return new Promise((resolve) => {
|
||||
const data = {
|
||||
title: (game as Game).i18n.format("midgard5.chat.taskCheck.title", { type: taskType }),
|
||||
title: (game as Game).i18n.localize("midgard5.chat.roll"),
|
||||
content: html,
|
||||
buttons: {
|
||||
normal: {
|
||||
label: (game as Game).i18n.localize("midgard5.chat.actions.roll"),
|
||||
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.actions.cancel"),
|
||||
label: (game as Game).i18n.localize("midgard5.chat.cancel"),
|
||||
callback: (html) => resolve({ cancelled: true }),
|
||||
},
|
||||
},
|
||||
default: "normal",
|
||||
default: "roll",
|
||||
close: () => resolve({ cancelled: true }),
|
||||
};
|
||||
|
||||
@@ -359,8 +358,7 @@ export class M5Roll {
|
||||
return {
|
||||
difficulty: parseInt(form.difficulty?.value),
|
||||
modifier: parseInt(form.modifier?.value),
|
||||
useFortune: form.useFortune?.checked,
|
||||
closedRoll: form.closedRoll?.checked,
|
||||
rollMode: form.rollMode?.value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
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"),
|
||||
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.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 + " + 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);
|
||||
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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user