fix(locations): only show locations that are accessible to the player (by level)
authorxangelo <me@xangelo.ca>
Thu, 5 Dec 2024 05:30:55 +0000 (00:30 -0500)
committerxangelo <me@xangelo.ca>
Thu, 5 Dec 2024 05:30:55 +0000 (00:30 -0500)
src/server/api.ts
src/server/map.ts
src/server/routes/travel.ts

index fc5ffa7ad709888a3193ed0e6562b6037e3e61a0..74cde0ad7f085f61310e09c5eeb6289d68264ab1 100644 (file)
@@ -223,7 +223,7 @@ app.get('/player/explore', authEndpoint, async (req: Request, res: Response) =>
   // display the default explore view
   const [city, locations, paths] = await Promise.all([
     getCityDetails(req.player.city_id),
-    getAllServices(req.player.city_id),
+    getAllServices(req.player.city_id, req.player.level),
     getAllPaths(req.player.city_id)
   ]);
 
index fb88b0a1626d1a5797346fe26f48f9d080a7f9a9..45975bd1d3fc3ec739a0d0b9d054adf337f2f71e 100644 (file)
@@ -4,11 +4,12 @@ import type { Travel, TravelWithNames } from "@shared/travel";
 import { db } from './lib/db';
 import { random } from 'lodash';
 
-export async function getAllServices(city_id: number): Promise<Location[]> {
+export async function getAllServices(city_id: number, minLevel: number = 0): Promise<Location[]> {
   return db.select('*')
             .from<Location>('locations')
             .where({city_id})
             .andWhere('is_visible', true)
+            .andWhere('min_level', '<=', minLevel)
             .orderBy('type')
             .orderBy('display_order');
 }
index 2a685632bfc7cdeaab66b9632ea3fc96187a2468..ba2f70cfcd053fde1a77d9e6ee95554ff48b2961 100644 (file)
@@ -40,7 +40,7 @@ travelRouter.post('/travel/step', authEndpoint, async (req: Request, res: Respon
 
     const [city, locations, paths] = await Promise.all([
       getCityDetails(travel.destination_id),
-      getAllServices(travel.destination_id),
+      getAllServices(travel.destination_id, req.player.level),
       getAllPaths(travel.destination_id)
     ]);
 
@@ -97,7 +97,7 @@ travelRouter.post('/travel/return-to-source', authEndpoint, async (req: Request,
   else {
     const [city, locations, paths] = await Promise.all([
       getCityDetails(req.player.city_id),
-      getAllServices(req.player.city_id),
+      getAllServices(req.player.city_id, req.player.level),
       getAllPaths(req.player.city_id)
     ]);