Add travel
This commit is contained in:
parent
eea6031423
commit
1c0a2124f0
2 changed files with 28 additions and 7 deletions
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue