Work on tomorrow

This commit is contained in:
dinomking33 2024-06-02 04:18:20 -05:00
parent 420822aab4
commit 7a325470f1
5 changed files with 70 additions and 46 deletions

View File

@ -1,6 +1,7 @@
#include "InventoryComponent.h" #include "InventoryComponent.h"
#include <sstream> #include <sstream>
#include <ranges>
#include "Entity.h" #include "Entity.h"
#include "Item.h" #include "Item.h"
@ -194,7 +195,12 @@ void InventoryComponent::AddItem(
auto* inventory = GetInventory(inventoryType); auto* inventory = GetInventory(inventoryType);
if (!config.empty() || bound) { if (!config.empty() || bound) {
if (inventoryType == eInventoryType::VENDOR_BUYBACK && buybackItems.size() >= 27) {
RemoveItem(buybackItems.back());
buybackItems.pop_back();
}
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) {
@ -202,10 +208,8 @@ void InventoryComponent::AddItem(
} }
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);
if (inventoryType == eInventoryType::VENDOR_BUYBACK && buybackItems.size() <= 27) {
// Check if inventory type is VENDOR_BUYBACK and manage the inventory size buybackItems.push_front(item->GetId());
if (inventoryType == eInventoryType::VENDOR_BUYBACK) {
ManageVendorBuybackInventory(item->GetId(), inventory);
} }
if (missions != nullptr && !IsTransferInventory(inventoryType)) { if (missions != nullptr && !IsTransferInventory(inventoryType)) {
@ -250,6 +254,11 @@ void InventoryComponent::AddItem(
const auto size = std::min(left, stack); const auto size = std::min(left, stack);
left -= size; left -= size;
if (inventoryType == eInventoryType::VENDOR_BUYBACK && buybackItems.size() >= 27) {
RemoveItem(buybackItems.back());
buybackItems.pop_back();
}
int32_t slot; int32_t slot;
if (preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot)) { if (preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot)) {
slot = preferredSlot; slot = preferredSlot;
@ -280,10 +289,8 @@ void InventoryComponent::AddItem(
} }
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);
if (inventoryType == eInventoryType::VENDOR_BUYBACK && buybackItems.size() <= 27) {
// Check if inventory type is VENDOR_BUYBACK and manage the inventory size buybackItems.push_front(item->GetId());
if (inventoryType == eInventoryType::VENDOR_BUYBACK) {
ManageVendorBuybackInventory(item->GetId(), inventory);
} }
isModMoveAndEquip = false; isModMoveAndEquip = false;
@ -325,6 +332,9 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
} }
auto* origin = item->GetInventory(); auto* origin = item->GetInventory();
if (origin->GetType() == eInventoryType::VENDOR_BUYBACK) {
buybackItems.erase(std::ranges::find(buybackItems, item->GetId()));
}
const auto lot = item->GetLot(); const auto lot = item->GetLot();
@ -366,6 +376,16 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
item->SetCount(item->GetCount() - delta, false, false); item->SetCount(item->GetCount() - delta, false, false);
} }
// if (origin->GetType() == eInventoryType::VENDOR_BUYBACK) {
// auto& items = origin->GetItems();
// int32_t slotItr = 0;
// for (auto* item : items | std::views::values) {
// GameMessages::SendMoveItemInInventory(m_Parent->GetObjectID(), m_Parent->GetSystemAddress(), inventory, item->GetId(), origin->GetType(), 0, slotItr);
// item->SetSlot(slotItr);
// slotItr++;
// }
// }
auto* missionComponent = m_Parent->GetComponent<MissionComponent>(); auto* missionComponent = m_Parent->GetComponent<MissionComponent>();
if (missionComponent != nullptr) { if (missionComponent != nullptr) {
@ -1606,26 +1626,7 @@ bool InventoryComponent::SetSkill(BehaviorSlot slot, uint32_t skillId) {
return true; return true;
} }
void InventoryComponent::ManageVendorBuybackInventory(LWOOBJID newItem, Inventory* inventory) { void InventoryComponent::RemoveItem(LWOOBJID itemId) {
const size_t maxVendorBuybackItems = 27;
if (buybackItems.size() == 26) {
LWOOBJID oldestItemId = buybackItems.front();
buybackItems.pop();
RemoveItem(oldestItemId, inventory->GetType());
}
if (buybackItems.size() >= maxVendorBuybackItems) {
LWOOBJID oldestItemId = buybackItems.front();
buybackItems.pop();
RemoveItem(oldestItemId, inventory->GetType());
}
buybackItems.push(newItem);
}
void InventoryComponent::RemoveItem(LWOOBJID itemId, eInventoryType inventoryType) {
auto* item = FindItemById(itemId); auto* item = FindItemById(itemId);
if (item) { if (item) {
item->SetCount(0); item->SetCount(0);

View File

@ -372,21 +372,12 @@ public:
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);
/**
* Called during AddItem to manage the vendor buyback inventory if the inventory is of that type
*
* @param newItem The item ID which is being moved to the vendor buyback inventory
* @param inventory The entity/vendor's inventory
*/
void ManageVendorBuybackInventory(LWOOBJID newItem, Inventory* inventory);
/** /**
* Called in ManageVendorBuybackInventory to remove an item given the ItemId * Called in ManageVendorBuybackInventory to remove an item given the ItemId
* *
* @param itemId item ID for item being removed * @param itemId item ID for item being removed
* @param inventoryType inventory type
*/ */
void RemoveItem(LWOOBJID itemId, eInventoryType inventoryType); void RemoveItem(LWOOBJID itemId);
~InventoryComponent() override; ~InventoryComponent() override;
@ -398,7 +389,7 @@ private:
/** /**
*A queue of LWOOBJIDs representing the buybackItems which are sold to a vendor *A queue of LWOOBJIDs representing the buybackItems which are sold to a vendor
*/ */
std::queue<LWOOBJID> buybackItems; std::deque<LWOOBJID> buybackItems;
/** /**
* The skills that this entity currently has active * The skills that this entity currently has active
*/ */

View File

@ -6210,3 +6210,27 @@ void GameMessages::SendSlashCommandFeedbackText(Entity* entity, std::u16string t
auto sysAddr = entity->GetSystemAddress(); auto sysAddr = entity->GetSystemAddress();
SEND_PACKET; SEND_PACKET;
} }
void GameMessages::SendMoveItemInInventory(
const LWOOBJID objectId,
const SystemAddress& sysAddr,
eInventoryType destination,
const LWOOBJID item,
const eInventoryType source,
const int32_t responseCode,
const int32_t slot) {
CBITSTREAM;
CMSGHEADER;
bitStream.Write(objectId);
bitStream.Write(eGameMessageType::MOVE_ITEM_IN_INVENTORY);
bitStream.Write(destination != eInventoryType::INVALID);
if (destination != eInventoryType::INVALID) bitStream.Write(destination);
bitStream.Write(item);
bitStream.Write(source);
bitStream.Write(responseCode);
bitStream.Write(slot);
SEND_PACKET;
}

View File

@ -666,6 +666,16 @@ namespace GameMessages {
void HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity); void HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);
void SendSlashCommandFeedbackText(Entity* entity, std::u16string text); void SendSlashCommandFeedbackText(Entity* entity, std::u16string text);
void SendMoveItemInInventory(
const LWOOBJID objectId,
const SystemAddress& sysAddr,
eInventoryType destination,
const LWOOBJID item,
const eInventoryType source,
const int32_t responseCode,
const int32_t slot
);
}; };
#endif // GAMEMESSAGES_H #endif // GAMEMESSAGES_H

View File

@ -82,13 +82,11 @@ void Inventory::SetSize(const uint32_t value) {
int32_t Inventory::FindEmptySlot() { int32_t Inventory::FindEmptySlot() {
if (free <= 6) // Up from 1 if (free <= 6) // Up from 1
{ {
if (type != ITEMS && type != VAULT_ITEMS && type != eInventoryType::VAULT_MODELS) { if (type != ITEMS && type != VAULT_ITEMS && type != eInventoryType::VAULT_MODELS && type != eInventoryType::VENDOR_BUYBACK) {
uint32_t newSize = size; uint32_t newSize = size;
if (type == MODELS) { if (type == MODELS) {
newSize = 240; newSize = 240;
} else if (type == eInventoryType::VENDOR_BUYBACK) {
newSize += 9u;
} else { } else {
newSize += 10u; newSize += 10u;
} }