Add travel

This commit is contained in:
Aslan 2026-01-21 15:45:41 -05:00
parent eea6031423
commit 1c0a2124f0
2 changed files with 28 additions and 7 deletions

View file

@ -51,6 +51,16 @@ const hasLocation = (
return childLocations.includes(locationChild);
};
const getTravelTimeInHours = (
player: IPlayer,
locationA: ILocation,
locationB: ILocation,
) => {
const distance = getLocationDistance(locationA, locationB);
return (distance / getSpeed(player)) * 3600000;
};
const startTravel = (
player: IPlayer,
location: Location,
@ -60,13 +70,11 @@ const startTravel = (
const currentLocation = getLocation(player.location);
const newLocation = getLocation(location);
const distance = getLocationDistance(currentLocation, newLocation);
setTimeout(
() => {
finishTravel(player, newLocation, client, roomId);
},
(distance / getSpeed(player)) * 3600000,
getTravelTimeInHours(player, currentLocation, newLocation),
);
};
@ -90,6 +98,7 @@ export {
getLocationDistance,
getParentLocation,
hasLocation,
getTravelTimeInHours,
startTravel,
finishTravel,
};