step 6.3: done
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user