1 import { server } from '../../lib/server';
2 import { Static, Type } from '@sinclair/typebox';
3 import { prisma } from '../../lib/db';
4 import { ForbiddenError } from '../../lib/http-errors';
5 import {Player} from '@prisma/client';
6 import {maxHp, maxStamina} from '../../formulas';
8 const PlayerInput = Type.Object({
10 playerId: Type.String()
17 type PlayerInputType = Static<typeof PlayerInput>;
19 export const increaseStat = server.post<PlayerInputType, Player>('/v1/accounts/:playerId/stat', {
23 const player = await prisma.player.findUnique({
25 id: req.params.playerId
30 throw new ForbiddenError('Not Allowed');
33 if(player.statPoints <= 0) {
34 throw new ForbiddenError('Insufficient Stat Points');
39 const stats = ['pow', 'zest', 'aha', 'luck', 'woosh', 'wow'];
40 if(stats.indexOf(req.body.stat) < 0) {
41 throw new ForbiddenError('That is not a stat');
44 switch(req.body.stat) {
50 player.hp = maxHp(player.level, player.zest);
54 player.stamina = maxStamina(player.level, player.woosh);
67 await prisma.player.update({
79 stamina: player.stamina,
80 statPoints: player.statPoints