Botcraft 26.3
Loading...
Searching...
No Matches
Botcraft::InventoryManager Class Reference

#include <InventoryManager.hpp>

Inheritance diagram for Botcraft::InventoryManager:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Packet, AllPackets >

Public Member Functions

 InventoryManager (const std::shared_ptr< NetworkManager > &network_manager)
 
void SetIndexHotbarSelected (const short index)
 
std::shared_ptr< Window > GetWindow (const short window_id) const
 
short GetFirstOpenedWindowId () const
 
std::shared_ptr< Window > GetPlayerInventory () const
 
short GetIndexHotbarSelected () const
 
ProtocolCraft::Slot GetHotbarSelected () const
 
ProtocolCraft::Slot GetOffHand () const
 
ProtocolCraft::Slot GetCursor () const
 
void EraseInventory (const short window_id)
 
int SendInventoryTransaction (const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &transaction)
 
std::vector< ProtocolCraft::MerchantOffer > GetAvailableMerchantOffers () const
 
void IncrementMerchantOfferUse (const int index)
 

Private Member Functions

void SetIndexHotbarSelectedLocal (const short index)
 
void SetCursor (const ProtocolCraft::Slot &c)
 
void AddInventory (const short window_id, const InventoryType window_type)
 
void SetSlot (const short window_id, const short index, const ProtocolCraft::Slot &slot)
 
void SynchronizeContainerPlayerInventory (const short window_id)
 
void SetStateId (const short window_id, const int state_id)
 
InventoryTransaction PrepareTransactionImpl (const std::shared_ptr< Window > &window, const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &transaction)
 "think" about the changes made by this transaction, filling in the necessary values in the packet, must be called with inventory_manager_mutex locked
 
virtual void Handle (ProtocolCraft::ClientboundContainerSetSlotPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundContainerSetContentPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundOpenScreenPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundSetHeldSlotPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundMerchantOffersPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundContainerClosePacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundSetCursorItemPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundSetPlayerInventoryPacket &packet) override
 
void ApplyTransactionImpl (const InventoryTransaction &transaction)
 

Private Attributes

std::shared_mutex inventory_manager_mutex
 
std::map< short, std::shared_ptr< Window > > inventories
 
short index_hotbar_selected
 
ProtocolCraft::Slot cursor
 
int trading_container_id
 
std::vector< ProtocolCraft::MerchantOffer > available_trades
 
std::shared_ptr< NetworkManager > network_manager
 

Detailed Description

Definition at line 37 of file InventoryManager.hpp.

Constructor & Destructor Documentation

◆ InventoryManager()

Botcraft::InventoryManager::InventoryManager ( const std::shared_ptr< NetworkManager > &  network_manager)

Member Function Documentation

◆ AddInventory()

void Botcraft::InventoryManager::AddInventory ( const short  window_id,
const InventoryType  window_type 
)
private

Definition at line 235 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

Referenced by Handle().

◆ ApplyTransactionImpl()

void Botcraft::InventoryManager::ApplyTransactionImpl ( const InventoryTransaction &  transaction)
private

◆ EraseInventory()

void Botcraft::InventoryManager::EraseInventory ( const short  window_id)

◆ GetAvailableMerchantOffers()

std::vector< MerchantOffer > Botcraft::InventoryManager::GetAvailableMerchantOffers ( ) const

Definition at line 518 of file InventoryManager.cpp.

References available_trades, and inventory_manager_mutex.

◆ GetCursor()

Slot Botcraft::InventoryManager::GetCursor ( ) const

Definition at line 251 of file InventoryManager.cpp.

References cursor, and inventory_manager_mutex.

◆ GetFirstOpenedWindowId()

short Botcraft::InventoryManager::GetFirstOpenedWindowId ( ) const

◆ GetHotbarSelected()

Slot Botcraft::InventoryManager::GetHotbarSelected ( ) const

◆ GetIndexHotbarSelected()

short Botcraft::InventoryManager::GetIndexHotbarSelected ( ) const

Definition at line 80 of file InventoryManager.cpp.

References index_hotbar_selected, and inventory_manager_mutex.

Referenced by GetHotbarSelected().

◆ GetOffHand()

Slot Botcraft::InventoryManager::GetOffHand ( ) const

◆ GetPlayerInventory()

std::shared_ptr< Window > Botcraft::InventoryManager::GetPlayerInventory ( ) const

Definition at line 75 of file InventoryManager.cpp.

References GetWindow(), and Botcraft::Window::PLAYER_INVENTORY_INDEX.

Referenced by GetHotbarSelected(), and GetOffHand().

◆ GetWindow()

std::shared_ptr< Window > Botcraft::InventoryManager::GetWindow ( const short  window_id) const

Definition at line 64 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

Referenced by GetPlayerInventory(), and Handle().

◆ Handle() [1/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundContainerClosePacket &  packet)
overrideprivatevirtual

Definition at line 676 of file InventoryManager.cpp.

References EraseInventory().

◆ Handle() [2/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundContainerSetContentPacket &  packet)
overrideprivatevirtual

Definition at line 565 of file InventoryManager.cpp.

References GetWindow(), SetCursor(), and SetStateId().

◆ Handle() [3/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundContainerSetSlotPacket &  packet)
overrideprivatevirtual

◆ Handle() [4/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundMerchantOffersPacket &  packet)
overrideprivatevirtual

◆ Handle() [5/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundOpenScreenPacket &  packet)
overrideprivatevirtual

◆ Handle() [6/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundSetCursorItemPacket &  packet)
overrideprivatevirtual

Definition at line 682 of file InventoryManager.cpp.

References SetCursor().

◆ Handle() [7/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundSetHeldSlotPacket &  packet)
overrideprivatevirtual

Definition at line 620 of file InventoryManager.cpp.

◆ Handle() [8/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundSetPlayerInventoryPacket &  packet)
overrideprivatevirtual

Definition at line 687 of file InventoryManager.cpp.

References Botcraft::Window::PLAYER_INVENTORY_INDEX, and SetSlot().

◆ IncrementMerchantOfferUse()

void Botcraft::InventoryManager::IncrementMerchantOfferUse ( const int  index)

Definition at line 524 of file InventoryManager.cpp.

References available_trades, inventory_manager_mutex, and LOG_WARNING.

◆ PrepareTransactionImpl()

InventoryTransaction Botcraft::InventoryManager::PrepareTransactionImpl ( const std::shared_ptr< Window > &  window,
const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &  transaction 
)
private

"think" about the changes made by this transaction, filling in the necessary values in the packet, must be called with inventory_manager_mutex locked

Parameters
windowThe container the transaction takes place in
transactionThe transaction to update with the modifications
Returns
An InventoryTransaction with the modified slots and carried item

Definition at line 263 of file InventoryManager.cpp.

References Botcraft::Crafting, cursor, Botcraft::AssetsManager::getInstance(), ProtocolCraft::Slot::IsEmptySlot(), Botcraft::AssetsManager::Items(), LOG_ERROR, Botcraft::PlayerInventory, and ProtocolCraft::Slot::SameItem().

Referenced by SendInventoryTransaction().

◆ SendInventoryTransaction()

int Botcraft::InventoryManager::SendInventoryTransaction ( const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &  transaction)

◆ SetCursor()

void Botcraft::InventoryManager::SetCursor ( const ProtocolCraft::Slot &  c)
private

Definition at line 257 of file InventoryManager.cpp.

References cursor, and inventory_manager_mutex.

Referenced by Handle(), Handle(), and Handle().

◆ SetIndexHotbarSelected()

void Botcraft::InventoryManager::SetIndexHotbarSelected ( const short  index)

Definition at line 29 of file InventoryManager.cpp.

References network_manager, and SetIndexHotbarSelectedLocal().

◆ SetIndexHotbarSelectedLocal()

void Botcraft::InventoryManager::SetIndexHotbarSelectedLocal ( const short  index)
private

Definition at line 245 of file InventoryManager.cpp.

References index_hotbar_selected, and inventory_manager_mutex.

Referenced by SetIndexHotbarSelected().

◆ SetSlot()

void Botcraft::InventoryManager::SetSlot ( const short  window_id,
const short  index,
const ProtocolCraft::Slot &  slot 
)
private

Definition at line 38 of file InventoryManager.cpp.

References inventories, inventory_manager_mutex, and LOG_WARNING.

Referenced by Handle(), and Handle().

◆ SetStateId()

void Botcraft::InventoryManager::SetStateId ( const short  window_id,
const int  state_id 
)
private

Definition at line 223 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

Referenced by Handle(), and Handle().

◆ SynchronizeContainerPlayerInventory()

void Botcraft::InventoryManager::SynchronizeContainerPlayerInventory ( const short  window_id)
private

Member Data Documentation

◆ available_trades

std::vector<ProtocolCraft::MerchantOffer> Botcraft::InventoryManager::available_trades
private

◆ cursor

ProtocolCraft::Slot Botcraft::InventoryManager::cursor
private

◆ index_hotbar_selected

short Botcraft::InventoryManager::index_hotbar_selected
private

◆ inventories

std::map<short, std::shared_ptr<Window> > Botcraft::InventoryManager::inventories
private

◆ inventory_manager_mutex

◆ network_manager

std::shared_ptr<NetworkManager> Botcraft::InventoryManager::network_manager
private

Definition at line 133 of file InventoryManager.hpp.

Referenced by SendInventoryTransaction(), and SetIndexHotbarSelected().

◆ trading_container_id

int Botcraft::InventoryManager::trading_container_id
private

Definition at line 129 of file InventoryManager.hpp.

Referenced by EraseInventory(), Handle(), and InventoryManager().


The documentation for this class was generated from the following files: