Botcraft 26.2
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 PrepareTransaction (const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &transaction)
 "think" about the changes made by this transaction, filling in the necessary values in the packet
 
void ApplyTransaction (const InventoryTransaction &transaction)
 Apply a given transaction to a container.
 
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 41 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 230 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

Referenced by Handle().

◆ ApplyTransaction()

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

Apply a given transaction to a container.

Parameters
transactionThe transaction to apply

Definition at line 508 of file InventoryManager.cpp.

References ApplyTransactionImpl(), and inventory_manager_mutex.

Referenced by SendInventoryTransaction().

◆ 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 530 of file InventoryManager.cpp.

References available_trades, and inventory_manager_mutex.

◆ GetCursor()

Slot Botcraft::InventoryManager::GetCursor ( ) const

Definition at line 246 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 73 of file InventoryManager.cpp.

References index_hotbar_selected, and inventory_manager_mutex.

◆ GetOffHand()

Slot Botcraft::InventoryManager::GetOffHand ( ) const

◆ GetPlayerInventory()

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

Definition at line 68 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 57 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

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

◆ Handle() [1/8]

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

Definition at line 689 of file InventoryManager.cpp.

References EraseInventory().

◆ Handle() [2/8]

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

Definition at line 581 of file InventoryManager.cpp.

References GetWindow(), and SetStateId().

◆ Handle() [3/8]

◆ 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

◆ Handle() [7/8]

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

Definition at line 633 of file InventoryManager.cpp.

◆ Handle() [8/8]

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

Definition at line 701 of file InventoryManager.cpp.

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

◆ IncrementMerchantOfferUse()

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

Definition at line 536 of file InventoryManager.cpp.

References available_trades, inventory_manager_mutex, and LOG_WARNING.

◆ PrepareTransaction()

InventoryTransaction Botcraft::InventoryManager::PrepareTransaction ( const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &  transaction)
private

"think" about the changes made by this transaction, filling in the necessary values in the packet

Parameters
transactionThe transaction to update with the modifications
Returns
An InventoryTransaction with various info, depending on the version

Definition at line 258 of file InventoryManager.cpp.

References Botcraft::Crafting, cursor, Botcraft::AssetsManager::getInstance(), GetWindow(), inventory_manager_mutex, 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)

Definition at line 514 of file InventoryManager.cpp.

References ApplyTransaction(), network_manager, and PrepareTransaction().

◆ SetCursor()

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

Definition at line 252 of file InventoryManager.cpp.

References cursor, and inventory_manager_mutex.

Referenced by Handle().

◆ SetIndexHotbarSelected()

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

Definition at line 22 of file InventoryManager.cpp.

References network_manager, and SetIndexHotbarSelectedLocal().

◆ SetIndexHotbarSelectedLocal()

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

Definition at line 240 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 31 of file InventoryManager.cpp.

References inventories, inventory_manager_mutex, and LOG_WARNING.

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

◆ SetStateId()

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

Definition at line 218 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 137 of file InventoryManager.hpp.

Referenced by SendInventoryTransaction(), and SetIndexHotbarSelected().

◆ trading_container_id

int Botcraft::InventoryManager::trading_container_id
private

Definition at line 133 of file InventoryManager.hpp.

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


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