bol/module/system/bol-combat.js

66 lines
1.8 KiB
JavaScript
Raw 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-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 = {}) {
console.log(`${game.data.system.data.title} | Combat.rollInitiative()`, ids, formula, messageOptions);
// Structure input data
ids = typeof ids === "string" ? [ids] : ids;
const currentId = this.combatant._id;
2022-01-16 22:53:41 +01:00
2021-12-29 19:15:06 +01:00
// calculate initiative
2022-01-16 22:53:41 +01:00
for (let cId = 0; cId < ids.length; cId++) {
const combatant = this.combatants.get(ids[cId]);
let fvttInit = 5
if (combatant.actor.type == 'character') {
2022-02-20 10:12:25 +01:00
let initData = combatant.actor.getLastInitData()
console.log("Init data !!!", initData)
2022-01-16 22:53:41 +01:00
if (initData.isLegendary) {
fvttInit = 10
} else if (initData.isCritical) {
fvttInit = 9
} else if (initData.lastinit >= 9) {
fvttInit = 8
} else if (initData.isFumble) {
fvttInit = 3
}
} else {
fvttInit = 4 // Pietaille par defaut
if ( combatant.actor.getSubtype == 'adversary') {
fvttInit = 7
}
if ( combatant.actor.getSubtype == 'tough') {
fvttInit = 6
}
2021-12-29 19:15:06 +01:00
}
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() {
let combatants = this.combatants.contents
for (let c of combatants) {
let actor = game.actors.get( c.data.actorId )
2022-03-10 21:39:12 +01:00
actor.clearRoundModifiers()
2022-03-10 21:05:53 +01:00
}
super.nextRound()
}
2022-01-16 22:53:41 +01:00
}
2021-12-29 19:15:06 +01:00