예제 #1
0
        public void NoCraftingStepsTest()
        {
            List <ICraftingStep> craftingSteps = new List <ICraftingStep>();
            Equipment            equipment     = GetTestEquipment(true);

            CancellationToken token = new CancellationToken(false);

            AffixManager affixManager = CreateAffixManager(equipment.ItemBase);

            _craftManager.Craft(craftingSteps, equipment, affixManager, token, _progressManager);

            Assert.IsFalse(equipment.Completed);
        }
예제 #2
0
 private void OnClick()
 {
     _manager.Craft(_recipe);
 }
예제 #3
0
        private SimulationArtifacts Run(CancellationToken ct)
        {
            // Pay for the first item
            _simulationArtifacts.CostInChaos += _baseItemInfo.ItemCost;

            for (Progress = 0; Progress < 100; Progress = GetSimulationProgress())
            {
                // Craft item
                var item    = _itemFactory.ToEquipment(_baseItem, _baseItemInfo.ItemLevel, _baseItemInfo.Influence);
                var results = _craftingManager.Craft(_craftingInfo.CraftingSteps, item, _affixManager, ct, _financeInfo.BudgetInChaos - _simulationArtifacts.CostInChaos);

                bool saved = false;
                // Update item results
                foreach (var craftingTarget in _craftingInfo.CraftingTargets)
                {
                    if (craftingTarget.Condition != null && _conditionResolution.IsValid(craftingTarget.Condition, results.Result))
                    {
                        _simulationArtifacts.MatchingGeneratedItems[craftingTarget].Add(results.Result);
                        saved = true;
                        break;
                    }
                }

                _simulationArtifacts.AllGeneratedItems.Add(results.Result);

                // Update crafting cost
                foreach (var result in results.CraftingStepMetadata)
                {
                    foreach (var currency in result.Value.CurrencyAmounts)
                    {
                        if (!_simulationArtifacts.CurrencyUsed.ContainsKey(currency.Key))
                        {
                            _simulationArtifacts.CurrencyUsed.Add(currency.Key, 0);
                        }

                        int amountOfCurrencyUsed = currency.Value * result.Value.TimesModified;
                        _simulationArtifacts.CurrencyUsed[currency.Key] += amountOfCurrencyUsed;
                        _simulationArtifacts.CostInChaos += amountOfCurrencyUsed * _currencyValues[currency.Key];
                    }
                }

                if (GetSimulationProgress() < 100)
                {
                    // Get a new item ready.
                    if (saved ||
                        results.Result.Corrupted ||
                        results.Result.Rarity != EquipmentRarity.Normal &&
                        _baseItemInfo.ItemCost <= _currencyValues[CurrencyNames.ScouringOrb])
                    {
                        _simulationArtifacts.CostInChaos += _baseItemInfo.ItemCost;
                    }
                    else if (results.Result.Rarity != EquipmentRarity.Normal)
                    {
                        _simulationArtifacts.CostInChaos += _currencyValues[CurrencyNames.ScouringOrb];
                    }
                }

                // Update progress results
                if (OnProgressUpdate != null)
                {
                    var args = new ProgressUpdateEventArgs
                    {
                        Progress = Progress
                    };

                    OnProgressUpdate(args);
                }
            }

            if (OnSimulationComplete != null)
            {
                Status = SimulationStatus.Completed;

                var args = new SimulationCompleteEventArgs
                {
                    SimulationArtifacts = _simulationArtifacts
                };

                OnSimulationComplete(args);
            }

            return(_simulationArtifacts);
        }
예제 #4
0
        private SimulationArtifacts Run(CancellationToken ct)
        {
            // Check for recursive/duplicate crafting steps
            if (RecursionCheck(new HashSet <Model.Crafting.Steps.ICraftingStep>(), _craftingInfo.CraftingSteps))
            {
                throw new ArgumentException("Crafting steps are infinitely recursive");
            }

            // Pay for the first item
            SimulationArtifacts.CostInChaos += _baseItemInfo.ItemCost;

            double previousProgress = -1;

            var baseInfluence   = InfluenceToDomain(_baseItemInfo.Influence);
            var craftingSteps   = CraftingStepsToDomain(_craftingInfo.CraftingSteps);
            var craftingTargets = _craftingInfo.CraftingTargets.Select(x =>

                                                                       new PoeCraftLib.Entities.Items.CraftingTarget()
            {
                Name      = x.Name,
                Value     = x.Value,
                Condition = ConditionToDomain(x.Condition)
            }).ToList();

            for (ProgressManager progressManager = GetProgressManager(); progressManager.Progress < 100; previousProgress = progressManager.Progress)
            {
                // Craft item
                var item    = _itemFactory.ToEquipment(_baseItem, _baseItemInfo.ItemLevel, baseInfluence);
                var results = _craftingManager.Craft(craftingSteps, item, _affixManager, ct, progressManager);

                bool saved = false;

                // No normal items are evaluated since that would cause a lot of clutter
                if (results.Result.Rarity != EquipmentRarity.Normal)
                {
                    var equipment = EquipmentToClient(results.Result);
                    SimulationArtifacts.AllGeneratedItems.Add(equipment);

                    foreach (var craftingTarget in craftingTargets)
                    {
                        if (craftingTarget.Condition != null &&
                            _conditionResolution.IsValid(craftingTarget.Condition, results.Result))
                        {
                            if (!SimulationArtifacts.MatchingGeneratedItems.ContainsKey(craftingTarget.Name))
                            {
                                SimulationArtifacts.MatchingGeneratedItems.Add(craftingTarget.Name, new List <Equipment>());
                            }

                            SimulationArtifacts.MatchingGeneratedItems[craftingTarget.Name].Add(equipment);
                            saved = true;
                            break;
                        }
                    }
                }

                // Update crafting cost
                foreach (var result in results.CraftingStepMetadata)
                {
                    foreach (var currency in result.Value.CurrencyAmounts)
                    {
                        if (!SimulationArtifacts.CurrencyUsed.ContainsKey(currency.Key))
                        {
                            SimulationArtifacts.CurrencyUsed.Add(currency.Key, 0);
                        }
                        // The progress manager is updated with this information in the craft manager
                        int amountOfCurrencyUsed = currency.Value * result.Value.TimesModified;
                        SimulationArtifacts.CurrencyUsed[currency.Key] += amountOfCurrencyUsed;
                        SimulationArtifacts.CostInChaos += amountOfCurrencyUsed * _currencyValues[currency.Key];
                    }
                }

                if (progressManager.Progress < 100)
                {
                    // Get a new item ready.
                    if (saved ||
                        results.Result.Corrupted ||
                        results.Result.Rarity != EquipmentRarity.Normal &&
                        _baseItemInfo.ItemCost <= _currencyValues[CurrencyNames.ScouringOrb])
                    {
                        SimulationArtifacts.CostInChaos += _baseItemInfo.ItemCost;
                        progressManager.AddCost(_baseItemInfo.ItemCost);
                    }
                    else if (results.Result.Rarity != EquipmentRarity.Normal)
                    {
                        SimulationArtifacts.CostInChaos += _currencyValues[CurrencyNames.ScouringOrb];
                        progressManager.SpendCurrency(CurrencyNames.ScouringOrb, 1);
                    }
                }

                // Check for no crafting steps
                if (Math.Abs(previousProgress - progressManager.Progress) < double.Epsilon)
                {
                    throw new ArgumentException("Crafting steps do not spend currency");
                }
            }

            if (OnSimulationComplete != null)
            {
                Status = SimulationStatus.Completed;

                var args = new SimulationCompleteEventArgs
                {
                    SimulationArtifacts = SimulationArtifacts
                };

                OnSimulationComplete(args);
            }

            return(SimulationArtifacts);
        }