@rian8337/osu-rebalance-difficulty-calculator 4.0.0-beta.4 → 4.0.0-beta.41

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