feat: min level for all locations
authorxangelo <me@xangelo.ca>
Fri, 29 Sep 2023 14:31:19 +0000 (10:31 -0400)
committerxangelo <me@xangelo.ca>
Fri, 29 Sep 2023 14:31:19 +0000 (10:31 -0400)
All locations default to a min level of 1, so they're always visible.
but some things (stores, dungeons) can have a higher level where they
will not be visible until the player meets the requirement.

seeds/cities.ts
src/server/api.ts
src/server/fight.ts
src/server/map.ts

index 2e1bfbaed0c32d6761b7854d1b08bc01f84b8079..866907fa490d7c7e27cf970d42f38e548270258b 100644 (file)
@@ -73,7 +73,8 @@ export async function createLocations(): Promise<void> {
           type: r.fields.Type,
           city_id: r.fields.city_id[0],
           display_order: r.fields["Display Order"],
-          event_name: r.fields['event_name']
+          event_name: r.fields['event_name'],
+          min_level: Math.max(parseInt(r.fields['Min Level'].toString()), 1)
         }
       })).onConflict('id').merge();
 
index 9d1b6413a286ee8f7277c50747569b51682e8382..c476f770041a2c927a4bfd8910077dd367a71657 100644 (file)
@@ -359,7 +359,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)
   ]);
 
@@ -725,7 +725,7 @@ app.post('/travel/step', authEndpoint, async (req: Request, res: Response) => {
 
     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)
     ]);
 
@@ -782,7 +782,7 @@ app.post('/travel/return-to-source', authEndpoint, async (req: Request, res: Res
   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)
     ]);
 
index 83a813225d6c5ebb178ae3b5cbd506bb6194872a..4515c30b60edbd8890d9202ee69905b0995cdbb6 100644 (file)
@@ -163,6 +163,13 @@ export async function fightRound(player: Player, monster: Fight,  data: {action:
     roundData.monster.hp = 0;
     roundData.winner = 'player';
 
+    addEvent('MONSTER_KILLED', player.id, {
+      monster_id: roundData.monster.ref_id,
+      monster_name: roundData.monster.name,
+      level: roundData.monster.level,
+      fightTrigger: roundData.monster.fight_trigger
+    });
+
     const expGained = exponentialExp(monster.exp, monster.level, player.level);
 
     roundData.rewards.exp = expGained;
index 8a49db36dde83ac4bfc0131bddca531b6016f33c..45b008470c293dcc26d897d8ccf3287f4e71f371 100644 (file)
@@ -4,10 +4,11 @@ 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, min_level: number): Promise<Location[]> {
   return db.select('*')
             .from<Location>('locations')
             .where({city_id})
+            .andWhere('min_level', '<=', min_level)
             .orderBy('type')
             .orderBy('display_order');
 }