|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
// Import document classes.
|
|
|
|
|
import { KidsOnBroomsActor } from "./documents/actor.mjs";
|
|
|
|
|
import { NeverStopBlowingUpActor } from "./documents/actor.mjs";
|
|
|
|
|
|
|
|
|
|
// Import sheet classes.
|
|
|
|
|
import { KidsOnBroomsActorSheet } from "./sheets/actor-sheet.mjs";
|
|
|
|
|
import { NeverStopBlowingUpActorSheet } from "./sheets/actor-sheet.mjs";
|
|
|
|
|
|
|
|
|
|
// Import helper/utility classes and constants.
|
|
|
|
|
import { preloadHandlebarsTemplates } from "./helpers/templates.mjs";
|
|
|
|
|
import { KIDSONBROOMS } from "./helpers/config.mjs";
|
|
|
|
|
import { NEVERSTOPBLOWINGUP } from "./helpers/config.mjs";
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
/* Init Hook */
|
|
|
|
@ -25,13 +25,13 @@ Hooks.once('init', async function() {
|
|
|
|
|
// Add utility classes and functions to the global game object so that they're more easily
|
|
|
|
|
// accessible in global contexts.
|
|
|
|
|
game.kidsonbrooms = {
|
|
|
|
|
KidsOnBroomsActor,
|
|
|
|
|
NeverStopBlowingUpActor,
|
|
|
|
|
_onTakeAdversityToken: _onTakeAdversityToken, // Add the function to the global object
|
|
|
|
|
_onSpendAdversityTokens: _onSpendAdversityTokens // Add the function to the global object
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Add custom constants for configuration.
|
|
|
|
|
CONFIG.KIDSONBROOMS = KIDSONBROOMS;
|
|
|
|
|
CONFIG.NEVERSTOPBLOWINGUP = NEVERSTOPBLOWINGUP;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set an initiative formula for the system
|
|
|
|
@ -44,11 +44,11 @@ Hooks.once('init', async function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Define custom Document classes
|
|
|
|
|
CONFIG.Actor.documentClass = KidsOnBroomsActor;
|
|
|
|
|
CONFIG.Actor.documentClass = NeverStopBlowingUpActor;
|
|
|
|
|
|
|
|
|
|
// Register sheet application classes
|
|
|
|
|
Actors.unregisterSheet("core", ActorSheet);
|
|
|
|
|
Actors.registerSheet("kidsonbrooms", KidsOnBroomsActorSheet, { makeDefault: true });
|
|
|
|
|
Actors.registerSheet("fvtt-never-stop-blowing-up", NeverStopBlowingUpActorSheet, { makeDefault: true });
|
|
|
|
|
|
|
|
|
|
//If there is a new chat message that is a roll we add the adversity token controls
|
|
|
|
|
Hooks.on("renderChatMessage", (message, html, messageData) => {
|
|
|
|
@ -86,10 +86,10 @@ Hooks.once('init', async function() {
|
|
|
|
|
// Update the message content
|
|
|
|
|
tokenControls.update({ content: updatedContent });
|
|
|
|
|
// Set the flag on the chat message to indicate that the token has been claimed
|
|
|
|
|
tokenControls.setFlag("kidsonbrooms", "tokenClaimed", true);
|
|
|
|
|
tokenControls.setFlag("fvtt-never-stop-blowing-up", "tokenClaimed", true);
|
|
|
|
|
} else {
|
|
|
|
|
// Emit a socket request to update the message to show that the token has been claimed
|
|
|
|
|
game.socket.emit('system.kidsonbrooms', {
|
|
|
|
|
game.socket.emit('system.fvtt-never-stop-blowing-up', {
|
|
|
|
|
action: "takeToken",
|
|
|
|
|
messageID: message.id,
|
|
|
|
|
actorID: actor.id,
|
|
|
|
@ -117,7 +117,7 @@ Hooks.once('init', async function() {
|
|
|
|
|
* if a player wants to claim a token we will update the message since they do not have the permissions
|
|
|
|
|
*/
|
|
|
|
|
Hooks.once('ready', function() {
|
|
|
|
|
game.socket.on('system.kidsonbrooms', async (data) => {
|
|
|
|
|
game.socket.on('system.fvtt-never-stop-blowing-up', async (data) => {
|
|
|
|
|
console.log("Socket data received:", data);
|
|
|
|
|
|
|
|
|
|
if (data.action === "spendTokens") {
|
|
|
|
@ -189,7 +189,7 @@ Hooks.once('ready', function() {
|
|
|
|
|
// Update the message content
|
|
|
|
|
tokenControls.update({ content: updatedContent });
|
|
|
|
|
// Set the flag on the chat message to indicate that the token has been claimed
|
|
|
|
|
tokenControls.setFlag("kidsonbrooms", "tokenClaimed", true);
|
|
|
|
|
tokenControls.setFlag("fvtt-never-stop-blowing-up", "tokenClaimed", true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
@ -276,7 +276,7 @@ async function _onSpendAdversityTokens(e, rollMessageId) {
|
|
|
|
|
console.log(`Requesting to spend ${tokensToSpend} tokens for ${rollActor.name} by ${spendingPlayerActor.name} (cost: ${tokenCost})`);
|
|
|
|
|
|
|
|
|
|
// Emit a socket request to spend tokens
|
|
|
|
|
game.socket.emit('system.kidsonbrooms', {
|
|
|
|
|
game.socket.emit('system.fvtt-never-stop-blowing-up', {
|
|
|
|
|
action: "spendTokens",
|
|
|
|
|
rollActorId: rollActorId,
|
|
|
|
|
spendingActorId: spendingPlayerActor.id, // Send the player's actor who is spending the tokens
|
|
|
|
@ -299,8 +299,8 @@ async function _updateRollMessage(rollMessageId, tokensToSpend, isPlayerOfActor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve current tokens spent from flags, or initialize to 0 if not found
|
|
|
|
|
let cumulativeTokensSpent = message.getFlag("kidsonbrooms", "tokensSpent") || 0;
|
|
|
|
|
let newTotal = message.getFlag("kidsonbrooms", "newRollTotal") || message.rolls[0].total;
|
|
|
|
|
let cumulativeTokensSpent = message.getFlag("fvtt-never-stop-blowing-up", "tokensSpent") || 0;
|
|
|
|
|
let newTotal = message.getFlag("fvtt-never-stop-blowing-up", "newRollTotal") || message.rolls[0].total;
|
|
|
|
|
|
|
|
|
|
/*if(isPlayerOfActor)
|
|
|
|
|
{
|
|
|
|
@ -311,10 +311,10 @@ async function _updateRollMessage(rollMessageId, tokensToSpend, isPlayerOfActor)
|
|
|
|
|
}*/
|
|
|
|
|
cumulativeTokensSpent += tokensToSpend;
|
|
|
|
|
newTotal += tokensToSpend;
|
|
|
|
|
await message.setFlag("kidsonbrooms", "newRollTotal", newTotal);
|
|
|
|
|
await message.setFlag("fvtt-never-stop-blowing-up", "newRollTotal", newTotal);
|
|
|
|
|
|
|
|
|
|
// Update the message's flags to store the cumulative tokens spent
|
|
|
|
|
await message.setFlag("kidsonbrooms", "tokensSpent", cumulativeTokensSpent);
|
|
|
|
|
await message.setFlag("fvtt-never-stop-blowing-up", "tokensSpent", cumulativeTokensSpent);
|
|
|
|
|
let newContent = "";
|
|
|
|
|
if(cumulativeTokensSpent === 1)
|
|
|
|
|
{
|