forked from akanyan/mu3-mods
feat: reachable rating
This commit is contained in:
105
Extras/MoreProfileOptions/MU3.Mod/CustomRating.cs
Normal file
105
Extras/MoreProfileOptions/MU3.Mod/CustomRating.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using MU3.Data;
|
||||
using MU3.DataStudio;
|
||||
using MU3.User;
|
||||
using MU3.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MU3.Mod;
|
||||
|
||||
public static class CustomRating {
|
||||
// Adapted from MU3.User.UserRating.calcBest()
|
||||
private static RatingList calcNaive() {
|
||||
RatingList ratingList = [];
|
||||
|
||||
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 GetNaive() {
|
||||
int res = 0;
|
||||
foreach(Rating best in calcNaive().Take(45)) {
|
||||
res += best.rate100;
|
||||
}
|
||||
return res / 45;
|
||||
}
|
||||
|
||||
public static int GetReachable() {
|
||||
FieldInfo piOld = typeof(UserRating).GetField("_bestOldList", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
FieldInfo piNew = typeof(UserRating).GetField("_bestNewList", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
var ur = Singleton<UserManager>.instance.userRating;
|
||||
|
||||
int res = 0;
|
||||
int top = 0;
|
||||
foreach(Rating best in ((RatingList)piOld.GetValue(ur))) {
|
||||
res += best.rate100;
|
||||
if(best.musicID < 7000) {
|
||||
top = Math.Max(top, best.rate100);
|
||||
}
|
||||
}
|
||||
foreach(Rating best in ((RatingList)piNew.GetValue(ur))) {
|
||||
res += best.rate100;
|
||||
if(best.musicID < 7000) {
|
||||
top = Math.Max(top, best.rate100);
|
||||
}
|
||||
}
|
||||
|
||||
res += top * 10;
|
||||
|
||||
return res / 55;
|
||||
}
|
||||
|
||||
public static bool IsNaiveEnabled() {
|
||||
return Singleton<UserManager>.instance.userOption.customSet.Rating == (UserOption.eRating)patch_UserOption.eRating.Naive;
|
||||
}
|
||||
public static bool IsReachableEnabled() {
|
||||
return Singleton<UserManager>.instance.userOption.customSet.Rating == (UserOption.eRating)patch_UserOption.eRating.Reachable;
|
||||
}
|
||||
public static bool IsEnabled() {
|
||||
return IsNaiveEnabled() || IsReachableEnabled();
|
||||
}
|
||||
|
||||
public static int Get() {
|
||||
if(IsNaiveEnabled()) {
|
||||
return GetNaive();
|
||||
} else if(IsReachableEnabled()) {
|
||||
return GetReachable();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte GetSuffix() {
|
||||
if(IsNaiveEnabled()) {
|
||||
return MU3CounterBase.FigurePlus;
|
||||
} else {
|
||||
return MU3CounterBase.FigureMinus;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user