Get the delve tour incrementer changes working and affecting fate as well
This commit is contained in:
parent
7639962130
commit
110823a26b
9 changed files with 174 additions and 14 deletions
51
module/utils/fates.mjs
Normal file
51
module/utils/fates.mjs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { gameTerms } from "../gameTerms.mjs";
|
||||
import { Logger } from "./Logger.mjs";
|
||||
|
||||
const { FatePath } = gameTerms;
|
||||
|
||||
export function isOppositeFates(a, b) {
|
||||
return (a === FatePath.NORTH && b === FatePath.SOUTH)
|
||||
|| (a === FatePath.EAST && b === FatePath.WEST);
|
||||
};
|
||||
|
||||
export function distanceBetweenFates(start, end) {
|
||||
if (!start || !end) {
|
||||
Logger.error(`Start and End must both have a defined value, given`, {start, end});
|
||||
return undefined;
|
||||
};
|
||||
|
||||
if (start === end) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
if (isOppositeFates(start, end) || isOppositeFates(end, start)) {
|
||||
return 2;
|
||||
};
|
||||
|
||||
let isForward = start === FatePath.SOUTH && end === FatePath.WEST;
|
||||
isForward ||= start === FatePath.NORTH && end === FatePath.EAST;
|
||||
isForward ||= start === FatePath.WEST && end === FatePath.NORTH;
|
||||
isForward ||= start === FatePath.EAST && end === FatePath.SOUTH;
|
||||
if (isForward) {
|
||||
return 1;
|
||||
};
|
||||
return 3;
|
||||
};
|
||||
|
||||
const fateOrder = [
|
||||
FatePath.WEST, // to make the .find not integer overflow
|
||||
FatePath.NORTH,
|
||||
FatePath.EAST,
|
||||
FatePath.SOUTH,
|
||||
FatePath.WEST,
|
||||
];
|
||||
|
||||
export function nextFate(fate) {
|
||||
const fateIndex = fateOrder.findIndex(f => f === fate);
|
||||
return fateOrder[fateIndex + 1];
|
||||
};
|
||||
|
||||
export function previousFate(fate) {
|
||||
const fateIndex = fateOrder.lastIndexOf(fate);
|
||||
return fateOrder[fateIndex - 1];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue