import {FightTrigger, Monster, MonsterForFight} from '../shared/monsters';
import {getShopEquipment, listShopItems } from './shopEquipment';
import {EquipmentSlot} from '../shared/inventory';
-import { clearTravelPlan, completeTravel, getAllPaths, getAllServices, getCityDetails, getService, getTravelPlan, stepForward, travel } from './map';
+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 { router as dungeonRouter } from './locations/dungeon';
import * as Alert from './views/alert';
+import { ExplorePane } from './views/components/explore-pane';
import { renderPlayerBar } from './views/player-bar'
import { renderEquipmentDetails, renderStore } from './views/stores';
import { renderMap } from './views/map';
import { Item, PlayerItem, ShopItem } from 'shared/items';
import { equip, unequip } from './equipment';
import { HealthPotionSmall } from '../shared/items/health_potion';
-import { completeDungeonFight, getRoomVists, loadRoom, updatePlayerDungeonState } from './dungeon';
+import { completeDungeonFight, getActiveDungeon, getRoomVists, loadRoom, blockPlayerInDungeon } from './dungeon';
import { renderDungeon, renderDungeonRoom } from './views/dungeons/room';
dotenv();
res.send(renderInventoryPage(inventory, items));
});
-app.post('/player/equip/:item_id/:slot', authEndpoint, blockPlayerInFight, async (req: Request, res: Response) => {
+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;
res.send(renderInventoryPage(inventory, items, inventoryItem.type) + renderPlayerBar(req.player));
});
-app.post('/player/unequip/:item_id', authEndpoint, blockPlayerInFight, async (req: Request, res: Response) => {
+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 location = await getMonsterLocation(fight.ref_id);
res.send(renderPlayerBar(req.player) + renderFightPreRound(fight, true, location, closestTown));
+ return;
}
- else {
- if(travelPlan) {
- // traveling!
- const chanceToSeeMonster = random(0, 100);
- const things: any[] = [];
- if(chanceToSeeMonster <= 30) {
- const monster = await getRandomMonster([closestTown]);
- things.push(monster);
- }
- // STEP_DELAY
- const nextAction = cache[`step:${req.player.id}`] || 0;
+ const dungeon = await getActiveDungeon(req.player.id);
+ if(dungeon) {
+ const service = await getDungeon(dungeon.dungeon_id);
+ const room = await loadRoom(dungeon.current_room_id);
+ const visits = await getRoomVists(req.player.id, service.event_name);
- res.send(renderPlayerBar(req.player) + renderTravel({
- things,
- nextAction,
- closestTown: closestTown,
- walkingText: '',
- travelPlan
- }));
- }
- else {
- // display the city info!
- const [city, locations, paths] = await Promise.all([
- getCityDetails(req.player.city_id),
- getAllServices(req.player.city_id),
- getAllPaths(req.player.city_id)
- ]);
-
- res.send(renderPlayerBar(req.player) + await renderMap({city, locations, paths}, closestTown));
+ res.send(ExplorePane(service.city_id, renderDungeon(service.city_name, service.name, room, visits)));
+ return;
+ }
+
+ // are you in a dungeon?
+ if(travelPlan) {
+ // traveling!
+ const chanceToSeeMonster = random(0, 100);
+ const things: any[] = [];
+ if(chanceToSeeMonster <= 30) {
+ const monster = await getRandomMonster([closestTown]);
+ things.push(monster);
}
+ // STEP_DELAY
+ const nextAction = cache[`step:${req.player.id}`] || 0;
+
+ res.send(renderPlayerBar(req.player) + renderTravel({
+ things,
+ nextAction,
+ closestTown: closestTown,
+ walkingText: '',
+ travelPlan
+ }));
+ return;
}
+
+ // display the default explore view
+ const [city, locations, paths] = await Promise.all([
+ getCityDetails(req.player.city_id),
+ getAllServices(req.player.city_id),
+ getAllPaths(req.player.city_id)
+ ]);
+
+ res.send(renderPlayerBar(req.player) + await renderMap({city, locations, paths}, closestTown));
});
// used to purchase equipment from a particular shop