private void StartQuest(ChatMessage message, Player player, Quest quest) { Double successChance = player.GetQuestSuccessChance(); Boolean successful = Random.TryPercentChance(successChance); var resultMessage = successful ? quest.OnSuccess(player, Random.NextElement(EmoteManager.Get(message.Channel, EmoteCategory.Positive))) : quest.FailureMessage + " " + Random.NextElement(EmoteManager.Get(message.Channel, EmoteCategory.Negative)); StringBuilder questPrompt = new(); questPrompt .Append($"[Quest {String.Format("{0:0.0}", successChance * 100)}% success] "); if (quest.IsRare) { var positiveEmotes = EmoteManager.Get(message.Channel, EmoteCategory.Positive); questPrompt .Append(Random.NextElement(positiveEmotes)) .Append(" RARE QUEST!!! ") .Append(Random.NextElement(positiveEmotes)) .Append(' '); } questPrompt .Append($"{GetPlayerWithWorkers(player)} travel to {quest.Location}. {resultMessage}"); Client.SpoolMessageAsMe(message.Channel, player, questPrompt.ToString()); }
private String GetRankUpMessage(ChatMessage message, Player player, IApplicationContext context, out Priority priority) { priority = Priority.Low; if (RanksToPoints.TryGetValue(player.Rank, out Int32 pointsToRank)) { Rank nextRank = player.Rank.Next(); if (player.Points >= pointsToRank) { if (nextRank == Rank.None) { if (player.HasUnlockedAllRecipes()) { HeistManager.LeaveAllHeists(context, player); // Prestige instead of rank up player.ResetRank(); player.Prestige++; context.SaveChanges(); var positiveEmotes = EmoteManager.Get(message.Channel, EmoteCategory.Positive); priority = Priority.Medium; return($"{Random.NextElement(positiveEmotes)} You prestiged back to {Rank.Bronze} and have gained a permanent {(Int32)(PrestigeBonus * 100)}% cheese gain boost. {Random.NextElement(positiveEmotes)}"); } return($"You need to buy all cheese recipes in order to prestige back to {Rank.Bronze} rank. " + $"You will lose all your cheese and upgrades, but will gain a permanent {(Int32)(PrestigeBonus * 100)}% bonus on your cheese gains."); } player.Points -= pointsToRank; player.Rank = nextRank; context.SaveChanges(); priority = Priority.Medium; return($"You ranked up to {nextRank}. {Random.NextElement(EmoteManager.Get(message.Channel, EmoteCategory.Positive))} (-{pointsToRank} cheese)"); } var pointsNeededToRank = pointsToRank - player.Points; if (nextRank == Rank.None) { return($"You need {pointsNeededToRank} more cheese in order to prestige back to {Rank.Bronze} rank. " + $"You will lose all your cheese and upgrades, but will gain a permanent {(Int32)(PrestigeBonus * 100)}% bonus on your cheese gains."); } return($"You need {pointsNeededToRank} more cheese in order to rank up to {nextRank}."); } return($"Uh oh, you broke something. You have an invalid rank of {player.Rank}."); }
private void InitiateNewHeist(ChatMessage message) { using var context = ContextFactory.GetContext(); var player = context.GetPlayer(Client, message); // Trying to initiate new heist var now = DateTime.Now; var oldLastHeistInitiated = player.LastHeistInitiated; var timeSinceLastHeistInitiated = now - oldLastHeistInitiated; if (timeSinceLastHeistInitiated >= HeistCooldown) { // Update last heist initiated to prevent initiating // multiple heists in multiple channels. player.LastHeistInitiated = now; context.SaveChanges(); var heist = new Heist(message, Random, Client); OngoingHeists.TryAdd(message.Channel, heist); Client.SpoolMessageAsMe(message.Channel, player, Messages.NewHeistInitiated.Format(HeistWaitTime.Format())); // Join the heist in a separate thread so that the heist // countdown can start immediately as the join is being // processed. This should only save around a second or so of // time. Task.Run(() => JoinHeist(message, player, context)); // Since we are sleeping, this needs to be async. ThreadService.Sleep(HeistWaitTime); if (!heist.Start(context)) { // No one joined the heist. Let the user initiate another heist. player.LastHeistInitiated = oldLastHeistInitiated; context.SaveChanges(); } OngoingHeists.TryRemove(message.Channel, out _); return; } var timeUntilNextHeistAvailable = HeistCooldown - timeSinceLastHeistInitiated; var timeToWait = timeUntilNextHeistAvailable.Format(); Client.SpoolMessageAsMe(message.Channel, player, Messages.Wait.Format(timeToWait, Random.NextElement(EmoteManager.Get(message.Channel, EmoteCategory.Waiting)))); }
private void PromptStartQuestFailed(ChatMessage message, Player player, TimeSpan timeSinceLastQuestVentured) { var timeUntilNextQuestAvailable = QuestCooldown - timeSinceLastQuestVentured; var timeToWait = timeUntilNextQuestAvailable.Format(); Client.SpoolMessageAsMe(message.Channel, player, $"[Quest {String.Format("{0:0.0}", player.GetQuestSuccessChance() * 100)}% success] " + $"You must wait {timeToWait} until you can go on your next quest. {Random.NextElement(EmoteManager.Get(message.Channel, EmoteCategory.Waiting))}", Priority.Low); }
public async void AddPoints(ChatMessage message) { DateTime now = DateTime.Now; using var context = ContextFactory.GetContext(); Player player = context.GetPlayer(Client, message); TimeSpan timeSinceLastPointGain = now - player.LastPointsGained; Int32 playerStorage = player.GetTotalStorage(); if (timeSinceLastPointGain >= PointGainCooldown) { if (player.Points >= playerStorage) { Client.SpoolMessageAsMe(message.Channel, player, $" You have {player.Points}/{playerStorage} cheese and cannot store any more. Consider buying more cheese storage with \"!cheese buy storage\"."); return; } RecipeInfo initialCheese = Random.NextElement(RecipeRepository, player.CheeseUnlocked); RecipeModifier modifier = Random.NextElement(RecipeModifierManager, (Int32)player.NextCheeseModifierUpgradeUnlock); RecipeInfo cheese = modifier.Modify(initialCheese); StringBuilder outputMessage = new(); String infestationStatus = HazardManager.UpdateInfestationStatus(player); var infestationTask = context.SaveChangesAsync(); if (!String.IsNullOrWhiteSpace(infestationStatus)) { outputMessage .Append(infestationStatus) .Append(Random.NextElement(EmoteManager.Get(message.Channel, EmoteCategory.Rat))) .Append(' '); } Boolean isCritical = Random.TryPercentChance((Int32)player.NextCriticalCheeseUpgradeUnlock * RankUpgradeExtensions.CriticalCheeseUpgradePercent); await infestationTask; var modifiedPoints = player.GetModifiedPoints(cheese.Points, isCritical); player.AddPoints(modifiedPoints); player.LastPointsGained = now; var addPointsTask = context.SaveChangesAsync(); Boolean isPositive = cheese.Points > 0; var emoteCategory = isPositive ? EmoteCategory.Positive : EmoteCategory.Negative; var emoteList = EmoteManager.Get(message.Channel, emoteCategory); if (isCritical) { outputMessage.Append(Random.NextElement(emoteList)); if (!isPositive) { outputMessage.Append(" NEGATIVE "); } outputMessage .Append(" CRITICAL CHEESE!!! ") .Append(Random.NextElement(emoteList)) .Append(' '); } outputMessage.Append($"You made some {cheese.Name}. {Random.NextElement(emoteList)} ({(isPositive ? "+" : String.Empty)}{modifiedPoints} cheese)"); Client.SpoolMessageAsMe(message.Channel, player, outputMessage.ToString()); await addPointsTask; return; } TimeSpan timeUntilNextValidPointGain = PointGainCooldown - timeSinceLastPointGain; String timeToWait = timeUntilNextValidPointGain.Format(); Client.SpoolMessageAsMe(message.Channel, player, $"You must wait {timeToWait} until you can make more cheese. {Random.NextElement(EmoteManager.Get(message.Channel, EmoteCategory.Waiting))}", Priority.Low); }