Exemple #1
0
 private static IEnumerable <KeyValuePair <string, long> > GetVisibleStats(ArcadeUser user)
 => user.Stats.Where(x =>
                     x.Value != 0 &&
                     Var.TypeOf(x.Key) == VarType.Stat &&
                     !ItemHelper.Exists(Var.GetGroup(x.Key)) &&
                     !ShopHelper.Exists(Var.GetGroup(x.Key))
                     ).OrderBy(x => x.Key);
Exemple #2
0
        // 35 / 25 => 1.23

        public static string GetRandomStat(ArcadeUser user, IEnumerable <string> chosen)
        => Randomizer.ChooseOrDefault(user.Stats.Keys.Where(x =>
                                                            user.GetVar(x) != 0 &&
                                                            !x.EqualsAny(Vars.Balance, Vars.Debt, Vars.Chips, Vars.Tokens) &&
                                                            Var.TypeOf(x) == VarType.Stat &&
                                                            !ItemHelper.Exists(Var.GetGroup(x)) &&
                                                            !ShopHelper.Exists(Var.GetGroup(x)) &&
                                                            (Check.NotNullOrEmpty(chosen) ? !chosen.Contains(x) : true)));
        public override Task <TypeReaderResult> ReadAsync(ICommandContext ctx, string input, IServiceProvider provider)
        {
            if (ItemHelper.Exists(input))
            {
                return(Task.FromResult(TypeReaderResult.FromSuccess(ItemHelper.GetItem(input))));
            }

            return(Task.FromResult(TypeReaderResult.FromError(CommandError.ObjectNotFound, "Could not find an Item with the specified ID.")));
        }
Exemple #4
0
        /// <summary>
        /// Generates a new <see cref="ItemCatalog"/>.
        /// </summary>
        public ItemCatalog Generate(long tier = 1)
        {
            int specials        = 0;
            int discounts       = 0;
            var counters        = new Dictionary <string, int>();
            var discountEntries = new Dictionary <string, int>();
            var groupCounters   = new Dictionary <string, int>();
            int entries         = 0;

            if (Size <= 0)
            {
                throw new ArgumentException("Cannot initialize a catalog with an empty or negative size.");
            }

            while (entries < Size)
            {
                CatalogEntry entry = GetNextEntry(tier, specials, counters, groupCounters);

                if (entry == null)
                {
                    break;
                }

                if (entry.IsSpecial)
                {
                    Logger.Debug($"Special entry applied ({entry.ItemId})");
                    specials++;
                }
                else
                {
                    Logger.Debug($"Next entry loaded ({entry.ItemId})");
                }

                if (entry.DiscountChance > 0 && entry.MaxDiscount.HasValue)
                {
                    if (!discountEntries.ContainsKey(entry.ItemId) &&
                        discounts < MaxDiscountsAllowed &&
                        RandomProvider.Instance.NextDouble() <= entry.DiscountChance)
                    {
                        // NOTE: Since the upper bound is exclusive, add 1 to the max discount, so that it's possible to land on the specified max
                        int discountToApply = RandomProvider.Instance
                                              .Next(entry.MinDiscount ?? CatalogEntry.DefaultMinDiscount, (entry.MaxDiscount ?? CatalogEntry.DefaultMaxDiscount) + 1);

                        discountEntries.Add(entry.ItemId, discountToApply);

                        Logger.Debug($"{discountToApply}% discount applied ({entry.ItemId})");
                        discounts++;
                    }
                }

                if (!ItemHelper.Exists(entry.ItemId))
                {
                    throw new Exception("The specified item ID could not be found.");
                }

                if (!counters.TryAdd(entry.ItemId, 1))
                {
                    counters[entry.ItemId]++;
                }

                if (Check.NotNull(entry.GroupId))
                {
                    if (!groupCounters.TryAdd(entry.GroupId, 1))
                    {
                        groupCounters[entry.GroupId]++;
                    }
                }

                entries++;
            }

            Logger.Debug($"Compiling catalog with {entries} {Format.TryPluralize("entry", entries)}");

            return(new ItemCatalog(counters, discountEntries));
        }