public static string CompleteAndDisplay(ArcadeUser user) { if (user.Quests.Count == 0) { return($"> {Icons.Warning} You do not have any currently assigned objectives."); } if (!user.Quests.Any(MeetsCriteria)) { return($"> {Icons.Warning} You have not met the criteria for any currently assigned objectives."); } IEnumerable <QuestData> complete = user.Quests.Where(MeetsCriteria); var info = new StringBuilder(); int count = complete.Count(); if (count == 0) { throw new Exception("Expected at least 1 completed merit but returned 0"); } if (count == 1) { QuestData completed = complete.FirstOrDefault(); Quest quest = GetQuest(completed.Id); user.Quests.Remove(completed); user.AddToVar(Stats.TotalCompletedQuests); info.AppendLine($"> **{quest.Name}** ({quest.Difficulty})"); info.AppendLine($"> {Icons.Complete} You have completed an objective!\n"); info.AppendLine("> You have been rewarded:"); info.AppendLine(WriteReward(quest.Reward)); quest.Reward.Apply(user); return(info.ToString()); } user.Quests.RemoveAll(x => complete.Contains(x)); Reward sum = SumRewards(complete.Select(x => GetQuest(x.Id)?.Reward)); info.AppendLine($"> {Icons.Complete} You have completed **{count}** objectives!\n"); info.AppendLine("> You have been rewarded:"); info.AppendLine(WriteReward(sum)); user.AddToVar(Stats.TotalCompletedQuests, count); sum.Apply(user); return(info.ToString()); }
public static bool Craft(ArcadeUser user, Recipe recipe) { if (GetRecipeStatus(user, recipe) == RecipeStatus.Unknown) { return(false); } if (!CanCraft(user, recipe)) { return(false); } if (recipe.Result == null) { throw new Exception("Expected recipe result but returned null"); } foreach ((string itemId, int amount) in recipe.Components) { ItemHelper.TakeItem(user, itemId, amount); } ItemHelper.GiveItem(user, recipe.Result.ItemId, recipe.Result.Amount); user.AddToVar(Stats.ItemsCrafted); return(true); }
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())); }