From: xangelo Date: Thu, 17 Aug 2023 17:55:14 +0000 (-0400) Subject: fix: background not appearing if reload during fight X-Git-Tag: v0.2.10~5 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=64a76af51449d76cf14f961d4d686f9463a4f286;p=risinglegends.git fix: background not appearing if reload during fight If you reload during a fight the city background was not properly appearing. You would need to complete the fight, then revisit the Explore tab for the city background to load. --- diff --git a/src/server/api.ts b/src/server/api.ts index 923e716..8a7eec8 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -544,8 +544,13 @@ async function blockPlayerInFight(req: AuthRequest, res: Response, next) { app.get('/player/explore', authEndpoint, async (req: AuthRequest, res: Response) => { const fight = await loadMonsterFromFight(req.player.id); + const travelPlan = await getTravelPlan(req.player.id); let closestTown = req.player.city_id; + if(travelPlan) { + closestTown = (travelPlan.current_position / travelPlan.total_distance) > 0.5 ? travelPlan.destination_id : travelPlan.source_id; + } + const equippedItems = await getEquippedItems(req.player.id); if(fight) { const data: MonsterForFight = { @@ -558,20 +563,16 @@ app.get('/player/explore', authEndpoint, async (req: AuthRequest, res: Response) }; const location = await getMonsterLocation(fight.ref_id); - res.send(renderPlayerBar(req.player, equippedItems) + renderFightPreRound(data, true, location)); + + res.send(renderPlayerBar(req.player, equippedItems) + renderFightPreRound(data, true, location, closestTown)); } else { - const travelPlan = await getTravelPlan(req.player.id); if(travelPlan) { // traveling! - const travelPlan = await getTravelPlan(req.player.id); - - const closest: number = (travelPlan.current_position / travelPlan.total_distance) > 0.5 ? travelPlan.destination_id : travelPlan.source_id; - const chanceToSeeMonster = random(0, 100); const things: any[] = []; if(chanceToSeeMonster <= 30) { - const monster = await getRandomMonster([closest]); + const monster = await getRandomMonster([closestTown]); things.push(monster); } @@ -581,7 +582,7 @@ app.get('/player/explore', authEndpoint, async (req: AuthRequest, res: Response) res.send(renderPlayerBar(req.player, equippedItems) + renderTravel({ things, nextAction, - closestTown: closest, + closestTown: closestTown, walkingText: '', travelPlan })); @@ -902,7 +903,7 @@ app.post('/fight', authEndpoint, async (req: AuthRequest, res: Response) => { fight_trigger: fight.fight_trigger }; - res.send(renderFightPreRound(data, true, location)); + res.send(renderFightPreRound(data, true, location, location.city_id)); }); app.post('/travel/step', authEndpoint, async (req: AuthRequest, res: Response) => { diff --git a/src/server/views/fight.ts b/src/server/views/fight.ts index 4663c62..400a7d8 100644 --- a/src/server/views/fight.ts +++ b/src/server/views/fight.ts @@ -69,10 +69,11 @@ export function renderFight(monster: MonsterForFight, results: string = '', disp return html; } -export function renderFightPreRound(monster: MonsterForFight, displayFightActions: boolean = true, location: LocationWithCity) { +export function renderFightPreRound(monster: MonsterForFight, displayFightActions: boolean = true, location: LocationWithCity, closestTown: number) { const hpPercent = Math.floor((monster.hp / monster.maxHp) * 100); let html = ` +
${location.city_name}
@@ -106,7 +107,9 @@ export function renderFightPreRound(monster: MonsterForFight, displayFightActio
-`; + +
+`; return html; } diff --git a/src/server/views/map.ts b/src/server/views/map.ts index 76a546b..e432ebd 100644 --- a/src/server/views/map.ts +++ b/src/server/views/map.ts @@ -39,6 +39,7 @@ export async function renderMap(data: { city: City, locations: Location[], paths + `; return html;