Ejemplo n.º 1
0
        public ActionResult OreCalculator(MineralList desiredMinerals, IEnumerable <ItemLookupViewModel> itemList)
        {
            var skills = _playerService.GetReprocessingSkills();

            var viewModel = new OreListModel
            {
                Skills          = skills,
                DesiredMinerals = desiredMinerals,
            };

            if (desiredMinerals.TotalVolume > 0)
            {
                viewModel.OreOrderSummary = _itemService.GetCompressedOres(skills, desiredMinerals);
            }

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult ParseItems(string textInput, bool useCompressedOres = false, bool buildShips = false, int multiplier = 1)
        {
            var inputTests = new []
            {
                new Regex(@"^\[(?<itemName>[^,]+),"),
                new Regex(@"^(?<itemName>[^\t]+)\t(?<itemQty>[\d,]+)$"),
                new Regex(@"^(?<itemQty>[\d,]+)x?\s+(?<itemName>[^\t]+)"),
                new Regex(@"^(?<itemName>.+?)(\sx(?<itemQty>[\d,]+))?$"),
                new Regex(@"^(?<itemName>[^\d\t]+)"),
            };

            var lines = textInput.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            var mineralList  = new MineralList();
            var itemList     = new List <ItemLookup>();
            var invalidLines = new List <string>();
            var mineralNames = mineralList.GetMineralNames().ToList();

            foreach (var line in lines)
            {
                var matchFound = false;
                foreach (var inputTest in inputTests)
                {
                    var inputMatch = inputTest.Match(line.Trim());
                    if (inputMatch.Success)
                    {
                        var itemQty  = inputMatch.Groups["itemQty"];
                        var itemName = inputMatch.Groups["itemName"].Value;
                        var qty      = multiplier * (itemQty.Success ? int.Parse(itemQty.Value.Replace(",", "")) : 1);

                        if (useCompressedOres && mineralNames.Contains(itemName))
                        {
                            mineralList[itemName] += qty;
                            matchFound             = true;
                        }
                        else
                        {
                            var item = _itemService.GetItem(itemName);

                            if (item != null)
                            {
                                var itemEntry = itemList.FirstOrDefault(il => il.TypeId == item.typeID);
                                if (itemEntry == null)
                                {
                                    itemList.Add(new ItemLookup
                                    {
                                        TypeId = item.typeID,
                                        Qty    = qty
                                    });
                                }
                                else
                                {
                                    itemEntry.Qty += qty;
                                }

                                matchFound = true;
                            }
                        }
                        break;
                    }
                }

                if (!matchFound)
                {
                    invalidLines.Add(line);
                }
            }

            var skills = _playerService.GetReprocessingSkills();

            var viewModel = new OreListModel
            {
                Skills            = skills,
                DesiredMinerals   = mineralList,
                TextInput         = textInput,
                InvalidLines      = invalidLines,
                UseCompressedOres = useCompressedOres,
                Multiplier        = multiplier,
                BuildShips        = buildShips,
            };

            if (mineralList.TotalVolume > 0)
            {
                var compressedOres = _itemService.GetCompressedOres(skills, mineralList);
                foreach (var ore in compressedOres.MarketItems)
                {
                    itemList.Add(new ItemLookup
                    {
                        TypeId = ore.Id,
                        Qty    = (int)ore.Qty,
                    });
                }
            }

            if (itemList.Any())
            {
                viewModel.ItemOrderSummary = _itemService.GetItemPricing(itemList, 300, .02m, 60003760);
            }
            viewModel.TextInput    = textInput;
            viewModel.InvalidLines = invalidLines;

            return(View("OreCalculator", viewModel));
        }