fvtt-imperium5/modules/imperium5-combat.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-03-13 16:17:04 +01:00
import { Imperium5Utility } from "./imperium5pegasus-utility.js";
/* -------------------------------------------- */
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;
}
/* -------------------------------------------- */
_onUpdate(changed, options, userId) {
}
/* -------------------------------------------- */
static async checkTurnPosition() {
while (game.combat.turn > 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
}
}