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) await this.setFlag("world", "abort-action", false)
} }
async holdAction() { async holdAction() {
await this.disableAbortAction()
if (this.getFlag("world", "hold-action")) { if (this.getFlag("world", "hold-action")) {
await this.setFlag("world", "hold-action", false) await this.setFlag("world", "hold-action", false)
//game.combat.holdAction(this.id, false)
game.combat.forceHold(this, false)
return false return false
} else { } else {
await this.setFlag("world", "hold-action", true) await this.setFlag("world", "hold-action", true)
//game.combat.holdAction(this.id, false)
game.combat.forceHold(this, true)
return true return true
} }
} }
@ -406,13 +411,16 @@ export class Hero6Actor extends Actor {
await this.setFlag("world", "abort-action", { state: false, count: 0 }) await this.setFlag("world", "abort-action", { state: false, count: 0 })
} }
async abortAction() { async abortAction() {
await this.disableHoldAction()
let abort = this.getFlag("world", "abort-action") let abort = this.getFlag("world", "abort-action")
if (abort.state) { if (abort.state) {
await this.setFlag("world", "abort-action", { state: false, count: 0 }) 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 { } else {
await this.setFlag("world", "abort-action", { state: true, count: 0 }) 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() { getHoldAction() {
@ -441,10 +449,13 @@ export class Hero6Actor extends Actor {
return __speed2Segments[index].toString() return __speed2Segments[index].toString()
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getBaseInit() { getBaseInit(turn) {
let r = new Roll("1d6").roll({ async: false }) if ( turn != this.turn) {
let base = this.system.characteristics.dex.value + (r.total / 10) let r = new Roll("1d6").roll({ async: false })
return base 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) { holdAction(combatantId) {
const combatant = game.combat.combatants.get(combatantId) this.rebuildInitiative()
console.log("Rebuilding.....")
/*const combatant = game.combat.combatants.get(combatantId)
if (combatant.actor.holdAction()) { if (combatant.actor.holdAction()) {
let id = combatant._id || combatant.id let id = combatant._id || combatant.id
let name = combatant.actor.name + " (H)" let name = combatant.actor.name + " (H)"
await game.combat.updateEmbeddedDocuments("Combatant", [{ _id: id, name: name, holdAction: true }]); await game.combat.updateEmbeddedDocuments("Combatant", [{ _id: id, name: name, holdAction: true }]);
} }*/
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async abortAction(actorId, abortState) { abortAction(actorId, abortState) {
const combatant = game.combat.combatants.find(c => c.actor.id == actorId) this.rebuildInitiative()
/*const combatant = game.combat.combatants.find(c => c.actor.id == actorId)
if (abortState) { if (abortState) {
let id = combatant._id || combatant.id let id = combatant._id || combatant.id
let name = combatant.actor.name + " (A)" let name = combatant.actor.name + " (A)"
await game.combat.updateEmbeddedDocuments("Combatant", [{ _id: id, name: name }]); await game.combat.updateEmbeddedDocuments("Combatant", [{ _id: id, name: name }]);
} }*/
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -82,15 +85,32 @@ export class Hero6Combat extends Combat {
super.startCombat(); 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) { computeInitiative(c, updList) {
let id = c._id || c.id let id = c._id || c.id
let hasSegment = c.actor.hasPhase(this.segmentNumber) let hasSegment = c.actor.hasPhase(this.segmentNumber)
let isOnHold = c.actor.getHoldAction() let isOnHold = c.actor.getHoldAction()
if (hasSegment || isOnHold) { let isOnAbort = c.actor.getAbortAction()
let baseInit = c.actor ? c.actor.getBaseInit() : 0; let name = c.actor.name
let name = c.actor.name if (hasSegment || isOnHold || isOnAbort) {
let baseInit = c.actor ? c.actor.getBaseInit(this.segmentNumber) : 0;
if (isOnHold) { if (isOnHold) {
if (hasSegment) { // On hold + current segment -> auto-disable on hold if (hasSegment) { // On hold + current segment -> auto-disable on hold
c.actor.disableHoldAction() c.actor.disableHoldAction()
@ -98,9 +118,11 @@ export class Hero6Combat extends Combat {
name = c.actor.name + " (H)" name = c.actor.name + " (H)"
} }
} }
if (c.actor.getAbortAction()) { if (isOnAbort) {
name = c.actor.name + " (A)" name = c.actor.name + " (A)"
c.actor.disableAbortAction() if ( hasSegment) {
c.actor.disableAbortAction()
}
} }
updList.push({ _id: id, name: name, initiative: baseInit, holdAction: c.holdAction }) updList.push({ _id: id, name: name, initiative: baseInit, holdAction: c.holdAction })
} else { } else {
@ -112,7 +134,6 @@ export class Hero6Combat extends Combat {
async rollInitiative(ids, formula = undefined, messageOptions = {}) { async rollInitiative(ids, formula = undefined, messageOptions = {}) {
ids = typeof ids === "string" ? [ids] : ids; ids = typeof ids === "string" ? [ids] : ids;
console.log("Roll INIT")
let updList = [] let updList = []
for (let cId = 0; cId < ids.length; cId++) { for (let cId = 0; cId < ids.length; cId++) {
const c = this.combatants.get(ids[cId]) const c = this.combatants.get(ids[cId])
@ -197,12 +218,14 @@ export class Hero6Combat extends Combat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onCreateEmbeddedDocuments(type, documents, result, options, userId) { 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) { _onUpdate(changed, options, userId) {
} }*/
/* -------------------------------------------- */ /* -------------------------------------------- */
static async checkTurnPosition() { static async checkTurnPosition() {

View File

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