Implement ConsumeItem.
parent
d3e8a701dd
commit
942f011ee0
|
@ -282,7 +282,7 @@ uint32 GetResultTimestamp( SteamInventoryResult_t resultHandle )
|
||||||
STEAM_METHOD_DESC(Returns true if the result belongs to the target steam ID or false if the result does not. This is important when using DeserializeResult to verify that a remote player is not pretending to have a different users inventory.)
|
STEAM_METHOD_DESC(Returns true if the result belongs to the target steam ID or false if the result does not. This is important when using DeserializeResult to verify that a remote player is not pretending to have a different users inventory.)
|
||||||
bool CheckResultSteamID( SteamInventoryResult_t resultHandle, CSteamID steamIDExpected )
|
bool CheckResultSteamID( SteamInventoryResult_t resultHandle, CSteamID steamIDExpected )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("CheckResultSteamID\n");
|
PRINT_DEBUG("CheckResultSteamID %llu\n", steamIDExpected.ConvertToUint64());
|
||||||
//TODO
|
//TODO
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -496,10 +496,37 @@ bool AddPromoItems( SteamInventoryResult_t *pResultHandle, STEAM_ARRAY_COUNT(unA
|
||||||
STEAM_METHOD_DESC(ConsumeItem() removes items from the inventory permanently.)
|
STEAM_METHOD_DESC(ConsumeItem() removes items from the inventory permanently.)
|
||||||
bool ConsumeItem( SteamInventoryResult_t *pResultHandle, SteamItemInstanceID_t itemConsume, uint32 unQuantity )
|
bool ConsumeItem( SteamInventoryResult_t *pResultHandle, SteamItemInstanceID_t itemConsume, uint32 unQuantity )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("ConsumeItem\n");
|
PRINT_DEBUG("ConsumeItem %llu %u\n", itemConsume, unQuantity);
|
||||||
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||||
|
|
||||||
|
auto it = user_items.find(std::to_string(itemConsume));
|
||||||
|
if (it != user_items.end()) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint32 current = it->get<int>();
|
||||||
|
PRINT_DEBUG("ConsumeItem previous %u\n", current);
|
||||||
|
if (current < unQuantity) unQuantity = current;
|
||||||
|
uint32 result = current - unQuantity;
|
||||||
|
if (result == 0) {
|
||||||
|
user_items.erase(it);
|
||||||
|
} else {
|
||||||
|
*it = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {}
|
||||||
|
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Steam_Inventory_Requests* request = new_inventory_result(false, &itemConsume, 1);
|
||||||
|
|
||||||
|
if (pResultHandle != nullptr)
|
||||||
|
*pResultHandle = request->inventory_result;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ExchangeItems() is an atomic combination of item generation and consumption.
|
// ExchangeItems() is an atomic combination of item generation and consumption.
|
||||||
// It can be used to implement crafting recipes or transmutations, or items which unpack
|
// It can be used to implement crafting recipes or transmutations, or items which unpack
|
||||||
|
|
Loading…
Reference in New Issue