Esempio n. 1
0
        /// <summary>
        ///     Sets rich presence based on which activity we're doing in gameplay.
        /// </summary>
        public void SetRichPresence()
        {
            DiscordHelper.Presence.Details = Map.ToString();

            if (OnlineManager.CurrentGame != null)
            {
                if (OnlineManager.CurrentGame.Ruleset == MultiplayerGameRuleset.Battle_Royale)
                {
                    var view = View as GameplayScreenView;

                    var alivePlayers = OnlineManager.CurrentGame.Players.Count;

                    if (view?.ScoreboardLeft != null)
                    {
                        alivePlayers = view.ScoreboardLeft.Users.FindAll(x => !x.Processor.MultiplayerProcessor.IsBattleRoyaleEliminated).Count;
                    }

                    DiscordHelper.Presence.State = $"Battle Royale - {alivePlayers} Left";
                }
                else
                {
                    DiscordHelper.Presence.State = $"{OnlineManager.CurrentGame.Name} " +
                                                   $"({OnlineManager.CurrentGame.PlayerIds.Count} of {OnlineManager.CurrentGame.MaxPlayers})";
                }
            }
            else if (IsPlayTesting)
            {
                DiscordHelper.Presence.State = "Play Testing";
            }
            else if (InReplayMode)
            {
                DiscordHelper.Presence.State = OnlineManager.IsSpectatingSomeone ? $"Spectating {LoadedReplay.PlayerName}" : $"Watching {LoadedReplay.PlayerName}";
            }
            else
            {
                DiscordHelper.Presence.State = $"Playing {(ModManager.Mods > 0 ? "+ " + ModHelper.GetModsString(ModManager.Mods) : "")}";
            }

            // Only set time if we're not spectating anywone
            if (!OnlineManager.IsSpectatingSomeone)
            {
                var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                var time  = Convert.ToInt64((DateTime.UtcNow.AddMilliseconds((Map.Length - Timing.Time) / AudioEngine.Track.Rate) - epoch).TotalSeconds);
                DiscordHelper.Presence.EndTimestamp = time;
            }

            DiscordHelper.Presence.LargeImageText = OnlineManager.GetRichPresenceLargeKeyText(Ruleset.Mode);
            DiscordRpc.UpdatePresence(ref DiscordHelper.Presence);
        }
Esempio n. 2
0
        /// <summary>
        ///     Sets rich presence based on which activity we're doing in gameplay.
        /// </summary>
        private void SetRichPresence()
        {
            DiscordHelper.Presence.Details = Map.ToString();

            if (InReplayMode)
                DiscordHelper.Presence.State = $"Watching {LoadedReplay.PlayerName}";
            else
                DiscordHelper.Presence.State = $"Playing {(ModManager.Mods > 0 ? "+ " + ModHelper.GetModsString(ModManager.Mods) : "")}";

            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var time = Convert.ToInt64((DateTime.UtcNow.AddMilliseconds((Map.Length - Timing.Time) / AudioEngine.Track.Rate) - epoch).TotalSeconds);

            DiscordHelper.Presence.EndTimestamp = time;
            DiscordHelper.Presence.LargeImageText = OnlineManager.GetRichPresenceLargeKeyText(Ruleset.Mode);
            DiscordRpc.UpdatePresence(ref DiscordHelper.Presence);
        }