mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 22:25:49 +03:00
Serialize etc
This commit is contained in:
parent
afb1277d62
commit
1014178db6
@ -36,10 +36,33 @@ internal Inventory( Client c )
|
|||||||
client = c;
|
client = c;
|
||||||
|
|
||||||
LoadItemDefinitions();
|
LoadItemDefinitions();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Call this at least every two minutes, every frame doesn't hurt.
|
||||||
|
/// You should call it when you consider it active play time.
|
||||||
|
/// IE - your player is alive, and playing.
|
||||||
|
/// Don't stress on it too much tho cuz it's super hijackable anyway.
|
||||||
|
/// </summary>
|
||||||
|
public void DropHeartbeat()
|
||||||
|
{
|
||||||
|
client._inventory.SendItemDropHeartbeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trigger an item drop. Call this when it's a good time to award
|
||||||
|
/// an item drop to a player. This won't automatically result in giving
|
||||||
|
/// an item to a player. Just call it every minute or so, or on launch.
|
||||||
|
/// ItemDefinition is usually a generator
|
||||||
|
/// </summary>
|
||||||
|
public void TriggerItemDrop( Definition definition )
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
client._inventory.TriggerItemDrop( ref result, definition.Id );
|
||||||
|
client._inventory.DestroyResult( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this to retrieve the items.
|
/// Call this to retrieve the items.
|
||||||
/// Note that if this has already been called it won't
|
/// Note that if this has already been called it won't
|
||||||
@ -128,7 +151,18 @@ private void UpdateRequest()
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Item[] Items;
|
public Item[] Items;
|
||||||
|
|
||||||
private void RetrieveInventory()
|
/// <summary>
|
||||||
|
/// You can send this data to a server, or another player who can then deserialize it
|
||||||
|
/// and get a verified list of items.
|
||||||
|
/// </summary>
|
||||||
|
public byte[] SerializedItems;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serialized data exprires after an hour. This is the time the value in SerializedItems will expire.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime SerializedExpireTime;
|
||||||
|
|
||||||
|
private unsafe void RetrieveInventory()
|
||||||
{
|
{
|
||||||
Valve.Steamworks.SteamItemDetails_t[] items = null;
|
Valve.Steamworks.SteamItemDetails_t[] items = null;
|
||||||
client._inventory.GetResultItems( updateRequest, out items );
|
client._inventory.GetResultItems( updateRequest, out items );
|
||||||
@ -146,6 +180,20 @@ private void RetrieveInventory()
|
|||||||
};
|
};
|
||||||
} ).ToArray();
|
} ).ToArray();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get a serialized version
|
||||||
|
//
|
||||||
|
uint size = 0;
|
||||||
|
client._inventory.SerializeResult( updateRequest, IntPtr.Zero, ref size );
|
||||||
|
SerializedItems = new byte[size];
|
||||||
|
|
||||||
|
fixed( byte* b = SerializedItems )
|
||||||
|
{
|
||||||
|
client._inventory.SerializeResult( updateRequest, (IntPtr) b, ref size );
|
||||||
|
}
|
||||||
|
|
||||||
|
SerializedExpireTime = DateTime.Now.Add( TimeSpan.FromMinutes( 60 ) );
|
||||||
|
|
||||||
//
|
//
|
||||||
// Tell everyone we've got new items!
|
// Tell everyone we've got new items!
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user