This commit is contained in:
Marces Zastrow
2025-01-17 14:41:56 +01:00
parent e6f017b0b3
commit 50c7c2c550
3 changed files with 143 additions and 41 deletions
Binary file not shown.
+48 -4
View File
@@ -362,6 +362,44 @@ app.put('/games/:gameId/:userId/character', (req, res) => {
stmt.finalize();
});
// Update Player Character
app.put('/games/character/:charId', async (req, res) => {
const charId = req.params.charId;
const {
charName, race, sex, age, job, description,
maxHealth, currentHealth, maxMana, currentMana,
strength, dexterity, agility, endurance,
level, gold
} = req.body;
const stmt = db.prepare(`
UPDATE PlayerCharacter
SET CharName = ?, Race = ?, Sex = ?, Age = ?, Job = ?,
Description = ?, MaxHealth = ?, CurrentHealth = ?,
MaxMana = ?, CurrentMana = ?, Strength = ?,
Dexterity = ?, Agility = ?, Endurance = ?,
Level = ?, Gold = ?
WHERE CharID = ?
`);
stmt.run([
charName, race, sex, age, job, description,
maxHealth, currentHealth, maxMana, currentMana,
strength, dexterity, agility, endurance,
level, gold, charId
], function(err) {
if (err) {
console.error('Database error:', err);
return res.status(500).json({ error: 'Internal server error' });
}
if (this.changes === 0) {
return res.status(404).json({ error: 'Character not found' });
}
res.json({ message: 'Character updated successfully!' });
});
stmt.finalize();
});
// Fetch Player Items
app.get('/games/:gameId/:charId/items', (req, res) => {
const gameId = req.params.gameId;
@@ -424,13 +462,18 @@ app.post('/games/:charId/:itemId/owner', (req, res) => {
})
// Update Item details including owner
app.put('/games/item/:itemId', async (req, res) => {
app.put('/games/item/:itemId', (req, res) => {
const itemId = req.params.itemId;
const {
ItemName, Type, Art, Rarity, MaxDurability, CurrentDurability,
GoldValue, Abilities, OwnerID, AP
} = req.body;
// Validate required fields
if (!ItemName) {
return res.status(400).json({ error: 'Item name is required' });
}
const stmt = db.prepare(`
UPDATE Item
SET ItemName = ?, Type = ?, Art = ?, Rarity = ?,
@@ -440,8 +483,9 @@ app.put('/games/item/:itemId', async (req, res) => {
`);
stmt.run([
ItemName, Type, Art, Rarity, MaxDurability, CurrentDurability,
GoldValue, Abilities, OwnerID, AP, itemId
ItemName, Type, Art, Rarity,
MaxDurability, CurrentDurability, GoldValue,
Abilities, OwnerID, AP, itemId
], function(err) {
if (err) {
console.error('Database error:', err);