Modifikation für alle Würfe
This commit is contained in:
parent
7333b54a35
commit
332f035846
|
|
@ -28,6 +28,7 @@ export interface M5Attribute {
|
||||||
export interface M5RollData {
|
export interface M5RollData {
|
||||||
c: any;
|
c: any;
|
||||||
i: any;
|
i: any;
|
||||||
|
b: any;
|
||||||
iType: string;
|
iType: string;
|
||||||
rolls: {};
|
rolls: {};
|
||||||
res: {
|
res: {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ 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;
|
||||||
const roll = new Roll(formula.formula, this.data);
|
const roll = new Roll(formula.formula, this.data);
|
||||||
return roll;
|
return roll;
|
||||||
});
|
});
|
||||||
|
|
@ -66,7 +67,7 @@ export class M5Roll {
|
||||||
const parseResult = M5Roll.parseDiceSides(rollResult.formula);
|
const parseResult = M5Roll.parseDiceSides(rollResult.formula);
|
||||||
//console.log("evaluate roll", parseResult)
|
//console.log("evaluate roll", parseResult)
|
||||||
if (parseResult?.sides === 20) {
|
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;
|
if (rowRes === M5EwResult.TBD || rowRes === M5EwResult.HIGH) rowRes = M5EwResult.FAIL;
|
||||||
} else {
|
} else {
|
||||||
if (rowRes === M5EwResult.TBD) rowRes = M5EwResult.PASS;
|
if (rowRes === M5EwResult.TBD) rowRes = M5EwResult.PASS;
|
||||||
|
|
@ -99,6 +100,13 @@ export class M5Roll {
|
||||||
}
|
}
|
||||||
|
|
||||||
async toMessage() {
|
async toMessage() {
|
||||||
|
let checkOptions = await this.popUp();
|
||||||
|
if (checkOptions["cancelled"]) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.data.b = checkOptions;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this._evaluated) await this.evaluate();
|
if (!this._evaluated) await this.evaluate();
|
||||||
|
|
||||||
const rMode = (game as Game).settings.get("core", "rollMode");
|
const rMode = (game as Game).settings.get("core", "rollMode");
|
||||||
|
|
@ -313,6 +321,48 @@ export class M5Roll {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async popUp({
|
||||||
|
hasFortune = true,
|
||||||
|
taskType = null,
|
||||||
|
useFortune = false,
|
||||||
|
difficulty = 20,
|
||||||
|
modifier = 0,
|
||||||
|
closedRoll = false,
|
||||||
|
template = "systems/midgard5/templates/chat/task-check-dialog.hbs",
|
||||||
|
} = {}) {
|
||||||
|
const html = await renderTemplate(template, { hasFortune, useFortune, difficulty, modifier, closedRoll });
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const data = {
|
||||||
|
title: (game as Game).i18n.format("midgard5.chat.taskCheck.title", { type: taskType }),
|
||||||
|
content: html,
|
||||||
|
buttons: {
|
||||||
|
normal: {
|
||||||
|
label: (game as Game).i18n.localize("midgard5.chat.actions.roll"),
|
||||||
|
callback: (html) => resolve(this._processTaskCheckOptions(html[0].querySelector("form"))),
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
label: (game as Game).i18n.localize("midgard5.chat.actions.cancel"),
|
||||||
|
callback: (html) => resolve({ cancelled: true }),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: "normal",
|
||||||
|
close: () => resolve({ cancelled: true }),
|
||||||
|
};
|
||||||
|
|
||||||
|
new Dialog(data, null).render(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_processTaskCheckOptions(form) {
|
||||||
|
return {
|
||||||
|
difficulty: parseInt(form.difficulty?.value),
|
||||||
|
modifier: parseInt(form.modifier?.value),
|
||||||
|
useFortune: form.useFortune?.checked,
|
||||||
|
closedRoll: form.closedRoll?.checked,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FormulaParseResult {
|
interface FormulaParseResult {
|
||||||
|
|
|
||||||
|
|
@ -77,17 +77,6 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||||
let target = event.target.closest("[data-attribute]") as HTMLElement;
|
let target = event.target.closest("[data-attribute]") as HTMLElement;
|
||||||
let attributeValue = target ? parseInt(target.dataset.value) : null;
|
let attributeValue = target ? parseInt(target.dataset.value) : null;
|
||||||
let attributeStr = target ? target.dataset.attribute : null;
|
let attributeStr = target ? target.dataset.attribute : null;
|
||||||
let hasFortune: boolean;
|
|
||||||
let taskType: string;
|
|
||||||
let useFortune: boolean;
|
|
||||||
let modifier: number;
|
|
||||||
let difficulty: number;
|
|
||||||
let closedRoll: boolean;
|
|
||||||
let checkOptions = await GetRollOptions({ hasFortune, taskType, useFortune, modifier, difficulty, closedRoll });
|
|
||||||
console.log("Check Options", checkOptions);
|
|
||||||
if (checkOptions["cancelled"]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const roll = M5Roll.fromAttributeValue(this.actor, attributeStr, attributeValue);
|
const roll = M5Roll.fromAttributeValue(this.actor, attributeStr, attributeValue);
|
||||||
await roll.toMessage();
|
await roll.toMessage();
|
||||||
});
|
});
|
||||||
|
|
@ -527,43 +516,3 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function GetRollOptions({
|
|
||||||
hasFortune = true,
|
|
||||||
taskType = null,
|
|
||||||
useFortune = false,
|
|
||||||
difficulty = 0,
|
|
||||||
modifier = 0,
|
|
||||||
closedRoll = false,
|
|
||||||
template = "systems/midgard5/templates/chat/task-check-dialog.hbs" } = {}) {
|
|
||||||
const html = await renderTemplate(template, { hasFortune, useFortune, difficulty, modifier, closedRoll });
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const data = {
|
|
||||||
title: (game as Game).i18n.format("midgard5.chat.taskCheck.title", { type: taskType }),
|
|
||||||
content: html,
|
|
||||||
buttons: {
|
|
||||||
normal: {
|
|
||||||
label: (game as Game).i18n.localize("midgard5.chat.actions.roll"),
|
|
||||||
callback: html => resolve(_processTaskCheckOptions(html[0].querySelector("form")))
|
|
||||||
},
|
|
||||||
cancel: {
|
|
||||||
label: (game as Game).i18n.localize("midgard5.chat.actions.cancel"),
|
|
||||||
callback: html => resolve({ cancelled: true })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
default: "normal",
|
|
||||||
close: () => resolve({ cancelled: true })
|
|
||||||
};
|
|
||||||
|
|
||||||
new Dialog(data, null).render(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function _processTaskCheckOptions(form) {
|
|
||||||
return {
|
|
||||||
difficulty: parseInt(form.difficulty?.value),
|
|
||||||
modifier: parseInt(form.modifier?.value),
|
|
||||||
useFortune: form.useFortune?.checked,
|
|
||||||
closedRoll: form.closedRoll?.checked
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue