Int method for this section

If anyone is having issues with using Ints instead of floats here… this is my code for it. (Quick note I use a slightly different style guide than he does… remove the underscores from private variables and the capital letter from LevelToUnlock and you will be fine)

  private Dictionary<InventoryItem, int> GetAvailabilities()
        {
            Dictionary<InventoryItem, int> availabilities = new Dictionary<InventoryItem, int>();

            foreach (var config in GetAvailableConfigs())
            {
                if (!availabilities.ContainsKey(config._item))
                {
                    availabilities[config._item] = 0;
                }
                availabilities[config._item] += config._initialStock;
            }

            return availabilities;
        }

        private Dictionary<InventoryItem, int> GetPrices()
        {
            Dictionary<InventoryItem, int> prices = new Dictionary<InventoryItem, int>();

            foreach (var config in GetAvailableConfigs())
            {
                if (!prices.ContainsKey(config._item))
                {
                    prices[config._item] = config._item.GetPrice();
                }

                prices[config._item] = Mathf.CeilToInt(prices[config._item] * (1f - config._buyingDiscountPercentage / 100f));
            }

            return prices;
        }

        private IEnumerable<StockItemConfig> GetAvailableConfigs()
        {
            int shopperLevel = GetShopperLevel();
            foreach (var config in _stockConfig)
            {
                if (config.LevelToUnlock > shopperLevel) continue;
                yield return config;
            }
        }

Doesn’t seem to be private if you can access it like this. :thinking: :wink:

Yeah good point I think I didn’t catch that in a refactor i was doing. I usually scrub for those kinds of oversights at the end of a course. When I get though the whole course I’ll update the code snip to reflect mt final code (and something that doesn’t cause issues on future lessons I have not done yet).

1 Like

Privacy & Terms