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 { config } from "../../config.js";
|
||||||
import { getPlayerById, getRace } from "../../services/game/entity.js";
|
import { getPlayerById, getRace } from "../../services/game/entity.js";
|
||||||
import {
|
import {
|
||||||
|
existsLocation,
|
||||||
getLocation,
|
getLocation,
|
||||||
getLocationByName,
|
getLocationByName,
|
||||||
getLocationDistance,
|
getLocationDistance,
|
||||||
|
|
@ -211,12 +212,13 @@ const onTravel = (text: string, roomId: string, sender: string) => {
|
||||||
const player = getPlayerById(sender);
|
const player = getPlayerById(sender);
|
||||||
|
|
||||||
const locationName = text.replace(`${gamePrefix} travel `, "").trim();
|
const locationName = text.replace(`${gamePrefix} travel `, "").trim();
|
||||||
const travelLocation = getLocationByName(locationName);
|
if (!existsLocation(locationName)) {
|
||||||
if (!travelLocation) {
|
|
||||||
client.sendTextMessage(roomId, "No such location exists");
|
client.sendTextMessage(roomId, "No such location exists");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const travelLocation = getLocationByName(locationName);
|
||||||
|
|
||||||
const currentLocationHasLocation = hasLocation(
|
const currentLocationHasLocation = hasLocation(
|
||||||
player.location,
|
player.location,
|
||||||
travelLocation.id,
|
travelLocation.id,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ import {
|
||||||
import type { IPlayer } from "./structures/entities.js";
|
import type { IPlayer } from "./structures/entities.js";
|
||||||
import { getSpeed } from "./entity.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 getLocation = (id: Location): ILocation => {
|
||||||
const location = locations.find((location) => location.id === id);
|
const location = locations.find((location) => location.id === id);
|
||||||
|
|
||||||
|
|
@ -93,6 +97,7 @@ const finishTravel = (
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
existsLocation,
|
||||||
getLocation,
|
getLocation,
|
||||||
getLocationByName,
|
getLocationByName,
|
||||||
getLocationDistance,
|
getLocationDistance,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue