Team Fortress 2 Source Code as on 22/4/2020
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.

70 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Functions related to dynamic recipes
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "econ_quests.h"
  8. #ifndef GC_DLL
  9. #include "quest_objective_manager.h"
  10. #endif
  11. bool IsQuestItemUnidentified( const CEconItem* pQuestItem )
  12. {
  13. return pQuestItem && IsUnacknowledged( pQuestItem->GetInventoryToken() );
  14. }
  15. bool IsQuestItemReadyToTurnIn( const IEconItemInterface* pQuestItem )
  16. {
  17. uint32 nRequiredPoints = pQuestItem->GetItemDefinition()->GetQuestDef()->GetMaxStandardPoints();
  18. uint32 nEarnedStandardPoints = GetEarnedStandardPoints( pQuestItem );
  19. uint32 nEarnedBonusPoints = GetEarnedBonusPoints( pQuestItem );
  20. return ( nEarnedStandardPoints + nEarnedBonusPoints ) >= nRequiredPoints;
  21. }
  22. bool IsQuestItemFullyCompleted( const IEconItemInterface* pQuestItem )
  23. {
  24. uint32 nRequiredStandardPoints = pQuestItem->GetItemDefinition()->GetQuestDef()->GetMaxStandardPoints();
  25. uint32 nRequiredBonusPoints = pQuestItem->GetItemDefinition()->GetQuestDef()->GetMaxBonusPoints();
  26. uint32 nEarnedStandardPoints = GetEarnedStandardPoints( pQuestItem );
  27. uint32 nEarnedBonusPoints = GetEarnedBonusPoints( pQuestItem );
  28. return ( nEarnedStandardPoints + nEarnedBonusPoints ) == ( nRequiredStandardPoints + nRequiredBonusPoints );
  29. }
  30. uint32 GetEarnedStandardPoints( const IEconItemInterface* pQuestItem )
  31. {
  32. #ifndef GC_DLL
  33. const CQuestItemTracker* pItemTracker = assert_cast< const CQuestItemTracker* >( QuestObjectiveManager()->GetTypedTracker< CQuestItemTracker* >( pQuestItem->GetID() ) );
  34. if ( pItemTracker )
  35. {
  36. return pItemTracker->GetEarnedStandardPoints();
  37. }
  38. #endif
  39. uint32 nEarnedStandardPoints = 0;
  40. static CSchemaAttributeDefHandle pAttribDef_EarnedStandardPoints( "quest earned standard points" );
  41. pQuestItem->FindAttribute( pAttribDef_EarnedStandardPoints, &nEarnedStandardPoints );
  42. return nEarnedStandardPoints;
  43. }
  44. uint32 GetEarnedBonusPoints( const IEconItemInterface* pQuestItem )
  45. {
  46. #ifndef GC_DLL
  47. const CQuestItemTracker* pItemTracker = assert_cast< const CQuestItemTracker* >( QuestObjectiveManager()->GetTypedTracker< CQuestItemTracker* >( pQuestItem->GetID() ) );
  48. if ( pItemTracker )
  49. {
  50. return pItemTracker->GetEarnedBonusPoints();
  51. }
  52. #endif
  53. uint32 nEarnedBonusPoints = 0;
  54. static CSchemaAttributeDefHandle pAttribDef_EarnedBonusPoints( "quest earned bonus points" );
  55. pQuestItem->FindAttribute( pAttribDef_EarnedBonusPoints, &nEarnedBonusPoints );
  56. return nEarnedBonusPoints;
  57. }