forked from codecat/OpenSMO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFunc.cs
78 lines (69 loc) · 2.64 KB
/
Func.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenSMO {
public static class Func {
public static string RepeatChar(char chr, int count) {
string ret = "";
for (int i = 0; i < count; i++)
ret += chr;
return ret;
}
public static string ChatColor(string colorCode) {
if (colorCode.Length == 3) colorCode = RepeatChar(colorCode[0], 2) + RepeatChar(colorCode[1], 2) + RepeatChar(colorCode[2], 2);
return "|c0" + colorCode;
}
public static int GetStepWeight(NSNotes note) {
switch (note) {
case NSNotes.Mine: return -8;
case NSNotes.Miss: return -8;
case NSNotes.Barely: return -4;
case NSNotes.Great: return 1;
case NSNotes.Perfect:
case NSNotes.Flawless: return 2;
case NSNotes.Held: return 6;
default: return 0;
}
}
public static float GetPercTier(int i) {
switch (i) {
case 1: return 1.00f;
case 2: return 0.99f;
case 3: return 0.97f;
case 4: return 0.93f;
case 5: return 0.80f;
case 6: return 0.65f;
case 7: return 0.45f;
case 8: return -99999.00f;
default: return 0f;
}
}
public static NSGrades GetGrade(int[] notes) {
int gradePoints = GetGradePoints(notes);
int gradePointsMax = GetMaxGradePoints(notes);
float perc = gradePoints / (float)gradePointsMax;
return GetGrade(gradePoints / (float)gradePointsMax);
}
private static NSGrades GetGrade(float perc) {
for (int i = 1; i < (int)NSGrades.NUM_NS_GRADES; i++) {
if (perc >= GetPercTier(i))
return (NSGrades)(i - 1);
}
return NSGrades.F;
}
public static int GetGradePoints(int[] notes) {
int ret = 0;
for (int i = 0; i < (int)NSNotes.NUM_NS_NOTES; i++)
ret += notes[i] * GetStepWeight((NSNotes)i);
return ret;
}
public static int GetMaxGradePoints(int[] notes) {
int ret = 0;
int flawlessWeight = GetStepWeight(NSNotes.Flawless);
for (int i = 0; i < (int)NSNotes.NUM_NS_NOTES; i++)
ret += notes[i] * flawlessWeight;
return ret + (notes[(int)NSNotes.Held] + notes[(int)NSNotes.NG]) * GetStepWeight(NSNotes.Held);
}
}
}