public void TestBasicSimulation()
        {
            IRandom random = new PoeRandom();

            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Fencer Helm";
            financeInfo.BudgetInChaos = 1000;

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                new CurrencyCraftingStep(new AlchemyOrb(random))
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            var start = craftingSimulator.Start();

            start.Wait();

            Assert.IsTrue(start.Result.AllGeneratedItems.All(x => x != null));
            Assert.IsTrue(1000 < start.Result.AllGeneratedItems.Count);
            Assert.IsTrue(1000 <= start.Result.CostInChaos);
            Assert.IsTrue(start.Result.CurrencyUsed.ContainsKey(CurrencyNames.AlchemyOrb));
            Assert.IsTrue(1000 < start.Result.CurrencyUsed[CurrencyNames.AlchemyOrb]);
        }
        public void FossilTest()
        {
            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Fencer Helm";
            financeInfo.BudgetInChaos = 100;

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                new CurrencyCraftingStep()
                {
                    Name = "Fossil", SocketedCurrency = new List <string> {
                        _fossilName
                    }
                }
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            var start = craftingSimulator.Start();

            start.Wait();

            Assert.IsTrue(start.Result.AllGeneratedItems.All(x => x != null));
            Assert.IsTrue(10 < start.Result.AllGeneratedItems.Count);
            Assert.IsTrue(10 <= start.Result.CostInChaos);
            Assert.IsTrue(start.Result.CurrencyUsed.ContainsKey(_fossilName));
            Assert.IsTrue(10 < start.Result.CurrencyUsed[_fossilName]);
        }
        public void ProgressTest()
        {
            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Fencer Helm";
            financeInfo.BudgetInChaos = 100;

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                new CurrencyCraftingStep()
                {
                    Name = _alchemyName
                }
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            double previousProgress = 0;

            List <double> progressList = new List <double>();

            craftingSimulator.OnProgressUpdate = (x) =>
            {
                Assert.IsTrue(x.Progress > previousProgress);
                progressList.Add(x.Progress);
                previousProgress = x.Progress;
            };

            var start = craftingSimulator.Start(10000);

            start.Wait();
            Assert.AreEqual(progressList.Count, 100);
        }
        public void InfiniteRecursionTest()
        {
            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Fencer Helm";
            financeInfo.BudgetInChaos = 100;

            var recursiveCraftingStep = new WhileCraftingStep();

            recursiveCraftingStep.Children.Add(recursiveCraftingStep);

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                recursiveCraftingStep,
                new CurrencyCraftingStep()
                {
                    Name = _transmutationName
                }
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            var task = craftingSimulator.Start();

            task.Wait();

            throw task.Exception;
        }
        public void MatchingItemsTest()
        {
            String targetName = "Total ES Test";

            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Vaal Regalia";
            financeInfo.BudgetInChaos = 1000;

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                new CurrencyCraftingStep()
                {
                    Name = _alchemyName
                }
            };

            craftingInfo.CraftingTargets = new List <CraftingTarget>()
            {
                new CraftingTarget()
                {
                    Name      = targetName,
                    Condition = new CraftingCondition()
                    {
                        CraftingSubConditions = new List <CraftingSubcondition>()
                        {
                            new CraftingSubcondition()
                            {
                                ValueType      = StatValueType.Flat,
                                AggregateType  = SubconditionAggregateType.And,
                                MetaConditions = new List <ConditionAffix>()
                                {
                                    new ConditionAffix()
                                    {
                                        ModType = "Total Energy Shield",
                                        Min1    = 200
                                    }
                                }
                            }
                        }
                    }
                }
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            var start = craftingSimulator.Start();

            start.Wait();

            Assert.IsTrue(start.Result.MatchingGeneratedItems[targetName].Any());
        }
Пример #6
0
        public CraftingSimulator(
            SimBaseItemInfo baseItemInfo,
            SimFinanceInfo financeInfo,
            SimCraftingInfo craftingInfo)
        {
            _affixFactory     = new AffixFactory();
            _itemFactory      = new ItemFactory(_affixFactory);
            _fossilFactory    = new FossilFactory(_affixFactory);
            _masterModFactory = new MasterModFactory(_affixFactory, _itemFactory);
            _essenceFactory   = new EssenceFactory(_itemFactory, _affixFactory);

            var currencyFactory = new CurrencyFactory(
                new PoeRandom(),
                _essenceFactory,
                _fossilFactory,
                _masterModFactory);

            var clientToDomainMapper = new ClientToDomainMapper(_itemFactory, currencyFactory);
            var domainToClientMapper = new DomainToClientMapper();

            _clientToDomain = clientToDomainMapper.GenerateMapper();
            _domainToClient = domainToClientMapper.GenerateMapper();

            _financeInfo  = financeInfo;
            _craftingInfo = craftingInfo;
            _baseItemInfo = baseItemInfo;

            _baseItem = _itemFactory.Items.First(x => x.Name == _baseItemInfo.ItemName);

            var itemAffixes = _affixFactory.GetAffixesForItem(
                _baseItem.Tags,
                _baseItem.ItemClass,
                _baseItemInfo.ItemLevel);

            var fossilAffixes = _fossilFactory.Fossils
                                .SelectMany(x => x.AddedAffixes)
                                .ToList();

            var essenceAffixes = _essenceFactory.GetAffixesByItemClass(_baseItem.ItemClass)
                                 .ToList();

            var currencyAffixes = fossilAffixes.Union(essenceAffixes).ToList();

            var influences         = new List <Influence>((Influence[])Enum.GetValues(typeof(Influence)));
            var affixesByInfluence =
                _affixFactory.GetAffixesByInfluence(influences, _baseItem.ItemClass, _baseItemInfo.ItemLevel);
            var influenceSpawnTag = _affixFactory.GetInfluenceSpawnTags(_baseItem.ItemClass);

            _affixManager = new AffixManager(_baseItem, itemAffixes, currencyAffixes, affixesByInfluence,
                                             influenceSpawnTag);
            _currencyValues = _currencyValueFactory.GetCurrencyValues(financeInfo.League);
        }
Пример #7
0
        public CraftingSimulator(
            SimBaseItemInfo baseItemInfo,
            SimFinanceInfo financeInfo,
            SimCraftingInfo craftingInfo)
        {
            _financeInfo  = financeInfo;
            _craftingInfo = craftingInfo;
            _baseItemInfo = baseItemInfo;

            _baseItem = _itemFactory.Items.First(x => x.Name == _baseItemInfo.ItemName);
            var itemAffixes   = _affixFactory.GetAffixesForItem(_baseItem.Tags, _baseItem.ItemClass, _baseItemInfo.ItemLevel, _baseItemInfo.Influence);
            var fossilAffixes = _fossilFactory.Fossils.SelectMany(x => x.AddedAffixes).ToList();

            _affixManager   = new AffixManager(_baseItem, itemAffixes, fossilAffixes);
            _currencyValues = _currencyValueFactory.GetCurrencyValues(financeInfo.League);
        }
        public void MasterCraftTest()
        {
            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Fencer Helm";
            financeInfo.BudgetInChaos = 100;

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                new CurrencyCraftingStep()
                {
                    Name = _transmutationName
                },
                new CurrencyCraftingStep()
                {
                    Name = _annulmentName
                },
                new CurrencyCraftingStep()
                {
                    Name = _annulmentName
                },
                new CurrencyCraftingStep()
                {
                    Name = _masterModName
                }
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            var start = craftingSimulator.Start();

            start.Wait();

            Assert.IsTrue(start.Result.AllGeneratedItems.All(x => x != null));
            Assert.IsTrue(1 <= start.Result.AllGeneratedItems.Count);
            Assert.IsTrue(10 <= start.Result.CostInChaos);
            Assert.IsTrue(start.Result.CurrencyUsed.ContainsKey(_annulmentName));
            Assert.IsTrue(start.Result.CurrencyUsed.ContainsKey(_transmutationName));
            Assert.IsTrue(start.Result.CurrencyUsed.Any(x => x.Key != _transmutationName && x.Key != _annulmentName));
        }
        public void TimeoutTest()
        {
            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Fencer Helm";
            financeInfo.BudgetInChaos = 10000000;

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                new CurrencyCraftingStep()
                {
                    Name = _alchemyName
                }
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            var start = craftingSimulator.Start(.01);

            start.Wait();
        }
        public void NoCurrencyTest()
        {
            SimBaseItemInfo baseItemInfo = new SimBaseItemInfo();
            SimCraftingInfo craftingInfo = new SimCraftingInfo();
            SimFinanceInfo  financeInfo  = new SimFinanceInfo();

            baseItemInfo.ItemName     = "Fencer Helm";
            financeInfo.BudgetInChaos = 100;

            var flowControlCraftingStep = new WhileCraftingStep();

            craftingInfo.CraftingSteps = new List <ICraftingStep>()
            {
                flowControlCraftingStep,
            };

            CraftingSimulator craftingSimulator = new CraftingSimulator(baseItemInfo, financeInfo, craftingInfo);

            var task = craftingSimulator.Start();

            task.Wait();

            throw task.Exception;
        }