Combat tracker enhancements
This commit is contained in:
@@ -10,6 +10,23 @@ export class PegasusCombatTracker extends CombatTracker {
|
||||
template: path,
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getData() {
|
||||
let combatData = await super.getData()
|
||||
for (let t of combatData.turns) {
|
||||
let c = game.combat.combatants.get(t.id)
|
||||
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)
|
||||
@@ -23,6 +40,11 @@ export class PegasusCombatTracker extends CombatTracker {
|
||||
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)
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,11 +68,11 @@ export class PegasusCombat extends Combat {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async resetNPCInitiative() {
|
||||
for(let c of this.combatants) {
|
||||
for (let c of this.combatants) {
|
||||
if (c.actor && c.actor.type == "npc") {
|
||||
await this.updateEmbeddedDocuments("Combatant", [{ _id: c.id, initiative: -1 }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -62,6 +84,21 @@ export class PegasusCombat extends Combat {
|
||||
return false
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
selectActor(combatantId) {
|
||||
const combatant = game.combat.combatants.get(combatantId)
|
||||
if (combatant) {
|
||||
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: `<div>${combatant.actor.name} has been nominated to act, ${combatant.actor.name} choose which TIC you wish to activate!</div`
|
||||
}
|
||||
ChatMessage.create(chatData);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async setTic(combatantId, rollData) {
|
||||
if (!combatantId) {
|
||||
@@ -69,65 +106,74 @@ export class PegasusCombat extends Combat {
|
||||
}
|
||||
const combatant = game.combat.combatants.get(combatantId)
|
||||
if (combatant) {
|
||||
await combatant.setFlag("world", "tic1", { revealed: false, text: rollData.tic1, displayed: false })
|
||||
await combatant.setFlag("world", "tic2", { revealed: false, text: rollData.tic2, displayed: false })
|
||||
await combatant.setFlag("world", "TICs", rollData.TICs)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getTIC(num, combatantId) {
|
||||
if (!combatantId) {
|
||||
return ""
|
||||
}
|
||||
const combatant = game.combat.combatants.get(combatantId)
|
||||
if (combatant) {
|
||||
let ticData = combatant.getFlag("world", "tic" + num)
|
||||
if (ticData) {
|
||||
/* returns if revealed */
|
||||
if (ticData.revealed && ticData.displayed) {
|
||||
return "ACTED"
|
||||
}
|
||||
if (ticData.revealed && !ticData.displayed) {
|
||||
ticData.displayed = true
|
||||
combatant.setFlag("world", "tic" + num, ticData ).then(() => {
|
||||
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: `<div>${combatant.actor.name} is performing ${ticData.text}</div`
|
||||
};
|
||||
ChatMessage.create(chatData);
|
||||
return "ACTED"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return "TIC " + num
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async revealTIC(num, combatantId) {
|
||||
if (!num || !combatantId) {
|
||||
console.log('revealTIC', num, combatantId)
|
||||
if (num == undefined || combatantId == undefined) {
|
||||
return
|
||||
}
|
||||
const combatant = game.combat.combatants.get(combatantId)
|
||||
if (combatant) {
|
||||
let ticData = combatant.getFlag("world", "tic" + num)
|
||||
console.log('revealTIC', num, combatantId, combatant)
|
||||
let ticData = combatant.getFlag("world", "TICs")
|
||||
if (ticData) {
|
||||
ticData.revealed = true
|
||||
await combatant.setFlag("world", "tic" + num, ticData)
|
||||
console.log('revealTIC', num, combatantId, ticData)
|
||||
num = Number(num)
|
||||
ticData[num].revealed = true
|
||||
ticData[num].displayed = true
|
||||
combatant.setFlag("world", "TICs", ticData).then(() => {
|
||||
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: `<div>${combatant.actor.name} is performing ${ticData[num].text}</div`
|
||||
};
|
||||
ChatMessage.create(chatData);
|
||||
// Manage if all TIC has been ACTED
|
||||
let allRevealed = true
|
||||
for (let c of this.combatants) {
|
||||
let TICs = c.getFlag("world", "TICs")
|
||||
if (TICs) {
|
||||
for (let t of TICs) {
|
||||
if (!t.revealed) {
|
||||
allRevealed = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If all TIC has been ACTED, display a message
|
||||
if (allRevealed) {
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
content: `<div>All Characters have acted, All Characters who do not have Stun gain 1 Momentum!</div`
|
||||
}
|
||||
ChatMessage.create(chatData);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
nextRound() {
|
||||
for(let c of this.combatants) {
|
||||
c.setFlag("world", "tic1", { revealed: false, text: "", displayed: false })
|
||||
c.setFlag("world", "tic2", { revealed: false, text: "", displayed: false })
|
||||
for (let c of this.combatants) {
|
||||
let TICs = duplicate(c.getFlag("world", "TICs"))
|
||||
for (let t of TICs) {
|
||||
t.displayed = false
|
||||
t.revealed = false
|
||||
t.text = ""
|
||||
}
|
||||
c.setFlag("world", "TICs", TICs)
|
||||
}
|
||||
super.nextRound()
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_onUpdate(changed, options, userId) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user