diff --git a/src/helpers.ts b/src/helpers.ts
index 1fee0c4..88a8c52 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -69,15 +69,7 @@ const getLevel = (experience: number): ILevel => {
};
const getUserName = (user: IUser): string => {
- const userPattern = /@[a-zA-Z0-9]*/;
- const match = user.id.match(userPattern)?.at(0);
- if (!match) {
- return "";
- }
-
- let username = match.replaceAll("@", "");
- username = username.charAt(0).toUpperCase() + username.slice(1);
- return username;
+ return getUserNameById(user.id);
};
const getUserNameById = (userId: string): string => {
diff --git a/src/modules/game/game.ts b/src/modules/game/game.ts
index 31eb125..2a10536 100644
--- a/src/modules/game/game.ts
+++ b/src/modules/game/game.ts
@@ -32,6 +32,7 @@ import {
type IStat,
type Location,
} from "../../services/game/index.js";
+import { getUserNameById } from "../../helpers.js";
let client: MatrixClient;
const gamePrefix = `${config.app.triggerPrefix}game`;
@@ -66,6 +67,10 @@ const registerModuleGame = (
startConditions: [`${gamePrefix} travel `],
callbackFunc: onTravel,
});
+ callbackStore.messageCallbacks.push({
+ startConditions: [`${gamePrefix} leave`],
+ callbackFunc: onLeave,
+ });
callbackStore.messageCallbacks.push({
startConditions: [`${gamePrefix} entities`],
callbackFunc: onEntities,
@@ -88,6 +93,7 @@ const onHelp = (_text: string, roomId: string) => {
!game location - Shows information about your current location
!game nearby - Shows nearby locations
!game travel {location} - Travel to a location
+ !game leave - Leave your current location
!game entities - Shows entities at your location
!game entity {entity} - Shows information about an entity
(WIP) !game talk {entity} - Talk to an entity
@@ -98,7 +104,11 @@ const onHelp = (_text: string, roomId: string) => {
};
const onStatus = (_text: string, roomId: string, sender: string) => {
- const entity = getEntityByName(sender);
+ onStatusName(roomId, getUserNameById(sender));
+};
+
+const onStatusName = (roomId: string, name: string) => {
+ const entity = getEntityByName(name);
const race = getRace(entity.race);
const location = getLocation(entity.location);
@@ -275,6 +285,24 @@ const onTravel = (text: string, roomId: string, sender: string) => {
startTravel(player, travelLocation.id, client, roomId);
};
+const onLeave = (_text: string, roomId: string, sender: string) => {
+ const player = getPlayer(sender);
+ const parentLocation = getParentLocation(player.location);
+
+ const travelTime = getTravelTimeInHours(
+ player,
+ getLocation(player.location),
+ parentLocation,
+ );
+
+ client.sendTextMessage(
+ roomId,
+ `You're now travelling to ${parentLocation.name}. It will take you ${travelTime.toFixed(1)} hours`,
+ );
+
+ startTravel(player, parentLocation.id, client, roomId);
+};
+
const onEntities = (_text: string, roomId: string, sender: string) => {
const player = getPlayer(sender);
const location = getLocation(player.location);
@@ -312,7 +340,7 @@ const onEntity = (text: string, roomId: string, sender: string) => {
return;
}
- onStatus("", roomId, entity.name);
+ onStatusName(roomId, entity.name);
};
export { registerModuleGame };