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';
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)
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;
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)
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,