Exemplo n.º 1
0
        public Inventory(string datafile, int minPercentile = 50, string workingDir = @".\")
        {
            this.StatsAsString     = Enum.GetNames(typeof(Stats));
            this.ItemTypesAsString = Enum.GetNames(typeof(ItemType));

            this.Items = new Dictionary <string, List <GearItem> >
            {
                { "vest", new List <GearItem>() },
                { "mask", new List <GearItem>() },
                { "kneepads", new List <GearItem>() },
                { "backpack", new List <GearItem>() },
                { "gloves", new List <GearItem>() },
                { "holster", new List <GearItem>() },
                { "gearmod", new List <GearItem>() }
            };

            this.WorkingDir = workingDir;

            int rawItemCount = 0;
            int itemCount    = 0;

            using (var sr = new StreamReader(datafile))
            {
                Console.WriteLine("Importing items from data file...");
                var rawItems = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(sr.ReadToEnd());
                foreach (var item in rawItems)
                {
                    var gearItem = new GearItem(item);
                    if (ensureMinimumPercentile(gearItem, minPercentile))
                    {
                        Items[gearItem.ItemType.ToLower()].Add(gearItem);
                        itemCount++;
                    }
                    rawItemCount++;
                }
            }

            // calculate the combinations of gear mods that can be used with each build
            this.GearModCombinations = this.Items["gearmod"].DifferentCombinations(5).ToList();

            Console.WriteLine(string.Format(" Completed importing {0} gear items and {1} gear mods.", rawItemCount - Items["gearmod"].Count(), Items["gearmod"].Count()));
            Console.WriteLine(string.Format(" Excluded {0} gear items due to minimum stat criteria ({2}%) - {1} will included in the build analysis.", rawItemCount - itemCount, itemCount, minPercentile));
            Console.WriteLine(string.Format(" Derived {0} gear mod combinations.", this.GearModCombinations.Count()));
        }
Exemplo n.º 2
0
        private bool ensureMinimumPercentile(GearItem item, int minPercentile = 50)
        {
            decimal minStat  = 1193;
            double  minArmor = 0;

            switch (item.ItemType.ToLower())
            {
            case "vest":
                minArmor = ((2003.0 - 1704.0) / 100.0 * minPercentile) + 1704;
                minArmor = 2003 / 100 * minPercentile;
                break;

            case "mask":
                minArmor = ((1001.0 - 852.0) / 100.0 * minPercentile) + 852;
                break;

            case "kneepads":
                minArmor = ((1668.0 - 1419.0) / 100.0 * minPercentile) + 1419;
                break;

            case "backpack":
                minArmor = ((1334.0 - 1135.0) / 100.0 * minPercentile) + 1135;
                break;

            case "gloves":
                minArmor = ((1001.0 - 852.0) / 100.0 * minPercentile) + 852;
                break;

            case "holster":
                minArmor = ((1001.0 - 852.0) / 100.0 * minPercentile) + 852;
                break;

            case "gearmod":
                return(true);

            default:
                throw new Exception(string.Format("Unknown item type: {0}", item.ItemType));
            }

            var mainStatValue = (new [] { item.Stats["firearms"], item.Stats["stamina"], item.Stats["electronics"] }).Select(s => Convert.ToDecimal(s)).Max();

            return(item.Stats["armor"] > Convert.ToDecimal(minArmor) && mainStatValue > minStat);
        }