Пример #1
0
    // Start is called before the first frame update
    void Awake()
    {
        CustomEvents.EventUtil.AddListener(CustomEventList.ADD_POINTS, OnPointsAdded);
        CustomEvents.EventUtil.AddListener(CustomEventList.SLOW_TIME, OnSlowTime);
        CustomEvents.EventUtil.AddListener(CustomEventList.PLAYER_DIED, OnPlayerDied);

        ResetParameters();

        instance = this;
    }
Пример #2
0
        public SongListItem(GameplayParameters parameters)
        {
            this.parameters   = parameters;
            cancellationToken = new CancellationTokenSource();

            if (OstHelper.IsOst(parameters.Beatmap.LevelId) || SongUtils.masterLevelList.Any(x => x.levelID == parameters.Beatmap.LevelId))
            {
                downloadState = DownloadState.Complete;
                level         = SongUtils.masterLevelList.First(x => x.levelID == parameters.Beatmap.LevelId);
            }
            else
            {
                SongDownloader.DownloadSong(parameters.Beatmap.LevelId, true, OnSongDownloaded, OnDownloadProgress);
            }
        }
        private void songDetail_didPressPlayButtonEvent(IBeatmapLevel _, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty)
        {
            var playSong           = new PlaySong();
            var gameplayParameters = new GameplayParameters();

            gameplayParameters.Beatmap = new Beatmap();
            gameplayParameters.Beatmap.Characteristic = Match.SelectedLevel.Characteristics.First(x => x.SerializedName == characteristic.serializedName);
            gameplayParameters.Beatmap.Difficulty     = (SharedConstructs.BeatmapDifficulty)difficulty;
            gameplayParameters.Beatmap.LevelId        = Match.SelectedLevel.LevelId;

            gameplayParameters.GameplayModifiers = new TournamentAssistantShared.Models.GameplayModifiers();
            gameplayParameters.PlayerSettings    = new TournamentAssistantShared.Models.PlayerSpecificSettings();

            playSong.GameplayParameters = gameplayParameters;
            playSong.FloatingScoreboard = true;

            Plugin.client.Send(Match.Players.Select(x => x.Id).ToArray(), new Packet(playSong));
        }
Пример #4
0
        public void SetSongs(List <IPreviewBeatmapLevel> songs)
        {
            this.songs.Clear();
            this.songs.AddRange(songs.Select(x => {
                var parameters = new GameplayParameters
                {
                    Beatmap = new Beatmap
                    {
                        LevelId        = x.levelID,
                        Characteristic = new Characteristic
                        {
                            SerializedName = "Standard"
                        },
                        Difficulty = TournamentAssistantShared.SharedConstructs.BeatmapDifficulty.ExpertPlus
                    },
                    GameplayModifiers = new TournamentAssistantShared.Models.GameplayModifiers(),
                    PlayerSettings    = new TournamentAssistantShared.Models.PlayerSpecificSettings()
                };
                return(new SongListItem(parameters));
            }));

            songList?.tableView.ReloadData();
        }
Пример #5
0
 public void MergeFrom(PlaySong other)
 {
     if (other == null)
     {
         return;
     }
     if (other.gameplayParameters_ != null)
     {
         if (gameplayParameters_ == null)
         {
             GameplayParameters = new global::TournamentAssistantShared.Models.GameplayParameters();
         }
         GameplayParameters.MergeFrom(other.GameplayParameters);
     }
     if (other.FloatingScoreboard != false)
     {
         FloatingScoreboard = other.FloatingScoreboard;
     }
     if (other.StreamSync != false)
     {
         StreamSync = other.StreamSync;
     }
     if (other.DisablePause != false)
     {
         DisablePause = other.DisablePause;
     }
     if (other.DisableScoresaberSubmission != false)
     {
         DisableScoresaberSubmission = other.DisableScoresaberSubmission;
     }
     if (other.ShowNormalNotesOnStream != false)
     {
         ShowNormalNotesOnStream = other.ShowNormalNotesOnStream;
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
        public async Task AddSongAsync([Remainder] string paramString = null)
        {
            if (IsAdmin())
            {
                var eventId = paramString.ParseArgs("eventId");
                var songId  = paramString.ParseArgs("song");

                if (string.IsNullOrEmpty(eventId) || string.IsNullOrEmpty(songId))
                {
                    await ReplyAsync(embed : ("Usage: `addSong -eventId \"[event id]\" -song [song link]`\n" +
                                              "To find event ids, please run `listEvents`\n" +
                                              "Optional parameters: `-difficulty [difficulty]`, `-characteristic [characteristic]` (example: `-characteristic onesaber`), `-[modifier]` (example: `-nofail`)").ErrorEmbed());

                    return;
                }

                //Parse the difficulty input, either as an int or a string
                BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus;

                string difficultyArg = paramString.ParseArgs("difficulty");
                if (difficultyArg != null)
                {
                    //If the enum conversion doesn't succeed, try it as an int
                    if (!Enum.TryParse(difficultyArg, true, out difficulty))
                    {
                        await ReplyAsync(embed : "Could not parse difficulty parameter".ErrorEmbed());

                        return;
                    }
                }

                string characteristic = paramString.ParseArgs("characteristic");
                characteristic = characteristic ?? "Standard";

                GameOptions   gameOptions   = GameOptions.None;
                PlayerOptions playerOptions = PlayerOptions.None;

                //Load up the GameOptions and PlayerOptions
                foreach (GameOptions o in Enum.GetValues(typeof(GameOptions)))
                {
                    if (paramString.ParseArgs(o.ToString()) == "true")
                    {
                        gameOptions = (gameOptions | o);
                    }
                }

                foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions)))
                {
                    if (paramString.ParseArgs(o.ToString()) == "true")
                    {
                        playerOptions = (playerOptions | o);
                    }
                }

                //Sanitize input
                if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/"))
                {
                    //Strip off the trailing slash if there is one
                    if (songId.EndsWith("/"))
                    {
                        songId = songId.Substring(0, songId.Length - 1);
                    }

                    //Strip off the beginning of the url to leave the id
                    songId = songId.Substring(songId.LastIndexOf("/") + 1);
                }

                if (songId.Contains("&"))
                {
                    songId = songId.Substring(0, songId.IndexOf("&"));
                }

                var server = ServerService.GetServer();
                if (server == null)
                {
                    await ReplyAsync(embed : "The Server is not running, so we can't can't add songs to it".ErrorEmbed());
                }
                else
                {
                    //Get the hash for the song
                    var hash       = BeatSaverDownloader.GetHashFromID(songId);
                    var knownPairs = await HostScraper.ScrapeHosts(server.State.KnownHosts, $"{server.CoreServer.Address}:{server.CoreServer.Port}", 0);

                    var targetPair  = knownPairs.FirstOrDefault(x => x.Value.Events.Any(y => y.EventId.ToString() == eventId));
                    var targetEvent = targetPair.Value.Events.FirstOrDefault(x => x.EventId.ToString() == eventId);
                    var songPool    = targetEvent.QualifierMaps.ToList();

                    if (OstHelper.IsOst(hash))
                    {
                        if (!SongExists(songPool, hash, characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions))
                        {
                            GameplayParameters parameters = new GameplayParameters
                            {
                                Beatmap = new Beatmap
                                {
                                    Name           = OstHelper.GetOstSongNameFromLevelId(hash),
                                    LevelId        = hash,
                                    Characteristic = new Characteristic
                                    {
                                        SerializedName = characteristic
                                    },
                                    Difficulty = difficulty
                                },
                                GameplayModifiers = new GameplayModifiers
                                {
                                    Options = gameOptions
                                },
                                PlayerSettings = new PlayerSpecificSettings
                                {
                                    Options = playerOptions
                                }
                            };

                            songPool.Add(parameters);
                            targetEvent.QualifierMaps = songPool.ToArray();

                            var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent);

                            if (response.Type == Response.ResponseType.Success)
                            {
                                await ReplyAsync(embed : ($"Added: {parameters.Beatmap.Name} ({difficulty}) ({characteristic})" +
                                                          $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" +
                                                          $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}").SuccessEmbed());
                            }
                            else if (response.Type == Response.ResponseType.Fail)
                            {
                                await ReplyAsync(embed : response.Message.ErrorEmbed());
                            }
                        }
                        else
                        {
                            await ReplyAsync(embed : "Song is already active in the database".ErrorEmbed());
                        }
                    }
                    else
                    {
                        BeatSaverDownloader.DownloadSong(hash, async(songPath) =>
                        {
                            if (songPath != null)
                            {
                                DownloadedSong song = new DownloadedSong(hash);
                                string songName     = song.Name;

                                if (!song.GetBeatmapDifficulties(characteristic).Contains(difficulty))
                                {
                                    BeatmapDifficulty nextBestDifficulty = song.GetClosestDifficultyPreferLower(difficulty);

                                    if (SongExists(songPool, hash, characteristic, (int)nextBestDifficulty, (int)gameOptions, (int)playerOptions))
                                    {
                                        await ReplyAsync(embed: $"{songName} doesn't have {difficulty}, and {nextBestDifficulty} is already in the event".ErrorEmbed());
                                    }
                                    else
                                    {
                                        GameplayParameters parameters = new GameplayParameters
                                        {
                                            Beatmap = new Beatmap
                                            {
                                                Name           = songName,
                                                LevelId        = $"custom_level_{hash.ToUpper()}",
                                                Characteristic = new Characteristic
                                                {
                                                    SerializedName = characteristic
                                                },
                                                Difficulty = nextBestDifficulty
                                            },
                                            GameplayModifiers = new GameplayModifiers
                                            {
                                                Options = gameOptions
                                            },
                                            PlayerSettings = new PlayerSpecificSettings
                                            {
                                                Options = playerOptions
                                            }
                                        };

                                        songPool.Add(parameters);
                                        targetEvent.QualifierMaps = songPool.ToArray();

                                        var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent);
                                        if (response.Type == Response.ResponseType.Success)
                                        {
                                            await ReplyAsync(embed: ($"{songName} doesn't have {difficulty}, using {nextBestDifficulty} instead.\n" +
                                                                     $"Added to the song list" +
                                                                     $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" +
                                                                     $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}").SuccessEmbed());
                                        }
                                        else if (response.Type == Response.ResponseType.Fail)
                                        {
                                            await ReplyAsync(embed: response.Message.ErrorEmbed());
                                        }
                                    }
                                }
                                else
                                {
                                    GameplayParameters parameters = new GameplayParameters
                                    {
                                        Beatmap = new Beatmap
                                        {
                                            Name           = songName,
                                            LevelId        = $"custom_level_{hash.ToUpper()}",
                                            Characteristic = new Characteristic
                                            {
                                                SerializedName = characteristic
                                            },
                                            Difficulty = difficulty
                                        },
                                        GameplayModifiers = new GameplayModifiers
                                        {
                                            Options = gameOptions
                                        },
                                        PlayerSettings = new PlayerSpecificSettings
                                        {
                                            Options = playerOptions
                                        }
                                    };

                                    songPool.Add(parameters);
                                    targetEvent.QualifierMaps = songPool.ToArray();

                                    var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent);
                                    if (response.Type == Response.ResponseType.Success)
                                    {
                                        await ReplyAsync(embed: ($"{songName} ({difficulty}) ({characteristic}) downloaded and added to song list" +
                                                                 $"{(gameOptions != GameOptions.None ? $" with game options: ({gameOptions})" : "")}" +
                                                                 $"{(playerOptions != PlayerOptions.None ? $" with player options: ({playerOptions})" : "!")}").SuccessEmbed());
                                    }
                                    else if (response.Type == Response.ResponseType.Fail)
                                    {
                                        await ReplyAsync(embed: response.Message.ErrorEmbed());
                                    }
                                }
                            }
                            else
                            {
                                await ReplyAsync(embed: "Could not download song.".ErrorEmbed());
                            }
                        });
                    }
                }
            }
            else
            {
                await ReplyAsync(embed : "You do not have sufficient permissions to use this command".ErrorEmbed());
            }
        }
Пример #7
0
        public async Task AddSongAsync([Remainder] string paramString = null)
        {
            if (IsAdmin())
            {
                var eventId = paramString.ParseArgs("赛事");
                var songId  = paramString.ParseArgs("歌曲");

                if (string.IsNullOrEmpty(eventId) || string.IsNullOrEmpty(songId))
                {
                    await ReplyAsync(embed : ("用法: `添加歌曲 -赛事 \"[赛事ID]\" -歌曲 [链接/key]`\n" +
                                              "赛事ID可以通过`赛事列表`命令查找\n" +
                                              "可选参数: `-难度 [Easy/Normal/Hard/Expert/ExpertPlus]`, `-谱型 [例如: onesaber]`, `-[修改项]` (例如: 不死模式为 `-nofail`)").ErrorEmbed());

                    return;
                }

                //Parse the difficulty input, either as an int or a string
                BeatmapDifficulty difficulty = BeatmapDifficulty.ExpertPlus;

                string difficultyArg = paramString.ParseArgs("难度");
                if (difficultyArg != null)
                {
                    //If the enum conversion doesn't succeed, try it as an int
                    if (!Enum.TryParse(difficultyArg, true, out difficulty))
                    {
                        await ReplyAsync(embed : "请检查难度参数".ErrorEmbed());

                        return;
                    }
                }

                string characteristic = paramString.ParseArgs("谱型");
                characteristic = characteristic ?? "Standard";

                GameOptions   gameOptions   = GameOptions.None;
                PlayerOptions playerOptions = PlayerOptions.None;

                //Load up the GameOptions and PlayerOptions
                foreach (GameOptions o in Enum.GetValues(typeof(GameOptions)))
                {
                    if (paramString.ParseArgs(o.ToString()) == "true")
                    {
                        gameOptions = (gameOptions | o);
                    }
                }

                foreach (PlayerOptions o in Enum.GetValues(typeof(PlayerOptions)))
                {
                    if (paramString.ParseArgs(o.ToString()) == "true")
                    {
                        playerOptions = (playerOptions | o);
                    }
                }

                //Sanitize input
                if (songId.StartsWith("https://beatsaver.com/") || songId.StartsWith("https://bsaber.com/"))
                {
                    //Strip off the trailing slash if there is one
                    if (songId.EndsWith("/"))
                    {
                        songId = songId.Substring(0, songId.Length - 1);
                    }

                    //Strip off the beginning of the url to leave the id
                    songId = songId.Substring(songId.LastIndexOf("/") + 1);
                }

                if (songId.Contains("&"))
                {
                    songId = songId.Substring(0, songId.IndexOf("&"));
                }

                var server = ServerService.GetServer();
                if (server == null)
                {
                    await ReplyAsync(embed : "服务器不在线,所以不能添加歌曲".ErrorEmbed());
                }
                else
                {
                    //Get the hash for the song
                    var hash       = BeatSaverDownloader.GetHashFromID(songId);
                    var knownPairs = await HostScraper.ScrapeHosts(server.State.KnownHosts, $"{server.CoreServer.Address}:{server.CoreServer.Port}", 0);

                    var targetPair  = knownPairs.FirstOrDefault(x => x.Value.Events.Any(y => y.EventId.ToString() == eventId));
                    var targetEvent = targetPair.Value.Events.FirstOrDefault(x => x.EventId.ToString() == eventId);
                    var songPool    = targetEvent.QualifierMaps.ToList();

                    if (OstHelper.IsOst(hash))
                    {
                        if (!SongExists(songPool, hash, characteristic, (int)difficulty, (int)gameOptions, (int)playerOptions))
                        {
                            GameplayParameters parameters = new GameplayParameters
                            {
                                Beatmap = new Beatmap
                                {
                                    Name           = OstHelper.GetOstSongNameFromLevelId(hash),
                                    LevelId        = hash,
                                    Characteristic = new Characteristic
                                    {
                                        SerializedName = characteristic
                                    },
                                    Difficulty = difficulty
                                },
                                GameplayModifiers = new GameplayModifiers
                                {
                                    Options = gameOptions
                                },
                                PlayerSettings = new PlayerSpecificSettings
                                {
                                    Options = playerOptions
                                }
                            };

                            songPool.Add(parameters);
                            targetEvent.QualifierMaps = songPool.ToArray();

                            var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent);

                            if (response.Type == Response.ResponseType.Success)
                            {
                                await ReplyAsync(embed : ($"已添加: {parameters.Beatmap.Name} ({difficulty}) ({characteristic})" +
                                                          $"{(gameOptions != GameOptions.None ? $" 附加游戏参数: ({gameOptions})" : "")}" +
                                                          $"{(playerOptions != PlayerOptions.None ? $" 附加玩家参数: ({playerOptions})" : "!")}").SuccessEmbed());
                            }
                            else if (response.Type == Response.ResponseType.Fail)
                            {
                                await ReplyAsync(embed : response.Message.ErrorEmbed());
                            }
                        }
                        else
                        {
                            await ReplyAsync(embed : "歌曲已存在于数据库".ErrorEmbed());
                        }
                    }
                    else
                    {
                        var songInfo = await BeatSaverDownloader.GetSongInfo(songId);

                        string songName = songInfo.Name;

                        if (!songInfo.HasDifficulty(characteristic, difficulty))
                        {
                            BeatmapDifficulty nextBestDifficulty = songInfo.GetClosestDifficultyPreferLower(characteristic, difficulty);

                            if (SongExists(songPool, hash, characteristic, (int)nextBestDifficulty, (int)gameOptions, (int)playerOptions))
                            {
                                await ReplyAsync(embed : $"{songName} 不存在 {difficulty} 难度, 而且 {nextBestDifficulty} 已存在于赛事".ErrorEmbed());
                            }
                            else
                            {
                                GameplayParameters parameters = new GameplayParameters
                                {
                                    Beatmap = new Beatmap
                                    {
                                        Name           = songName,
                                        LevelId        = $"custom_level_{hash.ToUpper()}",
                                        Characteristic = new Characteristic
                                        {
                                            SerializedName = characteristic
                                        },
                                        Difficulty = nextBestDifficulty
                                    },
                                    GameplayModifiers = new GameplayModifiers
                                    {
                                        Options = gameOptions
                                    },
                                    PlayerSettings = new PlayerSpecificSettings
                                    {
                                        Options = playerOptions
                                    }
                                };

                                songPool.Add(parameters);
                                targetEvent.QualifierMaps = songPool.ToArray();

                                var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent);

                                if (response.Type == Response.ResponseType.Success)
                                {
                                    await ReplyAsync(embed : ($"{songName} 不存在 {difficulty} 难度, 使用 {nextBestDifficulty} 难度代替。\n" +
                                                              $"已添加至歌曲列表" +
                                                              $"{(gameOptions != GameOptions.None ? $" 附加游戏参数: ({gameOptions})" : "")}" +
                                                              $"{(playerOptions != PlayerOptions.None ? $" 附加玩家参数: ({playerOptions})" : "!")}").SuccessEmbed());
                                }
                                else if (response.Type == Response.ResponseType.Fail)
                                {
                                    await ReplyAsync(embed : response.Message.ErrorEmbed());
                                }
                            }
                        }
                        else
                        {
                            GameplayParameters parameters = new GameplayParameters
                            {
                                Beatmap = new Beatmap
                                {
                                    Name           = songName,
                                    LevelId        = $"custom_level_{hash.ToUpper()}",
                                    Characteristic = new Characteristic
                                    {
                                        SerializedName = characteristic
                                    },
                                    Difficulty = difficulty
                                },
                                GameplayModifiers = new GameplayModifiers
                                {
                                    Options = gameOptions
                                },
                                PlayerSettings = new PlayerSpecificSettings
                                {
                                    Options = playerOptions
                                }
                            };

                            songPool.Add(parameters);
                            targetEvent.QualifierMaps = songPool.ToArray();

                            var response = await server.SendUpdateQualifierEvent(targetPair.Key, targetEvent);

                            if (response.Type == Response.ResponseType.Success)
                            {
                                await ReplyAsync(embed : ($"{songName} ({difficulty}) ({characteristic}) 已下载并添加至歌曲列表" +
                                                          $"{(gameOptions != GameOptions.None ? $" 附加游戏参数: ({gameOptions})" : "")}" +
                                                          $"{(playerOptions != PlayerOptions.None ? $" 附加玩家参数: ({playerOptions})" : "!")}").SuccessEmbed());
                            }
                            else if (response.Type == Response.ResponseType.Fail)
                            {
                                await ReplyAsync(embed : response.Message.ErrorEmbed());
                            }
                        }
                    }
                }
            }
            else
            {
                await ReplyAsync(embed : "你没有足够的权限使用该命令".ErrorEmbed());
            }
        }
 private void SongSelection_SongSelected(GameplayParameters parameters) => SongSelection_SongSelected(parameters.Beatmap.LevelId);