Merge dice-roller branch
This commit is contained in:
@ -202,7 +202,7 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
|
||||
async renderCharacterSettings(data) {
|
||||
console.log(data);
|
||||
const configSheet = await renderTemplate("systems/fvtt-rolemaster-frp/templates/sheets/actors/dialogs/actor-settings.html", data);
|
||||
const configSheet = await renderTemplate("systems/fvtt-rolemaster-frp/templates/sheets/actors/dialogs/app_skill_category_importer.html", data);
|
||||
return (configSheet);
|
||||
}
|
||||
|
||||
@ -215,6 +215,11 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
item.sheet.render(true);
|
||||
});
|
||||
|
||||
html.find(".item-roll").click(ev => {
|
||||
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
|
||||
new game.rmss.applications.RMSSToolsDiceRoller(item.name, item.system.total_bonus).render(true);
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.isEditable) return;
|
||||
@ -229,15 +234,14 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
item.delete();
|
||||
});
|
||||
|
||||
// Show Sheet Settings
|
||||
// Show Skill Category Importer
|
||||
html.find(".import-skillcats").click(async ev => {
|
||||
|
||||
let selectOptions = {};
|
||||
for (const pack of game.packs) {
|
||||
selectOptions[pack.metadata.id] = pack.metadata.label;
|
||||
}
|
||||
|
||||
new game.rmss.applications.RMSSActorSheetConfig(selectOptions, this.actor).render(true);
|
||||
new game.rmss.applications.RMSSToolsSCImporter(selectOptions, this.actor).render(true);
|
||||
});
|
||||
|
||||
// Check/Uncheck Favorite Skill
|
||||
|
85
module/sheets/apps/rmss_dice_roller.js
Normal file
85
module/sheets/apps/rmss_dice_roller.js
Normal file
@ -0,0 +1,85 @@
|
||||
import {
|
||||
roll_one_to_onehundred,
|
||||
roll_low_open_ended,
|
||||
roll_high_open_ended,
|
||||
roll_open_ended
|
||||
} from "./rmss_dice_roller_rolls.js";
|
||||
import {
|
||||
getOpenEndedRollModifier,
|
||||
processOpenEndedSixtySixRoll,
|
||||
processOpenEndedRoll,
|
||||
processHighOpenEndedRoll,
|
||||
processLowOpenEndedRoll
|
||||
} from "./rmss_dice_roller_processing.js";
|
||||
|
||||
export default class RMSSToolsDiceRoller extends FormApplication {
|
||||
constructor(itemName, characterBonus) {
|
||||
super();
|
||||
this.itemName = itemName;
|
||||
this.characterBonus = characterBonus;
|
||||
this.rollType = [
|
||||
{value: "one_to_onehundred", text: "1-100", selected: false},
|
||||
{value: "open_ended", text: "Open-Ended", selected: true},
|
||||
{value: "high_open_ended", text: "High Open-Ended", selected: false},
|
||||
{value: "low_open_ended", text: "Low Open-Ended", selected: false}
|
||||
];
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["form"],
|
||||
title: "Rolemaster Dice Roller",
|
||||
popOut: true,
|
||||
width: 380,
|
||||
height: 210,
|
||||
template: "systems/fvtt-rolemaster-frp/templates/sheets/apps/app_dice_roller.html"
|
||||
});
|
||||
}
|
||||
|
||||
getData() {
|
||||
// Send data to the template
|
||||
return {
|
||||
itemName: this.itemName,
|
||||
characterBonus: this.characterBonus,
|
||||
selectOptions: this.rollType,
|
||||
};
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
}
|
||||
|
||||
async _updateObject(event, formData) {
|
||||
console.log("Rolling Dice");
|
||||
console.log(formData);
|
||||
console.log(event);
|
||||
switch (formData.rollType) {
|
||||
case "one_to_onehundred":
|
||||
this.roll_one_to_onehundred();
|
||||
break;
|
||||
case "open_ended":
|
||||
this.roll_open_ended();
|
||||
break;
|
||||
case "high_open_ended":
|
||||
this.roll_high_open_ended();
|
||||
break;
|
||||
case "low_open_ended":
|
||||
this.roll_low_open_ended();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RMSSToolsDiceRoller.prototype.roll_one_to_onehundred = roll_one_to_onehundred;
|
||||
RMSSToolsDiceRoller.prototype.roll_low_open_ended = roll_low_open_ended;
|
||||
RMSSToolsDiceRoller.prototype.roll_high_open_ended = roll_high_open_ended;
|
||||
RMSSToolsDiceRoller.prototype.roll_open_ended = roll_open_ended;
|
||||
|
||||
RMSSToolsDiceRoller.prototype.getOpenEndedRollModifier =
|
||||
getOpenEndedRollModifier;
|
||||
RMSSToolsDiceRoller.prototype.processOpenEndedSixtySixRoll =
|
||||
processOpenEndedSixtySixRoll;
|
||||
RMSSToolsDiceRoller.prototype.processOpenEndedRoll = processOpenEndedRoll;
|
||||
RMSSToolsDiceRoller.prototype.processHighOpenEndedRoll =
|
||||
processHighOpenEndedRoll;
|
||||
RMSSToolsDiceRoller.prototype.processLowOpenEndedRoll = processLowOpenEndedRoll;
|
131
module/sheets/apps/rmss_dice_roller_processing.js
Normal file
131
module/sheets/apps/rmss_dice_roller_processing.js
Normal file
@ -0,0 +1,131 @@
|
||||
export async function getOpenEndedRollModifier() {
|
||||
return await new Roll("1d100x>95").roll();
|
||||
}
|
||||
|
||||
export function processOpenEndedSixtySixRoll(baseroll, rolltype) {
|
||||
// Log the Roll to Chat
|
||||
let chatOptions = {
|
||||
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
|
||||
rolls: [baseroll],
|
||||
flavor: rolltype,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
content: "You rolled a 66!",
|
||||
};
|
||||
|
||||
ChatMessage.create(chatOptions);
|
||||
}
|
||||
|
||||
export function processOpenEndedRoll(baseroll, rolltype) {
|
||||
// Define the Chat Message Template
|
||||
let chatTemplate = "systems/fvtt-rolemaster-frp/templates/chat/chat_dice_roll.html";
|
||||
|
||||
// Pass the Data through to be used in the Chat Message
|
||||
let chatData = {
|
||||
baseroll: baseroll,
|
||||
total: baseroll.result,
|
||||
highopen: false,
|
||||
lowopen: false,
|
||||
};
|
||||
|
||||
// Render the Rolls to the Chat Window
|
||||
renderTemplate(chatTemplate, chatData).then((html) => {
|
||||
let chatOptions = {
|
||||
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
|
||||
rolls: [baseroll],
|
||||
flavor: rolltype,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
content: html,
|
||||
};
|
||||
|
||||
ChatMessage.create(chatOptions);
|
||||
});
|
||||
}
|
||||
|
||||
export async function processHighOpenEndedRoll(baseroll, rolltype) {
|
||||
// Get the Base Roll followed by the High Open Ended Roll
|
||||
let originalRoll = baseroll;
|
||||
let openendedRoll = await this.getOpenEndedRollModifier();
|
||||
|
||||
// Create a rolls array for Dice So Nice integration.
|
||||
let rolls = [originalRoll, openendedRoll];
|
||||
|
||||
// Create an Array to hold the High Open Ended Roll Results and set the total to base roll
|
||||
let openendedResults = [];
|
||||
let total = Number(originalRoll.result);
|
||||
|
||||
// Each time the High Open Ended Roll is triggered add the result to an array and add it to the total.
|
||||
for (const rollResult of openendedRoll.dice[0].results) {
|
||||
openendedResults.push(rollResult.result);
|
||||
total = total + Number(rollResult.result);
|
||||
}
|
||||
|
||||
// Define the Chat Message Template
|
||||
let chatTemplate = "systems/fvtt-rolemaster-frp/templates/chat/chat_dice_roll.html";
|
||||
|
||||
// Pass the Data through to be used in the Chat Message
|
||||
let chatData = {
|
||||
baseroll: baseroll,
|
||||
opeendedresults: [openendedResults],
|
||||
highopen: true,
|
||||
lowopen: false,
|
||||
total: total,
|
||||
};
|
||||
|
||||
// Render the Rolls to the Chat Window
|
||||
renderTemplate(chatTemplate, chatData).then((html) => {
|
||||
let chatOptions = {
|
||||
style: CONST.CHAT_MESSAGE_STYLES.ROLL,
|
||||
rolls: rolls,
|
||||
flavor: rolltype,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
content: html,
|
||||
};
|
||||
|
||||
ChatMessage.create(chatOptions);
|
||||
});
|
||||
}
|
||||
|
||||
export async function processLowOpenEndedRoll(baseroll, rolltype) {
|
||||
// Get the Base Roll followed by the Low Open Ended Roll
|
||||
let originalRoll = baseroll;
|
||||
let openendedRoll = await this.getOpenEndedRollModifier();
|
||||
|
||||
// Create a rolls array for Dice So Nice integration.
|
||||
let rolls = [originalRoll, openendedRoll];
|
||||
|
||||
// Create an Array to hold the Low Open Ended Roll Results and set the total to base roll
|
||||
let openendedResults = [];
|
||||
let total = Number(originalRoll.result);
|
||||
|
||||
// Each time the Low Open Ended Roll is triggered add the result to an array and subtract it from the total.
|
||||
for (const rollResult of openendedRoll.dice[0].results) {
|
||||
openendedResults.push(rollResult.result);
|
||||
total = total - Number(rollResult.result);
|
||||
}
|
||||
|
||||
// Define the Chat Message Template
|
||||
let chatTemplate = "systems/fvtt-rolemaster-frp/templates/chat/chat_dice_roll.html";
|
||||
|
||||
// Pass the Data through to be used in the Chat Message
|
||||
let chatData = {
|
||||
baseroll: baseroll,
|
||||
rolls: rolls,
|
||||
opeendedresults: [openendedResults],
|
||||
highopen: false,
|
||||
lowopen: true,
|
||||
total: total,
|
||||
};
|
||||
|
||||
// Render the Rolls to the Chat Window
|
||||
renderTemplate(chatTemplate, chatData).then((html) => {
|
||||
let chatOptions = {
|
||||
style: CONST.CHAT_MESSAGE_STYLES.ROLL,
|
||||
rolls: rolls,
|
||||
flavor: rolltype,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
content: html,
|
||||
};
|
||||
|
||||
ChatMessage.create(chatOptions);
|
||||
});
|
||||
}
|
71
module/sheets/apps/rmss_dice_roller_rolls.js
Normal file
71
module/sheets/apps/rmss_dice_roller_rolls.js
Normal file
@ -0,0 +1,71 @@
|
||||
export async function roll_one_to_onehundred() {
|
||||
// Construct the Roll instance
|
||||
let baseroll = await new Roll("1d100 + @characterBonus", {characterBonus: this.characterBonus}).roll({async: true});
|
||||
let rolltype = "Roll Type: 1-100";
|
||||
|
||||
// Log the Roll to Chat
|
||||
let chatOptions = {
|
||||
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
|
||||
rolls: [baseroll],
|
||||
flavor: rolltype,
|
||||
rollMode: game.settings.get("core", "rollMode")
|
||||
};
|
||||
|
||||
ChatMessage.create(chatOptions);
|
||||
this.close();
|
||||
};
|
||||
|
||||
export async function roll_low_open_ended() {
|
||||
// Construct the Roll instance
|
||||
let baseroll = await new Roll("1d100").roll({async: true});
|
||||
console.log(baseroll.result);
|
||||
let rolltype = "Roll Type: Low Open-Ended";
|
||||
|
||||
switch (true) {
|
||||
case (baseroll.result < 6):
|
||||
this.processLowOpenEndedRoll(baseroll, rolltype);
|
||||
break;
|
||||
case (baseroll.result === 66):
|
||||
this.processOpenEndedSixtySixRoll(baseroll, rolltype);
|
||||
break;
|
||||
default:
|
||||
this.processOpenEndedRoll(baseroll, rolltype);
|
||||
}
|
||||
}
|
||||
|
||||
export async function roll_high_open_ended() {
|
||||
// Construct the Roll instance
|
||||
let baseroll = await new Roll("1d100").roll({async: true});
|
||||
console.log(baseroll.result);
|
||||
let rolltype = "Roll Type: High Open-Ended";
|
||||
switch (true) {
|
||||
case (baseroll.result === 66):
|
||||
this.processOpenEndedSixtySixRoll(baseroll, rolltype);
|
||||
break;
|
||||
case (baseroll.result > 95):
|
||||
this.processHighOpenEndedRoll(baseroll, rolltype);
|
||||
break;
|
||||
default:
|
||||
this.processOpenEndedRoll(baseroll, rolltype);
|
||||
}
|
||||
}
|
||||
|
||||
export async function roll_open_ended() {
|
||||
// Construct the Roll instance
|
||||
let baseroll = await new Roll("1d100").roll({async: true});
|
||||
console.log(baseroll.result);
|
||||
let rolltype = "Roll Type: Open-Ended";
|
||||
switch (true) {
|
||||
case (baseroll.result < 6):
|
||||
this.processLowOpenEndedRoll(baseroll, rolltype);
|
||||
break;
|
||||
case (baseroll.result === 66):
|
||||
this.processOpenEndedSixtySixRoll(baseroll, rolltype);
|
||||
break;
|
||||
case (baseroll.result > 95):
|
||||
this.processHighOpenEndedRoll(baseroll, rolltype);
|
||||
break;
|
||||
default:
|
||||
this.processOpenEndedRoll(baseroll, rolltype);
|
||||
}
|
||||
}
|
56
module/sheets/apps/rmss_import_skill_categories.js
Normal file
56
module/sheets/apps/rmss_import_skill_categories.js
Normal file
@ -0,0 +1,56 @@
|
||||
export default class RMSSToolsSCImporter extends FormApplication {
|
||||
|
||||
constructor(selectOptions, character) {
|
||||
super();
|
||||
this.selectOptions = selectOptions;
|
||||
this.character = character;
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["form"],
|
||||
popOut: true,
|
||||
title: "Import Skill Categories",
|
||||
template: "systems/fvtt-rolemaster-frp/templates/sheets/apps/app_skill_category_importer.html"
|
||||
});
|
||||
}
|
||||
|
||||
getData() {
|
||||
// Send data to the template
|
||||
return {
|
||||
selectOptions: this.selectOptions
|
||||
};
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
}
|
||||
|
||||
async _updateObject(event, formData) {
|
||||
console.log("Deleting Old Skill Categories.");
|
||||
for (const item of this.character.items) {
|
||||
if (item.type === "skill_category") {
|
||||
item.delete();
|
||||
}
|
||||
}
|
||||
|
||||
const pack = game.packs.get(formData.selectOptions);
|
||||
const skillCategoryData = await pack.getIndex();
|
||||
|
||||
console.log("Importing New Skill Categories.");
|
||||
|
||||
for (const sc of skillCategoryData) {
|
||||
const newitem = await pack.getDocument(sc._id);
|
||||
|
||||
let newDocuments = [];
|
||||
if (newitem.type === "skill_category") {
|
||||
console.log(newitem);
|
||||
newDocuments.push(newitem);
|
||||
}
|
||||
if (newDocuments.length > 0) {
|
||||
await Item.createDocuments(newDocuments, {parent: this.character});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user