+++ /dev/null
-export * from './profession-changing/client';
-export * from './travel/client';
+++ /dev/null
-import {SocketEvent} from "../../server/socket-event.server";
-import { Socket } from 'socket.io';
-import {EquipmentSlot} from '../../shared/inventory';
-import {getEquippedItems, getInventory, getInventoryItem} from '../../server/inventory';
-import { equip, unequip } from '../../server/equipment';
-import { logger } from '../../server/lib/logger';
-import {EquippedItemDetails} from '../../shared/equipped';
-import { getPlayersItems } from "../../server/items";
-
-class EquipmentInSlotError extends Error {
- code: number;
- constructor() {
- super('You already have something in that slot');
- this.code = 23505;
- }
-}
-
-
-function calcAp(inventoryItem: EquippedItemDetails[], socket: Socket) {
- const ap: Record<any | EquipmentSlot, {currentAp: number, maxAp: number}> = {};
- inventoryItem.forEach(item => {
- if(item.is_equipped && item.type === 'ARMOUR') {
- ap[item.equipment_slot] = {
- currentAp: item.currentAp,
- maxAp: item.maxAp
- };
- }
- });
-
- socket.emit('calc:ap', {ap});
-}
-
-export const equipItem: SocketEvent = {
- eventName: 'equip',
- handler: async (api, data: {id: string, slot: EquipmentSlot}) => {
- const inventoryItem = await getInventoryItem(api.player.id, data.id);
- const equippedItems = await getEquippedItems(api.player.id);
- 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(data.slot === 'LEFT_HAND' || data.slot === 'RIGHT_HAND') {
- // get the players current equipment in that slot!
- if(equippedItems.some(v => {
- return v.equipment_slot === data.slot || v.equipment_slot === 'TWO_HANDED';
- })) {
- throw new EquipmentInSlotError();
- }
- else {
- desiredSlot = data.slot;
- }
- }
- }
-
- if(data.slot === 'TWO_HANDED') {
- if(equippedItems.some(v => {
- return v.equipment_slot === 'LEFT_HAND' || v.equipment_slot === 'RIGHT_HAND';
- })) {
- throw new EquipmentInSlotError();
- }
- }
-
-
- await equip(api.player.id, inventoryItem, desiredSlot);
- api.socket.emit('alert', {
- type: 'success',
- text: `You equipped your ${inventoryItem.name}`
- });
- }
- catch(e) {
- if(e.code.toString() === '23505') {
- api.socket.emit('alert', {
- type: 'error',
- text: 'You already have an item equipped in that slot'
- });
- }
- else {
- logger.log(e);
- }
- }
-
- const inventory = await getInventory(api.player.id);
- const items = await getPlayersItems(api.player.id);
- api.socket.emit('inventory', {
- inventory,
- items
- });
- calcAp(inventory, api.socket);
-
- }
-}
-
-export const unequipItem: SocketEvent = {
- eventName: 'unequip',
- handler: async (api, data: {id: string}) => {
- await unequip(api.player.id, data.id);
-
- const inventory = await getInventory(api.player.id);
- calcAp(inventory, api.socket);
- const items = await getPlayersItems(api.player.id);
- api.socket.emit('inventory', {
- inventory,
- items
- });
- }
-}
+++ /dev/null
-import {Monster, MonsterForList} from "../../shared/monsters";
-import {SocketEvent} from "../../server/socket-event.server";
-import {getMonsterList} from "../../server/monster";
-
-export const exploreInCity: SocketEvent = {
- eventName: 'city:explore',
- handler: async (api, data: { args: string }) => {
- // @TODO add check to make sure player is in this town and can actually explore this area
- const locationId = parseInt(data.args);
-
- if(!locationId || isNaN(locationId)) {
- return;
- }
-
- const monsters: Monster[] = await getMonsterList(locationId);
- let monsterList: MonsterForList[] = monsters.map(monster => {
- return {
- id: monster.id,
- name: monster.name,
- level: monster.level
- }
- });
-
- api.socket.emit('explore:fights', monsterList);
- }
-}
+++ /dev/null
-import { getItemFromPlayer, getPlayersItems, updateItemCount } from "../../server/items";
-import {API, SocketEvent} from "../../server/socket-event.server";
-import { maxHp } from "../../shared/player";
-import { updatePlayer } from "../../server/player";
-import { HealthPotionSmall } from "../../shared/items/health_potion";
-import { getInventory } from "../../server/inventory";
-
-export const smallHeal: SocketEvent = {
- eventName: 'item:use:heal_small',
- handler: async (api: API, data: {args: string}): Promise<any> => {
- const itemId = parseInt(data.args);
- const item = await getItemFromPlayer(api.player.id, itemId);
-
- if(!item) {
- console.log(`Can't find item [${data.args}]`);
- return;
- }
-
- if(item.amount < 1) {
- api.socket.emit('alert', {
- type: 'error',
- text: `You don't have enough ${item.name}`
- });
- return;
- }
-
- item.amount -= 1;
-
- const hpGain = HealthPotionSmall.effect(api.player);
-
- api.player.hp += hpGain;
-
- if(api.player.hp > maxHp(api.player.constitution, api.player.level)) {
- api.player.hp = maxHp(api.player.constitution, api.player.level);
- }
-
- await updateItemCount(api.player.id, item.item_id, -1);
- await updatePlayer(api.player);
- const inventory = await getInventory(api.player.id);
- const items = await getPlayersItems(api.player.id);
-
- api.socket.emit('updatePlayer', api.player);
- api.socket.emit('inventory', {
- inventory,
- items
- });
- api.socket.emit('alert', {
- type: 'success',
- text: `You used the Small Health Potion`
- });
-
- return;
- }
-}
+++ /dev/null
-import {SocketEvent} from "../../client/socket-event.client";
-import $ from 'jquery';
-import { EVENT_NAME } from "./shared";
-
-function generalTextReplacementHandler(api, data: { text: string }) {
- $('#map').html(data.text);
-}
-
-export const professionRecruiter: SocketEvent = new SocketEvent(EVENT_NAME, generalTextReplacementHandler);
-
-export const professionChangeWarrior: SocketEvent = new SocketEvent(
- `${EVENT_NAME}:warrior`,
- generalTextReplacementHandler
-);
-
-export const professionChangeMage: SocketEvent = new SocketEvent(
- `${EVENT_NAME}:mage`,
- generalTextReplacementHandler
-);
-
-export const professionChangeRogue: SocketEvent = new SocketEvent(
- `${EVENT_NAME}:rogue`,
- generalTextReplacementHandler
-);
+++ /dev/null
-import {API, SocketEvent} from "../../server/socket-event.server";
-import { EVENT_NAME } from './shared';
-import { changeProfession } from "../../server/player";
-import {Profession} from "shared/profession";
-import {broadcastMessage} from "../../shared/message";
-
-const MIN_LEVEL = 25;
-
-export const professionRecruiter: SocketEvent = {
- eventName: EVENT_NAME,
- handler: (api, data): Promise<any> => {
-
- let text: string = '';
-
- if(api.player.profession === 'Wanderer') {
- text = `
- <b>Welcome to the Professional Services at Windcross!</b>
- <p>Our duty is to help Wanderers such as yourself become more than they are. By helping you achieve new levels in service of the King, we can ensure that the Kingdom of Khatis continues to grow!</p>
- <p>You have 3 choices laid before you.</p>
- <p>You could become a great and mighty <b>Warrior</b>! Wielding powerful swords and maces.</p>
- <p>You could become a powerful <b>Mage</b>! Casting spells to rain fire upon our enemies.</p>
- <p>You could become a lithe <b>Rogue</b>! Attacking our enemies swiftly when they least expect!</p>
- `;
-
- if(api.player.level < MIN_LEVEL) {
- text += `<p>Unfortunately.. you have to be at least level ${MIN_LEVEL} to take part in our training...</p>`;
- }
- else {
- text += `
- <p><b>Be Careful!</b> Once you change your profession, you will never again be a Wanderer</p>
- <div>
- <button class="city-emit-event" data-event="${EVENT_NAME}:warrior">Become a Warrior</button>
- <button class="city-emit-event" data-event="${EVENT_NAME}:mage">Become a Mage</button>
- <button class="city-emit-event" data-event="${EVENT_NAME}:rogue">Become a Rogue</button>
- </div>
- `
- }
- }
- else {
-
- let town = 'UNSET';
- let place = 'UNSETPLACE';
- switch(api.player.profession) {
- case 'Warrior':
- town = 'Stether';
- place = 'Highbreaker Inn'
- break;
- case 'Mage':
- town = 'Davelfell';
- place = 'Mages Tower';
- break;
- case 'Rogue':
- town = 'Ferbalt Gap';
- place = 'Keepers Tavern';
- break;
- }
-
- text = `<p>Welcome <b>${api.player.profession}</b>!`;
- text += `<p>Unfortunately I won't be of much help to you now that you are no longer a wanderer...</p>`;
- text += `<p>However, you should visit the ${place} in ${town} that can probably provide some guidance!</p>`;
- }
-
-
- api.socket.emit('city:services:profession_recruitor_windcross', {
- text
- });
-
- return;
- }
-};
-
-async function generalFirstLevelProfessionChange(api: API, data: unknown, profession: Profession) {
- console.log(`${api.player.username} is becoming a ${profession}!`);
- const update = await changeProfession(api.player.id, profession);
-
- api.player.level = update.level;
- api.player.exp = update.exp;
- api.player.profession = profession;
-
- api.socket.emit('updatePlayer', api.player);
- api.socket.emit(`${EVENT_NAME}:${profession.toLowerCase()}`, {
- text: `Congratulations! You are now a ${profession}!`
- });
-
- api.io.emit('chat', broadcastMessage('server', `${api.player.username} is now a ${profession}`));
-}
-
-export const professionChangeWarrior: SocketEvent = {
- eventName: `${EVENT_NAME}:warrior`,
- handler: async (api, data) => {
- generalFirstLevelProfessionChange(api, data, 'Warrior');
- }
-}
-
-export const professionChangeMage: SocketEvent = {
- eventName: `${EVENT_NAME}:mage`,
- handler: async (api, data) => {
- generalFirstLevelProfessionChange(api, data, 'Mage');
- }
-}
-
-export const professionChangeRogue: SocketEvent = {
- eventName: `${EVENT_NAME}:rogue`,
- handler: async (api, data) => {
- generalFirstLevelProfessionChange(api, data, 'Rogue');
- }
-}
+++ /dev/null
-export const EVENT_NAME: string = 'city:services:profession_recruitor_windcross';
+++ /dev/null
-export * from './profession-changing/server';
-export * from './equipping-items/server';
-export * from './travel/server';
-export * from './explore/server';
-export * from './stores/server';
-export * from './stat-points/server';
-export * from './items/server';
+++ /dev/null
-import {SocketEvent} from "../../server/socket-event.server";
-import { professionList } from "../../shared/profession";
-import { updatePlayer } from "../../server/player";
-import { Stat } from "../../shared/stats";
-
-export const spendStatPoint: SocketEvent = {
- eventName: 'spend-stat-point',
- handler: async (api, data: { args: any }): Promise<void> => {
-
- if(!Stat[data.args]) {
- api.socket.emit('alert', {
- type: 'error',
- text: `Invalid stat type [${data.args}]`
- });
- return;
- }
-
- const statToIncrease: Stat = data.args as Stat;
- const costToIncrease: number = professionList[api.player.profession].classStats.includes(statToIncrease) ? 1 : 2;
-
- if(api.player.stat_points < costToIncrease) {
- api.socket.emit('alert', {
- type: 'error',
- text: 'You don\'t have enough stat points'
- });
- }
- else {
- api.player[statToIncrease] += costToIncrease;
- api.player.stat_points -= costToIncrease;
-
- await updatePlayer(api.player);
- api.socket.emit('updatePlayer', api.player);
- }
-
- }
-}
+++ /dev/null
-import {SocketEvent} from "../../server/socket-event.server";
-import {listShopItems} from '../../server/shopEquipment';
-import { getShopItems } from "../../server/items";
-import { logger } from '../../server/lib/logger';
-
-export const stores: SocketEvent = {
- eventName: 'city:stores',
- handler: async (api, data: {args: string}) => {
- const storeId = parseInt(data.args);
-
- if(!storeId || isNaN(storeId)) {
- logger.log(`Invalid store id: ${storeId}`);
- }
-
- const [shopEquipemnt, shopItems] = await Promise.all([
- listShopItems({location_id: storeId}),
- getShopItems(storeId)
- ]);
-
- if(shopEquipemnt && shopEquipemnt.length) {
- api.socket.emit('city:stores', {
- equipment: shopEquipemnt,
- items: shopItems
- });
- }
- else {
- logger.log(`Insufficient shop items: ${shopEquipemnt.length}`);
- }
- }
-}
+++ /dev/null
-import {SocketEvent} from "../../client/socket-event.client";
-import $ from 'jquery';
-import { TravelDTO } from './shared';
-
-export const travel: SocketEvent = new SocketEvent(
- 'city:travel',
- (api, data) => {
- api.events.emit('renderTravel',[data as TravelDTO]);
- }
-);
-
-export const renderCity: SocketEvent = new SocketEvent(
- 'city:display',
- async (api, data) => {
- api.cache.delete('currentMapHTML');
- api.events.emit('renderMap', [data]);
- }
-)
+++ /dev/null
-import {movePlayer} from "../../server/player";
-import {getCityDetails, getAllServices, getAllPaths, travel, getTravelPlan, stepForward, completeTravel} from "../../server/map";
-import {SocketEvent} from "../../server/socket-event.server";
-import { sample, random } from 'lodash';
-import { getRandomMonster } from "../../server/monster";
-import { STEP_DELAY } from "./shared";
-
-const MONSTER_ENCOUNTER_CHANCE = 30;
-
-export const explore: SocketEvent = {
- eventName: 'city:travel',
- handler: async (api, data: { args: string }) => {
- if(api.player.hp <= 0) {
- api.socket.emit('alert', {
- type: 'error',
- text: 'Sorry, you need some HP to start your travel'
- });
- return;
- }
-
- const destinationCity = parseInt(data.args);
-
-
- if(!destinationCity || isNaN(destinationCity)) {
- console.log(`Invalid destination city [${destinationCity}]`);
- return;
- }
-
- try {
- const city = await getCityDetails(destinationCity);
-
- if(!city) {
- console.log(`Invalid destination city [${destinationCity}]`);
- return;
- }
-
- console.log(`${api.player.username} attempting travel to ${city.name}`);
- const travelPlan = await travel(api.player, city.id);
-
- api.socket.emit('city:travel', {
- things: [],
- nextAction: 0,
- closestTown: api.player.city_id,
- walkingText: ''
- });
- }
- catch(e) {
- console.log(e);
- }
- }
-}
-
-const walkingText: string[] = [
- 'You take a step forward',
- 'You keep moving'
-];
-
-export const nextStep: SocketEvent = {
- eventName: 'travel:step',
- handler: async (api, data: { args: string }) => {
- const stepTimerKey = `step:${api.player.id}`;
- const travelPlan = await getTravelPlan(api.player.id);
-
- if(api.cache[stepTimerKey]) {
- if(api.cache[stepTimerKey] > Date.now()) {
- // clicked too fast
- return;
- }
- }
-
- if(!travelPlan) {
- return;
- }
-
- travelPlan.current_position++;
- if(travelPlan.current_position >= travelPlan.total_distance) {
- const travel = await completeTravel(api.player.id);
-
- api.player.city_id = travel.destination_id;
- await movePlayer(travel.destination_id, api.player.id);
-
- const [city, locations, paths] = await Promise.all([
- getCityDetails(travel.destination_id),
- getAllServices(travel.destination_id),
- getAllPaths(travel.destination_id)
- ]);
-
- api.socket.emit('city:display', {
- city,
- locations,
- paths
- });
-
- delete api.cache[stepTimerKey];
- }
- else {
- // update existing plan..
- // decide if they will run into anything
- const travelPlan = await stepForward(api.player.id);
-
- const closest: number = (travelPlan.current_position / travelPlan.total_distance) > 0.5 ? travelPlan.destination_id : travelPlan.source_id;
-
- const chanceToSeeMonster = random(0, 100);
- const things: any[] = [];
- if(chanceToSeeMonster < MONSTER_ENCOUNTER_CHANCE) {
- const monster = await getRandomMonster([closest]);
- things.push(monster);
- }
-
- const nextAction = Date.now() + STEP_DELAY;
-
- api.cache[stepTimerKey] = nextAction;
-
- api.socket.emit('city:travel', {
- things,
- nextAction,
- closestTown: closest,
- walkingText: sample(walkingText)
- });
-
- }
- }
-};
+++ /dev/null
-import {City, Location, Path} from "../../shared/map"
-
-export type DTO = {
- city: City,
- locations: Location[],
- paths: Path[]
-}
-
-export type TravelDTO = {
- things: any[],
- nextAction: number;
- walkingText: string,
- closestTown: number;
-}
-
-export const STEP_DELAY = 3000;