import { PegasusUtility } from "./pegasus-utility.js"; /* -------------------------------------------- */ export class PegasusCombatTracker extends CombatTracker { /* -------------------------------------------- */ static get defaultOptions() { let path = "systems/fvtt-pegasus-rpg/templates/pegasus-combat-tracker.html"; return foundry.utils.mergeObject(super.defaultOptions, { template: path, }); } /* -------------------------------------------- */ async getData() { let combatData = await super.getData() for (let t of combatData.turns) { let c = game.combat.combatants.get(t.id) t.displayTIC = (c.actor.isOwner && c.actor.hasPlayerOwner && !game.user.isGM) || (c.actor.type == "npc" && !c.actor.hasPlayerOwner && game.user.isGM) let TICs = c.getFlag("world", "TICs") if (TICs) { t.TICs = TICs } else { t.TICs = [] } } //console.log("CBT", combatData) return combatData } /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html) html.find('.combat-tracker-tic').click(ev => { let ticNum = $(ev.currentTarget).data("tic-num") let combatantId = $(ev.currentTarget).data("combatant-id") game.combat.revealTIC(ticNum, combatantId) }) html.find('.reset-npc-initiative').click(ev => { game.combat.resetNPCInitiative() }) html.find('.select-combat-actor').click(ev => { let combatantId = $(ev.currentTarget).data("combatant-id") game.combat.selectActor(combatantId) }) } } /* -------------------------------------------- */ export class PegasusCombat extends Combat { /* -------------------------------------------- */ async rollInitiative(ids, formula = undefined, messageOptions = {}) { ids = typeof ids === "string" ? [ids] : ids; for (let cId = 0; cId < ids.length; cId++) { const c = this.combatants.get(ids[cId]); let id = c._id || c.id; let initBonus = c.actor ? c.actor.getInitiativeScore(this.id, id) : -1; await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: initBonus }]); } return this; } /* -------------------------------------------- */ async resetNPCInitiative() { for (let c of this.combatants) { if (c.actor && c.actor.type == "npc") { await this.updateEmbeddedDocuments("Combatant", [{ _id: c.id, initiative: -1 }]); } } } /* -------------------------------------------- */ isCharacter(combatantId) { const combatant = game.combat.combatants.get(combatantId) if (combatant) { return combatant.actor.type == "character" } return false } /* -------------------------------------------- */ selectActor(combatantId) { const combatant = game.combat.combatants.get(combatantId) if (combatant) { let TICs = combatant.getFlag("world", "TICs") || [] let allRevealed = true for(let tic of TICs) { if (!tic.revealed ) { allRevealed = false } } let msg = `
${combatant.actor.name} has been nominated to act, ${combatant.actor.name} choose which TIC you wish to activate!${combatant.actor.name} has used all its TIC's please choose a different character.${combatant.actor.name} : This Action has already been performed please choose a different TIC { let chatData = { user: game.user.id, alias: combatant.actor.name, rollMode: game.settings.get("core", "rollMode"), whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')), content: `
${combatant.actor.name} is performing ${ticData[num].text}All Characters have acted, All Characters who do not have Stun gain 1 Momentum! 0) { await game.combat.previousTurn() } } /* -------------------------------------------- */ static async decInitBy10(combatantId, value) { const combatant = game.combat.combatants.get(combatantId) let initValue = combatant.initiative + value await game.combat.setInitiative(combatantId, initValue) setTimeout(this.checkTurnPosition, 400) // The setInitiative is no more blocking for unknown reason } }