diff --git a/src/modules/game/game.ts b/src/modules/game/game.ts index c753374..371dd8f 100644 --- a/src/modules/game/game.ts +++ b/src/modules/game/game.ts @@ -3,6 +3,7 @@ import type { ICallbackStore } from "../types.js"; import { config } from "../../config.js"; import { getPlayerById, getRace } from "../../services/game/entity.js"; import { + existsLocation, getLocation, getLocationByName, getLocationDistance, @@ -211,12 +212,13 @@ const onTravel = (text: string, roomId: string, sender: string) => { const player = getPlayerById(sender); const locationName = text.replace(`${gamePrefix} travel `, "").trim(); - const travelLocation = getLocationByName(locationName); - if (!travelLocation) { + if (!existsLocation(locationName)) { client.sendTextMessage(roomId, "No such location exists"); return; } + const travelLocation = getLocationByName(locationName); + const currentLocationHasLocation = hasLocation( player.location, travelLocation.id, diff --git a/src/services/game/location.ts b/src/services/game/location.ts index 0e734e1..c6051ac 100644 --- a/src/services/game/location.ts +++ b/src/services/game/location.ts @@ -8,6 +8,10 @@ import { import type { IPlayer } from "./structures/entities.js"; import { getSpeed } from "./entity.js"; +const existsLocation = (name: string): boolean => { + return locations.find((location) => location.name === name) !== undefined; +}; + const getLocation = (id: Location): ILocation => { const location = locations.find((location) => location.id === id); @@ -93,6 +97,7 @@ const finishTravel = ( }; export { + existsLocation, getLocation, getLocationByName, getLocationDistance,