ArchiSteamFarm.JSON.Steam.TradeOffer.IsFairTypesExchange C# (CSharp) Method

IsFairTypesExchange() private method

private IsFairTypesExchange ( ) : bool
return bool
			internal bool IsFairTypesExchange() {
				Dictionary<uint, Dictionary<Item.EType, uint>> itemsToGivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>();
				foreach (Item item in ItemsToGive) {
					Dictionary<Item.EType, uint> itemsPerType;
					if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) {
						itemsPerType = new Dictionary<Item.EType, uint> { [item.Type] = item.Amount };
						itemsToGivePerGame[item.RealAppID] = itemsPerType;
					} else {
						uint amount;
						if (itemsPerType.TryGetValue(item.Type, out amount)) {
							itemsPerType[item.Type] = amount + item.Amount;
						} else {
							itemsPerType[item.Type] = item.Amount;
						}
					}
				}

				Dictionary<uint, Dictionary<Item.EType, uint>> itemsToReceivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>();
				foreach (Item item in ItemsToReceive) {
					Dictionary<Item.EType, uint> itemsPerType;
					if (!itemsToReceivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) {
						itemsPerType = new Dictionary<Item.EType, uint> {
							{ item.Type, item.Amount }
						};

						itemsToReceivePerGame[item.RealAppID] = itemsPerType;
					} else {
						uint amount;
						if (itemsPerType.TryGetValue(item.Type, out amount)) {
							itemsPerType[item.Type] = amount + item.Amount;
						} else {
							itemsPerType[item.Type] = item.Amount;
						}
					}
				}

				// Ensure that amount of items to give is at least amount of items to receive (per game and per type)
				foreach (KeyValuePair<uint, Dictionary<Item.EType, uint>> itemsPerGame in itemsToGivePerGame) {
					Dictionary<Item.EType, uint> otherItemsPerType;
					if (!itemsToReceivePerGame.TryGetValue(itemsPerGame.Key, out otherItemsPerType)) {
						return false;
					}

					foreach (KeyValuePair<Item.EType, uint> itemsPerType in itemsPerGame.Value) {
						uint otherAmount;
						if (!otherItemsPerType.TryGetValue(itemsPerType.Key, out otherAmount)) {
							return false;
						}

						if (itemsPerType.Value > otherAmount) {
							return false;
						}
					}
				}

				return true;
			}