@rian8337/osu-rebalance-difficulty-calculator 4.0.0-beta.3 → 4.0.0-beta.30

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