Add hotbar

This commit is contained in:
2022-08-04 16:28:10 +02:00
parent ea06648a67
commit f55fc1d59a
11 changed files with 149 additions and 18 deletions

View File

@@ -153,12 +153,10 @@ export class CrucibleActorSheet extends ActorSheet {
this.actor.rollWeapon(skillId)
});
html.find('.roll-armor-die').click((event) => {
//TODO
ui.notifications.warn("Not implemented")
this.actor.rollArmorDie()
});
html.find('.roll-shield-die').click((event) => {
//TODO
ui.notifications.warn("Not implemented")
this.actor.rollShieldDie()
});
html.find('.roll-save').click((event) => {

View File

@@ -570,6 +570,30 @@ export class CrucibleActor extends Actor {
}
}
}
/* -------------------------------------------- */
rollShieldDie() {
let shield = this.getEquippedShield()
if (shield) {
shield = duplicate(shield)
let rollData = this.getCommonRollData()
rollData.mode = "shield"
rollData.shield = shield
rollData.img = shield.img
this.startRoll(rollData)
}
}
/* -------------------------------------------- */
rollArmorDie() {
let armor = this.getEquippedArmor()
if (armor) {
armor = duplicate(armor)
let diceValue = armor.data.absorprionroll
}
}
/* -------------------------------------------- */
rollSave(saveKey) {
let saves = this.getSaveRoll()

View File

@@ -7,11 +7,11 @@ import { CrucibleRollDialog } from "./crucible-roll-dialog.js";
export class CrucibleCommands {
static init() {
if (!game.system.crucible.commands) {
if (!game.system.cruciblerpg.commands) {
const crucibleCommands = new CrucibleCommands();
//crucibleCommands.registerCommand({ path: ["/char"], func: (content, msg, params) => crucibleCommands.createChar(msg), descr: "Create a new character" });
//crucibleCommands.registerCommand({ path: ["/pool"], func: (content, msg, params) => crucibleCommands.poolRoll(msg), descr: "Generic Roll Window" });
game.system.crucible.commands = crucibleCommands;
game.system.cruciblerpg.commands = crucibleCommands;
}
}
constructor() {

View File

@@ -0,0 +1,86 @@
export class CrucibleHotbar {
/**
* Create a macro when dropping an entity on the hotbar
* Item - open roll dialog for item
* Actor - open actor sheet
* Journal - open journal sheet
*/
static init( ) {
Hooks.on("hotbarDrop", async (bar, documentData, slot) => {
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
if (documentData.type == "Item") {
console.log("Drop done !!!", bar, documentData, slot)
let item = documentData.data
let command = `game.system.cruciblerpg.CrucibleHotbar.rollMacro("${item.name}", "${item.type}");`
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command))
if (!macro) {
macro = await Macro.create({
name: item.name,
type: "script",
img: item.img,
command: command
}, { displaySheet: false })
}
game.user.assignHotbarMacro(macro, slot);
}
// Create a macro to open the actor sheet of the actor dropped on the hotbar
else if (documentData.type == "Actor") {
let actor = game.actors.get(documentData.id);
let command = `game.actors.get("${documentData.id}").sheet.render(true)`
let macro = game.macros.contents.find(m => (m.name === actor.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: actor.data.name,
type: "script",
img: actor.data.img,
command: command
}, { displaySheet: false })
game.user.assignHotbarMacro(macro, slot);
}
}
// Create a macro to open the journal sheet of the journal dropped on the hotbar
else if (documentData.type == "JournalEntry") {
let journal = game.journal.get(documentData.id);
let command = `game.journal.get("${documentData.id}").sheet.render(true)`
let macro = game.macros.contents.find(m => (m.name === journal.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: journal.data.name,
type: "script",
img: "",
command: command
}, { displaySheet: false })
game.user.assignHotbarMacro(macro, slot);
}
}
return false;
});
}
/** Roll macro */
static rollMacro(itemName, itemType, bypassData) {
const speaker = ChatMessage.getSpeaker()
let actor
if (speaker.token) actor = game.actors.tokens[speaker.token]
if (!actor) actor = game.actors.get(speaker.actor)
if (!actor) {
return ui.notifications.warn(`Select your actor to run the macro`)
}
let item = actor.items.find(it => it.name === itemName && it.type == itemType)
if (!item ) {
return ui.notifications.warn(`Unable to find the item of the macro in the current actor`)
}
// Trigger the item roll
if (item.type === "weapon") {
return actor.rollWeapon( item.id)
}
if (item.type === "skill") {
return actor.rollSkill( item.id)
}
}
}

View File

@@ -15,6 +15,7 @@ import { CrucibleNPCSheet } from "./crucible-npc-sheet.js";
import { CrucibleUtility } from "./crucible-utility.js";
import { CrucibleCombat } from "./crucible-combat.js";
import { CrucibleItem } from "./crucible-item.js";
import { CrucibleHotbar } from "./crucible-hotbar.js"
/* -------------------------------------------- */
/* Foundry VTT Initialization */
@@ -22,7 +23,12 @@ import { CrucibleItem } from "./crucible-item.js";
/************************************************************************************/
Hooks.once("init", async function () {
console.log(`Initializing Crucible RPG`);
game.system.cruciblerpg = {
CrucibleHotbar
}
/* -------------------------------------------- */
// preload handlebars templates
@@ -56,7 +62,6 @@ Hooks.once("init", async function () {
CONFIG.Actor.documentClass = CrucibleActor
CONFIG.Item.documentClass = CrucibleItem
//CONFIG.Token.objectClass = CrucibleToken
game.system.crucible = { };
/* -------------------------------------------- */
// Register sheet application classes
@@ -67,8 +72,7 @@ Hooks.once("init", async function () {
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("fvtt-crucible", CrucibleItemSheet, { makeDefault: true });
CrucibleUtility.init();
CrucibleUtility.init()
});
/* -------------------------------------------- */
@@ -103,6 +107,7 @@ Hooks.once("ready", function () {
welcomeMessage();
CrucibleUtility.ready()
CrucibleHotbar.init()
})
/* -------------------------------------------- */

View File

@@ -285,6 +285,9 @@ export class CrucibleUtility {
if ( rollData.save) {
startFormula = String(rollData.save.value) + "d6cs>=5"
}
if ( rollData.shield) {
startFormula = "1" + String(rollData.shield.data.shielddie) + "cs>=5"
}
diceFormula = startFormula
// skill => 2
@@ -344,7 +347,9 @@ export class CrucibleUtility {
// armor => 12
let skillArmorPenalty = 0
for (let armor of rollData.armors) {
skillArmorPenalty += armor.data.skillpenalty
if (armor.data.equipped) {
skillArmorPenalty += armor.data.skillpenalty
}
}
if (rollData.skill && rollData.skill.data.armorpenalty && skillArmorPenalty > 0 ) {
rollData.skillArmorPenalty = skillArmorPenalty