bol/module/system/bol-combat.js

85 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2022-01-16 22:53:41 +01:00
/*
Init order =
10 - Legendary
9 - Heroic
8 - Success
7 - Rivals/adversary
6 - Coriaces/tough
5 - Failure
4 - Pietaille
3 - Echec critique
*/
2021-12-29 19:15:06 +01:00
2022-11-30 20:58:27 +01:00
import { BoLUtility } from "../system/bol-utility.js";
2022-01-16 22:53:41 +01:00
export class BoLCombatManager extends Combat {
2021-12-29 19:15:06 +01:00
/************************************************************************************/
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
2022-09-09 23:49:01 +02:00
console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions);
2021-12-29 19:15:06 +01:00
// Structure input data
ids = typeof ids === "string" ? [ids] : ids;
2023-05-01 18:50:32 +02:00
// Get initiative malus from tough/adversary
let malusInit = 0
for (let combatant of this.combatants) {
malusInit = Math.max(malusInit, combatant.actor.getInitiativeMalus())
}
2021-12-29 19:15:06 +01:00
// calculate initiative
2023-05-01 18:50:32 +02:00
for (let cId = 0; cId < ids.length; cId++) {
2022-11-30 20:58:27 +01:00
const combatant = this.combatants.get(ids[cId])
2023-05-01 18:50:32 +02:00
let fvttInit = combatant.actor.getInitiativeRank(false, true, { combatId: this.id, combatantId: combatant.id, malusInit })
2022-01-16 22:58:28 +01:00
fvttInit += (cId / 100)
2022-01-16 22:53:41 +01:00
await this.updateEmbeddedDocuments("Combatant", [{ _id: ids[cId], initiative: fvttInit }]);
2021-12-29 19:15:06 +01:00
}
}
2022-03-10 21:05:53 +01:00
/************************************************************************************/
nextRound() {
2023-04-29 21:48:51 +02:00
if (game.user.isGM) {
let combatants = this.combatants.contents
let autoRemoveDead = game.settings.get("bol", "auto-remove-dead") // Optionnal auto-removal of dead char.
for (let c of combatants) {
//let actor = game.actors.get(c.actorId)
c.actor.clearRoundModifiers()
let toRemove = []
if (autoRemoveDead && c.actor.type == "encounter" && (c.actor.system.chartype == "tough" || c.actor.system.chartype == "creature" || c.actor.system.chartype == "base") && c.actor.system.resources.hp.value <= 0) {
toRemove.push(c.id || c._id)
}
//console.log("REM", autoRemoveDead, toRemove, c.actor)
if (toRemove.length > 0) {
this.deleteEmbeddedDocuments('Combatant', toRemove)
}
2023-04-06 20:15:04 +02:00
}
2022-03-10 21:05:53 +01:00
}
super.nextRound()
}
2023-03-18 10:24:30 +01:00
/************************************************************************************/
startCombat() {
2023-04-29 21:48:51 +02:00
if (game.user.isGM) {
let combatants = this.combatants.contents
for (let c of combatants) {
let actor = game.actors.get(c.actorId)
actor.storeVitaliteCombat()
}
2023-03-18 10:24:30 +01:00
}
return super.startCombat()
}
2023-04-06 20:15:04 +02:00
2023-05-01 18:50:32 +02:00
/*-***********************************************************************************/
2022-12-23 16:38:41 +01:00
_onDelete() {
2023-04-29 21:48:51 +02:00
if (game.user.isGM) {
let combatants = this.combatants.contents
for (let c of combatants) {
let actor = game.actors.get(c.actorId)
actor.clearInitiative()
actor.displayRecuperation()
}
2022-12-23 16:38:41 +01:00
}
super._onDelete()
}
2022-03-10 21:05:53 +01:00
2022-01-16 22:53:41 +01:00
}
2023-04-06 20:15:04 +02:00