mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-13 15:18:07 +03:00
Consume, Split, Transfer
This commit is contained in:
parent
b74d45814a
commit
683925430d
@ -145,14 +145,7 @@ namespace Steamworks
|
|||||||
if ( !Internal.GetAllItems( ref sresult ) )
|
if ( !Internal.GetAllItems( ref sresult ) )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var result = new InventoryResult( sresult );
|
return await InventoryResult.GetAsync( sresult );
|
||||||
|
|
||||||
if ( !await result.WaitUntilReadyAsync() )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Steamworks.Data;
|
using Steamworks.Data;
|
||||||
|
|
||||||
namespace Steamworks
|
namespace Steamworks
|
||||||
@ -44,6 +45,46 @@ namespace Steamworks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsConsumed => (_flags & 1 << 9) != 0;
|
public bool IsConsumed => (_flags & 1 << 9) != 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Consumes items from a user's inventory. If the quantity of the given item goes to zero, it is permanently removed.
|
||||||
|
/// Once an item is removed it cannot be recovered.This is not for the faint of heart - if your game implements item removal at all,
|
||||||
|
/// a high-friction UI confirmation process is highly recommended.ConsumeItem can be restricted to certain item definitions or fully
|
||||||
|
/// blocked via the Steamworks website to minimize support/abuse issues such as the classic "my brother borrowed my laptop and deleted all of my rare items".
|
||||||
|
/// </summary>
|
||||||
|
public async Task<InventoryResult?> Consume( int amount = 1 )
|
||||||
|
{
|
||||||
|
var sresult = default( SteamInventoryResult_t );
|
||||||
|
if ( !SteamInventory.Internal.ConsumeItem( ref sresult, Id, (uint)amount ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return await InventoryResult.GetAsync( sresult );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Split stack into two items
|
||||||
|
/// </summary>
|
||||||
|
public async Task<InventoryResult?> SplitStack( int quantity = 1 )
|
||||||
|
{
|
||||||
|
var sresult = default( SteamInventoryResult_t );
|
||||||
|
if ( !SteamInventory.Internal.TransferItemQuantity( ref sresult, Id, (uint)quantity, ulong.MaxValue ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return await InventoryResult.GetAsync( sresult );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Transfer x quantity from this item to the target item
|
||||||
|
/// </summary>
|
||||||
|
public async Task<InventoryResult?> TransferItemQuantity( InventoryItem toItem, int quantity )
|
||||||
|
{
|
||||||
|
var sresult = default( SteamInventoryResult_t );
|
||||||
|
if ( !SteamInventory.Internal.TransferItemQuantity( ref sresult, Id, (uint)quantity, toItem.Id ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return await InventoryResult.GetAsync( sresult );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static InventoryItem From( SteamItemDetails_t details )
|
internal static InventoryItem From( SteamItemDetails_t details )
|
||||||
{
|
{
|
||||||
var i = new InventoryItem
|
var i = new InventoryItem
|
||||||
|
@ -8,23 +8,13 @@ namespace Steamworks
|
|||||||
public struct InventoryResult : IDisposable
|
public struct InventoryResult : IDisposable
|
||||||
{
|
{
|
||||||
internal SteamInventoryResult_t _id;
|
internal SteamInventoryResult_t _id;
|
||||||
internal Result _result;
|
|
||||||
|
|
||||||
internal InventoryResult( SteamInventoryResult_t id )
|
public bool Expired { get; internal set; }
|
||||||
|
|
||||||
|
internal InventoryResult( SteamInventoryResult_t id, bool expired )
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_result = Result.Pending;
|
Expired = expired;
|
||||||
}
|
|
||||||
|
|
||||||
internal async Task<bool> WaitUntilReadyAsync()
|
|
||||||
{
|
|
||||||
while ( _result == Result.Pending )
|
|
||||||
{
|
|
||||||
_result = SteamInventory.Internal.GetResultStatus( _id );
|
|
||||||
await Task.Delay( 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return _result == Result.OK || _result == Result.Expired;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ItemCount
|
public int ItemCount
|
||||||
@ -71,6 +61,21 @@ namespace Steamworks
|
|||||||
SteamInventory.Internal.DestroyResult( _id );
|
SteamInventory.Internal.DestroyResult( _id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static async Task<InventoryResult?> GetAsync( SteamInventoryResult_t sresult )
|
||||||
|
{
|
||||||
|
var _result = Result.Pending;
|
||||||
|
while ( _result == Result.Pending )
|
||||||
|
{
|
||||||
|
_result = SteamInventory.Internal.GetResultStatus( sresult );
|
||||||
|
await Task.Delay( 10 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( _result != Result.OK && _result != Result.Expired )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new InventoryResult( sresult, _result == Result.Expired );
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serialized result sets contain a short signature which can't be forged or replayed across different game sessions.
|
/// Serialized result sets contain a short signature which can't be forged or replayed across different game sessions.
|
||||||
/// A result set can be serialized on the local client, transmitted to other players via your game networking, and
|
/// A result set can be serialized on the local client, transmitted to other players via your game networking, and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user