Skip to content

Commit

Permalink
retry dynamic property init once. don't do it at all on tag tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed May 28, 2024
1 parent fa6d92c commit 5db568f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 39 deletions.
104 changes: 65 additions & 39 deletions src/game/shared/swarm/rd_inventory_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
SteamItemDef_t m_iAccessoryDef{ 0 };
SteamItemInstanceID_t m_iReplaceItemInstance{ k_SteamItemInstanceIDInvalid };
SteamInventoryResult_t m_hResult{ k_SteamInventoryResultInvalid };
CUtlVector<SteamItemInstanceID_t> m_RetryItemList;
};
CUtlVectorAutoPurge<CraftItemTask_t *> m_CraftingQueue;
bool m_bModalCraftingWaitScreenActive{ false };
Expand All @@ -1131,6 +1132,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
iAccessoryDef,
iReplaceItemInstance,
k_SteamInventoryResultInvalid,
{},
};

bool bHadModal = HasModalCraftingTask();
Expand All @@ -1154,6 +1156,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
case CRAFT_CLAIM_MINOR:
case CRAFT_CLAIM_MAJOR:
case CRAFT_DYNAMIC_PROPERTY_INIT:
case CRAFT_DYNAMIC_PROPERTY_INIT_RETRY:
case CRAFT_USER_DYNAMIC_PROPERTY_UPDATE:
case CRAFT_DELETE:
return true;
Expand Down Expand Up @@ -1188,6 +1191,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
case CRAFT_DELETE:
return true;
case CRAFT_DYNAMIC_PROPERTY_INIT:
case CRAFT_DYNAMIC_PROPERTY_INIT_RETRY:
return pTask->m_iAccessoryDef != BaseModUI::ItemShowcase::MODE_ITEM_DROP;
case CRAFT_PICKUP_MATERIAL:
// returning false to avoid popping up modal errors during gameplay
Expand Down Expand Up @@ -1219,14 +1223,21 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
EResult eResult = pInventory->GetResultStatus( pTask->m_hResult );
if ( eResult != k_EResultOK )
{
Warning( "Crafting task (type %d) failed with EResult %d %s\n", pTask->m_Type, eResult, UTIL_RD_EResultToString( eResult ) );
DebugPrintResult( pTask->m_hResult );

if ( pTask->m_Type == CRAFT_DYNAMIC_PROPERTY_INIT && pTask->m_RetryItemList.Count() )
{
// silently retry the init after re-obtaining a snapshot of the items
pInventory->GetItemsByID( AddCraftItemTask( CRAFT_DYNAMIC_PROPERTY_INIT_RETRY, pTask->m_iAccessoryDef, pTask->m_iReplaceItemInstance ), pTask->m_RetryItemList.Base(), pTask->m_RetryItemList.Count() );
return;
}

if ( !HasModalCraftingTask() )
{
HideModalCraftingWaitScreen();
}

Warning( "Crafting task (type %d) failed with EResult %d %s\n", pTask->m_Type, eResult, UTIL_RD_EResultToString( eResult ) );
DebugPrintResult( pTask->m_hResult );

if ( IsUserInitiatedTask( pTask ) )
{
BaseModUI::GenericConfirmation *pConfirm = assert_cast< BaseModUI::GenericConfirmation * >( BaseModUI::CBaseModPanel::GetSingleton().OpenWindow( BaseModUI::WT_GENERICCONFIRMATION, NULL, false ) );
Expand Down Expand Up @@ -1313,6 +1324,9 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
case CRAFT_DYNAMIC_PROPERTY_INIT:
BaseModUI::ItemShowcase::ShowItems( pTask->m_hResult, 0, -1, ( BaseModUI::ItemShowcase::Mode_t )pTask->m_iAccessoryDef );
break;
case CRAFT_DYNAMIC_PROPERTY_INIT_RETRY:
InitDynamicPropertiesAndShowcase( pTask, ( BaseModUI::ItemShowcase::Mode_t )pTask->m_iAccessoryDef, false, false, true );
break;
case CRAFT_DROP:
InitDynamicPropertiesAndShowcase( pTask, BaseModUI::ItemShowcase::MODE_ITEM_DROP, true );
break;
Expand Down Expand Up @@ -1426,7 +1440,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
}
}
}
void InitDynamicPropertiesAndShowcase( CraftItemTask_t *pTask, BaseModUI::ItemShowcase::Mode_t iMode, bool bCheckPreferences = false, bool bSilenceNotification = false )
void InitDynamicPropertiesAndShowcase( CraftItemTask_t *pTask, BaseModUI::ItemShowcase::Mode_t iMode, bool bCheckPreferences = false, bool bSilenceNotification = false, bool bIsRetry = false )
{
GET_INVENTORY_OR_BAIL;

Expand All @@ -1437,6 +1451,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
CUtlVector<SteamItemDetails_t> items;
items.AddMultipleToTail( nCount );
pInventory->GetResultItems( pTask->m_hResult, items.Base(), &nCount );
CUtlVector<SteamItemInstanceID_t> itemsForInit;

FOR_EACH_VEC( items, i )
{
Expand All @@ -1451,53 +1466,56 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE

bool bHeldBack = false;

FOR_EACH_VEC( pDef->CompressedDynamicProps, j )
if ( !pDef->IsTagTool )
{
if ( V_stricmp( pDef->CompressedDynamicProps[j], "m_unQuantity" ) && !instance.DynamicProps.Defined(pDef->CompressedDynamicProps[j]) )
FOR_EACH_VEC( pDef->CompressedDynamicProps, j )
{
Assert( ReactiveDropInventory::DynamicPropertyDataType( pDef->CompressedDynamicProps[j] ) == FIELD_INTEGER64 );
if ( hUpdate == k_SteamInventoryUpdateHandleInvalid )
if ( V_stricmp( pDef->CompressedDynamicProps[j], "m_unQuantity" ) && !instance.DynamicProps.Defined( pDef->CompressedDynamicProps[j] ) )
{
hUpdate = pInventory->StartUpdateProperties();
Assert( hUpdate != k_SteamInventoryUpdateHandleInvalid );
}
Assert( ReactiveDropInventory::DynamicPropertyDataType( pDef->CompressedDynamicProps[j] ) == FIELD_INTEGER64 );
if ( hUpdate == k_SteamInventoryUpdateHandleInvalid )
{
hUpdate = pInventory->StartUpdateProperties();
Assert( hUpdate != k_SteamInventoryUpdateHandleInvalid );
}

if ( rd_debug_inventory.GetBool() )
Msg( "[C] Initializing missing dynamic property '%s' on item %llu (%d %s) to 0.\n", pDef->CompressedDynamicProps[j], instance.ItemID, instance.ItemDefID, pDef->Name.Get() );
if ( rd_debug_inventory.GetBool() )
Msg( "[C] Initializing missing dynamic property '%s' on item %llu (%d %s) to 0.\n", pDef->CompressedDynamicProps[j], instance.ItemID, instance.ItemDefID, pDef->Name.Get() );

bHeldBack = true;
pInventory->SetProperty( hUpdate, instance.ItemID, pDef->CompressedDynamicProps[j], 0ll );
bHeldBack = true;
pInventory->SetProperty( hUpdate, instance.ItemID, pDef->CompressedDynamicProps[j], 0ll );
}
}
}

if ( !pDef->AccessoryTag.IsEmpty() && instance.Tags.Defined( pDef->AccessoryTag ) )
{
const CUtlStringList &accessories = instance.Tags[pDef->AccessoryTag];
FOR_EACH_VEC( accessories, j )
if ( !pDef->AccessoryTag.IsEmpty() && instance.Tags.Defined( pDef->AccessoryTag ) )
{
SteamItemDef_t accessoryID = V_atoi( accessories[j] );
Assert( accessoryID > 0 && accessoryID < 1000000000 );
const ReactiveDropInventory::ItemDef_t *pAccessoryDef = ReactiveDropInventory::GetItemDef( accessoryID );
Assert( pAccessoryDef );
if ( !pAccessoryDef )
continue;

FOR_EACH_VEC( pAccessoryDef->CompressedDynamicProps, k )
const CUtlStringList &accessories = instance.Tags[pDef->AccessoryTag];
FOR_EACH_VEC( accessories, j )
{
if ( V_stricmp( pAccessoryDef->CompressedDynamicProps[k], "m_unQuantity" ) && !instance.DynamicProps.Defined( pAccessoryDef->CompressedDynamicProps[k] ) )
SteamItemDef_t accessoryID = V_atoi( accessories[j] );
Assert( accessoryID > 0 && accessoryID < 1000000000 );
const ReactiveDropInventory::ItemDef_t *pAccessoryDef = ReactiveDropInventory::GetItemDef( accessoryID );
Assert( pAccessoryDef );
if ( !pAccessoryDef )
continue;

FOR_EACH_VEC( pAccessoryDef->CompressedDynamicProps, k )
{
Assert( ReactiveDropInventory::DynamicPropertyDataType( pAccessoryDef->CompressedDynamicProps[k] ) == FIELD_INTEGER64 );
if ( hUpdate == k_SteamInventoryUpdateHandleInvalid )
if ( V_stricmp( pAccessoryDef->CompressedDynamicProps[k], "m_unQuantity" ) && !instance.DynamicProps.Defined( pAccessoryDef->CompressedDynamicProps[k] ) )
{
hUpdate = pInventory->StartUpdateProperties();
Assert( hUpdate != k_SteamInventoryUpdateHandleInvalid );
Assert( ReactiveDropInventory::DynamicPropertyDataType( pAccessoryDef->CompressedDynamicProps[k] ) == FIELD_INTEGER64 );
if ( hUpdate == k_SteamInventoryUpdateHandleInvalid )
{
hUpdate = pInventory->StartUpdateProperties();
Assert( hUpdate != k_SteamInventoryUpdateHandleInvalid );
}

if ( rd_debug_inventory.GetBool() )
Msg( "[C] Initializing missing dynamic property '%s' on item %llu (%d %s) (from accessory %d %s) to 0.\n", pAccessoryDef->CompressedDynamicProps[k], instance.ItemID, instance.ItemDefID, pDef->Name.Get(), accessoryID, pAccessoryDef->Name.Get() );

bHeldBack = true;
pInventory->SetProperty( hUpdate, instance.ItemID, pAccessoryDef->CompressedDynamicProps[k], 0ll );
}

if ( rd_debug_inventory.GetBool() )
Msg( "[C] Initializing missing dynamic property '%s' on item %llu (%d %s) (from accessory %d %s) to 0.\n", pAccessoryDef->CompressedDynamicProps[k], instance.ItemID, instance.ItemDefID, pDef->Name.Get(), accessoryID, pAccessoryDef->Name.Get() );

bHeldBack = true;
pInventory->SetProperty( hUpdate, instance.ItemID, pAccessoryDef->CompressedDynamicProps[k], 0ll );
}
}
}
Expand All @@ -1511,11 +1529,19 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
if ( !bSilenceNotification )
BaseModUI::ItemShowcase::ShowItems( pTask->m_hResult, i, 1, iMode );
}
else
{
itemsForInit.AddToTail( instance.ItemID );
}
}

if ( hUpdate != k_SteamInventoryUpdateHandleInvalid )
{
pInventory->SubmitUpdateProperties( hUpdate, AddCraftItemTask( bSilenceNotification ? CRAFT_DYNAMIC_PROPERTY_UPDATE : CRAFT_DYNAMIC_PROPERTY_INIT, SteamItemDef_t( iMode ) ) );
if ( !bIsRetry )
{
m_CraftingQueue.Tail()->m_RetryItemList.AddVectorToTail( itemsForInit );
}
}
}
void ReplaceEquippedItemInstance( SteamItemInstanceID_t iOldInstance, SteamInventoryResult_t hResult, uint32 index )
Expand Down
2 changes: 2 additions & 0 deletions src/game/shared/swarm/rd_inventory_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ namespace ReactiveDropInventory
CRAFT_BTS,
// set dynamic properties on newly created item to 0. modal while in progress. notifies user when complete (replaces notification from craft task that queued this).
CRAFT_DYNAMIC_PROPERTY_INIT,
// when CRAFT_DYNAMIC_PROPERTY_INIT fails, we re-request the item IDs and retry initialization once.
CRAFT_DYNAMIC_PROPERTY_INIT_RETRY,
// checking for item drop. notifies user based on preferences if successful.
CRAFT_DROP,
// checking for promo item. notifies user and server if successful.
Expand Down

0 comments on commit 5db568f

Please sign in to comment.