final List<Integer> reserved = bot.queueHandler.getReservedItems();
final List<Long> alreadyTrade = new ArrayList<Long>();
for (final long child : trade.MyTrade) {
final Item item = trade.MyInventory.getItem(child);
if (item != null) {
if (item.defIndex < 5000 || item.defIndex > 5002) {
if (reserved.contains(item.defIndex)) {
alreadyTrade.add(child);
reserved.remove((Integer) item.defIndex);
if (scrapA > 0) {
scrapA--;
} else {
scrapB--;
}
} else {
trade.removeItem(child);
reservedGiven.remove((Integer) item.defIndex);
usedSlots.remove(child);
}
}
}
}
for (final long child : trade.MyItems.getIds()) {
final Item item = trade.MyInventory.getItem(child);
if (item != null) {
if (reserved.contains(item.defIndex) && !alreadyTrade.contains(item.id)) {
trade.addItem(child, slot++);
reservedGiven.add(item.defIndex);
reserved.remove((Integer) item.defIndex);
if (scrapA > 0) {
scrapA--;
} else {
scrapB--;
}
}
}
}
if (reserved.size() > 0) {
// This really shouldn't happen :/
trade.sendMessage("Missing " + reserved.size() + " of your reserved items. Join the queue again to get them.");
}
for (final long child : trade.MyTrade) {
final Item item = trade.MyInventory.getItem(child);
if (item.defIndex == 5000) {
cScrap++;
} else if (item.defIndex == 5001) {
cScrap += 3;
} else if (item.defIndex == 5002) {