1 import {SocketEvent} from "../../server/socket-event.server";
2 import { professionList } from "../../shared/profession";
3 import { updatePlayer } from "../../server/player";
4 import { Stat } from "../../shared/stats";
6 export const spendStatPoint: SocketEvent = {
7 eventName: 'spend-stat-point',
8 handler: async (api, data: { args: any }): Promise<void> => {
10 if(!Stat[data.args]) {
11 api.socket.emit('alert', {
13 text: `Invalid stat type [${data.args}]`
18 const statToIncrease: Stat = data.args as Stat;
19 const costToIncrease: number = professionList[api.player.profession].classStats.includes(statToIncrease) ? 1 : 2;
21 if(api.player.stat_points < costToIncrease) {
22 api.socket.emit('alert', {
24 text: 'You don\'t have enough stat points'
28 api.player[statToIncrease] += costToIncrease;
29 api.player.stat_points -= costToIncrease;
31 await updatePlayer(api.player);
32 api.socket.emit('updatePlayer', api.player);