1 import {movePlayer, updatePlayer} from "../../server/player";
2 import {getCityDetails, getAllServices, getAllPaths, travel, getTravelPlan, stepForward, completeTravel} from "../../server/map";
3 import {SocketEvent} from "../../server/socket-event.server";
4 import { sample, random } from 'lodash';
5 import { createFight, getRandomMonster, loadMonster } from "../../server/monster";
7 export const explore: SocketEvent = {
8 eventName: 'city:travel',
9 handler: async (api, data: { args: string }) => {
10 if(api.player.hp <= 0) {
11 api.socket.emit('alert', {
13 text: 'Sorry, you need some HP to start your travel'
18 const destinationCity = parseInt(data.args);
21 if(!destinationCity || isNaN(destinationCity)) {
22 console.log(`Invalid destination city [${destinationCity}]`);
27 const city = await getCityDetails(destinationCity);
30 console.log(`Invalid destination city [${destinationCity}]`);
34 console.log(`${api.player.username} attempting travel to ${city.name}`);
35 const travelPlan = await travel(api.player, city.id);
37 api.socket.emit('city:travel', {
39 closestTown: api.player.city_id,
49 const walkingText: string[] = [
50 'You take a step forward',
54 export const nextStep: SocketEvent = {
55 eventName: 'travel:step',
56 handler: async (api, data: { args: string }) => {
57 const travelPlan = await getTravelPlan(api.player.id);
63 travelPlan.current_position++;
64 if(travelPlan.current_position >= travelPlan.total_distance) {
65 const travel = await completeTravel(api.player.id);
67 api.player.city_id = travel.destination_id;
68 await movePlayer(travel.destination_id, api.player.id);
70 const [city, locations, paths] = await Promise.all([
71 getCityDetails(travel.destination_id),
72 getAllServices(travel.destination_id),
73 getAllPaths(travel.destination_id)
76 api.socket.emit('city:display', {
83 // update existing plan..
84 // decide if they will run into anything
85 const travelPlan = await stepForward(api.player.id);
87 const closest: number = (travelPlan.current_position / travelPlan.total_distance) > 0.5 ? travelPlan.destination_id : travelPlan.source_id;
89 // @TODO send back monsters
90 const chanceToSeeMonster = random(0, 100);
91 // 20% chance to see monster
92 const things: any[] = [];
93 if(chanceToSeeMonster < 20 || true) {
94 const monster = await getRandomMonster([closest]);
99 api.socket.emit('city:travel', {
101 closestTown: closest,
102 walkingText: sample(walkingText)