From: xangelo Date: Thu, 14 Sep 2023 16:11:49 +0000 (-0400) Subject: fix: auto-enter dungeon if you are in it X-Git-Tag: v0.4.0~4 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=dfa62a7e55a7d2cc991b4d9bce179ab5f8afe836;p=risinglegends.git fix: auto-enter dungeon if you are in it --- diff --git a/src/server/api.ts b/src/server/api.ts index da7f014..b1ff042 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -21,7 +21,7 @@ import { getItemFromPlayer, getItemFromShop, getPlayersItems, getShopItems, give import {FightTrigger, Monster, MonsterForFight} from '../shared/monsters'; import {getShopEquipment, listShopItems } from './shopEquipment'; import {EquipmentSlot} from '../shared/inventory'; -import { clearTravelPlan, completeTravel, getAllPaths, getAllServices, getCityDetails, getService, getTravelPlan, stepForward, travel } from './map'; +import { clearTravelPlan, completeTravel, getAllPaths, getAllServices, getCityDetails, getService, getTravelPlan, stepForward, travel, getDungeon } from './map'; import { signup, login, authEndpoint } from './auth'; import {db} from './lib/db'; import { getPlayerSkills} from './skills'; @@ -35,6 +35,7 @@ import { router as repairRouter } from './locations/repair'; import { router as dungeonRouter } from './locations/dungeon'; import * as Alert from './views/alert'; +import { ExplorePane } from './views/components/explore-pane'; import { renderPlayerBar } from './views/player-bar' import { renderEquipmentDetails, renderStore } from './views/stores'; import { renderMap } from './views/map'; @@ -50,7 +51,7 @@ import { renderChatMessage } from './views/chat'; import { Item, PlayerItem, ShopItem } from 'shared/items'; import { equip, unequip } from './equipment'; import { HealthPotionSmall } from '../shared/items/health_potion'; -import { completeDungeonFight, getRoomVists, loadRoom, updatePlayerDungeonState } from './dungeon'; +import { completeDungeonFight, getActiveDungeon, getRoomVists, loadRoom, blockPlayerInDungeon } from './dungeon'; import { renderDungeon, renderDungeonRoom } from './views/dungeons/room'; dotenv(); @@ -237,7 +238,7 @@ app.get('/player/inventory', authEndpoint, async (req: Request, res: Response) = res.send(renderInventoryPage(inventory, items)); }); -app.post('/player/equip/:item_id/:slot', authEndpoint, blockPlayerInFight, async (req: Request, res: Response) => { +app.post('/player/equip/:item_id/:slot', authEndpoint, blockPlayerInFight, blockPlayerInDungeon, async (req: Request, res: Response) => { const inventoryItem = await getInventoryItem(req.player.id, req.params.item_id); const equippedItems = await getEquippedItems(req.player.id); const requestedSlot = req.params.slot; @@ -289,7 +290,7 @@ app.post('/player/equip/:item_id/:slot', authEndpoint, blockPlayerInFight, async res.send(renderInventoryPage(inventory, items, inventoryItem.type) + renderPlayerBar(req.player)); }); -app.post('/player/unequip/:item_id', authEndpoint, blockPlayerInFight, async (req: Request, res: Response) => { +app.post('/player/unequip/:item_id', authEndpoint, blockPlayerInFight, blockPlayerInDungeon, async (req: Request, res: Response) => { const [item, ] = await Promise.all([ getInventoryItem(req.player.id, req.params.item_id), unequip(req.player.id, req.params.item_id) @@ -316,40 +317,50 @@ app.get('/player/explore', authEndpoint, async (req: Request, res: Response) => const location = await getMonsterLocation(fight.ref_id); res.send(renderPlayerBar(req.player) + renderFightPreRound(fight, true, location, closestTown)); + return; } - else { - if(travelPlan) { - // traveling! - const chanceToSeeMonster = random(0, 100); - const things: any[] = []; - if(chanceToSeeMonster <= 30) { - const monster = await getRandomMonster([closestTown]); - things.push(monster); - } - // STEP_DELAY - const nextAction = cache[`step:${req.player.id}`] || 0; + const dungeon = await getActiveDungeon(req.player.id); + if(dungeon) { + const service = await getDungeon(dungeon.dungeon_id); + const room = await loadRoom(dungeon.current_room_id); + const visits = await getRoomVists(req.player.id, service.event_name); - res.send(renderPlayerBar(req.player) + renderTravel({ - things, - nextAction, - closestTown: closestTown, - walkingText: '', - travelPlan - })); - } - else { - // display the city info! - const [city, locations, paths] = await Promise.all([ - getCityDetails(req.player.city_id), - getAllServices(req.player.city_id), - getAllPaths(req.player.city_id) - ]); - - res.send(renderPlayerBar(req.player) + await renderMap({city, locations, paths}, closestTown)); + res.send(ExplorePane(service.city_id, renderDungeon(service.city_name, service.name, room, visits))); + return; + } + + // are you in a dungeon? + if(travelPlan) { + // traveling! + const chanceToSeeMonster = random(0, 100); + const things: any[] = []; + if(chanceToSeeMonster <= 30) { + const monster = await getRandomMonster([closestTown]); + things.push(monster); } + // STEP_DELAY + const nextAction = cache[`step:${req.player.id}`] || 0; + + res.send(renderPlayerBar(req.player) + renderTravel({ + things, + nextAction, + closestTown: closestTown, + walkingText: '', + travelPlan + })); + return; } + + // display the default explore view + const [city, locations, paths] = await Promise.all([ + getCityDetails(req.player.city_id), + getAllServices(req.player.city_id), + getAllPaths(req.player.city_id) + ]); + + res.send(renderPlayerBar(req.player) + await renderMap({city, locations, paths}, closestTown)); }); // used to purchase equipment from a particular shop diff --git a/src/server/dungeon.ts b/src/server/dungeon.ts index b2d3830..a58168d 100644 --- a/src/server/dungeon.ts +++ b/src/server/dungeon.ts @@ -1,6 +1,18 @@ import { Fight } from "shared/monsters"; -import { Dungeon, DungeonRoom, DungeonThing, DungeonPlayer, DungeonState, DungeonStateSummaryVists, DungeonStateSummaryFights } from "../shared/dungeon"; +import { Dungeon, DungeonRoom, DungeonPlayer, DungeonState, DungeonStateSummaryVists, DungeonStateSummaryFights } from "../shared/dungeon"; import { db } from './lib/db'; +import { Request, Response } from 'express'; +import { ErrorAlert } from "./views/alert"; + +export async function blockPlayerInDungeon(req: Request, res: Response, next: any) { + const state = await getActiveDungeon(req.player.id); + if(!state) { + next(); + } + else { + res.send(ErrorAlert('You are currently exploring a dungeon')); + } +} export async function getActiveDungeon(player_id: string): Promise { return db.select('*').from('dungeon_players').where({ diff --git a/src/server/views/components/explore-pane.ts b/src/server/views/components/explore-pane.ts new file mode 100644 index 0000000..581677b --- /dev/null +++ b/src/server/views/components/explore-pane.ts @@ -0,0 +1,5 @@ +export function ExplorePane(townId: number, contents: string): string { + return `
+ ${contents} +
`; +} diff --git a/src/server/views/dungeons/room.ts b/src/server/views/dungeons/room.ts index 5f371e8..cde75e5 100644 --- a/src/server/views/dungeons/room.ts +++ b/src/server/views/dungeons/room.ts @@ -67,5 +67,4 @@ export function dungeonRewards(dungeon: Dungeon, rewards: DungeonRewards): strin `; - }