mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Fixed items not being removed when the player no longer has it
Fixed item quantity and properties not updating when changed Fixed an error message getting into the items list Also checking if an item is nul wont NRE anymore
This commit is contained in:
parent
13280cd57c
commit
7d66fc9744
@ -57,17 +57,17 @@ public Definition Definition
|
|||||||
|
|
||||||
public bool Equals(Item other)
|
public bool Equals(Item other)
|
||||||
{
|
{
|
||||||
return Equals( other, this );
|
if (ReferenceEquals(null, other)) return false;
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
return Id == other.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if ( obj == null || GetType() != obj.GetType() )
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
{
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
}
|
return Equals((Item)obj);
|
||||||
|
|
||||||
return ((Item)obj).Id == Id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
@ -75,15 +75,14 @@ public override int GetHashCode()
|
|||||||
return Id.GetHashCode();
|
return Id.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Item left, Item right)
|
||||||
public static bool operator ==( Item c1, Item c2 )
|
|
||||||
{
|
{
|
||||||
return c1.Equals( c2 );
|
return Equals(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=( Item c1, Item c2 )
|
public static bool operator !=(Item left, Item right)
|
||||||
{
|
{
|
||||||
return !c1.Equals( c2 );
|
return !Equals(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -114,6 +114,10 @@ internal void Fill()
|
|||||||
for ( int i=0; i< steamItems.Length; i++ )
|
for ( int i=0; i< steamItems.Length; i++ )
|
||||||
{
|
{
|
||||||
var item = inventory.ItemFrom( Handle, steamItems[i], i );
|
var item = inventory.ItemFrom( Handle, steamItems[i], i );
|
||||||
|
if ( item == null )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ( steamItems[i].Flags & (int)SteamNative.SteamItemFlags.Removed ) != 0 )
|
if ( ( steamItems[i].Flags & (int)SteamNative.SteamItemFlags.Removed ) != 0 )
|
||||||
{
|
{
|
||||||
@ -189,6 +193,13 @@ internal Item ItemFrom( SteamInventoryResult_t handle, SteamItemDetails_t detail
|
|||||||
{
|
{
|
||||||
if ( inventory.GetResultItemProperty(handle, (uint)index, propertyName, out string propertyValue ) )
|
if ( inventory.GetResultItemProperty(handle, (uint)index, propertyName, out string propertyValue ) )
|
||||||
{
|
{
|
||||||
|
if (propertyName == "error")
|
||||||
|
{
|
||||||
|
Console.Write("Steam item error: ");
|
||||||
|
Console.WriteLine(propertyValue);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
props.Add(propertyName, propertyValue);
|
props.Add(propertyName, propertyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,14 +129,14 @@ private void onResultReady( SteamInventoryResultReady_t data )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onResult( Result r, bool serialize )
|
private void onResult( Result r, bool isFullUpdate )
|
||||||
{
|
{
|
||||||
if ( r.IsSuccess )
|
if ( r.IsSuccess )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// We only serialize FULL updates
|
// We only serialize FULL updates
|
||||||
//
|
//
|
||||||
if ( serialize )
|
if ( isFullUpdate )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Only serialize if this result is newer than the last one
|
// Only serialize if this result is newer than the last one
|
||||||
@ -149,7 +149,7 @@ private void onResult( Result r, bool serialize )
|
|||||||
}
|
}
|
||||||
|
|
||||||
LastTimestamp = r.Timestamp;
|
LastTimestamp = r.Timestamp;
|
||||||
ApplyResult( r );
|
ApplyResult( r, isFullUpdate );
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Dispose();
|
r.Dispose();
|
||||||
@ -161,7 +161,7 @@ private void onResult( Result r, bool serialize )
|
|||||||
/// Here we're trying to keep our stack up to date with whatever happens
|
/// Here we're trying to keep our stack up to date with whatever happens
|
||||||
/// with the crafting, stacking etc
|
/// with the crafting, stacking etc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void ApplyResult( Result r )
|
internal void ApplyResult( Result r, bool isFullUpdate )
|
||||||
{
|
{
|
||||||
if ( IsServer ) return;
|
if ( IsServer ) return;
|
||||||
|
|
||||||
@ -170,12 +170,19 @@ internal void ApplyResult( Result r )
|
|||||||
if ( Items == null )
|
if ( Items == null )
|
||||||
Items = new Item[0];
|
Items = new Item[0];
|
||||||
|
|
||||||
|
if (isFullUpdate)
|
||||||
|
{
|
||||||
|
Items = r.Items;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// keep the new item instance because it might have a different quantity, properties, etc
|
||||||
Items = Items
|
Items = Items
|
||||||
.Union( r.Items )
|
.UnionSelect(r.Items, (oldItem, newItem) => newItem)
|
||||||
.Distinct()
|
|
||||||
.Where(x => !r.Removed.Contains(x))
|
.Where(x => !r.Removed.Contains(x))
|
||||||
.Where(x => !r.Consumed.Contains(x))
|
.Where(x => !r.Consumed.Contains(x))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Tell everyone we've got new items!
|
// Tell everyone we've got new items!
|
||||||
|
@ -95,5 +95,27 @@ public static string ReadNullTerminatedUTF8String( this BinaryReader br, byte[]
|
|||||||
return Encoding.UTF8.GetString( buffer, 0, i );
|
return Encoding.UTF8.GetString( buffer, 0, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<T> UnionSelect<T>(
|
||||||
|
this IEnumerable<T> first,
|
||||||
|
IEnumerable<T> second,
|
||||||
|
Func<T, T, T> selector) where T : IEquatable<T>
|
||||||
|
{
|
||||||
|
var items = new Dictionary<T, T>();
|
||||||
|
|
||||||
|
foreach (var i in first)
|
||||||
|
{
|
||||||
|
items[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var i in second)
|
||||||
|
{
|
||||||
|
T firstValue;
|
||||||
|
if (items.TryGetValue(i, out firstValue))
|
||||||
|
{
|
||||||
|
items.Remove(i);
|
||||||
|
yield return selector(firstValue, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user