This commit is contained in:
dinomking33 2024-05-29 23:01:34 -05:00
parent cce5755366
commit d4e6acf9b7
2 changed files with 49 additions and 32 deletions

View File

@ -161,7 +161,7 @@ const EquipmentMap& InventoryComponent::GetEquippedItems() const {
return m_Equipped; return m_Equipped;
} }
void InventoryComponent::AddItem( std::vector<LWOOBJID> InventoryComponent::AddItem(
const LOT lot, const LOT lot,
const uint32_t count, const uint32_t count,
eLootSourceType lootSourceType, eLootSourceType lootSourceType,
@ -175,90 +175,90 @@ void InventoryComponent::AddItem(
const int32_t sourceType, const int32_t sourceType,
const bool bound, const bool bound,
int32_t preferredSlot) { int32_t preferredSlot) {
std::vector<LWOOBJID> toReturn;
LOG("AddItem called with parameters: LOT %i, Count %u, LootSourceType %i, InventoryType %i, Parent %llu, ShowFlyingLoot %i, IsModMoveAndEquip %i, SubKey %llu, InventorySourceType %i, SourceType %i, Bound %i, PreferredSlot %i",
lot, count, lootSourceType, inventoryType, parent, showFlyingLoot, isModMoveAndEquip, subKey, inventorySourceType, sourceType, bound, preferredSlot);
if (count == 0) { if (count == 0) {
LOG("Attempted to add 0 of item (%i) to the inventory!", lot); LOG("Attempted to add 0 of item (%i) to the inventory!", lot);
return toReturn;
return;
} }
if (!Inventory::IsValidItem(lot)) { if (!Inventory::IsValidItem(lot)) {
if (lot > 0) { if (lot > 0) {
LOG("Attempted to add invalid item (%i) to the inventory!", lot); LOG("Attempted to add invalid item (%i) to the inventory!", lot);
} }
return toReturn;
return;
} }
if (inventoryType == INVALID) { if (inventoryType == INVALID) {
inventoryType = Inventory::FindInventoryTypeForLot(lot); inventoryType = Inventory::FindInventoryTypeForLot(lot);
LOG("InventoryType was INVALID, found InventoryType %i for LOT %i", inventoryType, lot);
} }
auto* missions = static_cast<MissionComponent*>(this->m_Parent->GetComponent(eReplicaComponentType::MISSION)); auto* missions = static_cast<MissionComponent*>(this->m_Parent->GetComponent(eReplicaComponentType::MISSION));
auto* inventory = GetInventory(inventoryType); auto* inventory = GetInventory(inventoryType);
LOG("Retrieved inventory of type %i", inventoryType);
if (!config.empty() || bound) { if (!config.empty() || bound) {
LOG("Adding item with config or bound. Config size: %lu, Bound: %i", config.size(), bound);
const auto slot = preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot) ? preferredSlot : inventory->FindEmptySlot(); const auto slot = preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot) ? preferredSlot : inventory->FindEmptySlot();
if (slot == -1) { if (slot == -1) {
LOG("Failed to find empty slot for inventory (%i)!", inventoryType); LOG("Failed to find empty slot for inventory (%i)!", inventoryType);
return toReturn;
return;
} }
auto* item = new Item(lot, inventory, slot, count, config, parent, showFlyingLoot, isModMoveAndEquip, subKey, bound, lootSourceType); auto* item = new Item(lot, inventory, slot, count, config, parent, showFlyingLoot, isModMoveAndEquip, subKey, bound, lootSourceType);
toReturn.push_back(item->GetId());
invTransferred.push_back(item->GetId());
LOG("Created new item with LOT %i in slot %i", lot, slot);
if (missions != nullptr && !IsTransferInventory(inventoryType)) { if (missions != nullptr && !IsTransferInventory(inventoryType)) {
LOG("Progressing mission for adding item with LOT %i, count %u", lot, count);
missions->Progress(eMissionTaskType::GATHER, lot, LWOOBJID_EMPTY, "", count, IsTransferInventory(inventorySourceType)); missions->Progress(eMissionTaskType::GATHER, lot, LWOOBJID_EMPTY, "", count, IsTransferInventory(inventorySourceType));
} }
return toReturn;
return;
} }
const auto info = Inventory::FindItemComponent(lot); const auto info = Inventory::FindItemComponent(lot);
LOG("Retrieved item component info for LOT %i", lot);
auto left = count; auto left = count;
int32_t outOfSpace = 0; int32_t outOfSpace = 0;
auto stack = static_cast<uint32_t>(info.stackSize); auto stack = static_cast<uint32_t>(info.stackSize);
bool isBrick = inventoryType == eInventoryType::BRICKS || (stack == 0 && info.itemType == 1); bool isBrick = inventoryType == eInventoryType::BRICKS || (stack == 0 && info.itemType == 1);
// info.itemType of 1 is item type brick
if (isBrick) { if (isBrick) {
stack = UINT32_MAX; stack = UINT32_MAX;
} else if (stack == 0) { } else if (stack == 0) {
stack = 1; stack = 1;
} }
auto* existing = FindItemByLot(lot, inventoryType); LOG("Stack size determined: %u, IsBrick: %i", stack, isBrick);
auto* existing = FindItemByLot(lot, inventoryType);
if (existing != nullptr) { if (existing != nullptr) {
const auto delta = std::min<uint32_t>(left, stack - existing->GetCount()); const auto delta = std::min<uint32_t>(left, stack - existing->GetCount());
left -= delta; left -= delta;
existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot, lootSourceType); existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot, lootSourceType);
LOG("Updated existing item with LOT %i, new count %u", lot, existing->GetCount());
if (isModMoveAndEquip) { if (isModMoveAndEquip) {
existing->Equip(); existing->Equip();
LOG("Equipped item with LOT %i", lot);
isModMoveAndEquip = false; isModMoveAndEquip = false;
} }
} }
// If we have some leftover and we aren't bricks, make a new stack
while (left > 0 && (!isBrick || (isBrick && !existing))) { while (left > 0 && (!isBrick || (isBrick && !existing))) {
const auto size = std::min(left, stack); const auto size = std::min(left, stack);
left -= size; left -= size;
int32_t slot; int32_t slot;
if (preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot)) { if (preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot)) {
slot = preferredSlot; slot = preferredSlot;
preferredSlot = -1; preferredSlot = -1;
} else { } else {
slot = inventory->FindEmptySlot(); slot = inventory->FindEmptySlot();
@ -266,33 +266,49 @@ void InventoryComponent::AddItem(
if (slot == -1) { if (slot == -1) {
outOfSpace += size; outOfSpace += size;
LOG("No empty slot found, out of space for %u items of LOT %i", size, lot);
switch (sourceType) { switch (sourceType) {
case 0: case 0:
Mail::SendMail(LWOOBJID_EMPTY, "Darkflame Universe", m_Parent, "Lost Reward", "You received an item and didn&apos;t have room for it.", lot, size); Mail::SendMail(LWOOBJID_EMPTY, "Darkflame Universe", m_Parent, "Lost Reward", "You received an item and didn't have room for it.", lot, size);
LOG("Sent mail for lost reward: LOT %i, count %u", lot, size);
break; break;
case 1: case 1:
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
GameMessages::SendDropClientLoot(this->m_Parent, this->m_Parent->GetObjectID(), lot, 0, this->m_Parent->GetPosition(), 1); GameMessages::SendDropClientLoot(this->m_Parent, this->m_Parent->GetObjectID(), lot, 0, this->m_Parent->GetPosition(), 1);
} }
LOG("Dropped client loot for LOT %i, count %u", lot, size);
break; break;
default: default:
break; break;
} }
continue; continue;
} }
auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey, false, lootSourceType); auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey, false, lootSourceType);
toReturn.push_back(item->GetId());
invTransferred.push_back(item->GetId());
LOG("Created new item with LOT %i in slot %i, count %u", lot, slot, size);
isModMoveAndEquip = false; isModMoveAndEquip = false;
} }
if (missions != nullptr && !IsTransferInventory(inventoryType)) { if (missions != nullptr && !IsTransferInventory(inventoryType)) {
LOG("Progressing mission for adding item with LOT %i, count %u", lot, count - outOfSpace);
missions->Progress(eMissionTaskType::GATHER, lot, LWOOBJID_EMPTY, "", count - outOfSpace, IsTransferInventory(inventorySourceType)); missions->Progress(eMissionTaskType::GATHER, lot, LWOOBJID_EMPTY, "", count - outOfSpace, IsTransferInventory(inventorySourceType));
} }
LOG("AddItem completed for LOT %i, count %u", lot, count);
if (!toReturn.empty()) {
for (const auto& id : toReturn) {
LOG("LWOOBJID IN TORETURN %llu", id);
}
for (const auto& id : invTransferred) {
LOG("LWOOBJID IN INVTRANSFERRED %llu", id);
}
}
return toReturn;
} }
bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound, const bool silent) { bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound, const bool silent) {
@ -318,6 +334,7 @@ bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInvent
} }
void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType inventory, const uint32_t count, const bool showFlyingLot, bool isModMoveAndEquip, const bool ignoreEquipped, const int32_t preferredSlot) { void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType inventory, const uint32_t count, const bool showFlyingLot, bool isModMoveAndEquip, const bool ignoreEquipped, const int32_t preferredSlot) {
std::vector<LWOOBJID> objIds;
if (item == nullptr) { if (item == nullptr) {
return; return;
} }
@ -344,7 +361,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
left -= delta; left -= delta;
AddItem(lot, delta, eLootSourceType::NONE, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot); objIds = AddItem(lot, delta, eLootSourceType::NONE, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot);
item->SetCount(item->GetCount() - delta, false, false); item->SetCount(item->GetCount() - delta, false, false);
@ -359,7 +376,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
const auto delta = std::min<uint32_t>(item->GetCount(), count); const auto delta = std::min<uint32_t>(item->GetCount(), count);
AddItem(lot, delta, eLootSourceType::NONE, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, subkey, origin->GetType(), 0, item->GetBound(), preferredSlot); objIds = AddItem(lot, delta, eLootSourceType::NONE, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, subkey, origin->GetType(), 0, item->GetBound(), preferredSlot);
item->SetCount(item->GetCount() - delta, false, false); item->SetCount(item->GetCount() - delta, false, false);
} }

View File

@ -95,7 +95,7 @@ public:
* @param preferredSlot the preferred slot to store this item * @param preferredSlot the preferred slot to store this item
* @param lootSourceType The source of the loot. Defaults to none. * @param lootSourceType The source of the loot. Defaults to none.
*/ */
void AddItem( std::vector<LWOOBJID> AddItem(
LOT lot, LOT lot,
uint32_t count, uint32_t count,
eLootSourceType lootSourceType = eLootSourceType::NONE, eLootSourceType lootSourceType = eLootSourceType::NONE,
@ -367,7 +367,7 @@ public:
*/ */
void UnequipScripts(Item* unequippedItem); void UnequipScripts(Item* unequippedItem);
std::map<BehaviorSlot, uint32_t> GetSkills(){ return m_Skills; }; std::map<BehaviorSlot, uint32_t> GetSkills() { return m_Skills; };
bool SetSkill(int slot, uint32_t skillId); bool SetSkill(int slot, uint32_t skillId);
bool SetSkill(BehaviorSlot slot, uint32_t skillId); bool SetSkill(BehaviorSlot slot, uint32_t skillId);
@ -379,7 +379,7 @@ private:
* All the inventory this entity possesses * All the inventory this entity possesses
*/ */
std::map<eInventoryType, Inventory*> m_Inventories; std::map<eInventoryType, Inventory*> m_Inventories;
std::vector<LWOOBJID> invTransferred;
/** /**
* The skills that this entity currently has active * The skills that this entity currently has active
*/ */