/// <summary> /// Changes discord rich presence to show results. /// </summary> private void ChangeDiscordPresence() { DiscordHelper.Presence.EndTimestamp = 0; // Don't change if we're loading in from a replay file. if (ResultsType == ResultScreenType.Replay || Gameplay.InReplayMode) { DiscordHelper.Presence.Details = "Idle"; DiscordHelper.Presence.State = "In the Menus"; DiscordRpc.UpdatePresence(ref DiscordHelper.Presence); return; } var state = Gameplay.Failed ? "Fail" : "Pass"; var score = $"{ScoreProcessor.Score / 1000}k"; var acc = $"{StringHelper.AccuracyToString(ScoreProcessor.Accuracy)}"; var grade = Gameplay.Failed ? "F" : GradeHelper.GetGradeFromAccuracy(ScoreProcessor.Accuracy).ToString(); var combo = $"{ScoreProcessor.MaxCombo}x"; if (OnlineManager.CurrentGame == null) { DiscordHelper.Presence.State = $"{state}: {grade} {score} {acc} {combo}"; } else { if (OnlineManager.CurrentGame.Ruleset == MultiplayerGameRuleset.Team) { var redTeamAverage = GetTeamAverage(MultiplayerTeam.Red); var blueTeamAverage = GetTeamAverage(MultiplayerTeam.Blue); DiscordHelper.Presence.State = $"Red: {redTeamAverage:0.00} vs. Blue: {blueTeamAverage:0.00}"; } else { DiscordHelper.Presence.State = $"{StringHelper.AddOrdinal(MultiplayerScores.First().Rank)} " + $"Place: {MultiplayerScores.First().RatingProcessor.CalculateRating(ScoreProcessor):0.00} {acc} {grade}"; } } DiscordRpc.UpdatePresence(ref DiscordHelper.Presence); }
private async Task ResumeMainMenu(IDialogContext context, IAwaitable <GameState> result) { var state = await result; if (state.IsGameOver) { var user = this.GetUser(context); var score = user.Wallet; if (user.LoanDebt > 0) { await context.PostAsync($"Ya' punk #$%! kid--I'm gonna break both your legs and take back my {user.LoanDebt:C0}!"); await context.PostAsync("The loan shark proceeds to break your legs and take his money."); score = user.Wallet - user.LoanDebt; } // record log of game before resetting var db = new DrugBotDataContext(); var game = new Game { UserId = user.UserId, Score = score }; db.Games.Add(game); db.Commit(); // get their rank var orderedGame = db.Games .OrderByDescending(x => x.Score) .AsEnumerable() .Select((x, i) => new { Game = x, Rank = i + 1 }) .Single(x => x.Game.GameId == game.GameId); await context.PostAsync("Game Over."); await context.PostAsync($"You finished with {score:C0} " + $"({StringHelper.AddOrdinal(orderedGame.Rank)} overall)"); await this.ShowLeaderboard(context); await context.PostAsync("Type PLAY to start another game!"); // reset user (this commits db changes) this.ResetUser(context); this.Done(context); } else if (state.IsTraveling) { var user = this.GetUser(context); // todo: random events for the day if (RandomEvent.IsGoingToHappen) { // pass context and user to do db things, receive event info var randomEvent = RandomEvent.Get(context, user.UserId); context.UserData.SetValue(StateKeys.RandomEvent, randomEvent); } // get day and location var location = this.GetLocations().Single(x => x.LocationId == user.LocationId); await context.PostAsync($"It's day {user.DayOfGame}. You're in {location.Name}."); await StartAsync(context); } else { // print menu and start again--hopefully await StartAsync(context); } }
/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnBeatSnapChanged(object sender, BindableValueChangedEventArgs <int> e) => TextBeatSnap.Text = $"Beat Snap: 1/{StringHelper.AddOrdinal(Screen.BeatSnap.Value)}";
/// <summary> /// Pauses the game. /// </summary> internal void Pause(GameTime gameTime = null) { // Don't allow pausing if the play is already finished. if (IsPlayComplete) { return; } // Grab the casted version of the screenview. var screenView = (GameplayScreenView)View; // Handle pause. // Spectating is an exception here because we're not technically "paused" if (!IsPaused || SpectatorClient != null) { // Handle cases where someone (a developer) calls pause but there is not GameTime. // shouldn't ever happen though. if (gameTime == null) { const string log = "Cannot pause if GameTime is null"; Logger.Error(log, LogType.Runtime); throw new InvalidOperationException(log); } // Increase the time the pause key has been held. TimePauseKeyHeld += gameTime.ElapsedGameTime.TotalMilliseconds; screenView.Transitioner.Alpha = MathHelper.Lerp(screenView.Transitioner.Alpha, 1, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / TimeToHoldPause, 1)); // Make the user hold the pause key down before pausing if tap to pause is disabled. if (!ConfigManager.TapToPause.Value && TimePauseKeyHeld < TimeToHoldPause) { return; } IsPaused = true; IsResumeInProgress = false; PauseCount++; GameBase.Game.GlobalUserInterface.Cursor.Alpha = 1; // Exit right away if playing a replay. if (InReplayMode) { CustomAudioSampleCache.StopAll(); ModManager.RemoveAllMods(); if (SpectatorClient != null) { OnlineManager.Client?.StopSpectating(); } Exit(() => new SelectScreen()); return; } // Show notification to the user that their score is invalid. NotificationManager.Show(NotificationLevel.Warning, "WARNING! Your score will not be submitted due to pausing during gameplay!"); // Add the pause mod to their score. if (!ModManager.IsActivated(ModIdentifier.Paused)) { ModManager.AddMod(ModIdentifier.Paused); ReplayCapturer.Replay.Mods |= ModIdentifier.Paused; Ruleset.ScoreProcessor.Mods |= ModIdentifier.Paused; } try { AudioEngine.Track.Pause(); } catch (Exception) { // ignored } CustomAudioSampleCache.PauseAll(); DiscordHelper.Presence.State = $"Paused for the {StringHelper.AddOrdinal(PauseCount)} time"; DiscordHelper.Presence.EndTimestamp = 0; DiscordRpc.UpdatePresence(ref DiscordHelper.Presence); OnlineManager.Client?.UpdateClientStatus(GetClientStatus()); // Fade in the transitioner. screenView.Transitioner.Animations.Clear(); screenView.Transitioner.Animations.Add(new Animation(AnimationProperty.Alpha, Easing.Linear, screenView.Transitioner.Alpha, 0.75f, 400)); // Activate pause menu screenView.PauseScreen?.Activate(); return; } if (IsResumeInProgress) { return; } // Setting the resume time in this case allows us to give the user time to react // with a delay before starting the audio track again. // When that resume time is past the specific set offset, it'll unpause the game. IsResumeInProgress = true; ResumeTime = GameBase.Game.TimeRunning; // Fade screen transitioner screenView.Transitioner.Animations.Clear(); var alphaTransformation = new Animation(AnimationProperty.Alpha, Easing.Linear, 0.75f, 0, 400); screenView.Transitioner.Animations.Add(alphaTransformation); // Deactivate pause screen. screenView.PauseScreen?.Deactivate(); SetRichPresence(); OnlineManager.Client?.UpdateClientStatus(GetClientStatus()); GameBase.Game.GlobalUserInterface.Cursor.Alpha = 0; }
/// <summary> /// </summary> private void CreateTextBeatSnap() => TextBeatSnap = new SpriteTextBitmap(FontsBitmap.AllerRegular, $"Beat Snap: 1/{StringHelper.AddOrdinal(Screen.BeatSnap.Value)}") { Parent = this, X = 10, Y = ObjectCount.Y + ObjectCount.Height + 14, FontSize = 16 };