From 2be01609a627d3db6fc39ff63f46b70016abbc43 Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 29 Sep 2023 10:31:19 -0400 Subject: [PATCH] feat: min level for all locations 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 | 3 ++- src/server/api.ts | 6 +++--- src/server/fight.ts | 7 +++++++ src/server/map.ts | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/seeds/cities.ts b/seeds/cities.ts index 2e1bfba..866907f 100644 --- a/seeds/cities.ts +++ b/seeds/cities.ts @@ -73,7 +73,8 @@ export async function createLocations(): Promise { 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(); diff --git a/src/server/api.ts b/src/server/api.ts index 9d1b641..c476f77 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -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) ]); diff --git a/src/server/fight.ts b/src/server/fight.ts index 83a8132..4515c30 100644 --- a/src/server/fight.ts +++ b/src/server/fight.ts @@ -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; diff --git a/src/server/map.ts b/src/server/map.ts index 8a49db3..45b0084 100644 --- a/src/server/map.ts +++ b/src/server/map.ts @@ -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 { +export async function getAllServices(city_id: number, min_level: number): Promise { return db.select('*') .from('locations') .where({city_id}) + .andWhere('min_level', '<=', min_level) .orderBy('type') .orderBy('display_order'); } -- 2.25.1