Combat tracker fixes

This commit is contained in:
LeRatierBretonnien 2023-07-16 14:33:26 +02:00
parent 6d6b7075df
commit 9099e812d5
3 changed files with 58 additions and 25 deletions

View File

@ -391,11 +391,16 @@ export class Hero6Actor extends Actor {
await this.setFlag("world", "abort-action", false)
}
async holdAction() {
await this.disableAbortAction()
if (this.getFlag("world", "hold-action")) {
await this.setFlag("world", "hold-action", false)
//game.combat.holdAction(this.id, false)
game.combat.forceHold(this, false)
return false
} else {
await this.setFlag("world", "hold-action", true)
//game.combat.holdAction(this.id, false)
game.combat.forceHold(this, true)
return true
}
}
@ -406,13 +411,16 @@ export class Hero6Actor extends Actor {
await this.setFlag("world", "abort-action", { state: false, count: 0 })
}
async abortAction() {
await this.disableHoldAction()
let abort = this.getFlag("world", "abort-action")
if (abort.state) {
await this.setFlag("world", "abort-action", { state: false, count: 0 })
game.combat.abortAction(this.id, false)
game.combat.forceAbort(this, false)
//game.combat.abortAction(this.id, false)
} else {
await this.setFlag("world", "abort-action", { state: true, count: 0 })
game.combat.abortAction(this.id, true)
game.combat.forceAbort(this, true)
//game.combat.abortAction(this.id, true)
}
}
getHoldAction() {
@ -441,10 +449,13 @@ export class Hero6Actor extends Actor {
return __speed2Segments[index].toString()
}
/* -------------------------------------------- */
getBaseInit() {
let r = new Roll("1d6").roll({ async: false })
let base = this.system.characteristics.dex.value + (r.total / 10)
return base
getBaseInit(turn) {
if ( turn != this.turn) {
let r = new Roll("1d6").roll({ async: false })
this.currentInit = this.system.characteristics.dex.value + (r.total / 10)
this.turn = turn
}
return this.currentInit
}
/* -------------------------------------------- */

View File

@ -40,23 +40,26 @@ export class Hero6Combat extends Combat {
}
/* -------------------------------------------- */
static async holdAction(combatantId) {
const combatant = game.combat.combatants.get(combatantId)
holdAction(combatantId) {
this.rebuildInitiative()
console.log("Rebuilding.....")
/*const combatant = game.combat.combatants.get(combatantId)
if (combatant.actor.holdAction()) {
let id = combatant._id || combatant.id
let name = combatant.actor.name + " (H)"
await game.combat.updateEmbeddedDocuments("Combatant", [{ _id: id, name: name, holdAction: true }]);
}
}*/
}
/* -------------------------------------------- */
static async abortAction(actorId, abortState) {
const combatant = game.combat.combatants.find(c => c.actor.id == actorId)
abortAction(actorId, abortState) {
this.rebuildInitiative()
/*const combatant = game.combat.combatants.find(c => c.actor.id == actorId)
if (abortState) {
let id = combatant._id || combatant.id
let name = combatant.actor.name + " (A)"
await game.combat.updateEmbeddedDocuments("Combatant", [{ _id: id, name: name }]);
}
}*/
}
/* -------------------------------------------- */
@ -82,15 +85,32 @@ export class Hero6Combat extends Combat {
super.startCombat();
}
/* -------------------------------------------- */
forceHold(actor, isHold) {
let updList = []
let c = this.combatants.find(c => c.actor._id == actor.id)
let name = actor.name + ((isHold) ? " (H)" : "")
updList.push({ _id: c.id || c._id, name: name, initiative: actor.getBaseInit(this.segmentNumber) })
this.updateEmbeddedDocuments("Combatant", updList)
}
/* -------------------------------------------- */
forceAbort(actor, isAbort) {
let updList = []
let c = this.combatants.find(c => c.actor._id == actor.id)
let name = actor.name + ((isAbort) ? " (A)" : "")
updList.push({ _id: c.id || c._id, name: name, initiative: actor.getBaseInit(this.segmentNumber) })
this.updateEmbeddedDocuments("Combatant", updList)
}
/* -------------------------------------------- */
computeInitiative(c, updList) {
let id = c._id || c.id
let hasSegment = c.actor.hasPhase(this.segmentNumber)
let isOnHold = c.actor.getHoldAction()
if (hasSegment || isOnHold) {
let baseInit = c.actor ? c.actor.getBaseInit() : 0;
let name = c.actor.name
let isOnAbort = c.actor.getAbortAction()
let name = c.actor.name
if (hasSegment || isOnHold || isOnAbort) {
let baseInit = c.actor ? c.actor.getBaseInit(this.segmentNumber) : 0;
if (isOnHold) {
if (hasSegment) { // On hold + current segment -> auto-disable on hold
c.actor.disableHoldAction()
@ -98,9 +118,11 @@ export class Hero6Combat extends Combat {
name = c.actor.name + " (H)"
}
}
if (c.actor.getAbortAction()) {
if (isOnAbort) {
name = c.actor.name + " (A)"
c.actor.disableAbortAction()
if ( hasSegment) {
c.actor.disableAbortAction()
}
}
updList.push({ _id: id, name: name, initiative: baseInit, holdAction: c.holdAction })
} else {
@ -112,7 +134,6 @@ export class Hero6Combat extends Combat {
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
ids = typeof ids === "string" ? [ids] : ids;
console.log("Roll INIT")
let updList = []
for (let cId = 0; cId < ids.length; cId++) {
const c = this.combatants.get(ids[cId])
@ -197,12 +218,14 @@ export class Hero6Combat extends Combat {
/* -------------------------------------------- */
async _onCreateEmbeddedDocuments(type, documents, result, options, userId) {
super._onCreateEmbeddedDocuments(type, documents, result, options, userId)
//console.log("Added...")
await super._onCreateEmbeddedDocuments(type, documents, result, options, userId)
await this.rebuildInitiative()
}
/* -------------------------------------------- */
/* --------------------------------------------
_onUpdate(changed, options, userId) {
}
}*/
/* -------------------------------------------- */
static async checkTurnPosition() {

View File

@ -91,15 +91,14 @@
"styles": [
"styles/simple.css"
],
"version": "10.0.46",
"version": "10.0.47",
"compatibility": {
"minimum": "10",
"verified": "10",
"maximum": "11"
"verified": "11"
},
"title": "Hero System v6 for FoundrtVTT (Official)",
"manifest": "https://www.uberwald.me/gitea/uberwald/fvtt-hero-system-6/raw/branch/main/system.json",
"download": "https://www.uberwald.me/gitea/uberwald/fvtt-hero-system-6/archive/fvtt-hero-system-6-v10.0.46.zip",
"download": "https://www.uberwald.me/gitea/uberwald/fvtt-hero-system-6/archive/fvtt-hero-system-6-v10.0.47.zip",
"url": "https://www.uberwald.me/gitea/uberwald/",
"background": "images/ui/hero6_welcome_page.webp",
"id": "fvtt-hero-system-6"