Add travel
This commit is contained in:
parent
fa02c95c41
commit
540319541d
2 changed files with 9 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue