Пример #1
0
        private static bool TryWriteCooldown(ArcadeUser user, string name, string id, TimeSpan duration, out string row)
        {
            row = null;
            if (user.GetVar(id) > 0)
            {
                TimeSpan since = StatHelper.SinceLast(user, id);

                if (since < duration)
                {
                    row = $"> • **{name}:** **{Format.Countdown(duration - since)}** until reset";
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        private static List <string> GetRandomStats(ArcadeUser user, int count)
        {
            var    chosen = new List <string>();
            string stat   = StatHelper.GetRandomStat(user, chosen);

            while (!string.IsNullOrWhiteSpace(stat))
            {
                if (chosen.Count >= count)
                {
                    break;
                }

                chosen.Add(stat);
                stat = StatHelper.GetRandomStat(user, chosen);
            }

            return(chosen);
        }
Пример #3
0
        public static string TossSlot(ArcadeUser user, int index)
        {
            QuestData slot = GetSlot(user, index);

            if (slot == null)
            {
                return($"> {Icons.Warning} There isn't an assigned objective in this slot.");
            }

            if (user.GetVar(Stats.LastSkippedQuest) > 0)
            {
                if (StatHelper.SinceLast(user, Stats.LastSkippedQuest) >= SkipCooldown)
                {
                    return($"> {Icons.Warning} You have skipped an objective too recently. Try again in {Format.Countdown(SkipCooldown - StatHelper.SinceLast(user, Stats.LastSkippedQuest))}.");
                }
            }

            Quest quest = GetQuest(slot.Id);

            if (quest == null)
            {
                throw new Exception("Expected to find a parent quest but returned null");
            }

            user.Quests.RemoveAt(index);
            user.SetVar(Stats.LastSkippedQuest, DateTime.UtcNow.Ticks);

            TimeSpan since = StatHelper.SinceLast(user, Stats.LastAssignedQuest);

            bool canAssign = since >= AssignCooldown;

            if (!canAssign)
            {
                TimeSpan toSkip = (AssignCooldown - since) / 2; // skip 50% of the remaining time
                user.SetVar(Stats.LastAssignedQuest, new DateTime(user.GetVar(Stats.LastAssignedQuest)).Add(toSkip).Ticks);
            }

            return($"> 🗑️ You have declined the **{quest.Name}** objective.");
        }
Пример #4
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()));
        }
Пример #5
0
        public static bool CanAssign(ArcadeUser user)
        {
            TimeSpan since = StatHelper.SinceLast(user, Stats.LastAssignedQuest);

            return(since >= AssignCooldown && user.Quests.Count <= user.GetVar(Stats.QuestCapacity));
        }