-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScore.cs
More file actions
238 lines (208 loc) · 7.74 KB
/
Score.cs
File metadata and controls
238 lines (208 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using OsuVideoUploader.API;
using System;
namespace OsuVideoUploader
{
public class Score
{
[JsonProperty(@"score")]
public long TotalScore { get; set; }
[JsonProperty(@"max_combo")]
public int MaxCombo { get; set; }
[JsonProperty(@"perfect")]
public bool Perfect { get; set; }
[JsonProperty(@"created_at")]
public DateTime Date { get; set; }
internal float Accuracy
{
get
{
switch (PlayMode)
{
default:
case PlayModes.Osu:
return TotalHits > 0 ? (float)(Count50 * 50 + Count100 * 100 + Count300 * 300) / (TotalHits * 300) : 1;
case PlayModes.Taiko:
return TotalHits > 0 ? (float)(Count100 * 150 + Count300 * 300) / (TotalHits * 300) : 0;
case PlayModes.CatchTheBeat:
if (TotalHits == 0) return 1;
return (float)TotalSuccessfulHits / TotalHits;
case PlayModes.OsuMania:
if (TotalHits == 0)
return 1;
return (float)(Count50 * 50 + Count100 * 100 + CountKatu * 200 + (Count300 + CountGeki) * 300) / (TotalHits * 300);
}
}
}
internal int TotalHits
{
get
{
switch (PlayMode)
{
default:
return Count50 + Count100 + Count300 + CountMiss;
case PlayModes.CatchTheBeat:
return Count50 + Count100 + Count300 + CountMiss + CountKatu;
case PlayModes.OsuMania:
return Count50 + Count100 + Count300 + CountMiss + CountGeki + CountKatu;
}
}
}
internal int TotalSuccessfulHits
{
get
{
switch (PlayMode)
{
default:
return Count50 + Count100 + Count300;
case PlayModes.OsuMania:
return Count50 + Count100 + Count300 + CountGeki + CountKatu;
}
}
}
internal virtual ScoreRank Rank
{
get
{
float acc = Accuracy;
switch (PlayMode)
{
default:
case PlayModes.Osu:
float ratio300 = (float)Count300 / TotalHits;
float ratio50 = (float)Count50 / TotalHits;
if (ratio300 == 1)
return ModUtils.CheckActive(EnabledMods, Mods.Hidden) ||
ModUtils.CheckActive(EnabledMods, Mods.Flashlight)
? ScoreRank.XH
: ScoreRank.X;
if (ratio300 > 0.9 && ratio50 <= 0.01 && CountMiss == 0)
return ModUtils.CheckActive(EnabledMods, Mods.Hidden) ||
ModUtils.CheckActive(EnabledMods, Mods.Flashlight)
? ScoreRank.SH
: ScoreRank.S;
if ((ratio300 > 0.8 && CountMiss == 0) || (ratio300 > 0.9))
return ScoreRank.A;
if ((ratio300 > 0.7 && CountMiss == 0) || (ratio300 > 0.8))
return ScoreRank.B;
if (ratio300 > 0.6)
return ScoreRank.C;
return ScoreRank.D;
case PlayModes.CatchTheBeat:
if (acc == 1)
return ModUtils.CheckActive(EnabledMods, Mods.Hidden) ||
ModUtils.CheckActive(EnabledMods, Mods.Flashlight)
? ScoreRank.XH
: ScoreRank.X;
if (acc > 0.98)
return ModUtils.CheckActive(EnabledMods, Mods.Hidden) ||
ModUtils.CheckActive(EnabledMods, Mods.Flashlight)
? ScoreRank.SH
: ScoreRank.S;
if (acc > 0.94)
return ScoreRank.A;
if (acc > 0.9)
return ScoreRank.B;
return acc > 0.85 ? ScoreRank.C : ScoreRank.D;
case PlayModes.OsuMania:
if (acc == 1)
return ModUtils.CheckActive(EnabledMods, Mods.Hidden | Mods.Flashlight | Mods.FadeIn) ? ScoreRank.XH : ScoreRank.X;
if (acc > 0.95)
return ModUtils.CheckActive(EnabledMods, Mods.Hidden | Mods.Flashlight | Mods.FadeIn) ? ScoreRank.SH : ScoreRank.S;
if (acc > 0.9)
return ScoreRank.A;
if (acc > 0.8)
return ScoreRank.B;
if (acc > 0.7)
return ScoreRank.C;
return ScoreRank.D;
}
}
}
public Mods EnabledMods;
public APIBeatmap Beatmap;
public string PlayerName;
public ushort Count300;
public ushort Count100;
public ushort Count50;
public ushort CountGeki;
public ushort CountKatu;
public ushort CountMiss;
public string BeatmapChecksum;
public PlayModes PlayMode;
public override string ToString()
{
string str = $"{Beatmap}";
if (EnabledMods != Mods.None)
{
str += $" {ModUtils.Format(EnabledMods)}";
}
if (Accuracy < 1)
{
str += $" {Accuracy:P2}";
}
return str;
}
public string ToStringDetails()
{
string str = ToString();
if (Perfect)
{
str += Rank >= ScoreRank.X ? " SS" : " FC";
}
else if (Count100 == 1)
{
str += " 1x100";
}
else if (CountMiss == 1)
{
str += " 1miss";
}
return str;
}
public static Score ReadFromReplay(string file)
{
using var sr = new SerializationReader(File.OpenRead(file));
var score = new Score();
score.PlayMode = (PlayModes)sr.ReadByte();
sr.ReadInt32(); // Version
score.BeatmapChecksum = sr.ReadString();
score.PlayerName = sr.ReadString();
sr.ReadString(); // localScoreChecksum
score.Count300 = sr.ReadUInt16();
score.Count100 = sr.ReadUInt16();
score.Count50 = sr.ReadUInt16();
score.CountGeki = sr.ReadUInt16();
score.CountKatu = sr.ReadUInt16();
score.CountMiss = sr.ReadUInt16();
score.TotalScore = sr.ReadInt32();
score.MaxCombo = sr.ReadUInt16();
score.Perfect = sr.ReadBoolean();
score.EnabledMods = (Mods)sr.ReadInt32();
sr.ReadString(); // HpGraphString
score.Date = sr.ReadDateTime();
return score;
}
}
public enum ScoreRank
{
D,
C,
B,
A,
S,
SH,
X,
XH,
}
public enum PlayModes
{
Osu = 0,
Taiko = 1,
CatchTheBeat = 2,
OsuMania = 3
}
}