mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-17 23:10:30 +00:00
Implement DeepClone() for asset and description
This commit is contained in:
@@ -1347,11 +1347,11 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
|
|||||||
fairClassIDsToReceive[theirItem] = ++fairReceivedAmount;
|
fairClassIDsToReceive[theirItem] = ++fairReceivedAmount;
|
||||||
|
|
||||||
// Filter their inventory for the sets we're trading or have traded with this user
|
// Filter their inventory for the sets we're trading or have traded with this user
|
||||||
HashSet<Asset> fairFiltered = theirInventory.Where(item => ((item.RealAppID == set.RealAppID) && (item.Type == set.Type) && (item.Rarity == set.Rarity)) || skippedSetsThisTrade.Contains((item.RealAppID, item.Type, item.Rarity))).Select(static item => item.CreateShallowCopy()).ToHashSet();
|
HashSet<Asset> fairFiltered = theirInventory.Where(item => ((item.RealAppID == set.RealAppID) && (item.Type == set.Type) && (item.Rarity == set.Rarity)) || skippedSetsThisTrade.Contains((item.RealAppID, item.Type, item.Rarity))).Select(static item => item.DeepClone()).ToHashSet();
|
||||||
|
|
||||||
// Copy list to HashSet<Steam.Asset>
|
// Copy list to HashSet<Steam.Asset>
|
||||||
HashSet<Asset> fairItemsToGive = Trading.GetTradableItemsFromInventory(ourInventory.Values.Where(item => ((item.RealAppID == set.RealAppID) && (item.Type == set.Type) && (item.Rarity == set.Rarity)) || skippedSetsThisTrade.Contains((item.RealAppID, item.Type, item.Rarity))).Select(static item => item.CreateShallowCopy()).ToHashSet(), fairClassIDsToGive.ToDictionary(static classID => classID.Key, static classID => classID.Value));
|
HashSet<Asset> fairItemsToGive = Trading.GetTradableItemsFromInventory(ourInventory.Values.Where(item => ((item.RealAppID == set.RealAppID) && (item.Type == set.Type) && (item.Rarity == set.Rarity)) || skippedSetsThisTrade.Contains((item.RealAppID, item.Type, item.Rarity))).Select(static item => item.DeepClone()).ToHashSet(), fairClassIDsToGive.ToDictionary(static classID => classID.Key, static classID => classID.Value));
|
||||||
HashSet<Asset> fairItemsToReceive = Trading.GetTradableItemsFromInventory(fairFiltered.Select(static item => item.CreateShallowCopy()).ToHashSet(), fairClassIDsToReceive.ToDictionary(static classID => classID.Key, static classID => classID.Value));
|
HashSet<Asset> fairItemsToReceive = Trading.GetTradableItemsFromInventory(fairFiltered.Select(static item => item.DeepClone()).ToHashSet(), fairClassIDsToReceive.ToDictionary(static classID => classID.Key, static classID => classID.Value));
|
||||||
|
|
||||||
// Actual check
|
// Actual check
|
||||||
if (!Trading.IsTradeNeutralOrBetter(fairFiltered, fairItemsToReceive, fairItemsToGive)) {
|
if (!Trading.IsTradeNeutralOrBetter(fairFiltered, fairItemsToReceive, fairItemsToGive)) {
|
||||||
|
|||||||
@@ -723,7 +723,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
|
|||||||
|
|
||||||
foreach (Asset item in itemsOfClass.TakeWhile(_ => classRemaining > 0)) {
|
foreach (Asset item in itemsOfClass.TakeWhile(_ => classRemaining > 0)) {
|
||||||
if (item.Amount > classRemaining) {
|
if (item.Amount > classRemaining) {
|
||||||
Asset itemToSend = item.CreateShallowCopy();
|
Asset itemToSend = item.DeepClone();
|
||||||
itemToSend.Amount = classRemaining;
|
itemToSend.Amount = classRemaining;
|
||||||
result.Add(itemToSend);
|
result.Add(itemToSend);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using ProtoBuf;
|
||||||
using SteamKit2.Internal;
|
using SteamKit2.Internal;
|
||||||
|
|
||||||
namespace ArchiSteamFarm.Steam.Data;
|
namespace ArchiSteamFarm.Steam.Data;
|
||||||
@@ -141,5 +142,5 @@ public sealed class Asset {
|
|||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private Asset() { }
|
private Asset() { }
|
||||||
|
|
||||||
internal Asset CreateShallowCopy() => (Asset) MemberwiseClone();
|
public Asset DeepClone() => new(Serializer.DeepClone(Body), Description?.DeepClone());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ using ArchiSteamFarm.Core;
|
|||||||
using ArchiSteamFarm.Helpers.Json;
|
using ArchiSteamFarm.Helpers.Json;
|
||||||
using ArchiSteamFarm.Localization;
|
using ArchiSteamFarm.Localization;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using ProtoBuf;
|
||||||
using SteamKit2.Internal;
|
using SteamKit2.Internal;
|
||||||
|
|
||||||
namespace ArchiSteamFarm.Steam.Data;
|
namespace ArchiSteamFarm.Steam.Data;
|
||||||
@@ -543,4 +544,6 @@ public sealed class InventoryDescription {
|
|||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private InventoryDescription() { }
|
private InventoryDescription() { }
|
||||||
|
|
||||||
|
public InventoryDescription DeepClone() => new(Serializer.DeepClone(Body));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ public sealed class Trading : IDisposable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Asset itemToAdd = item.CreateShallowCopy();
|
Asset itemToAdd = item.DeepClone();
|
||||||
|
|
||||||
if (amount < itemToAdd.Amount) {
|
if (amount < itemToAdd.Amount) {
|
||||||
// We give only a fraction of this item
|
// We give only a fraction of this item
|
||||||
@@ -664,7 +664,7 @@ public sealed class Trading : IDisposable {
|
|||||||
return ParseTradeResult.EResult.TryAgain;
|
return ParseTradeResult.EResult.TryAgain;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool accept = IsTradeNeutralOrBetter(inventory, tradeOffer.ItemsToGive.Select(static item => item.CreateShallowCopy()).ToHashSet(), tradeOffer.ItemsToReceive.Select(static item => item.CreateShallowCopy()).ToHashSet());
|
bool accept = IsTradeNeutralOrBetter(inventory, tradeOffer.ItemsToGive.Select(static item => item.DeepClone()).ToHashSet(), tradeOffer.ItemsToReceive.Select(static item => item.DeepClone()).ToHashSet());
|
||||||
|
|
||||||
// We're now sure whether the trade is neutral+ for us or not
|
// We're now sure whether the trade is neutral+ for us or not
|
||||||
ParseTradeResult.EResult acceptResult = accept ? ParseTradeResult.EResult.Accepted : ParseTradeResult.EResult.Rejected;
|
ParseTradeResult.EResult acceptResult = accept ? ParseTradeResult.EResult.Accepted : ParseTradeResult.EResult.Rejected;
|
||||||
|
|||||||
Reference in New Issue
Block a user