private void MoveRandomValue(IEnumerable <ResourceAmount> source, List <ResourceAmount> destination, ITradeEntity trader) { foreach (var amount in source) { Resource r = ResourceLibrary.GetResourceByName(amount.ResourceType); if (trader.TraderRace.HatedResources.Any(tag => r.Tags.Contains(tag))) { continue; } if (amount.NumResources == 0) { continue; } ResourceAmount destAmount = destination.FirstOrDefault(resource => resource.ResourceType == amount.ResourceType); if (destAmount == null) { destAmount = new ResourceAmount(amount.ResourceType, 0); destination.Add(destAmount); } int numToMove = MathFunctions.RandInt(1, amount.NumResources + 1); amount.NumResources -= numToMove; destAmount.NumResources += numToMove; break; } }
private void MoveRandomValue(IEnumerable <TradeableItem> source, List <TradeableItem> destination, ITradeEntity trader) { foreach (var amount in source) { if (Library.GetResourceType(amount.ResourceType).HasValue(out var r) && trader.TraderFaction.Race.HasValue(out var race) && race.HatedResources.Any(tag => r.Tags.Contains(tag))) { continue; } if (amount.Count == 0) { continue; } var destAmount = destination.FirstOrDefault(resource => resource.ResourceType == amount.ResourceType); if (destAmount == null) { destAmount = new TradeableItem { Resources = new List <Resource>(), ResourceType = amount.ResourceType }; destination.Add(destAmount); } int numToMove = MathFunctions.RandInt(1, amount.Count + 1); var toMove = amount.Resources.Take(numToMove).ToList(); amount.Resources.RemoveRange(0, numToMove); destAmount.Resources.AddRange(toMove); destAmount.Prototype = destAmount.Resources[0]; break; } }