Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
8.7 KiB

  1. //====== Copyright � Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Container that allows client & server access to data in player inventories & loadouts
  4. //
  5. //=============================================================================
  6. #pragma once
  7. #include "econ_item_inventory.h"
  8. #include "shareddefs.h"
  9. #include "cs_shareddefs.h"
  10. #include "econ_item_constants.h"
  11. #include "cstrike15_item_constants.h"
  12. #define LOADOUT_SLOT_USE_BASE_ITEM 0
  13. namespace vgui
  14. {
  15. class Panel;
  16. }
  17. struct baseitemcriteria_t;
  18. //===============================================================================================================
  19. //-----------------------------------------------------------------------------
  20. // Purpose: A single player's inventory.
  21. // On the client, the inventory manager contains contains an instance of this for the local player.
  22. // On the server, each player contains an instance of this.
  23. //-----------------------------------------------------------------------------
  24. class CCSPlayerInventory : public CPlayerInventory
  25. {
  26. DECLARE_CLASS( CCSPlayerInventory, CPlayerInventory );
  27. public:
  28. CCSPlayerInventory();
  29. virtual CEconItemView *GetItemInLoadout( int iClass, int iSlot ) const;
  30. CEconItemView* GetItemInLoadoutFilteredByProhibition( int iClass, int iSlot ) const;
  31. #ifdef CLIENT_DLL
  32. // Removes any item in a loadout slot. If the slot has a base item,
  33. // the player essentially returns to using that item.
  34. // NOTE: This can fail if the player has no backpack space to contain the equipped item.
  35. bool ClearLoadoutSlot( int iClass, int iSlot );
  36. int GetLastCompletedNodeForCampaign( uint32 unCampaignID ) const;
  37. #endif
  38. virtual int GetMaxItemCount( void ) const;
  39. virtual bool CanPurchaseItems( int iItemCount ) const;
  40. virtual int GetPreviewItemDef( void ) const;
  41. bool IsMissionRefuseAllowed( void ) const;
  42. // Derived inventory hooks
  43. virtual void ItemHasBeenUpdated( CEconItemView *pItem, bool bUpdateAckFile, bool bWriteAckFile, EInventoryItemEvent eEventType ) OVERRIDE;
  44. virtual void ItemIsBeingRemoved( CEconItemView *pItem ) OVERRIDE;
  45. virtual void DefaultEquippedDefinitionHasBeenUpdated( CEconDefaultEquippedDefinitionInstanceClient *pDefaultEquippedDefinition ) OVERRIDE;
  46. // Debugging
  47. virtual void DumpInventoryToConsole( bool bRoot );
  48. virtual void NotifyHasNewItems() { OnHasNewItems(); }
  49. public:
  50. float FindInventoryItemWithMaxAttributeValue( char const *szItemType, char const *szAttrClass, CEconItemView **ppItemFound = NULL );
  51. void FindInventoryItemsWithAttribute( char const *szAttrClass, CUtlVector< CEconItemView* > &foundItems, bool bMatchValue = false, uint32 unValue = 0 ); // DEPRECATED. Use CSchemaAttributeDefHandle version instead and use static handles.
  52. void FindInventoryItemsWithAttribute( CSchemaAttributeDefHandle pAttr, CUtlVector< CEconItemView* > &foundItems, CUtlVector< CEconItemView* > *searchSet = NULL, bool bMatchValue = false, uint32 unValue = 0 );
  53. itemid_t GetActiveSeasonItemId( bool bCoin = true /* false is the Pass */ );
  54. uint32 GetActiveQuestID( void ) const;
  55. void RefreshActiveQuestID( void );
  56. bool IsEquipped( CEconItemView * pEconItem, int nTeam );
  57. bool IsEquipped( CEconItemView * pEconItem );
  58. protected:
  59. #ifdef CLIENT_DLL
  60. // Converts an old format inventory to the new format.
  61. void ConvertOldFormatInventoryToNew( void );
  62. #endif
  63. int m_nActiveQuestID;
  64. virtual void OnHasNewItems();
  65. virtual void ValidateInventoryPositions( void );
  66. virtual void SOCacheSubscribed( GCSDK::SOID_t owner, GCSDK::ESOCacheEvent eEvent ) OVERRIDE;
  67. // Extracts the position that should be used to sort items in the inventory from the backend position.
  68. // Necessary if your inventory packs a bunch of info into the position instead of using it just as a position.
  69. virtual int ExtractInventorySortPosition( uint32 iBackendPosition )
  70. {
  71. // Consider unack'd items as -1, so they get stacked up before the 0th slot item
  72. if ( IsUnacknowledged(iBackendPosition) )
  73. return -1;
  74. return ExtractBackpackPositionFromBackend(iBackendPosition);
  75. }
  76. virtual void SOCreated( GCSDK::SOID_t owner, const GCSDK::CSharedObject *pObject, GCSDK::ESOCacheEvent eEvent ) OVERRIDE;
  77. virtual void SOUpdated( GCSDK::SOID_t owner, const GCSDK::CSharedObject *pObject, GCSDK::ESOCacheEvent eEvent ) OVERRIDE;
  78. virtual void SODestroyed( GCSDK::SOID_t owner, const GCSDK::CSharedObject *pObject, GCSDK::ESOCacheEvent eEvent ) OVERRIDE;
  79. protected:
  80. // Global indices of the items in our inventory in the loadout slots
  81. itemid_t m_LoadoutItems[ LOADOUT_COUNT ][ LOADOUT_POSITION_COUNT ];
  82. friend class CCSInventoryManager;
  83. };
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. //-----------------------------------------------------------------------------
  87. class CCSInventoryManager : public CInventoryManager
  88. {
  89. DECLARE_CLASS( CCSInventoryManager, CInventoryManager );
  90. public:
  91. CCSInventoryManager();
  92. virtual bool Init( void );
  93. virtual void PostInit( void );
  94. virtual void Shutdown( void );
  95. virtual void LevelInitPreEntity( void ) OVERRIDE;
  96. #ifdef CLIENT_DLL
  97. virtual CPlayerInventory *GeneratePlayerInventoryObject() const { return new CCSPlayerInventory; }
  98. // Get the number of items picked up
  99. virtual int GetNumItemPickedUpItems( void );
  100. // Show the player a pickup screen with any items they've collected recently, if any
  101. virtual bool ShowItemsPickedUp( bool bForce = false, bool bReturnToGame = true, bool bNoPanel = false );
  102. void UpdateUnacknowledgedItems( void );
  103. void RebuildUnacknowledgedItemList( CUtlVector< CEconItemView* > *pVecItemsAckedOnClientOnly = NULL );
  104. // Get list of unacknowledged items. Optionally will rebuild the list before returning.
  105. CUtlVector<CEconItemView*> &GetUnacknowledgedItems( bool bRefreshList );
  106. void AcknowledgeUnacknowledgedItems( void );
  107. bool AcknowledgeUnacknowledgedItem( itemid_t ui64ItemID );
  108. // Show the player a pickup screen with the items they've crafted
  109. virtual void ShowItemsCrafted( CUtlVector<itemid_t> *vecCraftedIndices );
  110. // Force the player to discard an item to make room for a new item, if they have one
  111. virtual bool CheckForRoomAndForceDiscard( void );
  112. #endif
  113. // Does a mapping to a "class" index based on a class index and a preset index, so that presets can be stored in the GC.
  114. virtual equipped_class_t DoClassMapping( equipped_class_t unClass, equipped_preset_t unPreset );
  115. // Returns the item data for the base item in the loadout slot for a given class
  116. CEconItemView *GetBaseItemForTeam( int iClass, int iSlot );
  117. void GenerateBaseItems( void );
  118. // Gets the specified inventory for the steam ID
  119. CCSPlayerInventory *GetInventoryForPlayer( const CSteamID &playerID );
  120. // Returns the item in the specified loadout slot for a given class
  121. CEconItemView *GetItemInLoadoutForTeam( int iClass, int iSlot, CSteamID *pID = NULL );
  122. int GetSlotForBaseOrDefaultEquipped( int iClass, item_definition_index_t );
  123. // Fills out the vector with the sets that are currently active on the specified player & class
  124. void GetActiveSets( CUtlVector<const CEconItemSetDefinition *> *pItemSets, CSteamID steamIDForPlayer, int iClass );
  125. // We're generating a base item. We need to add the game-specific keys to the criteria so that it'll find the right base item.
  126. virtual void AddBaseItemCriteria( baseitemcriteria_t *pCriteria, CItemSelectionCriteria *pSelectionCriteria );
  127. private:
  128. // Base items, returned for slots that the player doesn't have anything in
  129. CEconItemView m_pBaseLoadoutItems[ LOADOUT_COUNT ][ LOADOUT_POSITION_COUNT ];
  130. #ifdef CLIENT_DLL
  131. // On the client, we have a single inventory for the local player. Stored here, instead of in the
  132. // local player entity, because players need to access it while not being connected to a server.
  133. public:
  134. CPlayerInventory *GetLocalInventory( void ) { Assert( m_pLocalInventory ); return m_pLocalInventory; }
  135. CCSPlayerInventory *GetLocalCSInventory( void ) { Assert( m_pLocalInventory ); return m_pLocalInventory; }
  136. // Try and equip the specified item in the specified class's loadout slot
  137. bool EquipItemInLoadout( int iClass, int iSlot, itemid_t iItemID, bool bSwap = false );
  138. bool CleanupDuplicateBaseItems( int iClass );
  139. // Fills out pList with all inventory items that could fit into the specified loadout slot for a given class
  140. int GetAllUsableItemsForSlot( int iClass, int iSlot, unsigned int unUsedEquipRegionMask, CUtlVector<CEconItemView*> *pList );
  141. virtual int GetBackpackPositionFromBackend( uint32 iBackendPosition ) { return ExtractBackpackPositionFromBackend(iBackendPosition); }
  142. private:
  143. CCSPlayerInventory *m_pLocalInventory;
  144. CUtlVector<CEconItemView*> m_UnacknowledgedItems;
  145. #endif // CLIENT_DLL
  146. };
  147. CCSInventoryManager *CSInventoryManager( void );
  148. bool AreSlotsConsideredIdentical( int iBaseSlot, int iTestSlot );