mu3-mods/NaiveRating/NaiveRating.cs

55 lines
1.7 KiB
C#

using MU3.Data;
using MU3.DataStudio;
using MU3.User;
using MU3.Util;
using System.Collections.Generic;
using System.Linq;
public static class NaiveRating {
public static int PrevRating { get; private set; }
// Adapted from MU3.User.UserRating.calcBest()
private static RatingList calcSane() {
RatingList ratingList = new();
var usMgr = Singleton<UserManager>.instance;
var musicDict = usMgr.userMusic;
foreach(KeyValuePair<int, UserMusic> item in musicDict) {
var musicData = SingletonStateMachine<DataManager, DataManager.EState>
.instance.getMusicData(item.Key);
if(musicData == null || item.Key == 1 || musicData.isBonusTrack) {
continue;
}
for(int i = 0; i < 5; i++) {
var fumenDifficulty = (FumenDifficulty)i;
var userFumen = usMgr.getUserFumen(item.Key, fumenDifficulty, create: false);
if(userFumen == null) {
continue;
}
Rating rating = new(musicData.id, fumenDifficulty, userFumen.TechScoreMax);
if(rating.level100 == 0) {
continue;
}
ratingList.Add(rating);
}
}
ratingList.Sort();
return ratingList;
}
public static int Get() {
int res = 0;
foreach(Rating best in calcSane().Take(45)) {
res += best.rate100;
}
return res / 45;
}
public static bool IsEnabled() {
return Singleton<UserManager>.instance.userOption.customSet.Rating == (UserOption.eRating)patch_UserOption.patch_eRating.Naive;
}
public static void SavePrev() {
PrevRating = Get();
}
}