@rian8337/osu-rebalance-difficulty-calculator 4.0.0-beta.52 → 4.0.0-beta.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +790 -952
  2. package/package.json +3 -3
  3. package/typings/index.d.ts +258 -345
package/dist/index.js CHANGED
@@ -3,137 +3,121 @@
3
3
  var osuBase = require('@rian8337/osu-base');
4
4
 
5
5
  /**
6
- * The base of a difficulty calculator.
6
+ * Holds data that can be used to calculate performance points.
7
7
  */
8
- class DifficultyCalculator {
9
- /**
10
- * The difficulty objects of the beatmap.
11
- */
12
- get objects() {
13
- return this._objects;
14
- }
15
- /**
16
- * The total star rating of the beatmap.
17
- */
18
- get total() {
19
- return this.attributes.starRating;
20
- }
21
- /**
22
- * Constructs a new instance of the calculator.
23
- *
24
- * @param beatmap The beatmap to calculate.
25
- */
26
- constructor(beatmap) {
27
- /**
28
- * The difficulty objects of the beatmap.
29
- */
30
- this._objects = [];
31
- /**
32
- * The modifications applied.
33
- */
8
+ class DifficultyAttributes {
9
+ constructor(cacheableAttributes) {
34
10
  this.mods = [];
35
- /**
36
- * The strain peaks of various calculated difficulties.
37
- */
38
- this.strainPeaks = {
39
- aimWithSliders: [],
40
- aimWithoutSliders: [],
41
- speed: [],
42
- flashlight: [],
43
- };
44
- this.beatmap = beatmap;
11
+ this.starRating = 0;
12
+ this.maxCombo = 0;
13
+ this.aimDifficulty = 0;
14
+ this.flashlightDifficulty = 0;
15
+ this.speedNoteCount = 0;
16
+ this.sliderFactor = 1;
17
+ this.clockRate = 1;
18
+ this.overallDifficulty = 0;
19
+ this.hitCircleCount = 0;
20
+ this.sliderCount = 0;
21
+ this.spinnerCount = 0;
22
+ this.aimDifficultSliderCount = 0;
23
+ this.aimDifficultStrainCount = 0;
24
+ if (!cacheableAttributes) {
25
+ return;
26
+ }
27
+ this.mods = osuBase.ModUtil.deserializeMods(cacheableAttributes.mods);
28
+ this.starRating = cacheableAttributes.starRating;
29
+ this.maxCombo = cacheableAttributes.maxCombo;
30
+ this.aimDifficulty = cacheableAttributes.aimDifficulty;
31
+ this.flashlightDifficulty = cacheableAttributes.flashlightDifficulty;
32
+ this.speedNoteCount = cacheableAttributes.speedNoteCount;
33
+ this.sliderFactor = cacheableAttributes.sliderFactor;
34
+ this.clockRate = cacheableAttributes.clockRate;
35
+ this.overallDifficulty = cacheableAttributes.overallDifficulty;
36
+ this.hitCircleCount = cacheableAttributes.hitCircleCount;
37
+ this.sliderCount = cacheableAttributes.sliderCount;
38
+ this.spinnerCount = cacheableAttributes.spinnerCount;
39
+ this.aimDifficultSliderCount =
40
+ cacheableAttributes.aimDifficultSliderCount;
41
+ this.aimDifficultStrainCount =
42
+ cacheableAttributes.aimDifficultStrainCount;
45
43
  }
46
44
  /**
47
- * Calculates the star rating of the specified beatmap.
45
+ * Converts this `DifficultyAttributes` instance to an attribute structure that can be cached.
48
46
  *
49
- * The beatmap is analyzed in chunks of `sectionLength` duration.
50
- * For each chunk the highest hitobject strains are added to
51
- * a list which is then collapsed into a weighted sum, much
52
- * like scores are weighted on a user's profile.
53
- *
54
- * For subsequent chunks, the initial max strain is calculated
55
- * by decaying the previous hitobject's strain until the
56
- * beginning of the new chunk.
57
- *
58
- * @param options Options for the difficulty calculation.
59
- * @returns The current instance.
47
+ * @returns The cacheable attributes.
60
48
  */
61
- calculate(options) {
62
- var _a;
63
- this.mods = (_a = options === null || options === void 0 ? void 0 : options.mods) !== null && _a !== void 0 ? _a : [];
64
- const playableBeatmap = this.beatmap.createPlayableBeatmap({
65
- mode: this.mode,
66
- mods: this.mods,
67
- customSpeedMultiplier: options === null || options === void 0 ? void 0 : options.customSpeedMultiplier,
68
- });
69
- const clockRate = this.calculateClockRate(options);
70
- this.populateDifficultyAttributes(playableBeatmap, clockRate);
71
- this._objects = this.generateDifficultyHitObjects(playableBeatmap, clockRate);
72
- this.calculateAll();
73
- return this;
49
+ toCacheableAttributes() {
50
+ return Object.assign(Object.assign({}, this), { mods: osuBase.ModUtil.serializeMods(this.mods) });
74
51
  }
75
52
  /**
76
- * Calculates the skills provided.
77
- *
78
- * @param skills The skills to calculate.
53
+ * Returns a string representation of the difficulty attributes.
79
54
  */
80
- calculateSkills(...skills) {
81
- // The first object doesn't generate a strain, so we begin calculating from the second object.
82
- for (const object of this.objects.slice(1)) {
55
+ toString() {
56
+ return `${this.starRating.toFixed(2)} stars`;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * The base of a difficulty calculator.
62
+ */
63
+ class DifficultyCalculator {
64
+ constructor() {
65
+ /**
66
+ * `Mod`s that adjust the difficulty of a beatmap.
67
+ */
68
+ this.difficultyAdjustmentMods = new Set([
69
+ osuBase.ModDoubleTime,
70
+ osuBase.ModNightCore,
71
+ osuBase.ModDifficultyAdjust,
72
+ osuBase.ModCustomSpeed,
73
+ osuBase.ModHalfTime,
74
+ osuBase.ModEasy,
75
+ osuBase.ModHardRock,
76
+ osuBase.ModFlashlight,
77
+ osuBase.ModHidden,
78
+ osuBase.ModRelax,
79
+ osuBase.ModAutopilot,
80
+ ]);
81
+ }
82
+ calculate(beatmap, mods = []) {
83
+ const playableBeatmap = beatmap instanceof osuBase.PlayableBeatmap
84
+ ? beatmap
85
+ : this.createPlayableBeatmap(beatmap, mods);
86
+ const skills = this.createSkills(playableBeatmap);
87
+ const objects = this.createDifficultyHitObjects(playableBeatmap);
88
+ for (const object of objects) {
83
89
  for (const skill of skills) {
84
90
  skill.process(object);
85
91
  }
86
92
  }
93
+ return this.createDifficultyAttributes(playableBeatmap, skills, objects);
87
94
  }
88
- /**
89
- * Obtains the clock rate of the beatmap.
90
- *
91
- * @param options The options to obtain the clock rate with.
92
- * @returns The clock rate of the beatmap.
93
- */
94
- calculateClockRate(options) {
95
- var _a, _b;
96
- return (osuBase.ModUtil.calculateRateWithMods((_a = options === null || options === void 0 ? void 0 : options.mods) !== null && _a !== void 0 ? _a : []) *
97
- ((_b = options === null || options === void 0 ? void 0 : options.customSpeedMultiplier) !== null && _b !== void 0 ? _b : 1));
98
- }
99
- /**
100
- * Populates the stored difficulty attributes with necessary data.
101
- *
102
- * @param beatmap The beatmap to populate the attributes with.
103
- * @param clockRate The clock rate of the beatmap.
104
- */
105
- populateDifficultyAttributes(beatmap, clockRate) {
106
- this.attributes.hitCircleCount = this.beatmap.hitObjects.circles;
107
- this.attributes.maxCombo = this.beatmap.maxCombo;
108
- this.attributes.mods = this.mods.slice();
109
- this.attributes.sliderCount = this.beatmap.hitObjects.sliders;
110
- this.attributes.spinnerCount = this.beatmap.hitObjects.spinners;
111
- this.attributes.clockRate = clockRate;
112
- let greatWindow;
113
- switch (this.mode) {
114
- case osuBase.Modes.droid:
115
- if (this.mods.some((m) => m instanceof osuBase.ModPrecise)) {
116
- greatWindow = new osuBase.PreciseDroidHitWindow(beatmap.difficulty.od).greatWindow;
117
- }
118
- else {
119
- greatWindow = new osuBase.DroidHitWindow(beatmap.difficulty.od)
120
- .greatWindow;
121
- }
122
- break;
123
- case osuBase.Modes.osu:
124
- greatWindow = new osuBase.OsuHitWindow(beatmap.difficulty.od)
125
- .greatWindow;
126
- break;
95
+ calculateStrainPeaks(beatmap, mods = []) {
96
+ const playableBeatmap = beatmap instanceof osuBase.PlayableBeatmap
97
+ ? beatmap
98
+ : this.createPlayableBeatmap(beatmap, mods);
99
+ const skills = this.createStrainPeakSkills(playableBeatmap);
100
+ const objects = this.createDifficultyHitObjects(playableBeatmap);
101
+ for (const object of objects) {
102
+ for (const skill of skills) {
103
+ skill.process(object);
104
+ }
127
105
  }
128
- this.attributes.overallDifficulty = osuBase.OsuHitWindow.greatWindowToOD(greatWindow / clockRate);
106
+ return {
107
+ aimWithSliders: skills[0].strainPeaks,
108
+ aimWithoutSliders: skills[1].strainPeaks,
109
+ speed: skills[2].strainPeaks,
110
+ flashlight: skills[3].strainPeaks,
111
+ };
129
112
  }
130
113
  /**
131
- * Calculates the star rating value of a difficulty.
114
+ * Calculates the base rating of a `Skill`.
132
115
  *
133
- * @param difficulty The difficulty to calculate.
116
+ * @param skill The `Skill` to calculate the rating of.
117
+ * @returns The rating of the `Skill`.
134
118
  */
135
- starValue(difficulty) {
136
- return Math.sqrt(difficulty) * this.difficultyMultiplier;
119
+ calculateRating(skill) {
120
+ return Math.sqrt(skill.difficultyValue()) * this.difficultyMultiplier;
137
121
  }
138
122
  /**
139
123
  * Calculates the base performance value of a difficulty rating.
@@ -165,7 +149,7 @@ class DifficultyHitObject {
165
149
  * @param difficultyHitObjects All difficulty hitobjects in the processed beatmap.
166
150
  * @param clockRate The clock rate of the beatmap.
167
151
  */
168
- constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate) {
152
+ constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate, index) {
169
153
  var _a, _b, _c, _d;
170
154
  /**
171
155
  * The aim strain generated by the hitobject if sliders are considered.
@@ -222,6 +206,7 @@ class DifficultyHitObject {
222
206
  this.lastObject = lastObject;
223
207
  this.lastLastObject = lastLastObject;
224
208
  this.hitObjects = difficultyHitObjects;
209
+ this.index = index;
225
210
  if (object instanceof osuBase.Slider) {
226
211
  this.fullGreatWindow =
227
212
  ((_b = (_a = object.head.hitWindow) === null || _a === void 0 ? void 0 : _a.greatWindow) !== null && _b !== void 0 ? _b : 1200) * 2;
@@ -230,7 +215,6 @@ class DifficultyHitObject {
230
215
  this.fullGreatWindow = ((_d = (_c = object.hitWindow) === null || _c === void 0 ? void 0 : _c.greatWindow) !== null && _d !== void 0 ? _d : 1200) * 2;
231
216
  }
232
217
  this.fullGreatWindow /= clockRate;
233
- this.index = difficultyHitObjects.length - 1;
234
218
  // Capped to 25ms to prevent difficulty calculation breaking from simultaneous objects.
235
219
  this.startTime = object.startTime / clockRate;
236
220
  this.endTime = object.endTime / clockRate;
@@ -267,7 +251,7 @@ class DifficultyHitObject {
267
251
  */
268
252
  previous(backwardsIndex) {
269
253
  var _a;
270
- return (_a = this.hitObjects[this.index - backwardsIndex]) !== null && _a !== void 0 ? _a : null;
254
+ return ((_a = this.hitObjects[this.index - backwardsIndex - 1]) !== null && _a !== void 0 ? _a : null);
271
255
  }
272
256
  /**
273
257
  * Gets the difficulty hitobject at a specific index with respect to the current
@@ -281,7 +265,7 @@ class DifficultyHitObject {
281
265
  */
282
266
  next(forwardsIndex) {
283
267
  var _a;
284
- return ((_a = this.hitObjects[this.index + forwardsIndex + 2]) !== null && _a !== void 0 ? _a : null);
268
+ return ((_a = this.hitObjects[this.index + forwardsIndex + 1]) !== null && _a !== void 0 ? _a : null);
285
269
  }
286
270
  /**
287
271
  * Calculates the opacity of the hitobject at a given time.
@@ -532,8 +516,8 @@ class DroidDifficultyHitObject extends DifficultyHitObject {
532
516
  * @param difficultyHitObjects All difficulty hitobjects in the processed beatmap.
533
517
  * @param clockRate The clock rate of the beatmap.
534
518
  */
535
- constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate) {
536
- super(object, lastObject, lastLastObject, difficultyHitObjects, clockRate);
519
+ constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate, index) {
520
+ super(object, lastObject, lastLastObject, difficultyHitObjects, clockRate, index);
537
521
  /**
538
522
  * The tap strain generated by the hitobject.
539
523
  */
@@ -590,6 +574,14 @@ class DroidDifficultyHitObject extends DifficultyHitObject {
590
574
  }
591
575
  return super.opacityAt(time, mods);
592
576
  }
577
+ previous(backwardsIndex) {
578
+ var _a;
579
+ return (_a = this.hitObjects[this.index - backwardsIndex]) !== null && _a !== void 0 ? _a : null;
580
+ }
581
+ next(forwardsIndex) {
582
+ var _a;
583
+ return ((_a = this.hitObjects[this.index + forwardsIndex + 2]) !== null && _a !== void 0 ? _a : null);
584
+ }
593
585
  /**
594
586
  * Determines whether this hitobject is considered overlapping with the hitobject before it.
595
587
  *
@@ -995,6 +987,9 @@ class StrainSkill extends Skill {
995
987
  */
996
988
  class DroidSkill extends StrainSkill {
997
989
  process(current) {
990
+ if (current.index < 0) {
991
+ return;
992
+ }
998
993
  super.process(current);
999
994
  this._objectStrains.push(this.getObjectStrain(current));
1000
995
  }
@@ -1083,132 +1078,41 @@ class DroidAim extends DroidSkill {
1083
1078
  }
1084
1079
 
1085
1080
  /**
1086
- * An evaluator for calculating osu!droid tap skill.
1087
- */
1088
- class DroidTapEvaluator {
1089
- /**
1090
- * Evaluates the difficulty of tapping the current object, based on:
1091
- *
1092
- * - time between pressing the previous and current object,
1093
- * - distance between those objects,
1094
- * - how easily they can be cheesed,
1095
- * - and the strain time cap.
1096
- *
1097
- * @param current The current object.
1098
- * @param considerCheesability Whether to consider cheesability.
1099
- * @param strainTimeCap The strain time to cap the object's strain time to.
1100
- */
1101
- static evaluateDifficultyOf(current, considerCheesability, strainTimeCap) {
1102
- if (current.object instanceof osuBase.Spinner ||
1103
- // Exclude overlapping objects that can be tapped at once.
1104
- current.isOverlapping(false)) {
1105
- return 0;
1106
- }
1107
- const doubletapness = considerCheesability
1108
- ? 1 - current.doubletapness
1109
- : 1;
1110
- const strainTime = strainTimeCap !== undefined
1111
- ? // We cap the strain time to 50 here as the chance of vibro is higher in any BPM higher than 300.
1112
- Math.max(50, strainTimeCap, current.strainTime)
1113
- : current.strainTime;
1114
- let speedBonus = 1;
1115
- if (strainTime < this.minSpeedBonus) {
1116
- speedBonus +=
1117
- 0.75 *
1118
- Math.pow(osuBase.ErrorFunction.erf((this.minSpeedBonus - strainTime) / 40), 2);
1119
- }
1120
- return (speedBonus * Math.pow(doubletapness, 1.5) * 1000) / strainTime;
1121
- }
1122
- }
1123
- // ~200 1/4 BPM streams
1124
- DroidTapEvaluator.minSpeedBonus = 75;
1125
-
1126
- /**
1127
- * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
1081
+ * Holds data that can be used to calculate osu!droid performance points.
1128
1082
  */
1129
- class DroidTap extends DroidSkill {
1130
- /**
1131
- * The delta time of hitobjects.
1132
- */
1133
- get objectDeltaTimes() {
1134
- return this._objectDeltaTimes;
1135
- }
1136
- constructor(mods, considerCheesability, strainTimeCap) {
1137
- super(mods);
1138
- this.reducedSectionCount = 10;
1139
- this.reducedSectionBaseline = 0.75;
1140
- this.strainDecayBase = 0.3;
1141
- this.starsPerDouble = 1.1;
1142
- this.currentTapStrain = 0;
1143
- this.currentRhythmMultiplier = 0;
1144
- this.skillMultiplier = 1.375;
1145
- this._objectDeltaTimes = [];
1146
- this.considerCheesability = considerCheesability;
1147
- this.strainTimeCap = strainTimeCap;
1148
- }
1149
- /**
1150
- * The amount of notes that are relevant to the difficulty.
1151
- */
1152
- relevantNoteCount() {
1153
- if (this._objectStrains.length === 0) {
1154
- return 0;
1155
- }
1156
- const maxStrain = osuBase.MathUtils.max(this._objectStrains);
1157
- if (maxStrain === 0) {
1158
- return 0;
1159
- }
1160
- return this._objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
1161
- }
1162
- /**
1163
- * The delta time relevant to the difficulty.
1164
- */
1165
- relevantDeltaTime() {
1166
- if (this._objectStrains.length === 0) {
1167
- return 0;
1168
- }
1169
- const maxStrain = osuBase.MathUtils.max(this._objectStrains);
1170
- if (maxStrain === 0) {
1171
- return 0;
1172
- }
1173
- return (this._objectDeltaTimes.reduce((total, next, index) => total +
1174
- (next * 1) /
1175
- (1 +
1176
- Math.exp(-((this._objectStrains[index] / maxStrain) *
1177
- 25 -
1178
- 20))), 0) /
1179
- this._objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 25 - 20))), 0));
1180
- }
1181
- strainValueAt(current) {
1182
- this.currentTapStrain *= this.strainDecay(current.strainTime);
1183
- this.currentTapStrain +=
1184
- DroidTapEvaluator.evaluateDifficultyOf(current, this.considerCheesability, this.strainTimeCap) * this.skillMultiplier;
1185
- this.currentRhythmMultiplier = current.rhythmMultiplier;
1186
- this._objectDeltaTimes.push(current.deltaTime);
1187
- return this.currentTapStrain * current.rhythmMultiplier;
1188
- }
1189
- calculateInitialStrain(time, current) {
1190
- var _a, _b;
1191
- return (this.currentTapStrain *
1192
- this.currentRhythmMultiplier *
1193
- this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
1194
- }
1195
- getObjectStrain() {
1196
- return this.currentTapStrain * this.currentRhythmMultiplier;
1197
- }
1198
- /**
1199
- * @param current The hitobject to save to.
1200
- */
1201
- saveToHitObject(current) {
1202
- if (this.strainTimeCap !== undefined) {
1083
+ class DroidDifficultyAttributes extends DifficultyAttributes {
1084
+ constructor(cacheableAttributes) {
1085
+ super(cacheableAttributes);
1086
+ this.tapDifficulty = 0;
1087
+ this.rhythmDifficulty = 0;
1088
+ this.visualDifficulty = 0;
1089
+ this.tapDifficultStrainCount = 0;
1090
+ this.flashlightDifficultStrainCount = 0;
1091
+ this.visualDifficultStrainCount = 0;
1092
+ this.averageSpeedDeltaTime = 0;
1093
+ this.vibroFactor = 1;
1094
+ if (!cacheableAttributes) {
1203
1095
  return;
1204
1096
  }
1205
- const strain = this.currentTapStrain * this.currentRhythmMultiplier;
1206
- if (this.considerCheesability) {
1207
- current.tapStrain = strain;
1208
- }
1209
- else {
1210
- current.originalTapStrain = strain;
1211
- }
1097
+ this.tapDifficulty = cacheableAttributes.tapDifficulty;
1098
+ this.rhythmDifficulty = cacheableAttributes.rhythmDifficulty;
1099
+ this.visualDifficulty = cacheableAttributes.visualDifficulty;
1100
+ this.tapDifficultStrainCount =
1101
+ cacheableAttributes.tapDifficultStrainCount;
1102
+ this.flashlightDifficultStrainCount =
1103
+ cacheableAttributes.flashlightDifficultStrainCount;
1104
+ this.visualDifficultStrainCount =
1105
+ cacheableAttributes.visualDifficultStrainCount;
1106
+ this.averageSpeedDeltaTime = cacheableAttributes.averageSpeedDeltaTime;
1107
+ this.vibroFactor = cacheableAttributes.vibroFactor;
1108
+ }
1109
+ toString() {
1110
+ return (super.toString() +
1111
+ ` (${this.aimDifficulty.toFixed(2)} aim, ` +
1112
+ `${this.tapDifficulty.toFixed(2)} tap, ` +
1113
+ `${this.rhythmDifficulty.toFixed(2)} rhythm, ` +
1114
+ `${this.flashlightDifficulty.toFixed(2)} flashlight, ` +
1115
+ `${this.visualDifficulty.toFixed(2)} visual)`);
1212
1116
  }
1213
1117
  }
1214
1118
 
@@ -1586,56 +1490,186 @@ class DroidRhythm extends DroidSkill {
1586
1490
  }
1587
1491
 
1588
1492
  /**
1589
- * An evaluator for calculating osu!droid visual skill.
1493
+ * An evaluator for calculating osu!droid tap skill.
1590
1494
  */
1591
- class DroidVisualEvaluator {
1495
+ class DroidTapEvaluator {
1592
1496
  /**
1593
- * Evaluates the difficulty of reading the current object, based on:
1497
+ * Evaluates the difficulty of tapping the current object, based on:
1594
1498
  *
1595
- * - note density of the current object,
1596
- * - overlapping factor of the current object,
1597
- * - the preempt time of the current object,
1598
- * - the visual opacity of the current object,
1599
- * - the velocity of the current object if it's a slider,
1600
- * - past objects' velocity if they are sliders,
1601
- * - and whether the Hidden mod is enabled.
1499
+ * - time between pressing the previous and current object,
1500
+ * - distance between those objects,
1501
+ * - how easily they can be cheesed,
1502
+ * - and the strain time cap.
1602
1503
  *
1603
1504
  * @param current The current object.
1604
- * @param mods The mods used.
1605
- * @param withSliders Whether to take slider difficulty into account.
1505
+ * @param considerCheesability Whether to consider cheesability.
1506
+ * @param strainTimeCap The strain time to cap the object's strain time to.
1606
1507
  */
1607
- static evaluateDifficultyOf(current, mods, withSliders) {
1508
+ static evaluateDifficultyOf(current, considerCheesability, strainTimeCap) {
1608
1509
  if (current.object instanceof osuBase.Spinner ||
1609
1510
  // Exclude overlapping objects that can be tapped at once.
1610
- current.isOverlapping(true) ||
1611
- current.index === 0) {
1511
+ current.isOverlapping(false)) {
1612
1512
  return 0;
1613
1513
  }
1614
- // Start with base density and give global bonus for Hidden.
1615
- // Add density caps for sanity.
1616
- let strain;
1617
- if (mods.some((m) => m instanceof osuBase.ModHidden)) {
1618
- strain = Math.min(30, Math.pow(current.noteDensity, 3));
1619
- }
1620
- else if (mods.some((m) => m instanceof osuBase.ModTraceable)) {
1621
- // Give more bonus for hit circles due to there being no circle piece.
1622
- if (current.object instanceof osuBase.Circle) {
1623
- strain = Math.min(25, Math.pow(current.noteDensity, 2.5));
1624
- }
1625
- else {
1626
- strain = Math.min(22.5, Math.pow(current.noteDensity, 2.25));
1627
- }
1628
- }
1629
- else {
1630
- strain = Math.min(20, Math.pow(current.noteDensity, 2));
1514
+ const doubletapness = considerCheesability
1515
+ ? 1 - current.doubletapness
1516
+ : 1;
1517
+ const strainTime = strainTimeCap !== undefined
1518
+ ? // We cap the strain time to 50 here as the chance of vibro is higher in any BPM higher than 300.
1519
+ Math.max(50, strainTimeCap, current.strainTime)
1520
+ : current.strainTime;
1521
+ let speedBonus = 1;
1522
+ if (strainTime < this.minSpeedBonus) {
1523
+ speedBonus +=
1524
+ 0.75 *
1525
+ Math.pow(osuBase.ErrorFunction.erf((this.minSpeedBonus - strainTime) / 40), 2);
1631
1526
  }
1632
- // Bonus based on how visible the object is.
1633
- for (let i = 0; i < Math.min(current.index, 10); ++i) {
1634
- const previous = current.previous(i);
1635
- if (previous.object instanceof osuBase.Spinner ||
1636
- // Exclude overlapping objects that can be tapped at once.
1637
- previous.isOverlapping(true)) {
1638
- continue;
1527
+ return (speedBonus * Math.pow(doubletapness, 1.5) * 1000) / strainTime;
1528
+ }
1529
+ }
1530
+ // ~200 1/4 BPM streams
1531
+ DroidTapEvaluator.minSpeedBonus = 75;
1532
+
1533
+ /**
1534
+ * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
1535
+ */
1536
+ class DroidTap extends DroidSkill {
1537
+ /**
1538
+ * The delta time of hitobjects.
1539
+ */
1540
+ get objectDeltaTimes() {
1541
+ return this._objectDeltaTimes;
1542
+ }
1543
+ constructor(mods, considerCheesability, strainTimeCap) {
1544
+ super(mods);
1545
+ this.reducedSectionCount = 10;
1546
+ this.reducedSectionBaseline = 0.75;
1547
+ this.strainDecayBase = 0.3;
1548
+ this.starsPerDouble = 1.1;
1549
+ this.currentTapStrain = 0;
1550
+ this.currentRhythmMultiplier = 0;
1551
+ this.skillMultiplier = 1.375;
1552
+ this._objectDeltaTimes = [];
1553
+ this.considerCheesability = considerCheesability;
1554
+ this.strainTimeCap = strainTimeCap;
1555
+ }
1556
+ /**
1557
+ * The amount of notes that are relevant to the difficulty.
1558
+ */
1559
+ relevantNoteCount() {
1560
+ if (this._objectStrains.length === 0) {
1561
+ return 0;
1562
+ }
1563
+ const maxStrain = osuBase.MathUtils.max(this._objectStrains);
1564
+ if (maxStrain === 0) {
1565
+ return 0;
1566
+ }
1567
+ return this._objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
1568
+ }
1569
+ /**
1570
+ * The delta time relevant to the difficulty.
1571
+ */
1572
+ relevantDeltaTime() {
1573
+ if (this._objectStrains.length === 0) {
1574
+ return 0;
1575
+ }
1576
+ const maxStrain = osuBase.MathUtils.max(this._objectStrains);
1577
+ if (maxStrain === 0) {
1578
+ return 0;
1579
+ }
1580
+ return (this._objectDeltaTimes.reduce((total, next, index) => total +
1581
+ (next * 1) /
1582
+ (1 +
1583
+ Math.exp(-((this._objectStrains[index] / maxStrain) *
1584
+ 25 -
1585
+ 20))), 0) /
1586
+ this._objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 25 - 20))), 0));
1587
+ }
1588
+ strainValueAt(current) {
1589
+ this.currentTapStrain *= this.strainDecay(current.strainTime);
1590
+ this.currentTapStrain +=
1591
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.considerCheesability, this.strainTimeCap) * this.skillMultiplier;
1592
+ this.currentRhythmMultiplier = current.rhythmMultiplier;
1593
+ this._objectDeltaTimes.push(current.deltaTime);
1594
+ return this.currentTapStrain * current.rhythmMultiplier;
1595
+ }
1596
+ calculateInitialStrain(time, current) {
1597
+ var _a, _b;
1598
+ return (this.currentTapStrain *
1599
+ this.currentRhythmMultiplier *
1600
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
1601
+ }
1602
+ getObjectStrain() {
1603
+ return this.currentTapStrain * this.currentRhythmMultiplier;
1604
+ }
1605
+ /**
1606
+ * @param current The hitobject to save to.
1607
+ */
1608
+ saveToHitObject(current) {
1609
+ if (this.strainTimeCap !== undefined) {
1610
+ return;
1611
+ }
1612
+ const strain = this.currentTapStrain * this.currentRhythmMultiplier;
1613
+ if (this.considerCheesability) {
1614
+ current.tapStrain = strain;
1615
+ }
1616
+ else {
1617
+ current.originalTapStrain = strain;
1618
+ }
1619
+ }
1620
+ }
1621
+
1622
+ /**
1623
+ * An evaluator for calculating osu!droid visual skill.
1624
+ */
1625
+ class DroidVisualEvaluator {
1626
+ /**
1627
+ * Evaluates the difficulty of reading the current object, based on:
1628
+ *
1629
+ * - note density of the current object,
1630
+ * - overlapping factor of the current object,
1631
+ * - the preempt time of the current object,
1632
+ * - the visual opacity of the current object,
1633
+ * - the velocity of the current object if it's a slider,
1634
+ * - past objects' velocity if they are sliders,
1635
+ * - and whether the Hidden mod is enabled.
1636
+ *
1637
+ * @param current The current object.
1638
+ * @param mods The mods used.
1639
+ * @param withSliders Whether to take slider difficulty into account.
1640
+ */
1641
+ static evaluateDifficultyOf(current, mods, withSliders) {
1642
+ if (current.object instanceof osuBase.Spinner ||
1643
+ // Exclude overlapping objects that can be tapped at once.
1644
+ current.isOverlapping(true) ||
1645
+ current.index === 0) {
1646
+ return 0;
1647
+ }
1648
+ // Start with base density and give global bonus for Hidden.
1649
+ // Add density caps for sanity.
1650
+ let strain;
1651
+ if (mods.some((m) => m instanceof osuBase.ModHidden)) {
1652
+ strain = Math.min(30, Math.pow(current.noteDensity, 3));
1653
+ }
1654
+ else if (mods.some((m) => m instanceof osuBase.ModTraceable)) {
1655
+ // Give more bonus for hit circles due to there being no circle piece.
1656
+ if (current.object instanceof osuBase.Circle) {
1657
+ strain = Math.min(25, Math.pow(current.noteDensity, 2.5));
1658
+ }
1659
+ else {
1660
+ strain = Math.min(22.5, Math.pow(current.noteDensity, 2.25));
1661
+ }
1662
+ }
1663
+ else {
1664
+ strain = Math.min(20, Math.pow(current.noteDensity, 2));
1665
+ }
1666
+ // Bonus based on how visible the object is.
1667
+ for (let i = 0; i < Math.min(current.index, 10); ++i) {
1668
+ const previous = current.previous(i);
1669
+ if (previous.object instanceof osuBase.Spinner ||
1670
+ // Exclude overlapping objects that can be tapped at once.
1671
+ previous.isOverlapping(true)) {
1672
+ continue;
1639
1673
  }
1640
1674
  // Do not consider objects that don't fall under time preempt.
1641
1675
  if (current.object.startTime - previous.object.endTime >
@@ -1732,151 +1766,78 @@ class DroidVisual extends DroidSkill {
1732
1766
  }
1733
1767
  }
1734
1768
 
1769
+ /**
1770
+ * Holds data that can be used to calculate osu!droid performance points as well
1771
+ * as doing some analysis using the replay of a score.
1772
+ */
1773
+ class ExtendedDroidDifficultyAttributes extends DroidDifficultyAttributes {
1774
+ constructor(cacheableAttributes) {
1775
+ super(cacheableAttributes);
1776
+ this.mode = "rebalance";
1777
+ this.possibleThreeFingeredSections = [];
1778
+ this.difficultSliders = [];
1779
+ this.aimNoteCount = 0;
1780
+ this.flashlightSliderFactor = 1;
1781
+ this.visualSliderFactor = 1;
1782
+ if (!cacheableAttributes) {
1783
+ return;
1784
+ }
1785
+ this.possibleThreeFingeredSections =
1786
+ cacheableAttributes.possibleThreeFingeredSections;
1787
+ this.difficultSliders = cacheableAttributes.difficultSliders;
1788
+ this.aimNoteCount = cacheableAttributes.aimNoteCount;
1789
+ this.flashlightSliderFactor =
1790
+ cacheableAttributes.flashlightSliderFactor;
1791
+ this.visualSliderFactor = cacheableAttributes.visualSliderFactor;
1792
+ }
1793
+ }
1794
+
1735
1795
  /**
1736
1796
  * A difficulty calculator for osu!droid gamemode.
1737
1797
  */
1738
1798
  class DroidDifficultyCalculator extends DifficultyCalculator {
1739
1799
  constructor() {
1740
- super(...arguments);
1741
- this.attributes = {
1742
- mode: "rebalance",
1743
- aimDifficultSliderCount: 0,
1744
- tapDifficulty: 0,
1745
- rhythmDifficulty: 0,
1746
- visualDifficulty: 0,
1747
- aimNoteCount: 0,
1748
- mods: [],
1749
- starRating: 0,
1750
- maxCombo: 0,
1751
- aimDifficulty: 0,
1752
- flashlightDifficulty: 0,
1753
- speedNoteCount: 0,
1754
- sliderFactor: 0,
1755
- clockRate: 1,
1756
- overallDifficulty: 0,
1757
- hitCircleCount: 0,
1758
- sliderCount: 0,
1759
- spinnerCount: 0,
1760
- aimDifficultStrainCount: 0,
1761
- tapDifficultStrainCount: 0,
1762
- flashlightDifficultStrainCount: 0,
1763
- visualDifficultStrainCount: 0,
1764
- flashlightSliderFactor: 0,
1765
- visualSliderFactor: 0,
1766
- possibleThreeFingeredSections: [],
1767
- difficultSliders: [],
1768
- averageSpeedDeltaTime: 0,
1769
- vibroFactor: 1,
1770
- };
1800
+ super();
1771
1801
  this.difficultyMultiplier = 0.18;
1772
- this.mode = osuBase.Modes.droid;
1773
- }
1774
- /**
1775
- * The aim star rating of the beatmap.
1776
- */
1777
- get aim() {
1778
- return this.attributes.aimDifficulty;
1779
- }
1780
- /**
1781
- * The tap star rating of the beatmap.
1782
- */
1783
- get tap() {
1784
- return this.attributes.tapDifficulty;
1785
- }
1786
- /**
1787
- * The rhythm star rating of the beatmap.
1788
- */
1789
- get rhythm() {
1790
- return this.attributes.rhythmDifficulty;
1791
- }
1792
- /**
1793
- * The flashlight star rating of the beatmap.
1794
- */
1795
- get flashlight() {
1796
- return this.attributes.flashlightDifficulty;
1797
- }
1798
- /**
1799
- * The visual star rating of the beatmap.
1800
- */
1801
- get visual() {
1802
- return this.attributes.visualDifficulty;
1803
- }
1804
- get cacheableAttributes() {
1805
- return Object.assign(Object.assign({}, this.attributes), { mods: osuBase.ModUtil.modsToOsuString(this.attributes.mods) });
1806
- }
1807
- // Override to use DroidDifficultyCalculationOptions
1808
- calculate(options) {
1809
- return super.calculate(options);
1810
- }
1811
- /**
1812
- * Calculates the aim star rating of the beatmap and stores it in this instance.
1813
- */
1814
- calculateAim() {
1815
- if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
1816
- this.attributes.aimDifficulty = 0;
1817
- return;
1818
- }
1819
- const aimSkill = new DroidAim(this.mods, true);
1820
- const aimSkillWithoutSliders = new DroidAim(this.mods, false);
1821
- this.calculateSkills(aimSkill, aimSkillWithoutSliders);
1822
- this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
1823
- }
1824
- /**
1825
- * Calculates the tap star rating of the beatmap and stores it in this instance.
1826
- */
1827
- calculateTap() {
1828
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1829
- this.attributes.tapDifficulty = 0;
1830
- return;
1831
- }
1832
- const tapSkillCheese = new DroidTap(this.mods, true);
1833
- const tapSkillNoCheese = new DroidTap(this.mods, false);
1834
- this.calculateSkills(tapSkillCheese, tapSkillNoCheese);
1835
- const tapSkillVibro = new DroidTap(this.mods, true, tapSkillCheese.relevantDeltaTime());
1836
- this.calculateSkills(tapSkillVibro);
1837
- this.postCalculateTap(tapSkillCheese, tapSkillVibro);
1838
- }
1839
- /**
1840
- * Calculates the rhythm star rating of the beatmap and stores it in this instance.
1841
- */
1842
- calculateRhythm() {
1843
- const rhythmSkill = new DroidRhythm(this.mods);
1844
- this.calculateSkills(rhythmSkill);
1845
- this.postCalculateRhythm(rhythmSkill);
1846
- }
1847
- /**
1848
- * Calculates the flashlight star rating of the beatmap and stores it in this instance.
1849
- */
1850
- calculateFlashlight() {
1851
- if (!this.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1852
- this.attributes.flashlightDifficulty = 0;
1853
- return;
1854
- }
1855
- const flashlightSkill = new DroidFlashlight(this.mods, true);
1856
- const flashlightSkillWithoutSliders = new DroidFlashlight(this.mods, false);
1857
- this.calculateSkills(flashlightSkill, flashlightSkillWithoutSliders);
1858
- this.postCalculateFlashlight(flashlightSkill, flashlightSkillWithoutSliders);
1859
- }
1860
- /**
1861
- * Calculates the visual star rating of the beatmap and stores it in this instance.
1862
- */
1863
- calculateVisual() {
1864
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1865
- this.attributes.visualDifficulty = 0;
1866
- return;
1867
- }
1868
- const visualSkill = new DroidVisual(this.mods, true);
1869
- const visualSkillWithoutSliders = new DroidVisual(this.mods, false);
1870
- this.calculateSkills(visualSkill, visualSkillWithoutSliders);
1871
- this.postCalculateVisual(visualSkill, visualSkillWithoutSliders);
1872
- }
1873
- calculateTotal() {
1874
- const aimPerformanceValue = this.basePerformanceValue(Math.pow(this.aim, 0.8));
1875
- const tapPerformanceValue = this.basePerformanceValue(this.tap);
1876
- const flashlightPerformanceValue = this.mods.some((m) => m instanceof osuBase.ModFlashlight)
1877
- ? Math.pow(this.flashlight, 1.6) * 25
1878
- : 0;
1879
- const visualPerformanceValue = Math.pow(this.visual, 1.6) * 22.5;
1802
+ this.difficultyAdjustmentMods
1803
+ .add(osuBase.ModPrecise)
1804
+ .add(osuBase.ModScoreV2)
1805
+ .add(osuBase.ModTraceable);
1806
+ }
1807
+ retainDifficultyAdjustmentMods(mods) {
1808
+ return mods.filter((mod) => mod.isApplicableToDroid() &&
1809
+ this.difficultyAdjustmentMods.has(mod.constructor) &&
1810
+ mod.isDroidRelevant);
1811
+ }
1812
+ createDifficultyAttributes(beatmap, skills, objects) {
1813
+ const attributes = new ExtendedDroidDifficultyAttributes();
1814
+ attributes.mods = beatmap.mods.slice();
1815
+ attributes.maxCombo = beatmap.maxCombo;
1816
+ attributes.clockRate = beatmap.speedMultiplier;
1817
+ attributes.hitCircleCount = beatmap.hitObjects.circles;
1818
+ attributes.sliderCount = beatmap.hitObjects.sliders;
1819
+ attributes.spinnerCount = beatmap.hitObjects.spinners;
1820
+ this.populateAimAttributes(attributes, skills, objects);
1821
+ this.populateTapAttributes(attributes, skills, objects);
1822
+ this.populateRhythmAttributes(attributes, skills);
1823
+ this.populateFlashlightAttributes(attributes, skills);
1824
+ this.populateVisualAttributes(attributes, skills);
1825
+ if (attributes.mods.some((m) => m instanceof osuBase.ModRelax)) {
1826
+ attributes.aimDifficulty *= 0.9;
1827
+ attributes.tapDifficulty = 0;
1828
+ attributes.rhythmDifficulty = 0;
1829
+ attributes.flashlightDifficulty *= 0.7;
1830
+ attributes.visualDifficulty = 0;
1831
+ }
1832
+ else if (attributes.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
1833
+ attributes.aimDifficulty = 0;
1834
+ attributes.flashlightDifficulty *= 0.3;
1835
+ attributes.visualDifficulty *= 0.8;
1836
+ }
1837
+ const aimPerformanceValue = this.basePerformanceValue(Math.pow(attributes.aimDifficulty, 0.8));
1838
+ const tapPerformanceValue = this.basePerformanceValue(attributes.tapDifficulty);
1839
+ const flashlightPerformanceValue = Math.pow(attributes.flashlightDifficulty, 1.6) * 25;
1840
+ const visualPerformanceValue = Math.pow(attributes.visualDifficulty, 1.6) * 22.5;
1880
1841
  const basePerformanceValue = Math.pow(Math.pow(aimPerformanceValue, 1.1) +
1881
1842
  Math.pow(tapPerformanceValue, 1.1) +
1882
1843
  Math.pow(flashlightPerformanceValue, 1.1) +
@@ -1884,126 +1845,82 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1884
1845
  if (basePerformanceValue > 1e-5) {
1885
1846
  // Document for formula derivation:
1886
1847
  // https://docs.google.com/document/d/10DZGYYSsT_yjz2Mtp6yIJld0Rqx4E-vVHupCqiM4TNI/edit
1887
- this.attributes.starRating =
1848
+ attributes.starRating =
1888
1849
  0.027 *
1889
1850
  (Math.cbrt((100000 / Math.pow(2, 1 / 1.1)) * basePerformanceValue) +
1890
1851
  4);
1891
1852
  }
1892
1853
  else {
1893
- this.attributes.starRating = 0;
1894
- }
1895
- }
1896
- calculateAll() {
1897
- const skills = this.createSkills();
1898
- this.calculateSkills(...skills);
1899
- const aimSkill = skills.find((s) => s instanceof DroidAim && s.withSliders);
1900
- const aimSkillWithoutSliders = skills.find((s) => s instanceof DroidAim && !s.withSliders);
1901
- const rhythmSkill = skills.find((s) => s instanceof DroidRhythm);
1902
- const tapSkillCheese = skills.find((s) => s instanceof DroidTap && s.considerCheesability);
1903
- const flashlightSkill = skills.find((s) => s instanceof DroidFlashlight && s.withSliders);
1904
- const flashlightSkillWithoutSliders = skills.find((s) => s instanceof DroidFlashlight && !s.withSliders);
1905
- const visualSkill = skills.find((s) => s instanceof DroidVisual && s.withSliders);
1906
- const visualSkillWithoutSliders = skills.find((s) => s instanceof DroidVisual && !s.withSliders);
1907
- if (aimSkill && aimSkillWithoutSliders) {
1908
- this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
1909
- }
1910
- if (tapSkillCheese) {
1911
- const tapSkillVibro = new DroidTap(this.mods, true, tapSkillCheese.relevantDeltaTime());
1912
- this.calculateSkills(tapSkillVibro);
1913
- this.postCalculateTap(tapSkillCheese, tapSkillVibro);
1854
+ attributes.starRating = 0;
1914
1855
  }
1915
- this.postCalculateRhythm(rhythmSkill);
1916
- if (flashlightSkill && flashlightSkillWithoutSliders) {
1917
- this.postCalculateFlashlight(flashlightSkill, flashlightSkillWithoutSliders);
1856
+ let greatWindow;
1857
+ if (attributes.mods.some((m) => m instanceof osuBase.ModPrecise)) {
1858
+ greatWindow = new osuBase.PreciseDroidHitWindow(beatmap.difficulty.od)
1859
+ .greatWindow;
1918
1860
  }
1919
- if (visualSkill && visualSkillWithoutSliders) {
1920
- this.postCalculateVisual(visualSkill, visualSkillWithoutSliders);
1861
+ else {
1862
+ greatWindow = new osuBase.DroidHitWindow(beatmap.difficulty.od).greatWindow;
1921
1863
  }
1922
- this.calculateTotal();
1864
+ attributes.overallDifficulty = osuBase.OsuHitWindow.greatWindowToOD(greatWindow / attributes.clockRate);
1865
+ return attributes;
1923
1866
  }
1924
- toString() {
1925
- return (this.total.toFixed(2) +
1926
- " stars (" +
1927
- this.aim.toFixed(2) +
1928
- " aim, " +
1929
- this.tap.toFixed(2) +
1930
- " tap, " +
1931
- this.rhythm.toFixed(2) +
1932
- " rhythm, " +
1933
- this.flashlight.toFixed(2) +
1934
- " flashlight, " +
1935
- this.visual.toFixed(2) +
1936
- " visual)");
1867
+ createPlayableBeatmap(beatmap, mods) {
1868
+ return beatmap.createDroidPlayableBeatmap(mods);
1937
1869
  }
1938
- generateDifficultyHitObjects(beatmap, clockRate) {
1870
+ createDifficultyHitObjects(beatmap) {
1939
1871
  var _a, _b;
1872
+ const clockRate = beatmap.speedMultiplier;
1940
1873
  const difficultyObjects = [];
1941
1874
  const { objects } = beatmap.hitObjects;
1942
1875
  for (let i = 0; i < objects.length; ++i) {
1943
- const difficultyObject = new DroidDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, clockRate);
1876
+ const difficultyObject = new DroidDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, clockRate, i - 1);
1944
1877
  difficultyObject.computeProperties(clockRate, objects);
1945
1878
  difficultyObjects.push(difficultyObject);
1946
1879
  }
1947
1880
  return difficultyObjects;
1948
1881
  }
1949
- createSkills() {
1882
+ createSkills(beatmap) {
1883
+ const { mods } = beatmap;
1950
1884
  const skills = [];
1951
- if (!this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
1952
- skills.push(new DroidAim(this.mods, true));
1953
- skills.push(new DroidAim(this.mods, false));
1885
+ if (!mods.some((m) => m instanceof osuBase.ModAutopilot)) {
1886
+ skills.push(new DroidAim(mods, true));
1887
+ skills.push(new DroidAim(mods, false));
1954
1888
  }
1955
- if (!this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1889
+ if (!mods.some((m) => m instanceof osuBase.ModRelax)) {
1956
1890
  // Tap and visual skills depend on rhythm skill, so we put it first
1957
- skills.push(new DroidRhythm(this.mods));
1958
- skills.push(new DroidTap(this.mods, true));
1959
- skills.push(new DroidTap(this.mods, false));
1960
- skills.push(new DroidVisual(this.mods, true));
1961
- skills.push(new DroidVisual(this.mods, false));
1891
+ skills.push(new DroidRhythm(mods));
1892
+ skills.push(new DroidTap(mods, true));
1893
+ skills.push(new DroidTap(mods, false));
1894
+ skills.push(new DroidVisual(mods, true));
1895
+ skills.push(new DroidVisual(mods, false));
1962
1896
  }
1963
- if (this.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1964
- skills.push(new DroidFlashlight(this.mods, true));
1965
- skills.push(new DroidFlashlight(this.mods, false));
1897
+ if (mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1898
+ skills.push(new DroidFlashlight(mods, true));
1899
+ skills.push(new DroidFlashlight(mods, false));
1966
1900
  }
1967
1901
  return skills;
1968
1902
  }
1969
- calculateClockRate(options) {
1970
- var _a, _b;
1971
- return (osuBase.ModUtil.calculateRateWithMods((_a = options === null || options === void 0 ? void 0 : options.mods) !== null && _a !== void 0 ? _a : [], options === null || options === void 0 ? void 0 : options.oldStatistics) * ((_b = options === null || options === void 0 ? void 0 : options.customSpeedMultiplier) !== null && _b !== void 0 ? _b : 1));
1972
- }
1973
- /**
1974
- * Called after aim skill calculation.
1975
- *
1976
- * @param aimSkill The aim skill that considers sliders.
1977
- * @param aimSkillWithoutSliders The aim skill that doesn't consider sliders.
1978
- */
1979
- postCalculateAim(aimSkill, aimSkillWithoutSliders) {
1980
- this.strainPeaks.aimWithSliders = aimSkill.strainPeaks;
1981
- this.strainPeaks.aimWithoutSliders = aimSkillWithoutSliders.strainPeaks;
1982
- this.attributes.aimDifficulty = this.mods.some((m) => m instanceof osuBase.ModAutopilot)
1983
- ? 0
1984
- : this.starValue(aimSkill.difficultyValue());
1985
- if (this.aim) {
1986
- this.attributes.sliderFactor =
1987
- this.starValue(aimSkillWithoutSliders.difficultyValue()) /
1988
- this.aim;
1989
- }
1990
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1991
- this.attributes.aimDifficulty *= 0.9;
1903
+ createStrainPeakSkills(beatmap) {
1904
+ const { mods } = beatmap;
1905
+ return [
1906
+ new DroidAim(mods, true),
1907
+ new DroidAim(mods, false),
1908
+ new DroidTap(mods, true),
1909
+ new DroidFlashlight(mods, true),
1910
+ ];
1911
+ }
1912
+ populateAimAttributes(attributes, skills, objects) {
1913
+ const aim = skills.find((s) => s instanceof DroidAim && s.withSliders);
1914
+ const aimNoSlider = skills.find((s) => s instanceof DroidAim && !s.withSliders);
1915
+ if (!aim || !aimNoSlider) {
1916
+ return;
1992
1917
  }
1993
- this.attributes.aimDifficultStrainCount =
1994
- aimSkill.countDifficultStrains();
1995
- this.attributes.aimDifficultSliderCount =
1996
- aimSkill.countDifficultSliders();
1997
- this.calculateAimAttributes();
1998
- }
1999
- /**
2000
- * Calculates aim-related attributes.
2001
- */
2002
- calculateAimAttributes() {
2003
- this.attributes.difficultSliders = [];
1918
+ attributes.aimDifficulty = this.calculateRating(aim);
1919
+ attributes.aimDifficultSliderCount = aim.countDifficultSliders();
1920
+ attributes.aimDifficultStrainCount = aim.countDifficultStrains();
2004
1921
  const topDifficultSliders = [];
2005
- for (let i = 0; i < this.objects.length; ++i) {
2006
- const object = this.objects[i];
1922
+ for (let i = 0; i < objects.length; ++i) {
1923
+ const object = objects[i];
2007
1924
  const velocity = object.travelDistance / object.travelTime;
2008
1925
  if (velocity > 0) {
2009
1926
  topDifficultSliders.push({
@@ -2017,53 +1934,50 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
2017
1934
  const difficultyRating = slider.velocity / velocitySum;
2018
1935
  // Only consider sliders that are fast enough.
2019
1936
  if (difficultyRating > 0.02) {
2020
- this.attributes.difficultSliders.push({
1937
+ attributes.difficultSliders.push({
2021
1938
  index: slider.index,
2022
1939
  difficultyRating: slider.velocity / velocitySum,
2023
1940
  });
2024
1941
  }
2025
1942
  }
2026
- this.attributes.difficultSliders.sort((a, b) => b.difficultyRating - a.difficultyRating);
1943
+ attributes.difficultSliders.sort((a, b) => b.difficultyRating - a.difficultyRating);
2027
1944
  // Take the top 15% most difficult sliders.
2028
- while (this.attributes.difficultSliders.length >
2029
- Math.ceil(0.15 * this.beatmap.hitObjects.sliders)) {
2030
- this.attributes.difficultSliders.pop();
1945
+ while (attributes.difficultSliders.length >
1946
+ Math.ceil(0.15 * attributes.sliderCount)) {
1947
+ attributes.difficultSliders.pop();
1948
+ }
1949
+ if (attributes.aimDifficulty > 0) {
1950
+ attributes.sliderFactor =
1951
+ this.calculateRating(aimNoSlider) / attributes.aimDifficulty;
1952
+ }
1953
+ else {
1954
+ attributes.sliderFactor = 1;
2031
1955
  }
2032
1956
  }
2033
- /**
2034
- * Called after tap skill calculation.
2035
- *
2036
- * @param tapSkillCheese The tap skill that considers cheesing.
2037
- * @param tapSkillVibro The tap skill that considers vibro.
2038
- */
2039
- postCalculateTap(tapSkillCheese, tapSkillVibro) {
2040
- this.strainPeaks.speed = tapSkillCheese.strainPeaks;
2041
- this.attributes.tapDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
2042
- ? 0
2043
- : this.starValue(tapSkillCheese.difficultyValue());
2044
- if (this.tap) {
2045
- this.attributes.vibroFactor =
2046
- this.starValue(tapSkillVibro.difficultyValue()) / this.tap;
2047
- }
2048
- this.attributes.speedNoteCount = tapSkillCheese.relevantNoteCount();
2049
- this.attributes.averageSpeedDeltaTime =
2050
- tapSkillCheese.relevantDeltaTime();
2051
- this.attributes.tapDifficultStrainCount =
2052
- tapSkillCheese.countDifficultStrains();
2053
- this.calculateTapAttributes();
2054
- }
2055
- /**
2056
- * Calculates tap-related attributes.
2057
- */
2058
- calculateTapAttributes() {
2059
- this.attributes.possibleThreeFingeredSections = [];
1957
+ populateTapAttributes(attributes, skills, objects) {
1958
+ const tap = skills.find((s) => s instanceof DroidTap && s.considerCheesability);
1959
+ if (!tap) {
1960
+ return;
1961
+ }
1962
+ attributes.tapDifficulty = this.calculateRating(tap);
1963
+ attributes.tapDifficultStrainCount = tap.countDifficultStrains();
1964
+ attributes.speedNoteCount = tap.relevantNoteCount();
1965
+ attributes.averageSpeedDeltaTime = tap.relevantDeltaTime();
1966
+ if (attributes.tapDifficulty > 0) {
1967
+ const tapVibro = new DroidTap(attributes.mods, true, attributes.averageSpeedDeltaTime);
1968
+ for (const object of objects) {
1969
+ tapVibro.process(object);
1970
+ }
1971
+ attributes.vibroFactor =
1972
+ this.calculateRating(tapVibro) / attributes.tapDifficulty;
1973
+ }
2060
1974
  const { threeFingerStrainThreshold } = DroidDifficultyCalculator;
2061
1975
  const minSectionObjectCount = 5;
2062
1976
  let inSpeedSection = false;
2063
1977
  let firstSpeedObjectIndex = 0;
2064
- for (let i = 2; i < this.objects.length; ++i) {
2065
- const current = this.objects[i];
2066
- const prev = this.objects[i - 1];
1978
+ for (let i = 2; i < objects.length; ++i) {
1979
+ const current = objects[i];
1980
+ const prev = objects[i - 1];
2067
1981
  if (!inSpeedSection &&
2068
1982
  current.originalTapStrain >= threeFingerStrainThreshold) {
2069
1983
  inSpeedSection = true;
@@ -2079,17 +1993,17 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
2079
1993
  // Stop speed section on slowing down 1/2 rhythm change or anything slower.
2080
1994
  (prevDelta < currentDelta && deltaRatio <= 0.5) ||
2081
1995
  // Don't forget to manually add the last section, which would otherwise be ignored.
2082
- i === this.objects.length - 1)) {
2083
- const lastSpeedObjectIndex = i - (i === this.objects.length - 1 ? 0 : 1);
1996
+ i === objects.length - 1)) {
1997
+ const lastSpeedObjectIndex = i - (i === objects.length - 1 ? 0 : 1);
2084
1998
  inSpeedSection = false;
2085
1999
  // Ignore sections that don't meet object count requirement.
2086
2000
  if (i - firstSpeedObjectIndex < minSectionObjectCount) {
2087
2001
  continue;
2088
2002
  }
2089
- this.attributes.possibleThreeFingeredSections.push({
2003
+ attributes.possibleThreeFingeredSections.push({
2090
2004
  firstObjectIndex: firstSpeedObjectIndex,
2091
2005
  lastObjectIndex: lastSpeedObjectIndex,
2092
- sumStrain: Math.pow(this.objects
2006
+ sumStrain: Math.pow(objects
2093
2007
  .slice(firstSpeedObjectIndex, lastSpeedObjectIndex + 1)
2094
2008
  .reduce((a, v) => a +
2095
2009
  v.originalTapStrain /
@@ -2098,62 +2012,48 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
2098
2012
  }
2099
2013
  }
2100
2014
  }
2101
- /**
2102
- * Called after rhythm skill calculation.
2103
- *
2104
- * @param rhythmSkill The rhythm skill.
2105
- */
2106
- postCalculateRhythm(rhythmSkill) {
2107
- this.attributes.rhythmDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
2108
- ? 0
2109
- : this.starValue(rhythmSkill.difficultyValue());
2110
- }
2111
- /**
2112
- * Called after flashlight skill calculation.
2113
- *
2114
- * @param flashlightSkill The flashlight skill that considers sliders.
2115
- * @param flashlightSkillWithoutSliders The flashlight skill that doesn't consider sliders.
2116
- */
2117
- postCalculateFlashlight(flashlightSkill, flashlightSkillWithoutSliders) {
2118
- this.strainPeaks.flashlight = flashlightSkill.strainPeaks;
2119
- this.attributes.flashlightDifficulty = this.starValue(flashlightSkill.difficultyValue());
2120
- if (this.flashlight) {
2121
- this.attributes.flashlightSliderFactor =
2122
- this.starValue(flashlightSkillWithoutSliders.difficultyValue()) / this.flashlight;
2015
+ populateRhythmAttributes(attributes, skills) {
2016
+ const rhythm = skills.find((s) => s instanceof DroidRhythm);
2017
+ if (!rhythm) {
2018
+ return;
2123
2019
  }
2124
- if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
2125
- this.attributes.flashlightDifficulty *= 0.3;
2020
+ attributes.rhythmDifficulty = this.calculateRating(rhythm);
2021
+ }
2022
+ populateFlashlightAttributes(attributes, skills) {
2023
+ const flashlight = skills.find((s) => s instanceof DroidFlashlight && s.withSliders);
2024
+ const flashlightNoSliders = skills.find((s) => s instanceof DroidFlashlight && !s.withSliders);
2025
+ if (!flashlight || !flashlightNoSliders) {
2026
+ return;
2126
2027
  }
2127
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
2128
- this.attributes.flashlightDifficulty *= 0.7;
2028
+ attributes.flashlightDifficulty = this.calculateRating(flashlight);
2029
+ attributes.flashlightDifficultStrainCount =
2030
+ flashlight.countDifficultStrains();
2031
+ if (attributes.flashlightDifficulty > 0) {
2032
+ attributes.flashlightSliderFactor =
2033
+ this.calculateRating(flashlightNoSliders) /
2034
+ attributes.flashlightDifficulty;
2129
2035
  }
2130
- else if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
2131
- this.attributes.flashlightDifficulty *= 0.4;
2036
+ else {
2037
+ attributes.flashlightSliderFactor = 1;
2132
2038
  }
2133
- this.attributes.flashlightDifficultStrainCount =
2134
- flashlightSkill.countDifficultStrains();
2135
2039
  }
2136
- /**
2137
- * Called after visual skill calculation.
2138
- *
2139
- * @param visualSkillWithSliders The visual skill that considers sliders.
2140
- * @param visualSkillWithoutSliders The visual skill that doesn't consider sliders.
2141
- */
2142
- postCalculateVisual(visualSkillWithSliders, visualSkillWithoutSliders) {
2143
- this.attributes.visualDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
2144
- ? 0
2145
- : this.starValue(visualSkillWithSliders.difficultyValue());
2146
- if (this.visual) {
2147
- this.attributes.visualSliderFactor =
2148
- this.starValue(visualSkillWithoutSliders.difficultyValue()) /
2149
- this.visual;
2040
+ populateVisualAttributes(attributes, skills) {
2041
+ const visual = skills.find((s) => s instanceof DroidVisual && s.withSliders);
2042
+ const visualNoSliders = skills.find((s) => s instanceof DroidVisual && !s.withSliders);
2043
+ if (!visual || !visualNoSliders) {
2044
+ return;
2150
2045
  }
2151
- if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
2152
- this.attributes.visualDifficulty *= 0.8;
2046
+ attributes.visualDifficulty = this.calculateRating(visual);
2047
+ attributes.visualDifficultStrainCount = visual.countDifficultStrains();
2048
+ if (attributes.visualDifficulty > 0) {
2049
+ attributes.visualSliderFactor =
2050
+ this.calculateRating(visualNoSliders) /
2051
+ attributes.visualDifficulty;
2153
2052
  }
2154
- this.attributes.visualDifficultStrainCount =
2155
- visualSkillWithSliders.countDifficultStrains();
2156
- }
2053
+ else {
2054
+ attributes.visualSliderFactor = 1;
2055
+ }
2056
+ }
2157
2057
  }
2158
2058
  /**
2159
2059
  * The strain threshold to start detecting for possible three-fingered section.
@@ -2188,7 +2088,7 @@ class PerformanceCalculator {
2188
2088
  this.sliderNerfFactor = 1;
2189
2089
  this.difficultyAttributes = difficultyAttributes;
2190
2090
  this.mods = this.isCacheableAttribute(difficultyAttributes)
2191
- ? osuBase.ModUtil.pcStringToMods(difficultyAttributes.mods)
2091
+ ? osuBase.ModUtil.deserializeMods(difficultyAttributes.mods)
2192
2092
  : difficultyAttributes.mods;
2193
2093
  }
2194
2094
  /**
@@ -3125,62 +3025,149 @@ class OsuAim extends OsuSkill {
3125
3025
  }
3126
3026
 
3127
3027
  /**
3128
- * An evaluator for calculating osu!standard speed skill.
3028
+ * Holds data that can be used to calculate osu!standard performance points.
3129
3029
  */
3130
- class OsuSpeedEvaluator {
3030
+ class OsuDifficultyAttributes extends DifficultyAttributes {
3031
+ constructor(cacheableAttributes) {
3032
+ super(cacheableAttributes);
3033
+ this.approachRate = 0;
3034
+ this.speedDifficulty = 0;
3035
+ this.speedDifficultStrainCount = 0;
3036
+ if (!cacheableAttributes) {
3037
+ return;
3038
+ }
3039
+ this.approachRate = cacheableAttributes.approachRate;
3040
+ this.speedDifficulty = cacheableAttributes.speedDifficulty;
3041
+ this.speedDifficultStrainCount =
3042
+ cacheableAttributes.speedDifficultStrainCount;
3043
+ }
3044
+ toString() {
3045
+ return (super.toString() +
3046
+ ` (${this.aimDifficulty.toFixed(2)} aim, ` +
3047
+ `${this.speedDifficulty.toFixed(2)} speed, ` +
3048
+ `${this.flashlightDifficulty.toFixed(2)} flashlight)`);
3049
+ }
3050
+ }
3051
+
3052
+ /**
3053
+ * An evaluator for calculating osu!standard Flashlight skill.
3054
+ */
3055
+ class OsuFlashlightEvaluator {
3131
3056
  /**
3132
- * Evaluates the difficulty of tapping the current object, based on:
3057
+ * Evaluates the difficulty of memorizing and hitting the current object, based on:
3133
3058
  *
3134
- * - time between pressing the previous and current object,
3135
- * - distance between those objects,
3136
- * - and how easily they can be cheesed.
3059
+ * - distance between a number of previous objects and the current object,
3060
+ * - the visual opacity of the current object,
3061
+ * - the angle made by the current object,
3062
+ * - length and speed of the current object (for sliders),
3063
+ * - and whether Hidden mod is enabled.
3137
3064
  *
3138
3065
  * @param current The current object.
3139
- * @param mods The mods applied.
3066
+ * @param mods The mods used.
3140
3067
  */
3141
3068
  static evaluateDifficultyOf(current, mods) {
3142
- var _a;
3143
3069
  if (current.object instanceof osuBase.Spinner) {
3144
3070
  return 0;
3145
3071
  }
3146
- const prev = current.previous(0);
3147
- let strainTime = current.strainTime;
3148
- // Nerf doubletappable doubles.
3149
- const doubletapness = 1 - current.doubletapness;
3150
- // Cap deltatime to the OD 300 hitwindow.
3151
- // 0.93 is derived from making sure 260 BPM 1/4 OD8 streams aren't nerfed harshly, whilst 0.92 limits the effect of the cap.
3152
- strainTime /= osuBase.MathUtils.clamp(strainTime / current.fullGreatWindow / 0.93, 0.92, 1);
3153
- // speedBonus will be 0.0 for BPM < 200
3154
- let speedBonus = 0;
3155
- // Add additional scaling bonus for streams/bursts higher than 200bpm
3156
- if (strainTime < this.minSpeedBonus) {
3157
- speedBonus =
3158
- 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
3072
+ const scalingFactor = 52 / current.object.radius;
3073
+ let smallDistNerf = 1;
3074
+ let cumulativeStrainTime = 0;
3075
+ let result = 0;
3076
+ let last = current;
3077
+ let angleRepeatCount = 0;
3078
+ for (let i = 0; i < Math.min(current.index, 10); ++i) {
3079
+ const currentObject = current.previous(i);
3080
+ cumulativeStrainTime += last.strainTime;
3081
+ if (!(currentObject.object instanceof osuBase.Spinner)) {
3082
+ const jumpDistance = current.object
3083
+ .getStackedPosition(osuBase.Modes.osu)
3084
+ .subtract(currentObject.object.getStackedEndPosition(osuBase.Modes.osu)).length;
3085
+ // We want to nerf objects that can be easily seen within the Flashlight circle radius.
3086
+ if (i === 0) {
3087
+ smallDistNerf = Math.min(1, jumpDistance / 75);
3088
+ }
3089
+ // We also want to nerf stacks so that only the first object of the stack is accounted for.
3090
+ const stackNerf = Math.min(1, currentObject.lazyJumpDistance / scalingFactor / 25);
3091
+ // Bonus based on how visible the object is.
3092
+ const opacityBonus = 1 +
3093
+ this.maxOpacityBonus *
3094
+ (1 -
3095
+ current.opacityAt(currentObject.object.startTime, mods));
3096
+ result +=
3097
+ (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
3098
+ cumulativeStrainTime;
3099
+ if (currentObject.angle !== null && current.angle !== null) {
3100
+ // Objects further back in time should count less for the nerf.
3101
+ if (Math.abs(currentObject.angle - current.angle) < 0.02) {
3102
+ angleRepeatCount += Math.max(0, 1 - 0.1 * i);
3103
+ }
3104
+ }
3105
+ }
3106
+ last = currentObject;
3159
3107
  }
3160
- const travelDistance = (_a = prev === null || prev === void 0 ? void 0 : prev.travelDistance) !== null && _a !== void 0 ? _a : 0;
3161
- // Cap distance at spacing threshold
3162
- const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
3163
- // Max distance bonus is 1 * `distance_multiplier` at single_spacing_threshold
3164
- let distanceBonus = Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.95) *
3165
- this.DISTANCE_MULTIPLIER;
3166
- if (mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3167
- distanceBonus = 0;
3108
+ result = Math.pow(smallDistNerf * result, 2);
3109
+ // Additional bonus for Hidden due to there being no approach circles.
3110
+ if (mods.some((m) => m instanceof osuBase.ModHidden)) {
3111
+ result *= 1 + this.hiddenBonus;
3168
3112
  }
3169
- // Base difficulty with all bonuses
3170
- const difficulty = ((1 + speedBonus + distanceBonus) * 1000) / strainTime;
3171
- // Apply penalty if there's doubletappable doubles
3172
- return difficulty * doubletapness;
3113
+ // Nerf patterns with repeated angles.
3114
+ result *=
3115
+ this.minAngleMultiplier +
3116
+ (1 - this.minAngleMultiplier) / (angleRepeatCount + 1);
3117
+ let sliderBonus = 0;
3118
+ if (current.object instanceof osuBase.Slider) {
3119
+ // Invert the scaling factor to determine the true travel distance independent of circle size.
3120
+ const pixelTravelDistance = current.object.lazyTravelDistance / scalingFactor;
3121
+ // Reward sliders based on velocity.
3122
+ sliderBonus = Math.pow(Math.max(0, pixelTravelDistance / current.travelTime - this.minVelocity), 0.5);
3123
+ // Longer sliders require more memorization.
3124
+ sliderBonus *= pixelTravelDistance;
3125
+ // Nerf sliders with repeats, as less memorization is required.
3126
+ if (current.object.repeatCount > 0)
3127
+ sliderBonus /= current.object.repeatCount + 1;
3128
+ }
3129
+ result += sliderBonus * this.sliderMultiplier;
3130
+ return result;
3173
3131
  }
3174
3132
  }
3133
+ OsuFlashlightEvaluator.maxOpacityBonus = 0.4;
3134
+ OsuFlashlightEvaluator.hiddenBonus = 0.2;
3135
+ OsuFlashlightEvaluator.minVelocity = 0.5;
3136
+ OsuFlashlightEvaluator.sliderMultiplier = 1.3;
3137
+ OsuFlashlightEvaluator.minAngleMultiplier = 0.2;
3138
+
3175
3139
  /**
3176
- * Spacing threshold for a single hitobject spacing.
3177
- *
3178
- * About 1.25 circles distance between hitobject centers.
3140
+ * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
3179
3141
  */
3180
- OsuSpeedEvaluator.SINGLE_SPACING_THRESHOLD = 125;
3181
- // ~200 1/4 BPM streams
3182
- OsuSpeedEvaluator.minSpeedBonus = 75;
3183
- OsuSpeedEvaluator.DISTANCE_MULTIPLIER = 0.9;
3142
+ class OsuFlashlight extends OsuSkill {
3143
+ constructor() {
3144
+ super(...arguments);
3145
+ this.strainDecayBase = 0.15;
3146
+ this.reducedSectionCount = 0;
3147
+ this.reducedSectionBaseline = 1;
3148
+ this.decayWeight = 1;
3149
+ this.currentFlashlightStrain = 0;
3150
+ this.skillMultiplier = 0.05512;
3151
+ }
3152
+ difficultyValue() {
3153
+ return this.strainPeaks.reduce((a, b) => a + b, 0);
3154
+ }
3155
+ strainValueAt(current) {
3156
+ this.currentFlashlightStrain *= this.strainDecay(current.deltaTime);
3157
+ this.currentFlashlightStrain +=
3158
+ OsuFlashlightEvaluator.evaluateDifficultyOf(current, this.mods) *
3159
+ this.skillMultiplier;
3160
+ return this.currentFlashlightStrain;
3161
+ }
3162
+ calculateInitialStrain(time, current) {
3163
+ var _a, _b;
3164
+ return (this.currentFlashlightStrain *
3165
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
3166
+ }
3167
+ saveToHitObject(current) {
3168
+ current.flashlightStrain = this.currentFlashlightStrain;
3169
+ }
3170
+ }
3184
3171
 
3185
3172
  /**
3186
3173
  * An evaluator for calculating osu!standard Rhythm skill.
@@ -3330,6 +3317,64 @@ OsuRhythmEvaluator.historyObjectsMax = 32;
3330
3317
  OsuRhythmEvaluator.rhythmOverallMultiplier = 0.95;
3331
3318
  OsuRhythmEvaluator.rhythmRatioMultiplier = 12;
3332
3319
 
3320
+ /**
3321
+ * An evaluator for calculating osu!standard speed skill.
3322
+ */
3323
+ class OsuSpeedEvaluator {
3324
+ /**
3325
+ * Evaluates the difficulty of tapping the current object, based on:
3326
+ *
3327
+ * - time between pressing the previous and current object,
3328
+ * - distance between those objects,
3329
+ * - and how easily they can be cheesed.
3330
+ *
3331
+ * @param current The current object.
3332
+ * @param mods The mods applied.
3333
+ */
3334
+ static evaluateDifficultyOf(current, mods) {
3335
+ var _a;
3336
+ if (current.object instanceof osuBase.Spinner) {
3337
+ return 0;
3338
+ }
3339
+ const prev = current.previous(0);
3340
+ let strainTime = current.strainTime;
3341
+ // Nerf doubletappable doubles.
3342
+ const doubletapness = 1 - current.doubletapness;
3343
+ // Cap deltatime to the OD 300 hitwindow.
3344
+ // 0.93 is derived from making sure 260 BPM 1/4 OD8 streams aren't nerfed harshly, whilst 0.92 limits the effect of the cap.
3345
+ strainTime /= osuBase.MathUtils.clamp(strainTime / current.fullGreatWindow / 0.93, 0.92, 1);
3346
+ // speedBonus will be 0.0 for BPM < 200
3347
+ let speedBonus = 0;
3348
+ // Add additional scaling bonus for streams/bursts higher than 200bpm
3349
+ if (strainTime < this.minSpeedBonus) {
3350
+ speedBonus =
3351
+ 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
3352
+ }
3353
+ const travelDistance = (_a = prev === null || prev === void 0 ? void 0 : prev.travelDistance) !== null && _a !== void 0 ? _a : 0;
3354
+ // Cap distance at spacing threshold
3355
+ const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
3356
+ // Max distance bonus is 1 * `distance_multiplier` at single_spacing_threshold
3357
+ let distanceBonus = Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.95) *
3358
+ this.DISTANCE_MULTIPLIER;
3359
+ if (mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3360
+ distanceBonus = 0;
3361
+ }
3362
+ // Base difficulty with all bonuses
3363
+ const difficulty = ((1 + speedBonus + distanceBonus) * 1000) / strainTime;
3364
+ // Apply penalty if there's doubletappable doubles
3365
+ return difficulty * doubletapness;
3366
+ }
3367
+ }
3368
+ /**
3369
+ * Spacing threshold for a single hitobject spacing.
3370
+ *
3371
+ * About 1.25 circles distance between hitobject centers.
3372
+ */
3373
+ OsuSpeedEvaluator.SINGLE_SPACING_THRESHOLD = 125;
3374
+ // ~200 1/4 BPM streams
3375
+ OsuSpeedEvaluator.minSpeedBonus = 75;
3376
+ OsuSpeedEvaluator.DISTANCE_MULTIPLIER = 0.9;
3377
+
3333
3378
  /**
3334
3379
  * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
3335
3380
  */
@@ -3344,6 +3389,19 @@ class OsuSpeed extends OsuSkill {
3344
3389
  this.currentRhythm = 0;
3345
3390
  this.skillMultiplier = 1.46;
3346
3391
  }
3392
+ /**
3393
+ * The amount of notes that are relevant to the difficulty.
3394
+ */
3395
+ relevantNoteCount() {
3396
+ if (this._objectStrains.length === 0) {
3397
+ return 0;
3398
+ }
3399
+ const maxStrain = osuBase.MathUtils.max(this._objectStrains);
3400
+ if (maxStrain === 0) {
3401
+ return 0;
3402
+ }
3403
+ return this._objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
3404
+ }
3347
3405
  /**
3348
3406
  * @param current The hitobject to calculate.
3349
3407
  */
@@ -3372,360 +3430,136 @@ class OsuSpeed extends OsuSkill {
3372
3430
  }
3373
3431
  }
3374
3432
 
3375
- /**
3376
- * An evaluator for calculating osu!standard Flashlight skill.
3377
- */
3378
- class OsuFlashlightEvaluator {
3379
- /**
3380
- * Evaluates the difficulty of memorizing and hitting the current object, based on:
3381
- *
3382
- * - distance between a number of previous objects and the current object,
3383
- * - the visual opacity of the current object,
3384
- * - the angle made by the current object,
3385
- * - length and speed of the current object (for sliders),
3386
- * - and whether Hidden mod is enabled.
3387
- *
3388
- * @param current The current object.
3389
- * @param mods The mods used.
3390
- */
3391
- static evaluateDifficultyOf(current, mods) {
3392
- if (current.object instanceof osuBase.Spinner) {
3393
- return 0;
3394
- }
3395
- const scalingFactor = 52 / current.object.radius;
3396
- let smallDistNerf = 1;
3397
- let cumulativeStrainTime = 0;
3398
- let result = 0;
3399
- let last = current;
3400
- let angleRepeatCount = 0;
3401
- for (let i = 0; i < Math.min(current.index, 10); ++i) {
3402
- const currentObject = current.previous(i);
3403
- cumulativeStrainTime += last.strainTime;
3404
- if (!(currentObject.object instanceof osuBase.Spinner)) {
3405
- const jumpDistance = current.object
3406
- .getStackedPosition(osuBase.Modes.osu)
3407
- .subtract(currentObject.object.getStackedEndPosition(osuBase.Modes.osu)).length;
3408
- // We want to nerf objects that can be easily seen within the Flashlight circle radius.
3409
- if (i === 0) {
3410
- smallDistNerf = Math.min(1, jumpDistance / 75);
3411
- }
3412
- // We also want to nerf stacks so that only the first object of the stack is accounted for.
3413
- const stackNerf = Math.min(1, currentObject.lazyJumpDistance / scalingFactor / 25);
3414
- // Bonus based on how visible the object is.
3415
- const opacityBonus = 1 +
3416
- this.maxOpacityBonus *
3417
- (1 -
3418
- current.opacityAt(currentObject.object.startTime, mods));
3419
- result +=
3420
- (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
3421
- cumulativeStrainTime;
3422
- if (currentObject.angle !== null && current.angle !== null) {
3423
- // Objects further back in time should count less for the nerf.
3424
- if (Math.abs(currentObject.angle - current.angle) < 0.02) {
3425
- angleRepeatCount += Math.max(0, 1 - 0.1 * i);
3426
- }
3427
- }
3428
- }
3429
- last = currentObject;
3430
- }
3431
- result = Math.pow(smallDistNerf * result, 2);
3432
- // Additional bonus for Hidden due to there being no approach circles.
3433
- if (mods.some((m) => m instanceof osuBase.ModHidden)) {
3434
- result *= 1 + this.hiddenBonus;
3435
- }
3436
- // Nerf patterns with repeated angles.
3437
- result *=
3438
- this.minAngleMultiplier +
3439
- (1 - this.minAngleMultiplier) / (angleRepeatCount + 1);
3440
- let sliderBonus = 0;
3441
- if (current.object instanceof osuBase.Slider) {
3442
- // Invert the scaling factor to determine the true travel distance independent of circle size.
3443
- const pixelTravelDistance = current.object.lazyTravelDistance / scalingFactor;
3444
- // Reward sliders based on velocity.
3445
- sliderBonus = Math.pow(Math.max(0, pixelTravelDistance / current.travelTime - this.minVelocity), 0.5);
3446
- // Longer sliders require more memorization.
3447
- sliderBonus *= pixelTravelDistance;
3448
- // Nerf sliders with repeats, as less memorization is required.
3449
- if (current.object.repeatCount > 0)
3450
- sliderBonus /= current.object.repeatCount + 1;
3451
- }
3452
- result += sliderBonus * this.sliderMultiplier;
3453
- return result;
3454
- }
3455
- }
3456
- OsuFlashlightEvaluator.maxOpacityBonus = 0.4;
3457
- OsuFlashlightEvaluator.hiddenBonus = 0.2;
3458
- OsuFlashlightEvaluator.minVelocity = 0.5;
3459
- OsuFlashlightEvaluator.sliderMultiplier = 1.3;
3460
- OsuFlashlightEvaluator.minAngleMultiplier = 0.2;
3461
-
3462
- /**
3463
- * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
3464
- */
3465
- class OsuFlashlight extends OsuSkill {
3466
- constructor() {
3467
- super(...arguments);
3468
- this.strainDecayBase = 0.15;
3469
- this.reducedSectionCount = 0;
3470
- this.reducedSectionBaseline = 1;
3471
- this.decayWeight = 1;
3472
- this.currentFlashlightStrain = 0;
3473
- this.skillMultiplier = 0.05512;
3474
- }
3475
- difficultyValue() {
3476
- return this.strainPeaks.reduce((a, b) => a + b, 0);
3477
- }
3478
- strainValueAt(current) {
3479
- this.currentFlashlightStrain *= this.strainDecay(current.deltaTime);
3480
- this.currentFlashlightStrain +=
3481
- OsuFlashlightEvaluator.evaluateDifficultyOf(current, this.mods) *
3482
- this.skillMultiplier;
3483
- return this.currentFlashlightStrain;
3484
- }
3485
- calculateInitialStrain(time, current) {
3486
- var _a, _b;
3487
- return (this.currentFlashlightStrain *
3488
- this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
3489
- }
3490
- saveToHitObject(current) {
3491
- current.flashlightStrain = this.currentFlashlightStrain;
3492
- }
3493
- }
3494
-
3495
3433
  /**
3496
3434
  * A difficulty calculator for osu!standard gamemode.
3497
3435
  */
3498
3436
  class OsuDifficultyCalculator extends DifficultyCalculator {
3499
3437
  constructor() {
3500
- super(...arguments);
3501
- this.attributes = {
3502
- speedDifficulty: 0,
3503
- mods: [],
3504
- starRating: 0,
3505
- maxCombo: 0,
3506
- aimDifficulty: 0,
3507
- flashlightDifficulty: 0,
3508
- speedNoteCount: 0,
3509
- sliderFactor: 0,
3510
- clockRate: 1,
3511
- approachRate: 0,
3512
- overallDifficulty: 0,
3513
- hitCircleCount: 0,
3514
- sliderCount: 0,
3515
- spinnerCount: 0,
3516
- aimDifficultSliderCount: 0,
3517
- aimDifficultStrainCount: 0,
3518
- speedDifficultStrainCount: 0,
3519
- };
3438
+ super();
3520
3439
  this.difficultyMultiplier = 0.0675;
3521
- this.mode = osuBase.Modes.osu;
3522
- }
3523
- /**
3524
- * The aim star rating of the beatmap.
3525
- */
3526
- get aim() {
3527
- return this.attributes.aimDifficulty;
3528
- }
3529
- /**
3530
- * The speed star rating of the beatmap.
3531
- */
3532
- get speed() {
3533
- return this.attributes.speedDifficulty;
3534
- }
3535
- /**
3536
- * The flashlight star rating of the beatmap.
3537
- */
3538
- get flashlight() {
3539
- return this.attributes.flashlightDifficulty;
3540
- }
3541
- get cacheableAttributes() {
3542
- return Object.assign(Object.assign({}, this.attributes), { mods: osuBase.ModUtil.modsToOsuString(this.attributes.mods) });
3543
- }
3544
- /**
3545
- * Calculates the aim star rating of the beatmap and stores it in this instance.
3546
- */
3547
- calculateAim() {
3548
- if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3549
- this.attributes.aimDifficulty = 0;
3550
- return;
3551
- }
3552
- const aimSkill = new OsuAim(this.mods, true);
3553
- const aimSkillWithoutSliders = new OsuAim(this.mods, false);
3554
- this.calculateSkills(aimSkill, aimSkillWithoutSliders);
3555
- this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
3556
- }
3557
- /**
3558
- * Calculates the speed star rating of the beatmap and stores it in this instance.
3559
- */
3560
- calculateSpeed() {
3561
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3562
- this.attributes.speedDifficulty = 0;
3563
- return;
3564
- }
3565
- const speedSkill = new OsuSpeed(this.mods);
3566
- this.calculateSkills(speedSkill);
3567
- this.postCalculateSpeed(speedSkill);
3568
- }
3569
- /**
3570
- * Calculates the flashlight star rating of the beatmap and stores it in this instance.
3571
- */
3572
- calculateFlashlight() {
3573
- if (!this.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
3574
- this.attributes.flashlightDifficulty = 0;
3575
- return;
3576
- }
3577
- const flashlightSkill = new OsuFlashlight(this.mods);
3578
- this.calculateSkills(flashlightSkill);
3579
- this.postCalculateFlashlight(flashlightSkill);
3580
- }
3581
- calculateTotal() {
3582
- const aimPerformanceValue = this.basePerformanceValue(this.aim);
3583
- const speedPerformanceValue = this.basePerformanceValue(this.speed);
3584
- let flashlightPerformanceValue = 0;
3585
- if (this.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
3586
- flashlightPerformanceValue = Math.pow(this.flashlight, 2) * 25;
3587
- }
3440
+ this.difficultyAdjustmentMods.add(osuBase.ModTouchDevice);
3441
+ }
3442
+ retainDifficultyAdjustmentMods(mods) {
3443
+ return mods.filter((mod) => mod.isApplicableToOsu() &&
3444
+ this.difficultyAdjustmentMods.has(mod.constructor) &&
3445
+ mod.isOsuRelevant);
3446
+ }
3447
+ createDifficultyAttributes(beatmap, skills) {
3448
+ const attributes = new OsuDifficultyAttributes();
3449
+ attributes.mods = beatmap.mods.slice();
3450
+ attributes.maxCombo = beatmap.maxCombo;
3451
+ attributes.clockRate = beatmap.speedMultiplier;
3452
+ attributes.hitCircleCount = beatmap.hitObjects.circles;
3453
+ attributes.sliderCount = beatmap.hitObjects.sliders;
3454
+ attributes.spinnerCount = beatmap.hitObjects.spinners;
3455
+ this.populateAimAttributes(attributes, skills);
3456
+ this.populateSpeedAttributes(attributes, skills);
3457
+ this.populateFlashlightAttributes(attributes, skills);
3458
+ if (attributes.mods.some((m) => m instanceof osuBase.ModRelax)) {
3459
+ attributes.aimDifficulty *= 0.9;
3460
+ attributes.speedDifficulty = 0;
3461
+ attributes.flashlightDifficulty *= 0.7;
3462
+ }
3463
+ else if (attributes.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3464
+ attributes.aimDifficulty = 0;
3465
+ attributes.speedDifficulty *= 0.5;
3466
+ attributes.flashlightDifficulty *= 0.4;
3467
+ }
3468
+ const aimPerformanceValue = this.basePerformanceValue(attributes.aimDifficulty);
3469
+ const speedPerformanceValue = this.basePerformanceValue(attributes.speedDifficulty);
3470
+ const flashlightPerformanceValue = Math.pow(attributes.flashlightDifficulty, 2) * 25;
3588
3471
  const basePerformanceValue = Math.pow(Math.pow(aimPerformanceValue, 1.1) +
3589
3472
  Math.pow(speedPerformanceValue, 1.1) +
3590
3473
  Math.pow(flashlightPerformanceValue, 1.1), 1 / 1.1);
3591
3474
  if (basePerformanceValue > 1e-5) {
3592
3475
  // Document for formula derivation:
3593
3476
  // https://docs.google.com/document/d/10DZGYYSsT_yjz2Mtp6yIJld0Rqx4E-vVHupCqiM4TNI/edit
3594
- this.attributes.starRating =
3477
+ attributes.starRating =
3595
3478
  Math.cbrt(1.15) *
3596
3479
  0.027 *
3597
3480
  (Math.cbrt((100000 / Math.pow(2, 1 / 1.1)) * basePerformanceValue) +
3598
3481
  4);
3599
3482
  }
3600
3483
  else {
3601
- this.attributes.starRating = 0;
3484
+ attributes.starRating = 0;
3602
3485
  }
3486
+ const preempt = osuBase.BeatmapDifficulty.difficultyRange(beatmap.difficulty.ar, osuBase.HitObject.preemptMax, osuBase.HitObject.preemptMid, osuBase.HitObject.preemptMin) / attributes.clockRate;
3487
+ attributes.approachRate = osuBase.BeatmapDifficulty.inverseDifficultyRange(preempt, osuBase.HitObject.preemptMax, osuBase.HitObject.preemptMid, osuBase.HitObject.preemptMin);
3488
+ const { greatWindow } = new osuBase.OsuHitWindow(beatmap.difficulty.od);
3489
+ attributes.overallDifficulty = osuBase.OsuHitWindow.greatWindowToOD(greatWindow / attributes.clockRate);
3490
+ return attributes;
3603
3491
  }
3604
- calculateAll() {
3605
- const skills = this.createSkills();
3606
- this.calculateSkills(...skills);
3607
- const aimSkill = skills.find((s) => s instanceof OsuAim && s.withSliders);
3608
- const aimSkillWithoutSliders = skills.find((s) => s instanceof OsuAim && !s.withSliders);
3609
- const speedSkill = skills.find((s) => s instanceof OsuSpeed);
3610
- const flashlightSkill = skills.find((s) => s instanceof OsuFlashlight);
3611
- if (aimSkill && aimSkillWithoutSliders) {
3612
- this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
3613
- }
3614
- if (speedSkill) {
3615
- this.postCalculateSpeed(speedSkill);
3616
- }
3617
- if (flashlightSkill) {
3618
- this.postCalculateFlashlight(flashlightSkill);
3619
- }
3620
- this.calculateTotal();
3492
+ createPlayableBeatmap(beatmap, mods) {
3493
+ return beatmap.createOsuPlayableBeatmap(mods);
3621
3494
  }
3622
- toString() {
3623
- return (this.total.toFixed(2) +
3624
- " stars (" +
3625
- this.aim.toFixed(2) +
3626
- " aim, " +
3627
- this.speed.toFixed(2) +
3628
- " speed, " +
3629
- this.flashlight.toFixed(2) +
3630
- " flashlight)");
3631
- }
3632
- generateDifficultyHitObjects(beatmap, clockRate) {
3495
+ createDifficultyHitObjects(beatmap) {
3633
3496
  var _a, _b;
3497
+ const clockRate = beatmap.speedMultiplier;
3634
3498
  const difficultyObjects = [];
3635
3499
  const { objects } = beatmap.hitObjects;
3636
- for (let i = 0; i < objects.length; ++i) {
3637
- const difficultyObject = new OsuDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, clockRate);
3500
+ for (let i = 1; i < objects.length; ++i) {
3501
+ const difficultyObject = new OsuDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, clockRate, i - 1);
3638
3502
  difficultyObject.computeProperties(clockRate, objects);
3639
3503
  difficultyObjects.push(difficultyObject);
3640
3504
  }
3641
3505
  return difficultyObjects;
3642
3506
  }
3643
- createSkills() {
3507
+ createSkills(beatmap) {
3508
+ const { mods } = beatmap;
3644
3509
  const skills = [];
3645
- if (!this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3646
- skills.push(new OsuAim(this.mods, true));
3647
- skills.push(new OsuAim(this.mods, false));
3510
+ if (!mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3511
+ skills.push(new OsuAim(mods, true));
3512
+ skills.push(new OsuAim(mods, false));
3648
3513
  }
3649
- if (!this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3650
- skills.push(new OsuSpeed(this.mods));
3514
+ if (!mods.some((m) => m instanceof osuBase.ModRelax)) {
3515
+ skills.push(new OsuSpeed(mods));
3651
3516
  }
3652
- if (this.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
3653
- skills.push(new OsuFlashlight(this.mods));
3517
+ if (mods.some((m) => m instanceof osuBase.ModFlashlight)) {
3518
+ skills.push(new OsuFlashlight(mods));
3654
3519
  }
3655
3520
  return skills;
3656
3521
  }
3657
- populateDifficultyAttributes(beatmap, clockRate) {
3658
- super.populateDifficultyAttributes(beatmap, clockRate);
3659
- const preempt = osuBase.BeatmapDifficulty.difficultyRange(beatmap.difficulty.ar, osuBase.HitObject.preemptMax, osuBase.HitObject.preemptMid, osuBase.HitObject.preemptMin) / clockRate;
3660
- this.attributes.approachRate = osuBase.BeatmapDifficulty.inverseDifficultyRange(preempt, osuBase.HitObject.preemptMax, osuBase.HitObject.preemptMid, osuBase.HitObject.preemptMin);
3661
- }
3662
- /**
3663
- * Called after aim skill calculation.
3664
- *
3665
- * @param aimSkill The aim skill that considers sliders.
3666
- * @param aimSkillWithoutSliders The aim skill that doesn't consider sliders.
3667
- */
3668
- postCalculateAim(aimSkill, aimSkillWithoutSliders) {
3669
- this.strainPeaks.aimWithSliders = aimSkill.strainPeaks;
3670
- this.strainPeaks.aimWithoutSliders = aimSkillWithoutSliders.strainPeaks;
3671
- this.attributes.aimDifficulty = this.starValue(aimSkill.difficultyValue());
3672
- if (this.aim) {
3673
- this.attributes.sliderFactor =
3674
- this.starValue(aimSkillWithoutSliders.difficultyValue()) /
3675
- this.aim;
3676
- }
3677
- if (this.mods.some((m) => m instanceof osuBase.ModTouchDevice)) {
3678
- this.attributes.aimDifficulty = Math.pow(this.aim, 0.8);
3522
+ createStrainPeakSkills(beatmap) {
3523
+ const { mods } = beatmap;
3524
+ return [
3525
+ new OsuAim(mods, true),
3526
+ new OsuAim(mods, false),
3527
+ new OsuSpeed(mods),
3528
+ new OsuFlashlight(mods),
3529
+ ];
3530
+ }
3531
+ populateAimAttributes(attributes, skills) {
3532
+ const aim = skills.find((s) => s instanceof OsuAim && s.withSliders);
3533
+ const aimNoSlider = skills.find((s) => s instanceof OsuAim && !s.withSliders);
3534
+ if (!aim || !aimNoSlider) {
3535
+ return;
3679
3536
  }
3680
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3681
- this.attributes.aimDifficulty *= 0.9;
3537
+ attributes.aimDifficulty = this.calculateRating(aim);
3538
+ attributes.aimDifficultSliderCount = aim.countDifficultSliders();
3539
+ attributes.aimDifficultStrainCount = aim.countDifficultStrains();
3540
+ if (attributes.aimDifficulty > 0) {
3541
+ attributes.sliderFactor =
3542
+ this.calculateRating(aimNoSlider) / attributes.aimDifficulty;
3682
3543
  }
3683
- else if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3684
- this.attributes.aimDifficulty = 0;
3544
+ else {
3545
+ attributes.sliderFactor = 1;
3685
3546
  }
3686
- this.attributes.aimDifficultStrainCount =
3687
- aimSkill.countDifficultStrains();
3688
- this.attributes.aimDifficultSliderCount =
3689
- aimSkill.countDifficultSliders();
3690
3547
  }
3691
- /**
3692
- * Called after speed skill calculation.
3693
- *
3694
- * @param speedSkill The speed skill.
3695
- */
3696
- postCalculateSpeed(speedSkill) {
3697
- this.strainPeaks.speed = speedSkill.strainPeaks;
3698
- this.attributes.speedDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
3699
- ? 0
3700
- : this.starValue(speedSkill.difficultyValue());
3701
- if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3702
- this.attributes.speedDifficulty *= 0.5;
3703
- }
3704
- this.attributes.speedDifficultStrainCount =
3705
- speedSkill.countDifficultStrains();
3706
- const objectStrains = this.objects.map((v) => v.speedStrain);
3707
- const maxStrain = osuBase.MathUtils.max(objectStrains);
3708
- if (maxStrain) {
3709
- this.attributes.speedNoteCount = objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
3548
+ populateSpeedAttributes(attributes, skills) {
3549
+ const speed = skills.find((s) => s instanceof OsuSpeed);
3550
+ if (!speed) {
3551
+ return;
3710
3552
  }
3553
+ attributes.speedDifficulty = this.calculateRating(speed);
3554
+ attributes.speedNoteCount = speed.relevantNoteCount();
3555
+ attributes.speedDifficultStrainCount = speed.countDifficultStrains();
3711
3556
  }
3712
- /**
3713
- * Called after flashlight skill calculation.
3714
- *
3715
- * @param flashlightSkill The flashlight skill.
3716
- */
3717
- postCalculateFlashlight(flashlightSkill) {
3718
- this.strainPeaks.flashlight = flashlightSkill.strainPeaks;
3719
- this.attributes.flashlightDifficulty = this.starValue(flashlightSkill.difficultyValue());
3720
- if (this.mods.some((m) => m instanceof osuBase.ModTouchDevice)) {
3721
- this.attributes.flashlightDifficulty = Math.pow(this.flashlight, 0.8);
3722
- }
3723
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3724
- this.attributes.flashlightDifficulty *= 0.7;
3725
- }
3726
- else if (this.mods.some((m) => m instanceof osuBase.ModAutopilot)) {
3727
- this.attributes.flashlightDifficulty *= 0.4;
3557
+ populateFlashlightAttributes(attributes, skills) {
3558
+ const flashlight = skills.find((s) => s instanceof OsuFlashlight);
3559
+ if (!flashlight) {
3560
+ return;
3728
3561
  }
3562
+ attributes.flashlightDifficulty = this.calculateRating(flashlight);
3729
3563
  }
3730
3564
  }
3731
3565
 
@@ -4059,10 +3893,12 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
4059
3893
  }
4060
3894
  }
4061
3895
 
3896
+ exports.DifficultyAttributes = DifficultyAttributes;
4062
3897
  exports.DifficultyCalculator = DifficultyCalculator;
4063
3898
  exports.DifficultyHitObject = DifficultyHitObject;
4064
3899
  exports.DroidAim = DroidAim;
4065
3900
  exports.DroidAimEvaluator = DroidAimEvaluator;
3901
+ exports.DroidDifficultyAttributes = DroidDifficultyAttributes;
4066
3902
  exports.DroidDifficultyCalculator = DroidDifficultyCalculator;
4067
3903
  exports.DroidDifficultyHitObject = DroidDifficultyHitObject;
4068
3904
  exports.DroidFlashlight = DroidFlashlight;
@@ -4074,8 +3910,10 @@ exports.DroidTap = DroidTap;
4074
3910
  exports.DroidTapEvaluator = DroidTapEvaluator;
4075
3911
  exports.DroidVisual = DroidVisual;
4076
3912
  exports.DroidVisualEvaluator = DroidVisualEvaluator;
3913
+ exports.ExtendedDroidDifficultyAttributes = ExtendedDroidDifficultyAttributes;
4077
3914
  exports.OsuAim = OsuAim;
4078
3915
  exports.OsuAimEvaluator = OsuAimEvaluator;
3916
+ exports.OsuDifficultyAttributes = OsuDifficultyAttributes;
4079
3917
  exports.OsuDifficultyCalculator = OsuDifficultyCalculator;
4080
3918
  exports.OsuDifficultyHitObject = OsuDifficultyHitObject;
4081
3919
  exports.OsuFlashlight = OsuFlashlight;