import { loadPlayer, createPlayer, updatePlayer, movePlayer } from './player';
import { random, sample, each } from 'lodash';
import {broadcastMessage} from '../shared/message';
-import {maxHp, maxVigor, Player} from '../shared/player';
+import {maxHp, Player} from '../shared/player';
import {createFight, getMonsterList, getMonsterLocation, getRandomMonster, loadMonster, loadMonsterFromFight} from './monster';
-import {addInventoryItem, getEquippedItems, getInventory } from './inventory';
+import {addInventoryItem, getInventory } from './inventory';
import { getItemFromPlayer, getItemFromShop, getPlayersItems, getShopItems, givePlayerItem, updateItemCount } from './items';
import {FightTrigger, Monster} from '../shared/monsters';
import {getShopEquipment, listShopItems } from './shopEquipment';
import { renderPlayerBar } from './views/player-bar'
import { renderEquipmentDetails, renderStore } from './views/stores';
import { renderMap } from './views/map';
-import { renderProfilePage } from './views/profile';
import { renderSkills } from './views/skills';
import { renderInventoryPage } from './views/inventory';
import { renderMonsterSelector, renderOnlyMonsterSelector } from './views/monster-selector';
app.use(router);
});
-app.get('/player', authEndpoint, async (req: Request, res: Response) => {
- const equipment = await getEquippedItems(req.player.id);
- res.send(renderPlayerBar(req.player) + renderProfilePage(req.player, equipment));
-});
-
-app.post('/player/stat/:stat', authEndpoint, async (req: Request, res: Response) => {
- const equipment = await getEquippedItems(req.player.id);
- const stat = req.params.stat;
- if(!['strength', 'constitution', 'dexterity', 'intelligence'].includes(stat)) {
- res.send(Alert.ErrorAlert(`Sorry, that's not a valid stat to increase`));
- return;
- }
-
- if(req.player.stat_points <= 0) {
- res.send(Alert.ErrorAlert(`Sorry, you don't have enough stat points`));
- return;
- }
-
- req.player.stat_points -= 1;
- req.player[stat]++;
-
- req.player.hp = maxHp(req.player.constitution, req.player.level);
- req.player.vigor = maxVigor(req.player.constitution, req.player.level);
- updatePlayer(req.player);
-
- res.send(renderPlayerBar(req.player) + renderProfilePage(req.player, equipment));
-});
-
app.get('/player/skills', authEndpoint, async (req: Request, res: Response) => {
const skills = await getPlayerSkills(req.player.id);
import { authEndpoint } from '../auth';
import { blockPlayerInFight } from '../fight';
import { blockPlayerInDungeon } from '../dungeon';
-import {addInventoryItem, getEquippedItems, getInventory, getInventoryItem} from '../inventory';
-import { getItemFromPlayer, getItemFromShop, getPlayersItems, getShopItems, givePlayerItem, updateItemCount } from '../items';
+import { getEquippedItems, getInventory, getInventoryItem } from '../inventory';
+import { getPlayersItems } from '../items';
import { equip, unequip } from '../equipment';
import { renderInventoryPage } from '../views/inventory';
import { renderPlayerBar } from '../views/player-bar';
--- /dev/null
+import { Request, Response, Router } from 'express';
+import { authEndpoint } from '../auth';
+import { getEquippedItems } from '../inventory';
+import { updatePlayer } from '../player';
+import {maxHp, maxVigor } from '../../shared/player';
+import * as Alert from '../views/alert';
+import { renderPlayerBar } from '../views/player-bar'
+import { renderProfilePage } from '../views/profile';
+
+export const profileRouter = Router();
+
+profileRouter.get('/player', authEndpoint, async (req: Request, res: Response) => {
+ const equipment = await getEquippedItems(req.player.id);
+ res.send(renderPlayerBar(req.player) + renderProfilePage(req.player, equipment));
+});
+
+profileRouter.post('/player/stat/:stat', authEndpoint, async (req: Request, res: Response) => {
+ const equipment = await getEquippedItems(req.player.id);
+ const stat = req.params.stat;
+ if(!['strength', 'constitution', 'dexterity', 'intelligence'].includes(stat)) {
+ res.send(Alert.ErrorAlert(`Sorry, that's not a valid stat to increase`));
+ return;
+ }
+
+ if(req.player.stat_points <= 0) {
+ res.send(Alert.ErrorAlert(`Sorry, you don't have enough stat points`));
+ return;
+ }
+
+ req.player.stat_points -= 1;
+ req.player[stat]++;
+
+ req.player.hp = maxHp(req.player.constitution, req.player.level);
+ req.player.vigor = maxVigor(req.player.constitution, req.player.level);
+ updatePlayer(req.player);
+
+ res.send(renderPlayerBar(req.player) + renderProfilePage(req.player, equipment));
+});
+
+