step 6.3: done

This commit is contained in:
bepis
2026-10-21 01:10:23 +11:00
parent 2930c70010
commit cf5c4616d8
4 changed files with 91 additions and 22 deletions
+13 -6
View File
@@ -148,6 +148,19 @@ function sellItem(characterId, itemId, quantity) {
const item = s.itemById.get(itemId);
if (!item) throw new AppError('NOT_FOUND', 'Item not found.', 404);
// Find inventory rows for this (character, item).
const rows = s.inventoryRows.all(characterId, itemId, 1);
if (rows.length === 0) {
throw new AppError('NOT_FOUND', 'Item not in inventory.', 404);
}
// Reject if any row is equipped.
for (const row of rows) {
if (row.equipped_slot !== null) {
throw new AppError('VALIDATION_ERROR', 'Unequip the item before selling.', 400);
}
}
if (item.type !== 'material') {
throw new AppError('VALIDATION_ERROR', 'Only materials can be sold.', 400);
}
@@ -161,12 +174,6 @@ function sellItem(characterId, itemId, quantity) {
sellPrice = Math.max(1, Math.floor(defaultRate * ch.level / item.min_level));
}
// Find inventory rows for this (character, item).
const rows = s.inventoryRows.all(characterId, itemId, 1);
if (rows.length === 0) {
throw new AppError('NOT_FOUND', 'Item not in inventory.', 404);
}
// Calculate how many we can actually sell from available rows.
let remaining = quantity;
const sales = []; // { rowId, qty, sellPrice }