124 lines
3.0 KiB
JavaScript
124 lines
3.0 KiB
JavaScript
|
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);
|
||
|
|
||
|
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,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async rollSkillInChat(skillName, skillValue, showValue, speaker) {
|
||
|
const roll = new Roll(`1d100`);
|
||
|
|
||
|
let res = roll.roll();
|
||
|
|
||
|
let computedName = skillName
|
||
|
|
||
|
if(showValue) {
|
||
|
computedName += " (" + skillValue + ")"
|
||
|
}
|
||
|
|
||
|
let rollData = {
|
||
|
name: computedName,
|
||
|
res: res
|
||
|
};
|
||
|
|
||
|
if(skillValue > 0) {
|
||
|
if(res.total <= skillValue) {
|
||
|
rollData.success = true
|
||
|
} else {
|
||
|
rollData.failure = 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,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
}
|