2020-11-28 19:12:19 +01:00
|
|
|
export default class KHDiceRoller {
|
|
|
|
async rollSpellCostInChat(cost, speaker) {
|
|
|
|
let formula = cost + "d6"
|
|
|
|
|
|
|
|
const roll = new Roll(formula);
|
|
|
|
|
|
|
|
let res = roll.roll();
|
|
|
|
|
|
|
|
let rollData = {
|
|
|
|
name: "SPELL.COST",
|
|
|
|
res: res,
|
|
|
|
showFormula: true
|
|
|
|
};
|
|
|
|
|
|
|
|
const html = await renderTemplate("systems/kopparhavet/templates/dice/roll.html", rollData);
|
|
|
|
|
2020-12-04 03:45:09 +01:00
|
|
|
if(game.settings.get("kopparhavet", "applySpellCost")) {
|
|
|
|
let totalCostForActor = speaker.data.data.mana.value + roll.total
|
|
|
|
|
|
|
|
speaker.update({ ["data.mana.value"]: totalCostForActor });
|
|
|
|
}
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
await roll.toMessage({
|
|
|
|
create: true,
|
|
|
|
content: html,
|
|
|
|
user: game.user._id,
|
|
|
|
speaker: {
|
|
|
|
actor: speaker._id,
|
|
|
|
token: speaker.token,
|
|
|
|
alias: speaker.name,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async rollDamageInChat(facesNr, speaker) {
|
|
|
|
let formula = facesNr + "d6x6"
|
|
|
|
|
|
|
|
const roll = new Roll(formula);
|
|
|
|
|
|
|
|
let res = roll.roll();
|
|
|
|
|
|
|
|
let rollData = {
|
|
|
|
name: "ITEM.DAMAGE",
|
|
|
|
res: res,
|
|
|
|
showFormula: true
|
|
|
|
};
|
|
|
|
|
|
|
|
const html = await renderTemplate("systems/kopparhavet/templates/dice/roll.html", rollData);
|
|
|
|
|
|
|
|
await roll.toMessage({
|
|
|
|
create: true,
|
|
|
|
content: html,
|
|
|
|
user: game.user._id,
|
|
|
|
speaker: {
|
|
|
|
actor: speaker._id,
|
|
|
|
token: speaker.token,
|
|
|
|
alias: speaker.name,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async rollArmorInChat(armor, hasHelmet, speaker) {
|
|
|
|
let formula = armor + "d6"
|
|
|
|
|
|
|
|
if(hasHelmet) {
|
|
|
|
formula += "x6"
|
|
|
|
}
|
|
|
|
|
|
|
|
const roll = new Roll(formula);
|
|
|
|
|
|
|
|
let res = roll.roll();
|
|
|
|
|
|
|
|
let rollData = {
|
|
|
|
name: "ITEM.DEFENCE",
|
|
|
|
res: res,
|
|
|
|
showFormula: true
|
|
|
|
};
|
|
|
|
|
|
|
|
const html = await renderTemplate("systems/kopparhavet/templates/dice/roll.html", rollData);
|
|
|
|
|
|
|
|
await roll.toMessage({
|
|
|
|
create: true,
|
|
|
|
content: html,
|
|
|
|
user: game.user._id,
|
|
|
|
speaker: {
|
|
|
|
actor: speaker._id,
|
|
|
|
token: speaker.token,
|
|
|
|
alias: speaker.name,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-01 04:12:47 +01:00
|
|
|
async rollSkillInChat(skillName, skillValue, showValue, speaker, openclosed) {
|
2020-11-28 19:12:19 +01:00
|
|
|
const roll = new Roll(`1d100`);
|
|
|
|
|
|
|
|
let res = roll.roll();
|
|
|
|
|
|
|
|
let computedName = skillName
|
|
|
|
|
|
|
|
if(showValue) {
|
|
|
|
computedName += " (" + skillValue + ")"
|
|
|
|
}
|
|
|
|
|
2020-12-01 04:12:47 +01:00
|
|
|
if(openclosed === undefined) {
|
|
|
|
openclosed = 0
|
|
|
|
}
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
let rollData = {
|
|
|
|
name: computedName,
|
|
|
|
res: res
|
|
|
|
};
|
|
|
|
|
|
|
|
if(skillValue > 0) {
|
2020-12-01 04:12:47 +01:00
|
|
|
let oneRes = Math.floor((res.total / 1) % 10);
|
|
|
|
let tenRes = Math.floor((res.total / 10) % 10);
|
|
|
|
|
|
|
|
if(openclosed < 0) {
|
|
|
|
rollData.closed = Math.abs(openclosed)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(openclosed > 0) {
|
|
|
|
rollData.opened = Math.abs(openclosed)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(openclosed < 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes) {
|
|
|
|
// roll is closed
|
|
|
|
rollData.failure = true
|
|
|
|
} else if(openclosed > 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes){
|
|
|
|
// roll is opened
|
2020-11-28 19:12:19 +01:00
|
|
|
rollData.success = true
|
|
|
|
} else {
|
2020-12-01 04:12:47 +01:00
|
|
|
if (res.total <= skillValue) {
|
|
|
|
rollData.success = true
|
|
|
|
} else {
|
|
|
|
rollData.failure = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(oneRes === tenRes) {
|
|
|
|
rollData.excetional = true
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const html = await renderTemplate("systems/kopparhavet/templates/dice/roll.html", rollData);
|
|
|
|
|
|
|
|
await roll.toMessage({
|
|
|
|
create: true,
|
|
|
|
content: html,
|
|
|
|
user: game.user._id,
|
|
|
|
speaker: {
|
|
|
|
actor: speaker._id,
|
|
|
|
token: speaker.token,
|
|
|
|
alias: speaker.name,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-12-01 04:12:47 +01:00
|
|
|
|
|
|
|
async rollSkillDialogInChat(skillName, skillValue, showValue, speaker, startopen) {
|
|
|
|
const id = randomID();
|
|
|
|
|
|
|
|
if(startopen === undefined) {
|
|
|
|
startopen = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
const content = await renderTemplate("systems/kopparhavet/templates/roll-dialog.html", {
|
|
|
|
id,
|
|
|
|
startopen,
|
|
|
|
skillName,
|
|
|
|
skillValue,
|
|
|
|
});
|
|
|
|
|
|
|
|
await new Dialog({
|
|
|
|
title: game.i18n.localize("ROLL.TITLE"),
|
|
|
|
content,
|
|
|
|
buttons: {
|
|
|
|
one: {
|
|
|
|
icon: '<i class="fas fa-check"></i>',
|
|
|
|
label: game.i18n.localize("BUTTON.ROLL"),
|
|
|
|
callback: async () => {
|
|
|
|
const container = document.getElementById(id);
|
|
|
|
let openclosed = container.querySelector('[name="openclosed"]').value
|
|
|
|
|
|
|
|
const roll = new Roll(`1d100`);
|
|
|
|
|
|
|
|
let res = roll.roll();
|
|
|
|
|
|
|
|
let computedName = skillName
|
|
|
|
|
|
|
|
if(showValue) {
|
|
|
|
computedName += " (" + skillValue + ")"
|
|
|
|
}
|
|
|
|
|
|
|
|
let rollData = {
|
|
|
|
name: computedName,
|
|
|
|
res: res
|
|
|
|
};
|
|
|
|
|
|
|
|
// Evaluate result only if we have a positive skillvalue
|
|
|
|
if(skillValue > 0) {
|
|
|
|
let oneRes = Math.floor((res.total / 1) % 10);
|
|
|
|
let tenRes = Math.floor((res.total / 10) % 10);
|
|
|
|
|
|
|
|
if(openclosed < 0) {
|
|
|
|
rollData.closed = Math.abs(openclosed)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(openclosed > 0) {
|
|
|
|
rollData.opened = Math.abs(openclosed)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(openclosed < 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes) {
|
|
|
|
// roll is closed
|
|
|
|
rollData.failure = true
|
|
|
|
} else if(openclosed > 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes){
|
|
|
|
// roll is opened
|
|
|
|
rollData.success = true
|
|
|
|
} else {
|
|
|
|
if (res.total <= skillValue) {
|
|
|
|
rollData.success = true
|
|
|
|
} else {
|
|
|
|
rollData.failure = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(oneRes === tenRes) {
|
|
|
|
rollData.excetional = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const html = await renderTemplate("systems/kopparhavet/templates/dice/roll.html", rollData);
|
|
|
|
|
|
|
|
await roll.toMessage({
|
|
|
|
create: true,
|
|
|
|
content: html,
|
|
|
|
user: game.user._id,
|
|
|
|
speaker: {
|
|
|
|
actor: speaker._id,
|
|
|
|
token: speaker.token,
|
|
|
|
alias: speaker.name,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
two: {
|
|
|
|
icon: '<i class="fas fa-times"></i>',
|
|
|
|
label: game.i18n.localize("BUTTON.CANCEL"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
classes: ["dialog", "kopparhavet"],
|
|
|
|
}).render(true);
|
|
|
|
}
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|