コード例 #1
0
ファイル: TradePanel.cs プロジェクト: polytronicgr/dwarfcorp
        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;
            }
        }
コード例 #2
0
        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;
            }
        }