Get most of the custom Initiative sorting stuff through the door

This commit is contained in:
Oliver-Akins 2025-02-14 00:04:48 -07:00
parent ed93e9f927
commit e302b56a4e
10 changed files with 142 additions and 14 deletions

View file

@ -6,6 +6,24 @@ Resources:
*/
export class RipCryptCombat extends Combat {
get groups() {
let groups = new Map();
for (const combatant of this.combatants) {
const groupKey = combatant.groupKey;
if (!groupKey) { continue };
if (groups.has(groupKey)) {
groups.get(groupKey).push(combatant);
} else {
groups.set(groupKey, [combatant]);
};
};
return groups;
};
/**
* @override
* Sorts combatants for the combat tracker in the following way:
@ -14,13 +32,14 @@ export class RipCryptCombat extends Combat {
*/
_sortCombatants(a, b) {
// The distance from fate
return super._sortCombatants(a, b) * -1;
};
nextTurn() {
// Make it skip all combatants with the same initiative value
};
// nextTurn() {
// // Make it skip all combatants with the same initiative value
// };
previousTurn() {
// Go back a step
};
// previousTurn() {
// // Go back a step
// };
};

View file

@ -0,0 +1,37 @@
import { distanceBetweenFates } from "../utils/distanceBetweenFates.mjs";
export class RipCryptCombatant extends Combatant {
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) { return false };
const start = game.settings.get(`ripcrypt`, `currentFate`);
const end = this.actor?.system?.fate || this.baseActor?.system?.fate;
const fateDistance = distanceBetweenFates(start, end);
this.updateSource({
initiative: fateDistance,
});
};
get groupKey() {
const path = this.token?.actor?.system?.fate;
// Disallow grouping things that don't have a fate path
if (!path) { return null };
// Token Disposition (group into: friendlies, unknown, hostiles)
let disposition = `unknown`;
switch (this.token.disposition) {
case CONST.TOKEN_DISPOSITIONS.HOSTILE:
disposition = `hostile`;
break;
case CONST.TOKEN_DISPOSITIONS.FRIENDLY:
disposition = `friendly`;
break;
};
return `${path}:${disposition}`;
};
};