@@ -59,7 +59,7 @@ bool InventorySystem::AddItem(uint64_t playerId, const LootItem& item, int quant
5959
6060 // Need new slots
6161 while (quantity > 0 ) {
62- if (inventory.inventorySlots .size () >= inventory.maxInventorySize ) {
62+ if (inventory.inventorySlots .size () >= ( uint64_t ) inventory.maxInventorySize ) {
6363 Logger::Error (" Inventory full for player {}" , playerId);
6464 SaveInventory (playerId);
6565 return false ;
@@ -80,6 +80,38 @@ bool InventorySystem::AddItem(uint64_t playerId, const LootItem& item, int quant
8080 return true ;
8181}
8282
83+ bool InventorySystem::MoveItem (uint64_t playerId, int fromSlot, int toSlot) {
84+ std::lock_guard<std::mutex> lock (mutex_);
85+
86+ auto it = playerInventories_.find (playerId);
87+ if (it == playerInventories_.end ())
88+ return false ;
89+
90+ auto & inventory = it->second ;
91+ // Validate slot indices
92+ if (fromSlot < 0 || fromSlot >= static_cast <int >(inventory.inventorySlots .size ()) ||
93+ toSlot < 0 || toSlot >= static_cast <int >(inventory.inventorySlots .size ()))
94+ return false ;
95+
96+ if (fromSlot == toSlot)
97+ return true ; // Nothing to do
98+
99+ auto & slotFrom = inventory.inventorySlots [fromSlot];
100+ auto & slotTo = inventory.inventorySlots [toSlot];
101+
102+ // Swap the contents
103+ std::swap (slotFrom.item , slotTo.item );
104+ std::swap (slotFrom.quantity , slotTo.quantity );
105+ std::swap (slotFrom.equipped , slotTo.equipped );
106+
107+ // Update position fields to match their new indices
108+ slotFrom.position = fromSlot;
109+ slotTo.position = toSlot;
110+
111+ SaveInventory (playerId);
112+ return true ;
113+ }
114+
83115bool InventorySystem::RemoveItem (uint64_t playerId, uint64_t itemId, int quantity) {
84116 std::lock_guard<std::mutex> lock (mutex_);
85117
@@ -137,7 +169,7 @@ bool InventorySystem::EquipItem(uint64_t playerId, int inventorySlot) {
137169 auto & inventory = it->second ;
138170
139171 if (!ValidateSlot (playerId, inventorySlot) ||
140- inventorySlot >= inventory.inventorySlots .size ()) {
172+ ( uint64_t ) inventorySlot >= inventory.inventorySlots .size ()) {
141173 return false ;
142174 }
143175
@@ -151,7 +183,7 @@ bool InventorySystem::EquipItem(uint64_t playerId, int inventorySlot) {
151183 }
152184
153185 int equipSlot = GetEquipmentSlotForItem (*slot.item );
154- if (equipSlot == -1 || equipSlot >= inventory.equipmentSlots .size ()) {
186+ if (equipSlot == -1 || ( uint64_t ) equipSlot >= inventory.equipmentSlots .size ()) {
155187 return false ;
156188 }
157189
@@ -296,6 +328,73 @@ bool InventorySystem::AddGold(uint64_t playerId, int64_t amount) {
296328 return true ;
297329}
298330
331+ bool InventorySystem::RemoveGold (uint64_t playerId, int64_t amount) {
332+ std::lock_guard<std::mutex> lock (mutex_);
333+
334+ auto it = playerInventories_.find (playerId);
335+ if (it == playerInventories_.end ()) {
336+ return false ; // No inventory → cannot remove gold
337+ }
338+
339+ if (amount < 0 ) return false ; // Cannot remove negative amount
340+ if (it->second .gold < amount) return false ; // Insufficient funds
341+
342+ it->second .gold -= amount;
343+ SaveInventory (playerId);
344+ return true ;
345+ }
346+
347+ bool InventorySystem::TransferGold (uint64_t fromPlayerId, uint64_t toPlayerId, int64_t amount) {
348+ if (fromPlayerId == toPlayerId || amount <= 0 )
349+ return false ;
350+
351+ std::lock_guard<std::mutex> lock (mutex_); // Lock once for atomicity
352+
353+ auto fromIt = playerInventories_.find (fromPlayerId);
354+ auto toIt = playerInventories_.find (toPlayerId);
355+
356+ if (fromIt == playerInventories_.end () || toIt == playerInventories_.end ())
357+ return false ; // Both players must have inventories
358+
359+ if (fromIt->second .gold < amount)
360+ return false ; // Insufficient funds
361+
362+ // Perform transfer
363+ fromIt->second .gold -= amount;
364+ toIt->second .gold += amount;
365+
366+ // Cap at max (though gold is int64_t, addition could overflow, but unlikely)
367+ if (toIt->second .gold < 0 ) toIt->second .gold = INT64_MAX;
368+
369+ // Save both inventories (optional – SaveInventory already writes to DB)
370+ SaveInventory (fromPlayerId);
371+ SaveInventory (toPlayerId);
372+ return true ;
373+ }
374+
375+ std::shared_ptr<LootItem> InventorySystem::GetItem (uint64_t playerId, int slot) {
376+ std::lock_guard<std::mutex> lock (mutex_);
377+
378+ auto it = playerInventories_.find (playerId);
379+ if (it == playerInventories_.end ())
380+ return nullptr ;
381+
382+ if (slot < 0 || slot >= static_cast <int >(it->second .inventorySlots .size ()))
383+ return nullptr ;
384+
385+ const auto & slotData = it->second .inventorySlots [slot];
386+ return slotData.item ; // may be nullptr if slot empty
387+ }
388+
389+ std::vector<InventorySlot> InventorySystem::GetInventory (uint64_t playerId) const {
390+ std::lock_guard<std::mutex> lock (mutex_);
391+ auto it = playerInventories_.find (playerId);
392+ if (it == playerInventories_.end ()) {
393+ return {};
394+ }
395+ return it->second .inventorySlots ;
396+ }
397+
299398// Helper method implementations
300399bool InventorySystem::ValidateSlot (uint64_t playerId, int slot) const {
301400 auto it = playerInventories_.find (playerId);
@@ -318,6 +417,8 @@ int InventorySystem::GetEquipmentSlotForItem(const LootItem& item) const {
318417}
319418
320419bool InventorySystem::MeetsRequirements (uint64_t playerId, const LootItem& item) const {
420+ (void )playerId;
421+ (void )item;
321422 // TODO: Implement player level and other requirement checks
322423 // For now, just check level requirement
323424 // This would need access to player stats/level
0 commit comments