@rian8337/osu-rebalance-difficulty-calculator 4.0.0-beta.2 → 4.0.0-beta.20

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.
package/dist/index.js CHANGED
@@ -8,10 +8,6 @@ var osuBase = require('@rian8337/osu-base');
8
8
  * This class should be considered an "evaluating" class and not persisted.
9
9
  */
10
10
  class AimEvaluator {
11
- static wideAngleMultiplier = 1.5;
12
- static acuteAngleMultiplier = 1.95;
13
- static sliderMultiplier = 1.35;
14
- static velocityChangeMultiplier = 0.75;
15
11
  /**
16
12
  * Calculates the bonus of wide angles.
17
13
  */
@@ -27,154 +23,225 @@ class AimEvaluator {
27
23
  return 1 - this.calculateWideAngleBonus(angle);
28
24
  }
29
25
  }
26
+ AimEvaluator.wideAngleMultiplier = 1.5;
27
+ AimEvaluator.acuteAngleMultiplier = 1.95;
28
+ AimEvaluator.sliderMultiplier = 1.35;
29
+ AimEvaluator.velocityChangeMultiplier = 0.75;
30
30
 
31
31
  /**
32
- * Represents an osu!standard hit object with difficulty calculation values.
32
+ * The base of a difficulty calculator.
33
33
  */
34
- class DifficultyHitObject {
35
- /**
36
- * The underlying hitobject.
37
- */
38
- object;
39
- /**
40
- * The index of this hitobject in the list of all hitobjects.
41
- *
42
- * This is one less than the actual index of the hitobject in the beatmap.
43
- */
44
- index = 0;
45
- /**
46
- * The preempt time of the hitobject.
47
- */
48
- baseTimePreempt = 600;
49
- /**
50
- * Adjusted preempt time of the hitobject, taking speed multiplier into account.
51
- */
52
- timePreempt = 600;
53
- /**
54
- * The fade in time of the hitobject.
55
- */
56
- timeFadeIn = 400;
57
- /**
58
- * The aim strain generated by the hitobject if sliders are considered.
59
- */
60
- aimStrainWithSliders = 0;
61
- /**
62
- * The aim strain generated by the hitobject if sliders are not considered.
63
- */
64
- aimStrainWithoutSliders = 0;
65
- /**
66
- * The tap strain generated by the hitobject.
67
- *
68
- * This is also used for osu!standard as opposed to "speed strain".
69
- */
70
- tapStrain = 0;
71
- /**
72
- * The tap strain generated by the hitobject if `strainTime` isn't modified by
73
- * OD. This is used in three-finger detection.
74
- */
75
- originalTapStrain = 0;
76
- /**
77
- * The rhythm multiplier generated by the hitobject. This is used to alter tap strain.
78
- */
79
- rhythmMultiplier = 0;
80
- /**
81
- * The rhythm strain generated by the hitobject.
82
- */
83
- rhythmStrain = 0;
84
- /**
85
- * The flashlight strain generated by the hitobject if sliders are considered.
86
- */
87
- flashlightStrainWithSliders = 0;
88
- /**
89
- * The flashlight strain generated by the hitobject if sliders are not considered.
90
- */
91
- flashlightStrainWithoutSliders = 0;
92
- /**
93
- * The visual strain generated by the hitobject if sliders are considered.
94
- */
95
- visualStrainWithSliders = 0;
34
+ class DifficultyCalculator {
96
35
  /**
97
- * The visual strain generated by the hitobject if sliders are not considered.
36
+ * The total star rating of the beatmap.
98
37
  */
99
- visualStrainWithoutSliders = 0;
38
+ get total() {
39
+ return this.attributes.starRating;
40
+ }
100
41
  /**
101
- * The normalized distance from the "lazy" end position of the previous hitobject to the start position of this hitobject.
42
+ * Constructs a new instance of the calculator.
102
43
  *
103
- * The "lazy" end position is the position at which the cursor ends up if the previous hitobject is followed with as minimal movement as possible (i.e. on the edge of slider follow circles).
44
+ * @param beatmap The beatmap to calculate. This beatmap will be deep-cloned to prevent reference changes.
104
45
  */
105
- lazyJumpDistance = 0;
46
+ constructor(beatmap) {
47
+ var _a;
48
+ /**
49
+ * The difficulty objects of the beatmap.
50
+ */
51
+ this.objects = [];
52
+ /**
53
+ * The modifications applied.
54
+ */
55
+ this.mods = [];
56
+ /**
57
+ * The strain peaks of various calculated difficulties.
58
+ */
59
+ this.strainPeaks = {
60
+ aimWithSliders: [],
61
+ aimWithoutSliders: [],
62
+ speed: [],
63
+ flashlight: [],
64
+ };
65
+ this.beatmap = beatmap;
66
+ this.difficultyStatistics = {
67
+ circleSize: beatmap.difficulty.cs,
68
+ approachRate: (_a = beatmap.difficulty.ar) !== null && _a !== void 0 ? _a : beatmap.difficulty.od,
69
+ overallDifficulty: beatmap.difficulty.od,
70
+ healthDrain: beatmap.difficulty.hp,
71
+ overallSpeedMultiplier: 1,
72
+ };
73
+ }
106
74
  /**
107
- * The normalized shortest distance to consider for a jump between the previous hitobject and this hitobject.
75
+ * Calculates the star rating of the specified beatmap.
108
76
  *
109
- * This is bounded from above by `lazyJumpDistance`, and is smaller than the former if a more natural path is able to be taken through the previous hitobject.
77
+ * The beatmap is analyzed in chunks of `sectionLength` duration.
78
+ * For each chunk the highest hitobject strains are added to
79
+ * a list which is then collapsed into a weighted sum, much
80
+ * like scores are weighted on a user's profile.
110
81
  *
111
- * Suppose a linear slider - circle pattern. Following the slider lazily (see: `lazyJumpDistance`) will result in underestimating the true end position of the slider as being closer towards the start position.
112
- * As a result, `lazyJumpDistance` overestimates the jump distance because the player is able to take a more natural path by following through the slider to its end,
113
- * such that the jump is felt as only starting from the slider's true end position.
82
+ * For subsequent chunks, the initial max strain is calculated
83
+ * by decaying the previous hitobject's strain until the
84
+ * beginning of the new chunk.
114
85
  *
115
- * Now consider a slider - circle pattern where the circle is stacked along the path inside the slider.
116
- * In this case, the lazy end position correctly estimates the true end position of the slider and provides the more natural movement path.
117
- */
118
- minimumJumpDistance = 0;
119
- /**
120
- * The time taken to travel through `minimumJumpDistance`, with a minimum value of 25ms.
121
- */
122
- minimumJumpTime = 0;
123
- /**
124
- * The normalized distance between the start and end position of this hitobject.
125
- */
126
- travelDistance = 0;
127
- /**
128
- * The time taken to travel through `travelDistance`, with a minimum value of 25ms for sliders.
86
+ * @param options Options for the difficulty calculation.
87
+ * @returns The current instance.
129
88
  */
130
- travelTime = 0;
89
+ calculate(options) {
90
+ var _a;
91
+ this.mods = (_a = options === null || options === void 0 ? void 0 : options.mods) !== null && _a !== void 0 ? _a : [];
92
+ const converted = new osuBase.BeatmapConverter(this.beatmap).convert({
93
+ mode: this.mode,
94
+ mods: this.mods,
95
+ customSpeedMultiplier: options === null || options === void 0 ? void 0 : options.customSpeedMultiplier,
96
+ });
97
+ this.difficultyStatistics = Object.seal(this.computeDifficultyStatistics(options));
98
+ this.populateDifficultyAttributes();
99
+ this.objects.push(...this.generateDifficultyHitObjects(converted));
100
+ this.calculateAll();
101
+ return this;
102
+ }
131
103
  /**
132
- * Angle the player has to take to hit this hitobject.
104
+ * Calculates the skills provided.
133
105
  *
134
- * Calculated as the angle between the circles (current-2, current-1, current).
135
- */
136
- angle = null;
137
- /**
138
- * The amount of milliseconds elapsed between this hitobject and the last hitobject.
139
- */
140
- deltaTime = 0;
141
- /**
142
- * The amount of milliseconds elapsed since the start time of the previous hitobject, with a minimum of 25ms.
143
- */
144
- strainTime = 0;
145
- /**
146
- * Adjusted start time of the hitobject, taking speed multiplier into account.
147
- */
148
- startTime = 0;
149
- /**
150
- * Adjusted end time of the hitobject, taking speed multiplier into account.
106
+ * @param skills The skills to calculate.
151
107
  */
152
- endTime = 0;
108
+ calculateSkills(...skills) {
109
+ // The first object doesn't generate a strain, so we begin calculating from the second object.
110
+ for (const object of this.objects.slice(1)) {
111
+ for (const skill of skills) {
112
+ skill.process(object);
113
+ }
114
+ }
115
+ }
153
116
  /**
154
- * The note density of the hitobject.
117
+ * Populates the stored difficulty attributes with necessary data.
155
118
  */
156
- noteDensity = 1;
119
+ populateDifficultyAttributes() {
120
+ this.attributes.approachRate = this.difficultyStatistics.approachRate;
121
+ this.attributes.hitCircleCount = this.beatmap.hitObjects.circles;
122
+ this.attributes.maxCombo = this.beatmap.maxCombo;
123
+ this.attributes.mods = this.mods.slice();
124
+ this.attributes.overallDifficulty =
125
+ this.difficultyStatistics.overallDifficulty;
126
+ this.attributes.sliderCount = this.beatmap.hitObjects.sliders;
127
+ this.attributes.spinnerCount = this.beatmap.hitObjects.spinners;
128
+ this.attributes.clockRate =
129
+ this.difficultyStatistics.overallSpeedMultiplier;
130
+ }
157
131
  /**
158
- * The overlapping factor of the hitobject.
132
+ * Calculates the star rating value of a difficulty.
159
133
  *
160
- * This is used to scale visual skill.
161
- */
162
- overlappingFactor = 0;
163
- /**
164
- * Adjusted velocity of the hitobject, taking speed multiplier into account.
134
+ * @param difficulty The difficulty to calculate.
165
135
  */
166
- velocity = 0;
136
+ starValue(difficulty) {
137
+ return Math.sqrt(difficulty) * this.difficultyMultiplier;
138
+ }
167
139
  /**
168
- * Other hitobjects in the beatmap, including this hitobject.
140
+ * Calculates the base performance value of a difficulty rating.
141
+ *
142
+ * @param rating The difficulty rating.
169
143
  */
170
- hitObjects;
144
+ basePerformanceValue(rating) {
145
+ return Math.pow(5 * Math.max(1, rating / 0.0675) - 4, 3) / 100000;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Represents a hit object with difficulty calculation values.
151
+ */
152
+ class DifficultyHitObject {
171
153
  /**
154
+ * Note: You **must** call `computeProperties` at some point due to how TypeScript handles
155
+ * overridden properties (see [this](https://github.com/microsoft/TypeScript/issues/1617) GitHub issue).
156
+ *
172
157
  * @param object The underlying hitobject.
173
- * @param hitObjects All difficulty hitobjects in the processed beatmap.
174
- */
175
- constructor(object, hitObjects) {
158
+ * @param lastObject The hitobject before this hitobject.
159
+ * @param lastLastObject The hitobject before the last hitobject.
160
+ * @param difficultyHitObjects All difficulty hitobjects in the processed beatmap.
161
+ * @param clockRate The clock rate of the beatmap.
162
+ */
163
+ constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate) {
164
+ /**
165
+ * The aim strain generated by the hitobject if sliders are considered.
166
+ */
167
+ this.aimStrainWithSliders = 0;
168
+ /**
169
+ * The aim strain generated by the hitobject if sliders are not considered.
170
+ */
171
+ this.aimStrainWithoutSliders = 0;
172
+ /**
173
+ * The rhythm multiplier generated by the hitobject. This is used to alter tap strain.
174
+ */
175
+ this.rhythmMultiplier = 0;
176
+ /**
177
+ * The normalized distance from the "lazy" end position of the previous hitobject to the start position of this hitobject.
178
+ *
179
+ * The "lazy" end position is the position at which the cursor ends up if the previous hitobject is followed with as minimal movement as possible (i.e. on the edge of slider follow circles).
180
+ */
181
+ this.lazyJumpDistance = 0;
182
+ /**
183
+ * The normalized shortest distance to consider for a jump between the previous hitobject and this hitobject.
184
+ *
185
+ * This is bounded from above by `lazyJumpDistance`, and is smaller than the former if a more natural path is able to be taken through the previous hitobject.
186
+ *
187
+ * Suppose a linear slider - circle pattern. Following the slider lazily (see: `lazyJumpDistance`) will result in underestimating the true end position of the slider as being closer towards the start position.
188
+ * As a result, `lazyJumpDistance` overestimates the jump distance because the player is able to take a more natural path by following through the slider to its end,
189
+ * such that the jump is felt as only starting from the slider's true end position.
190
+ *
191
+ * Now consider a slider - circle pattern where the circle is stacked along the path inside the slider.
192
+ * In this case, the lazy end position correctly estimates the true end position of the slider and provides the more natural movement path.
193
+ */
194
+ this.minimumJumpDistance = 0;
195
+ /**
196
+ * The time taken to travel through `minimumJumpDistance`, with a minimum value of 25ms.
197
+ */
198
+ this.minimumJumpTime = 0;
199
+ /**
200
+ * The normalized distance between the start and end position of this hitobject.
201
+ */
202
+ this.travelDistance = 0;
203
+ /**
204
+ * The time taken to travel through `travelDistance`, with a minimum value of 25ms for sliders.
205
+ */
206
+ this.travelTime = 0;
207
+ /**
208
+ * Angle the player has to take to hit this hitobject.
209
+ *
210
+ * Calculated as the angle between the circles (current-2, current-1, current).
211
+ */
212
+ this.angle = null;
213
+ this.normalizedRadius = 50;
214
+ this.maximumSliderRadius = this.normalizedRadius * 2.4;
215
+ this.assumedSliderRadius = this.normalizedRadius * 1.8;
216
+ this.minDeltaTime = 25;
176
217
  this.object = object;
177
- this.hitObjects = hitObjects;
218
+ this.lastObject = lastObject;
219
+ this.lastLastObject = lastLastObject;
220
+ this.hitObjects = difficultyHitObjects;
221
+ this.index = difficultyHitObjects.length - 1;
222
+ // Capped to 25ms to prevent difficulty calculation breaking from simultaneous objects.
223
+ this.startTime = object.startTime / clockRate;
224
+ this.endTime = object.endTime / clockRate;
225
+ if (lastObject) {
226
+ this.deltaTime = this.startTime - lastObject.startTime / clockRate;
227
+ this.strainTime = Math.max(this.deltaTime, this.minDeltaTime);
228
+ }
229
+ else {
230
+ this.deltaTime = 0;
231
+ this.strainTime = 0;
232
+ }
233
+ }
234
+ /**
235
+ * Computes the properties of this hitobject.
236
+ *
237
+ * @param clockRate The clock rate of the beatmap.
238
+ * @param hitObjects The hitobjects in the beatmap.
239
+ */
240
+ computeProperties(clockRate,
241
+ // Required for `DroidDifficultyHitObject` override.
242
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
243
+ hitObjects) {
244
+ this.setDistances(clockRate);
178
245
  }
179
246
  /**
180
247
  * Gets the difficulty hitobject at a specific index with respect to the current
@@ -187,7 +254,8 @@ class DifficultyHitObject {
187
254
  * difficulty hitobject's index, `null` if the index is out of range.
188
255
  */
189
256
  previous(backwardsIndex) {
190
- return this.hitObjects[this.index - backwardsIndex] ?? null;
257
+ var _a;
258
+ return (_a = this.hitObjects[this.index - backwardsIndex]) !== null && _a !== void 0 ? _a : null;
191
259
  }
192
260
  /**
193
261
  * Gets the difficulty hitobject at a specific index with respect to the current
@@ -200,289 +268,105 @@ class DifficultyHitObject {
200
268
  * difficulty hitobject's index, `null` if the index is out of range.
201
269
  */
202
270
  next(forwardsIndex) {
203
- return this.hitObjects[this.index + forwardsIndex + 2] ?? null;
271
+ var _a;
272
+ return ((_a = this.hitObjects[this.index + forwardsIndex + 2]) !== null && _a !== void 0 ? _a : null);
204
273
  }
205
274
  /**
206
275
  * Calculates the opacity of the hitobject at a given time.
207
276
  *
208
277
  * @param time The time to calculate the hitobject's opacity at.
209
278
  * @param isHidden Whether Hidden mod is used.
210
- * @param mode The gamemode to calculate the opacity for.
211
279
  * @returns The opacity of the hitobject at the given time.
212
280
  */
213
- opacityAt(time, isHidden, mode) {
281
+ opacityAt(time, isHidden) {
214
282
  if (time > this.object.startTime) {
215
283
  // Consider a hitobject as being invisible when its start time is passed.
216
284
  // In reality the hitobject will be visible beyond its start time up until its hittable window has passed,
217
285
  // but this is an approximation and such a case is unlikely to be hit where this function is used.
218
286
  return 0;
219
287
  }
220
- const fadeInStartTime = this.object.startTime - this.baseTimePreempt;
221
- const fadeInDuration = this.timeFadeIn;
288
+ const fadeInStartTime = this.object.startTime - this.object.timePreempt;
289
+ const fadeInDuration = this.object.timeFadeIn;
222
290
  if (isHidden) {
223
291
  const fadeOutStartTime = fadeInStartTime + fadeInDuration;
224
- const fadeOutDuration = this.baseTimePreempt *
225
- (mode === osuBase.Modes.droid
226
- ? 0.35
227
- : osuBase.ModHidden.fadeOutDurationMultiplier);
292
+ const fadeOutDuration = this.object.timePreempt * osuBase.ModHidden.fadeOutDurationMultiplier;
228
293
  return Math.min(osuBase.MathUtils.clamp((time - fadeInStartTime) / fadeInDuration, 0, 1), 1 -
229
294
  osuBase.MathUtils.clamp((time - fadeOutStartTime) / fadeOutDuration, 0, 1));
230
295
  }
231
296
  return osuBase.MathUtils.clamp((time - fadeInStartTime) / fadeInDuration, 0, 1);
232
297
  }
233
- /**
234
- * Determines whether this hitobject is considered overlapping with the hitobject before it.
235
- *
236
- * Keep in mind that "overlapping" in this case is overlapping to the point where both hitobjects
237
- * can be hit with just a single tap in osu!droid.
238
- *
239
- * @param considerDistance Whether to consider the distance between both hitobjects.
240
- * @returns Whether the hitobject is considered overlapping.
241
- */
242
- isOverlapping(considerDistance) {
243
- if (this.object instanceof osuBase.Spinner) {
244
- return false;
245
- }
246
- const previous = this.previous(0);
247
- if (!previous || previous.object instanceof osuBase.Spinner) {
248
- return false;
249
- }
250
- if (this.deltaTime >= 5) {
251
- return false;
252
- }
253
- if (considerDistance) {
254
- const endPosition = this.object.getStackedPosition(osuBase.Modes.droid);
255
- let distance = previous.object
256
- .getStackedEndPosition(osuBase.Modes.droid)
257
- .getDistance(endPosition);
258
- if (previous.object instanceof osuBase.Slider &&
259
- previous.object.lazyEndPosition) {
260
- distance = Math.min(distance, previous.object.lazyEndPosition.getDistance(endPosition));
298
+ setDistances(clockRate) {
299
+ if (this.object instanceof osuBase.Slider) {
300
+ this.calculateSliderCursorPosition(this.object);
301
+ this.travelDistance = this.object.lazyTravelDistance;
302
+ // Bonus for repeat sliders until a better per nested object strain system can be achieved.
303
+ if (this.mode === osuBase.Modes.droid) {
304
+ this.travelDistance *= Math.pow(1 + this.object.repeatCount / 4, 1 / 4);
261
305
  }
262
- return distance <= 2 * this.object.getRadius(osuBase.Modes.droid);
306
+ else {
307
+ this.travelDistance *= Math.pow(1 + this.object.repeatCount / 2.5, 1 / 2.5);
308
+ }
309
+ this.travelTime = Math.max(this.object.lazyTravelTime / clockRate, this.minDeltaTime);
263
310
  }
264
- return true;
265
- }
266
- }
267
-
268
- /**
269
- * A converter used to convert normal hitobjects into difficulty hitobjects.
270
- */
271
- class DifficultyHitObjectCreator {
272
- /**
273
- * The threshold for small circle buff for osu!droid.
274
- */
275
- DROID_CIRCLESIZE_BUFF_THRESHOLD = 70;
276
- /**
277
- * The threshold for small circle buff for osu!standard.
278
- */
279
- PC_CIRCLESIZE_BUFF_THRESHOLD = 30;
280
- /**
281
- * The gamemode this creator is creating for.
282
- */
283
- mode = osuBase.Modes.osu;
284
- /**
285
- * The base normalized radius of hitobjects.
286
- */
287
- normalizedRadius = 50;
288
- maximumSliderRadius = this.normalizedRadius * 2.4;
289
- assumedSliderRadius = this.normalizedRadius * 1.8;
290
- minDeltaTime = 25;
291
- /**
292
- * Generates difficulty hitobjects for difficulty calculation.
293
- */
294
- generateDifficultyObjects(params) {
295
- params.preempt ??= 600;
296
- this.mode = params.mode;
297
- if (this.mode === osuBase.Modes.droid) {
298
- this.maximumSliderRadius = this.normalizedRadius * 2;
311
+ // We don't need to calculate either angle or distance when one of the last->curr objects is a spinner.
312
+ if (!this.lastObject ||
313
+ this.object instanceof osuBase.Spinner ||
314
+ this.lastObject instanceof osuBase.Spinner) {
315
+ return;
299
316
  }
300
- const droidCircleSize = new osuBase.MapStats({
301
- cs: params.circleSize,
302
- mods: params.mods,
303
- }).calculate({ mode: osuBase.Modes.droid }).cs;
304
- const droidScale = (1 - (0.7 * (droidCircleSize - 5)) / 5) / 2;
305
- const osuCircleSize = new osuBase.MapStats({
306
- cs: params.circleSize,
307
- mods: params.mods,
308
- }).calculate({ mode: osuBase.Modes.osu }).cs;
309
- const osuScale = (1 - (0.7 * (osuCircleSize - 5)) / 5) / 2;
310
- params.objects[0].droidScale = droidScale;
311
- params.objects[0].osuScale = osuScale;
312
- const scalingFactor = this.getScalingFactor(params.objects[0].getRadius(this.mode));
313
- const difficultyObjects = [];
314
- for (let i = 0; i < params.objects.length; ++i) {
315
- const object = new DifficultyHitObject(params.objects[i], difficultyObjects);
316
- object.index = difficultyObjects.length - 1;
317
- object.object.droidScale = droidScale;
318
- object.object.osuScale = osuScale;
319
- object.timePreempt = params.preempt;
320
- object.baseTimePreempt = params.preempt * params.speedMultiplier;
321
- if (object.object instanceof osuBase.Slider) {
322
- object.velocity =
323
- object.object.velocity * params.speedMultiplier;
324
- object.object.nestedHitObjects.forEach((o) => {
325
- o.droidScale = droidScale;
326
- o.osuScale = osuScale;
327
- });
328
- this.calculateSliderCursorPosition(object.object);
329
- object.travelDistance = object.object.lazyTravelDistance;
330
- // Bonus for repeat sliders until a better per nested object strain system can be achieved.
331
- if (this.mode === osuBase.Modes.droid) {
332
- object.travelDistance *= Math.pow(1 + object.object.repeats / 4, 1 / 4);
333
- }
334
- else {
335
- object.travelDistance *= Math.pow(1 + object.object.repeats / 2.5, 1 / 2.5);
336
- }
337
- object.travelTime = Math.max(object.object.lazyTravelTime / params.speedMultiplier, this.minDeltaTime);
338
- }
339
- const lastObject = difficultyObjects[i - 1];
340
- const lastLastObject = difficultyObjects[i - 2];
341
- object.startTime = object.object.startTime / params.speedMultiplier;
342
- object.endTime = object.object.endTime / params.speedMultiplier;
343
- if (!lastObject) {
344
- difficultyObjects.push(object);
345
- continue;
346
- }
347
- object.deltaTime =
348
- (object.object.startTime - lastObject.object.startTime) /
349
- params.speedMultiplier;
350
- // Cap to 25ms to prevent difficulty calculation breaking from simultaneous objects.
351
- object.strainTime = Math.max(this.minDeltaTime, object.deltaTime);
352
- if (object.object instanceof osuBase.Spinner) {
353
- difficultyObjects.push(object);
354
- continue;
355
- }
356
- // We'll have two visible object arrays. The first array contains objects before the current object starts in a reversed order,
357
- // while the second array contains objects after the current object ends.
358
- // For overlapping factor, we also need to consider previous visible objects.
359
- const prevVisibleObjects = [];
360
- const nextVisibleObjects = [];
361
- for (let j = i + 1; j < params.objects.length; ++j) {
362
- const o = params.objects[j];
363
- if (o instanceof osuBase.Spinner) {
364
- continue;
365
- }
366
- if (o.startTime / params.speedMultiplier >
367
- object.endTime + object.timePreempt) {
368
- break;
369
- }
370
- // Future objects do not have their scales set, so we set them here.
371
- o.droidScale = droidScale;
372
- o.osuScale = osuScale;
373
- nextVisibleObjects.push(o);
374
- }
375
- for (let j = 0; j < object.index; ++j) {
376
- const prev = object.previous(j);
377
- if (prev.object instanceof osuBase.Spinner) {
378
- continue;
379
- }
380
- if (prev.startTime >= object.startTime) {
381
- continue;
382
- }
383
- if (prev.startTime < object.startTime - object.timePreempt) {
384
- break;
385
- }
386
- prevVisibleObjects.push(prev.object);
387
- }
388
- for (const hitObject of prevVisibleObjects) {
389
- const distance = object.object
390
- .getStackedPosition(this.mode)
391
- .getDistance(hitObject.getStackedEndPosition(this.mode));
392
- const deltaTime = object.startTime -
393
- hitObject.endTime / params.speedMultiplier;
394
- this.applyToOverlappingFactor(object, distance, deltaTime);
395
- }
396
- for (const hitObject of nextVisibleObjects) {
397
- const distance = hitObject
398
- .getStackedPosition(this.mode)
399
- .getDistance(object.object.getStackedEndPosition(this.mode));
400
- const deltaTime = hitObject.startTime / params.speedMultiplier -
401
- object.endTime;
402
- if (deltaTime >= 0) {
403
- object.noteDensity += 1 - deltaTime / object.timePreempt;
404
- }
405
- this.applyToOverlappingFactor(object, distance, deltaTime);
406
- }
407
- if (lastObject.object instanceof osuBase.Spinner) {
408
- difficultyObjects.push(object);
409
- continue;
410
- }
411
- const lastCursorPosition = this.getEndCursorPosition(lastObject.object);
412
- object.lazyJumpDistance = object.object
317
+ // We will scale distances by this factor, so we can assume a uniform CircleSize among beatmaps.
318
+ const { scalingFactor } = this;
319
+ const lastCursorPosition = this.getEndCursorPosition(this.lastObject);
320
+ this.lazyJumpDistance = this.object
321
+ .getStackedPosition(this.mode)
322
+ .scale(scalingFactor)
323
+ .subtract(lastCursorPosition.scale(scalingFactor)).length;
324
+ this.minimumJumpTime = this.strainTime;
325
+ this.minimumJumpDistance = this.lazyJumpDistance;
326
+ if (this.lastObject instanceof osuBase.Slider) {
327
+ const lastTravelTime = Math.max(this.lastObject.lazyTravelTime / clockRate, this.minDeltaTime);
328
+ this.minimumJumpTime = Math.max(this.strainTime - lastTravelTime, this.minDeltaTime);
329
+ // There are two types of slider-to-object patterns to consider in order to better approximate the real movement a player will take to jump between the hitobjects.
330
+ //
331
+ // 1. The anti-flow pattern, where players cut the slider short in order to move to the next hitobject.
332
+ //
333
+ // <======o==> ← slider
334
+ // | ← most natural jump path
335
+ // o ← a follow-up hitcircle
336
+ //
337
+ // In this case the most natural jump path is approximated by LazyJumpDistance.
338
+ //
339
+ // 2. The flow pattern, where players follow through the slider to its visual extent into the next hitobject.
340
+ //
341
+ // <======o==>---o
342
+ // ↑
343
+ // most natural jump path
344
+ //
345
+ // In this case the most natural jump path is better approximated by a new distance called "tailJumpDistance" - the distance between the slider's tail and the next hitobject.
346
+ //
347
+ // Thus, the player is assumed to jump the minimum of these two distances in all cases.
348
+ const tailJumpDistance = this.lastObject.tail
413
349
  .getStackedPosition(this.mode)
414
- .scale(scalingFactor)
415
- .subtract(lastCursorPosition.scale(scalingFactor)).length;
416
- object.minimumJumpTime = object.strainTime;
417
- object.minimumJumpDistance = object.lazyJumpDistance;
418
- if (lastObject.object instanceof osuBase.Slider) {
419
- object.minimumJumpTime = Math.max(object.strainTime - lastObject.travelTime, this.minDeltaTime);
420
- // There are two types of slider-to-object patterns to consider in order to better approximate the real movement a player will take to jump between the hitobjects.
421
- //
422
- // 1. The anti-flow pattern, where players cut the slider short in order to move to the next hitobject.
423
- //
424
- // <======o==> ← slider
425
- // | ← most natural jump path
426
- // o ← a follow-up hitcircle
427
- //
428
- // In this case the most natural jump path is approximated by LazyJumpDistance.
429
- //
430
- // 2. The flow pattern, where players follow through the slider to its visual extent into the next hitobject.
431
- //
432
- // <======o==>---o
433
- // ↑
434
- // most natural jump path
435
- //
436
- // In this case the most natural jump path is better approximated by a new distance called "tailJumpDistance" - the distance between the slider's tail and the next hitobject.
437
- //
438
- // Thus, the player is assumed to jump the minimum of these two distances in all cases.
439
- const tailJumpDistance = lastObject.object.tail
440
- .getStackedPosition(this.mode)
441
- .subtract(object.object.getStackedPosition(this.mode))
442
- .length * scalingFactor;
443
- object.minimumJumpDistance = Math.max(0, Math.min(object.lazyJumpDistance -
444
- (this.maximumSliderRadius -
445
- this.assumedSliderRadius), tailJumpDistance - this.maximumSliderRadius));
446
- }
447
- if (lastLastObject && !(lastLastObject.object instanceof osuBase.Spinner)) {
448
- const lastLastCursorPosition = this.getEndCursorPosition(lastLastObject.object);
449
- const v1 = lastLastCursorPosition.subtract(lastObject.object.getStackedPosition(this.mode));
450
- const v2 = object.object
451
- .getStackedPosition(this.mode)
452
- .subtract(lastCursorPosition);
453
- const dot = v1.dot(v2);
454
- const det = v1.x * v2.y - v1.y * v2.x;
455
- object.angle = Math.abs(Math.atan2(det, dot));
456
- }
457
- difficultyObjects.push(object);
350
+ .subtract(this.object.getStackedPosition(this.mode))
351
+ .length * scalingFactor;
352
+ this.minimumJumpDistance = Math.max(0, Math.min(this.lazyJumpDistance -
353
+ (this.maximumSliderRadius - this.assumedSliderRadius), tailJumpDistance - this.maximumSliderRadius));
354
+ }
355
+ if (this.lastLastObject && !(this.lastLastObject instanceof osuBase.Spinner)) {
356
+ const lastLastCursorPosition = this.getEndCursorPosition(this.lastLastObject);
357
+ const v1 = lastLastCursorPosition.subtract(this.lastObject.getStackedPosition(this.mode));
358
+ const v2 = this.object
359
+ .getStackedPosition(this.mode)
360
+ .subtract(lastCursorPosition);
361
+ const dot = v1.dot(v2);
362
+ const det = v1.x * v2.y - v1.y * v2.x;
363
+ this.angle = Math.abs(Math.atan2(det, dot));
458
364
  }
459
- return difficultyObjects;
460
365
  }
461
- /**
462
- * Calculates a slider's cursor position.
463
- */
464
366
  calculateSliderCursorPosition(slider) {
465
367
  if (slider.lazyEndPosition) {
466
368
  return;
467
369
  }
468
- // Droid doesn't have a legacy slider tail. Since beatmap parser defaults slider tail
469
- // to legacy slider tail, it needs to be changed to real slider tail first.
470
- if (this.mode === osuBase.Modes.droid) {
471
- slider.tail.startTime += osuBase.Slider.legacyLastTickOffset;
472
- slider.tail.endTime += osuBase.Slider.legacyLastTickOffset;
473
- slider.nestedHitObjects.sort((a, b) => a.startTime - b.startTime);
474
- // Temporary lazy end position until a real result can be derived.
475
- slider.lazyEndPosition = slider.getStackedPosition(this.mode);
476
- // Stop here if the slider has too short duration due to float number limitation.
477
- // Incredibly close start and end time fluctuates travel distance and lazy
478
- // end position heavily, which we do not want to happen.
479
- //
480
- // In the real game, this shouldn't happen. Perhaps we need to reinvestigate this
481
- // in the future.
482
- if (osuBase.Precision.almostEqualsNumber(slider.startTime, slider.endTime)) {
483
- return;
484
- }
485
- }
486
370
  // Not using slider.endTime due to legacy last tick offset.
487
371
  slider.lazyTravelTime =
488
372
  slider.nestedHitObjects.at(-1).startTime - slider.startTime;
@@ -498,7 +382,7 @@ class DifficultyHitObjectCreator {
498
382
  .getStackedPosition(this.mode)
499
383
  .add(slider.path.positionAt(endTimeMin));
500
384
  let currentCursorPosition = slider.getStackedPosition(this.mode);
501
- const scalingFactor = this.normalizedRadius / slider.getRadius(this.mode);
385
+ const scalingFactor = this.normalizedRadius / slider.radius;
502
386
  for (let i = 1; i < slider.nestedHitObjects.length; ++i) {
503
387
  const currentMovementObject = slider.nestedHitObjects[i];
504
388
  let currentMovement = currentMovementObject
@@ -514,209 +398,37 @@ class DifficultyHitObjectCreator {
514
398
  // This code is designed to prevent buffing situations where lazy end is actually a less efficient movement.
515
399
  const lazyMovement = slider.lazyEndPosition.subtract(currentCursorPosition);
516
400
  if (lazyMovement.length < currentMovement.length) {
517
- currentMovement = lazyMovement;
518
- }
519
- currentMovementLength = scalingFactor * currentMovement.length;
520
- }
521
- else if (currentMovementObject instanceof osuBase.SliderRepeat) {
522
- // For a slider repeat, assume a tighter movement threshold to better assess repeat sliders.
523
- requiredMovement = this.normalizedRadius;
524
- }
525
- if (currentMovementLength > requiredMovement) {
526
- // This finds the positional delta from the required radius and the current position,
527
- // and updates the currentCursorPosition accordingly, as well as rewarding distance.
528
- currentCursorPosition = currentCursorPosition.add(currentMovement.scale((currentMovementLength - requiredMovement) /
529
- currentMovementLength));
530
- currentMovementLength *=
531
- (currentMovementLength - requiredMovement) /
532
- currentMovementLength;
533
- slider.lazyTravelDistance += currentMovementLength;
534
- }
535
- if (i === slider.nestedHitObjects.length - 1) {
536
- slider.lazyEndPosition = currentCursorPosition;
537
- }
538
- }
539
- }
540
- /**
541
- * Gets the scaling factor of a radius.
542
- *
543
- * @param radius The radius to get the scaling factor from.
544
- */
545
- getScalingFactor(radius) {
546
- // We will scale distances by this factor, so we can assume a uniform CircleSize among beatmaps.
547
- let scalingFactor = this.normalizedRadius / radius;
548
- // High circle size (small CS) bonus
549
- switch (this.mode) {
550
- case osuBase.Modes.droid:
551
- if (radius < this.DROID_CIRCLESIZE_BUFF_THRESHOLD) {
552
- scalingFactor *=
553
- 1 +
554
- Math.pow((this.DROID_CIRCLESIZE_BUFF_THRESHOLD - radius) /
555
- 50, 2);
556
- }
557
- break;
558
- case osuBase.Modes.osu:
559
- if (radius < this.PC_CIRCLESIZE_BUFF_THRESHOLD) {
560
- scalingFactor *=
561
- 1 +
562
- Math.min(this.PC_CIRCLESIZE_BUFF_THRESHOLD - radius, 5) /
563
- 50;
564
- }
565
- }
566
- return scalingFactor;
567
- }
568
- /**
569
- * Returns the end cursor position of a hitobject.
570
- */
571
- getEndCursorPosition(object) {
572
- let pos = object.getStackedPosition(this.mode);
573
- if (object instanceof osuBase.Slider) {
574
- this.calculateSliderCursorPosition(object);
575
- pos = object.lazyEndPosition ?? pos;
576
- }
577
- return pos;
578
- }
579
- applyToOverlappingFactor(object, distance, deltaTime) {
580
- // Penalize objects that are too close to the object in both distance
581
- // and delta time to prevent stream maps from being overweighted.
582
- object.overlappingFactor +=
583
- Math.max(0, 1 - distance / (3 * object.object.getRadius(this.mode))) *
584
- (7.5 /
585
- (1 +
586
- Math.exp(0.15 * (Math.max(deltaTime, this.minDeltaTime) - 75))));
587
- }
588
- }
589
-
590
- /**
591
- * The base of a difficulty calculator.
592
- */
593
- class DifficultyCalculator {
594
- /**
595
- * The calculated beatmap.
596
- */
597
- beatmap;
598
- /**
599
- * The difficulty objects of the beatmap.
600
- */
601
- objects = [];
602
- /**
603
- * The modifications applied.
604
- */
605
- mods = [];
606
- /**
607
- * The total star rating of the beatmap.
608
- */
609
- total = 0;
610
- /**
611
- * The map statistics of the beatmap after modifications are applied.
612
- */
613
- stats = new osuBase.MapStats();
614
- /**
615
- * The strain peaks of various calculated difficulties.
616
- */
617
- strainPeaks = {
618
- aimWithSliders: [],
619
- aimWithoutSliders: [],
620
- speed: [],
621
- flashlight: [],
622
- };
623
- sectionLength = 400;
624
- /**
625
- * Constructs a new instance of the calculator.
626
- *
627
- * @param beatmap The beatmap to calculate. This beatmap will be deep-cloned to prevent reference changes.
628
- */
629
- constructor(beatmap) {
630
- this.beatmap = osuBase.Utils.deepCopy(beatmap);
631
- }
632
- /**
633
- * Calculates the star rating of the specified beatmap.
634
- *
635
- * The beatmap is analyzed in chunks of `sectionLength` duration.
636
- * For each chunk the highest hitobject strains are added to
637
- * a list which is then collapsed into a weighted sum, much
638
- * like scores are weighted on a user's profile.
639
- *
640
- * For subsequent chunks, the initial max strain is calculated
641
- * by decaying the previous hitobject's strain until the
642
- * beginning of the new chunk.
643
- *
644
- * @param options Options for the difficulty calculation.
645
- */
646
- calculate(options) {
647
- this.mods = options?.mods ?? [];
648
- this.stats = new osuBase.MapStats({
649
- cs: this.beatmap.difficulty.cs,
650
- ar: this.beatmap.difficulty.ar,
651
- od: this.beatmap.difficulty.od,
652
- hp: this.beatmap.difficulty.hp,
653
- mods: options?.mods,
654
- speedMultiplier: options?.stats?.speedMultiplier ?? 1,
655
- oldStatistics: options?.stats?.oldStatistics ?? false,
656
- }).calculate({ mode: this.mode });
657
- this.populateDifficultyAttributes();
658
- this.generateDifficultyHitObjects();
659
- this.calculateAll();
660
- return this;
661
- }
662
- /**
663
- * Generates difficulty hitobjects for this calculator.
664
- */
665
- generateDifficultyHitObjects() {
666
- this.objects.length = 0;
667
- this.objects.push(...new DifficultyHitObjectCreator().generateDifficultyObjects({
668
- objects: this.beatmap.hitObjects.objects,
669
- circleSize: this.beatmap.difficulty.cs,
670
- mods: this.mods,
671
- speedMultiplier: this.stats.speedMultiplier,
672
- mode: this.mode,
673
- preempt: osuBase.MapStats.arToMS(this.stats.ar),
674
- }));
675
- }
676
- /**
677
- * Calculates the skills provided.
678
- *
679
- * @param skills The skills to calculate.
680
- */
681
- calculateSkills(...skills) {
682
- // The first object doesn't generate a strain, so we begin calculating from the second object.
683
- this.objects.slice(1).forEach((h, i) => {
684
- skills.forEach((skill) => {
685
- skill.process(h);
686
- if (i === this.objects.length - 2) {
687
- // Don't forget to save the last strain peak, which would otherwise be ignored.
688
- skill.saveCurrentPeak();
401
+ currentMovement = lazyMovement;
689
402
  }
690
- });
691
- });
692
- }
693
- /**
694
- * Populates the stored difficulty attributes with necessary data.
695
- */
696
- populateDifficultyAttributes() {
697
- this.attributes.approachRate = this.stats.ar;
698
- this.attributes.hitCircleCount = this.beatmap.hitObjects.circles;
699
- this.attributes.maxCombo = this.beatmap.maxCombo;
700
- this.attributes.mods = this.mods.slice();
701
- this.attributes.overallDifficulty = this.stats.od;
702
- this.attributes.sliderCount = this.beatmap.hitObjects.sliders;
703
- this.attributes.spinnerCount = this.beatmap.hitObjects.spinners;
704
- }
705
- /**
706
- * Calculates the star rating value of a difficulty.
707
- *
708
- * @param difficulty The difficulty to calculate.
709
- */
710
- starValue(difficulty) {
711
- return Math.sqrt(difficulty) * this.difficultyMultiplier;
403
+ currentMovementLength = scalingFactor * currentMovement.length;
404
+ }
405
+ else if (currentMovementObject instanceof osuBase.SliderRepeat) {
406
+ // For a slider repeat, assume a tighter movement threshold to better assess repeat sliders.
407
+ requiredMovement = this.normalizedRadius;
408
+ }
409
+ if (currentMovementLength > requiredMovement) {
410
+ // This finds the positional delta from the required radius and the current position,
411
+ // and updates the currentCursorPosition accordingly, as well as rewarding distance.
412
+ currentCursorPosition = currentCursorPosition.add(currentMovement.scale((currentMovementLength - requiredMovement) /
413
+ currentMovementLength));
414
+ currentMovementLength *=
415
+ (currentMovementLength - requiredMovement) /
416
+ currentMovementLength;
417
+ slider.lazyTravelDistance += currentMovementLength;
418
+ }
419
+ if (i === slider.nestedHitObjects.length - 1) {
420
+ slider.lazyEndPosition = currentCursorPosition;
421
+ }
422
+ }
712
423
  }
713
- /**
714
- * Calculates the base performance value of a difficulty rating.
715
- *
716
- * @param rating The difficulty rating.
717
- */
718
- basePerformanceValue(rating) {
719
- return Math.pow(5 * Math.max(1, rating / 0.0675) - 4, 3) / 100000;
424
+ getEndCursorPosition(object) {
425
+ var _a;
426
+ let pos = object.getStackedPosition(this.mode);
427
+ if (object instanceof osuBase.Slider) {
428
+ this.calculateSliderCursorPosition(object);
429
+ pos = (_a = object.lazyEndPosition) !== null && _a !== void 0 ? _a : pos;
430
+ }
431
+ return pos;
720
432
  }
721
433
  }
722
434
 
@@ -724,15 +436,6 @@ class DifficultyCalculator {
724
436
  * An evaluator for calculating osu!droid Aim skill.
725
437
  */
726
438
  class DroidAimEvaluator extends AimEvaluator {
727
- static wideAngleMultiplier = 1.65;
728
- static sliderMultiplier = 1.5;
729
- static velocityChangeMultiplier = 0.85;
730
- /**
731
- * Spacing threshold for a single hitobject spacing.
732
- */
733
- static SINGLE_SPACING_THRESHOLD = 175;
734
- // ~200 1/2 BPM jumps
735
- static minSpeedBonus = 150;
736
439
  /**
737
440
  * Evaluates the difficulty of aiming the current object, based on:
738
441
  *
@@ -750,15 +453,16 @@ class DroidAimEvaluator extends AimEvaluator {
750
453
  current.isOverlapping(true)) {
751
454
  return 0;
752
455
  }
753
- return (this.aimStrainOf(current, withSliders) +
754
- this.movementStrainOf(current));
456
+ return (this.snapAimStrainOf(current, withSliders) +
457
+ this.flowAimStrainOf(current));
755
458
  }
756
459
  /**
757
- * Calculates the aim strain of a hitobject.
460
+ * Calculates the snap aim strain of a hitobject.
758
461
  */
759
- static aimStrainOf(current, withSliders) {
462
+ static snapAimStrainOf(current, withSliders) {
463
+ var _a;
760
464
  if (current.index <= 1 ||
761
- current.previous(0)?.object instanceof osuBase.Spinner) {
465
+ ((_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.object) instanceof osuBase.Spinner) {
762
466
  return 0;
763
467
  }
764
468
  const last = current.previous(0);
@@ -860,37 +564,38 @@ class DroidAimEvaluator extends AimEvaluator {
860
564
  velocityChangeBonus * this.velocityChangeMultiplier);
861
565
  // Add in additional slider velocity bonus.
862
566
  if (withSliders) {
863
- strain += sliderBonus * this.sliderMultiplier;
567
+ strain +=
568
+ Math.pow(1 + sliderBonus * this.sliderMultiplier, 1.25) - 1;
864
569
  }
865
570
  return strain;
866
571
  }
867
572
  /**
868
- * Calculates the movement strain of a hitobject.
573
+ * Calculates the flow aim strain of a hitobject.
869
574
  */
870
- static movementStrainOf(current) {
575
+ static flowAimStrainOf(current) {
576
+ var _a, _b;
871
577
  let speedBonus = 1;
872
578
  if (current.strainTime < this.minSpeedBonus) {
873
579
  speedBonus +=
874
580
  0.75 *
875
- Math.pow((this.minSpeedBonus - current.strainTime) / 45, 2);
581
+ Math.pow((this.minSpeedBonus - current.strainTime) / 40, 2);
876
582
  }
877
- const travelDistance = current.previous(0)?.travelDistance ?? 0;
878
- const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
879
- return ((50 *
880
- speedBonus *
881
- Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 5)) /
882
- current.strainTime);
583
+ const travelDistance = (_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.travelDistance) !== null && _b !== void 0 ? _b : 0;
584
+ const shortDistancePenalty = Math.pow(Math.min(this.singleSpacingThreshold, travelDistance + current.minimumJumpDistance) / this.singleSpacingThreshold, 3.5);
585
+ return (200 * speedBonus * shortDistancePenalty) / current.strainTime;
883
586
  }
884
587
  }
588
+ DroidAimEvaluator.wideAngleMultiplier = 1.65;
589
+ DroidAimEvaluator.sliderMultiplier = 1.5;
590
+ DroidAimEvaluator.velocityChangeMultiplier = 0.85;
591
+ DroidAimEvaluator.singleSpacingThreshold = 100;
592
+ // 200 1/4 BPM delta time
593
+ DroidAimEvaluator.minSpeedBonus = 75;
885
594
 
886
595
  /**
887
596
  * A bare minimal abstract skill for fully custom skill implementations.
888
597
  */
889
598
  class Skill {
890
- /**
891
- * The mods that this skill processes.
892
- */
893
- mods;
894
599
  constructor(mods) {
895
600
  this.mods = mods;
896
601
  }
@@ -901,33 +606,21 @@ class Skill {
901
606
  * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
902
607
  */
903
608
  class StrainSkill extends Skill {
904
- /**
905
- * The strain of currently calculated hitobject.
906
- */
907
- currentStrain = 0;
908
- /**
909
- * The current section's strain peak.
910
- */
911
- currentSectionPeak = 0;
912
- /**
913
- * Strain peaks are stored here.
914
- */
915
- strainPeaks = [];
916
- sectionLength = 400;
917
- currentSectionEnd = 0;
918
- isFirstObject = true;
919
- /**
920
- * Calculates the strain value of a hitobject and stores the value in it. This value is affected by previously processed objects.
921
- *
922
- * @param current The hitobject to process.
923
- */
609
+ constructor() {
610
+ super(...arguments);
611
+ /**
612
+ * Strain peaks are stored here.
613
+ */
614
+ this.strainPeaks = [];
615
+ this.sectionLength = 400;
616
+ this.currentStrain = 0;
617
+ this.currentSectionPeak = 0;
618
+ this.currentSectionEnd = 0;
619
+ }
924
620
  process(current) {
925
621
  // The first object doesn't generate a strain, so we begin with an incremented section end
926
- if (this.isFirstObject) {
927
- this.currentSectionEnd =
928
- Math.ceil(current.startTime / this.sectionLength) *
929
- this.sectionLength;
930
- this.isFirstObject = false;
622
+ if (current.index === 0) {
623
+ this.currentSectionEnd = this.calculateCurrentSectionStart(current);
931
624
  }
932
625
  while (current.startTime > this.currentSectionEnd) {
933
626
  this.saveCurrentPeak();
@@ -938,6 +631,10 @@ class StrainSkill extends Skill {
938
631
  this.currentStrain = this.strainValueAt(current);
939
632
  this.saveToHitObject(current);
940
633
  this.currentSectionPeak = Math.max(this.currentStrain, this.currentSectionPeak);
634
+ if (!current.next(0)) {
635
+ // Don't forget to save the last strain peak, which would otherwise be ignored.
636
+ this.saveCurrentPeak();
637
+ }
941
638
  }
942
639
  /**
943
640
  * Saves the current peak strain level to the list of strain peaks, which will be used to calculate an overall difficulty.
@@ -953,18 +650,26 @@ class StrainSkill extends Skill {
953
650
  strainDecay(ms) {
954
651
  return Math.pow(this.strainDecayBase, ms / 1000);
955
652
  }
653
+ /**
654
+ * Calculates the starting time of a strain section at an object.
655
+ *
656
+ * @param current The object at which the strain section starts.
657
+ * @returns The start time of the strain section.
658
+ */
659
+ calculateCurrentSectionStart(current) {
660
+ return (Math.ceil(current.startTime / this.sectionLength) *
661
+ this.sectionLength);
662
+ }
956
663
  /**
957
664
  * Sets the initial strain level for a new section.
958
665
  *
959
- * @param offset The beginning of the new section in milliseconds, adjusted by speed multiplier.
666
+ * @param time The beginning of the new section in milliseconds.
960
667
  * @param current The current hitobject.
961
668
  */
962
- startNewSectionFrom(offset, current) {
963
- // The maximum strain of the new section is not zero by default, strain decays as usual regardless of section boundaries.
669
+ startNewSectionFrom(time, current) {
670
+ // The maximum strain of the new section is not zero by default.
964
671
  // This means we need to capture the strain level at the beginning of the new section, and use that as the initial peak level.
965
- this.currentSectionPeak =
966
- this.currentStrain *
967
- this.strainDecay(offset - current.previous(0).startTime);
672
+ this.currentSectionPeak = this.calculateInitialStrain(time, current);
968
673
  }
969
674
  }
970
675
 
@@ -973,6 +678,35 @@ class StrainSkill extends Skill {
973
678
  * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
974
679
  */
975
680
  class DroidSkill extends StrainSkill {
681
+ constructor() {
682
+ super(...arguments);
683
+ this._objectStrains = [];
684
+ }
685
+ /**
686
+ * The strains of hitobjects.
687
+ */
688
+ get objectStrains() {
689
+ return this._objectStrains;
690
+ }
691
+ /**
692
+ * Returns the number of strains weighed against the top strain.
693
+ *
694
+ * The result is scaled by clock rate as it affects the total number of strains.
695
+ */
696
+ countDifficultStrains() {
697
+ if (this._objectStrains.length === 0) {
698
+ return 0;
699
+ }
700
+ const maxStrain = Math.max(...this._objectStrains);
701
+ if (maxStrain === 0) {
702
+ return 0;
703
+ }
704
+ return this._objectStrains.reduce((total, next) => total + Math.pow(next / maxStrain, 4), 0);
705
+ }
706
+ process(current) {
707
+ super.process(current);
708
+ this._objectStrains.push(this.getObjectStrain(current));
709
+ }
976
710
  difficultyValue() {
977
711
  const strains = this.strainPeaks.slice();
978
712
  if (this.reducedSectionCount > 0) {
@@ -992,41 +726,49 @@ class DroidSkill extends StrainSkill {
992
726
  return a + Math.pow(v, 1 / Math.log2(this.starsPerDouble));
993
727
  }, 0), Math.log2(this.starsPerDouble));
994
728
  }
729
+ calculateCurrentSectionStart(current) {
730
+ return current.startTime;
731
+ }
995
732
  }
996
733
 
997
734
  /**
998
735
  * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
999
736
  */
1000
737
  class DroidAim extends DroidSkill {
1001
- skillMultiplier = 24.55;
1002
- strainDecayBase = 0.15;
1003
- reducedSectionCount = 10;
1004
- reducedSectionBaseline = 0.75;
1005
- starsPerDouble = 1.05;
1006
- withSliders;
1007
738
  constructor(mods, withSliders) {
1008
739
  super(mods);
740
+ this.strainDecayBase = 0.15;
741
+ this.reducedSectionCount = 10;
742
+ this.reducedSectionBaseline = 0.75;
743
+ this.starsPerDouble = 1.05;
744
+ this.skillMultiplier = 24.55;
745
+ this.currentAimStrain = 0;
1009
746
  this.withSliders = withSliders;
1010
747
  }
1011
- /**
1012
- * @param current The hitobject to calculate.
1013
- */
1014
748
  strainValueAt(current) {
1015
- this.currentStrain *= this.strainDecay(current.deltaTime);
1016
- this.currentStrain +=
749
+ this.currentAimStrain *= this.strainDecay(current.deltaTime);
750
+ this.currentAimStrain +=
1017
751
  DroidAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
1018
752
  this.skillMultiplier;
1019
- return this.currentStrain;
753
+ return this.currentAimStrain;
754
+ }
755
+ calculateInitialStrain(time, current) {
756
+ var _a, _b;
757
+ return (this.currentAimStrain *
758
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
759
+ }
760
+ getObjectStrain() {
761
+ return this.currentAimStrain;
1020
762
  }
1021
763
  /**
1022
764
  * @param current The hitobject to save to.
1023
765
  */
1024
766
  saveToHitObject(current) {
1025
767
  if (this.withSliders) {
1026
- current.aimStrainWithSliders = this.currentStrain;
768
+ current.aimStrainWithSliders = this.currentAimStrain;
1027
769
  }
1028
770
  else {
1029
- current.aimStrainWithoutSliders = this.currentStrain;
771
+ current.aimStrainWithoutSliders = this.currentAimStrain;
1030
772
  }
1031
773
  }
1032
774
  }
@@ -1037,9 +779,9 @@ class DroidAim extends DroidSkill {
1037
779
  * This class should be considered an "evaluating" class and not persisted.
1038
780
  */
1039
781
  class SpeedEvaluator {
1040
- // ~200 1/4 BPM streams
1041
- static minSpeedBonus = 75;
1042
782
  }
783
+ // ~200 1/4 BPM streams
784
+ SpeedEvaluator.minSpeedBonus = 75;
1043
785
 
1044
786
  /**
1045
787
  * An evaluator for calculating osu!droid tap skill.
@@ -1050,25 +792,26 @@ class DroidTapEvaluator extends SpeedEvaluator {
1050
792
  *
1051
793
  * - time between pressing the previous and current object,
1052
794
  * - distance between those objects,
1053
- * - and how easily they can be cheesed.
795
+ * - how easily they can be cheesed,
796
+ * - and the strain time cap.
1054
797
  *
1055
798
  * @param current The current object.
1056
799
  * @param greatWindow The great hit window of the current object.
1057
800
  * @param considerCheesability Whether to consider cheesability.
801
+ * @param strainTimeCap The strain time to cap the object's strain time to.
1058
802
  */
1059
- static evaluateDifficultyOf(current, greatWindow, considerCheesability) {
803
+ static evaluateDifficultyOf(current, greatWindow, considerCheesability, strainTimeCap) {
1060
804
  if (current.object instanceof osuBase.Spinner ||
1061
805
  // Exclude overlapping objects that can be tapped at once.
1062
806
  current.isOverlapping(false)) {
1063
807
  return 0;
1064
808
  }
1065
- let strainTime = current.strainTime;
1066
809
  let doubletapness = 1;
1067
810
  if (considerCheesability) {
1068
- const greatWindowFull = greatWindow * 2;
1069
811
  // Nerf doubletappable doubles.
1070
812
  const next = current.next(0);
1071
813
  if (next) {
814
+ const greatWindowFull = greatWindow * 2;
1072
815
  const currentDeltaTime = Math.max(1, current.deltaTime);
1073
816
  const nextDeltaTime = Math.max(1, next.deltaTime);
1074
817
  const deltaDifference = Math.abs(nextDeltaTime - currentDeltaTime);
@@ -1077,16 +820,18 @@ class DroidTapEvaluator extends SpeedEvaluator {
1077
820
  const windowRatio = Math.pow(Math.min(1, currentDeltaTime / greatWindowFull), 2);
1078
821
  doubletapness = Math.pow(speedRatio, 1 - windowRatio);
1079
822
  }
1080
- // Cap deltatime to the OD 300 hitwindow.
1081
- // 0.58 is derived from making sure 260 BPM 1/4 OD5 streams aren't nerfed harshly, whilst 0.91 limits the effect of the cap.
1082
- strainTime /= osuBase.MathUtils.clamp(strainTime / greatWindowFull / 0.58, 0.91, 1);
1083
823
  }
824
+ const strainTime = strainTimeCap !== undefined
825
+ ? // We cap the strain time to 50 here as the chance of vibro is higher in any BPM higher than 300.
826
+ Math.max(50, strainTimeCap, current.strainTime)
827
+ : current.strainTime;
1084
828
  let speedBonus = 1;
1085
829
  if (strainTime < this.minSpeedBonus) {
1086
830
  speedBonus +=
1087
- 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
831
+ 0.75 *
832
+ Math.pow(osuBase.ErrorFunction.erf((this.minSpeedBonus - strainTime) / 40), 2);
1088
833
  }
1089
- return (speedBonus * doubletapness) / strainTime;
834
+ return (speedBonus * Math.pow(doubletapness, 1.5)) / strainTime;
1090
835
  }
1091
836
  }
1092
837
 
@@ -1094,38 +839,89 @@ class DroidTapEvaluator extends SpeedEvaluator {
1094
839
  * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
1095
840
  */
1096
841
  class DroidTap extends DroidSkill {
1097
- skillMultiplier = 1375;
1098
- reducedSectionCount = 10;
1099
- reducedSectionBaseline = 0.75;
1100
- strainDecayBase = 0.3;
1101
- starsPerDouble = 1.1;
1102
- currentTapStrain = 0;
1103
- currentOriginalTapStrain = 0;
1104
- greatWindow;
1105
- constructor(mods, overallDifficulty) {
842
+ /**
843
+ * The delta time of hitobjects.
844
+ */
845
+ get objectDeltaTimes() {
846
+ return this._objectDeltaTimes;
847
+ }
848
+ constructor(mods, overallDifficulty, considerCheesability, strainTimeCap) {
1106
849
  super(mods);
850
+ this.reducedSectionCount = 10;
851
+ this.reducedSectionBaseline = 0.75;
852
+ this.strainDecayBase = 0.3;
853
+ this.starsPerDouble = 1.1;
854
+ this.currentTapStrain = 0;
855
+ this.currentRhythmMultiplier = 0;
856
+ this.skillMultiplier = 1375;
857
+ this._objectDeltaTimes = [];
1107
858
  this.greatWindow = new osuBase.OsuHitWindow(overallDifficulty).hitWindowFor300();
859
+ this.considerCheesability = considerCheesability;
860
+ this.strainTimeCap = strainTimeCap;
1108
861
  }
1109
862
  /**
1110
- * @param current The hitobject to calculate.
863
+ * The amount of notes that are relevant to the difficulty.
864
+ */
865
+ relevantNoteCount() {
866
+ if (this._objectStrains.length === 0) {
867
+ return 0;
868
+ }
869
+ const maxStrain = Math.max(...this._objectStrains);
870
+ if (maxStrain === 0) {
871
+ return 0;
872
+ }
873
+ return this._objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
874
+ }
875
+ /**
876
+ * The delta time relevant to the difficulty.
1111
877
  */
878
+ relevantDeltaTime() {
879
+ if (this._objectStrains.length === 0) {
880
+ return 0;
881
+ }
882
+ const maxStrain = Math.max(...this._objectStrains);
883
+ if (maxStrain === 0) {
884
+ return 0;
885
+ }
886
+ return (this._objectDeltaTimes.reduce((total, next, index) => total +
887
+ (next * 1) /
888
+ (1 +
889
+ Math.exp(-((this._objectStrains[index] / maxStrain) *
890
+ 25 -
891
+ 20))), 0) /
892
+ this._objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 25 - 20))), 0));
893
+ }
1112
894
  strainValueAt(current) {
1113
- const decay = this.strainDecay(current.strainTime);
1114
- this.currentTapStrain *= decay;
895
+ this.currentTapStrain *= this.strainDecay(current.strainTime);
1115
896
  this.currentTapStrain +=
1116
- DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, true) * this.skillMultiplier;
1117
- this.currentOriginalTapStrain *= decay;
1118
- this.currentOriginalTapStrain +=
1119
- DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, false) * this.skillMultiplier;
1120
- this.currentOriginalTapStrain *= current.rhythmMultiplier;
897
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, this.considerCheesability, this.strainTimeCap) * this.skillMultiplier;
898
+ this.currentRhythmMultiplier = current.rhythmMultiplier;
899
+ this._objectDeltaTimes.push(current.deltaTime);
1121
900
  return this.currentTapStrain * current.rhythmMultiplier;
1122
901
  }
902
+ calculateInitialStrain(time, current) {
903
+ var _a, _b;
904
+ return (this.currentTapStrain *
905
+ this.currentRhythmMultiplier *
906
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
907
+ }
908
+ getObjectStrain() {
909
+ return this.currentTapStrain * this.currentRhythmMultiplier;
910
+ }
1123
911
  /**
1124
912
  * @param current The hitobject to save to.
1125
913
  */
1126
914
  saveToHitObject(current) {
1127
- current.tapStrain = this.currentStrain;
1128
- current.originalTapStrain = this.currentOriginalTapStrain;
915
+ if (this.strainTimeCap !== undefined) {
916
+ return;
917
+ }
918
+ const strain = this.currentTapStrain * this.currentRhythmMultiplier;
919
+ if (this.considerCheesability) {
920
+ current.tapStrain = strain;
921
+ }
922
+ else {
923
+ current.originalTapStrain = strain;
924
+ }
1129
925
  }
1130
926
  }
1131
927
 
@@ -1135,12 +931,12 @@ class DroidTap extends DroidSkill {
1135
931
  * This class should be considered an "evaluating" class and not persisted.
1136
932
  */
1137
933
  class FlashlightEvaluator {
1138
- static maxOpacityBonus = 0.4;
1139
- static hiddenBonus = 0.2;
1140
- static minVelocity = 0.5;
1141
- static sliderMultiplier = 1.3;
1142
- static minAngleMultiplier = 0.2;
1143
934
  }
935
+ FlashlightEvaluator.maxOpacityBonus = 0.4;
936
+ FlashlightEvaluator.hiddenBonus = 0.2;
937
+ FlashlightEvaluator.minVelocity = 0.5;
938
+ FlashlightEvaluator.sliderMultiplier = 1.3;
939
+ FlashlightEvaluator.minAngleMultiplier = 0.2;
1144
940
 
1145
941
  /**
1146
942
  * An evaluator for calculating osu!droid Flashlight skill.
@@ -1165,7 +961,7 @@ class DroidFlashlightEvaluator extends FlashlightEvaluator {
1165
961
  current.isOverlapping(true)) {
1166
962
  return 0;
1167
963
  }
1168
- const scalingFactor = 52 / current.object.getRadius(osuBase.Modes.droid);
964
+ const scalingFactor = 52 / current.object.radius;
1169
965
  let smallDistNerf = 1;
1170
966
  let cumulativeStrainTime = 0;
1171
967
  let result = 0;
@@ -1190,7 +986,7 @@ class DroidFlashlightEvaluator extends FlashlightEvaluator {
1190
986
  const opacityBonus = 1 +
1191
987
  this.maxOpacityBonus *
1192
988
  (1 -
1193
- current.opacityAt(currentObject.object.startTime, isHiddenMod, osuBase.Modes.droid));
989
+ current.opacityAt(currentObject.object.startTime, isHiddenMod));
1194
990
  result +=
1195
991
  (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
1196
992
  cumulativeStrainTime;
@@ -1221,8 +1017,8 @@ class DroidFlashlightEvaluator extends FlashlightEvaluator {
1221
1017
  // Longer sliders require more memorization.
1222
1018
  sliderBonus *= pixelTravelDistance;
1223
1019
  // Nerf sliders with repeats, as less memorization is required.
1224
- if (current.object.repeats > 0)
1225
- sliderBonus /= current.object.repeats + 1;
1020
+ if (current.object.repeatCount > 0)
1021
+ sliderBonus /= current.object.repeatCount + 1;
1226
1022
  }
1227
1023
  result += sliderBonus * this.sliderMultiplier;
1228
1024
  return result;
@@ -1233,35 +1029,43 @@ class DroidFlashlightEvaluator extends FlashlightEvaluator {
1233
1029
  * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
1234
1030
  */
1235
1031
  class DroidFlashlight extends DroidSkill {
1236
- skillMultiplier = 0.125;
1237
- strainDecayBase = 0.15;
1238
- reducedSectionCount = 0;
1239
- reducedSectionBaseline = 1;
1240
- starsPerDouble = 1.05;
1241
- isHidden;
1242
- withSliders;
1243
1032
  constructor(mods, withSliders) {
1244
1033
  super(mods);
1034
+ this.strainDecayBase = 0.15;
1035
+ this.reducedSectionCount = 0;
1036
+ this.reducedSectionBaseline = 1;
1037
+ this.starsPerDouble = 1.06;
1038
+ this.skillMultiplier = 0.052;
1039
+ this.currentFlashlightStrain = 0;
1245
1040
  this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1246
1041
  this.withSliders = withSliders;
1247
1042
  }
1248
- /**
1249
- * @param current The hitobject to calculate.
1250
- */
1251
1043
  strainValueAt(current) {
1252
- this.currentStrain *= this.strainDecay(current.deltaTime);
1253
- this.currentStrain +=
1044
+ this.currentFlashlightStrain *= this.strainDecay(current.deltaTime);
1045
+ this.currentFlashlightStrain +=
1254
1046
  DroidFlashlightEvaluator.evaluateDifficultyOf(current, this.isHidden, this.withSliders) * this.skillMultiplier;
1255
- return this.currentStrain;
1047
+ return this.currentFlashlightStrain;
1048
+ }
1049
+ calculateInitialStrain(time, current) {
1050
+ var _a, _b;
1051
+ return (this.currentFlashlightStrain *
1052
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
1053
+ }
1054
+ getObjectStrain() {
1055
+ return this.currentFlashlightStrain;
1256
1056
  }
1257
1057
  saveToHitObject(current) {
1258
1058
  if (this.withSliders) {
1259
- current.flashlightStrainWithSliders = this.currentStrain;
1059
+ current.flashlightStrainWithSliders = this.currentFlashlightStrain;
1260
1060
  }
1261
1061
  else {
1262
- current.flashlightStrainWithoutSliders = this.currentStrain;
1062
+ current.flashlightStrainWithoutSliders =
1063
+ this.currentFlashlightStrain;
1263
1064
  }
1264
1065
  }
1066
+ difficultyValue() {
1067
+ return Math.pow(this.strainPeaks.reduce((a, v) => a + v, 0) * this.starsPerDouble, 0.8);
1068
+ }
1265
1069
  }
1266
1070
 
1267
1071
  /**
@@ -1270,9 +1074,9 @@ class DroidFlashlight extends DroidSkill {
1270
1074
  * This class should be considered an "evaluating" class and not persisted.
1271
1075
  */
1272
1076
  class RhythmEvaluator {
1273
- static rhythmMultiplier = 0.75;
1274
- static historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1275
1077
  }
1078
+ RhythmEvaluator.rhythmMultiplier = 0.75;
1079
+ RhythmEvaluator.historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1276
1080
 
1277
1081
  /**
1278
1082
  * An evaluator for calculating osu!droid Rhythm skill.
@@ -1330,8 +1134,8 @@ class DroidRhythmEvaluator extends RhythmEvaluator {
1330
1134
  Math.min(0.5, Math.pow(Math.sin(Math.PI /
1331
1135
  (Math.min(prevDelta, currentDelta) /
1332
1136
  Math.max(prevDelta, currentDelta))), 2));
1333
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - greatWindow * 0.4) /
1334
- (greatWindow * 0.4));
1137
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - greatWindow * 0.6) /
1138
+ (greatWindow * 0.6));
1335
1139
  let effectiveRatio = windowPenalty * currentRatio;
1336
1140
  if (firstDeltaSwitch) {
1337
1141
  if (prevDelta <= 1.25 * currentDelta &&
@@ -1408,31 +1212,39 @@ class DroidRhythmEvaluator extends RhythmEvaluator {
1408
1212
  * Represents the skill required to properly follow a beatmap's rhythm.
1409
1213
  */
1410
1214
  class DroidRhythm extends DroidSkill {
1411
- skillMultiplier = 1;
1412
- reducedSectionCount = 5;
1413
- reducedSectionBaseline = 0.75;
1414
- strainDecayBase = 0.3;
1415
- starsPerDouble = 1.75;
1416
- currentRhythm = 1;
1417
- hitWindow;
1418
1215
  constructor(mods, overallDifficulty) {
1419
1216
  super(mods);
1217
+ this.reducedSectionCount = 5;
1218
+ this.reducedSectionBaseline = 0.75;
1219
+ this.strainDecayBase = 0.3;
1220
+ this.starsPerDouble = 1.75;
1221
+ this.currentRhythmStrain = 0;
1222
+ this.currentRhythmMultiplier = 1;
1420
1223
  this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1421
1224
  }
1422
1225
  strainValueAt(current) {
1423
- this.currentRhythm = DroidRhythmEvaluator.evaluateDifficultyOf(current, this.hitWindow.hitWindowFor300());
1424
- this.currentStrain *= this.strainDecay(current.deltaTime);
1425
- this.currentStrain += this.currentRhythm - 1;
1426
- return this.currentStrain;
1226
+ this.currentRhythmMultiplier =
1227
+ DroidRhythmEvaluator.evaluateDifficultyOf(current, this.hitWindow.hitWindowFor300());
1228
+ this.currentRhythmStrain *= this.strainDecay(current.deltaTime);
1229
+ this.currentRhythmStrain += this.currentRhythmMultiplier - 1;
1230
+ return this.currentRhythmStrain;
1231
+ }
1232
+ calculateInitialStrain(time, current) {
1233
+ var _a, _b;
1234
+ return (this.currentRhythmStrain *
1235
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
1236
+ }
1237
+ getObjectStrain() {
1238
+ return this.currentRhythmStrain;
1427
1239
  }
1428
1240
  saveToHitObject(current) {
1429
- current.rhythmStrain = this.currentStrain;
1430
- current.rhythmMultiplier = this.currentRhythm;
1241
+ current.rhythmStrain = this.currentRhythmStrain;
1242
+ current.rhythmMultiplier = this.currentRhythmMultiplier;
1431
1243
  }
1432
1244
  }
1433
1245
 
1434
1246
  /**
1435
- * An evaluator for calculating osu!droid Visual skill.
1247
+ * An evaluator for calculating osu!droid visual skill.
1436
1248
  */
1437
1249
  class DroidVisualEvaluator {
1438
1250
  /**
@@ -1453,7 +1265,8 @@ class DroidVisualEvaluator {
1453
1265
  static evaluateDifficultyOf(current, isHiddenMod, withSliders) {
1454
1266
  if (current.object instanceof osuBase.Spinner ||
1455
1267
  // Exclude overlapping objects that can be tapped at once.
1456
- current.isOverlapping(true)) {
1268
+ current.isOverlapping(true) ||
1269
+ current.index === 0) {
1457
1270
  return 0;
1458
1271
  }
1459
1272
  // Start with base density and give global bonus for Hidden.
@@ -1475,28 +1288,30 @@ class DroidVisualEvaluator {
1475
1288
  }
1476
1289
  // Do not consider objects that don't fall under time preempt.
1477
1290
  if (current.object.startTime - previous.object.endTime >
1478
- current.baseTimePreempt) {
1291
+ current.object.timePreempt) {
1479
1292
  break;
1480
1293
  }
1481
1294
  strain +=
1482
1295
  (1 -
1483
- current.opacityAt(previous.object.startTime, isHiddenMod, osuBase.Modes.droid)) /
1296
+ current.opacityAt(previous.object.startTime, isHiddenMod)) /
1484
1297
  4;
1485
1298
  }
1486
- // Scale the value with overlapping factor.
1487
- strain /= 10 * (1 + current.overlappingFactor);
1488
1299
  if (current.timePreempt < 400) {
1489
1300
  // Give bonus for AR higher than 10.33.
1490
- strain += Math.pow(400 - current.timePreempt, 1.3) / 100;
1301
+ strain += Math.pow(400 - current.timePreempt, 1.35) / 100;
1491
1302
  }
1303
+ // Scale the value with overlapping factor.
1304
+ strain /= 10 * (1 + current.overlappingFactor);
1492
1305
  if (current.object instanceof osuBase.Slider && withSliders) {
1493
- const scalingFactor = 50 / current.object.getRadius(osuBase.Modes.droid);
1494
- // Reward sliders based on velocity.
1306
+ const scalingFactor = 50 / current.object.radius;
1307
+ // Invert the scaling factor to determine the true travel distance independent of circle size.
1308
+ const pixelTravelDistance = current.object.lazyTravelDistance / scalingFactor;
1309
+ const currentVelocity = pixelTravelDistance / current.travelTime;
1495
1310
  strain +=
1496
- // Avoid overbuffing extremely fast sliders.
1497
- Math.min(6, current.velocity * 1.5) *
1498
- // Scale with distance travelled to avoid overbuffing fast sliders with short distance.
1499
- Math.min(1, current.travelDistance / scalingFactor / 125);
1311
+ // Reward sliders based on velocity, while also avoiding overbuffing extremely fast sliders.
1312
+ Math.min(6, currentVelocity * 1.5) *
1313
+ // Longer sliders require more reading.
1314
+ (pixelTravelDistance / 100);
1500
1315
  let cumulativeStrainTime = 0;
1501
1316
  // Reward for velocity changes based on last few sliders.
1502
1317
  for (let i = 0; i < Math.min(current.index, 4); ++i) {
@@ -1507,52 +1322,18 @@ class DroidVisualEvaluator {
1507
1322
  last.isOverlapping(true)) {
1508
1323
  continue;
1509
1324
  }
1325
+ // Invert the scaling factor to determine the true travel distance independent of circle size.
1326
+ const pixelTravelDistance = last.object.lazyTravelDistance / scalingFactor;
1327
+ const lastVelocity = pixelTravelDistance / last.travelTime;
1510
1328
  strain +=
1511
- // Avoid overbuffing extremely fast velocity changes.
1512
- Math.min(10, 2.5 * Math.abs(current.velocity - last.velocity)) *
1513
- // Scale with distance travelled to avoid overbuffing fast sliders with short distance.
1514
- Math.min(1, last.travelDistance / scalingFactor / 100) *
1515
- // Scale with cumulative strain time to avoid overbuffing past sliders.
1516
- Math.min(1, 300 / cumulativeStrainTime);
1517
- }
1518
- }
1519
- // Reward for rhythm changes.
1520
- if (current.rhythmMultiplier > 1) {
1521
- let rhythmBonus = (current.rhythmMultiplier - 1) / 20;
1522
- // Rhythm changes are harder to read in Hidden.
1523
- // Add additional bonus for Hidden.
1524
- if (isHiddenMod) {
1525
- rhythmBonus += (current.rhythmMultiplier - 1) / 25;
1526
- }
1527
- // Rhythm changes are harder to read when objects are stacked together.
1528
- // Scale rhythm bonus based on the stack of past objects.
1529
- const diameter = 2 * current.object.getRadius(osuBase.Modes.droid);
1530
- let cumulativeStrainTime = 0;
1531
- for (let i = 0; i < Math.min(current.index, 5); ++i) {
1532
- const previous = current.previous(i);
1533
- if (previous.object instanceof osuBase.Spinner ||
1534
- // Exclude overlapping objects that can be tapped at once.
1535
- previous.isOverlapping(true)) {
1536
- continue;
1537
- }
1538
- const jumpDistance = current.object
1539
- .getStackedPosition(osuBase.Modes.droid)
1540
- .getDistance(previous.object.getStackedEndPosition(osuBase.Modes.droid));
1541
- cumulativeStrainTime += previous.strainTime;
1542
- rhythmBonus +=
1543
- // Scale the bonus with diameter.
1544
- osuBase.MathUtils.clamp((0.5 - jumpDistance / diameter) / 10, 0, 0.05) *
1545
- // Scale with cumulative strain time to avoid overbuffing past objects.
1329
+ // Reward past sliders based on velocity changes, while also
1330
+ // avoiding overbuffing extremely fast velocity changes.
1331
+ Math.min(10, 2.5 * Math.abs(currentVelocity - lastVelocity)) *
1332
+ // Longer sliders require more reading.
1333
+ (pixelTravelDistance / 125) *
1334
+ // Avoid overbuffing past sliders.
1546
1335
  Math.min(1, 300 / cumulativeStrainTime);
1547
- // Give a larger bonus for Hidden.
1548
- if (isHiddenMod) {
1549
- rhythmBonus +=
1550
- (1 -
1551
- current.opacityAt(previous.object.startTime, isHiddenMod, osuBase.Modes.droid)) /
1552
- 20;
1553
- }
1554
1336
  }
1555
- strain += rhythmBonus;
1556
1337
  }
1557
1338
  return strain;
1558
1339
  }
@@ -1562,31 +1343,212 @@ class DroidVisualEvaluator {
1562
1343
  * Represents the skill required to read every object in the map.
1563
1344
  */
1564
1345
  class DroidVisual extends DroidSkill {
1565
- starsPerDouble = 1.025;
1566
- reducedSectionCount = 10;
1567
- reducedSectionBaseline = 0.75;
1568
- skillMultiplier = 10;
1569
- strainDecayBase = 0.1;
1570
- isHidden;
1571
- withsliders;
1572
1346
  constructor(mods, withSliders) {
1573
1347
  super(mods);
1348
+ this.starsPerDouble = 1.025;
1349
+ this.reducedSectionCount = 10;
1350
+ this.reducedSectionBaseline = 0.75;
1351
+ this.strainDecayBase = 0.1;
1352
+ this.currentVisualStrain = 0;
1353
+ this.currentRhythmMultiplier = 1;
1354
+ this.skillMultiplier = 10;
1574
1355
  this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1575
- this.withsliders = withSliders;
1356
+ this.withSliders = withSliders;
1576
1357
  }
1577
1358
  strainValueAt(current) {
1578
- this.currentStrain *= this.strainDecay(current.deltaTime);
1579
- this.currentStrain +=
1580
- DroidVisualEvaluator.evaluateDifficultyOf(current, this.isHidden, this.withsliders) * this.skillMultiplier;
1581
- return this.currentStrain;
1359
+ this.currentVisualStrain *= this.strainDecay(current.deltaTime);
1360
+ this.currentVisualStrain +=
1361
+ DroidVisualEvaluator.evaluateDifficultyOf(current, this.isHidden, this.withSliders) * this.skillMultiplier;
1362
+ this.currentRhythmMultiplier = current.rhythmMultiplier;
1363
+ return this.currentVisualStrain * this.currentRhythmMultiplier;
1364
+ }
1365
+ calculateInitialStrain(time, current) {
1366
+ var _a, _b;
1367
+ return (this.currentVisualStrain *
1368
+ this.currentRhythmMultiplier *
1369
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
1370
+ }
1371
+ getObjectStrain() {
1372
+ return this.currentVisualStrain * this.currentRhythmMultiplier;
1582
1373
  }
1583
1374
  saveToHitObject(current) {
1584
- if (this.withsliders) {
1585
- current.visualStrainWithSliders = this.currentStrain;
1375
+ const strain = this.currentVisualStrain * this.currentRhythmMultiplier;
1376
+ if (this.withSliders) {
1377
+ current.visualStrainWithSliders = strain;
1586
1378
  }
1587
1379
  else {
1588
- current.visualStrainWithoutSliders = this.currentStrain;
1380
+ current.visualStrainWithoutSliders = strain;
1381
+ }
1382
+ }
1383
+ }
1384
+
1385
+ /**
1386
+ * Represents an osu!droid hit object with difficulty calculation values.
1387
+ */
1388
+ class DroidDifficultyHitObject extends DifficultyHitObject {
1389
+ get scalingFactor() {
1390
+ const radius = this.object.radius;
1391
+ // We will scale distances by this factor, so we can assume a uniform CircleSize among beatmaps.
1392
+ let scalingFactor = this.normalizedRadius / radius;
1393
+ // High circle size (small CS) bonus
1394
+ if (radius < this.radiusBuffThreshold) {
1395
+ scalingFactor *=
1396
+ 1 + Math.pow((this.radiusBuffThreshold - radius) / 50, 2);
1397
+ }
1398
+ return scalingFactor;
1399
+ }
1400
+ /**
1401
+ * Note: You **must** call `computeProperties` at some point due to how TypeScript handles
1402
+ * overridden properties (see [this](https://github.com/microsoft/TypeScript/issues/1617) GitHub issue).
1403
+ *
1404
+ * @param object The underlying hitobject.
1405
+ * @param lastObject The hitobject before this hitobject.
1406
+ * @param lastLastObject The hitobject before the last hitobject.
1407
+ * @param difficultyHitObjects All difficulty hitobjects in the processed beatmap.
1408
+ * @param clockRate The clock rate of the beatmap.
1409
+ * @param isForceAR Whether force AR is enabled.
1410
+ */
1411
+ constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate, isForceAR) {
1412
+ super(object, lastObject, lastLastObject, difficultyHitObjects, clockRate);
1413
+ /**
1414
+ * The tap strain generated by the hitobject.
1415
+ */
1416
+ this.tapStrain = 0;
1417
+ /**
1418
+ * The tap strain generated by the hitobject if `strainTime` isn't modified by
1419
+ * OD. This is used in three-finger detection.
1420
+ */
1421
+ this.originalTapStrain = 0;
1422
+ /**
1423
+ * The rhythm strain generated by the hitobject.
1424
+ */
1425
+ this.rhythmStrain = 0;
1426
+ /**
1427
+ * The flashlight strain generated by the hitobject if sliders are considered.
1428
+ */
1429
+ this.flashlightStrainWithSliders = 0;
1430
+ /**
1431
+ * The flashlight strain generated by the hitobject if sliders are not considered.
1432
+ */
1433
+ this.flashlightStrainWithoutSliders = 0;
1434
+ /**
1435
+ * The visual strain generated by the hitobject if sliders are considered.
1436
+ */
1437
+ this.visualStrainWithSliders = 0;
1438
+ /**
1439
+ * The visual strain generated by the hitobject if sliders are not considered.
1440
+ */
1441
+ this.visualStrainWithoutSliders = 0;
1442
+ /**
1443
+ * The note density of the hitobject.
1444
+ */
1445
+ this.noteDensity = 1;
1446
+ /**
1447
+ * The overlapping factor of the hitobject.
1448
+ *
1449
+ * This is used to scale visual skill.
1450
+ */
1451
+ this.overlappingFactor = 0;
1452
+ this.radiusBuffThreshold = 70;
1453
+ this.mode = osuBase.Modes.droid;
1454
+ this.maximumSliderRadius = this.normalizedRadius * 2;
1455
+ this.timePreempt = object.timePreempt;
1456
+ if (!isForceAR) {
1457
+ this.timePreempt /= clockRate;
1458
+ }
1459
+ }
1460
+ computeProperties(clockRate, hitObjects) {
1461
+ super.computeProperties(clockRate, hitObjects);
1462
+ this.setVisuals(clockRate, hitObjects);
1463
+ }
1464
+ /**
1465
+ * Determines whether this hitobject is considered overlapping with the hitobject before it.
1466
+ *
1467
+ * Keep in mind that "overlapping" in this case is overlapping to the point where both hitobjects
1468
+ * can be hit with just a single tap in osu!droid.
1469
+ *
1470
+ * @param considerDistance Whether to consider the distance between both hitobjects.
1471
+ * @returns Whether the hitobject is considered overlapping.
1472
+ */
1473
+ isOverlapping(considerDistance) {
1474
+ if (this.object instanceof osuBase.Spinner) {
1475
+ return false;
1476
+ }
1477
+ const previous = this.previous(0);
1478
+ if (!previous || previous.object instanceof osuBase.Spinner) {
1479
+ return false;
1480
+ }
1481
+ if (this.deltaTime >= 5) {
1482
+ return false;
1483
+ }
1484
+ if (considerDistance) {
1485
+ const endPosition = this.object.getStackedPosition(osuBase.Modes.droid);
1486
+ let distance = previous.object
1487
+ .getStackedEndPosition(osuBase.Modes.droid)
1488
+ .getDistance(endPosition);
1489
+ if (previous.object instanceof osuBase.Slider &&
1490
+ previous.object.lazyEndPosition) {
1491
+ distance = Math.min(distance, previous.object.lazyEndPosition.getDistance(endPosition));
1492
+ }
1493
+ return distance <= 2 * this.object.radius;
1494
+ }
1495
+ return true;
1496
+ }
1497
+ setVisuals(clockRate, hitObjects) {
1498
+ // We'll have two visible object arrays. The first array contains objects before the current object starts in a reversed order,
1499
+ // while the second array contains objects after the current object ends.
1500
+ // For overlapping factor, we also need to consider previous visible objects.
1501
+ const prevVisibleObjects = [];
1502
+ const nextVisibleObjects = [];
1503
+ for (let j = this.index + 2; j < hitObjects.length; ++j) {
1504
+ const o = hitObjects[j];
1505
+ if (o instanceof osuBase.Spinner) {
1506
+ continue;
1507
+ }
1508
+ if (o.startTime / clockRate > this.endTime + this.timePreempt) {
1509
+ break;
1510
+ }
1511
+ nextVisibleObjects.push(o);
1512
+ }
1513
+ for (let j = 0; j < this.index; ++j) {
1514
+ const prev = this.previous(j);
1515
+ if (prev.object instanceof osuBase.Spinner) {
1516
+ continue;
1517
+ }
1518
+ if (prev.startTime >= this.startTime) {
1519
+ continue;
1520
+ }
1521
+ if (prev.startTime < this.startTime - this.timePreempt) {
1522
+ break;
1523
+ }
1524
+ prevVisibleObjects.push(prev.object);
1525
+ }
1526
+ for (const hitObject of prevVisibleObjects) {
1527
+ const distance = this.object
1528
+ .getStackedPosition(this.mode)
1529
+ .getDistance(hitObject.getStackedEndPosition(this.mode));
1530
+ const deltaTime = this.startTime - hitObject.endTime / clockRate;
1531
+ this.applyToOverlappingFactor(distance, deltaTime);
1589
1532
  }
1533
+ for (const hitObject of nextVisibleObjects) {
1534
+ const distance = hitObject
1535
+ .getStackedPosition(this.mode)
1536
+ .getDistance(this.object.getStackedEndPosition(this.mode));
1537
+ const deltaTime = hitObject.startTime / clockRate - this.endTime;
1538
+ if (deltaTime >= 0) {
1539
+ this.noteDensity += 1 - deltaTime / this.timePreempt;
1540
+ }
1541
+ this.applyToOverlappingFactor(distance, deltaTime);
1542
+ }
1543
+ }
1544
+ applyToOverlappingFactor(distance, deltaTime) {
1545
+ // Penalize objects that are too close to the object in both distance
1546
+ // and delta time to prevent stream maps from being overweighted.
1547
+ this.overlappingFactor +=
1548
+ Math.max(0, 1 - distance / (2.5 * this.object.radius)) *
1549
+ (7.5 /
1550
+ (1 +
1551
+ Math.exp(0.15 * (Math.max(deltaTime, this.minDeltaTime) - 75))));
1590
1552
  }
1591
1553
  }
1592
1554
 
@@ -1594,56 +1556,97 @@ class DroidVisual extends DroidSkill {
1594
1556
  * A difficulty calculator for osu!droid gamemode.
1595
1557
  */
1596
1558
  class DroidDifficultyCalculator extends DifficultyCalculator {
1559
+ constructor() {
1560
+ super(...arguments);
1561
+ this.attributes = {
1562
+ mode: "rebalance",
1563
+ tapDifficulty: 0,
1564
+ rhythmDifficulty: 0,
1565
+ visualDifficulty: 0,
1566
+ aimNoteCount: 0,
1567
+ mods: [],
1568
+ starRating: 0,
1569
+ maxCombo: 0,
1570
+ aimDifficulty: 0,
1571
+ flashlightDifficulty: 0,
1572
+ speedNoteCount: 0,
1573
+ sliderFactor: 0,
1574
+ clockRate: 1,
1575
+ approachRate: 0,
1576
+ overallDifficulty: 0,
1577
+ hitCircleCount: 0,
1578
+ sliderCount: 0,
1579
+ spinnerCount: 0,
1580
+ aimDifficultStrainCount: 0,
1581
+ tapDifficultStrainCount: 0,
1582
+ flashlightDifficultStrainCount: 0,
1583
+ visualDifficultStrainCount: 0,
1584
+ flashlightSliderFactor: 0,
1585
+ visualSliderFactor: 0,
1586
+ possibleThreeFingeredSections: [],
1587
+ difficultSliders: [],
1588
+ averageSpeedDeltaTime: 0,
1589
+ vibroFactor: 1,
1590
+ };
1591
+ this.difficultyMultiplier = 0.18;
1592
+ this.mode = osuBase.Modes.droid;
1593
+ }
1597
1594
  /**
1598
1595
  * The aim star rating of the beatmap.
1599
1596
  */
1600
- aim = 0;
1597
+ get aim() {
1598
+ return this.attributes.aimDifficulty;
1599
+ }
1601
1600
  /**
1602
1601
  * The tap star rating of the beatmap.
1603
1602
  */
1604
- tap = 0;
1603
+ get tap() {
1604
+ return this.attributes.tapDifficulty;
1605
+ }
1605
1606
  /**
1606
1607
  * The rhythm star rating of the beatmap.
1607
1608
  */
1608
- rhythm = 0;
1609
+ get rhythm() {
1610
+ return this.attributes.rhythmDifficulty;
1611
+ }
1609
1612
  /**
1610
1613
  * The flashlight star rating of the beatmap.
1611
1614
  */
1612
- flashlight = 0;
1615
+ get flashlight() {
1616
+ return this.attributes.flashlightDifficulty;
1617
+ }
1613
1618
  /**
1614
1619
  * The visual star rating of the beatmap.
1615
1620
  */
1616
- visual = 0;
1617
- /**
1618
- * The strain threshold to start detecting for possible three-fingered section.
1619
- *
1620
- * Increasing this number will result in less sections being flagged.
1621
- */
1622
- static threeFingerStrainThreshold = 175;
1623
- attributes = {
1624
- tapDifficulty: 0,
1625
- rhythmDifficulty: 0,
1626
- visualDifficulty: 0,
1627
- aimNoteCount: 0,
1628
- mods: [],
1629
- starRating: 0,
1630
- maxCombo: 0,
1631
- aimDifficulty: 0,
1632
- flashlightDifficulty: 0,
1633
- speedNoteCount: 0,
1634
- sliderFactor: 0,
1635
- approachRate: 0,
1636
- overallDifficulty: 0,
1637
- hitCircleCount: 0,
1638
- sliderCount: 0,
1639
- spinnerCount: 0,
1640
- flashlightSliderFactor: 0,
1641
- visualSliderFactor: 0,
1642
- possibleThreeFingeredSections: [],
1643
- difficultSliders: [],
1644
- };
1645
- difficultyMultiplier = 0.18;
1646
- mode = osuBase.Modes.droid;
1621
+ get visual() {
1622
+ return this.attributes.visualDifficulty;
1623
+ }
1624
+ get cacheableAttributes() {
1625
+ return {
1626
+ tapDifficulty: this.tap,
1627
+ rhythmDifficulty: this.rhythm,
1628
+ visualDifficulty: this.visual,
1629
+ mods: osuBase.ModUtil.modsToOsuString(this.attributes.mods),
1630
+ starRating: this.total,
1631
+ maxCombo: this.attributes.maxCombo,
1632
+ aimDifficulty: this.aim,
1633
+ flashlightDifficulty: this.flashlight,
1634
+ speedNoteCount: this.attributes.speedNoteCount,
1635
+ sliderFactor: this.attributes.sliderFactor,
1636
+ clockRate: this.attributes.clockRate,
1637
+ approachRate: this.attributes.approachRate,
1638
+ overallDifficulty: this.attributes.overallDifficulty,
1639
+ hitCircleCount: this.attributes.hitCircleCount,
1640
+ sliderCount: this.attributes.sliderCount,
1641
+ spinnerCount: this.attributes.spinnerCount,
1642
+ aimDifficultStrainCount: this.attributes.aimDifficultStrainCount,
1643
+ tapDifficultStrainCount: this.attributes.tapDifficultStrainCount,
1644
+ flashlightDifficultStrainCount: this.attributes.flashlightDifficultStrainCount,
1645
+ visualDifficultStrainCount: this.attributes.visualDifficultStrainCount,
1646
+ averageSpeedDeltaTime: this.attributes.averageSpeedDeltaTime,
1647
+ vibroFactor: this.attributes.vibroFactor,
1648
+ };
1649
+ }
1647
1650
  /**
1648
1651
  * Calculates the aim star rating of the beatmap and stores it in this instance.
1649
1652
  */
@@ -1657,26 +1660,19 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1657
1660
  * Calculates the tap star rating of the beatmap and stores it in this instance.
1658
1661
  */
1659
1662
  calculateTap() {
1660
- const tapSkill = new DroidTap(this.mods, this.stats.od);
1661
- this.calculateSkills(tapSkill);
1662
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1663
- this.tap = this.attributes.tapDifficulty = 0;
1664
- this.attributes.possibleThreeFingeredSections = [];
1665
- }
1666
- else {
1667
- this.postCalculateTap(tapSkill);
1668
- }
1669
- this.calculateSpeedAttributes();
1663
+ const od = this.difficultyStatistics.overallDifficulty;
1664
+ const tapSkillCheese = new DroidTap(this.mods, od, true);
1665
+ const tapSkillNoCheese = new DroidTap(this.mods, od, false);
1666
+ this.calculateSkills(tapSkillCheese, tapSkillNoCheese);
1667
+ const tapSkillVibro = new DroidTap(this.mods, od, true, tapSkillCheese.relevantDeltaTime());
1668
+ this.calculateSkills(tapSkillVibro);
1669
+ this.postCalculateTap(tapSkillCheese, tapSkillVibro);
1670
1670
  }
1671
1671
  /**
1672
1672
  * Calculates the rhythm star rating of the beatmap and stores it in this instance.
1673
1673
  */
1674
1674
  calculateRhythm() {
1675
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1676
- this.rhythm = this.attributes.rhythmDifficulty = 0;
1677
- return;
1678
- }
1679
- const rhythmSkill = new DroidRhythm(this.mods, this.stats.od);
1675
+ const rhythmSkill = new DroidRhythm(this.mods, this.difficultyStatistics.overallDifficulty);
1680
1676
  this.calculateSkills(rhythmSkill);
1681
1677
  this.postCalculateRhythm(rhythmSkill);
1682
1678
  }
@@ -1694,7 +1690,7 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1694
1690
  */
1695
1691
  calculateVisual() {
1696
1692
  if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1697
- this.visual = this.attributes.visualDifficulty = 0;
1693
+ this.attributes.visualDifficulty = 0;
1698
1694
  return;
1699
1695
  }
1700
1696
  const visualSkill = new DroidVisual(this.mods, true);
@@ -1716,55 +1712,35 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1716
1712
  if (basePerformanceValue > 1e-5) {
1717
1713
  // Document for formula derivation:
1718
1714
  // https://docs.google.com/document/d/10DZGYYSsT_yjz2Mtp6yIJld0Rqx4E-vVHupCqiM4TNI/edit
1719
- this.total = this.attributes.starRating =
1715
+ this.attributes.starRating =
1720
1716
  0.027 *
1721
1717
  (Math.cbrt((100000 / Math.pow(2, 1 / 1.1)) * basePerformanceValue) +
1722
1718
  4);
1723
1719
  }
1724
1720
  else {
1725
- this.total = this.attributes.starRating = 0;
1721
+ this.attributes.starRating = 0;
1726
1722
  }
1727
1723
  }
1728
1724
  calculateAll() {
1729
1725
  const skills = this.createSkills();
1730
- const isRelax = this.mods.some((m) => m instanceof osuBase.ModRelax);
1731
- if (isRelax) {
1732
- // Remove visual skills to reduce overhead.
1733
- skills.pop();
1734
- skills.pop();
1735
- }
1736
1726
  this.calculateSkills(...skills);
1737
1727
  const aimSkill = skills[0];
1738
- const aimSkillWithoutSliders = skills[1];
1739
- const rhythmSkill = skills[2];
1740
- const tapSkill = skills[3];
1741
- const flashlightSkill = skills[4];
1742
- const flashlightSkillWithoutSliders = skills[5];
1743
- const visualSkill = skills[6] ?? null;
1744
- const visualSkillWithoutSliders = skills[7] ?? null;
1745
- this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
1746
- if (isRelax) {
1747
- this.tap = this.attributes.tapDifficulty = 0;
1748
- }
1749
- else {
1750
- this.postCalculateTap(tapSkill);
1751
- }
1752
- this.calculateSpeedAttributes();
1753
- if (!isRelax) {
1754
- this.postCalculateRhythm(rhythmSkill);
1755
- }
1728
+ const aimSkillWithoutSliders = skills[1];
1729
+ const rhythmSkill = skills[2];
1730
+ const tapSkillCheese = skills[3];
1731
+ const flashlightSkill = skills[5];
1732
+ const flashlightSkillWithoutSliders = skills[6];
1733
+ const visualSkill = skills[7];
1734
+ const visualSkillWithoutSliders = skills[8];
1735
+ const tapSkillVibro = new DroidTap(this.mods, this.difficultyStatistics.overallDifficulty, true, tapSkillCheese.relevantDeltaTime());
1736
+ this.calculateSkills(tapSkillVibro);
1737
+ this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
1738
+ this.postCalculateTap(tapSkillCheese, tapSkillVibro);
1739
+ this.postCalculateRhythm(rhythmSkill);
1756
1740
  this.postCalculateFlashlight(flashlightSkill, flashlightSkillWithoutSliders);
1757
- if (visualSkill && visualSkillWithoutSliders) {
1758
- this.postCalculateVisual(visualSkill, visualSkillWithoutSliders);
1759
- }
1760
- else {
1761
- this.visual = this.attributes.visualDifficulty = 0;
1762
- }
1741
+ this.postCalculateVisual(visualSkill, visualSkillWithoutSliders);
1763
1742
  this.calculateTotal();
1764
1743
  }
1765
- /**
1766
- * Returns a string representative of the class.
1767
- */
1768
1744
  toString() {
1769
1745
  return (this.total.toFixed(2) +
1770
1746
  " stars (" +
@@ -1779,16 +1755,42 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1779
1755
  this.visual.toFixed(2) +
1780
1756
  " visual)");
1781
1757
  }
1782
- /**
1783
- * Creates skills to be calculated.
1784
- */
1758
+ generateDifficultyHitObjects(beatmap) {
1759
+ var _a, _b;
1760
+ const difficultyObjects = [];
1761
+ const { objects } = beatmap.hitObjects;
1762
+ const difficultyAdjustMod = this.mods.find((m) => m instanceof osuBase.ModDifficultyAdjust);
1763
+ for (let i = 0; i < objects.length; ++i) {
1764
+ 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, this.difficultyStatistics.overallSpeedMultiplier, (difficultyAdjustMod === null || difficultyAdjustMod === void 0 ? void 0 : difficultyAdjustMod.ar) !== undefined);
1765
+ difficultyObject.computeProperties(this.difficultyStatistics.overallSpeedMultiplier, objects);
1766
+ difficultyObjects.push(difficultyObject);
1767
+ }
1768
+ return difficultyObjects;
1769
+ }
1770
+ computeDifficultyStatistics(options) {
1771
+ var _a;
1772
+ const { difficulty } = this.beatmap;
1773
+ return osuBase.calculateDroidDifficultyStatistics({
1774
+ circleSize: difficulty.cs,
1775
+ approachRate: (_a = difficulty.ar) !== null && _a !== void 0 ? _a : difficulty.od,
1776
+ overallDifficulty: difficulty.od,
1777
+ healthDrain: difficulty.hp,
1778
+ mods: this.mods,
1779
+ customSpeedMultiplier: options === null || options === void 0 ? void 0 : options.customSpeedMultiplier,
1780
+ oldStatistics: options === null || options === void 0 ? void 0 : options.oldStatistics,
1781
+ });
1782
+ }
1785
1783
  createSkills() {
1784
+ const od = this.difficultyStatistics.overallDifficulty;
1786
1785
  return [
1787
1786
  new DroidAim(this.mods, true),
1788
1787
  new DroidAim(this.mods, false),
1789
1788
  // Tap skill depends on rhythm skill, so we put it first
1790
- new DroidRhythm(this.mods, this.stats.od),
1791
- new DroidTap(this.mods, this.stats.od),
1789
+ new DroidRhythm(this.mods, od),
1790
+ // Cheesability tap
1791
+ new DroidTap(this.mods, od, true),
1792
+ // Non-cheesability tap
1793
+ new DroidTap(this.mods, od, false),
1792
1794
  new DroidFlashlight(this.mods, true),
1793
1795
  new DroidFlashlight(this.mods, false),
1794
1796
  new DroidVisual(this.mods, true),
@@ -1804,152 +1806,119 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1804
1806
  postCalculateAim(aimSkill, aimSkillWithoutSliders) {
1805
1807
  this.strainPeaks.aimWithSliders = aimSkill.strainPeaks;
1806
1808
  this.strainPeaks.aimWithoutSliders = aimSkillWithoutSliders.strainPeaks;
1807
- this.aim = this.starValue(aimSkill.difficultyValue());
1809
+ this.attributes.aimDifficulty = this.starValue(aimSkill.difficultyValue());
1808
1810
  if (this.aim) {
1809
1811
  this.attributes.sliderFactor =
1810
1812
  this.starValue(aimSkillWithoutSliders.difficultyValue()) /
1811
1813
  this.aim;
1812
1814
  }
1813
1815
  if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1814
- this.aim *= 0.9;
1816
+ this.attributes.aimDifficulty *= 0.9;
1815
1817
  }
1816
- this.attributes.aimDifficulty = this.aim;
1818
+ this.attributes.aimDifficultStrainCount =
1819
+ aimSkill.countDifficultStrains();
1817
1820
  this.calculateAimAttributes();
1818
1821
  }
1819
1822
  /**
1820
1823
  * Calculates aim-related attributes.
1821
1824
  */
1822
1825
  calculateAimAttributes() {
1823
- const objectStrains = [];
1824
- let maxStrain = 0;
1825
- // Take the top 15% most difficult sliders based on velocity.
1826
1826
  const topDifficultSliders = [];
1827
1827
  for (let i = 0; i < this.objects.length; ++i) {
1828
1828
  const object = this.objects[i];
1829
- objectStrains.push(object.aimStrainWithSliders);
1830
- maxStrain = Math.max(maxStrain, object.aimStrainWithSliders);
1831
1829
  const velocity = object.travelDistance / object.travelTime;
1832
1830
  if (velocity > 0) {
1833
1831
  topDifficultSliders.push({
1834
1832
  index: i,
1835
1833
  velocity: velocity,
1836
1834
  });
1837
- topDifficultSliders.sort((a, b) => b.velocity - a.velocity);
1838
- while (topDifficultSliders.length >
1839
- Math.ceil(0.15 * this.beatmap.hitObjects.sliders)) {
1840
- topDifficultSliders.pop();
1841
- }
1842
1835
  }
1843
1836
  }
1844
- if (maxStrain) {
1845
- this.attributes.aimNoteCount = objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
1846
- }
1847
1837
  const velocitySum = topDifficultSliders.reduce((a, v) => a + v.velocity, 0);
1848
1838
  for (const slider of topDifficultSliders) {
1849
- this.attributes.difficultSliders.push({
1850
- index: slider.index,
1851
- difficultyRating: slider.velocity / velocitySum,
1852
- });
1839
+ const difficultyRating = slider.velocity / velocitySum;
1840
+ // Only consider sliders that are fast enough.
1841
+ if (difficultyRating > 0.02) {
1842
+ this.attributes.difficultSliders.push({
1843
+ index: slider.index,
1844
+ difficultyRating: slider.velocity / velocitySum,
1845
+ });
1846
+ }
1847
+ }
1848
+ this.attributes.difficultSliders.sort((a, b) => b.difficultyRating - a.difficultyRating);
1849
+ // Take the top 15% most difficult sliders.
1850
+ while (this.attributes.difficultSliders.length >
1851
+ Math.ceil(0.15 * this.beatmap.hitObjects.sliders)) {
1852
+ this.attributes.difficultSliders.pop();
1853
1853
  }
1854
1854
  }
1855
1855
  /**
1856
1856
  * Called after tap skill calculation.
1857
1857
  *
1858
- * @param tapSkill The tap skill.
1858
+ * @param tapSkillCheese The tap skill that considers cheesing.
1859
+ * @param tapSkillVibro The tap skill that considers vibro.
1859
1860
  */
1860
- postCalculateTap(tapSkill) {
1861
- this.strainPeaks.speed = tapSkill.strainPeaks;
1862
- this.tap = this.attributes.tapDifficulty = this.starValue(tapSkill.difficultyValue());
1861
+ postCalculateTap(tapSkillCheese, tapSkillVibro) {
1862
+ this.strainPeaks.speed = tapSkillCheese.strainPeaks;
1863
+ this.attributes.tapDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
1864
+ ? 0
1865
+ : this.starValue(tapSkillCheese.difficultyValue());
1866
+ if (this.tap) {
1867
+ this.attributes.vibroFactor =
1868
+ this.starValue(tapSkillVibro.difficultyValue()) / this.tap;
1869
+ }
1870
+ this.attributes.speedNoteCount = tapSkillCheese.relevantNoteCount();
1871
+ this.attributes.averageSpeedDeltaTime =
1872
+ tapSkillCheese.relevantDeltaTime();
1873
+ this.attributes.tapDifficultStrainCount =
1874
+ tapSkillCheese.countDifficultStrains();
1875
+ this.calculateTapAttributes();
1863
1876
  }
1864
1877
  /**
1865
- * Calculates speed-related attributes.
1878
+ * Calculates tap-related attributes.
1866
1879
  */
1867
- calculateSpeedAttributes() {
1880
+ calculateTapAttributes() {
1868
1881
  this.attributes.possibleThreeFingeredSections = [];
1869
- const tempSections = [];
1870
- const objectStrains = [];
1871
- let maxStrain = 0;
1872
- const maxSectionDeltaTime = 2000;
1882
+ const { threeFingerStrainThreshold } = DroidDifficultyCalculator;
1873
1883
  const minSectionObjectCount = 5;
1874
- let firstObjectIndex = 0;
1875
- for (let i = 0; i < this.objects.length - 1; ++i) {
1884
+ let inSpeedSection = false;
1885
+ let firstSpeedObjectIndex = 0;
1886
+ for (let i = 2; i < this.objects.length; ++i) {
1876
1887
  const current = this.objects[i];
1877
- const next = this.objects[i + 1];
1878
- if (i === 0) {
1879
- objectStrains.push(current.tapStrain);
1888
+ const prev = this.objects[i - 1];
1889
+ if (!inSpeedSection &&
1890
+ current.originalTapStrain >= threeFingerStrainThreshold) {
1891
+ inSpeedSection = true;
1892
+ firstSpeedObjectIndex = i;
1893
+ continue;
1880
1894
  }
1881
- objectStrains.push(next.tapStrain);
1882
- maxStrain = Math.max(current.tapStrain, maxStrain);
1883
- const realDeltaTime = next.object.startTime - current.object.endTime;
1884
- if (realDeltaTime >= maxSectionDeltaTime) {
1895
+ const currentDelta = current.deltaTime;
1896
+ const prevDelta = prev.deltaTime;
1897
+ const deltaRatio = Math.min(prevDelta, currentDelta) /
1898
+ Math.max(prevDelta, currentDelta);
1899
+ if (inSpeedSection &&
1900
+ (current.originalTapStrain < threeFingerStrainThreshold ||
1901
+ // Stop speed section on slowing down 1/2 rhythm change or anything slower.
1902
+ (prevDelta < currentDelta && deltaRatio <= 0.5) ||
1903
+ // Don't forget to manually add the last section, which would otherwise be ignored.
1904
+ i === this.objects.length - 1)) {
1905
+ const lastSpeedObjectIndex = i - (i === this.objects.length - 1 ? 0 : 1);
1906
+ inSpeedSection = false;
1885
1907
  // Ignore sections that don't meet object count requirement.
1886
- if (i - firstObjectIndex < minSectionObjectCount) {
1887
- firstObjectIndex = i + 1;
1908
+ if (i - firstSpeedObjectIndex < minSectionObjectCount) {
1888
1909
  continue;
1889
1910
  }
1890
- tempSections.push({
1891
- firstObjectIndex,
1892
- lastObjectIndex: i,
1893
- });
1894
- firstObjectIndex = i + 1;
1895
- }
1896
- }
1897
- // Don't forget to manually add the last beatmap section, which would otherwise be ignored.
1898
- if (this.objects.length - firstObjectIndex > minSectionObjectCount) {
1899
- tempSections.push({
1900
- firstObjectIndex,
1901
- lastObjectIndex: this.objects.length - 1,
1902
- });
1903
- }
1904
- // Refilter with tap strain in mind.
1905
- const { threeFingerStrainThreshold } = DroidDifficultyCalculator;
1906
- for (const section of tempSections) {
1907
- let inSpeedSection = false;
1908
- let newFirstObjectIndex = section.firstObjectIndex;
1909
- for (let i = section.firstObjectIndex; i <= section.lastObjectIndex; ++i) {
1910
- const current = this.objects[i];
1911
- if (!inSpeedSection &&
1912
- current.originalTapStrain >= threeFingerStrainThreshold) {
1913
- inSpeedSection = true;
1914
- newFirstObjectIndex = i;
1915
- continue;
1916
- }
1917
- if (inSpeedSection &&
1918
- current.originalTapStrain < threeFingerStrainThreshold) {
1919
- inSpeedSection = false;
1920
- this.attributes.possibleThreeFingeredSections.push({
1921
- firstObjectIndex: newFirstObjectIndex,
1922
- lastObjectIndex: i,
1923
- sumStrain: this.calculateThreeFingerSummedStrain(newFirstObjectIndex, i),
1924
- });
1925
- }
1926
- }
1927
- // Don't forget to manually add the last beatmap section, which would otherwise be ignored.
1928
- if (inSpeedSection) {
1929
1911
  this.attributes.possibleThreeFingeredSections.push({
1930
- firstObjectIndex: newFirstObjectIndex,
1931
- lastObjectIndex: section.lastObjectIndex,
1932
- sumStrain: this.calculateThreeFingerSummedStrain(newFirstObjectIndex, section.lastObjectIndex),
1912
+ firstObjectIndex: firstSpeedObjectIndex,
1913
+ lastObjectIndex: lastSpeedObjectIndex,
1914
+ sumStrain: Math.pow(this.objects
1915
+ .slice(firstSpeedObjectIndex, lastSpeedObjectIndex + 1)
1916
+ .reduce((a, v) => a +
1917
+ v.originalTapStrain /
1918
+ threeFingerStrainThreshold, 0), 0.75),
1933
1919
  });
1934
1920
  }
1935
1921
  }
1936
- if (maxStrain) {
1937
- this.attributes.speedNoteCount = objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
1938
- }
1939
- }
1940
- /**
1941
- * Calculates the sum of strains for possible three-fingered sections.
1942
- *
1943
- * @param firstObjectIndex The index of the first object in the section.
1944
- * @param lastObjectIndex The index of the last object in the section.
1945
- * @returns The summed strain of the section.
1946
- */
1947
- calculateThreeFingerSummedStrain(firstObjectIndex, lastObjectIndex) {
1948
- return Math.pow(this.objects
1949
- .slice(firstObjectIndex, lastObjectIndex)
1950
- .reduce((a, v) => a +
1951
- v.originalTapStrain /
1952
- DroidDifficultyCalculator.threeFingerStrainThreshold, 0), 0.75);
1953
1922
  }
1954
1923
  /**
1955
1924
  * Called after rhythm skill calculation.
@@ -1957,7 +1926,7 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1957
1926
  * @param rhythmSkill The rhythm skill.
1958
1927
  */
1959
1928
  postCalculateRhythm(rhythmSkill) {
1960
- this.rhythm = this.attributes.rhythmDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
1929
+ this.attributes.rhythmDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
1961
1930
  ? 0
1962
1931
  : this.starValue(rhythmSkill.difficultyValue());
1963
1932
  }
@@ -1969,15 +1938,17 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1969
1938
  */
1970
1939
  postCalculateFlashlight(flashlightSkill, flashlightSkillWithoutSliders) {
1971
1940
  this.strainPeaks.flashlight = flashlightSkill.strainPeaks;
1972
- this.flashlight = this.starValue(flashlightSkill.difficultyValue());
1941
+ this.attributes.flashlightDifficulty = this.starValue(flashlightSkill.difficultyValue());
1973
1942
  if (this.flashlight) {
1974
1943
  this.attributes.flashlightSliderFactor =
1975
1944
  this.starValue(flashlightSkillWithoutSliders.difficultyValue()) / this.flashlight;
1976
1945
  }
1977
1946
  if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1978
- this.flashlight *= 0.7;
1947
+ this.attributes.flashlightDifficulty *= 0.7;
1979
1948
  }
1980
1949
  this.attributes.flashlightDifficulty = this.flashlight;
1950
+ this.attributes.flashlightDifficultStrainCount =
1951
+ flashlightSkill.countDifficultStrains();
1981
1952
  }
1982
1953
  /**
1983
1954
  * Called after visual skill calculation.
@@ -1986,7 +1957,7 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1986
1957
  * @param visualSkillWithoutSliders The visual skill that doesn't consider sliders.
1987
1958
  */
1988
1959
  postCalculateVisual(visualSkillWithSliders, visualSkillWithoutSliders) {
1989
- this.visual = this.attributes.visualDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
1960
+ this.attributes.visualDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
1990
1961
  ? 0
1991
1962
  : this.starValue(visualSkillWithSliders.difficultyValue());
1992
1963
  if (this.visual) {
@@ -1994,33 +1965,52 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1994
1965
  this.starValue(visualSkillWithoutSliders.difficultyValue()) /
1995
1966
  this.visual;
1996
1967
  }
1968
+ this.attributes.visualDifficultStrainCount =
1969
+ visualSkillWithSliders.countDifficultStrains();
1997
1970
  }
1998
1971
  }
1972
+ /**
1973
+ * The strain threshold to start detecting for possible three-fingered section.
1974
+ *
1975
+ * Increasing this number will result in less sections being flagged.
1976
+ */
1977
+ DroidDifficultyCalculator.threeFingerStrainThreshold = 175;
1999
1978
 
2000
1979
  /**
2001
1980
  * The base class of performance calculators.
2002
1981
  */
2003
1982
  class PerformanceCalculator {
2004
1983
  /**
2005
- * The overall performance value.
2006
- */
2007
- total = 0;
2008
- /**
2009
- * The calculated accuracy.
2010
- */
2011
- computedAccuracy = new osuBase.Accuracy({});
2012
- /**
2013
- * Penalty for combo breaks.
2014
- */
2015
- comboPenalty = 0;
2016
- /**
2017
- * The amount of misses that are filtered out from sliderbreaks.
2018
- */
2019
- effectiveMissCount = 0;
2020
- /**
2021
- * Nerf factor used for nerfing beatmaps with very likely dropped sliderends.
1984
+ * @param difficultyAttributes The difficulty attributes to calculate.
2022
1985
  */
2023
- sliderNerfFactor = 1;
1986
+ constructor(difficultyAttributes) {
1987
+ /**
1988
+ * The overall performance value.
1989
+ */
1990
+ this.total = 0;
1991
+ /**
1992
+ * The calculated accuracy.
1993
+ */
1994
+ this.computedAccuracy = new osuBase.Accuracy({});
1995
+ /**
1996
+ * Penalty for combo breaks.
1997
+ */
1998
+ this.comboPenalty = 0;
1999
+ /**
2000
+ * The amount of misses that are filtered out from sliderbreaks.
2001
+ */
2002
+ this.effectiveMissCount = 0;
2003
+ /**
2004
+ * Nerf factor used for nerfing beatmaps with very likely dropped sliderends.
2005
+ */
2006
+ this.sliderNerfFactor = 1;
2007
+ if (this.isCacheableAttribute(difficultyAttributes)) {
2008
+ this.difficultyAttributes = Object.assign(Object.assign({}, difficultyAttributes), { mods: osuBase.ModUtil.pcStringToMods(difficultyAttributes.mods) });
2009
+ }
2010
+ else {
2011
+ this.difficultyAttributes = osuBase.Utils.deepCopy(difficultyAttributes);
2012
+ }
2013
+ }
2024
2014
  /**
2025
2015
  * Calculates the performance points of the beatmap.
2026
2016
  *
@@ -2030,7 +2020,7 @@ class PerformanceCalculator {
2030
2020
  calculate(options) {
2031
2021
  this.handleOptions(options);
2032
2022
  this.calculateValues();
2033
- this.calculateTotalValue();
2023
+ this.total = this.calculateTotalValue();
2034
2024
  return this;
2035
2025
  }
2036
2026
  /**
@@ -2061,11 +2051,12 @@ class PerformanceCalculator {
2061
2051
  * @param options Options for performance calculation.
2062
2052
  */
2063
2053
  handleOptions(options) {
2054
+ var _a;
2064
2055
  const maxCombo = this.difficultyAttributes.maxCombo;
2065
2056
  const miss = this.computedAccuracy.nmiss;
2066
- const combo = options?.combo ?? maxCombo - miss;
2057
+ const combo = (_a = options === null || options === void 0 ? void 0 : options.combo) !== null && _a !== void 0 ? _a : maxCombo - miss;
2067
2058
  this.comboPenalty = Math.min(Math.pow(combo / maxCombo, 0.8), 1);
2068
- if (options?.accPercent instanceof osuBase.Accuracy) {
2059
+ if ((options === null || options === void 0 ? void 0 : options.accPercent) instanceof osuBase.Accuracy) {
2069
2060
  // Copy into new instance to not modify the original
2070
2061
  this.computedAccuracy = new osuBase.Accuracy(options.accPercent);
2071
2062
  if (this.computedAccuracy.n300 <= 0) {
@@ -2080,9 +2071,9 @@ class PerformanceCalculator {
2080
2071
  }
2081
2072
  else {
2082
2073
  this.computedAccuracy = new osuBase.Accuracy({
2083
- percent: options?.accPercent,
2074
+ percent: options === null || options === void 0 ? void 0 : options.accPercent,
2084
2075
  nobjects: this.totalHits,
2085
- nmiss: options?.miss || 0,
2076
+ nmiss: (options === null || options === void 0 ? void 0 : options.miss) || 0,
2086
2077
  });
2087
2078
  }
2088
2079
  this.effectiveMissCount = this.calculateEffectiveMissCount(combo, maxCombo);
@@ -2116,7 +2107,7 @@ class PerformanceCalculator {
2116
2107
  if (this.difficultyAttributes.sliderCount > 0) {
2117
2108
  // We assume 15% of sliders in a beatmap are difficult since there's no way to tell from the performance calculator.
2118
2109
  const estimateDifficultSliders = this.difficultyAttributes.sliderCount * 0.15;
2119
- const estimateSliderEndsDropped = osuBase.MathUtils.clamp(Math.min(this.computedAccuracy.n300 +
2110
+ const estimateSliderEndsDropped = osuBase.MathUtils.clamp(Math.min(this.computedAccuracy.n100 +
2120
2111
  this.computedAccuracy.n50 +
2121
2112
  this.computedAccuracy.nmiss, maxCombo - combo), 0, estimateDifficultSliders);
2122
2113
  this.sliderNerfFactor =
@@ -2144,32 +2135,52 @@ class PerformanceCalculator {
2144
2135
  }
2145
2136
  return Math.max(this.computedAccuracy.nmiss, comboBasedMissCount);
2146
2137
  }
2138
+ /**
2139
+ * Determines whether an attribute is a cacheable attribute.
2140
+ *
2141
+ * @param attributes The attributes to check.
2142
+ * @returns Whether the attributes are cacheable.
2143
+ */
2144
+ isCacheableAttribute(attributes) {
2145
+ return typeof attributes.mods === "string";
2146
+ }
2147
2147
  }
2148
2148
 
2149
2149
  /**
2150
2150
  * A performance points calculator that calculates performance points for osu!droid gamemode.
2151
2151
  */
2152
2152
  class DroidPerformanceCalculator extends PerformanceCalculator {
2153
- /**
2154
- * The aim performance value.
2155
- */
2156
- aim = 0;
2157
- /**
2158
- * The tap performance value.
2159
- */
2160
- tap = 0;
2161
- /**
2162
- * The accuracy performance value.
2163
- */
2164
- accuracy = 0;
2165
- /**
2166
- * The flashlight performance value.
2167
- */
2168
- flashlight = 0;
2169
- /**
2170
- * The visual performance value.
2171
- */
2172
- visual = 0;
2153
+ constructor() {
2154
+ super(...arguments);
2155
+ /**
2156
+ * The aim performance value.
2157
+ */
2158
+ this.aim = 0;
2159
+ /**
2160
+ * The tap performance value.
2161
+ */
2162
+ this.tap = 0;
2163
+ /**
2164
+ * The accuracy performance value.
2165
+ */
2166
+ this.accuracy = 0;
2167
+ /**
2168
+ * The flashlight performance value.
2169
+ */
2170
+ this.flashlight = 0;
2171
+ /**
2172
+ * The visual performance value.
2173
+ */
2174
+ this.visual = 0;
2175
+ this.finalMultiplier = 1.24;
2176
+ this.mode = osuBase.Modes.droid;
2177
+ this._aimSliderCheesePenalty = 1;
2178
+ this._flashlightSliderCheesePenalty = 1;
2179
+ this._visualSliderCheesePenalty = 1;
2180
+ this._tapPenalty = 1;
2181
+ this._deviation = 0;
2182
+ this._tapDeviation = 0;
2183
+ }
2173
2184
  /**
2174
2185
  * The penalty used to penalize the tap performance value.
2175
2186
  *
@@ -2214,22 +2225,6 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2214
2225
  get visualSliderCheesePenalty() {
2215
2226
  return this._visualSliderCheesePenalty;
2216
2227
  }
2217
- difficultyAttributes;
2218
- finalMultiplier = 1.24;
2219
- mode = osuBase.Modes.droid;
2220
- _aimSliderCheesePenalty = 1;
2221
- _flashlightSliderCheesePenalty = 1;
2222
- _visualSliderCheesePenalty = 1;
2223
- _tapPenalty = 1;
2224
- _deviation = 0;
2225
- _tapDeviation = 0;
2226
- /**
2227
- * @param difficultyAttributes The difficulty attributes to calculate.
2228
- */
2229
- constructor(difficultyAttributes) {
2230
- super();
2231
- this.difficultyAttributes = osuBase.Utils.deepCopy(difficultyAttributes);
2232
- }
2233
2228
  /**
2234
2229
  * Applies a tap penalty value to this calculator.
2235
2230
  *
@@ -2244,9 +2239,9 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2244
2239
  if (value === this._tapPenalty) {
2245
2240
  return;
2246
2241
  }
2247
- this.tap *= this._tapPenalty / value;
2248
2242
  this._tapPenalty = value;
2249
- this.calculateTotalValue();
2243
+ this.tap = this.calculateTapValue();
2244
+ this.total = this.calculateTotalValue();
2250
2245
  }
2251
2246
  /**
2252
2247
  * Applies an aim slider cheese penalty value to this calculator.
@@ -2266,8 +2261,8 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2266
2261
  return;
2267
2262
  }
2268
2263
  this._aimSliderCheesePenalty = value;
2269
- this.calculateAimValue();
2270
- this.calculateTotalValue();
2264
+ this.aim = this.calculateAimValue();
2265
+ this.total = this.calculateTotalValue();
2271
2266
  }
2272
2267
  /**
2273
2268
  * Applies a flashlight slider cheese penalty value to this calculator.
@@ -2287,8 +2282,8 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2287
2282
  return;
2288
2283
  }
2289
2284
  this._flashlightSliderCheesePenalty = value;
2290
- this.calculateFlashlightValue();
2291
- this.calculateTotalValue();
2285
+ this.flashlight = this.calculateFlashlightValue();
2286
+ this.total = this.calculateTotalValue();
2292
2287
  }
2293
2288
  /**
2294
2289
  * Applies a visual slider cheese penalty value to this calculator.
@@ -2308,80 +2303,95 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2308
2303
  return;
2309
2304
  }
2310
2305
  this._visualSliderCheesePenalty = value;
2311
- this.calculateVisualValue();
2312
- this.calculateTotalValue();
2306
+ this.visual = this.calculateVisualValue();
2307
+ this.total = this.calculateTotalValue();
2313
2308
  }
2314
2309
  calculateValues() {
2315
2310
  this._deviation = this.calculateDeviation();
2316
2311
  this._tapDeviation = this.calculateTapDeviation();
2317
- this.calculateAimValue();
2318
- this.calculateTapValue();
2319
- this.calculateAccuracyValue();
2320
- this.calculateFlashlightValue();
2321
- this.calculateVisualValue();
2312
+ this.aim = this.calculateAimValue();
2313
+ this.tap = this.calculateTapValue();
2314
+ this.accuracy = this.calculateAccuracyValue();
2315
+ this.flashlight = this.calculateFlashlightValue();
2316
+ this.visual = this.calculateVisualValue();
2322
2317
  }
2323
2318
  calculateTotalValue() {
2324
- this.total =
2325
- Math.pow(Math.pow(this.aim, 1.1) +
2326
- Math.pow(this.tap, 1.1) +
2327
- Math.pow(this.accuracy, 1.1) +
2328
- Math.pow(this.flashlight, 1.1) +
2329
- Math.pow(this.visual, 1.1), 1 / 1.1) * this.finalMultiplier;
2319
+ return (Math.pow(Math.pow(this.aim, 1.1) +
2320
+ Math.pow(this.tap, 1.1) +
2321
+ Math.pow(this.accuracy, 1.1) +
2322
+ Math.pow(this.flashlight, 1.1) +
2323
+ Math.pow(this.visual, 1.1), 1 / 1.1) * this.finalMultiplier);
2330
2324
  }
2331
2325
  handleOptions(options) {
2332
- this._tapPenalty = options?.tapPenalty ?? 1;
2333
- this._aimSliderCheesePenalty = options?.aimSliderCheesePenalty ?? 1;
2326
+ var _a, _b, _c, _d;
2327
+ this._tapPenalty = (_a = options === null || options === void 0 ? void 0 : options.tapPenalty) !== null && _a !== void 0 ? _a : 1;
2328
+ this._aimSliderCheesePenalty = (_b = options === null || options === void 0 ? void 0 : options.aimSliderCheesePenalty) !== null && _b !== void 0 ? _b : 1;
2334
2329
  this._flashlightSliderCheesePenalty =
2335
- options?.flashlightSliderCheesePenalty ?? 1;
2330
+ (_c = options === null || options === void 0 ? void 0 : options.flashlightSliderCheesePenalty) !== null && _c !== void 0 ? _c : 1;
2336
2331
  this._visualSliderCheesePenalty =
2337
- options?.visualSliderCheesePenalty ?? 1;
2332
+ (_d = options === null || options === void 0 ? void 0 : options.visualSliderCheesePenalty) !== null && _d !== void 0 ? _d : 1;
2338
2333
  super.handleOptions(options);
2339
2334
  }
2340
2335
  /**
2341
2336
  * Calculates the aim performance value of the beatmap.
2342
2337
  */
2343
2338
  calculateAimValue() {
2344
- this.aim = this.baseValue(Math.pow(this.difficultyAttributes.aimDifficulty, 0.8));
2345
- if (this.effectiveMissCount > 0) {
2346
- // Penalize misses by assessing # of misses relative to the total # of objects.
2347
- // Default a 3% reduction for any # of misses.
2348
- this.aim *=
2349
- 0.97 *
2350
- Math.pow(1 -
2351
- Math.pow(this.effectiveMissCount / this.totalHits, 0.775), this.effectiveMissCount);
2352
- }
2353
- // Combo scaling
2354
- this.aim *= this.comboPenalty;
2339
+ let aimValue = this.baseValue(Math.pow(this.difficultyAttributes.aimDifficulty, 0.8));
2340
+ aimValue *= Math.min(this.calculateStrainBasedMissPenalty(this.difficultyAttributes.aimDifficultStrainCount), this.proportionalMissPenalty);
2341
+ // Scale the aim value with estimated full combo deviation.
2342
+ aimValue *= this.calculateDeviationBasedLengthScaling();
2355
2343
  // Scale the aim value with slider factor to nerf very likely dropped sliderends.
2356
- this.aim *= this.sliderNerfFactor;
2344
+ aimValue *= this.sliderNerfFactor;
2357
2345
  // Scale the aim value with slider cheese penalty.
2358
- this.aim *= this._aimSliderCheesePenalty;
2346
+ aimValue *= this._aimSliderCheesePenalty;
2359
2347
  // Scale the aim value with deviation.
2360
- this.aim *=
2348
+ aimValue *=
2361
2349
  1.05 *
2362
- Math.pow(osuBase.ErrorFunction.erf(32.0625 / (Math.SQRT2 * this._deviation)), 1.5);
2350
+ Math.sqrt(osuBase.ErrorFunction.erf(25 / (Math.SQRT2 * this._deviation)));
2351
+ // OD 7 SS stays the same.
2352
+ aimValue *= 0.98 + Math.pow(7, 2) / 2500;
2353
+ return aimValue;
2363
2354
  }
2364
2355
  /**
2365
2356
  * Calculates the tap performance value of the beatmap.
2366
2357
  */
2367
2358
  calculateTapValue() {
2368
- this.tap = this.baseValue(this.difficultyAttributes.tapDifficulty);
2369
- if (this.effectiveMissCount > 0) {
2370
- // Penalize misses by assessing # of misses relative to the total # of objects.
2371
- // Default a 3% reduction for any # of misses.
2372
- this.tap *=
2373
- 0.97 *
2374
- Math.pow(1 -
2375
- Math.pow(this.effectiveMissCount / this.totalHits, 0.775), Math.pow(this.effectiveMissCount, 0.875));
2376
- }
2377
- // Combo scaling
2378
- this.tap *= this.comboPenalty;
2359
+ let tapValue = this.baseValue(this.difficultyAttributes.tapDifficulty);
2360
+ tapValue *= this.calculateStrainBasedMissPenalty(this.difficultyAttributes.tapDifficultStrainCount);
2361
+ // Scale the tap value with estimated full combo deviation.
2362
+ // Require more objects to be present as object count can rack up easily in tap-oriented beatmaps.
2363
+ tapValue *= this.calculateDeviationBasedLengthScaling(this.totalHits / 1.45);
2364
+ // Normalize the deviation to 300 BPM.
2365
+ const normalizedDeviation = this.tapDeviation *
2366
+ Math.max(1, 50 / this.difficultyAttributes.averageSpeedDeltaTime);
2367
+ // We expect the player to get 7500/x deviation when doubletapping x BPM.
2368
+ // Using this expectation, we penalize scores with deviation above 25.
2369
+ const averageBPM = 60000 / 4 / this.difficultyAttributes.averageSpeedDeltaTime;
2370
+ const adjustedDeviation = normalizedDeviation *
2371
+ (1 +
2372
+ 1 /
2373
+ (1 +
2374
+ Math.exp(-(normalizedDeviation - 7500 / averageBPM) /
2375
+ ((2 * 300) / averageBPM))));
2379
2376
  // Scale the tap value with tap deviation.
2380
- this.tap *=
2377
+ tapValue *=
2381
2378
  1.1 *
2382
- Math.pow(osuBase.ErrorFunction.erf(25 / (Math.SQRT2 * this._tapDeviation)), 1.25);
2379
+ Math.pow(osuBase.ErrorFunction.erf(20 / (Math.SQRT2 * adjustedDeviation)), 0.625);
2380
+ // Additional scaling for tap value based on average BPM and how "vibroable" the beatmap is.
2381
+ // Higher BPMs require more precise tapping. When the deviation is too high,
2382
+ // it can be assumed that the player taps invariant to rhythm.
2383
+ // We harshen the punishment for such scenario.
2384
+ tapValue *=
2385
+ (1 - Math.pow(this.difficultyAttributes.vibroFactor, 6)) /
2386
+ (1 +
2387
+ Math.exp((this._tapDeviation - 7500 / averageBPM) /
2388
+ ((2 * 300) / averageBPM))) +
2389
+ Math.pow(this.difficultyAttributes.vibroFactor, 6);
2383
2390
  // Scale the tap value with three-fingered penalty.
2384
- this.tap /= this._tapPenalty;
2391
+ tapValue /= this._tapPenalty;
2392
+ // OD 8 SS stays the same.
2393
+ tapValue *= 0.95 + Math.pow(8, 2) / 750;
2394
+ return tapValue;
2385
2395
  }
2386
2396
  /**
2387
2397
  * Calculates the accuracy performance value of the beatmap.
@@ -2389,84 +2399,127 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2389
2399
  calculateAccuracyValue() {
2390
2400
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModRelax) ||
2391
2401
  this.totalSuccessfulHits === 0) {
2392
- this.accuracy = 0;
2393
- return;
2402
+ return 0;
2394
2403
  }
2395
- this.accuracy =
2396
- 650 *
2397
- Math.exp(-0.125 * this._deviation) *
2398
- // The following function is to give higher reward for deviations lower than 25 (250 UR).
2399
- (15 / (this._deviation + 15) + 0.65);
2400
- // Bonus for many hitcircles - it's harder to keep good accuracy up for longer.
2404
+ let accuracyValue = 800 * Math.exp(-0.1 * this._deviation);
2401
2405
  const ncircles = this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModScoreV2)
2402
2406
  ? this.totalHits - this.difficultyAttributes.spinnerCount
2403
2407
  : this.difficultyAttributes.hitCircleCount;
2404
- this.accuracy *= Math.min(1.15, Math.sqrt(Math.log(1 + ((Math.E - 1) * ncircles) / 1000)));
2408
+ // Bonus for many hitcircles - it's harder to keep good accuracy up for longer.
2409
+ accuracyValue *= Math.min(1.15, Math.sqrt(Math.log(1 + ((Math.E - 1) * ncircles) / 1000)));
2405
2410
  // Scale the accuracy value with rhythm complexity.
2406
- this.accuracy *=
2411
+ accuracyValue *=
2407
2412
  1.5 /
2408
2413
  (1 +
2409
2414
  Math.exp(-(this.difficultyAttributes.rhythmDifficulty - 1) / 2));
2415
+ // Penalize accuracy pp after the first miss.
2416
+ accuracyValue *= Math.pow(0.97, Math.max(0, this.effectiveMissCount - 1));
2410
2417
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2411
- this.accuracy *= 1.02;
2418
+ accuracyValue *= 1.02;
2412
2419
  }
2420
+ return accuracyValue;
2413
2421
  }
2414
2422
  /**
2415
2423
  * Calculates the flashlight performance value of the beatmap.
2416
2424
  */
2417
2425
  calculateFlashlightValue() {
2418
2426
  if (!this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2419
- this.flashlight = 0;
2420
- return;
2421
- }
2422
- this.flashlight =
2423
- Math.pow(this.difficultyAttributes.flashlightDifficulty, 1.6) * 25;
2424
- // Combo scaling
2425
- this.flashlight *= this.comboPenalty;
2426
- if (this.effectiveMissCount > 0) {
2427
- // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
2428
- this.flashlight *=
2429
- 0.97 *
2430
- Math.pow(1 -
2431
- Math.pow(this.effectiveMissCount / this.totalHits, 0.775), Math.pow(this.effectiveMissCount, 0.875));
2427
+ return 0;
2432
2428
  }
2429
+ let flashlightValue = Math.pow(this.difficultyAttributes.flashlightDifficulty, 1.6) * 25;
2430
+ flashlightValue *= Math.min(this.calculateStrainBasedMissPenalty(this.difficultyAttributes.flashlightDifficultStrainCount), this.proportionalMissPenalty);
2433
2431
  // Account for shorter maps having a higher ratio of 0 combo/100 combo flashlight radius.
2434
- this.flashlight *=
2432
+ flashlightValue *=
2435
2433
  0.7 +
2436
2434
  0.1 * Math.min(1, this.totalHits / 200) +
2437
2435
  (this.totalHits > 200
2438
2436
  ? 0.2 * Math.min(1, (this.totalHits - 200) / 200)
2439
2437
  : 0);
2440
2438
  // Scale the flashlight value with slider cheese penalty.
2441
- this.flashlight *= this._flashlightSliderCheesePenalty;
2439
+ flashlightValue *= this._flashlightSliderCheesePenalty;
2442
2440
  // Scale the flashlight value with deviation.
2443
- this.flashlight *= osuBase.ErrorFunction.erf(50 / (Math.SQRT2 * this._deviation));
2441
+ flashlightValue *= osuBase.ErrorFunction.erf(50 / (Math.SQRT2 * this._deviation));
2442
+ return flashlightValue;
2444
2443
  }
2445
2444
  /**
2446
2445
  * Calculates the visual performance value of the beatmap.
2447
2446
  */
2448
2447
  calculateVisualValue() {
2449
- this.visual =
2450
- Math.pow(this.difficultyAttributes.visualDifficulty, 1.6) * 22.5;
2451
- if (this.effectiveMissCount > 0) {
2452
- // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
2453
- this.visual *=
2454
- 0.97 *
2455
- Math.pow(1 -
2456
- Math.pow(this.effectiveMissCount / this.totalHits, 0.775), this.effectiveMissCount);
2457
- }
2458
- // Combo scaling
2459
- this.visual *= this.comboPenalty;
2460
- // Scale the visual value with object count to penalize short maps.
2461
- this.visual *= Math.min(1, 1.650668 +
2462
- (0.4845796 - 1.650668) /
2463
- (1 + Math.pow(this.totalHits / 817.9306, 1.147469)));
2448
+ let visualValue = Math.pow(this.difficultyAttributes.visualDifficulty, 1.6) * 22.5;
2449
+ visualValue *= Math.min(this.calculateStrainBasedMissPenalty(this.difficultyAttributes.visualDifficultStrainCount), this.proportionalMissPenalty);
2450
+ // Scale the visual value with estimated full combo deviation.
2451
+ // As visual is easily "bypassable" with memorization, punish for memorization.
2452
+ visualValue *= this.calculateDeviationBasedLengthScaling(undefined, true);
2464
2453
  // Scale the visual value with slider cheese penalty.
2465
- this.visual *= this._visualSliderCheesePenalty;
2454
+ visualValue *= this._visualSliderCheesePenalty;
2466
2455
  // Scale the visual value with deviation.
2467
- this.visual *=
2456
+ visualValue *=
2468
2457
  1.065 *
2469
- Math.pow(osuBase.ErrorFunction.erf(30 / (Math.SQRT2 * this._deviation)), 1.75);
2458
+ Math.pow(osuBase.ErrorFunction.erf(25 / (Math.SQRT2 * this._deviation)), 0.8);
2459
+ // OD 5 SS stays the same.
2460
+ visualValue *= 0.98 + Math.pow(5, 2) / 2500;
2461
+ return visualValue;
2462
+ }
2463
+ /**
2464
+ * Calculates a strain-based miss penalty.
2465
+ *
2466
+ * Strain-based miss penalty assumes that a player will miss on the hardest parts of a map,
2467
+ * so we use the amount of relatively difficult sections to adjust miss penalty
2468
+ * to make it more punishing on maps with lower amount of hard sections.
2469
+ */
2470
+ calculateStrainBasedMissPenalty(difficultStrainCount) {
2471
+ if (this.effectiveMissCount === 0) {
2472
+ return 1;
2473
+ }
2474
+ return (0.94 /
2475
+ (this.effectiveMissCount / (2 * Math.sqrt(difficultStrainCount)) +
2476
+ 1));
2477
+ }
2478
+ /**
2479
+ * The object-based proportional miss penalty.
2480
+ */
2481
+ get proportionalMissPenalty() {
2482
+ if (this.effectiveMissCount === 0) {
2483
+ return 1;
2484
+ }
2485
+ const missProportion = (this.totalHits - this.effectiveMissCount) / (this.totalHits + 1);
2486
+ const noMissProportion = this.totalHits / (this.totalHits + 1);
2487
+ return (
2488
+ // Aim deviation-based scale.
2489
+ (osuBase.ErrorFunction.erfInv(missProportion) /
2490
+ osuBase.ErrorFunction.erfInv(noMissProportion)) *
2491
+ // Cheesing-based scale (i.e. 50% misses is deliberately only hitting each other
2492
+ // note, 90% misses is deliberately only hitting 1 note every 10 notes).
2493
+ Math.pow(missProportion, 8));
2494
+ }
2495
+ /**
2496
+ * Calculates the object-based length scaling based on the deviation of a player for a full
2497
+ * combo in this beatmap, taking retries into account.
2498
+ *
2499
+ * @param objectCount The amount of objects to be considered. Defaults to the amount of
2500
+ * objects in this beatmap.
2501
+ * @param punishForMemorization Whether to punish the deviation for memorization. Defaults to `false`.
2502
+ */
2503
+ calculateDeviationBasedLengthScaling(objectCount = this.totalHits, punishForMemorization = false) {
2504
+ // Assume a sample proportion of hits for a full combo to be `(n - 0.5) / n` due to
2505
+ // continuity correction, where `n` is the object count.
2506
+ const calculateProportion = (notes) => (notes - 0.5) / notes;
2507
+ // Keeping `x` notes as the benchmark, assume that a player will retry a beatmap
2508
+ // `max(1, x/n)` times relative to an `x`-note beatmap.
2509
+ const benchmarkNotes = 700;
2510
+ // Calculate the proportion equivalent to the bottom half of retry count percentile of
2511
+ // scores and take it as the player's "real" proportion.
2512
+ const retryProportion = (proportion, notes, tries) => proportion +
2513
+ Math.sqrt((2 * proportion * (1 - proportion)) / notes) *
2514
+ osuBase.ErrorFunction.erfInv(1 / tries - 1);
2515
+ // Using the proportion, we calculate the deviation based off that proportion and again
2516
+ // compared to the hit deviation for proportion `(n - 0.5) / n`.
2517
+ let multiplier = Math.max(0, osuBase.ErrorFunction.erfInv(retryProportion(calculateProportion(objectCount), objectCount, Math.max(1, benchmarkNotes / objectCount))) / osuBase.ErrorFunction.erfInv(calculateProportion(benchmarkNotes)) || 0);
2518
+ // Punish for memorization if needed.
2519
+ if (punishForMemorization) {
2520
+ multiplier *= Math.min(1, Math.sqrt(objectCount / benchmarkNotes));
2521
+ }
2522
+ return multiplier;
2470
2523
  }
2471
2524
  /**
2472
2525
  * Estimates the player's tap deviation based on the OD, number of circles and sliders,
@@ -2487,40 +2540,65 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2487
2540
  return Number.POSITIVE_INFINITY;
2488
2541
  }
2489
2542
  const hitWindow300 = new osuBase.OsuHitWindow(this.difficultyAttributes.overallDifficulty).hitWindowFor300();
2490
- // Obtain the 50 hit window for droid.
2491
- const clockRate = new osuBase.MapStats({
2492
- mods: this.difficultyAttributes.mods,
2493
- }).calculate().speedMultiplier;
2494
- const realHitWindow300 = hitWindow300 * clockRate;
2495
- const droidHitWindow = new osuBase.DroidHitWindow(osuBase.OsuHitWindow.hitWindow300ToOD(realHitWindow300));
2496
- const hitWindow50 = droidHitWindow.hitWindowFor50(this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModPrecise)) / clockRate;
2497
- const greatCountOnCircles = this.difficultyAttributes.hitCircleCount -
2498
- this.computedAccuracy.n100 -
2499
- this.computedAccuracy.n50 -
2500
- this.computedAccuracy.nmiss;
2501
- // The probability that a player hits a circle is unknown, but we can estimate it to be
2502
- // the number of greats on circles divided by the number of circles, and then add one
2503
- // to the number of circles as a bias correction / bayesian prior.
2504
- const greatProbabilityCircle = Math.max(0, greatCountOnCircles / (this.difficultyAttributes.hitCircleCount + 1));
2505
- let greatProbabilitySlider;
2506
- if (greatCountOnCircles < 0) {
2507
- const nonCircleMisses = -greatCountOnCircles;
2508
- greatProbabilitySlider = Math.max(0, (this.difficultyAttributes.sliderCount - nonCircleMisses) /
2509
- (this.difficultyAttributes.sliderCount + 1));
2510
- }
2511
- else {
2512
- greatProbabilitySlider =
2513
- this.difficultyAttributes.sliderCount /
2514
- (this.difficultyAttributes.sliderCount + 1);
2515
- }
2516
- if (greatProbabilityCircle === 0 && greatProbabilitySlider === 0) {
2543
+ // Obtain the 50 and 100 hit window for droid.
2544
+ const isPrecise = this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModPrecise);
2545
+ const droidHitWindow = new osuBase.DroidHitWindow(osuBase.DroidHitWindow.hitWindow300ToOD(hitWindow300 * this.difficultyAttributes.clockRate, isPrecise));
2546
+ const hitWindow50 = droidHitWindow.hitWindowFor50(isPrecise) /
2547
+ this.difficultyAttributes.clockRate;
2548
+ const hitWindow100 = droidHitWindow.hitWindowFor100(isPrecise) /
2549
+ this.difficultyAttributes.clockRate;
2550
+ const { n100, n50, nmiss } = this.computedAccuracy;
2551
+ const circleCount = this.difficultyAttributes.hitCircleCount;
2552
+ const missCountCircles = Math.min(nmiss, circleCount);
2553
+ const mehCountCircles = Math.min(n50, circleCount - missCountCircles);
2554
+ const okCountCircles = Math.min(n100, circleCount - missCountCircles - mehCountCircles);
2555
+ const greatCountCircles = Math.max(0, circleCount - missCountCircles - mehCountCircles - okCountCircles);
2556
+ // Assume 100s, 50s, and misses happen on circles. If there are less non-300s on circles than 300s,
2557
+ // compute the deviation on circles.
2558
+ if (greatCountCircles > 0) {
2559
+ // The probability that a player hits a circle is unknown, but we can estimate it to be
2560
+ // the number of greats on circles divided by the number of circles, and then add one
2561
+ // to the number of circles as a bias correction.
2562
+ const greatProbabilityCircle = greatCountCircles /
2563
+ (circleCount - missCountCircles - mehCountCircles + 1);
2564
+ // Compute the deviation assuming 300s and 100s are normally distributed, and 50s are uniformly distributed.
2565
+ // Begin with the normal distribution first.
2566
+ let deviationOnCircles = hitWindow300 /
2567
+ (Math.SQRT2 * osuBase.ErrorFunction.erfInv(greatProbabilityCircle));
2568
+ deviationOnCircles *= Math.sqrt(1 -
2569
+ (Math.sqrt(2 / Math.PI) *
2570
+ hitWindow100 *
2571
+ Math.exp(-0.5 *
2572
+ Math.pow(hitWindow100 / deviationOnCircles, 2))) /
2573
+ (deviationOnCircles *
2574
+ osuBase.ErrorFunction.erf(hitWindow100 /
2575
+ (Math.SQRT2 * deviationOnCircles))));
2576
+ // Then compute the variance for 50s.
2577
+ const mehVariance = (hitWindow50 * hitWindow50 +
2578
+ hitWindow100 * hitWindow50 +
2579
+ hitWindow100 * hitWindow100) /
2580
+ 3;
2581
+ // Find the total deviation.
2582
+ deviationOnCircles = Math.sqrt(((greatCountCircles + okCountCircles) *
2583
+ Math.pow(deviationOnCircles, 2) +
2584
+ mehCountCircles * mehVariance) /
2585
+ (greatCountCircles + okCountCircles + mehCountCircles));
2586
+ return deviationOnCircles;
2587
+ }
2588
+ // If there are more non-300s than there are circles, compute the deviation on sliders instead.
2589
+ // Here, all that matters is whether or not the slider was missed, since it is impossible
2590
+ // to get a 100 or 50 on a slider by mis-tapping it.
2591
+ const sliderCount = this.difficultyAttributes.sliderCount;
2592
+ const missCountSliders = Math.min(sliderCount, nmiss - missCountCircles);
2593
+ const greatCountSliders = sliderCount - missCountSliders;
2594
+ // We only get here if nothing was hit. In this case, there is no estimate for deviation.
2595
+ // Note that this is never negative, so checking if this is only equal to 0 makes sense.
2596
+ if (greatCountSliders === 0) {
2517
2597
  return Number.POSITIVE_INFINITY;
2518
2598
  }
2519
- const deviationOnCircles = hitWindow300 /
2520
- (Math.SQRT2 * osuBase.ErrorFunction.erfInv(greatProbabilityCircle));
2521
- const deviationOnSliders = hitWindow50 /
2522
- (Math.SQRT2 * osuBase.ErrorFunction.erfInv(greatProbabilitySlider));
2523
- return Math.min(deviationOnCircles, deviationOnSliders);
2599
+ const greatProbabilitySlider = greatCountSliders / (sliderCount + 1);
2600
+ return (hitWindow50 /
2601
+ (Math.SQRT2 * osuBase.ErrorFunction.erfInv(greatProbabilitySlider)));
2524
2602
  }
2525
2603
  /**
2526
2604
  * Does the same as {@link calculateDeviation}, but only for notes and inaccuracies that are relevant to tap difficulty.
@@ -2532,14 +2610,59 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2532
2610
  if (this.totalSuccessfulHits === 0) {
2533
2611
  return Number.POSITIVE_INFINITY;
2534
2612
  }
2535
- const hitWindow300 = new osuBase.OsuHitWindow(this.difficultyAttributes.overallDifficulty).hitWindowFor300();
2536
- const relevantTotalDiff = this.totalHits - this.difficultyAttributes.speedNoteCount;
2537
- const relevantCountGreat = Math.max(0, this.computedAccuracy.n300 - relevantTotalDiff);
2538
- if (relevantCountGreat === 0) {
2539
- return Number.POSITIVE_INFINITY;
2540
- }
2541
- const greatProbability = relevantCountGreat / (this.difficultyAttributes.speedNoteCount + 1);
2542
- return (hitWindow300 / (Math.SQRT2 * osuBase.ErrorFunction.erfInv(greatProbability)));
2613
+ const { speedNoteCount, clockRate, overallDifficulty } = this.difficultyAttributes;
2614
+ const hitWindow300 = new osuBase.OsuHitWindow(overallDifficulty).hitWindowFor300();
2615
+ // Obtain the 50 and 100 hit window for droid.
2616
+ const isPrecise = this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModPrecise);
2617
+ const droidHitWindow = new osuBase.DroidHitWindow(osuBase.DroidHitWindow.hitWindow300ToOD(hitWindow300 * clockRate, isPrecise));
2618
+ const hitWindow50 = droidHitWindow.hitWindowFor50(isPrecise) / clockRate;
2619
+ const hitWindow100 = droidHitWindow.hitWindowFor100(isPrecise) / clockRate;
2620
+ const { n100, n50, nmiss } = this.computedAccuracy;
2621
+ // Assume a fixed ratio of non-300s hit in speed notes based on speed note count ratio and OD.
2622
+ // Graph: https://www.desmos.com/calculator/iskvgjkxr4
2623
+ const speedNoteRatio = speedNoteCount / this.totalHits;
2624
+ const nonGreatCount = n100 + n50 + nmiss;
2625
+ const nonGreatRatio = 1 -
2626
+ (Math.pow(Math.exp(Math.sqrt(hitWindow300)) + 1, 1 - speedNoteRatio) -
2627
+ 1) /
2628
+ Math.exp(Math.sqrt(hitWindow300));
2629
+ const relevantCountGreat = Math.max(0, speedNoteCount - nonGreatCount * nonGreatRatio);
2630
+ const relevantCountOk = n100 * nonGreatRatio;
2631
+ const relevantCountMeh = n50 * nonGreatRatio;
2632
+ const relevantCountMiss = nmiss * nonGreatRatio;
2633
+ // Assume 100s, 50s, and misses happen on circles. If there are less non-300s on circles than 300s,
2634
+ // compute the deviation on circles.
2635
+ if (relevantCountGreat > 0) {
2636
+ // The probability that a player hits a circle is unknown, but we can estimate it to be
2637
+ // the number of greats on circles divided by the number of circles, and then add one
2638
+ // to the number of circles as a bias correction.
2639
+ const greatProbabilityCircle = relevantCountGreat /
2640
+ (speedNoteCount - relevantCountMiss - relevantCountMeh + 1);
2641
+ // Compute the deviation assuming 300s and 100s are normally distributed, and 50s are uniformly distributed.
2642
+ // Begin with the normal distribution first.
2643
+ let deviationOnCircles = hitWindow300 /
2644
+ (Math.SQRT2 * osuBase.ErrorFunction.erfInv(greatProbabilityCircle));
2645
+ deviationOnCircles *= Math.sqrt(1 -
2646
+ (Math.sqrt(2 / Math.PI) *
2647
+ hitWindow100 *
2648
+ Math.exp(-0.5 *
2649
+ Math.pow(hitWindow100 / deviationOnCircles, 2))) /
2650
+ (deviationOnCircles *
2651
+ osuBase.ErrorFunction.erf(hitWindow100 /
2652
+ (Math.SQRT2 * deviationOnCircles))));
2653
+ // Then compute the variance for 50s.
2654
+ const mehVariance = (hitWindow50 * hitWindow50 +
2655
+ hitWindow100 * hitWindow50 +
2656
+ hitWindow100 * hitWindow100) /
2657
+ 3;
2658
+ // Find the total deviation.
2659
+ deviationOnCircles = Math.sqrt(((relevantCountGreat + relevantCountOk) *
2660
+ Math.pow(deviationOnCircles, 2) +
2661
+ relevantCountMeh * mehVariance) /
2662
+ (relevantCountGreat + relevantCountOk + relevantCountMeh));
2663
+ return deviationOnCircles;
2664
+ }
2665
+ return Number.POSITIVE_INFINITY;
2543
2666
  }
2544
2667
  toString() {
2545
2668
  return (this.total.toFixed(2) +
@@ -2562,16 +2685,13 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2562
2685
  * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
2563
2686
  */
2564
2687
  class OsuSkill extends StrainSkill {
2565
- /**
2566
- * The default multiplier applied to the final difficulty value after all other calculations.
2567
- *
2568
- * May be overridden via {@link difficultyMultiplier}.
2569
- */
2570
- static defaultDifficultyMultiplier = 1.06;
2571
- /**
2572
- * The final multiplier to be applied to the final difficulty value after all other calculations.
2573
- */
2574
- difficultyMultiplier = OsuSkill.defaultDifficultyMultiplier;
2688
+ constructor() {
2689
+ super(...arguments);
2690
+ /**
2691
+ * The final multiplier to be applied to the final difficulty value after all other calculations.
2692
+ */
2693
+ this.difficultyMultiplier = OsuSkill.defaultDifficultyMultiplier;
2694
+ }
2575
2695
  difficultyValue() {
2576
2696
  const strains = this.strainPeaks
2577
2697
  .slice()
@@ -2599,6 +2719,12 @@ class OsuSkill extends StrainSkill {
2599
2719
  return difficulty * this.difficultyMultiplier;
2600
2720
  }
2601
2721
  }
2722
+ /**
2723
+ * The default multiplier applied to the final difficulty value after all other calculations.
2724
+ *
2725
+ * May be overridden via {@link difficultyMultiplier}.
2726
+ */
2727
+ OsuSkill.defaultDifficultyMultiplier = 1.06;
2602
2728
 
2603
2729
  /**
2604
2730
  * An evaluator for calculating osu!standard Aim skill.
@@ -2619,7 +2745,7 @@ class OsuAimEvaluator extends AimEvaluator {
2619
2745
  const last = current.previous(0);
2620
2746
  if (current.object instanceof osuBase.Spinner ||
2621
2747
  current.index <= 1 ||
2622
- last?.object instanceof osuBase.Spinner) {
2748
+ (last === null || last === void 0 ? void 0 : last.object) instanceof osuBase.Spinner) {
2623
2749
  return 0;
2624
2750
  }
2625
2751
  const lastLast = current.previous(1);
@@ -2707,7 +2833,7 @@ class OsuAimEvaluator extends AimEvaluator {
2707
2833
  velocityChangeBonus *= Math.pow(Math.min(current.strainTime, last.strainTime) /
2708
2834
  Math.max(current.strainTime, last.strainTime), 2);
2709
2835
  }
2710
- if (last.object instanceof osuBase.Slider) {
2836
+ if (last.travelTime) {
2711
2837
  // Reward sliders based on velocity.
2712
2838
  sliderBonus = last.travelDistance / last.travelTime;
2713
2839
  }
@@ -2726,35 +2852,37 @@ class OsuAimEvaluator extends AimEvaluator {
2726
2852
  * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
2727
2853
  */
2728
2854
  class OsuAim extends OsuSkill {
2729
- skillMultiplier = 23.55;
2730
- strainDecayBase = 0.15;
2731
- reducedSectionCount = 10;
2732
- reducedSectionBaseline = 0.75;
2733
- decayWeight = 0.9;
2734
- withSliders;
2735
2855
  constructor(mods, withSliders) {
2736
2856
  super(mods);
2857
+ this.strainDecayBase = 0.15;
2858
+ this.reducedSectionCount = 10;
2859
+ this.reducedSectionBaseline = 0.75;
2860
+ this.decayWeight = 0.9;
2861
+ this.currentAimStrain = 0;
2862
+ this.skillMultiplier = 23.55;
2737
2863
  this.withSliders = withSliders;
2738
2864
  }
2739
- /**
2740
- * @param current The hitobject to calculate.
2741
- */
2742
2865
  strainValueAt(current) {
2743
- this.currentStrain *= this.strainDecay(current.deltaTime);
2744
- this.currentStrain +=
2866
+ this.currentAimStrain *= this.strainDecay(current.deltaTime);
2867
+ this.currentAimStrain +=
2745
2868
  OsuAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
2746
2869
  this.skillMultiplier;
2747
- return this.currentStrain;
2870
+ return this.currentAimStrain;
2871
+ }
2872
+ calculateInitialStrain(time, current) {
2873
+ var _a, _b;
2874
+ return (this.currentAimStrain *
2875
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
2748
2876
  }
2749
2877
  /**
2750
2878
  * @param current The hitobject to save to.
2751
2879
  */
2752
2880
  saveToHitObject(current) {
2753
2881
  if (this.withSliders) {
2754
- current.aimStrainWithSliders = this.currentStrain;
2882
+ current.aimStrainWithSliders = this.currentAimStrain;
2755
2883
  }
2756
2884
  else {
2757
- current.aimStrainWithoutSliders = this.currentStrain;
2885
+ current.aimStrainWithoutSliders = this.currentAimStrain;
2758
2886
  }
2759
2887
  }
2760
2888
  }
@@ -2763,10 +2891,6 @@ class OsuAim extends OsuSkill {
2763
2891
  * An evaluator for calculating osu!standard speed skill.
2764
2892
  */
2765
2893
  class OsuSpeedEvaluator extends SpeedEvaluator {
2766
- /**
2767
- * Spacing threshold for a single hitobject spacing.
2768
- */
2769
- static SINGLE_SPACING_THRESHOLD = 125;
2770
2894
  /**
2771
2895
  * Evaluates the difficulty of tapping the current object, based on:
2772
2896
  *
@@ -2778,6 +2902,7 @@ class OsuSpeedEvaluator extends SpeedEvaluator {
2778
2902
  * @param greatWindow The great hit window of the current object.
2779
2903
  */
2780
2904
  static evaluateDifficultyOf(current, greatWindow) {
2905
+ var _a;
2781
2906
  if (current.object instanceof osuBase.Spinner) {
2782
2907
  return 0;
2783
2908
  }
@@ -2803,7 +2928,7 @@ class OsuSpeedEvaluator extends SpeedEvaluator {
2803
2928
  speedBonus +=
2804
2929
  0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
2805
2930
  }
2806
- const travelDistance = prev?.travelDistance ?? 0;
2931
+ const travelDistance = (_a = prev === null || prev === void 0 ? void 0 : prev.travelDistance) !== null && _a !== void 0 ? _a : 0;
2807
2932
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
2808
2933
  return (((speedBonus +
2809
2934
  speedBonus *
@@ -2812,6 +2937,10 @@ class OsuSpeedEvaluator extends SpeedEvaluator {
2812
2937
  strainTime);
2813
2938
  }
2814
2939
  }
2940
+ /**
2941
+ * Spacing threshold for a single hitobject spacing.
2942
+ */
2943
+ OsuSpeedEvaluator.SINGLE_SPACING_THRESHOLD = 125;
2815
2944
 
2816
2945
  /**
2817
2946
  * An evaluator for calculating osu!standard Rhythm skill.
@@ -2926,18 +3055,17 @@ class OsuRhythmEvaluator extends RhythmEvaluator {
2926
3055
  * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
2927
3056
  */
2928
3057
  class OsuSpeed extends OsuSkill {
2929
- skillMultiplier = 1375;
2930
- strainDecayBase = 0.3;
2931
- reducedSectionCount = 5;
2932
- reducedSectionBaseline = 0.75;
2933
- difficultyMultiplier = 1.04;
2934
- decayWeight = 0.9;
2935
- currentSpeedStrain = 0;
2936
- currentRhythm = 0;
2937
- greatWindow;
2938
- constructor(mods, greatWindow) {
3058
+ constructor(mods, overallDifficulty) {
2939
3059
  super(mods);
2940
- this.greatWindow = greatWindow;
3060
+ this.strainDecayBase = 0.3;
3061
+ this.reducedSectionCount = 5;
3062
+ this.reducedSectionBaseline = 0.75;
3063
+ this.difficultyMultiplier = 1.04;
3064
+ this.decayWeight = 0.9;
3065
+ this.currentSpeedStrain = 0;
3066
+ this.currentRhythm = 0;
3067
+ this.skillMultiplier = 1375;
3068
+ this.greatWindow = new osuBase.OsuHitWindow(overallDifficulty).hitWindowFor300();
2941
3069
  }
2942
3070
  /**
2943
3071
  * @param current The hitobject to calculate.
@@ -2950,11 +3078,17 @@ class OsuSpeed extends OsuSkill {
2950
3078
  this.currentRhythm = OsuRhythmEvaluator.evaluateDifficultyOf(current, this.greatWindow);
2951
3079
  return this.currentSpeedStrain * this.currentRhythm;
2952
3080
  }
3081
+ calculateInitialStrain(time, current) {
3082
+ var _a, _b;
3083
+ return (this.currentSpeedStrain *
3084
+ this.currentRhythm *
3085
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
3086
+ }
2953
3087
  /**
2954
3088
  * @param current The hitobject to save to.
2955
3089
  */
2956
3090
  saveToHitObject(current) {
2957
- current.tapStrain = this.currentStrain;
3091
+ current.speedStrain = this.currentSpeedStrain * this.currentRhythm;
2958
3092
  current.rhythmMultiplier = this.currentRhythm;
2959
3093
  }
2960
3094
  }
@@ -2979,7 +3113,7 @@ class OsuFlashlightEvaluator extends FlashlightEvaluator {
2979
3113
  if (current.object instanceof osuBase.Spinner) {
2980
3114
  return 0;
2981
3115
  }
2982
- const scalingFactor = 52 / current.object.getRadius(osuBase.Modes.osu);
3116
+ const scalingFactor = 52 / current.object.radius;
2983
3117
  let smallDistNerf = 1;
2984
3118
  let cumulativeStrainTime = 0;
2985
3119
  let result = 0;
@@ -3002,7 +3136,7 @@ class OsuFlashlightEvaluator extends FlashlightEvaluator {
3002
3136
  const opacityBonus = 1 +
3003
3137
  this.maxOpacityBonus *
3004
3138
  (1 -
3005
- current.opacityAt(currentObject.object.startTime, isHiddenMod, osuBase.Modes.osu));
3139
+ current.opacityAt(currentObject.object.startTime, isHiddenMod));
3006
3140
  result +=
3007
3141
  (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
3008
3142
  cumulativeStrainTime;
@@ -3033,8 +3167,8 @@ class OsuFlashlightEvaluator extends FlashlightEvaluator {
3033
3167
  // Longer sliders require more memorization.
3034
3168
  sliderBonus *= pixelTravelDistance;
3035
3169
  // Nerf sliders with repeats, as less memorization is required.
3036
- if (current.object.repeats > 0)
3037
- sliderBonus /= current.object.repeats + 1;
3170
+ if (current.object.repeatCount > 0)
3171
+ sliderBonus /= current.object.repeatCount + 1;
3038
3172
  }
3039
3173
  result += sliderBonus * this.sliderMultiplier;
3040
3174
  return result;
@@ -3045,27 +3179,69 @@ class OsuFlashlightEvaluator extends FlashlightEvaluator {
3045
3179
  * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
3046
3180
  */
3047
3181
  class OsuFlashlight extends OsuSkill {
3048
- skillMultiplier = 0.052;
3049
- strainDecayBase = 0.15;
3050
- reducedSectionCount = 0;
3051
- reducedSectionBaseline = 1;
3052
- decayWeight = 1;
3053
- isHidden;
3054
3182
  constructor(mods) {
3055
3183
  super(mods);
3184
+ this.strainDecayBase = 0.15;
3185
+ this.reducedSectionCount = 0;
3186
+ this.reducedSectionBaseline = 1;
3187
+ this.decayWeight = 1;
3188
+ this.currentFlashlightStrain = 0;
3189
+ this.skillMultiplier = 0.052;
3056
3190
  this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
3057
3191
  }
3058
- /**
3059
- * @param current The hitobject to calculate.
3060
- */
3061
3192
  strainValueAt(current) {
3062
- this.currentStrain *= this.strainDecay(current.deltaTime);
3063
- this.currentStrain +=
3193
+ this.currentFlashlightStrain *= this.strainDecay(current.deltaTime);
3194
+ this.currentFlashlightStrain +=
3064
3195
  OsuFlashlightEvaluator.evaluateDifficultyOf(current, this.isHidden) * this.skillMultiplier;
3065
- return this.currentStrain;
3196
+ return this.currentFlashlightStrain;
3197
+ }
3198
+ calculateInitialStrain(time, current) {
3199
+ var _a, _b;
3200
+ return (this.currentFlashlightStrain *
3201
+ this.strainDecay(time - ((_b = (_a = current.previous(0)) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0)));
3066
3202
  }
3067
3203
  saveToHitObject(current) {
3068
- current.flashlightStrainWithSliders = this.currentStrain;
3204
+ current.flashlightStrain = this.currentFlashlightStrain;
3205
+ }
3206
+ }
3207
+
3208
+ /**
3209
+ * Represents an osu!standard hit object with difficulty calculation values.
3210
+ */
3211
+ class OsuDifficultyHitObject extends DifficultyHitObject {
3212
+ get scalingFactor() {
3213
+ const radius = this.object.radius;
3214
+ // We will scale distances by this factor, so we can assume a uniform CircleSize among beatmaps.
3215
+ let scalingFactor = this.normalizedRadius / radius;
3216
+ // High circle size (small CS) bonus
3217
+ if (radius < this.radiusBuffThreshold) {
3218
+ scalingFactor *=
3219
+ 1 + Math.min(this.radiusBuffThreshold - radius, 5) / 50;
3220
+ }
3221
+ return scalingFactor;
3222
+ }
3223
+ /**
3224
+ * Note: You **must** call `computeProperties` at some point due to how TypeScript handles
3225
+ * overridden properties (see [this](https://github.com/microsoft/TypeScript/issues/1617) GitHub issue).
3226
+ *
3227
+ * @param object The underlying hitobject.
3228
+ * @param lastObject The hitobject before this hitobject.
3229
+ * @param lastLastObject The hitobject before the last hitobject.
3230
+ * @param difficultyHitObjects All difficulty hitobjects in the processed beatmap.
3231
+ * @param clockRate The clock rate of the beatmap.
3232
+ */
3233
+ constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate) {
3234
+ super(object, lastObject, lastLastObject, difficultyHitObjects, clockRate);
3235
+ /**
3236
+ * The speed strain generated by the hitobject.
3237
+ */
3238
+ this.speedStrain = 0;
3239
+ /**
3240
+ * The flashlight strain generated by this hitobject.
3241
+ */
3242
+ this.flashlightStrain = 0;
3243
+ this.radiusBuffThreshold = 30;
3244
+ this.mode = osuBase.Modes.osu;
3069
3245
  }
3070
3246
  }
3071
3247
 
@@ -3073,35 +3249,48 @@ class OsuFlashlight extends OsuSkill {
3073
3249
  * A difficulty calculator for osu!standard gamemode.
3074
3250
  */
3075
3251
  class OsuDifficultyCalculator extends DifficultyCalculator {
3252
+ constructor() {
3253
+ super(...arguments);
3254
+ this.attributes = {
3255
+ speedDifficulty: 0,
3256
+ mods: [],
3257
+ starRating: 0,
3258
+ maxCombo: 0,
3259
+ aimDifficulty: 0,
3260
+ flashlightDifficulty: 0,
3261
+ speedNoteCount: 0,
3262
+ sliderFactor: 0,
3263
+ clockRate: 1,
3264
+ approachRate: 0,
3265
+ overallDifficulty: 0,
3266
+ hitCircleCount: 0,
3267
+ sliderCount: 0,
3268
+ spinnerCount: 0,
3269
+ };
3270
+ this.difficultyMultiplier = 0.0675;
3271
+ this.mode = osuBase.Modes.osu;
3272
+ }
3076
3273
  /**
3077
3274
  * The aim star rating of the beatmap.
3078
3275
  */
3079
- aim = 0;
3276
+ get aim() {
3277
+ return this.attributes.aimDifficulty;
3278
+ }
3080
3279
  /**
3081
3280
  * The speed star rating of the beatmap.
3082
3281
  */
3083
- speed = 0;
3282
+ get speed() {
3283
+ return this.attributes.speedDifficulty;
3284
+ }
3084
3285
  /**
3085
3286
  * The flashlight star rating of the beatmap.
3086
3287
  */
3087
- flashlight = 0;
3088
- attributes = {
3089
- speedDifficulty: 0,
3090
- mods: [],
3091
- starRating: 0,
3092
- maxCombo: 0,
3093
- aimDifficulty: 0,
3094
- flashlightDifficulty: 0,
3095
- speedNoteCount: 0,
3096
- sliderFactor: 0,
3097
- approachRate: 0,
3098
- overallDifficulty: 0,
3099
- hitCircleCount: 0,
3100
- sliderCount: 0,
3101
- spinnerCount: 0,
3102
- };
3103
- difficultyMultiplier = 0.0675;
3104
- mode = osuBase.Modes.osu;
3288
+ get flashlight() {
3289
+ return this.attributes.flashlightDifficulty;
3290
+ }
3291
+ get cacheableAttributes() {
3292
+ return Object.assign(Object.assign({}, this.attributes), { mods: osuBase.ModUtil.modsToOsuString(this.attributes.mods) });
3293
+ }
3105
3294
  /**
3106
3295
  * Calculates the aim star rating of the beatmap and stores it in this instance.
3107
3296
  */
@@ -3115,20 +3304,9 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3115
3304
  * Calculates the speed star rating of the beatmap and stores it in this instance.
3116
3305
  */
3117
3306
  calculateSpeed() {
3118
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3119
- this.speed = this.attributes.speedDifficulty = 0;
3120
- return;
3121
- }
3122
- const speedSkill = new OsuSpeed(this.mods, new osuBase.OsuHitWindow(this.stats.od).hitWindowFor300());
3307
+ const speedSkill = new OsuSpeed(this.mods, this.difficultyStatistics.overallDifficulty);
3123
3308
  this.calculateSkills(speedSkill);
3124
- if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3125
- this.speed = 0;
3126
- this.attributes.speedDifficulty = 0;
3127
- }
3128
- else {
3129
- this.postCalculateSpeed(speedSkill);
3130
- }
3131
- this.calculateSpeedAttributes();
3309
+ this.postCalculateSpeed(speedSkill);
3132
3310
  }
3133
3311
  /**
3134
3312
  * Calculates the flashlight star rating of the beatmap and stores it in this instance.
@@ -3151,39 +3329,29 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3151
3329
  if (basePerformanceValue > 1e-5) {
3152
3330
  // Document for formula derivation:
3153
3331
  // https://docs.google.com/document/d/10DZGYYSsT_yjz2Mtp6yIJld0Rqx4E-vVHupCqiM4TNI/edit
3154
- this.total = this.attributes.starRating =
3332
+ this.attributes.starRating =
3155
3333
  Math.cbrt(1.14) *
3156
3334
  0.027 *
3157
3335
  (Math.cbrt((100000 / Math.pow(2, 1 / 1.1)) * basePerformanceValue) +
3158
3336
  4);
3159
3337
  }
3160
3338
  else {
3161
- this.total = this.attributes.starRating = 0;
3339
+ this.attributes.starRating = 0;
3162
3340
  }
3163
3341
  }
3164
3342
  calculateAll() {
3165
3343
  const skills = this.createSkills();
3166
- const isRelax = this.mods.some((m) => m instanceof osuBase.ModRelax);
3167
3344
  this.calculateSkills(...skills);
3168
3345
  const aimSkill = skills[0];
3169
3346
  const aimSkillWithoutSliders = skills[1];
3170
3347
  const speedSkill = skills[2];
3171
3348
  const flashlightSkill = skills[3];
3172
3349
  this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
3173
- if (isRelax) {
3174
- this.speed = 0;
3175
- this.attributes.speedDifficulty = 0;
3176
- }
3177
- else {
3178
- this.postCalculateSpeed(speedSkill);
3179
- }
3350
+ this.postCalculateSpeed(speedSkill);
3180
3351
  this.calculateSpeedAttributes();
3181
3352
  this.postCalculateFlashlight(flashlightSkill);
3182
3353
  this.calculateTotal();
3183
3354
  }
3184
- /**
3185
- * Returns a string representative of the class.
3186
- */
3187
3355
  toString() {
3188
3356
  return (this.total.toFixed(2) +
3189
3357
  " stars (" +
@@ -3194,14 +3362,34 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3194
3362
  this.flashlight.toFixed(2) +
3195
3363
  " flashlight)");
3196
3364
  }
3197
- /**
3198
- * Creates skills to be calculated.
3199
- */
3365
+ generateDifficultyHitObjects(beatmap) {
3366
+ var _a, _b;
3367
+ const difficultyObjects = [];
3368
+ const { objects } = beatmap.hitObjects;
3369
+ for (let i = 0; i < objects.length; ++i) {
3370
+ 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, this.difficultyStatistics.overallSpeedMultiplier);
3371
+ difficultyObject.computeProperties(this.difficultyStatistics.overallSpeedMultiplier, objects);
3372
+ difficultyObjects.push(difficultyObject);
3373
+ }
3374
+ return difficultyObjects;
3375
+ }
3376
+ computeDifficultyStatistics(options) {
3377
+ var _a;
3378
+ const { difficulty } = this.beatmap;
3379
+ return osuBase.calculateOsuDifficultyStatistics({
3380
+ circleSize: difficulty.cs,
3381
+ approachRate: (_a = difficulty.ar) !== null && _a !== void 0 ? _a : difficulty.od,
3382
+ overallDifficulty: difficulty.od,
3383
+ healthDrain: difficulty.hp,
3384
+ mods: options === null || options === void 0 ? void 0 : options.mods,
3385
+ customSpeedMultiplier: options === null || options === void 0 ? void 0 : options.customSpeedMultiplier,
3386
+ });
3387
+ }
3200
3388
  createSkills() {
3201
3389
  return [
3202
3390
  new OsuAim(this.mods, true),
3203
3391
  new OsuAim(this.mods, false),
3204
- new OsuSpeed(this.mods, new osuBase.OsuHitWindow(this.stats.od).hitWindowFor300()),
3392
+ new OsuSpeed(this.mods, this.difficultyStatistics.overallDifficulty),
3205
3393
  new OsuFlashlight(this.mods),
3206
3394
  ];
3207
3395
  }
@@ -3214,19 +3402,18 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3214
3402
  postCalculateAim(aimSkill, aimSkillWithoutSliders) {
3215
3403
  this.strainPeaks.aimWithSliders = aimSkill.strainPeaks;
3216
3404
  this.strainPeaks.aimWithoutSliders = aimSkillWithoutSliders.strainPeaks;
3217
- this.aim = this.starValue(aimSkill.difficultyValue());
3405
+ this.attributes.aimDifficulty = this.starValue(aimSkill.difficultyValue());
3218
3406
  if (this.aim) {
3219
3407
  this.attributes.sliderFactor =
3220
3408
  this.starValue(aimSkillWithoutSliders.difficultyValue()) /
3221
3409
  this.aim;
3222
3410
  }
3223
3411
  if (this.mods.some((m) => m instanceof osuBase.ModTouchDevice)) {
3224
- this.aim = Math.pow(this.aim, 0.8);
3412
+ this.attributes.aimDifficulty = Math.pow(this.aim, 0.8);
3225
3413
  }
3226
3414
  if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3227
- this.aim *= 0.9;
3415
+ this.attributes.aimDifficulty *= 0.9;
3228
3416
  }
3229
- this.attributes.aimDifficulty = this.aim;
3230
3417
  }
3231
3418
  /**
3232
3419
  * Called after speed skill calculation.
@@ -3235,13 +3422,16 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3235
3422
  */
3236
3423
  postCalculateSpeed(speedSkill) {
3237
3424
  this.strainPeaks.speed = speedSkill.strainPeaks;
3238
- this.speed = this.attributes.speedDifficulty = this.starValue(speedSkill.difficultyValue());
3425
+ this.attributes.speedDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
3426
+ ? 0
3427
+ : this.starValue(speedSkill.difficultyValue());
3428
+ this.calculateSpeedAttributes();
3239
3429
  }
3240
3430
  /**
3241
3431
  * Calculates speed-related attributes.
3242
3432
  */
3243
3433
  calculateSpeedAttributes() {
3244
- const objectStrains = this.objects.map((v) => v.tapStrain);
3434
+ const objectStrains = this.objects.map((v) => v.speedStrain);
3245
3435
  const maxStrain = Math.max(...objectStrains);
3246
3436
  if (maxStrain) {
3247
3437
  this.attributes.speedNoteCount = objectStrains.reduce((total, next) => total + 1 / (1 + Math.exp(-((next / maxStrain) * 12 - 6))), 0);
@@ -3254,55 +3444,13 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3254
3444
  */
3255
3445
  postCalculateFlashlight(flashlightSkill) {
3256
3446
  this.strainPeaks.flashlight = flashlightSkill.strainPeaks;
3257
- this.flashlight = this.starValue(flashlightSkill.difficultyValue());
3447
+ this.attributes.flashlightDifficulty = this.starValue(flashlightSkill.difficultyValue());
3258
3448
  if (this.mods.some((m) => m instanceof osuBase.ModTouchDevice)) {
3259
- this.flashlight = Math.pow(this.flashlight, 0.8);
3449
+ this.attributes.flashlightDifficulty = Math.pow(this.flashlight, 0.8);
3260
3450
  }
3261
3451
  if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3262
- this.flashlight *= 0.7;
3452
+ this.attributes.flashlightDifficulty *= 0.7;
3263
3453
  }
3264
- this.attributes.flashlightDifficulty = this.flashlight;
3265
- }
3266
- }
3267
-
3268
- /**
3269
- * A difficulty calculator that calculates for both osu!droid and osu!standard gamemode.
3270
- */
3271
- class MapStars {
3272
- /**
3273
- * The osu!droid difficulty calculator of the beatmap.
3274
- */
3275
- droid;
3276
- /**
3277
- * The osu!standard difficulty calculator of the beatmap.
3278
- */
3279
- osu;
3280
- /**
3281
- * Constructs this instance and calculates the given beatmap's osu!droid and osu!standard difficulty.
3282
- *
3283
- * @param beatmap The beatmap to calculate.
3284
- * @param options Options for the difficulty calculation.
3285
- */
3286
- constructor(beatmap, options) {
3287
- const stats = new osuBase.MapStats({
3288
- speedMultiplier: options?.stats?.speedMultiplier ?? 1,
3289
- isForceAR: options?.stats?.isForceAR ?? false,
3290
- oldStatistics: options?.stats?.oldStatistics ?? false,
3291
- });
3292
- this.droid = new DroidDifficultyCalculator(beatmap).calculate({
3293
- ...options,
3294
- stats,
3295
- });
3296
- this.osu = new OsuDifficultyCalculator(beatmap).calculate({
3297
- ...options,
3298
- stats,
3299
- });
3300
- }
3301
- /**
3302
- * Returns a string representative of the class.
3303
- */
3304
- toString() {
3305
- return `${this.droid.toString()}\n${this.osu.toString()}`;
3306
3454
  }
3307
3455
  }
3308
3456
 
@@ -3310,66 +3458,60 @@ class MapStars {
3310
3458
  * A performance points calculator that calculates performance points for osu!standard gamemode.
3311
3459
  */
3312
3460
  class OsuPerformanceCalculator extends PerformanceCalculator {
3313
- /**
3314
- * The aim performance value.
3315
- */
3316
- aim = 0;
3317
- /**
3318
- * The speed performance value.
3319
- */
3320
- speed = 0;
3321
- /**
3322
- * The accuracy performance value.
3323
- */
3324
- accuracy = 0;
3325
- /**
3326
- * The flashlight performance value.
3327
- */
3328
- flashlight = 0;
3329
- difficultyAttributes;
3330
- finalMultiplier = 1.14;
3331
- mode = osuBase.Modes.osu;
3461
+ constructor() {
3462
+ super(...arguments);
3463
+ /**
3464
+ * The aim performance value.
3465
+ */
3466
+ this.aim = 0;
3467
+ /**
3468
+ * The speed performance value.
3469
+ */
3470
+ this.speed = 0;
3471
+ /**
3472
+ * The accuracy performance value.
3473
+ */
3474
+ this.accuracy = 0;
3475
+ /**
3476
+ * The flashlight performance value.
3477
+ */
3478
+ this.flashlight = 0;
3479
+ this.finalMultiplier = 1.14;
3480
+ this.mode = osuBase.Modes.osu;
3481
+ }
3332
3482
  calculateValues() {
3333
- this.calculateAimValue();
3334
- this.calculateSpeedValue();
3335
- this.calculateAccuracyValue();
3336
- this.calculateFlashlightValue();
3483
+ this.aim = this.calculateAimValue();
3484
+ this.speed = this.calculateSpeedValue();
3485
+ this.accuracy = this.calculateAccuracyValue();
3486
+ this.flashlight = this.calculateFlashlightValue();
3337
3487
  }
3338
3488
  calculateTotalValue() {
3339
- this.total =
3340
- Math.pow(Math.pow(this.aim, 1.1) +
3341
- Math.pow(this.speed, 1.1) +
3342
- Math.pow(this.accuracy, 1.1) +
3343
- Math.pow(this.flashlight, 1.1), 1 / 1.1) * this.finalMultiplier;
3344
- }
3345
- /**
3346
- * @param difficultyAttributes The difficulty attributes to calculate.
3347
- */
3348
- constructor(difficultyAttributes) {
3349
- super();
3350
- this.difficultyAttributes = osuBase.Utils.deepCopy(difficultyAttributes);
3489
+ return (Math.pow(Math.pow(this.aim, 1.1) +
3490
+ Math.pow(this.speed, 1.1) +
3491
+ Math.pow(this.accuracy, 1.1) +
3492
+ Math.pow(this.flashlight, 1.1), 1 / 1.1) * this.finalMultiplier);
3351
3493
  }
3352
3494
  /**
3353
3495
  * Calculates the aim performance value of the beatmap.
3354
3496
  */
3355
3497
  calculateAimValue() {
3356
- this.aim = this.baseValue(this.difficultyAttributes.aimDifficulty);
3498
+ let aimValue = this.baseValue(this.difficultyAttributes.aimDifficulty);
3357
3499
  // Longer maps are worth more
3358
3500
  let lengthBonus = 0.95 + 0.4 * Math.min(1, this.totalHits / 2000);
3359
3501
  if (this.totalHits > 2000) {
3360
3502
  lengthBonus += Math.log10(this.totalHits / 2000) * 0.5;
3361
3503
  }
3362
- this.aim *= lengthBonus;
3504
+ aimValue *= lengthBonus;
3363
3505
  if (this.effectiveMissCount > 0) {
3364
3506
  // Penalize misses by assessing # of misses relative to the total # of objects.
3365
3507
  // Default a 3% reduction for any # of misses.
3366
- this.aim *=
3508
+ aimValue *=
3367
3509
  0.97 *
3368
3510
  Math.pow(1 -
3369
3511
  Math.pow(this.effectiveMissCount / this.totalHits, 0.775), this.effectiveMissCount);
3370
3512
  }
3371
3513
  // Combo scaling
3372
- this.aim *= this.comboPenalty;
3514
+ aimValue *= this.comboPenalty;
3373
3515
  const calculatedAR = this.difficultyAttributes.approachRate;
3374
3516
  if (!this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModRelax)) {
3375
3517
  // AR scaling
@@ -3381,144 +3523,142 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
3381
3523
  arFactor += 0.05 * (8 - calculatedAR);
3382
3524
  }
3383
3525
  // Buff for longer maps with high AR.
3384
- this.aim *= 1 + arFactor * lengthBonus;
3526
+ aimValue *= 1 + arFactor * lengthBonus;
3385
3527
  }
3386
3528
  // We want to give more reward for lower AR when it comes to aim and HD. This nerfs high AR and buffs lower AR.
3387
3529
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModHidden)) {
3388
- this.aim *= 1 + 0.04 * (12 - calculatedAR);
3530
+ aimValue *= 1 + 0.04 * (12 - calculatedAR);
3389
3531
  }
3390
3532
  // Scale the aim value with slider factor to nerf very likely dropped sliderends.
3391
- this.aim *= this.sliderNerfFactor;
3533
+ aimValue *= this.sliderNerfFactor;
3392
3534
  // Scale the aim value with accuracy.
3393
- this.aim *= this.computedAccuracy.value(this.totalHits);
3535
+ aimValue *= this.computedAccuracy.value();
3394
3536
  // It is also important to consider accuracy difficulty when doing that.
3395
3537
  const odScaling = Math.pow(this.difficultyAttributes.overallDifficulty, 2) / 2500;
3396
- this.aim *= 0.98 + odScaling;
3538
+ aimValue *= 0.98 + odScaling;
3539
+ return aimValue;
3397
3540
  }
3398
3541
  /**
3399
3542
  * Calculates the speed performance value of the beatmap.
3400
3543
  */
3401
3544
  calculateSpeedValue() {
3402
3545
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModRelax)) {
3403
- this.speed = 0;
3404
- return;
3546
+ return 0;
3405
3547
  }
3406
- this.speed = this.baseValue(this.difficultyAttributes.speedDifficulty);
3548
+ let speedValue = this.baseValue(this.difficultyAttributes.speedDifficulty);
3407
3549
  // Longer maps are worth more
3408
3550
  let lengthBonus = 0.95 + 0.4 * Math.min(1, this.totalHits / 2000);
3409
3551
  if (this.totalHits > 2000) {
3410
3552
  lengthBonus += Math.log10(this.totalHits / 2000) * 0.5;
3411
3553
  }
3412
- this.speed *= lengthBonus;
3554
+ speedValue *= lengthBonus;
3413
3555
  if (this.effectiveMissCount > 0) {
3414
3556
  // Penalize misses by assessing # of misses relative to the total # of objects.
3415
3557
  // Default a 3% reduction for any # of misses.
3416
- this.speed *=
3558
+ speedValue *=
3417
3559
  0.97 *
3418
3560
  Math.pow(1 -
3419
3561
  Math.pow(this.effectiveMissCount / this.totalHits, 0.775), Math.pow(this.effectiveMissCount, 0.875));
3420
3562
  }
3421
3563
  // Combo scaling
3422
- this.speed *= this.comboPenalty;
3564
+ speedValue *= this.comboPenalty;
3423
3565
  // AR scaling
3424
3566
  const calculatedAR = this.difficultyAttributes.approachRate;
3425
3567
  if (calculatedAR > 10.33) {
3426
3568
  // Buff for longer maps with high AR.
3427
- this.speed *= 1 + 0.3 * (calculatedAR - 10.33) * lengthBonus;
3569
+ speedValue *= 1 + 0.3 * (calculatedAR - 10.33) * lengthBonus;
3428
3570
  }
3429
3571
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModHidden)) {
3430
- this.speed *= 1 + 0.04 * (12 - calculatedAR);
3572
+ speedValue *= 1 + 0.04 * (12 - calculatedAR);
3431
3573
  }
3432
3574
  // Calculate accuracy assuming the worst case scenario.
3433
3575
  const countGreat = this.computedAccuracy.n300;
3434
3576
  const countOk = this.computedAccuracy.n100;
3435
3577
  const countMeh = this.computedAccuracy.n50;
3436
3578
  const relevantTotalDiff = this.totalHits - this.difficultyAttributes.speedNoteCount;
3437
- const relevantAccuracy = new osuBase.Accuracy({
3438
- n300: Math.max(0, countGreat - relevantTotalDiff),
3439
- n100: Math.max(0, countOk - Math.max(0, relevantTotalDiff - countGreat)),
3440
- n50: Math.max(0, countMeh - Math.max(0, relevantTotalDiff - countGreat - countOk)),
3441
- nmiss: this.effectiveMissCount,
3442
- });
3579
+ const relevantAccuracy = new osuBase.Accuracy(this.difficultyAttributes.speedNoteCount > 0
3580
+ ? {
3581
+ n300: Math.max(0, countGreat - relevantTotalDiff),
3582
+ n100: Math.max(0, countOk - Math.max(0, relevantTotalDiff - countGreat)),
3583
+ n50: Math.max(0, countMeh -
3584
+ Math.max(0, relevantTotalDiff - countGreat - countOk)),
3585
+ }
3586
+ : // Set accuracy to 0.
3587
+ { n300: 0, nobjects: 1 });
3443
3588
  // Scale the speed value with accuracy and OD.
3444
- this.speed *=
3589
+ speedValue *=
3445
3590
  (0.95 +
3446
3591
  Math.pow(this.difficultyAttributes.overallDifficulty, 2) /
3447
3592
  750) *
3448
- Math.pow((this.computedAccuracy.value(this.totalHits) +
3449
- relevantAccuracy.value()) /
3593
+ Math.pow((this.computedAccuracy.value() +
3594
+ relevantAccuracy.value(this.difficultyAttributes.speedNoteCount)) /
3450
3595
  2, (14.5 -
3451
3596
  Math.max(this.difficultyAttributes.overallDifficulty, 8)) /
3452
3597
  2);
3453
3598
  // Scale the speed value with # of 50s to punish doubletapping.
3454
- this.speed *= Math.pow(0.99, Math.max(0, this.computedAccuracy.n50 - this.totalHits / 500));
3599
+ speedValue *= Math.pow(0.99, Math.max(0, this.computedAccuracy.n50 - this.totalHits / 500));
3600
+ return speedValue;
3455
3601
  }
3456
3602
  /**
3457
3603
  * Calculates the accuracy performance value of the beatmap.
3458
3604
  */
3459
3605
  calculateAccuracyValue() {
3460
3606
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModRelax)) {
3461
- this.accuracy = 0;
3462
- return;
3607
+ return 0;
3463
3608
  }
3464
3609
  const ncircles = this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModScoreV2)
3465
3610
  ? this.totalHits - this.difficultyAttributes.spinnerCount
3466
3611
  : this.difficultyAttributes.hitCircleCount;
3467
3612
  if (ncircles === 0) {
3468
- this.accuracy = 0;
3469
- return;
3613
+ return 0;
3470
3614
  }
3471
- const realAccuracy = new osuBase.Accuracy({
3472
- ...this.computedAccuracy,
3473
- n300: this.computedAccuracy.n300 - (this.totalHits - ncircles),
3474
- });
3615
+ const realAccuracy = new osuBase.Accuracy(Object.assign(Object.assign({}, this.computedAccuracy), { n300: this.computedAccuracy.n300 - (this.totalHits - ncircles) }));
3475
3616
  // Lots of arbitrary values from testing.
3476
3617
  // Considering to use derivation from perfect accuracy in a probabilistic manner - assume normal distribution
3477
- this.accuracy =
3478
- Math.pow(1.52163, this.difficultyAttributes.overallDifficulty) *
3479
- Math.pow(realAccuracy.value(ncircles), 24) *
3480
- 2.83;
3618
+ let accuracyValue = Math.pow(1.52163, this.difficultyAttributes.overallDifficulty) *
3619
+ // It is possible to reach a negative accuracy with this formula. Cap it at zero - zero points.
3620
+ Math.pow(realAccuracy.n300 < 0 ? 0 : realAccuracy.value(), 24) *
3621
+ 2.83;
3481
3622
  // Bonus for many hitcircles - it's harder to keep good accuracy up for longer
3482
- this.accuracy *= Math.min(1.15, Math.pow(ncircles / 1000, 0.3));
3623
+ accuracyValue *= Math.min(1.15, Math.pow(ncircles / 1000, 0.3));
3483
3624
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModHidden)) {
3484
- this.accuracy *= 1.08;
3625
+ accuracyValue *= 1.08;
3485
3626
  }
3486
3627
  if (this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
3487
- this.accuracy *= 1.02;
3628
+ accuracyValue *= 1.02;
3488
3629
  }
3630
+ return accuracyValue;
3489
3631
  }
3490
3632
  /**
3491
3633
  * Calculates the flashlight performance value of the beatmap.
3492
3634
  */
3493
3635
  calculateFlashlightValue() {
3494
3636
  if (!this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
3495
- this.flashlight = 0;
3496
- return;
3637
+ return 0;
3497
3638
  }
3498
- this.flashlight =
3499
- Math.pow(this.difficultyAttributes.flashlightDifficulty, 2) * 25;
3639
+ let flashlightValue = Math.pow(this.difficultyAttributes.flashlightDifficulty, 2) * 25;
3500
3640
  // Combo scaling
3501
- this.flashlight *= this.comboPenalty;
3641
+ flashlightValue *= this.comboPenalty;
3502
3642
  if (this.effectiveMissCount > 0) {
3503
3643
  // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
3504
- this.flashlight *=
3644
+ flashlightValue *=
3505
3645
  0.97 *
3506
3646
  Math.pow(1 -
3507
3647
  Math.pow(this.effectiveMissCount / this.totalHits, 0.775), Math.pow(this.effectiveMissCount, 0.875));
3508
3648
  }
3509
3649
  // Account for shorter maps having a higher ratio of 0 combo/100 combo flashlight radius.
3510
- this.flashlight *=
3650
+ flashlightValue *=
3511
3651
  0.7 +
3512
3652
  0.1 * Math.min(1, this.totalHits / 200) +
3513
3653
  (this.totalHits > 200
3514
3654
  ? 0.2 * Math.min(1, (this.totalHits - 200) / 200)
3515
3655
  : 0);
3516
3656
  // Scale the flashlight value with accuracy slightly.
3517
- this.flashlight *=
3518
- 0.5 + this.computedAccuracy.value(this.totalHits) / 2;
3657
+ flashlightValue *= 0.5 + this.computedAccuracy.value() / 2;
3519
3658
  // It is also important to consider accuracy difficulty when doing that.
3520
3659
  const odScaling = Math.pow(this.difficultyAttributes.overallDifficulty, 2) / 2500;
3521
- this.flashlight *= 0.98 + odScaling;
3660
+ flashlightValue *= 0.98 + odScaling;
3661
+ return flashlightValue;
3522
3662
  }
3523
3663
  toString() {
3524
3664
  return (this.total.toFixed(2) +
@@ -3537,10 +3677,10 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
3537
3677
  exports.AimEvaluator = AimEvaluator;
3538
3678
  exports.DifficultyCalculator = DifficultyCalculator;
3539
3679
  exports.DifficultyHitObject = DifficultyHitObject;
3540
- exports.DifficultyHitObjectCreator = DifficultyHitObjectCreator;
3541
3680
  exports.DroidAim = DroidAim;
3542
3681
  exports.DroidAimEvaluator = DroidAimEvaluator;
3543
3682
  exports.DroidDifficultyCalculator = DroidDifficultyCalculator;
3683
+ exports.DroidDifficultyHitObject = DroidDifficultyHitObject;
3544
3684
  exports.DroidFlashlight = DroidFlashlight;
3545
3685
  exports.DroidFlashlightEvaluator = DroidFlashlightEvaluator;
3546
3686
  exports.DroidPerformanceCalculator = DroidPerformanceCalculator;
@@ -3551,10 +3691,10 @@ exports.DroidTapEvaluator = DroidTapEvaluator;
3551
3691
  exports.DroidVisual = DroidVisual;
3552
3692
  exports.DroidVisualEvaluator = DroidVisualEvaluator;
3553
3693
  exports.FlashlightEvaluator = FlashlightEvaluator;
3554
- exports.MapStars = MapStars;
3555
3694
  exports.OsuAim = OsuAim;
3556
3695
  exports.OsuAimEvaluator = OsuAimEvaluator;
3557
3696
  exports.OsuDifficultyCalculator = OsuDifficultyCalculator;
3697
+ exports.OsuDifficultyHitObject = OsuDifficultyHitObject;
3558
3698
  exports.OsuFlashlight = OsuFlashlight;
3559
3699
  exports.OsuFlashlightEvaluator = OsuFlashlightEvaluator;
3560
3700
  exports.OsuPerformanceCalculator = OsuPerformanceCalculator;