fvtt-dark-stars/modules/dark-stars-combat.js

48 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2022-11-27 08:58:19 +01:00
import { DarkStarsUtility } from "./dark-stars-utility.js";
/* -------------------------------------------- */
export class DarkStarsCombat extends Combat {
2023-10-21 10:25:39 +02:00
/* -------------------------------------------- */
processOtherTurns(c, initScore) {
let toCreate = []
let token = canvas.tokens.get(c.tokenId)
let hasLastWord = token.actor.hasLastWord()
while ( (initScore > 5) || (hasLastWord && initScore >= 5)) {
initScore -= 5;
2023-10-21 14:16:06 +02:00
toCreate.push({tokenId: c.tokenId, sceneId: c.sceneId, actorId: c.actorId, hidden: c.hidden, initiative: initScore, flags: { world: { isDuplicated: true} } } );
2023-10-21 10:25:39 +02:00
}
this.createEmbeddedDocuments("Combatant", toCreate);
}
2022-11-27 08:58:19 +01:00
/* -------------------------------------------- */
2023-10-21 10:25:39 +02:00
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
2022-11-27 08:58:19 +01:00
ids = typeof ids === "string" ? [ids] : ids;
2023-10-21 10:25:39 +02:00
for (let cId of ids) {
const c = this.combatants.get(cId);
2022-11-27 08:58:19 +01:00
let id = c._id || c.id;
2023-10-21 10:25:39 +02:00
let initScore = c.actor ? c.actor.getInitiativeScore(this.id, id) : -1;
await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: initScore }]);
setTimeout(() => this.processOtherTurns(c, initScore), 400)
2022-11-27 08:58:19 +01:00
}
return this;
}
2023-10-21 14:16:06 +02:00
/* -------------------------------------------- */
nextRound() {
super.nextRound()
let toDelete = []
for (let c of this.combatants) {
if (c.flags?.world?.isDuplicated) {
toDelete.push(c._id)
}
}
this.deleteEmbeddedDocuments("Combatant", toDelete);
}
2022-11-27 08:58:19 +01:00
/* -------------------------------------------- */
_onUpdate(changed, options, userId) {
}
}