@rian8337/osu-rebalance-difficulty-calculator 2.0.0-alpha.8 → 2.0.1

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
@@ -4,6 +4,32 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var osuBase = require('@rian8337/osu-base');
6
6
 
7
+ /**
8
+ * An evaluator for calculating aim skill.
9
+ *
10
+ * This class should be considered an "evaluating" class and not persisted.
11
+ */
12
+ class AimEvaluator {
13
+ static wideAngleMultiplier = 1.5;
14
+ static acuteAngleMultiplier = 2;
15
+ static sliderMultiplier = 1.5;
16
+ static velocityChangeMultiplier = 0.75;
17
+ /**
18
+ * Calculates the bonus of wide angles.
19
+ */
20
+ static calculateWideAngleBonus(angle) {
21
+ return Math.pow(Math.sin((3 / 4) *
22
+ (Math.min((5 / 6) * Math.PI, Math.max(Math.PI / 6, angle)) -
23
+ Math.PI / 6)), 2);
24
+ }
25
+ /**
26
+ * Calculates the bonus of acute angles.
27
+ */
28
+ static calculateAcuteAngleBonus(angle) {
29
+ return 1 - this.calculateWideAngleBonus(angle);
30
+ }
31
+ }
32
+
7
33
  /**
8
34
  * Represents an osu!standard hit object with difficulty calculation values.
9
35
  */
@@ -12,6 +38,20 @@ class DifficultyHitObject {
12
38
  * The underlying hitobject.
13
39
  */
14
40
  object;
41
+ /**
42
+ * The index of this hitobject in the list of all hitobjects.
43
+ *
44
+ * This is one less than the actual index of the hitobject in the beatmap.
45
+ */
46
+ index = 0;
47
+ /**
48
+ * The preempt time of the hitobject.
49
+ */
50
+ timePreempt = 600;
51
+ /**
52
+ * The fade in time of the hitobject.
53
+ */
54
+ timeFadeIn = 450;
15
55
  /**
16
56
  * The aim strain generated by the hitobject if sliders are considered.
17
57
  */
@@ -103,7 +143,7 @@ class DifficultyHitObject {
103
143
  /**
104
144
  * The note density of the hitobject.
105
145
  */
106
- noteDensity = 0;
146
+ noteDensity = 1;
107
147
  /**
108
148
  * The overlapping factor of the hitobject.
109
149
  *
@@ -114,11 +154,64 @@ class DifficultyHitObject {
114
154
  * Adjusted velocity of the hitobject, taking speed multiplier into account.
115
155
  */
116
156
  velocity = 0;
157
+ hitObjects;
117
158
  /**
118
159
  * @param object The underlying hitobject.
160
+ * @param hitObjects All difficulty hitobjects in the processed beatmap.
119
161
  */
120
- constructor(object) {
162
+ constructor(object, hitObjects) {
121
163
  this.object = object;
164
+ this.hitObjects = hitObjects;
165
+ }
166
+ /**
167
+ * Gets the difficulty hitobject at a specific index with respect to the current
168
+ * difficulty hitobject's index.
169
+ *
170
+ * Will return `null` if the index is out of range.
171
+ *
172
+ * @param backwardsIndex The index to move backwards for.
173
+ * @returns The difficulty hitobject at the index with respect to the current
174
+ * difficulty hitobject's index, `null` if the index is out of range.
175
+ */
176
+ previous(backwardsIndex) {
177
+ return this.hitObjects[this.index - backwardsIndex] ?? null;
178
+ }
179
+ /**
180
+ * Gets the difficulty hitobject at a specific index with respect to the current
181
+ * difficulty hitobject's index.
182
+ *
183
+ * Will return `null` if the index is out of range.
184
+ *
185
+ * @param forwardsIndex The index to move forwards for.
186
+ * @returns The difficulty hitobject at the index with respect to the current
187
+ * difficulty hitobject's index, `null` if the index is out of range.
188
+ */
189
+ next(forwardsIndex) {
190
+ return this.hitObjects[this.index + forwardsIndex + 2] ?? null;
191
+ }
192
+ /**
193
+ * Calculates the opacity of the hitobject at a given time.
194
+ *
195
+ * @param time The time to calculate the hitobject's opacity at.
196
+ * @param isHidden Whether Hidden mod is used.
197
+ * @returns The opacity of the hitobject at the given time.
198
+ */
199
+ opacityAt(time, isHidden) {
200
+ if (time > this.object.startTime) {
201
+ // Consider a hitobject as being invisible when its start time is passed.
202
+ // In reality the hitobject will be visible beyond its start time up until its hittable window has passed,
203
+ // but this is an approximation and such a case is unlikely to be hit where this function is used.
204
+ return 0;
205
+ }
206
+ const fadeInStartTime = this.object.startTime - this.timePreempt;
207
+ const fadeInDuration = this.timeFadeIn;
208
+ if (isHidden) {
209
+ const fadeOutStartTime = fadeInStartTime + fadeInDuration;
210
+ const fadeOutDuration = this.timePreempt * osuBase.ModHidden.fadeOutDurationMultiplier;
211
+ return Math.min(osuBase.MathUtils.clamp((time - fadeInStartTime) / fadeInDuration, 0, 1), 1 -
212
+ osuBase.MathUtils.clamp((time - fadeOutStartTime) / fadeOutDuration, 0, 1));
213
+ }
214
+ return osuBase.MathUtils.clamp((time - fadeInStartTime) / fadeInDuration, 0, 1);
122
215
  }
123
216
  }
124
217
 
@@ -129,7 +222,7 @@ class DifficultyHitObjectCreator {
129
222
  /**
130
223
  * The threshold for small circle buff for osu!droid.
131
224
  */
132
- DROID_CIRCLESIZE_BUFF_THRESHOLD = 52.5;
225
+ DROID_CIRCLESIZE_BUFF_THRESHOLD = 70;
133
226
  /**
134
227
  * The threshold for small circle buff for osu!standard.
135
228
  */
@@ -156,9 +249,23 @@ class DifficultyHitObjectCreator {
156
249
  params.objects[0].scale = scale;
157
250
  const scalingFactor = this.getScalingFactor(params.objects[0].radius);
158
251
  const difficultyObjects = [];
252
+ const preemptWithoutSpeedMultiplier = params.preempt / params.speedMultiplier;
159
253
  for (let i = 0; i < params.objects.length; ++i) {
160
- const object = new DifficultyHitObject(params.objects[i]);
254
+ const object = new DifficultyHitObject(params.objects[i], difficultyObjects);
255
+ object.index = difficultyObjects.length - 1;
161
256
  object.object.scale = scale;
257
+ object.timePreempt = params.preempt;
258
+ // Preempt time can go below 450ms. Normally, this is achieved via the DT mod or a
259
+ // custom speed multiplier which uniformly speeds up all animations game wide regardless of AR.
260
+ //
261
+ // This uniform speedup is hard to match 1:1, however we can at least make AR>10 (via mods)
262
+ // feel good by extending the upper linear function above.
263
+ //
264
+ // Note that this doesn't exactly match the AR>10 visuals as they're classically known, but it feels good.
265
+ // This adjustment is necessary for AR>10, otherwise timePreempt can become smaller
266
+ // leading to hitcircles not fully fading in.
267
+ object.timeFadeIn =
268
+ 400 * Math.min(1, object.timePreempt / osuBase.MapStats.arToMS(10));
162
269
  if (object.object instanceof osuBase.Slider) {
163
270
  object.velocity =
164
271
  object.object.velocity * params.speedMultiplier;
@@ -182,10 +289,18 @@ class DifficultyHitObjectCreator {
182
289
  params.speedMultiplier;
183
290
  // Cap to 25ms to prevent difficulty calculation breaking from simultaneous objects.
184
291
  object.strainTime = Math.max(this.minDeltaTime, object.deltaTime);
185
- const visibleObjects = params.objects.filter((o) => o.startTime / params.speedMultiplier > object.startTime &&
292
+ if (object.object instanceof osuBase.Spinner ||
293
+ lastObject.object instanceof osuBase.Spinner) {
294
+ difficultyObjects.push(object);
295
+ continue;
296
+ }
297
+ const visibleObjects = params.objects
298
+ .filter((o) => o.startTime / params.speedMultiplier >=
299
+ object.startTime &&
186
300
  o.startTime / params.speedMultiplier <=
187
- object.endTime + params.preempt);
188
- object.noteDensity = 1;
301
+ object.endTime + preemptWithoutSpeedMultiplier)
302
+ // The current object will be included, so we need to exclude it.
303
+ .slice(1);
189
304
  for (const hitObject of visibleObjects) {
190
305
  // Calculate delta time assuming the current object is a circle.
191
306
  let deltaTime = Math.abs(hitObject.startTime / params.speedMultiplier -
@@ -204,7 +319,8 @@ class DifficultyHitObjectCreator {
204
319
  object.endTime));
205
320
  }
206
321
  }
207
- object.noteDensity += 1 - deltaTime / params.preempt;
322
+ object.noteDensity +=
323
+ 1 - deltaTime / preemptWithoutSpeedMultiplier;
208
324
  if (!(hitObject instanceof osuBase.Spinner)) {
209
325
  object.overlappingFactor +=
210
326
  // Penalize objects that are too close to the object in both distance
@@ -219,11 +335,6 @@ class DifficultyHitObjectCreator {
219
335
  75))));
220
336
  }
221
337
  }
222
- if (object.object instanceof osuBase.Spinner ||
223
- lastObject.object instanceof osuBase.Spinner) {
224
- difficultyObjects.push(object);
225
- continue;
226
- }
227
338
  const lastCursorPosition = this.getEndCursorPosition(lastObject.object);
228
339
  object.lazyJumpDistance = object.object.stackedPosition
229
340
  .scale(scalingFactor)
@@ -280,9 +391,7 @@ class DifficultyHitObjectCreator {
280
391
  if (this.mode === osuBase.modes.droid) {
281
392
  slider.tail.startTime += osuBase.Slider.legacyLastTickOffset;
282
393
  slider.tail.endTime += osuBase.Slider.legacyLastTickOffset;
283
- slider.nestedHitObjects.sort((a, b) => {
284
- return a.startTime - b.startTime;
285
- });
394
+ slider.nestedHitObjects.sort((a, b) => a.startTime - b.startTime);
286
395
  // Temporary lazy end position until a real result can be derived.
287
396
  slider.lazyEndPosition = slider.stackedPosition;
288
397
  // Stop here if the slider has too short duration due to float number limitation.
@@ -366,8 +475,8 @@ class DifficultyHitObjectCreator {
366
475
  if (radius < this.DROID_CIRCLESIZE_BUFF_THRESHOLD) {
367
476
  scalingFactor *=
368
477
  1 +
369
- Math.min(this.DROID_CIRCLESIZE_BUFF_THRESHOLD - radius, 20) /
370
- 40;
478
+ Math.pow((this.DROID_CIRCLESIZE_BUFF_THRESHOLD - radius) /
479
+ 50, 2);
371
480
  }
372
481
  break;
373
482
  case osuBase.modes.osu:
@@ -394,179 +503,184 @@ class DifficultyHitObjectCreator {
394
503
  }
395
504
 
396
505
  /**
397
- * A bare minimal abstract skill for fully custom skill implementations.
506
+ * The base of a difficulty calculator.
398
507
  */
399
- class Skill {
508
+ class DifficultyCalculator {
400
509
  /**
401
- * The hitobjects that were processed previously. They can affect the strain values of the following objects.
402
- *
403
- * The latest hitobject is at index 0.
510
+ * The calculated beatmap.
404
511
  */
405
- previous = [];
512
+ beatmap;
406
513
  /**
407
- * Number of previous hitobjects to keep inside the `previous` array.
514
+ * The difficulty objects of the beatmap.
408
515
  */
409
- historyLength = 2;
516
+ objects = [];
410
517
  /**
411
- * The mods that this skill processes.
518
+ * The modifications applied.
412
519
  */
413
- mods;
414
- constructor(mods) {
415
- this.mods = mods;
416
- }
417
- processInternal(current) {
418
- while (this.previous.length > this.historyLength) {
419
- this.previous.pop();
420
- }
421
- this.process(current);
422
- this.previous.unshift(current);
423
- }
424
- }
425
-
426
- /**
427
- * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
428
- * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
429
- */
430
- class StrainSkill extends Skill {
520
+ mods = [];
431
521
  /**
432
- * The strain of currently calculated hitobject.
522
+ * The total star rating of the beatmap.
433
523
  */
434
- currentStrain = 0;
524
+ total = 0;
435
525
  /**
436
- * The current section's strain peak.
526
+ * The map statistics of the beatmap after modifications are applied.
437
527
  */
438
- currentSectionPeak = 0;
528
+ stats = new osuBase.MapStats();
439
529
  /**
440
- * Strain peaks are stored here.
530
+ * The strain peaks of various calculated difficulties.
441
531
  */
442
- strainPeaks = [];
532
+ strainPeaks = {
533
+ aimWithSliders: [],
534
+ aimWithoutSliders: [],
535
+ speed: [],
536
+ flashlight: [],
537
+ };
538
+ /**
539
+ * Additional data that is used in performance calculation.
540
+ */
541
+ attributes = {
542
+ speedNoteCount: 0,
543
+ sliderFactor: 1,
544
+ aimDifficultStrainCount: 0,
545
+ speedDifficultStrainCount: 0,
546
+ };
443
547
  sectionLength = 400;
444
- currentSectionEnd = 0;
445
548
  /**
446
- * Calculates the strain value of a hitobject and stores the value in it. This value is affected by previously processed objects.
549
+ * Constructs a new instance of the calculator.
447
550
  *
448
- * @param current The hitobject to process.
551
+ * @param beatmap The beatmap to calculate. This beatmap will be deep-cloned to prevent reference changes.
449
552
  */
450
- process(current) {
451
- // The first object doesn't generate a strain, so we begin with an incremented section end
452
- if (this.previous.length === 0) {
453
- this.currentSectionEnd =
454
- Math.ceil(current.startTime / this.sectionLength) *
455
- this.sectionLength;
456
- }
457
- while (current.startTime > this.currentSectionEnd) {
458
- this.saveCurrentPeak();
459
- this.startNewSectionFrom(this.currentSectionEnd);
460
- this.currentSectionEnd += this.sectionLength;
461
- }
462
- this.currentStrain = this.strainValueAt(current);
463
- this.saveToHitObject(current);
464
- this.currentSectionPeak = Math.max(this.currentStrain, this.currentSectionPeak);
553
+ constructor(beatmap) {
554
+ this.beatmap = osuBase.Utils.deepCopy(beatmap);
465
555
  }
466
556
  /**
467
- * Saves the current peak strain level to the list of strain peaks, which will be used to calculate an overall difficulty.
557
+ * Calculates the star rating of the specified beatmap.
558
+ *
559
+ * The beatmap is analyzed in chunks of `sectionLength` duration.
560
+ * For each chunk the highest hitobject strains are added to
561
+ * a list which is then collapsed into a weighted sum, much
562
+ * like scores are weighted on a user's profile.
563
+ *
564
+ * For subsequent chunks, the initial max strain is calculated
565
+ * by decaying the previous hitobject's strain until the
566
+ * beginning of the new chunk.
567
+ *
568
+ * @param options Options for the difficulty calculation.
468
569
  */
469
- saveCurrentPeak() {
470
- this.strainPeaks.push(this.currentSectionPeak);
570
+ calculate(options) {
571
+ this.mods = options?.mods ?? [];
572
+ this.stats = new osuBase.MapStats({
573
+ cs: this.beatmap.difficulty.cs,
574
+ ar: this.beatmap.difficulty.ar,
575
+ od: this.beatmap.difficulty.od,
576
+ hp: this.beatmap.difficulty.hp,
577
+ mods: options?.mods,
578
+ speedMultiplier: options?.stats?.speedMultiplier ?? 1,
579
+ oldStatistics: options?.stats?.oldStatistics ?? false,
580
+ }).calculate({ mode: this.mode });
581
+ this.generateDifficultyHitObjects();
582
+ this.calculateAll();
583
+ return this;
471
584
  }
472
585
  /**
473
- * Sets the initial strain level for a new section.
586
+ * Generates difficulty hitobjects for this calculator.
587
+ */
588
+ generateDifficultyHitObjects() {
589
+ this.objects.length = 0;
590
+ this.objects.push(...new DifficultyHitObjectCreator().generateDifficultyObjects({
591
+ objects: this.beatmap.hitObjects.objects,
592
+ circleSize: this.stats.cs,
593
+ speedMultiplier: this.stats.speedMultiplier,
594
+ mode: this.mode,
595
+ preempt: osuBase.MapStats.arToMS(this.stats.ar),
596
+ }));
597
+ }
598
+ /**
599
+ * Calculates the skills provided.
474
600
  *
475
- * @param offset The beginning of the new section in milliseconds, adjusted by speed multiplier.
601
+ * @param skills The skills to calculate.
476
602
  */
477
- startNewSectionFrom(offset) {
478
- // The maximum strain of the new section is not zero by default, strain decays as usual regardless of section boundaries.
479
- // This means we need to capture the strain level at the beginning of the new section, and use that as the initial peak level.
480
- this.currentSectionPeak =
481
- this.currentStrain *
482
- this.strainDecay(offset - this.previous[0].startTime);
603
+ calculateSkills(...skills) {
604
+ // The first object doesn't generate a strain, so we begin calculating from the second object.
605
+ this.objects.slice(1).forEach((h, i) => {
606
+ skills.forEach((skill) => {
607
+ skill.process(h);
608
+ if (i === this.objects.length - 2) {
609
+ // Don't forget to save the last strain peak, which would otherwise be ignored.
610
+ skill.saveCurrentPeak();
611
+ }
612
+ });
613
+ });
483
614
  }
484
615
  /**
485
- * Calculates strain decay for a specified time frame.
616
+ * Calculates the star rating value of a difficulty.
486
617
  *
487
- * @param ms The time frame to calculate.
618
+ * @param difficulty The difficulty to calculate.
488
619
  */
489
- strainDecay(ms) {
490
- return Math.pow(this.strainDecayBase, ms / 1000);
620
+ starValue(difficulty) {
621
+ return Math.sqrt(difficulty) * this.difficultyMultiplier;
491
622
  }
492
- }
493
-
494
- /**
495
- * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
496
- * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
497
- */
498
- class DroidSkill extends StrainSkill {
499
- difficultyValue() {
500
- const sortedStrains = this.strainPeaks
501
- .slice()
502
- .sort((a, b) => {
503
- return b - a;
504
- });
505
- // We are reducing the highest strains first to account for extreme difficulty spikes.
506
- for (let i = 0; i < Math.min(sortedStrains.length, this.reducedSectionCount); ++i) {
507
- const scale = Math.log10(osuBase.Interpolation.lerp(1, 10, osuBase.MathUtils.clamp(i / this.reducedSectionCount, 0, 1)));
508
- sortedStrains[i] *= osuBase.Interpolation.lerp(this.reducedSectionBaseline, 1, scale);
509
- }
510
- // Math here preserves the property that two notes of equal difficulty x, we have their summed difficulty = x * starsPerDouble.
511
- // This also applies to two sets of notes with equal difficulty.
512
- return Math.pow(sortedStrains.reduce((a, v) => {
513
- if (v === 0) {
514
- return a;
515
- }
516
- return a + Math.pow(v, 1 / Math.log2(this.starsPerDouble));
517
- }, 0), Math.log2(this.starsPerDouble));
623
+ /**
624
+ * Calculates the base performance value of a difficulty rating.
625
+ *
626
+ * @param rating The difficulty rating.
627
+ */
628
+ basePerformanceValue(rating) {
629
+ return Math.pow(5 * Math.max(1, rating / 0.0675) - 4, 3) / 100000;
518
630
  }
519
631
  }
520
632
 
521
633
  /**
522
- * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
634
+ * An evaluator for calculating osu!droid Aim skill.
523
635
  */
524
- class DroidAim extends DroidSkill {
525
- skillMultiplier = 23.25;
526
- strainDecayBase = 0.15;
527
- reducedSectionCount = 10;
528
- reducedSectionBaseline = 0.75;
529
- starsPerDouble = 1.05;
636
+ class DroidAimEvaluator extends AimEvaluator {
530
637
  /**
531
638
  * Spacing threshold for a single hitobject spacing.
532
639
  */
533
- SINGLE_SPACING_THRESHOLD = 175;
640
+ static SINGLE_SPACING_THRESHOLD = 175;
534
641
  // ~200 1/2 BPM jumps
535
- minSpeedBonus = 150;
536
- wideAngleMultiplier = 1.5;
537
- acuteAngleMultiplier = 2;
538
- sliderMultiplier = 1.5;
539
- velocityChangeMultiplier = 0.75;
540
- withSliders;
541
- constructor(mods, withSliders) {
542
- super(mods);
543
- this.withSliders = withSliders;
544
- }
642
+ static minSpeedBonus = 150;
545
643
  /**
546
- * @param current The hitobject to calculate.
644
+ * Evaluates the difficulty of aiming the current object, based on:
645
+ *
646
+ * - cursor velocity to the current object,
647
+ * - angle difficulty,
648
+ * - sharp velocity increases,
649
+ * - and slider difficulty.
650
+ *
651
+ * @param current The current object.
652
+ * @param withSliders Whether to take slider difficulty into account.
547
653
  */
548
- strainValueOf(current) {
549
- if (current.object instanceof osuBase.Spinner) {
654
+ static evaluateDifficultyOf(current, withSliders) {
655
+ const last = current.previous(0);
656
+ if (current.object instanceof osuBase.Spinner ||
657
+ // Exclude overlapping objects that can be tapped at once.
658
+ (current.deltaTime < 5 &&
659
+ ((last?.object instanceof osuBase.Slider
660
+ ? Math.min(last.object.stackedEndPosition.getDistance(current.object.stackedPosition), last.object.lazyEndPosition.getDistance(current.object.stackedPosition))
661
+ : last?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) ?? Number.POSITIVE_INFINITY) <=
662
+ 2 * current.object.radius)) {
550
663
  return 0;
551
664
  }
552
- return this.aimStrainOf(current) + this.movementStrainOf(current);
665
+ return (this.aimStrainOf(current, withSliders) +
666
+ this.movementStrainOf(current));
553
667
  }
554
668
  /**
555
669
  * Calculates the aim strain of a hitobject.
556
670
  */
557
- aimStrainOf(current) {
558
- if (this.previous.length <= 1 ||
559
- this.previous[0].object instanceof osuBase.Spinner) {
671
+ static aimStrainOf(current, withSliders) {
672
+ if (current.index <= 1 ||
673
+ current.previous(0)?.object instanceof osuBase.Spinner) {
560
674
  return 0;
561
675
  }
562
- const last = this.previous[0];
563
- const lastLast = this.previous[1];
676
+ const last = current.previous(0);
677
+ const lastLast = current.previous(1);
564
678
  // Calculate the velocity to the current hitobject, which starts with a base distance / time assuming the last object is a hitcircle.
565
679
  let currentVelocity = current.lazyJumpDistance / current.strainTime;
566
680
  // But if the last object is a slider, then we extend the travel velocity through the slider into the current object.
567
681
  if (last.object instanceof osuBase.Slider &&
568
682
  last.object.ticks > 0 &&
569
- this.withSliders) {
683
+ withSliders) {
570
684
  // Calculate the slider velocity from slider head to slider end.
571
685
  const travelVelocity = last.travelDistance / last.travelTime;
572
686
  // Calculate the movement velocity from slider end to current object.
@@ -580,7 +694,7 @@ class DroidAim extends DroidSkill {
580
694
  let prevVelocity = last.lazyJumpDistance / last.strainTime;
581
695
  if (lastLast.object instanceof osuBase.Slider &&
582
696
  lastLast.object.ticks > 0 &&
583
- this.withSliders) {
697
+ withSliders) {
584
698
  const travelVelocity = lastLast.travelDistance / lastLast.travelTime;
585
699
  const movementVelocity = last.minimumJumpTime !== 0
586
700
  ? last.minimumJumpDistance / last.minimumJumpTime
@@ -669,7 +783,7 @@ class DroidAim extends DroidSkill {
669
783
  strain += Math.max(acuteAngleBonus * this.acuteAngleMultiplier, wideAngleBonus * this.wideAngleMultiplier +
670
784
  velocityChangeBonus * this.velocityChangeMultiplier);
671
785
  // Add in additional slider velocity bonus.
672
- if (this.withSliders) {
786
+ if (withSliders) {
673
787
  strain += sliderBonus * this.sliderMultiplier;
674
788
  }
675
789
  return strain;
@@ -677,93 +791,145 @@ class DroidAim extends DroidSkill {
677
791
  /**
678
792
  * Calculates the movement strain of a hitobject.
679
793
  */
680
- movementStrainOf(current) {
794
+ static movementStrainOf(current) {
681
795
  let speedBonus = 1;
682
796
  if (current.strainTime < this.minSpeedBonus) {
683
797
  speedBonus +=
684
798
  0.75 *
685
799
  Math.pow((this.minSpeedBonus - current.strainTime) / 45, 2);
686
800
  }
687
- const travelDistance = this.previous[0]?.travelDistance ?? 0;
801
+ const travelDistance = current.previous(0)?.travelDistance ?? 0;
688
802
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
689
803
  return ((50 *
690
804
  speedBonus *
691
805
  Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 5)) /
692
806
  current.strainTime);
693
807
  }
808
+ }
809
+
810
+ /**
811
+ * A bare minimal abstract skill for fully custom skill implementations.
812
+ */
813
+ class Skill {
694
814
  /**
695
- * @param current The hitobject to calculate.
815
+ * The mods that this skill processes.
696
816
  */
697
- strainValueAt(current) {
698
- this.currentStrain *= this.strainDecay(current.deltaTime);
699
- this.currentStrain +=
700
- this.strainValueOf(current) * this.skillMultiplier;
701
- return this.currentStrain;
817
+ mods;
818
+ constructor(mods) {
819
+ this.mods = mods;
702
820
  }
821
+ }
822
+
823
+ /**
824
+ * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
825
+ * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
826
+ */
827
+ class StrainSkill extends Skill {
703
828
  /**
704
- * @param current The hitobject to save to.
829
+ * The strain of currently calculated hitobject.
705
830
  */
706
- saveToHitObject(current) {
707
- if (this.withSliders) {
708
- current.aimStrainWithSliders = this.currentStrain;
709
- }
710
- else {
711
- current.aimStrainWithoutSliders = this.currentStrain;
712
- }
713
- }
831
+ currentStrain = 0;
714
832
  /**
715
- * Calculates the bonus of wide angles.
833
+ * The current section's strain peak.
716
834
  */
717
- calculateWideAngleBonus(angle) {
718
- return Math.pow(Math.sin((3 / 4) *
719
- (Math.min((5 / 6) * Math.PI, Math.max(Math.PI / 6, angle)) -
720
- Math.PI / 6)), 2);
721
- }
835
+ currentSectionPeak = 0;
722
836
  /**
723
- * Calculates the bonus of acute angles.
837
+ * Strain peaks are stored here.
724
838
  */
725
- calculateAcuteAngleBonus(angle) {
726
- return 1 - this.calculateWideAngleBonus(angle);
839
+ strainPeaks = [];
840
+ sectionLength = 400;
841
+ currentSectionEnd = 0;
842
+ isFirstObject = true;
843
+ /**
844
+ * Calculates the strain value of a hitobject and stores the value in it. This value is affected by previously processed objects.
845
+ *
846
+ * @param current The hitobject to process.
847
+ */
848
+ process(current) {
849
+ // The first object doesn't generate a strain, so we begin with an incremented section end
850
+ if (this.isFirstObject) {
851
+ this.currentSectionEnd =
852
+ Math.ceil(current.startTime / this.sectionLength) *
853
+ this.sectionLength;
854
+ this.isFirstObject = false;
855
+ }
856
+ while (current.startTime > this.currentSectionEnd) {
857
+ this.saveCurrentPeak();
858
+ this.startNewSectionFrom(this.currentSectionEnd, current);
859
+ this.currentSectionEnd += this.sectionLength;
860
+ }
861
+ // Ignore the first hitobject.
862
+ this.currentStrain = this.strainValueAt(current);
863
+ this.saveToHitObject(current);
864
+ this.currentSectionPeak = Math.max(this.currentStrain, this.currentSectionPeak);
865
+ }
866
+ /**
867
+ * Saves the current peak strain level to the list of strain peaks, which will be used to calculate an overall difficulty.
868
+ */
869
+ saveCurrentPeak() {
870
+ this.strainPeaks.push(this.currentSectionPeak);
871
+ }
872
+ /**
873
+ * Calculates strain decay for a specified time frame.
874
+ *
875
+ * @param ms The time frame to calculate.
876
+ */
877
+ strainDecay(ms) {
878
+ return Math.pow(this.strainDecayBase, ms / 1000);
879
+ }
880
+ /**
881
+ * Sets the initial strain level for a new section.
882
+ *
883
+ * @param offset The beginning of the new section in milliseconds, adjusted by speed multiplier.
884
+ * @param current The current hitobject.
885
+ */
886
+ startNewSectionFrom(offset, current) {
887
+ // The maximum strain of the new section is not zero by default, strain decays as usual regardless of section boundaries.
888
+ // This means we need to capture the strain level at the beginning of the new section, and use that as the initial peak level.
889
+ this.currentSectionPeak =
890
+ this.currentStrain *
891
+ this.strainDecay(offset - current.previous(0).startTime);
727
892
  }
728
893
  }
729
894
 
730
895
  /**
731
- * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
896
+ * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
897
+ * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
732
898
  */
733
- class DroidFlashlight extends DroidSkill {
734
- historyLength = 10;
735
- skillMultiplier = 0.15;
899
+ class DroidSkill extends StrainSkill {
900
+ difficultyValue() {
901
+ const sortedStrains = this.strainPeaks
902
+ .slice()
903
+ .sort((a, b) => b - a);
904
+ // We are reducing the highest strains first to account for extreme difficulty spikes.
905
+ for (let i = 0; i < Math.min(sortedStrains.length, this.reducedSectionCount); ++i) {
906
+ const scale = Math.log10(osuBase.Interpolation.lerp(1, 10, osuBase.MathUtils.clamp(i / this.reducedSectionCount, 0, 1)));
907
+ sortedStrains[i] *= osuBase.Interpolation.lerp(this.reducedSectionBaseline, 1, scale);
908
+ }
909
+ // Math here preserves the property that two notes of equal difficulty x, we have their summed difficulty = x * starsPerDouble.
910
+ // This also applies to two sets of notes with equal difficulty.
911
+ return Math.pow(sortedStrains.reduce((a, v) => {
912
+ if (v <= 0) {
913
+ return a;
914
+ }
915
+ return a + Math.pow(v, 1 / Math.log2(this.starsPerDouble));
916
+ }, 0), Math.log2(this.starsPerDouble));
917
+ }
918
+ }
919
+
920
+ /**
921
+ * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
922
+ */
923
+ class DroidAim extends DroidSkill {
924
+ skillMultiplier = 23.25;
736
925
  strainDecayBase = 0.15;
737
926
  reducedSectionCount = 10;
738
927
  reducedSectionBaseline = 0.75;
739
928
  starsPerDouble = 1.05;
740
- strainValueOf(current) {
741
- if (current.object instanceof osuBase.Spinner) {
742
- return 0;
743
- }
744
- const scalingFactor = 52 / current.object.radius;
745
- let smallDistNerf = 1;
746
- let cumulativeStrainTime = 0;
747
- let result = 0;
748
- let last = current;
749
- for (let i = 0; i < this.previous.length; ++i) {
750
- const currentObject = this.previous[i];
751
- if (!(currentObject.object instanceof osuBase.Spinner)) {
752
- const jumpDistance = current.object.stackedPosition.subtract(currentObject.object.endPosition).length;
753
- cumulativeStrainTime += last.strainTime;
754
- // We want to nerf objects that can be easily seen within the Flashlight circle radius.
755
- if (i === 0) {
756
- smallDistNerf = Math.min(1, jumpDistance / 75);
757
- }
758
- // We also want to nerf stacks so that only the first object of the stack is accounted for.
759
- const stackNerf = Math.min(1, currentObject.lazyJumpDistance / scalingFactor / 25);
760
- result +=
761
- (stackNerf * scalingFactor * jumpDistance) /
762
- cumulativeStrainTime;
763
- }
764
- last = currentObject;
765
- }
766
- return Math.pow(smallDistNerf * result, 2);
929
+ withSliders;
930
+ constructor(mods, withSliders) {
931
+ super(mods);
932
+ this.withSliders = withSliders;
767
933
  }
768
934
  /**
769
935
  * @param current The hitobject to calculate.
@@ -771,11 +937,79 @@ class DroidFlashlight extends DroidSkill {
771
937
  strainValueAt(current) {
772
938
  this.currentStrain *= this.strainDecay(current.deltaTime);
773
939
  this.currentStrain +=
774
- this.strainValueOf(current) * this.skillMultiplier;
940
+ DroidAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
941
+ this.skillMultiplier;
775
942
  return this.currentStrain;
776
943
  }
944
+ /**
945
+ * @param current The hitobject to save to.
946
+ */
777
947
  saveToHitObject(current) {
778
- current.flashlightStrain = this.currentStrain;
948
+ if (this.withSliders) {
949
+ current.aimStrainWithSliders = this.currentStrain;
950
+ }
951
+ else {
952
+ current.aimStrainWithoutSliders = this.currentStrain;
953
+ }
954
+ }
955
+ }
956
+
957
+ /**
958
+ * An evaluator for calculating speed or tap skill.
959
+ *
960
+ * This class should be considered an "evaluating" class and not persisted.
961
+ */
962
+ class SpeedEvaluator {
963
+ // ~200 1/4 BPM streams
964
+ static minSpeedBonus = 75;
965
+ }
966
+
967
+ /**
968
+ * An evaluator for calculating osu!droid tap skill.
969
+ */
970
+ class DroidTapEvaluator extends SpeedEvaluator {
971
+ /**
972
+ * Evaluates the difficulty of tapping the current object, based on:
973
+ *
974
+ * - time between pressing the previous and current object,
975
+ * - distance between those objects,
976
+ * - and how easily they can be cheesed.
977
+ *
978
+ * @param current The current object.
979
+ * @param greatWindow The great hit window of the current object.
980
+ * @param considerCheesability Whether to consider cheesability.
981
+ */
982
+ static evaluateDifficultyOf(current, greatWindow, considerCheesability) {
983
+ if (current.object instanceof osuBase.Spinner ||
984
+ // Exclude overlapping objects that can be tapped at once.
985
+ current.deltaTime < 5) {
986
+ return 0;
987
+ }
988
+ let strainTime = current.strainTime;
989
+ let doubletapness = 1;
990
+ if (considerCheesability) {
991
+ const greatWindowFull = greatWindow * 2;
992
+ // Nerf doubletappable doubles.
993
+ const next = current.next(0);
994
+ if (next) {
995
+ const currentDeltaTime = Math.max(1, current.deltaTime);
996
+ const nextDeltaTime = Math.max(1, next.deltaTime);
997
+ const deltaDifference = Math.abs(nextDeltaTime - currentDeltaTime);
998
+ const speedRatio = currentDeltaTime /
999
+ Math.max(currentDeltaTime, deltaDifference);
1000
+ const windowRatio = Math.pow(Math.min(1, currentDeltaTime / greatWindowFull), 2);
1001
+ doubletapness = Math.pow(speedRatio, 1 - windowRatio);
1002
+ }
1003
+ // Cap deltatime to the OD 300 hitwindow.
1004
+ // 0.58 is derived from making sure 260 BPM 1/4 OD5 streams aren't nerfed harshly, whilst 0.91 limits the effect of the cap.
1005
+ strainTime /= osuBase.MathUtils.clamp(strainTime / greatWindowFull / 0.58, 0.91, 1);
1006
+ }
1007
+ let speedBonus = 1;
1008
+ if (strainTime < this.minSpeedBonus) {
1009
+ speedBonus +=
1010
+ 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
1011
+ }
1012
+ return (speedBonus * doubletapness) / strainTime;
779
1013
  }
780
1014
  }
781
1015
 
@@ -792,63 +1026,25 @@ class DroidTap extends DroidSkill {
792
1026
  minSpeedBonus = 75;
793
1027
  currentTapStrain = 0;
794
1028
  currentOriginalTapStrain = 0;
795
- hitWindow;
1029
+ greatWindow;
796
1030
  constructor(mods, overallDifficulty) {
797
1031
  super(mods);
798
- this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1032
+ this.greatWindow = new osuBase.OsuHitWindow(overallDifficulty).hitWindowFor300();
799
1033
  }
800
1034
  /**
801
1035
  * @param current The hitobject to calculate.
802
1036
  */
803
- strainValueOf(current) {
804
- if (current.object instanceof osuBase.Spinner) {
805
- return 0;
806
- }
807
- let strainTime = current.strainTime;
808
- const greatWindowFull = this.hitWindow.hitWindowFor300() * 2;
809
- // Aim to nerf cheesy rhythms (very fast consecutive doubles with large deltatimes between).
810
- if (this.previous[0] &&
811
- strainTime < greatWindowFull &&
812
- this.previous[0].strainTime > strainTime) {
813
- strainTime = osuBase.Interpolation.lerp(this.previous[0].strainTime, strainTime, strainTime / greatWindowFull);
814
- }
815
- // Cap deltatime to the OD 300 hitwindow.
816
- // 0.58 is derived from making sure 260 BPM 1/4 OD5 streams aren't nerfed harshly, whilst 0.91 limits the effect of the cap.
817
- strainTime /= osuBase.MathUtils.clamp(strainTime / greatWindowFull / 0.58, 0.91, 1);
818
- let speedBonus = 1;
819
- if (strainTime < this.minSpeedBonus) {
820
- speedBonus +=
821
- 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
822
- }
823
- let originalSpeedBonus = 1;
824
- if (current.strainTime < this.minSpeedBonus) {
825
- originalSpeedBonus +=
826
- 0.75 *
827
- Math.pow((this.minSpeedBonus - current.strainTime) / 40, 2);
828
- }
829
- const decay = this.strainDecay(current.deltaTime);
1037
+ strainValueAt(current) {
1038
+ const decay = this.strainDecay(current.strainTime);
830
1039
  this.currentTapStrain *= decay;
831
1040
  this.currentTapStrain +=
832
- this.tapStrainOf(speedBonus, strainTime) * this.skillMultiplier;
1041
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, true) * this.skillMultiplier;
833
1042
  this.currentOriginalTapStrain *= decay;
834
1043
  this.currentOriginalTapStrain +=
835
- this.tapStrainOf(originalSpeedBonus, current.strainTime) *
836
- this.skillMultiplier;
1044
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, false) * this.skillMultiplier;
837
1045
  this.currentOriginalTapStrain *= current.rhythmMultiplier;
838
1046
  return this.currentTapStrain * current.rhythmMultiplier;
839
1047
  }
840
- /**
841
- * Calculates the tap strain of a hitobject given a specific speed bonus and strain time.
842
- */
843
- tapStrainOf(speedBonus, strainTime) {
844
- return speedBonus / strainTime;
845
- }
846
- /**
847
- * @param current The hitobject to calculate.
848
- */
849
- strainValueAt(current) {
850
- return this.strainValueOf(current);
851
- }
852
1048
  /**
853
1049
  * @param current The hitobject to save to.
854
1050
  */
@@ -859,158 +1055,129 @@ class DroidTap extends DroidSkill {
859
1055
  }
860
1056
 
861
1057
  /**
862
- * The base of difficulty calculation.
1058
+ * An evaluator for calculating flashlight skill.
1059
+ *
1060
+ * This class should be considered an "evaluating" class and not persisted.
863
1061
  */
864
- class StarRating {
865
- /**
866
- * The calculated beatmap.
867
- */
868
- map = new osuBase.Beatmap();
869
- /**
870
- * The difficulty objects of the beatmap.
871
- */
872
- objects = [];
873
- /**
874
- * The modifications applied.
875
- */
876
- mods = [];
877
- /**
878
- * The total star rating of the beatmap.
879
- */
880
- total = 0;
881
- /**
882
- * The map statistics of the beatmap after modifications are applied.
883
- */
884
- stats = new osuBase.MapStats();
885
- /**
886
- * The strain peaks of various calculated difficulties.
887
- */
888
- strainPeaks = {
889
- aimWithSliders: [],
890
- aimWithoutSliders: [],
891
- speed: [],
892
- flashlight: [],
893
- };
894
- /**
895
- * Additional data that is used in performance calculation.
896
- */
897
- attributes = {
898
- speedNoteCount: 0,
899
- sliderFactor: 1,
900
- aimDifficultStrainCount: 0,
901
- speedDifficultStrainCount: 0,
902
- };
903
- sectionLength = 400;
904
- /**
905
- * Calculates the star rating of the specified beatmap.
906
- *
907
- * The beatmap is analyzed in chunks of `sectionLength` duration.
908
- * For each chunk the highest hitobject strains are added to
909
- * a list which is then collapsed into a weighted sum, much
910
- * like scores are weighted on a user's profile.
911
- *
912
- * For subsequent chunks, the initial max strain is calculated
913
- * by decaying the previous hitobject's strain until the
914
- * beginning of the new chunk.
915
- *
916
- * The first object doesn't generate a strain
917
- * so we begin calculating from the second object.
918
- *
919
- * Also don't forget to manually add the peak strain for the last
920
- * section which would otherwise be ignored.
921
- */
922
- calculate(params, mode) {
923
- const map = (this.map = osuBase.Utils.deepCopy(params.map));
924
- const mod = (this.mods = params.mods ?? this.mods);
925
- this.stats = new osuBase.MapStats({
926
- cs: map.difficulty.cs,
927
- ar: map.difficulty.ar,
928
- od: map.difficulty.od,
929
- hp: map.difficulty.hp,
930
- mods: mod,
931
- speedMultiplier: params.stats?.speedMultiplier ?? 1,
932
- oldStatistics: params.stats?.oldStatistics ?? false,
933
- }).calculate({ mode: mode });
934
- this.generateDifficultyHitObjects(mode);
935
- this.calculateAll();
936
- return this;
937
- }
1062
+ class FlashlightEvaluator {
1063
+ static maxOpacityBonus = 0.4;
1064
+ static hiddenBonus = 0.2;
1065
+ }
1066
+
1067
+ /**
1068
+ * An evaluator for calculating osu!droid Flashlight skill.
1069
+ */
1070
+ class DroidFlashlightEvaluator extends FlashlightEvaluator {
938
1071
  /**
939
- * Generates difficulty hitobjects for this calculator.
1072
+ * Evaluates the difficulty of memorizing and hitting the current object, based on:
940
1073
  *
941
- * @param mode The gamemode to generate difficulty hitobjects for.
942
- */
943
- generateDifficultyHitObjects(mode) {
944
- this.objects.length = 0;
945
- this.objects.push(...new DifficultyHitObjectCreator().generateDifficultyObjects({
946
- objects: this.map.hitObjects.objects,
947
- circleSize: this.stats.cs,
948
- speedMultiplier: this.stats.speedMultiplier,
949
- mode: mode,
950
- preempt: osuBase.MapStats.arToMS(this.stats.ar),
951
- }));
952
- }
953
- /**
954
- * Calculates the skills provided.
1074
+ * - distance between the previous and the current object,
1075
+ * - the visual opacity of the current object,
1076
+ * - and whether Hidden mod is enabled.
955
1077
  *
956
- * @param skills The skills to calculate.
1078
+ * @param current The current object.
1079
+ * @param isHiddenMod Whether the Hidden mod is enabled.
957
1080
  */
958
- calculateSkills(...skills) {
959
- this.objects.slice(1).forEach((h, i) => {
960
- skills.forEach((skill) => {
961
- skill.processInternal(h);
962
- if (i === this.objects.length - 2) {
963
- // Don't forget to save the last strain peak, which would otherwise be ignored.
964
- skill.saveCurrentPeak();
1081
+ static evaluateDifficultyOf(current, isHiddenMod) {
1082
+ const actualLast = current.previous(0);
1083
+ if (current.object instanceof osuBase.Spinner ||
1084
+ // Exclude overlapping objects that can be tapped at once.
1085
+ (current.deltaTime < 5 &&
1086
+ ((actualLast?.object instanceof osuBase.Slider
1087
+ ? Math.min(actualLast.object.stackedEndPosition.getDistance(current.object.stackedPosition), actualLast.object.lazyEndPosition.getDistance(current.object.stackedPosition))
1088
+ : actualLast?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) ?? Number.POSITIVE_INFINITY) <=
1089
+ 2 * current.object.radius)) {
1090
+ return 0;
1091
+ }
1092
+ const scalingFactor = 52 / current.object.radius;
1093
+ let smallDistNerf = 1;
1094
+ let cumulativeStrainTime = 0;
1095
+ let result = 0;
1096
+ let last = current;
1097
+ for (let i = 0; i < Math.min(current.index, 10); ++i) {
1098
+ const currentObject = current.previous(i);
1099
+ if (!(currentObject.object instanceof osuBase.Spinner) &&
1100
+ // Exclude overlapping objects that can be tapped at once.
1101
+ currentObject.deltaTime >= 5) {
1102
+ const jumpDistance = current.object.stackedPosition.subtract(currentObject.object.endPosition).length;
1103
+ cumulativeStrainTime += last.strainTime;
1104
+ // We want to nerf objects that can be easily seen within the Flashlight circle radius.
1105
+ if (i === 0) {
1106
+ smallDistNerf = Math.min(1, jumpDistance / 75);
965
1107
  }
966
- });
967
- });
1108
+ // We also want to nerf stacks so that only the first object of the stack is accounted for.
1109
+ const stackNerf = Math.min(1, currentObject.lazyJumpDistance / scalingFactor / 25);
1110
+ // Bonus based on how visible the object is.
1111
+ const opacityBonus = 1 +
1112
+ this.maxOpacityBonus *
1113
+ (1.0 -
1114
+ current.opacityAt(currentObject.startTime, isHiddenMod));
1115
+ result +=
1116
+ (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
1117
+ cumulativeStrainTime;
1118
+ }
1119
+ last = currentObject;
1120
+ }
1121
+ // Additional bonus for Hidden due to there being no approach circles.
1122
+ if (isHiddenMod) {
1123
+ result *= 1 + this.hiddenBonus;
1124
+ }
1125
+ return Math.pow(smallDistNerf * result, 2);
968
1126
  }
969
- /**
970
- * Calculates the star rating value of a difficulty.
971
- *
972
- * @param difficulty The difficulty to calculate.
973
- */
974
- starValue(difficulty) {
975
- return Math.sqrt(difficulty) * this.difficultyMultiplier;
1127
+ }
1128
+
1129
+ /**
1130
+ * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
1131
+ */
1132
+ class DroidFlashlight extends DroidSkill {
1133
+ skillMultiplier = 0.1;
1134
+ strainDecayBase = 0.15;
1135
+ reducedSectionCount = 10;
1136
+ reducedSectionBaseline = 0.75;
1137
+ starsPerDouble = 1.05;
1138
+ isHidden;
1139
+ constructor(mods) {
1140
+ super(mods);
1141
+ this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
976
1142
  }
977
1143
  /**
978
- * Calculates the base performance value of a difficulty rating.
979
- *
980
- * @param rating The difficulty rating.
1144
+ * @param current The hitobject to calculate.
981
1145
  */
982
- basePerformanceValue(rating) {
983
- return Math.pow(5 * Math.max(1, rating / 0.0675) - 4, 3) / 100000;
1146
+ strainValueAt(current) {
1147
+ this.currentStrain *= this.strainDecay(current.deltaTime);
1148
+ this.currentStrain +=
1149
+ DroidFlashlightEvaluator.evaluateDifficultyOf(current, this.isHidden) * this.skillMultiplier;
1150
+ return this.currentStrain;
1151
+ }
1152
+ saveToHitObject(current) {
1153
+ current.flashlightStrain = this.currentStrain;
984
1154
  }
985
1155
  }
986
1156
 
987
1157
  /**
988
- * Represents the skill required to properly follow a beatmap's rhythm.
1158
+ * An evaluator for calculating rhythm skill.
1159
+ *
1160
+ * This class should be considered an "evaluating" class and not persisted.
989
1161
  */
990
- class DroidRhythm extends DroidSkill {
991
- historyLength = 32;
992
- skillMultiplier = 1;
993
- reducedSectionCount = 5;
994
- reducedSectionBaseline = 0.75;
995
- strainDecayBase = 0.3;
996
- starsPerDouble = 1.75;
997
- rhythmMultiplier;
998
- historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
999
- currentRhythm = 1;
1000
- hitWindow;
1001
- constructor(mods, overallDifficulty) {
1002
- super(mods);
1003
- this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1004
- const odScaling = Math.pow(this.hitWindow.overallDifficulty, 2) / 400;
1005
- this.rhythmMultiplier =
1006
- 0.75 +
1007
- (this.hitWindow.overallDifficulty >= 0 ? odScaling : -odScaling);
1008
- }
1162
+ class RhythmEvaluator {
1163
+ static historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1164
+ }
1165
+
1166
+ /**
1167
+ * An evaluator for calculating osu!droid Rhythm skill.
1168
+ */
1169
+ class DroidRhythmEvaluator extends RhythmEvaluator {
1009
1170
  /**
1010
- * Calculates a rhythm multiplier for the difficulty of the tap associated with historic data of the current object.
1171
+ * Calculates a rhythm multiplier for the difficulty of the tap associated
1172
+ * with historic data of the current object.
1173
+ *
1174
+ * @param current The current object.
1175
+ * @param greatWindow The great hit window of the current object.
1011
1176
  */
1012
- calculateRhythmBonus(current) {
1013
- if (current.object instanceof osuBase.Spinner) {
1177
+ static evaluateDifficultyOf(current, greatWindow) {
1178
+ if (current.object instanceof osuBase.Spinner ||
1179
+ // Exclude overlapping objects that can be tapped at once.
1180
+ current.deltaTime < 5) {
1014
1181
  return 1;
1015
1182
  }
1016
1183
  let previousIslandSize = 0;
@@ -1020,29 +1187,40 @@ class DroidRhythm extends DroidSkill {
1020
1187
  let startRatio = 0;
1021
1188
  let firstDeltaSwitch = false;
1022
1189
  let rhythmStart = 0;
1023
- while (rhythmStart < this.previous.length - 2 &&
1024
- current.startTime - this.previous[rhythmStart].startTime <
1190
+ const historicalNoteCount = Math.min(current.index, 32);
1191
+ // Exclude overlapping objects that can be tapped at once.
1192
+ const validPrevious = [];
1193
+ for (let i = 0; i < historicalNoteCount; ++i) {
1194
+ const object = current.previous(i);
1195
+ if (!object) {
1196
+ break;
1197
+ }
1198
+ if (object.deltaTime >= 5) {
1199
+ validPrevious.push(object);
1200
+ }
1201
+ }
1202
+ while (rhythmStart < validPrevious.length - 2 &&
1203
+ current.startTime - validPrevious[rhythmStart].startTime <
1025
1204
  this.historyTimeMax) {
1026
1205
  ++rhythmStart;
1027
1206
  }
1028
1207
  for (let i = rhythmStart; i > 0; --i) {
1029
1208
  // Scale note 0 to 1 from history to now.
1030
1209
  let currentHistoricalDecay = (this.historyTimeMax -
1031
- (current.startTime - this.previous[i - 1].startTime)) /
1210
+ (current.startTime - validPrevious[i - 1].startTime)) /
1032
1211
  this.historyTimeMax;
1033
1212
  // Either we're limited by time or limited by object count.
1034
- currentHistoricalDecay = Math.min(currentHistoricalDecay, (this.previous.length - i) / this.previous.length);
1035
- const currentDelta = this.previous[i - 1].strainTime;
1036
- const prevDelta = this.previous[i].strainTime;
1037
- const lastDelta = this.previous[i + 1].strainTime;
1213
+ currentHistoricalDecay = Math.min(currentHistoricalDecay, (validPrevious.length - i) / validPrevious.length);
1214
+ const currentDelta = validPrevious[i - 1].strainTime;
1215
+ const prevDelta = validPrevious[i].strainTime;
1216
+ const lastDelta = validPrevious[i + 1].strainTime;
1038
1217
  const currentRatio = 1 +
1039
1218
  6 *
1040
1219
  Math.min(0.5, Math.pow(Math.sin(Math.PI /
1041
1220
  (Math.min(prevDelta, currentDelta) /
1042
1221
  Math.max(prevDelta, currentDelta))), 2));
1043
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) -
1044
- this.hitWindow.hitWindowFor300() * 0.4) /
1045
- (this.hitWindow.hitWindowFor300() * 0.4));
1222
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - greatWindow * 0.4) /
1223
+ (greatWindow * 0.4));
1046
1224
  let effectiveRatio = windowPenalty * currentRatio;
1047
1225
  if (firstDeltaSwitch) {
1048
1226
  if (prevDelta <= 1.25 * currentDelta &&
@@ -1053,11 +1231,11 @@ class DroidRhythm extends DroidSkill {
1053
1231
  }
1054
1232
  }
1055
1233
  else {
1056
- if (this.previous[i - 1].object instanceof osuBase.Slider) {
1234
+ if (validPrevious[i - 1].object instanceof osuBase.Slider) {
1057
1235
  // BPM change is into slider, this is easy acc window.
1058
1236
  effectiveRatio /= 8;
1059
1237
  }
1060
- if (this.previous[i].object instanceof osuBase.Slider) {
1238
+ if (validPrevious[i].object instanceof osuBase.Slider) {
1061
1239
  // BPM change was from a slider, this is typically easier than circle -> circle.
1062
1240
  effectiveRatio /= 4;
1063
1241
  }
@@ -1100,10 +1278,39 @@ class DroidRhythm extends DroidSkill {
1100
1278
  islandSize = 1;
1101
1279
  }
1102
1280
  }
1103
- return Math.sqrt(4 + rhythmComplexitySum * this.rhythmMultiplier) / 2;
1281
+ return (Math.sqrt(4 +
1282
+ rhythmComplexitySum *
1283
+ this.calculateRhythmMultiplier(greatWindow)) / 2);
1284
+ }
1285
+ /**
1286
+ * Calculates the rhythm multiplier of a given hit window.
1287
+ *
1288
+ * @param greatWindow The great hit window.
1289
+ */
1290
+ static calculateRhythmMultiplier(greatWindow) {
1291
+ const od = osuBase.OsuHitWindow.hitWindow300ToOD(greatWindow);
1292
+ const odScaling = Math.pow(od, 2) / 400;
1293
+ return 0.75 + (od >= 0 ? odScaling : -odScaling);
1294
+ }
1295
+ }
1296
+
1297
+ /**
1298
+ * Represents the skill required to properly follow a beatmap's rhythm.
1299
+ */
1300
+ class DroidRhythm extends DroidSkill {
1301
+ skillMultiplier = 1;
1302
+ reducedSectionCount = 5;
1303
+ reducedSectionBaseline = 0.75;
1304
+ strainDecayBase = 0.3;
1305
+ starsPerDouble = 1.75;
1306
+ currentRhythm = 1;
1307
+ hitWindow;
1308
+ constructor(mods, overallDifficulty) {
1309
+ super(mods);
1310
+ this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1104
1311
  }
1105
1312
  strainValueAt(current) {
1106
- this.currentRhythm = this.calculateRhythmBonus(current);
1313
+ this.currentRhythm = DroidRhythmEvaluator.evaluateDifficultyOf(current, this.hitWindow.hitWindowFor300());
1107
1314
  this.currentStrain *= this.strainDecay(current.deltaTime);
1108
1315
  this.currentStrain += this.currentRhythm - 1;
1109
1316
  return this.currentStrain;
@@ -1115,27 +1322,31 @@ class DroidRhythm extends DroidSkill {
1115
1322
  }
1116
1323
 
1117
1324
  /**
1118
- * Represents the skill required to read every object in the map.
1325
+ * An evaluator for calculating osu!droid Rhythm skill.
1119
1326
  */
1120
- class DroidVisual extends DroidSkill {
1121
- historyLength = 4;
1122
- starsPerDouble = 1.025;
1123
- reducedSectionCount = 10;
1124
- reducedSectionBaseline = 0.75;
1125
- skillMultiplier = 20;
1126
- strainDecayBase = 0.1;
1127
- preempt;
1128
- isHidden;
1129
- constructor(mods, preempt) {
1130
- super(mods);
1131
- this.preempt = preempt;
1132
- this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1133
- }
1327
+ class DroidVisualEvaluator {
1134
1328
  /**
1135
- * @param current The hitobject to calculate.
1329
+ * Evaluates the difficulty of reading the current object, based on:
1330
+ *
1331
+ * - note density of the current object,
1332
+ * - overlapping factor of the current object,
1333
+ * - the preempt time of the current object,
1334
+ * - the velocity of the current object if it's a slider,
1335
+ * - past objects' velocity if they are sliders,
1336
+ * - and whether the Hidden mod is enabled.
1337
+ *
1338
+ * @param current The current object.
1339
+ * @param isHiddenMod Whether the Hidden mod is enabled.
1136
1340
  */
1137
- strainValueOf(current) {
1138
- if (current.object instanceof osuBase.Spinner) {
1341
+ static evaluateDifficultyOf(current, isHiddenMod) {
1342
+ const last = current.previous(0);
1343
+ if (current.object instanceof osuBase.Spinner ||
1344
+ // Exclude overlapping objects that can be tapped at once.
1345
+ (current.deltaTime < 5 &&
1346
+ ((last?.object instanceof osuBase.Slider
1347
+ ? Math.min(last.object.stackedEndPosition.getDistance(current.object.stackedPosition), last.object.lazyEndPosition.getDistance(current.object.stackedPosition))
1348
+ : last?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) ?? Number.POSITIVE_INFINITY) <=
1349
+ 2 * current.object.radius)) {
1139
1350
  return 0;
1140
1351
  }
1141
1352
  // Start with base density and give global bonus for Hidden.
@@ -1143,15 +1354,20 @@ class DroidVisual extends DroidSkill {
1143
1354
  let strain = Math.min(20, Math.pow(current.noteDensity, 2)) /
1144
1355
  10 /
1145
1356
  (1 + current.overlappingFactor);
1146
- if (this.isHidden) {
1357
+ if (isHiddenMod) {
1147
1358
  strain +=
1148
1359
  Math.min(25, Math.pow(current.noteDensity, 1.25)) /
1149
1360
  10 /
1150
1361
  (1 + current.overlappingFactor / 1.25);
1151
1362
  }
1152
- // Give bonus for AR higher than 10.33.
1153
- if (this.preempt < 400) {
1154
- strain += Math.pow(400 - this.preempt, 1.3) / 135;
1363
+ if (current.timePreempt < 400) {
1364
+ // Give bonus for AR higher than 10.33.
1365
+ strain += Math.pow(400 - current.timePreempt, 1.3) / 135;
1366
+ }
1367
+ else if (current.timePreempt < 525) {
1368
+ // Give bonus for AR between 9.5 and 10 to not make higher non-DT value less than NM.
1369
+ strain +=
1370
+ Math.pow(525 - Math.max(current.timePreempt, 450), 1.1) / 500;
1155
1371
  }
1156
1372
  if (current.object instanceof osuBase.Slider) {
1157
1373
  const scalingFactor = 50 / current.object.radius;
@@ -1163,10 +1379,14 @@ class DroidVisual extends DroidSkill {
1163
1379
  Math.min(1, current.travelDistance / scalingFactor / 125);
1164
1380
  let cumulativeStrainTime = 0;
1165
1381
  // Reward for velocity changes based on last few sliders.
1166
- for (let i = 0; i < this.previous.length; ++i) {
1167
- const last = this.previous[i];
1382
+ for (let i = 0; i < Math.min(current.index, 4); ++i) {
1383
+ const last = current.previous(i);
1168
1384
  cumulativeStrainTime += last.strainTime;
1169
- if (!(last.object instanceof osuBase.Slider)) {
1385
+ if (!(last.object instanceof osuBase.Slider) ||
1386
+ // Exclude overlapping objects that can be tapped at once.
1387
+ (last.deltaTime < 5 &&
1388
+ Math.min(last.object.stackedEndPosition.getDistance(current.object.stackedPosition), last.object.lazyEndPosition.getDistance(current.object.stackedPosition)) <=
1389
+ 2 * current.object.radius)) {
1170
1390
  continue;
1171
1391
  }
1172
1392
  strain +=
@@ -1180,10 +1400,27 @@ class DroidVisual extends DroidSkill {
1180
1400
  }
1181
1401
  return strain;
1182
1402
  }
1403
+ }
1404
+
1405
+ /**
1406
+ * Represents the skill required to read every object in the map.
1407
+ */
1408
+ class DroidVisual extends DroidSkill {
1409
+ starsPerDouble = 1.025;
1410
+ reducedSectionCount = 10;
1411
+ reducedSectionBaseline = 0.75;
1412
+ skillMultiplier = 20;
1413
+ strainDecayBase = 0.1;
1414
+ isHidden;
1415
+ constructor(mods) {
1416
+ super(mods);
1417
+ this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1418
+ }
1183
1419
  strainValueAt(current) {
1184
1420
  this.currentStrain *= this.strainDecay(current.deltaTime);
1185
1421
  this.currentStrain +=
1186
- this.strainValueOf(current) * this.skillMultiplier;
1422
+ DroidVisualEvaluator.evaluateDifficultyOf(current, this.isHidden) *
1423
+ this.skillMultiplier;
1187
1424
  return this.currentStrain * (1 + (current.rhythmMultiplier - 1) / 5);
1188
1425
  }
1189
1426
  saveToHitObject(current) {
@@ -1192,9 +1429,9 @@ class DroidVisual extends DroidSkill {
1192
1429
  }
1193
1430
 
1194
1431
  /**
1195
- * Difficulty calculator for osu!droid gamemode.
1432
+ * A difficulty calculator for osu!droid gamemode.
1196
1433
  */
1197
- class DroidStarRating extends StarRating {
1434
+ class DroidDifficultyCalculator extends DifficultyCalculator {
1198
1435
  /**
1199
1436
  * The aim star rating of the beatmap.
1200
1437
  */
@@ -1216,33 +1453,7 @@ class DroidStarRating extends StarRating {
1216
1453
  */
1217
1454
  visual = 0;
1218
1455
  difficultyMultiplier = 0.18;
1219
- /**
1220
- * Calculates the star rating of the specified beatmap.
1221
- *
1222
- * The beatmap is analyzed in chunks of `sectionLength` duration.
1223
- * For each chunk the highest hitobject strains are added to
1224
- * a list which is then collapsed into a weighted sum, much
1225
- * like scores are weighted on a user's profile.
1226
- *
1227
- * For subsequent chunks, the initial max strain is calculated
1228
- * by decaying the previous hitobject's strain until the
1229
- * beginning of the new chunk.
1230
- *
1231
- * The first object doesn't generate a strain
1232
- * so we begin calculating from the second object.
1233
- *
1234
- * Also don't forget to manually add the peak strain for the last
1235
- * section which would otherwise be ignored.
1236
- */
1237
- calculate(params) {
1238
- return super.calculate(params, osuBase.modes.droid);
1239
- }
1240
- /**
1241
- * Generates difficulty hitobjects for this calculator.
1242
- */
1243
- generateDifficultyHitObjects() {
1244
- super.generateDifficultyHitObjects(osuBase.modes.droid);
1245
- }
1456
+ mode = osuBase.modes.droid;
1246
1457
  /**
1247
1458
  * Calculates the aim star rating of the beatmap and stores it in this instance.
1248
1459
  */
@@ -1253,17 +1464,23 @@ class DroidStarRating extends StarRating {
1253
1464
  this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
1254
1465
  }
1255
1466
  /**
1256
- * Calculates the speed star rating of the beatmap and stores it in this instance.
1467
+ * Calculates the tap star rating of the beatmap and stores it in this instance.
1257
1468
  */
1258
1469
  calculateTap() {
1259
1470
  const tapSkill = new DroidTap(this.mods, this.stats.od);
1260
1471
  this.calculateSkills(tapSkill);
1261
- this.postCalculateTap(tapSkill);
1472
+ if (!this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1473
+ this.postCalculateTap(tapSkill);
1474
+ }
1475
+ this.calculateSpeedAttributes();
1262
1476
  }
1263
1477
  /**
1264
1478
  * Calculates the rhythm star rating of the beatmap and stores it in this instance.
1265
1479
  */
1266
1480
  calculateRhythm() {
1481
+ if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1482
+ return;
1483
+ }
1267
1484
  const rhythmSkill = new DroidRhythm(this.mods, this.stats.od);
1268
1485
  this.calculateSkills(rhythmSkill);
1269
1486
  this.postCalculateRhythm(rhythmSkill);
@@ -1280,7 +1497,7 @@ class DroidStarRating extends StarRating {
1280
1497
  * Calculates the visual star rating of the beatmap and stores it in this instance.
1281
1498
  */
1282
1499
  calculateVisual() {
1283
- const visualSkill = new DroidVisual(this.mods, osuBase.MapStats.arToMS(this.stats.ar));
1500
+ const visualSkill = new DroidVisual(this.mods);
1284
1501
  this.calculateSkills(visualSkill);
1285
1502
  this.postCalculateVisual(visualSkill);
1286
1503
  }
@@ -1317,9 +1534,7 @@ class DroidStarRating extends StarRating {
1317
1534
  if (!isRelax) {
1318
1535
  this.postCalculateTap(tapSkill);
1319
1536
  }
1320
- else {
1321
- this.calculateSpeedAttributes();
1322
- }
1537
+ this.calculateSpeedAttributes();
1323
1538
  if (!isRelax) {
1324
1539
  this.postCalculateRhythm(rhythmSkill);
1325
1540
  }
@@ -1355,7 +1570,7 @@ class DroidStarRating extends StarRating {
1355
1570
  new DroidRhythm(this.mods, this.stats.od),
1356
1571
  new DroidTap(this.mods, this.stats.od),
1357
1572
  new DroidFlashlight(this.mods),
1358
- new DroidVisual(this.mods, osuBase.MapStats.arToMS(this.stats.ar)),
1573
+ new DroidVisual(this.mods),
1359
1574
  ];
1360
1575
  }
1361
1576
  /**
@@ -1382,7 +1597,6 @@ class DroidStarRating extends StarRating {
1382
1597
  postCalculateTap(tapSkill) {
1383
1598
  this.strainPeaks.speed = tapSkill.strainPeaks;
1384
1599
  this.tap = this.starValue(tapSkill.difficultyValue());
1385
- this.calculateSpeedAttributes();
1386
1600
  }
1387
1601
  /**
1388
1602
  * Calculates speed-related attributes.
@@ -1433,6 +1647,10 @@ class PerformanceCalculator {
1433
1647
  * The calculated accuracy.
1434
1648
  */
1435
1649
  computedAccuracy = new osuBase.Accuracy({});
1650
+ /**
1651
+ * The difficulty calculator that is being calculated.
1652
+ */
1653
+ difficultyCalculator;
1436
1654
  /**
1437
1655
  * The map statistics after applying modifications.
1438
1656
  */
@@ -1450,12 +1668,21 @@ class PerformanceCalculator {
1450
1668
  */
1451
1669
  sliderNerfFactor = 1;
1452
1670
  /**
1453
- * Internal calculation method, used to process calculation from implementations.
1671
+ * @param difficultyCalculator The difficulty calculator to calculate.
1672
+ */
1673
+ constructor(difficultyCalculator) {
1674
+ this.difficultyCalculator = difficultyCalculator;
1675
+ }
1676
+ /**
1677
+ * Calculates the performance points of the beatmap.
1678
+ *
1679
+ * @param options Options for performance calculation.
1680
+ * @returns The current instance.
1454
1681
  */
1455
- calculateInternal(params, mode) {
1456
- this.handleParams(params, mode);
1682
+ calculate(options) {
1683
+ this.handleOptions(options);
1457
1684
  this.calculateValues();
1458
- this.total = this.calculateTotalValue();
1685
+ this.calculateTotalValue();
1459
1686
  return this;
1460
1687
  }
1461
1688
  /**
@@ -1465,45 +1692,44 @@ class PerformanceCalculator {
1465
1692
  return Math.pow(5 * Math.max(1, stars / 0.0675) - 4, 3) / 100000;
1466
1693
  }
1467
1694
  /**
1468
- * Processes given parameters for usage in performance calculation.
1695
+ * Processes given options for usage in performance calculation.
1469
1696
  */
1470
- handleParams(params, mode) {
1471
- this.stars = params.stars;
1472
- const maxCombo = this.stars.map.maxCombo;
1697
+ handleOptions(options) {
1698
+ const maxCombo = this.difficultyCalculator.beatmap.maxCombo;
1473
1699
  const miss = this.computedAccuracy.nmiss;
1474
- const combo = params.combo ?? maxCombo - miss;
1475
- const mod = this.stars.mods;
1476
- const baseAR = this.stars.map.difficulty.ar;
1477
- const baseOD = this.stars.map.difficulty.od;
1700
+ const combo = options?.combo ?? maxCombo - miss;
1701
+ const mod = this.difficultyCalculator.mods;
1702
+ const baseAR = this.difficultyCalculator.beatmap.difficulty.ar;
1703
+ const baseOD = this.difficultyCalculator.beatmap.difficulty.od;
1478
1704
  // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
1479
1705
  this.comboPenalty = Math.min(Math.pow(combo / maxCombo, 0.8), 1);
1480
- if (params.accPercent instanceof osuBase.Accuracy) {
1706
+ if (options?.accPercent instanceof osuBase.Accuracy) {
1481
1707
  // Copy into new instance to not modify the original
1482
- this.computedAccuracy = new osuBase.Accuracy(params.accPercent);
1708
+ this.computedAccuracy = new osuBase.Accuracy(options?.accPercent);
1483
1709
  }
1484
1710
  else {
1485
1711
  this.computedAccuracy = new osuBase.Accuracy({
1486
- percent: params.accPercent,
1487
- nobjects: this.stars.objects.length,
1488
- nmiss: params.miss || 0,
1712
+ percent: options?.accPercent,
1713
+ nobjects: this.difficultyCalculator.objects.length,
1714
+ nmiss: options?.miss || 0,
1489
1715
  });
1490
1716
  }
1491
1717
  this.effectiveMissCount = this.calculateEffectiveMissCount(combo, maxCombo);
1492
- if (this.stars.mods.some((m) => m instanceof osuBase.ModNoFail)) {
1718
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModNoFail)) {
1493
1719
  this.finalMultiplier *= Math.max(0.9, 1 - 0.02 * this.effectiveMissCount);
1494
1720
  }
1495
- if (this.stars.mods.some((m) => m instanceof osuBase.ModSpunOut)) {
1721
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModSpunOut)) {
1496
1722
  this.finalMultiplier *=
1497
1723
  1 -
1498
- Math.pow(this.stars.map.hitObjects.spinners /
1499
- this.stars.objects.length, 0.85);
1724
+ Math.pow(this.difficultyCalculator.beatmap.hitObjects.spinners /
1725
+ this.difficultyCalculator.objects.length, 0.85);
1500
1726
  }
1501
- if (this.stars.mods.some((m) => m instanceof osuBase.ModRelax)) {
1727
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModRelax)) {
1502
1728
  // As we're adding 100s and 50s to an approximated number of combo breaks, the result can be higher
1503
1729
  // than total hits in specific scenarios (which breaks some calculations), so we need to clamp it.
1504
1730
  this.effectiveMissCount = Math.min(this.effectiveMissCount +
1505
1731
  this.computedAccuracy.n100 +
1506
- this.computedAccuracy.n50, this.stars.objects.length);
1732
+ this.computedAccuracy.n50, this.difficultyCalculator.objects.length);
1507
1733
  this.finalMultiplier *= 0.6;
1508
1734
  }
1509
1735
  this.mapStatistics = new osuBase.MapStats({
@@ -1511,42 +1737,44 @@ class PerformanceCalculator {
1511
1737
  od: baseOD,
1512
1738
  mods: mod,
1513
1739
  });
1514
- if (this.stars.map.hitObjects.sliders > 0) {
1740
+ if (this.difficultyCalculator.beatmap.hitObjects.sliders > 0) {
1515
1741
  // We assume 15% of sliders in a beatmap are difficult since there's no way to tell from the performance calculator.
1516
- const estimateDifficultSliders = this.stars.map.hitObjects.sliders * 0.15;
1742
+ const estimateDifficultSliders = this.difficultyCalculator.beatmap.hitObjects.sliders * 0.15;
1517
1743
  const estimateSliderEndsDropped = osuBase.MathUtils.clamp(Math.min(this.computedAccuracy.n300 +
1518
1744
  this.computedAccuracy.n50 +
1519
1745
  this.computedAccuracy.nmiss, maxCombo - combo), 0, estimateDifficultSliders);
1520
1746
  this.sliderNerfFactor =
1521
- (1 - this.stars.attributes.sliderFactor) *
1747
+ (1 - this.difficultyCalculator.attributes.sliderFactor) *
1522
1748
  Math.pow(1 -
1523
1749
  estimateSliderEndsDropped /
1524
1750
  estimateDifficultSliders, 3) +
1525
- this.stars.attributes.sliderFactor;
1751
+ this.difficultyCalculator.attributes.sliderFactor;
1526
1752
  }
1527
- if (params.stats) {
1528
- this.mapStatistics.ar = params.stats.ar ?? this.mapStatistics.ar;
1753
+ if (options?.stats) {
1754
+ this.mapStatistics.ar = options?.stats.ar ?? this.mapStatistics.ar;
1529
1755
  this.mapStatistics.isForceAR =
1530
- params.stats.isForceAR ?? this.mapStatistics.isForceAR;
1756
+ options?.stats.isForceAR ?? this.mapStatistics.isForceAR;
1531
1757
  this.mapStatistics.speedMultiplier =
1532
- params.stats.speedMultiplier ??
1758
+ options?.stats.speedMultiplier ??
1533
1759
  this.mapStatistics.speedMultiplier;
1534
1760
  this.mapStatistics.oldStatistics =
1535
- params.stats.oldStatistics ?? this.mapStatistics.oldStatistics;
1761
+ options?.stats.oldStatistics ??
1762
+ this.mapStatistics.oldStatistics;
1536
1763
  }
1537
- this.mapStatistics.calculate({ mode: mode });
1764
+ this.mapStatistics.calculate({ mode: this.mode });
1538
1765
  }
1539
1766
  /**
1540
1767
  * Calculates the amount of misses + sliderbreaks from combo.
1541
1768
  */
1542
1769
  calculateEffectiveMissCount(combo, maxCombo) {
1543
1770
  let comboBasedMissCount = 0;
1544
- if (this.stars.map.hitObjects.sliders > 0) {
1545
- const fullComboThreshold = maxCombo - 0.1 * this.stars.map.hitObjects.sliders;
1771
+ if (this.difficultyCalculator.beatmap.hitObjects.sliders > 0) {
1772
+ const fullComboThreshold = maxCombo -
1773
+ 0.1 * this.difficultyCalculator.beatmap.hitObjects.sliders;
1546
1774
  if (combo < fullComboThreshold) {
1547
1775
  // We're clamping miss count because since it's derived from combo, it can
1548
1776
  // be higher than the amount of objects and that breaks some calculations.
1549
- comboBasedMissCount = Math.min(fullComboThreshold / Math.max(1, combo), this.stars.objects.length);
1777
+ comboBasedMissCount = Math.min(fullComboThreshold / Math.max(1, combo), this.difficultyCalculator.objects.length);
1550
1778
  }
1551
1779
  }
1552
1780
  return Math.max(this.computedAccuracy.nmiss, comboBasedMissCount);
@@ -1557,8 +1785,6 @@ class PerformanceCalculator {
1557
1785
  * A performance points calculator that calculates performance points for osu!droid gamemode.
1558
1786
  */
1559
1787
  class DroidPerformanceCalculator extends PerformanceCalculator {
1560
- stars = new DroidStarRating();
1561
- finalMultiplier = 1.24;
1562
1788
  /**
1563
1789
  * The aim performance value.
1564
1790
  */
@@ -1579,36 +1805,38 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1579
1805
  * The visual performance value.
1580
1806
  */
1581
1807
  visual = 0;
1808
+ finalMultiplier = 1.24;
1809
+ mode = osuBase.modes.droid;
1582
1810
  tapPenalty = 1;
1583
- calculate(params) {
1584
- this.tapPenalty = params.tapPenalty ?? 1;
1585
- return this.calculateInternal(params, osuBase.modes.droid);
1586
- }
1587
1811
  calculateValues() {
1588
1812
  this.calculateAimValue();
1589
1813
  this.calculateTapValue();
1590
1814
  this.calculateAccuracyValue();
1591
1815
  this.calculateFlashlightValue();
1592
1816
  this.calculateVisualValue();
1593
- // Apply tap penalty for penalized plays.
1594
- this.tap /= this.tapPenalty;
1595
1817
  }
1596
1818
  calculateTotalValue() {
1597
- return (Math.pow(Math.pow(this.aim, 1.1) +
1598
- Math.pow(this.tap, 1.1) +
1599
- Math.pow(this.accuracy, 1.1) +
1600
- Math.pow(this.flashlight, 1.1) +
1601
- Math.pow(this.visual, 1.1), 1 / 1.1) * this.finalMultiplier);
1819
+ this.total =
1820
+ Math.pow(Math.pow(this.aim, 1.1) +
1821
+ Math.pow(this.tap, 1.1) +
1822
+ Math.pow(this.accuracy, 1.1) +
1823
+ Math.pow(this.flashlight, 1.1) +
1824
+ Math.pow(this.visual, 1.1), 1 / 1.1) * this.finalMultiplier;
1825
+ }
1826
+ handleOptions(options) {
1827
+ this.tapPenalty = options?.tapPenalty ?? 1;
1828
+ super.handleOptions(options);
1602
1829
  }
1603
1830
  /**
1604
1831
  * Calculates the aim performance value of the beatmap.
1605
1832
  */
1606
1833
  calculateAimValue() {
1607
1834
  // Global variables
1608
- const objectCount = this.stars.objects.length;
1609
- this.aim = this.baseValue(Math.pow(this.stars.aim, 0.8));
1835
+ const objectCount = this.difficultyCalculator.objects.length;
1836
+ this.aim = this.baseValue(Math.pow(this.difficultyCalculator.aim, 0.8));
1610
1837
  if (this.effectiveMissCount > 0) {
1611
- // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
1838
+ // Penalize misses by assessing # of misses relative to the total # of objects.
1839
+ // Default a 3% reduction for any # of misses.
1612
1840
  this.aim *=
1613
1841
  0.97 *
1614
1842
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), this.effectiveMissCount);
@@ -1629,10 +1857,11 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1629
1857
  */
1630
1858
  calculateTapValue() {
1631
1859
  // Global variables
1632
- const objectCount = this.stars.objects.length;
1633
- this.tap = this.baseValue(this.stars.tap);
1860
+ const objectCount = this.difficultyCalculator.objects.length;
1861
+ this.tap = this.baseValue(this.difficultyCalculator.tap);
1634
1862
  if (this.effectiveMissCount > 0) {
1635
- // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
1863
+ // Penalize misses by assessing # of misses relative to the total # of objects.
1864
+ // Default a 3% reduction for any # of misses.
1636
1865
  this.tap *=
1637
1866
  0.97 *
1638
1867
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), Math.pow(this.effectiveMissCount, 0.875));
@@ -1643,36 +1872,39 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1643
1872
  const countGreat = this.computedAccuracy.n300;
1644
1873
  const countOk = this.computedAccuracy.n100;
1645
1874
  const countMeh = this.computedAccuracy.n50;
1646
- const relevantTotalDiff = objectCount - this.stars.attributes.speedNoteCount;
1875
+ const relevantTotalDiff = objectCount - this.difficultyCalculator.attributes.speedNoteCount;
1647
1876
  const relevantAccuracy = new osuBase.Accuracy({
1648
1877
  n300: Math.max(0, countGreat - relevantTotalDiff),
1649
1878
  n100: Math.max(0, countOk - Math.max(0, relevantTotalDiff - countGreat)),
1650
1879
  n50: Math.max(0, countMeh - Math.max(0, relevantTotalDiff - countGreat - countOk)),
1651
1880
  nmiss: this.effectiveMissCount,
1652
1881
  });
1653
- // Scale the speed value with accuracy and OD.
1882
+ // Scale the tap value with accuracy and OD.
1654
1883
  const od = this.mapStatistics.od;
1655
1884
  const odScaling = Math.pow(od, 2) / 750;
1656
1885
  this.tap *=
1657
1886
  (0.95 + (od > 0 ? odScaling : -odScaling)) *
1658
1887
  Math.pow((this.computedAccuracy.value(objectCount) +
1659
- relevantAccuracy.value(this.stars.attributes.speedNoteCount)) /
1888
+ relevantAccuracy.value(this.difficultyCalculator.attributes.speedNoteCount)) /
1660
1889
  2, (14 - Math.max(od, 2.5)) / 2);
1661
- // Scale the speed value with # of 50s to punish doubletapping.
1890
+ // Scale the tap value with # of 50s to punish doubletapping.
1662
1891
  this.tap *= Math.pow(0.98, Math.max(0, this.computedAccuracy.n50 - objectCount / 500));
1892
+ // Scale the tap value with three-fingered penalty.
1893
+ this.tap /= this.tapPenalty;
1663
1894
  }
1664
1895
  /**
1665
1896
  * Calculates the accuracy performance value of the beatmap.
1666
1897
  */
1667
1898
  calculateAccuracyValue() {
1668
- if (this.stars.mods.some((m) => m instanceof osuBase.ModRelax)) {
1899
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModRelax)) {
1669
1900
  return;
1670
1901
  }
1671
1902
  // Global variables
1672
- const objectCount = this.stars.objects.length;
1673
- const ncircles = this.stars.mods.some((m) => m instanceof osuBase.ModScoreV2)
1674
- ? objectCount - this.stars.map.hitObjects.spinners
1675
- : this.stars.map.hitObjects.circles;
1903
+ const objectCount = this.difficultyCalculator.objects.length;
1904
+ const ncircles = this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModScoreV2)
1905
+ ? objectCount -
1906
+ this.difficultyCalculator.beatmap.hitObjects.spinners
1907
+ : this.difficultyCalculator.beatmap.hitObjects.circles;
1676
1908
  if (ncircles === 0) {
1677
1909
  return;
1678
1910
  }
@@ -1689,11 +1921,12 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1689
1921
  // Bonus for many hitcircles - it's harder to keep good accuracy up for longer
1690
1922
  this.accuracy *= Math.min(1.15, Math.pow(ncircles / 1000, 0.3));
1691
1923
  // Scale the accuracy value with rhythm complexity.
1692
- this.accuracy *= 1.5 / (1 + Math.exp(-(this.stars.rhythm - 1) / 2));
1693
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
1924
+ this.accuracy *=
1925
+ 1.5 / (1 + Math.exp(-(this.difficultyCalculator.rhythm - 1) / 2));
1926
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModHidden)) {
1694
1927
  this.accuracy *= 1.08;
1695
1928
  }
1696
- if (this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1929
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1697
1930
  this.accuracy *= 1.02;
1698
1931
  }
1699
1932
  }
@@ -1701,17 +1934,14 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1701
1934
  * Calculates the flashlight performance value of the beatmap.
1702
1935
  */
1703
1936
  calculateFlashlightValue() {
1704
- if (!this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1937
+ if (!this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1705
1938
  return;
1706
1939
  }
1707
1940
  // Global variables
1708
- const objectCount = this.stars.objects.length;
1941
+ const objectCount = this.difficultyCalculator.objects.length;
1709
1942
  this.flashlight =
1710
- Math.pow(Math.pow(this.stars.flashlight, 0.8), 2) * 25;
1711
- // Add an additional bonus for HDFL.
1712
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
1713
- this.flashlight *= 1.3;
1714
- }
1943
+ Math.pow(Math.pow(this.difficultyCalculator.flashlight, 0.8), 2) *
1944
+ 25;
1715
1945
  // Combo scaling
1716
1946
  this.flashlight *= this.comboPenalty;
1717
1947
  if (this.effectiveMissCount > 0) {
@@ -1739,8 +1969,9 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1739
1969
  */
1740
1970
  calculateVisualValue() {
1741
1971
  // Global variables
1742
- const objectCount = this.stars.objects.length;
1743
- this.visual = Math.pow(Math.pow(this.stars.visual, 0.8), 2) * 25;
1972
+ const objectCount = this.difficultyCalculator.objects.length;
1973
+ this.visual =
1974
+ Math.pow(Math.pow(this.difficultyCalculator.visual, 0.8), 2) * 25;
1744
1975
  if (this.effectiveMissCount > 0) {
1745
1976
  // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
1746
1977
  this.visual *=
@@ -1784,9 +2015,7 @@ class OsuSkill extends StrainSkill {
1784
2015
  difficultyValue() {
1785
2016
  const sortedStrains = this.strainPeaks
1786
2017
  .slice()
1787
- .sort((a, b) => {
1788
- return b - a;
1789
- });
2018
+ .sort((a, b) => b - a);
1790
2019
  // We are reducing the highest strains first to account for extreme difficulty spikes.
1791
2020
  for (let i = 0; i < Math.min(sortedStrains.length, this.reducedSectionCount); ++i) {
1792
2021
  const scale = Math.log10(osuBase.Interpolation.lerp(1, 10, osuBase.MathUtils.clamp(i / this.reducedSectionCount, 0, 1)));
@@ -1794,9 +2023,7 @@ class OsuSkill extends StrainSkill {
1794
2023
  }
1795
2024
  // Difficulty is the weighted sum of the highest strains from every section.
1796
2025
  // We're sorting from highest to lowest strain.
1797
- sortedStrains.sort((a, b) => {
1798
- return b - a;
1799
- });
2026
+ sortedStrains.sort((a, b) => b - a);
1800
2027
  let difficulty = 0;
1801
2028
  let weight = 1;
1802
2029
  for (const strain of sortedStrains) {
@@ -1812,39 +2039,32 @@ class OsuSkill extends StrainSkill {
1812
2039
  }
1813
2040
 
1814
2041
  /**
1815
- * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
2042
+ * An evaluator for calculating osu!standard Aim skill.
1816
2043
  */
1817
- class OsuAim extends OsuSkill {
1818
- skillMultiplier = 23.25;
1819
- strainDecayBase = 0.15;
1820
- reducedSectionCount = 10;
1821
- reducedSectionBaseline = 0.75;
1822
- difficultyMultiplier = 1.06;
1823
- decayWeight = 0.9;
1824
- wideAngleMultiplier = 1.5;
1825
- acuteAngleMultiplier = 2;
1826
- sliderMultiplier = 1.5;
1827
- velocityChangeMultiplier = 0.75;
1828
- withSliders;
1829
- constructor(mods, withSliders) {
1830
- super(mods);
1831
- this.withSliders = withSliders;
1832
- }
2044
+ class OsuAimEvaluator extends AimEvaluator {
1833
2045
  /**
1834
- * @param current The hitobject to calculate.
2046
+ * Evaluates the difficulty of aiming the current object, based on:
2047
+ *
2048
+ * - cursor velocity to the current object,
2049
+ * - angle difficulty,
2050
+ * - sharp velocity increases,
2051
+ * - and slider difficulty.
2052
+ *
2053
+ * @param current The current object.
2054
+ * @param withSliders Whether to take slider difficulty into account.
1835
2055
  */
1836
- strainValueOf(current) {
2056
+ static evaluateDifficultyOf(current, withSliders) {
2057
+ const last = current.previous(0);
1837
2058
  if (current.object instanceof osuBase.Spinner ||
1838
- this.previous.length <= 1 ||
1839
- this.previous[0].object instanceof osuBase.Spinner) {
2059
+ current.index <= 1 ||
2060
+ last?.object instanceof osuBase.Spinner) {
1840
2061
  return 0;
1841
2062
  }
1842
- const last = this.previous[0];
1843
- const lastLast = this.previous[1];
2063
+ const lastLast = current.previous(1);
1844
2064
  // Calculate the velocity to the current hitobject, which starts with a base distance / time assuming the last object is a hitcircle.
1845
2065
  let currentVelocity = current.lazyJumpDistance / current.strainTime;
1846
2066
  // But if the last object is a slider, then we extend the travel velocity through the slider into the current object.
1847
- if (last.object instanceof osuBase.Slider && this.withSliders) {
2067
+ if (last.object instanceof osuBase.Slider && withSliders) {
1848
2068
  // Calculate the slider velocity from slider head to slider end.
1849
2069
  const travelVelocity = last.travelDistance / last.travelTime;
1850
2070
  // Calculate the movement velocity from slider end to current object.
@@ -1854,7 +2074,7 @@ class OsuAim extends OsuSkill {
1854
2074
  }
1855
2075
  // As above, do the same for the previous hitobject.
1856
2076
  let prevVelocity = last.lazyJumpDistance / last.strainTime;
1857
- if (lastLast.object instanceof osuBase.Slider && this.withSliders) {
2077
+ if (lastLast.object instanceof osuBase.Slider && withSliders) {
1858
2078
  const travelVelocity = lastLast.travelDistance / lastLast.travelTime;
1859
2079
  const movementVelocity = last.minimumJumpDistance / last.minimumJumpTime;
1860
2080
  prevVelocity = Math.max(prevVelocity, movementVelocity + travelVelocity);
@@ -1941,18 +2161,36 @@ class OsuAim extends OsuSkill {
1941
2161
  strain += Math.max(acuteAngleBonus * this.acuteAngleMultiplier, wideAngleBonus * this.wideAngleMultiplier +
1942
2162
  velocityChangeBonus * this.velocityChangeMultiplier);
1943
2163
  // Add in additional slider velocity bonus.
1944
- if (this.withSliders) {
2164
+ if (withSliders) {
1945
2165
  strain += sliderBonus * this.sliderMultiplier;
1946
2166
  }
1947
2167
  return strain;
1948
2168
  }
2169
+ }
2170
+
2171
+ /**
2172
+ * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
2173
+ */
2174
+ class OsuAim extends OsuSkill {
2175
+ skillMultiplier = 23.25;
2176
+ strainDecayBase = 0.15;
2177
+ reducedSectionCount = 10;
2178
+ reducedSectionBaseline = 0.75;
2179
+ difficultyMultiplier = 1.06;
2180
+ decayWeight = 0.9;
2181
+ withSliders;
2182
+ constructor(mods, withSliders) {
2183
+ super(mods);
2184
+ this.withSliders = withSliders;
2185
+ }
1949
2186
  /**
1950
2187
  * @param current The hitobject to calculate.
1951
2188
  */
1952
2189
  strainValueAt(current) {
1953
2190
  this.currentStrain *= this.strainDecay(current.deltaTime);
1954
2191
  this.currentStrain +=
1955
- this.strainValueOf(current) * this.skillMultiplier;
2192
+ OsuAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
2193
+ this.skillMultiplier;
1956
2194
  return this.currentStrain;
1957
2195
  }
1958
2196
  /**
@@ -1966,63 +2204,43 @@ class OsuAim extends OsuSkill {
1966
2204
  current.aimStrainWithoutSliders = this.currentStrain;
1967
2205
  }
1968
2206
  }
1969
- /**
1970
- * Calculates the bonus of wide angles.
1971
- */
1972
- calculateWideAngleBonus(angle) {
1973
- return Math.pow(Math.sin((3 / 4) *
1974
- (Math.min((5 / 6) * Math.PI, Math.max(Math.PI / 6, angle)) -
1975
- Math.PI / 6)), 2);
1976
- }
1977
- /**
1978
- * Calculates the bonus of acute angles.
1979
- */
1980
- calculateAcuteAngleBonus(angle) {
1981
- return 1 - this.calculateWideAngleBonus(angle);
1982
- }
1983
2207
  }
1984
2208
 
1985
2209
  /**
1986
- * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
2210
+ * An evaluator for calculating osu!standard speed skill.
1987
2211
  */
1988
- class OsuSpeed extends OsuSkill {
2212
+ class OsuSpeedEvaluator extends SpeedEvaluator {
1989
2213
  /**
1990
2214
  * Spacing threshold for a single hitobject spacing.
1991
2215
  */
1992
- SINGLE_SPACING_THRESHOLD = 125;
1993
- historyLength = 32;
1994
- skillMultiplier = 1375;
1995
- strainDecayBase = 0.3;
1996
- reducedSectionCount = 5;
1997
- reducedSectionBaseline = 0.75;
1998
- difficultyMultiplier = 1.04;
1999
- decayWeight = 0.9;
2000
- rhythmMultiplier = 0.75;
2001
- historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
2002
- currentSpeedStrain = 0;
2003
- currentRhythm = 0;
2004
- // ~200 1/4 BPM streams
2005
- minSpeedBonus = 75;
2006
- greatWindow;
2007
- constructor(mods, greatWindow) {
2008
- super(mods);
2009
- this.greatWindow = greatWindow;
2010
- }
2216
+ static SINGLE_SPACING_THRESHOLD = 125;
2011
2217
  /**
2012
- * @param current The hitobject to calculate.
2218
+ * Evaluates the difficulty of tapping the current object, based on:
2219
+ *
2220
+ * - time between pressing the previous and current object,
2221
+ * - distance between those objects,
2222
+ * - and how easily they can be cheesed.
2223
+ *
2224
+ * @param current The current object.
2225
+ * @param greatWindow The great hit window of the current object.
2013
2226
  */
2014
- strainValueOf(current) {
2227
+ static evaluateDifficultyOf(current, greatWindow) {
2015
2228
  if (current.object instanceof osuBase.Spinner) {
2016
2229
  return 0;
2017
2230
  }
2231
+ const prev = current.previous(0);
2018
2232
  let strainTime = current.strainTime;
2019
- const greatWindowFull = this.greatWindow * 2;
2020
- const speedWindowRatio = strainTime / greatWindowFull;
2021
- // Aim to nerf cheesy rhythms (very fast consecutive doubles with large deltatimes between).
2022
- if (this.previous[0] &&
2023
- strainTime < greatWindowFull &&
2024
- this.previous[0].strainTime > strainTime) {
2025
- strainTime = osuBase.Interpolation.lerp(this.previous[0].strainTime, strainTime, speedWindowRatio);
2233
+ const greatWindowFull = greatWindow * 2;
2234
+ // Nerf doubletappable doubles.
2235
+ const next = current.next(0);
2236
+ let doubletapness = 1;
2237
+ if (next) {
2238
+ const currentDeltaTime = Math.max(1, current.deltaTime);
2239
+ const nextDeltaTime = Math.max(1, next.deltaTime);
2240
+ const deltaDifference = Math.abs(nextDeltaTime - currentDeltaTime);
2241
+ const speedRatio = currentDeltaTime / Math.max(currentDeltaTime, deltaDifference);
2242
+ const windowRatio = Math.pow(Math.min(1, currentDeltaTime / greatWindowFull), 2);
2243
+ doubletapness = Math.pow(speedRatio, 1 - windowRatio);
2026
2244
  }
2027
2245
  // Cap deltatime to the OD 300 hitwindow.
2028
2246
  // 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.
@@ -2032,27 +2250,29 @@ class OsuSpeed extends OsuSkill {
2032
2250
  speedBonus +=
2033
2251
  0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
2034
2252
  }
2035
- const travelDistance = this.previous[0]?.travelDistance ?? 0;
2253
+ const travelDistance = prev?.travelDistance ?? 0;
2036
2254
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
2037
- return ((speedBonus +
2255
+ return (((speedBonus +
2038
2256
  speedBonus *
2039
- Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.5)) /
2257
+ Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.5)) *
2258
+ doubletapness) /
2040
2259
  strainTime);
2041
2260
  }
2261
+ }
2262
+
2263
+ /**
2264
+ * An evaluator for calculating osu!standard Rhythm skill.
2265
+ */
2266
+ class OsuRhythmEvaluator extends RhythmEvaluator {
2267
+ static rhythmMultiplier = 0.75;
2042
2268
  /**
2043
- * @param current The hitobject to calculate.
2044
- */
2045
- strainValueAt(current) {
2046
- this.currentSpeedStrain *= this.strainDecay(current.deltaTime);
2047
- this.currentSpeedStrain +=
2048
- this.strainValueOf(current) * this.skillMultiplier;
2049
- this.currentRhythm = this.calculateRhythmBonus(current);
2050
- return this.currentSpeedStrain * this.currentRhythm;
2051
- }
2052
- /**
2053
- * Calculates a rhythm multiplier for the difficulty of the tap associated with historic data of the current object.
2269
+ * Calculates a rhythm multiplier for the difficulty of the tap associated
2270
+ * with historic data of the current object.
2271
+ *
2272
+ * @param current The current object.
2273
+ * @param greatWindow The great hit window of the current object.
2054
2274
  */
2055
- calculateRhythmBonus(current) {
2275
+ static evaluateDifficultyOf(current, greatWindow) {
2056
2276
  if (current.object instanceof osuBase.Spinner) {
2057
2277
  return 0;
2058
2278
  }
@@ -2062,29 +2282,33 @@ class OsuSpeed extends OsuSkill {
2062
2282
  // Store the ratio of the current start of an island to buff for tighter rhythms.
2063
2283
  let startRatio = 0;
2064
2284
  let firstDeltaSwitch = false;
2285
+ const historicalNoteCount = Math.min(current.index, 32);
2065
2286
  let rhythmStart = 0;
2066
- while (rhythmStart < this.previous.length - 2 &&
2067
- current.startTime - this.previous[rhythmStart].startTime <
2287
+ while (rhythmStart < historicalNoteCount - 2 &&
2288
+ current.startTime - current.previous(rhythmStart).startTime <
2068
2289
  this.historyTimeMax) {
2069
2290
  ++rhythmStart;
2070
2291
  }
2071
2292
  for (let i = rhythmStart; i > 0; --i) {
2293
+ const currentObject = current.previous(i - 1);
2294
+ const prevObject = current.previous(i);
2295
+ const lastObject = current.previous(i + 1);
2072
2296
  // Scale note 0 to 1 from history to now.
2073
2297
  let currentHistoricalDecay = (this.historyTimeMax -
2074
- (current.startTime - this.previous[i - 1].startTime)) /
2298
+ (current.startTime - currentObject.startTime)) /
2075
2299
  this.historyTimeMax;
2076
2300
  // Either we're limited by time or limited by object count.
2077
- currentHistoricalDecay = Math.min(currentHistoricalDecay, (this.previous.length - i) / this.previous.length);
2078
- const currentDelta = this.previous[i - 1].strainTime;
2079
- const prevDelta = this.previous[i].strainTime;
2080
- const lastDelta = this.previous[i + 1].strainTime;
2301
+ currentHistoricalDecay = Math.min(currentHistoricalDecay, (historicalNoteCount - i) / historicalNoteCount);
2302
+ const currentDelta = currentObject.strainTime;
2303
+ const prevDelta = prevObject.strainTime;
2304
+ const lastDelta = lastObject.strainTime;
2081
2305
  const currentRatio = 1 +
2082
2306
  6 *
2083
2307
  Math.min(0.5, Math.pow(Math.sin(Math.PI /
2084
2308
  (Math.min(prevDelta, currentDelta) /
2085
2309
  Math.max(prevDelta, currentDelta))), 2));
2086
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - this.greatWindow * 0.6) /
2087
- (this.greatWindow * 0.6));
2310
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - greatWindow * 0.6) /
2311
+ (greatWindow * 0.6));
2088
2312
  let effectiveRatio = windowPenalty * currentRatio;
2089
2313
  if (firstDeltaSwitch) {
2090
2314
  if (prevDelta <= 1.25 * currentDelta &&
@@ -2095,11 +2319,11 @@ class OsuSpeed extends OsuSkill {
2095
2319
  }
2096
2320
  }
2097
2321
  else {
2098
- if (this.previous[i - 1].object instanceof osuBase.Slider) {
2322
+ if (currentObject.object instanceof osuBase.Slider) {
2099
2323
  // BPM change is into slider, this is easy acc window.
2100
2324
  effectiveRatio /= 8;
2101
2325
  }
2102
- if (this.previous[i].object instanceof osuBase.Slider) {
2326
+ if (prevObject.object instanceof osuBase.Slider) {
2103
2327
  // BPM change was from a slider, this is typically easier than circle -> circle.
2104
2328
  effectiveRatio /= 4;
2105
2329
  }
@@ -2144,6 +2368,38 @@ class OsuSpeed extends OsuSkill {
2144
2368
  }
2145
2369
  return Math.sqrt(4 + rhythmComplexitySum * this.rhythmMultiplier) / 2;
2146
2370
  }
2371
+ }
2372
+
2373
+ /**
2374
+ * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
2375
+ */
2376
+ class OsuSpeed extends OsuSkill {
2377
+ skillMultiplier = 1375;
2378
+ strainDecayBase = 0.3;
2379
+ reducedSectionCount = 5;
2380
+ reducedSectionBaseline = 0.75;
2381
+ difficultyMultiplier = 1.04;
2382
+ decayWeight = 0.9;
2383
+ currentSpeedStrain = 0;
2384
+ currentRhythm = 0;
2385
+ // ~200 1/4 BPM streams
2386
+ minSpeedBonus = 75;
2387
+ greatWindow;
2388
+ constructor(mods, greatWindow) {
2389
+ super(mods);
2390
+ this.greatWindow = greatWindow;
2391
+ }
2392
+ /**
2393
+ * @param current The hitobject to calculate.
2394
+ */
2395
+ strainValueAt(current) {
2396
+ this.currentSpeedStrain *= this.strainDecay(current.strainTime);
2397
+ this.currentSpeedStrain +=
2398
+ OsuSpeedEvaluator.evaluateDifficultyOf(current, this.greatWindow) *
2399
+ this.skillMultiplier;
2400
+ this.currentRhythm = OsuRhythmEvaluator.evaluateDifficultyOf(current, this.greatWindow);
2401
+ return this.currentSpeedStrain * this.currentRhythm;
2402
+ }
2147
2403
  /**
2148
2404
  * @param current The hitobject to save to.
2149
2405
  */
@@ -2154,17 +2410,20 @@ class OsuSpeed extends OsuSkill {
2154
2410
  }
2155
2411
 
2156
2412
  /**
2157
- * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
2413
+ * An evaluator for calculating osu!standard Flashlight skill.
2158
2414
  */
2159
- class OsuFlashlight extends OsuSkill {
2160
- historyLength = 10;
2161
- skillMultiplier = 0.07;
2162
- strainDecayBase = 0.15;
2163
- reducedSectionCount = 10;
2164
- reducedSectionBaseline = 0.75;
2165
- difficultyMultiplier = 1.06;
2166
- decayWeight = 1;
2167
- strainValueOf(current) {
2415
+ class OsuFlashlightEvaluator extends FlashlightEvaluator {
2416
+ /**
2417
+ * Evaluates the difficulty of memorizing and hitting the current object, based on:
2418
+ *
2419
+ * - distance between the previous and the current object,
2420
+ * - the visual opacity of the current object,
2421
+ * - and whether Hidden mod is enabled.
2422
+ *
2423
+ * @param current The current object.
2424
+ * @param isHiddenMod Whether the Hidden mod is enabled.
2425
+ */
2426
+ static evaluateDifficultyOf(current, isHiddenMod) {
2168
2427
  if (current.object instanceof osuBase.Spinner) {
2169
2428
  return 0;
2170
2429
  }
@@ -2173,8 +2432,8 @@ class OsuFlashlight extends OsuSkill {
2173
2432
  let cumulativeStrainTime = 0;
2174
2433
  let result = 0;
2175
2434
  let last = current;
2176
- for (let i = 0; i < this.previous.length; ++i) {
2177
- const currentObject = this.previous[i];
2435
+ for (let i = 0; i < Math.min(current.index, 10); ++i) {
2436
+ const currentObject = current.previous(i);
2178
2437
  if (!(currentObject.object instanceof osuBase.Spinner)) {
2179
2438
  const jumpDistance = current.object.stackedPosition.subtract(currentObject.object.endPosition).length;
2180
2439
  cumulativeStrainTime += last.strainTime;
@@ -2184,21 +2443,47 @@ class OsuFlashlight extends OsuSkill {
2184
2443
  }
2185
2444
  // We also want to nerf stacks so that only the first object of the stack is accounted for.
2186
2445
  const stackNerf = Math.min(1, currentObject.lazyJumpDistance / scalingFactor / 25);
2446
+ // Bonus based on how visible the object is.
2447
+ const opacityBonus = 1 +
2448
+ this.maxOpacityBonus *
2449
+ (1.0 -
2450
+ current.opacityAt(currentObject.startTime, isHiddenMod));
2187
2451
  result +=
2188
- (stackNerf * scalingFactor * jumpDistance) /
2452
+ (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
2189
2453
  cumulativeStrainTime;
2190
2454
  }
2191
2455
  last = currentObject;
2192
2456
  }
2457
+ // Additional bonus for Hidden due to there being no approach circles.
2458
+ if (isHiddenMod) {
2459
+ result *= 1 + this.hiddenBonus;
2460
+ }
2193
2461
  return Math.pow(smallDistNerf * result, 2);
2194
2462
  }
2463
+ }
2464
+
2465
+ /**
2466
+ * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
2467
+ */
2468
+ class OsuFlashlight extends OsuSkill {
2469
+ skillMultiplier = 0.05;
2470
+ strainDecayBase = 0.15;
2471
+ reducedSectionCount = 10;
2472
+ reducedSectionBaseline = 0.75;
2473
+ difficultyMultiplier = 1.06;
2474
+ decayWeight = 1;
2475
+ isHidden;
2476
+ constructor(mods) {
2477
+ super(mods);
2478
+ this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
2479
+ }
2195
2480
  /**
2196
2481
  * @param current The hitobject to calculate.
2197
2482
  */
2198
2483
  strainValueAt(current) {
2199
2484
  this.currentStrain *= this.strainDecay(current.deltaTime);
2200
2485
  this.currentStrain +=
2201
- this.strainValueOf(current) * this.skillMultiplier;
2486
+ OsuFlashlightEvaluator.evaluateDifficultyOf(current, this.isHidden) * this.skillMultiplier;
2202
2487
  return this.currentStrain;
2203
2488
  }
2204
2489
  saveToHitObject(current) {
@@ -2207,9 +2492,9 @@ class OsuFlashlight extends OsuSkill {
2207
2492
  }
2208
2493
 
2209
2494
  /**
2210
- * Difficulty calculator for osu!standard gamemode.
2495
+ * A difficulty calculator for osu!standard gamemode.
2211
2496
  */
2212
- class OsuStarRating extends StarRating {
2497
+ class OsuDifficultyCalculator extends DifficultyCalculator {
2213
2498
  /**
2214
2499
  * The aim star rating of the beatmap.
2215
2500
  */
@@ -2223,15 +2508,7 @@ class OsuStarRating extends StarRating {
2223
2508
  */
2224
2509
  flashlight = 0;
2225
2510
  difficultyMultiplier = 0.0675;
2226
- calculate(params) {
2227
- return super.calculate(params, osuBase.modes.osu);
2228
- }
2229
- /**
2230
- * Generates difficulty hitobjects for this calculator.
2231
- */
2232
- generateDifficultyHitObjects() {
2233
- super.generateDifficultyHitObjects(osuBase.modes.osu);
2234
- }
2511
+ mode = osuBase.modes.osu;
2235
2512
  /**
2236
2513
  * Calculates the aim star rating of the beatmap and stores it in this instance.
2237
2514
  */
@@ -2366,44 +2643,43 @@ class OsuStarRating extends StarRating {
2366
2643
  }
2367
2644
 
2368
2645
  /**
2369
- * A star rating calculator that configures which mode to calculate difficulty for and what mods are applied.
2646
+ * A difficulty calculator that calculates for both osu!droid and osu!standard gamemode.
2370
2647
  */
2371
2648
  class MapStars {
2372
2649
  /**
2373
- * The osu!droid star rating of the beatmap.
2650
+ * The osu!droid difficulty calculator of the beatmap.
2374
2651
  */
2375
- droidStars = new DroidStarRating();
2652
+ droid;
2376
2653
  /**
2377
- * The osu!standard star rating of the beatmap.
2654
+ * The osu!standard difficulty calculator of the beatmap.
2378
2655
  */
2379
- pcStars = new OsuStarRating();
2656
+ osu;
2380
2657
  /**
2381
- * Calculates the star rating of a beatmap.
2658
+ * Constructs this instance and calculates the given beatmap's osu!droid and osu!standard difficulty.
2659
+ *
2660
+ * @param beatmap The beatmap to calculate.
2661
+ * @param options Options for the difficulty calculation.
2382
2662
  */
2383
- calculate(params) {
2384
- const mod = params.mods ?? [];
2663
+ constructor(beatmap, options) {
2385
2664
  const stats = new osuBase.MapStats({
2386
- speedMultiplier: params.stats?.speedMultiplier ?? 1,
2387
- isForceAR: params.stats?.isForceAR ?? false,
2388
- oldStatistics: params.stats?.oldStatistics ?? false,
2665
+ speedMultiplier: options?.stats?.speedMultiplier ?? 1,
2666
+ isForceAR: options?.stats?.isForceAR ?? false,
2667
+ oldStatistics: options?.stats?.oldStatistics ?? false,
2389
2668
  });
2390
- this.droidStars.calculate({
2391
- map: params.map,
2392
- mods: mod,
2669
+ this.droid = new DroidDifficultyCalculator(beatmap).calculate({
2670
+ ...options,
2393
2671
  stats,
2394
2672
  });
2395
- this.pcStars.calculate({
2396
- map: params.map,
2397
- mods: mod,
2673
+ this.osu = new OsuDifficultyCalculator(beatmap).calculate({
2674
+ ...options,
2398
2675
  stats,
2399
2676
  });
2400
- return this;
2401
2677
  }
2402
2678
  /**
2403
2679
  * Returns a string representative of the class.
2404
2680
  */
2405
2681
  toString() {
2406
- return `${this.droidStars.toString()}\n${this.pcStars.toString()}`;
2682
+ return `${this.droid.toString()}\n${this.osu.toString()}`;
2407
2683
  }
2408
2684
  }
2409
2685
 
@@ -2411,8 +2687,6 @@ class MapStars {
2411
2687
  * A performance points calculator that calculates performance points for osu!standard gamemode.
2412
2688
  */
2413
2689
  class OsuPerformanceCalculator extends PerformanceCalculator {
2414
- stars = new OsuStarRating();
2415
- finalMultiplier = 1.12;
2416
2690
  /**
2417
2691
  * The aim performance value.
2418
2692
  */
@@ -2429,9 +2703,8 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2429
2703
  * The flashlight performance value.
2430
2704
  */
2431
2705
  flashlight = 0;
2432
- calculate(params) {
2433
- return this.calculateInternal(params, osuBase.modes.osu);
2434
- }
2706
+ finalMultiplier = 1.12;
2707
+ mode = osuBase.modes.osu;
2435
2708
  calculateValues() {
2436
2709
  this.calculateAimValue();
2437
2710
  this.calculateSpeedValue();
@@ -2439,19 +2712,20 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2439
2712
  this.calculateFlashlightValue();
2440
2713
  }
2441
2714
  calculateTotalValue() {
2442
- return (Math.pow(Math.pow(this.aim, 1.1) +
2443
- Math.pow(this.speed, 1.1) +
2444
- Math.pow(this.accuracy, 1.1) +
2445
- Math.pow(this.flashlight, 1.1), 1 / 1.1) * this.finalMultiplier);
2715
+ this.total =
2716
+ Math.pow(Math.pow(this.aim, 1.1) +
2717
+ Math.pow(this.speed, 1.1) +
2718
+ Math.pow(this.accuracy, 1.1) +
2719
+ Math.pow(this.flashlight, 1.1), 1 / 1.1) * this.finalMultiplier;
2446
2720
  }
2447
2721
  /**
2448
2722
  * Calculates the aim performance value of the beatmap.
2449
2723
  */
2450
2724
  calculateAimValue() {
2451
2725
  // Global variables
2452
- const objectCount = this.stars.objects.length;
2726
+ const objectCount = this.difficultyCalculator.objects.length;
2453
2727
  const calculatedAR = this.mapStatistics.ar;
2454
- this.aim = this.baseValue(Math.pow(this.stars.aim, this.stars.mods.some((m) => m instanceof osuBase.ModTouchDevice)
2728
+ this.aim = this.baseValue(Math.pow(this.difficultyCalculator.aim, this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModTouchDevice)
2455
2729
  ? 0.8
2456
2730
  : 1));
2457
2731
  // Longer maps are worth more
@@ -2461,7 +2735,8 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2461
2735
  }
2462
2736
  this.aim *= lengthBonus;
2463
2737
  if (this.effectiveMissCount > 0) {
2464
- // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
2738
+ // Penalize misses by assessing # of misses relative to the total # of objects.
2739
+ // Default a 3% reduction for any # of misses.
2465
2740
  this.aim *=
2466
2741
  0.97 *
2467
2742
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), this.effectiveMissCount);
@@ -2479,7 +2754,7 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2479
2754
  // Buff for longer maps with high AR.
2480
2755
  this.aim *= 1 + arFactor * lengthBonus;
2481
2756
  // We want to give more reward for lower AR when it comes to aim and HD. This nerfs high AR and buffs lower AR.
2482
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2757
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModHidden)) {
2483
2758
  this.aim *= 1 + 0.04 * (12 - calculatedAR);
2484
2759
  }
2485
2760
  // Scale the aim value with slider factor to nerf very likely dropped sliderends.
@@ -2495,10 +2770,10 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2495
2770
  */
2496
2771
  calculateSpeedValue() {
2497
2772
  // Global variables
2498
- const objectCount = this.stars.objects.length;
2773
+ const objectCount = this.difficultyCalculator.objects.length;
2499
2774
  const calculatedAR = this.mapStatistics.ar;
2500
2775
  const n50 = this.computedAccuracy.n50;
2501
- this.speed = this.baseValue(this.stars.speed);
2776
+ this.speed = this.baseValue(this.difficultyCalculator.speed);
2502
2777
  // Longer maps are worth more
2503
2778
  let lengthBonus = 0.95 + 0.4 * Math.min(1, objectCount / 2000);
2504
2779
  if (objectCount > 2000) {
@@ -2506,7 +2781,8 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2506
2781
  }
2507
2782
  this.speed *= lengthBonus;
2508
2783
  if (this.effectiveMissCount > 0) {
2509
- // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
2784
+ // Penalize misses by assessing # of misses relative to the total # of objects.
2785
+ // Default a 3% reduction for any # of misses.
2510
2786
  this.speed *=
2511
2787
  0.97 *
2512
2788
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), Math.pow(this.effectiveMissCount, 0.875));
@@ -2518,7 +2794,7 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2518
2794
  // Buff for longer maps with high AR.
2519
2795
  this.speed *= 1 + 0.3 * (calculatedAR - 10.33) * lengthBonus;
2520
2796
  }
2521
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2797
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModHidden)) {
2522
2798
  this.speed *= 1 + 0.04 * (12 - calculatedAR);
2523
2799
  }
2524
2800
  // Scale the speed value with accuracy and OD.
@@ -2532,21 +2808,21 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2532
2808
  * Calculates the accuracy performance value of the beatmap.
2533
2809
  */
2534
2810
  calculateAccuracyValue() {
2535
- if (this.stars.mods.some((m) => m instanceof osuBase.ModRelax)) {
2811
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModRelax)) {
2536
2812
  return;
2537
2813
  }
2538
2814
  // Global variables
2539
- const nobjects = this.stars.objects.length;
2540
- const ncircles = this.stars.mods.some((m) => m instanceof osuBase.ModScoreV2)
2541
- ? nobjects - this.stars.map.hitObjects.spinners
2542
- : this.stars.map.hitObjects.circles;
2815
+ const nobjects = this.difficultyCalculator.objects.length;
2816
+ const ncircles = this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModScoreV2)
2817
+ ? nobjects - this.difficultyCalculator.beatmap.hitObjects.spinners
2818
+ : this.difficultyCalculator.beatmap.hitObjects.circles;
2543
2819
  if (ncircles === 0) {
2544
2820
  return;
2545
2821
  }
2546
2822
  const realAccuracy = new osuBase.Accuracy({
2547
2823
  ...this.computedAccuracy,
2548
2824
  n300: this.computedAccuracy.n300 -
2549
- (this.stars.objects.length - ncircles),
2825
+ (this.difficultyCalculator.objects.length - ncircles),
2550
2826
  });
2551
2827
  // Lots of arbitrary values from testing.
2552
2828
  // Considering to use derivation from perfect accuracy in a probabilistic manner - assume normal distribution
@@ -2556,10 +2832,10 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2556
2832
  2.83;
2557
2833
  // Bonus for many hitcircles - it's harder to keep good accuracy up for longer
2558
2834
  this.accuracy *= Math.min(1.15, Math.pow(ncircles / 1000, 0.3));
2559
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2835
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModHidden)) {
2560
2836
  this.accuracy *= 1.08;
2561
2837
  }
2562
- if (this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2838
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2563
2839
  this.accuracy *= 1.02;
2564
2840
  }
2565
2841
  }
@@ -2567,19 +2843,15 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2567
2843
  * Calculates the flashlight performance value of the beatmap.
2568
2844
  */
2569
2845
  calculateFlashlightValue() {
2570
- if (!this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2846
+ if (!this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2571
2847
  return;
2572
2848
  }
2573
2849
  // Global variables
2574
- const objectCount = this.stars.objects.length;
2850
+ const objectCount = this.difficultyCalculator.objects.length;
2575
2851
  this.flashlight =
2576
- Math.pow(Math.pow(this.stars.flashlight, this.stars.mods.some((m) => m instanceof osuBase.ModTouchDevice)
2852
+ Math.pow(Math.pow(this.difficultyCalculator.flashlight, this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModTouchDevice)
2577
2853
  ? 0.8
2578
2854
  : 1), 2) * 25;
2579
- // Add an additional bonus for HDFL.
2580
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2581
- this.flashlight *= 1.3;
2582
- }
2583
2855
  // Combo scaling
2584
2856
  this.flashlight *= this.comboPenalty;
2585
2857
  if (this.effectiveMissCount > 0) {
@@ -2615,21 +2887,34 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2615
2887
  }
2616
2888
  }
2617
2889
 
2890
+ exports.AimEvaluator = AimEvaluator;
2891
+ exports.DifficultyCalculator = DifficultyCalculator;
2618
2892
  exports.DifficultyHitObject = DifficultyHitObject;
2619
2893
  exports.DifficultyHitObjectCreator = DifficultyHitObjectCreator;
2620
2894
  exports.DroidAim = DroidAim;
2895
+ exports.DroidAimEvaluator = DroidAimEvaluator;
2896
+ exports.DroidDifficultyCalculator = DroidDifficultyCalculator;
2621
2897
  exports.DroidFlashlight = DroidFlashlight;
2898
+ exports.DroidFlashlightEvaluator = DroidFlashlightEvaluator;
2622
2899
  exports.DroidPerformanceCalculator = DroidPerformanceCalculator;
2623
2900
  exports.DroidRhythm = DroidRhythm;
2624
- exports.DroidStarRating = DroidStarRating;
2901
+ exports.DroidRhythmEvaluator = DroidRhythmEvaluator;
2625
2902
  exports.DroidTap = DroidTap;
2903
+ exports.DroidTapEvaluator = DroidTapEvaluator;
2626
2904
  exports.DroidVisual = DroidVisual;
2905
+ exports.DroidVisualEvaluator = DroidVisualEvaluator;
2906
+ exports.FlashlightEvaluator = FlashlightEvaluator;
2627
2907
  exports.MapStars = MapStars;
2628
2908
  exports.OsuAim = OsuAim;
2909
+ exports.OsuAimEvaluator = OsuAimEvaluator;
2910
+ exports.OsuDifficultyCalculator = OsuDifficultyCalculator;
2629
2911
  exports.OsuFlashlight = OsuFlashlight;
2912
+ exports.OsuFlashlightEvaluator = OsuFlashlightEvaluator;
2630
2913
  exports.OsuPerformanceCalculator = OsuPerformanceCalculator;
2914
+ exports.OsuRhythmEvaluator = OsuRhythmEvaluator;
2631
2915
  exports.OsuSpeed = OsuSpeed;
2632
- exports.OsuStarRating = OsuStarRating;
2916
+ exports.OsuSpeedEvaluator = OsuSpeedEvaluator;
2633
2917
  exports.PerformanceCalculator = PerformanceCalculator;
2634
- exports.StarRating = StarRating;
2918
+ exports.RhythmEvaluator = RhythmEvaluator;
2919
+ exports.SpeedEvaluator = SpeedEvaluator;
2635
2920
  //# sourceMappingURL=index.js.map