mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-25 02:02:25 +00:00
Fix PutItemInInventoryWithStacking: complete stack-fill pass before using empty slots
Co-authored-by: Valorith <76063792+Valorith@users.noreply.github.com>
This commit is contained in:
parent
e85047f234
commit
0ac9625881
@ -4701,15 +4701,13 @@ bool Client::PutItemInInventoryWithStacking(EQ::ItemInstance *inst)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<temp> queue;
|
std::vector<temp> queue;
|
||||||
|
std::vector<int16> empty_bag_slots;
|
||||||
auto quantity = inst->GetCharges();
|
auto quantity = inst->GetCharges();
|
||||||
|
|
||||||
for (int i = EQ::invslot::GENERAL_BEGIN; i <= EQ::invslot::GENERAL_END; i++) {
|
for (int i = EQ::invslot::GENERAL_BEGIN; i <= EQ::invslot::GENERAL_END; i++) {
|
||||||
auto inv_inst = GetInv().GetItem(i);
|
auto inv_inst = GetInv().GetItem(i);
|
||||||
if (!inv_inst) {
|
if (!inv_inst) {
|
||||||
LogError("Found a slot {} in general inventory", i);
|
continue;
|
||||||
inst->SetCharges(quantity);
|
|
||||||
PutItemInInventory(i, *inst, true);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 base_slot_id = EQ::InventoryProfile::CalcSlotId(i, EQ::invbag::SLOT_BEGIN);
|
int16 base_slot_id = EQ::InventoryProfile::CalcSlotId(i, EQ::invbag::SLOT_BEGIN);
|
||||||
@ -4722,10 +4720,8 @@ bool Client::PutItemInInventoryWithStacking(EQ::ItemInstance *inst)
|
|||||||
|
|
||||||
auto bag_inst = GetInv().GetItem(base_slot_id + bag_slot);
|
auto bag_inst = GetInv().GetItem(base_slot_id + bag_slot);
|
||||||
if (!bag_inst && inv_inst->GetItem()->BagSize >= inst->GetItem()->Size) {
|
if (!bag_inst && inv_inst->GetItem()->BagSize >= inst->GetItem()->Size) {
|
||||||
LogError("Found a parent {} base_slot_id {} bag_slot {} in bag", i, base_slot_id, bag_slot);
|
empty_bag_slots.push_back(base_slot_id + bag_slot);
|
||||||
inst->SetCharges(quantity);
|
continue;
|
||||||
PutItemInInventory(base_slot_id + bag_slot, *inst, true);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bag_inst && bag_inst->IsStackable() && bag_inst->GetID() == inst->GetID()) {
|
if (bag_inst && bag_inst->IsStackable() && bag_inst->GetID() == inst->GetID()) {
|
||||||
@ -4736,12 +4732,6 @@ bool Client::PutItemInInventoryWithStacking(EQ::ItemInstance *inst)
|
|||||||
temp tmp = {temp_slot, quantity};
|
temp tmp = {temp_slot, quantity};
|
||||||
queue.push_back(tmp);
|
queue.push_back(tmp);
|
||||||
quantity = 0;
|
quantity = 0;
|
||||||
LogError(
|
|
||||||
"Found an item parent {} base_slot_id {} bag_slot {} in bag with ENOUGH space",
|
|
||||||
i,
|
|
||||||
base_slot_id,
|
|
||||||
bag_slot
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4749,12 +4739,6 @@ bool Client::PutItemInInventoryWithStacking(EQ::ItemInstance *inst)
|
|||||||
temp tmp = {temp_slot, stack_size - bag_inst_quantity};
|
temp tmp = {temp_slot, stack_size - bag_inst_quantity};
|
||||||
queue.push_back(tmp);
|
queue.push_back(tmp);
|
||||||
quantity -= stack_size - bag_inst_quantity;
|
quantity -= stack_size - bag_inst_quantity;
|
||||||
LogError(
|
|
||||||
"Found an item parent {} base_slot_id {} bag_slot {} in bag with SOME space",
|
|
||||||
i,
|
|
||||||
base_slot_id,
|
|
||||||
bag_slot
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4770,25 +4754,29 @@ bool Client::PutItemInInventoryWithStacking(EQ::ItemInstance *inst)
|
|||||||
}
|
}
|
||||||
bag_inst->SetCharges(i.quantity + bag_inst->GetCharges());
|
bag_inst->SetCharges(i.quantity + bag_inst->GetCharges());
|
||||||
PutItemInInventory(i.slot_id, *bag_inst, true);
|
PutItemInInventory(i.slot_id, *bag_inst, true);
|
||||||
LogError("Write out data. Item {} quantity {} slot {}", bag_inst->GetItem()->Name, i.quantity, i.slot_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
database.TransactionCommit();
|
database.TransactionCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quantity == 0) {
|
if (quantity == 0) {
|
||||||
LogError("Quantity was zero. All items placed in inventory.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inst->SetCharges(quantity);
|
inst->SetCharges(quantity);
|
||||||
|
for (auto slot_id : empty_bag_slots) {
|
||||||
|
if (PutItemInInventory(slot_id, *inst, true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (free_id != INVALID_INDEX &&
|
if (free_id != INVALID_INDEX &&
|
||||||
!EQ::ValueWithin(free_id, EQ::invslot::EQUIPMENT_BEGIN, EQ::invslot::EQUIPMENT_END) &&
|
!EQ::ValueWithin(free_id, EQ::invslot::EQUIPMENT_BEGIN, EQ::invslot::EQUIPMENT_END) &&
|
||||||
PutItemInInventory(free_id, *inst, true)) {
|
PutItemInInventory(free_id, *inst, true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogError("Could not find enough room");
|
LogError("Could not find enough room for item {} (quantity {}) for character {}", inst->GetItem()->Name, quantity, CharacterID());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user