Beispiel #1
0
        public ShopSession(ArcadeContext context, Shop shop)
        {
            Context = context;
            Shop    = shop;
            State   = ShopState.Enter;
            Catalog = context.Data.Data.GetOrGenerateCatalog(shop, context.Account);
            List <Vendor> possibleVendors = ShopHelper.GetVendors(ShopHelper.GetUniqueTags(Catalog)).ToList();

            Vendor = Check.NotNullOrEmpty(possibleVendors) ? Randomizer.Choose(possibleVendors) : null;

            if (!context.Account.CatalogHistory.ContainsKey(shop.Id))
            {
                context.Account.CatalogHistory[shop.Id] = new CatalogHistory();
            }

            if (!context.Account.CatalogHistory[shop.Id].HasVisited)
            {
                context.Account.CatalogHistory[shop.Id].HasVisited = true;
                context.Account.AddToVar(ShopHelper.GetVisitId(shop.Id));
            }

            Var.SetIfEmpty(context.Account, ShopHelper.GetTierId(shop.Id), 1);

            long tier = context.Account.GetVar(ShopHelper.GetTierId(shop.Id));

            if (Check.NotNullOrEmpty(shop.CriteriaTiers) && shop.CriteriaTiers.ContainsKey(tier + 1) && shop.CriteriaTiers[tier + 1].All(x => Var.MeetsCriterion(context.Account, x)))
            {
                context.Account.AddToVar(ShopHelper.GetTierId(shop.Id));
            }
        }
Beispiel #2
0
        // gets the best DialogEntry based on an NPC.
        public DialogEntry GetBestEntry(Character npc)
        {
            DialogEntry result = null;

            foreach (var entries in Entries
                     .Where(x => x.Criterion != null)
                     .GroupBy(x => x.Criterion.Priority)
                     .OrderByDescending(x => x.Key))
            {
                var available = entries
                                .Where(x => x.Criterion?.Judge?.Invoke(npc) ?? true);

                if (!available.Any())
                {
                    continue;
                }

                result = Randomizer.Choose(available);
                break;
            }

            if (result == null)
            {
                var generic = Entries.Where(x => x.Criterion == null);

                if (!generic.Any())
                {
                    throw new System.Exception("Could not find any available entries.");
                }

                return(Randomizer.Choose(generic));
            }

            return(result);
        }
Beispiel #3
0
        // gets the best reply for a dialog based on the criteria met for an NPC.
        // and the current dialog given.
        public Dialog GetBestReply(Character character, Husk husk, HuskBrain brain, ChatLog log, Dialog dialog)
        {
            var bestReplys = GetAvailableReplys(character, husk, brain, log, dialog)
                             .GroupBy(x => x.Criterion?.Priority ?? 0)
                             .OrderByDescending(x => x.Key);

            if (bestReplys?.Count() > 0)
            {
                return(Randomizer.Choose(bestReplys.First()));
            }

            return(null); // there isn't a reply.
        }
Beispiel #4
0
        public static string GetReply(TickResultFlag flag, ArcadeUser user = null, TickResult result = null)
        {
            IEnumerable <CasinoReply> replies = GetReplies(flag);

            if (user != null && result != null)
            {
                replies = replies.Where(x => MeetsCriteria(x, user, result));
            }

            if (Check.NotNullOrEmpty(replies))
            {
                return(Randomizer.Choose(replies).ToString(user, result));
            }

            return(GetGeneric(flag));
        }
Beispiel #5
0
        public static Message AssignAndDisplay(ArcadeUser user)
        {
            Var.SetIfEmpty(user, Stats.QuestCapacity, DefaultQuestCapacity);

            if (!CanAssign(user))
            {
                return(new Message($"> 🚫 You have already been assigned your daily objectives.\n> Check back in **{Format.Countdown(StatHelper.GetRemainder(user, Stats.LastAssignedQuest, AssignCooldown))}**."));
            }

            if (!HasAnyAssignable(user))
            {
                return(new Message($"> 🚫 You do not meet the criteria to be assigned an objective."));
            }

            IEnumerable <Quest> assignable = GetAssignable(user);

            long available = GetCurrentCapacity(user);

            if (available == 0)
            {
                return(new Message($"> 🚫 You don't currently have any room to be assigned any new objectives."));
            }

            var info = new StringBuilder();

            info.AppendLine($"> {Icons.Assign} You have been assigned new objectives!");

            // If you want to allow for preservation of existing quests, ignore ones already specified
            for (int i = 0; i < available; i++)
            {
                Quest toAssign = Randomizer.Choose(assignable);
                user.Quests.Add(new QuestData(toAssign));
                info.AppendLine($"**Slot {i + 1}: {toAssign.Name}** ({toAssign.Difficulty.ToString()})");
            }

            TimeSpan amountToSkip = AssignCooldown - ((AssignCooldown / user.GetVar(Stats.QuestCapacity)) * available);

            user.SetVar(Stats.LastAssignedQuest, DateTime.UtcNow.Add(amountToSkip).Ticks);
            user.AddToVar(Stats.TotalAssignedQuests, available);

            return(new Message(info.ToString()));
        }
        // Reimplementation of BountyManager.SelectBountyType().
        string SelectBountyType(CustomRandom rng, int level)
        {
            float[] chances = new float[Choices.Length];

            for (int i = 0; i < Choices.Length; i++)
            {
                chances[i] = Choices[i].Rarity;

                if (Choices[i].MinLevel > level)
                {
                    // The bounty's minimum level is higher than the player's level,
                    // so don't give them that bounty.
                    chances[i] = 0f;
                }
                else if (!string.IsNullOrEmpty(BountyManager.instance.LastRecycledBountyType) && BountyManager.instance.LastRecycledBountyType.Contains(Choices[i].Choice))
                {
                    // Don't give the player the same bounty twice in a row.
                    chances[i] = 0f;
                }
                else
                {
                    // Loop through all of the active bounties.
                    foreach (Bounty bounty in BountyManager.instance.Bounties)
                    {
                        // This is to ensure that we don't get the same bounty twice in a row.
                        if (bounty != null && bounty.GetType().ToString().Contains(Choices[i].Choice))
                        {
                            chances[i] = 0f;
                            break;
                        }
                    }
                }
            }

            BountyManager.instance.LastRecycledBountyType = "";

            // Choose the bounty we want to select.
            int chosenIndex = Randomizer.Choose(chances, rng);

            // Return the bounty that was chosen.
            return(Choices[chosenIndex].Choice);
        }
Beispiel #7
0
        public static void Assign(ArcadeUser user)
        {
            Var.SetIfEmpty(user, Stats.QuestCapacity, DefaultQuestCapacity);

            if (!CanAssign(user))
            {
                return;
            }

            if (!HasAnyAssignable(user))
            {
                throw new ArgumentException("The specified user does not have any assignable quests they can use.");
            }

            IEnumerable <Quest> assignable = GetAssignable(user);

            for (int i = 0; i < GetCurrentCapacity(user); i++)
            {
                user.Quests.Add(new QuestData(Randomizer.Choose(assignable)));
            }

            user.SetVar(Stats.LastAssignedQuest, DateTime.UtcNow.Ticks);
        }
Beispiel #8
0
        public RoutineEntry GetNextEntry(string id)
        {
            switch (Order)
            {
            case RoutineSortOrder.Cycle:
                int i = Entries.IndexOf(GetEntry(id));

                if (i >= Entries.Count - 1)
                {
                    i = -1;     // -1, due to ++i
                }
                return(Entries[++i]);

            /*
             * case RoutineSortOrder.Shuffle:
             *  // this would require an additional reference, think about how:
             *  break;
             */

            default:
                return(Randomizer.Choose(Entries));
            }
        }
Beispiel #9
0
 public DialogEntry GetAnyEntry()
 => Randomizer.Choose(Entries);
Beispiel #10
0
        //[Command("drawmoves")]
        public async Task DrawPieceMovesAsync(int whitePieceCount, int blackPieceCount, ChessOwner perspective)
        {
            ChessBoard board = ChessBoard.GetRandom(whitePieceCount, blackPieceCount);

            await Context.Channel.SendMessageAsync(board.DrawMoves(Randomizer.Choose(board.Pieces), perspective));
        }
Beispiel #11
0
 public string GetQuote()
 => Check.NotNullOrEmpty(Quotes) ? Randomizer.Choose(Quotes) : null;
Beispiel #12
0
        // return a random dialogue pool for any pool that is marked as random.
        public static DialogTree GetGenericTree()
        {
            var trees = Dialogs.Values.Where(x => x.IsGeneric);

            return(Randomizer.Choose(trees));
        }
Beispiel #13
0
 public static string GetReply(DailyResultFlag flag)
 {
     string[] replies = GetReplies(flag);
     return(Check.NotNullOrEmpty(replies) ? Randomizer.Choose(replies) : GetGeneric(flag));
 }
Beispiel #14
0
        public Message ApplyAndDisplay(ArcadeUser user)
        {
            var builder  = new MessageBuilder();
            var embedder = new Embedder();

            string         icon  = "💸";
            string         type  = "+";
            string         quote = Replies.GetReply(Flag, user, this);
            long           value = Reward;
            ImmutableColor color = ImmutableColor.GammaGreen;

            Var.Add(user, 1, GimiStats.TimesPlayed);

            switch (Flag)
            {
            case GimiResultFlag.Win:
            case GimiResultFlag.Gold:
                Var.Clear(user, GimiStats.CurrentCurseStreak, GimiStats.CurrentLossStreak, GimiStats.CurrentLossAmount);
                Var.Add(user, 1, GimiStats.TimesWon, GimiStats.CurrentWinStreak);
                Var.Add(user, Reward, GimiStats.TotalWon, GimiStats.CurrentWinAmount);
                Var.SetIfGreater(user, GimiStats.LongestWin, GimiStats.CurrentWinStreak);
                Var.SetIfGreater(user, GimiStats.LargestWin, GimiStats.CurrentWinAmount);

                if (Flag == GimiResultFlag.Gold)
                {
                    icon  = "💎";
                    type  = "+";
                    color = GammaPalette.Glass[Gamma.Max];

                    ItemHelper.GiveItem(user, Items.PocketLawyer);

                    if (RandomProvider.Instance.Next(0, 1001) == 1000)
                    {
                        ItemHelper.GiveItem(user, Items.PaletteGold);
                    }

                    Var.Add(user, 1, GimiStats.TimesGold, GimiStats.CurrentGoldStreak);
                    Var.SetIfGreater(user, GimiStats.LongestGold, GimiStats.CurrentGoldStreak);
                }
                else
                {
                    Var.Clear(user, GimiStats.CurrentGoldStreak);
                    Reward = CurrencyHelper.BoostValue(user, Reward, BoostType.Money);
                }
                long debt = user.Debt;
                user.Give(Reward);

                if (debt > Reward)
                {
                    icon  = "📃";
                    type  = "-";
                    quote = Replies.Recover.Length > 0 ? (string)Randomizer.Choose(Replies.Recover) : Replies.RecoverGeneric;
                }
                else if (debt > 0 && Reward - debt == 0)
                {
                    icon  = "📧";
                    type  = "";
                    quote = Replies.EvenGeneric;
                }

                break;

            case GimiResultFlag.Lose:
            case GimiResultFlag.Curse:
                type  = "-";
                color = ImmutableColor.NeonRed;

                Var.Clear(user, GimiStats.CurrentGoldStreak, GimiStats.CurrentWinStreak, GimiStats.CurrentWinAmount);
                Var.Add(user, 1, GimiStats.TimesLost, GimiStats.CurrentLossStreak);
                Var.Add(user, Reward, GimiStats.TotalLost, GimiStats.CurrentLossAmount);
                Var.SetIfGreater(user, GimiStats.LongestLoss, GimiStats.CurrentLossStreak);
                Var.SetIfGreater(user, GimiStats.LargestLoss, GimiStats.CurrentLossAmount);

                if (Flag == GimiResultFlag.Curse)
                {
                    icon  = "🌕";
                    type  = "-";
                    color = GammaPalette.Alconia[Gamma.Standard];

                    Var.Add(user, 1, GimiStats.TimesCursed, GimiStats.CurrentCurseStreak);
                    Var.SetIfGreater(user, GimiStats.LongestCurse, GimiStats.CurrentCurseStreak);
                }
                else
                {
                    Var.Clear(user, GimiStats.CurrentCurseStreak);
                    Reward = CurrencyHelper.BoostValue(user, Reward, BoostType.Money);
                }

                long balance = user.Balance;
                user.Take(Reward);

                if (balance < Reward)
                {
                    icon  = "📃";
                    type  = "+";
                    value = Reward - balance;
                    quote = Replies.Debt.Length > 0 ? (string)Randomizer.Choose(Replies.Debt) : Replies.DebtGeneric;
                }
                else if (balance > 0 && Reward - balance == 0)
                {
                    icon  = "📧";
                    value = Reward - balance;
                    type  = "";
                    quote = Replies.EvenGeneric;
                }
                break;
            }

            if (!string.IsNullOrWhiteSpace(type))
            {
                type += ' ';
            }

            string header  = $"**{type}{icon} {value:##,0}**";
            string content = $"*\"{quote}\"*";

            embedder.Header  = header;
            embedder.Color   = color;
            builder.Embedder = embedder;
            builder.Content  = content;

            return(builder.Build());
        }