Add entity info

This commit is contained in:
Aslan 2026-01-23 08:47:15 -05:00
parent 0958a8c272
commit 58df618956
4 changed files with 250 additions and 39 deletions

View file

@ -5,7 +5,7 @@ import {
locations,
type ILocation,
} from "./structures/locations.js";
import type { IPlayer } from "./structures/entities.js";
import type { IEntity, IPlayer } from "./structures/entities.js";
import { getSpeed } from "./entity.js";
const existsLocation = (name: string): boolean => {
@ -34,8 +34,24 @@ const getLocationDistance = (
locationA: ILocation,
locationB: ILocation,
): number => {
const deltaX = Math.abs(locationA.X - locationB.X);
const deltaY = Math.abs(locationA.Y - locationB.Y);
const parentOfA = getParentLocation(locationA.id);
const parentOfB = getParentLocation(locationB.id);
let locAX = locationA.X;
let locAY = locationA.Y;
let locBX = locationB.X;
let locBY = locationB.Y;
if (locationA.id === parentOfB.id) {
locBX += locAX;
locBY += locAY;
} else if (locationB.id === parentOfA.id) {
locAX += locBX;
locAY += locBY;
}
const deltaX = Math.abs(locAX - locBX);
const deltaY = Math.abs(locAY - locBY);
const deltaPow = Math.pow(deltaX, 2) + Math.pow(deltaY, 2);
@ -59,6 +75,13 @@ const hasLocation = (
return childLocations.includes(locationChild);
};
const entitiesShareLocation = (entityA: IEntity, entityB: IEntity): boolean => {
const locationA = getLocation(entityA.location);
const locationB = getLocation(entityB.location);
return locationA.id === locationB.id;
};
const getTravelTimeInHours = (
player: IPlayer,
locationA: ILocation,
@ -115,6 +138,7 @@ export {
getLocationDistance,
getParentLocation,
hasLocation,
entitiesShareLocation,
getTravelTimeInHours,
getTravelTimeInMilliseconds,
startTravel,