From b1a199928a9de17b1aecd117e8d8e3a7810de49b Mon Sep 17 00:00:00 2001 From: xangelo Date: Wed, 16 Aug 2023 16:00:17 -0400 Subject: [PATCH] fix: cant perform other actions in a fight --- src/server/api.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/server/api.ts b/src/server/api.ts index 35ba7e3..96adb4e 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -16,7 +16,7 @@ import {clearFight, createFight, getMonsterList, getMonsterLocation, getRandomMo import {FightRound} from '../shared/fight'; import {addInventoryItem, deleteInventoryItem, getEquippedItems, getInventory, getInventoryItem, updateAp} from './inventory'; import { getItemFromPlayer, getItemFromShop, getPlayersItems, getShopItems, givePlayerItem, updateItemCount } from './items'; -import {FightTrigger, Monster, MonsterForFight, MonsterWithFaction} from '../shared/monsters'; +import {Fight, FightTrigger, Monster, MonsterForFight, MonsterWithFaction} from '../shared/monsters'; import {getShopEquipment, listShopItems } from './shopEquipment'; import {EquippedItemDetails} from '../shared/equipped'; import {ArmourEquipmentSlot, EquipmentSlot} from '../shared/inventory'; @@ -451,13 +451,13 @@ app.post('/player/stat/:stat', authEndpoint, async (req: AuthRequest, res: Respo res.send(renderPlayerBar(req.player, equippedItems) + renderProfilePage(req.player)); }); -app.get('/player/skills', authEndpoint, async (req: AuthRequest, res: Response) => { +app.get('/player/skills', authEndpoint, blockPlayerInFight, async (req: AuthRequest, res: Response) => { const skills = await getPlayerSkills(req.player.id); res.send(renderSkills(skills)); }); -app.get('/player/inventory', authEndpoint, async (req: AuthRequest, res: Response) => { +app.get('/player/inventory', authEndpoint, blockPlayerInFight, async (req: AuthRequest, res: Response) => { const [inventory, items] = await Promise.all([ getInventory(req.player.id), getPlayersItems(req.player.id) @@ -466,7 +466,7 @@ app.get('/player/inventory', authEndpoint, async (req: AuthRequest, res: Respons res.send(renderInventoryPage(inventory, items)); }); -app.post('/player/equip/:item_id/:slot', authEndpoint, async (req: AuthRequest, res: Response) => { +app.post('/player/equip/:item_id/:slot', authEndpoint, blockPlayerInFight, async (req: AuthRequest, 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; @@ -518,7 +518,7 @@ app.post('/player/equip/:item_id/:slot', authEndpoint, async (req: AuthRequest, res.send(renderInventoryPage(inventory, items, inventoryItem.type) + renderPlayerBar(req.player, inventory)); }); -app.post('/player/unequip/:item_id', authEndpoint, async (req: AuthRequest, res: Response) => { +app.post('/player/unequip/:item_id', authEndpoint, blockPlayerInFight, async (req: AuthRequest, res: Response) => { const [item, ] = await Promise.all([ getInventoryItem(req.player.id, req.params.item_id), unequip(req.player.id, req.params.item_id) @@ -532,13 +532,22 @@ app.post('/player/unequip/:item_id', authEndpoint, async (req: AuthRequest, res: res.send(renderInventoryPage(inventory, items, item.type) + renderPlayerBar(req.player, inventory)); }); +async function blockPlayerInFight(req: AuthRequest, res: Response, next) { + const fight = await loadMonsterFromFight(req.player.id); + if(!fight) { + next(); + return; + } + + res.send(Alert.ErrorAlert(`You are currently in a fight with a ${fight.name}`)); +} + app.get('/player/explore', authEndpoint, async (req: AuthRequest, res: Response) => { const fight = await loadMonsterFromFight(req.player.id); let closestTown = req.player.city_id; const equippedItems = await getEquippedItems(req.player.id); if(fight) { - // ok lets display the fight screen! const data: MonsterForFight = { id: fight.id, hp: fight.hp, -- 2.25.1