MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / TryModifyingKeyItem

Function TryModifyingKeyItem

TombEngine/Game/pickup/pickup_key_items.cpp:67–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67bool TryModifyingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional<int> amount, ModificationType modType)
68{
69 // kick off the recursion starting at the last element
70 auto result = GetArrayInternal<nInfos - 1>(lara, objectID);
71
72 if (result.first)
73 {
74 auto& amt = result.first[result.second];
75 switch (modType)
76 {
77 case ModificationType::Set:
78 // infinite key items not yet implemented
79 amt = amount.value();
80 break;
81 default:
82 int defaultModify = modType == ModificationType::Add ? kDefaultPickupAmount : -kDefaultPickupAmount;
83 int newVal = int{ result.first[result.second] } + (amount.has_value() ? amount.value() : defaultModify);
84 result.first[result.second] = std::max(0, newVal);
85 }
86 return true;
87 }
88
89 return false;
90}
91
92bool TryAddingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional<int> amount)
93{

Callers 3

TryAddingKeyItemFunction · 0.85
TryRemovingKeyItemFunction · 0.85
SetInventoryCountFunction · 0.85

Calls 2

valueMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected