feat: return to town button while travelling
authorxangelo <me@xangelo.ca>
Mon, 21 Aug 2023 19:06:54 +0000 (15:06 -0400)
committerxangelo <me@xangelo.ca>
Mon, 21 Aug 2023 19:06:54 +0000 (15:06 -0400)
When you're travelling between towns, there's always an option to return
to the starting town.

public/assets/css/game.css
src/server/api.ts
src/server/views/travel.ts

index 69187e73a516f180a87db12ebfc4856fc8f22ef5..4060899f36c8779d646649f0e12aba787a262e95 100644 (file)
@@ -478,7 +478,7 @@ h3 {
 }
 
 #travelling {
-  padding-top: 2rem;
+  padding: 2rem;
 }
 #travelling-actions {
   display: flex;
index baed723e2c7e50348d50aa18d36077929b718dfe..5c6a55842bab26224a9438648834d963a15edac7 100644 (file)
@@ -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;
index cf2d7dbcc12cd71bd2f582fbd5bf910e577a10e6..9aff00eea77a0aefafdc89be0ab83b03787a7aa2 100644 (file)
@@ -9,12 +9,6 @@ export function renderTravel(data: TravelDTO): string {
   let promptText = data.walkingText;
   const blockTime = data.nextAction || 0;
 
-  /*
-  if(blockTime) {
-    updateStepButton();
-  }
-  */
-
   let html = `<section id="explore" class="tab active" hx-swap-oob="true" style="background-image: url('/assets/img/map/${data.closestTown}.jpeg')">
 
 <div id="travelling" class="city-details">`;
@@ -34,6 +28,8 @@ export function renderTravel(data: TravelDTO): string {
   html += '</div>';
   html += `<p>${promptText}</p>`;
 
+  html += `<p align="right"><a href="#" hx-post="/travel/return-to-source">Return to ${data.travelPlan.source_city_name}</a></p>`;
+
   html += '</div></section>';
 
   return html;