Add mana+AP reset buttons and conditions
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import { SYSTEM } from "./module/config/system.mjs"
|
||||
import { AFFLICTIONS, IMBUEMENTS } from "./module/config/effects.mjs"
|
||||
globalThis.SYSTEM = SYSTEM // Expose the SYSTEM object to the global scope
|
||||
|
||||
// Import modules
|
||||
@@ -52,6 +53,7 @@ Hooks.once("init", function () {
|
||||
CONFIG.Item.dataModels = {
|
||||
skill: models.PrismRPGSkill,
|
||||
"racial-ability": models.PrismRPGRacialAbility,
|
||||
ability: models.PrismRPGAbility,
|
||||
weapon: models.PrismRPGWeapon,
|
||||
armor: models.PrismRPGArmor,
|
||||
shield: models.PrismRPGShield,
|
||||
@@ -70,6 +72,7 @@ Hooks.once("init", function () {
|
||||
foundry.documents.collections.Items.unregisterSheet("core", foundry.appv1.sheets.ActorSheet)
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGSkillSheet, { types: ["skill"], makeDefault: true })
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGRacialAbilitySheet, { types: ["racial-ability"], makeDefault: true })
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGAbilitySheet, { types: ["ability"], makeDefault: true })
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGWeaponSheet, { types: ["weapon"], makeDefault: true })
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGSpellSheet, { types: ["spell"], makeDefault: true })
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGArmorSheet, { types: ["armor"], makeDefault: true })
|
||||
@@ -79,6 +82,13 @@ Hooks.once("init", function () {
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGClassSheet, { types: ["class"], makeDefault: true })
|
||||
foundry.documents.collections.Items.registerSheet("prismRPG", applications.PrismRPGCharacterPathSheet, { types: ["character-path"], makeDefault: true })
|
||||
|
||||
// Status Effects — Afflictions & Imbuements
|
||||
CONFIG.statusEffects = [
|
||||
{ id: "dead", name: "EFFECT.StatusDead", icon: "icons/svg/skull.svg" },
|
||||
...AFFLICTIONS,
|
||||
...IMBUEMENTS,
|
||||
]
|
||||
|
||||
// Other Document Configuration
|
||||
CONFIG.ChatMessage.documentClass = documents.PrismRPGChatMessage
|
||||
|
||||
@@ -196,6 +206,32 @@ Hooks.on(hookName, (message, html, data) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle new round AP/mana restore buttons (GM only)
|
||||
if (typeMessage === "newRound") {
|
||||
$html.find(".new-round-restore-btn").click(async (event) => {
|
||||
const btn = event.currentTarget
|
||||
const actorId = btn.dataset.actorId
|
||||
|
||||
const targets = actorId === "all"
|
||||
? $html.find(".new-round-restore-btn[data-actor-id!='all']").toArray().map(b => game.actors.get(b.dataset.actorId)).filter(Boolean)
|
||||
: [game.actors.get(actorId)].filter(Boolean)
|
||||
|
||||
for (const actor of targets) {
|
||||
await actor.update({
|
||||
"system.actionPoints.value": actor.system.actionPoints.max,
|
||||
"system.manaPoints.value": Math.min(actor.system.manaPoints.value + 1, actor.system.manaPoints.max)
|
||||
})
|
||||
}
|
||||
|
||||
if (actorId === "all") {
|
||||
$html.find(".new-round-restore-btn").prop("disabled", true).addClass("restored")
|
||||
} else {
|
||||
btn.disabled = true
|
||||
btn.classList.add("restored")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Handle Roll Damage button click in weapon attack messages
|
||||
$html.find(".roll-damage-button").click(async (event) => {
|
||||
const btn = event.currentTarget
|
||||
@@ -211,6 +247,45 @@ Hooks.on(hookName, (message, html, data) => {
|
||||
await actor.prepareRoll("weapon-damage-medium", weaponId)
|
||||
})
|
||||
})
|
||||
/**
|
||||
* Send a GM-only chat message with restore buttons at the start of each new round
|
||||
*/
|
||||
Hooks.on("updateCombat", async (combat, change, _options, _userId) => {
|
||||
if (!game.user.isGM) return
|
||||
if (change.round === undefined || change.round <= 1) return
|
||||
|
||||
// Deduplicated character-type actors from the active combat
|
||||
const seen = new Set()
|
||||
const playerActors = combat.combatants.contents
|
||||
.filter(c => c.actor?.type === "character" && !seen.has(c.actor.id) && seen.add(c.actor.id))
|
||||
.map(c => ({ id: c.actor.id, name: c.actor.name, img: c.actor.img }))
|
||||
|
||||
if (playerActors.length === 0) return
|
||||
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
"systems/fvtt-prism-rpg/templates/chat-new-round.hbs",
|
||||
{ actors: playerActors, round: change.round }
|
||||
)
|
||||
await ChatMessage.create({
|
||||
content,
|
||||
whisper: ChatMessage.getWhisperRecipients("GM"),
|
||||
flags: { prismRPG: { typeMessage: "newRound" } }
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Inject a visual separator between Afflictions and Imbuements in the Token HUD status tray
|
||||
*/
|
||||
Hooks.on("renderTokenHUD", (_app, html) => {
|
||||
const tray = html.querySelector(".status-effects")
|
||||
if (!tray) return
|
||||
const firstImb = tray.querySelector("[data-status-id^='imb-']")
|
||||
if (!firstImb) return
|
||||
const sep = document.createElement("div")
|
||||
sep.className = "status-separator"
|
||||
firstImb.before(sep)
|
||||
})
|
||||
|
||||
/**
|
||||
* Create a macro when dropping an entity on the hotbar
|
||||
* Item - open roll dialog
|
||||
|
||||
Reference in New Issue
Block a user