From fd070de32a394fd3452dcf1d8202e5325ec170aa Mon Sep 17 00:00:00 2001 From: xangelo Date: Mon, 21 Aug 2023 15:06:54 -0400 Subject: [PATCH] feat: return to town button while travelling When you're travelling between towns, there's always an option to return to the starting town. --- public/assets/css/game.css | 2 +- src/server/api.ts | 37 ++++++++++++++++++++++++++++++++++++- src/server/views/travel.ts | 8 ++------ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/public/assets/css/game.css b/public/assets/css/game.css index 69187e7..4060899 100644 --- a/public/assets/css/game.css +++ b/public/assets/css/game.css @@ -478,7 +478,7 @@ h3 { } #travelling { - padding-top: 2rem; + padding: 2rem; } #travelling-actions { display: flex; diff --git a/src/server/api.ts b/src/server/api.ts index baed723..5c6a558 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -975,8 +975,43 @@ app.post('/travel/step', authEndpoint, async (req: AuthRequest, res: Response) = } }); +app.post('/travel/return-to-source', authEndpoint, async (req: AuthRequest, res: Response) => { + // puts the player back in their starting town + // doesn't matter if they don't have one + // redirect them! + await clearTravelPlan(req.player.id); + const equippedItems = await getEquippedItems(req.player.id); + + const fight = await loadMonsterFromFight(req.player.id); + if(fight) { + // go to the fight screen + const data: MonsterForFight = { + id: fight.id, + hp: fight.hp, + maxHp: fight.maxHp, + name: fight.name, + level: fight.level, + fight_trigger: fight.fight_trigger + }; + const location = await getMonsterLocation(fight.ref_id); + + res.send(renderPlayerBar(req.player, equippedItems) + renderFightPreRound(data, true, location, req.player.city_id)); + } + else { + 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, equippedItems) + await renderMap({city, locations, paths}, req.player.city_id)); + + } + +}); + app.post('/travel/:destination_id', authEndpoint, async (req: AuthRequest, res: Response) => { - if(req.player.hp <= 0) { +if(req.player.hp <= 0) { logger.log(`Player didn\'t have enough hp`); res.send(Alert.ErrorAlert('Sorry, you need some HP to start travelling.')); return; diff --git a/src/server/views/travel.ts b/src/server/views/travel.ts index cf2d7db..9aff00e 100644 --- a/src/server/views/travel.ts +++ b/src/server/views/travel.ts @@ -9,12 +9,6 @@ export function renderTravel(data: TravelDTO): string { let promptText = data.walkingText; const blockTime = data.nextAction || 0; - /* - if(blockTime) { - updateStepButton(); - } - */ - let html = `
`; @@ -34,6 +28,8 @@ export function renderTravel(data: TravelDTO): string { html += '
'; html += `

${promptText}

`; + html += `

Return to ${data.travelPlan.source_city_name}

`; + html += '
'; return html; -- 2.25.1