app.get('/player', authEndpoint, async (req: AuthRequest, res: Response) => {
const inventory = await getEquippedItems(req.player.id);
- res.send(renderPlayerBar(req.player, inventory) + (await renderProfilePage(req.player)));
+ res.send(renderPlayerBar(req.player, inventory) + renderProfilePage(req.player));
+});
+
+app.post('/player/stat/:stat', authEndpoint, async (req: AuthRequest, res: Response) => {
+ const stat = req.params.stat;
+ if(!['strength', 'constitution', 'dexterity', 'intelligence'].includes(stat)) {
+ res.send(Alert.ErrorAlert(`Sorry, that's not a valid stat to increase`));
+ return;
+ }
+
+ if(req.player.stat_points <= 0) {
+ res.send(Alert.ErrorAlert(`Sorry, you don't have enough stat points`));
+ return;
+ }
+
+ req.player.stat_points -= 1;
+ req.player[stat]++;
+
+ updatePlayer(req.player);
+
+ const equippedItems = await getEquippedItems(req.player.id);
+ res.send(renderPlayerBar(req.player, equippedItems) + renderProfilePage(req.player));
});
app.get('/player/skills', authEndpoint, async (req: AuthRequest, res: Response) => {
import { Player, StatDef, StatDisplay } from "../../shared/player";
function statPointIncreaser(stat: StatDisplay) {
- return `<button class="increase-stat emit-event" data-event="spend-stat-point" data-args="${stat.id}">+</button>`;
+ return `<button class="increase-stat" hx-post="/player/stat/${stat.id}" hx-target="#profile">+</button>`;
}
-export async function renderProfilePage(player: Player): Promise<string> {
+export function renderProfilePage(player: Player): string {
let statBreakdown = '';
StatDef.forEach(stat => {