Character Creator

Added the character creation page.
This commit is contained in:
Marces Zastrow
2025-01-10 12:05:05 +01:00
parent b56b73754c
commit 9c45795e80
6 changed files with 385 additions and 344 deletions
Binary file not shown.
+37
View File
@@ -192,7 +192,44 @@ app.get('/games/:gameId/items', (req, res) => {
});
})
// Player Part
// Create Player Character
app.post('/games/character/create', upload.single('image'), (req, res) => {
const {
charName, race, sex, age, job, description,
maxHealth, maxMana, strength, dexterity, agility, endurance,
gameId, playerId
} = req.body;
const imageBuffer = req.file ? req.file.buffer : null;
const stmt = db.prepare(`
INSERT INTO PlayerCharacter (
GameID, PlayerID, CharName, Race, Sex, Age, Job,
description, maxHealth, currentHealth, maxMana, currentMana,
Strength, Dexterity, Agility, Endurance, Level, Gold, Img
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, 0, ?)
`);
stmt.run([
gameId, playerId, charName, race, sex, age, job,
description, maxHealth, maxHealth, maxMana, maxMana,
strength, dexterity, agility, endurance, imageBuffer
], function(err) {
if (err) {
console.error('Database error:', err);
return res.status(500).json({ error: 'Internal server error' });
}
res.status(201).json({
message: 'Character created successfully!',
characterId: this.lastID
});
});
stmt.finalize();
});
// Fetch all Player Characters of Player
app.get('/games/:userId/characters', (req, res) => {
const userId = req.params.userId;