Beispiel #1
0
        public static void Main(string[] args)
        {
            /*
             * 改造步骤
             *
             * 1. 复制ProcessorCommand.cs,以及Simulate目录下的文件到新项目中,并删除无用文件
             *
             * 2. 在依赖项引入项目PerformanceCalculator, 并将Simulate目录下类的命名空间,更改为当前项目下的命名空间
             *
             * 3. 给SimulateCommand及其子类的字段添加set访问属性
             *
             * 4. 将ProcessorCommand类中的Console字段删除
             *
             * 5. 添加一个字段到SimulateCommand类中 public Dictionary<string, string> Result = new Dictionary<string, string>();
             *
             * 6. 修改SimulateCommand里边的WriteAttribute方法,将每次调用的键值对赋值给Result对象
             *
             * 7. 修改OsuSimulateCommand和TaikoSimulateCommand里边的WritePlayInfo方法,将Accuracy改为Acc防止字段冲突
             *
             * 8. 添加ToJson方法到SimulateCommand类中 public string ToJson() => JsonConvert.SerializeObject(Result);
             *
             * 收工
             */

            SimulateCommand command = new OsuSimulateCommand();

            command.Beatmap  = "c:\\osu\\osu.osu";
            command.Accuracy = 75.3;
            command.Combo    = 2000;
            command.Misses   = 20;
            command.Execute();
            Console.WriteLine(command.ToJson());
        }
Beispiel #2
0
        public static string GetPP(
            string osuFilePath,
            int bid,
            int mode,
            string mods,
            double acc,
            int miss,
            int combo,
            int good,
            int meh,
            int score,
            double percentCombo)
        {
            //初始化计算对象数据
            SimulateCommand command = null;

            switch (mode)
            {
            case 0:
                command = new OsuSimulateCommand();
                break;

            case 1:
                command = new TaikoSimulateCommand();
                break;

            case 3:
                command = new ManiaSimulateCommand();
                break;
            }

            //校验传入参数
            if (command == null ||
                bid <= 0 ||
                miss < 0 ||
                combo < 0 ||
                good < 0 ||
                meh < 0 ||
                (acc < 0 && acc > 100) ||
                (score < 0 && score > 1000000 && mode == 3) ||
                (score < 0 && mode != 3) ||
                (percentCombo < 0 && percentCombo > 100))
            {
                return("[]");
            }



            try
            {
                var path = osuFilePath + Path.DirectorySeparatorChar + bid + ".osu";

                FileInfo info = new FileInfo(path);
                if (!info.Exists)
                {
                    string content = client.DownloadString("http://osu.ppy.sh/osu/" + bid);
                    if (!string.IsNullOrWhiteSpace(content))
                    {
                        File.WriteAllText(path, content);
                    }
                }

                //设置osu文件路径
                command.Beatmap = path;


                //设置acc
                command.Accuracy = (acc > 0) ? acc : 100;


                //设置miss
                if (miss > 0)
                {
                    command.Misses = miss;
                }


                //设置combo
                if (percentCombo > 0)
                {
                    command.PercentCombo = percentCombo;
                }
                else if (combo > 0)
                {
                    command.Combo = combo;
                }

                //设置100数量
                if (good > 0)
                {
                    command.Goods = good;
                }

                //设置50数量
                if (meh > 0)
                {
                    command.Mehs = meh;
                }

                //设置游玩模式
                command.Mods = GetMods(mods);

                //Mania的分数处理
                if (command is ManiaSimulateCommand)
                {
                    if (score > 0)
                    {
                        command.Score = score;
                    }
                    else
                    {
                        command.Score = 1000000;
                    }

                    foreach (var item in command.Mods)
                    {
                        if (item.Equals("EZ") || item.Equals("HT") || item.Equals("NF"))
                        {
                            command.Score = (int)(command.Score * 0.5);
                        }
                    }
                }

                //开始计算
                command.Execute();
            }
            catch
            {
            }


            return(command.ToJson());
        }