import * as CONSTANT from '../shared/constants';
import { logger } from './lib/logger';
import { loadPlayer, createPlayer, updatePlayer, movePlayer } from './player';
-import { random, sample } from 'lodash';
+import { random, sample, each } from 'lodash';
import {broadcastMessage} from '../shared/message';
import {maxHp, maxVigor, Player} from '../shared/player';
-import {createFight, getMonsterList, getMonsterLocation, getRandomMonster, loadMonster, loadMonsterFromFight, loadMonsterWithFaction} from './monster';
-import {addInventoryItem, getEquippedItems, getInventory, getInventoryItem} from './inventory';
+import {createFight, getMonsterList, getMonsterLocation, getRandomMonster, loadMonster, loadMonsterFromFight} from './monster';
+import {addInventoryItem, getEquippedItems, getInventory } from './inventory';
import { getItemFromPlayer, getItemFromShop, getPlayersItems, getShopItems, givePlayerItem, updateItemCount } from './items';
import {FightTrigger, Monster} from '../shared/monsters';
import {getShopEquipment, listShopItems } from './shopEquipment';
-import {EquipmentSlot} from '../shared/inventory';
import { clearTravelPlan, completeTravel, getAllPaths, getAllServices, getCityDetails, getService, getTravelPlan, stepForward, travel, getDungeon } from './map';
import { signup, login, authEndpoint } from './auth';
import {db} from './lib/db';
import { getPlayerSkills} from './skills';
-import { fightRound, blockPlayerInFight } from './fight';
+import { fightRound } from './fight';
import { router as healerRouter } from './locations/healer';
import { router as professionRouter } from './locations/recruiter';
import { router as repairRouter } from './locations/repair';
import { router as dungeonRouter } from './locations/dungeon';
-import { chatRouter } from './routes/chat';
+import * as Routers from './routes';
import * as Alert from './views/alert';
import { ExplorePane } from './views/components/explore-pane';
// TEMP!
import { Item, PlayerItem, ShopItem } from 'shared/items';
-import { equip, unequip } from './equipment';
import { HealthPotionSmall } from '../shared/items/health_potion';
-import { completeDungeonFight, getActiveDungeon, getRoomVists, loadRoom, blockPlayerInDungeon } from './dungeon';
+import { completeDungeonFight, getActiveDungeon, getRoomVists, loadRoom } from './dungeon';
import { renderDungeon, renderDungeonRoom } from './views/dungeons/room';
import { flushBuffer, addEvent } from './events';
app.use(professionRouter);
app.use(repairRouter);
app.use(dungeonRouter);
-app.use(chatRouter);
+each(Routers, router => {
+ app.use(router);
+});
app.get('/player', authEndpoint, async (req: Request, res: Response) => {
const equipment = await getEquippedItems(req.player.id);
res.send(renderSkills(skills));
});
-app.get('/player/inventory', authEndpoint, async (req: Request, 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, blockPlayerInFight, blockPlayerInDungeon, async (req: Request, 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;
- let desiredSlot: EquipmentSlot = inventoryItem.equipment_slot;
-
- try {
- // handes the situation where you're trying to equip an item
- // that can be equipped to any hand
- if(inventoryItem.equipment_slot === 'ANY_HAND') {
- if(requestedSlot === 'LEFT_HAND' || requestedSlot === 'RIGHT_HAND') {
- // get the players current equipment in that slot!
- if(equippedItems.some(v => {
- return v.equipment_slot === requestedSlot || v.equipment_slot === 'TWO_HANDED';
- })) {
- throw new Error();
- }
- else {
- desiredSlot = requestedSlot;
- }
- }
- }
-
- if(requestedSlot === 'TWO_HANDED') {
- if(equippedItems.some(v => {
- return v.equipment_slot === 'LEFT_HAND' || v.equipment_slot === 'RIGHT_HAND';
- })) {
- throw new Error();
- }
- }
-
-
- await equip(req.player.id, inventoryItem, desiredSlot);
- const socketId = cache.get(`socket:${req.player.id}`).toString();
- io.to(socketId).emit('updatePlayer', req.player);
- io.to(socketId).emit('alert', {
- type: 'success',
- text: `You equipped your ${inventoryItem.name}`
- });
- }
- catch(e) {
- logger.log(e);
- }
-
- const [inventory, items] = await Promise.all([
- getInventory(req.player.id),
- getPlayersItems(req.player.id)
- ]);
-
- res.send(renderInventoryPage(inventory, items, inventoryItem.type) + renderPlayerBar(req.player));
-});
-
-app.post('/player/unequip/:item_id', authEndpoint, blockPlayerInFight, blockPlayerInDungeon, async (req: Request, res: Response) => {
- const [item, ] = await Promise.all([
- getInventoryItem(req.player.id, req.params.item_id),
- unequip(req.player.id, req.params.item_id)
- ]);
-
- const [inventory, items] = await Promise.all([
- getInventory(req.player.id),
- getPlayersItems(req.player.id)
- ]);
-
- res.send(renderInventoryPage(inventory, items, item.type) + renderPlayerBar(req.player));
-});
-
app.get('/player/explore', authEndpoint, async (req: Request, res: Response) => {
const fight = await loadMonsterFromFight(req.player.id);
const travelPlan = await getTravelPlan(req.player.id);