@rian8337/osu-rebalance-difficulty-calculator 2.0.0-alpha.30 → 2.0.0-alpha.31

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,12 @@ 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;
15
47
  /**
16
48
  * The preempt time of the hitobject.
17
49
  */
@@ -122,11 +154,40 @@ class DifficultyHitObject {
122
154
  * Adjusted velocity of the hitobject, taking speed multiplier into account.
123
155
  */
124
156
  velocity = 0;
157
+ hitObjects;
125
158
  /**
126
159
  * @param object The underlying hitobject.
160
+ * @param hitObjects All difficulty hitobjects in the processed beatmap.
127
161
  */
128
- constructor(object) {
162
+ constructor(object, hitObjects) {
129
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;
130
191
  }
131
192
  /**
132
193
  * Calculates the opacity of the hitobject at a given time.
@@ -189,7 +250,8 @@ class DifficultyHitObjectCreator {
189
250
  const scalingFactor = this.getScalingFactor(params.objects[0].radius);
190
251
  const difficultyObjects = [];
191
252
  for (let i = 0; i < params.objects.length; ++i) {
192
- const object = new DifficultyHitObject(params.objects[i]);
253
+ const object = new DifficultyHitObject(params.objects[i], difficultyObjects);
254
+ object.index = difficultyObjects.length - 1;
193
255
  object.object.scale = scale;
194
256
  object.timePreempt = params.preempt;
195
257
  // Preempt time can go below 450ms. Normally, this is achieved via the DT mod or a
@@ -327,9 +389,7 @@ class DifficultyHitObjectCreator {
327
389
  if (this.mode === osuBase.modes.droid) {
328
390
  slider.tail.startTime += osuBase.Slider.legacyLastTickOffset;
329
391
  slider.tail.endTime += osuBase.Slider.legacyLastTickOffset;
330
- slider.nestedHitObjects.sort((a, b) => {
331
- return a.startTime - b.startTime;
332
- });
392
+ slider.nestedHitObjects.sort((a, b) => a.startTime - b.startTime);
333
393
  // Temporary lazy end position until a real result can be derived.
334
394
  slider.lazyEndPosition = slider.stackedPosition;
335
395
  // Stop here if the slider has too short duration due to float number limitation.
@@ -441,178 +501,54 @@ class DifficultyHitObjectCreator {
441
501
  }
442
502
 
443
503
  /**
444
- * A bare minimal abstract skill for fully custom skill implementations.
445
- */
446
- class Skill {
447
- /**
448
- * The hitobjects that were processed previously. They can affect the strain values of the following objects.
449
- *
450
- * The latest hitobject is at index 0.
451
- */
452
- previous = [];
453
- /**
454
- * Number of previous hitobjects to keep inside the `previous` array.
455
- */
456
- historyLength = 2;
457
- /**
458
- * The mods that this skill processes.
459
- */
460
- mods;
461
- constructor(mods) {
462
- this.mods = mods;
463
- }
464
- processInternal(current) {
465
- while (this.previous.length > this.historyLength) {
466
- this.previous.pop();
467
- }
468
- this.process(current);
469
- this.previous.unshift(current);
470
- }
471
- }
472
-
473
- /**
474
- * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
475
- * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
476
- */
477
- class StrainSkill extends Skill {
478
- /**
479
- * The strain of currently calculated hitobject.
480
- */
481
- currentStrain = 0;
482
- /**
483
- * The current section's strain peak.
484
- */
485
- currentSectionPeak = 0;
486
- /**
487
- * Strain peaks are stored here.
488
- */
489
- strainPeaks = [];
490
- sectionLength = 400;
491
- currentSectionEnd = 0;
492
- process(current) {
493
- // The first object doesn't generate a strain, so we begin with an incremented section end
494
- if (this.previous.length === 0) {
495
- this.currentSectionEnd =
496
- Math.ceil(current.startTime / this.sectionLength) *
497
- this.sectionLength;
498
- }
499
- while (current.startTime > this.currentSectionEnd) {
500
- this.saveCurrentPeak();
501
- this.startNewSectionFrom(this.currentSectionEnd);
502
- this.currentSectionEnd += this.sectionLength;
503
- }
504
- this.currentStrain = this.strainValueAt(current);
505
- this.saveToHitObject(current);
506
- this.currentSectionPeak = Math.max(this.currentStrain, this.currentSectionPeak);
507
- }
508
- /**
509
- * Saves the current peak strain level to the list of strain peaks, which will be used to calculate an overall difficulty.
510
- */
511
- saveCurrentPeak() {
512
- this.strainPeaks.push(this.currentSectionPeak);
513
- }
514
- /**
515
- * Sets the initial strain level for a new section.
516
- *
517
- * @param offset The beginning of the new section in milliseconds, adjusted by speed multiplier.
518
- */
519
- startNewSectionFrom(offset) {
520
- // The maximum strain of the new section is not zero by default, strain decays as usual regardless of section boundaries.
521
- // This means we need to capture the strain level at the beginning of the new section, and use that as the initial peak level.
522
- this.currentSectionPeak =
523
- this.currentStrain *
524
- this.strainDecay(offset - this.previous[0].startTime);
525
- }
526
- /**
527
- * Calculates strain decay for a specified time frame.
528
- *
529
- * @param ms The time frame to calculate.
530
- */
531
- strainDecay(ms) {
532
- return Math.pow(this.strainDecayBase, ms / 1000);
533
- }
534
- }
535
-
536
- /**
537
- * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
538
- * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
539
- */
540
- class DroidSkill extends StrainSkill {
541
- difficultyValue() {
542
- const sortedStrains = this.strainPeaks
543
- .slice()
544
- .sort((a, b) => {
545
- return b - a;
546
- });
547
- // We are reducing the highest strains first to account for extreme difficulty spikes.
548
- for (let i = 0; i < Math.min(sortedStrains.length, this.reducedSectionCount); ++i) {
549
- const scale = Math.log10(osuBase.Interpolation.lerp(1, 10, osuBase.MathUtils.clamp(i / this.reducedSectionCount, 0, 1)));
550
- sortedStrains[i] *= osuBase.Interpolation.lerp(this.reducedSectionBaseline, 1, scale);
551
- }
552
- // Math here preserves the property that two notes of equal difficulty x, we have their summed difficulty = x * starsPerDouble.
553
- // This also applies to two sets of notes with equal difficulty.
554
- return Math.pow(sortedStrains.reduce((a, v) => {
555
- if (v === 0) {
556
- return a;
557
- }
558
- return a + Math.pow(v, 1 / Math.log2(this.starsPerDouble));
559
- }, 0), Math.log2(this.starsPerDouble));
560
- }
561
- }
562
-
563
- /**
564
- * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
504
+ * An evaluator for calculating osu!droid Aim skill.
565
505
  */
566
- class DroidAim extends DroidSkill {
567
- skillMultiplier = 23.25;
568
- strainDecayBase = 0.15;
569
- reducedSectionCount = 10;
570
- reducedSectionBaseline = 0.75;
571
- starsPerDouble = 1.05;
506
+ class DroidAimEvaluator extends AimEvaluator {
572
507
  /**
573
508
  * Spacing threshold for a single hitobject spacing.
574
509
  */
575
- SINGLE_SPACING_THRESHOLD = 175;
510
+ static SINGLE_SPACING_THRESHOLD = 175;
576
511
  // ~200 1/2 BPM jumps
577
- minSpeedBonus = 150;
578
- wideAngleMultiplier = 1.5;
579
- acuteAngleMultiplier = 2;
580
- sliderMultiplier = 1.5;
581
- velocityChangeMultiplier = 0.75;
582
- withSliders;
583
- constructor(mods, withSliders) {
584
- super(mods);
585
- this.withSliders = withSliders;
586
- }
512
+ static minSpeedBonus = 150;
587
513
  /**
588
- * @param current The hitobject to calculate.
514
+ * Evaluates the difficulty of aiming the current object, based on:
515
+ *
516
+ * - cursor velocity to the current object,
517
+ * - angle difficulty,
518
+ * - sharp velocity increases,
519
+ * - and slider difficulty.
520
+ *
521
+ * @param current The current object.
522
+ * @param withSliders Whether to take slider difficulty into account.
589
523
  */
590
- strainValueOf(current) {
524
+ static evaluateDifficultyOf(current, withSliders) {
525
+ const last = current.previous(0);
591
526
  if (current.object instanceof osuBase.Spinner ||
592
527
  // Exclude overlapping objects that can be tapped at once.
593
528
  (current.deltaTime < 5 &&
594
- (this.previous[0]?.object instanceof osuBase.Slider
595
- ? Math.min(this.previous[0].object.stackedEndPosition.getDistance(current.object.stackedPosition), this.previous[0].object.lazyEndPosition.getDistance(current.object.stackedPosition))
596
- : this.previous[0]?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) <=
529
+ ((last?.object instanceof osuBase.Slider
530
+ ? Math.min(last.object.stackedEndPosition.getDistance(current.object.stackedPosition), last.object.lazyEndPosition.getDistance(current.object.stackedPosition))
531
+ : last?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) ?? Number.POSITIVE_INFINITY) <=
597
532
  2 * current.object.radius)) {
598
533
  return 0;
599
534
  }
600
- return this.aimStrainOf(current) + this.movementStrainOf(current);
535
+ return (this.aimStrainOf(current, withSliders) +
536
+ this.movementStrainOf(current));
601
537
  }
602
538
  /**
603
539
  * Calculates the aim strain of a hitobject.
604
540
  */
605
- aimStrainOf(current) {
606
- if (this.previous.length <= 1 ||
607
- this.previous[0].object instanceof osuBase.Spinner) {
541
+ static aimStrainOf(current, withSliders) {
542
+ if (current.index <= 1 ||
543
+ current.previous(0)?.object instanceof osuBase.Spinner) {
608
544
  return 0;
609
545
  }
610
- const last = this.previous[0];
611
- const lastLast = this.previous[1];
546
+ const last = current.previous(0);
547
+ const lastLast = current.previous(1);
612
548
  // Calculate the velocity to the current hitobject, which starts with a base distance / time assuming the last object is a hitcircle.
613
549
  let currentVelocity = current.lazyJumpDistance / current.strainTime;
614
550
  // But if the last object is a slider, then we extend the travel velocity through the slider into the current object.
615
- if (last.object instanceof osuBase.Slider && this.withSliders) {
551
+ if (last.object instanceof osuBase.Slider && withSliders) {
616
552
  // Calculate the slider velocity from slider head to slider end.
617
553
  const travelVelocity = last.travelDistance / last.travelTime;
618
554
  // Calculate the movement velocity from slider end to current object.
@@ -624,7 +560,7 @@ class DroidAim extends DroidSkill {
624
560
  }
625
561
  // As above, do the same for the previous hitobject.
626
562
  let prevVelocity = last.lazyJumpDistance / last.strainTime;
627
- if (lastLast.object instanceof osuBase.Slider && this.withSliders) {
563
+ if (lastLast.object instanceof osuBase.Slider && withSliders) {
628
564
  const travelVelocity = lastLast.travelDistance / lastLast.travelTime;
629
565
  const movementVelocity = last.minimumJumpTime !== 0
630
566
  ? last.minimumJumpDistance / last.minimumJumpTime
@@ -713,7 +649,7 @@ class DroidAim extends DroidSkill {
713
649
  strain += Math.max(acuteAngleBonus * this.acuteAngleMultiplier, wideAngleBonus * this.wideAngleMultiplier +
714
650
  velocityChangeBonus * this.velocityChangeMultiplier);
715
651
  // Add in additional slider velocity bonus.
716
- if (this.withSliders) {
652
+ if (withSliders) {
717
653
  strain += sliderBonus * this.sliderMultiplier;
718
654
  }
719
655
  return strain;
@@ -721,80 +657,201 @@ class DroidAim extends DroidSkill {
721
657
  /**
722
658
  * Calculates the movement strain of a hitobject.
723
659
  */
724
- movementStrainOf(current) {
660
+ static movementStrainOf(current) {
725
661
  let speedBonus = 1;
726
662
  if (current.strainTime < this.minSpeedBonus) {
727
663
  speedBonus +=
728
664
  0.75 *
729
665
  Math.pow((this.minSpeedBonus - current.strainTime) / 45, 2);
730
666
  }
731
- const travelDistance = this.previous[0]?.travelDistance ?? 0;
667
+ const travelDistance = current.previous(0)?.travelDistance ?? 0;
732
668
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
733
669
  return ((50 *
734
670
  speedBonus *
735
671
  Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 5)) /
736
672
  current.strainTime);
737
673
  }
674
+ }
675
+
676
+ /**
677
+ * A bare minimal abstract skill for fully custom skill implementations.
678
+ */
679
+ class Skill {
738
680
  /**
739
- * @param current The hitobject to calculate.
681
+ * The mods that this skill processes.
740
682
  */
741
- strainValueAt(current) {
742
- this.currentStrain *= this.strainDecay(current.deltaTime);
743
- this.currentStrain +=
744
- this.strainValueOf(current) * this.skillMultiplier;
745
- return this.currentStrain;
683
+ mods;
684
+ constructor(mods) {
685
+ this.mods = mods;
746
686
  }
687
+ }
688
+
689
+ /**
690
+ * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
691
+ * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
692
+ */
693
+ class StrainSkill extends Skill {
747
694
  /**
748
- * @param current The hitobject to save to.
695
+ * The strain of currently calculated hitobject.
749
696
  */
750
- saveToHitObject(current) {
751
- if (this.withSliders) {
752
- current.aimStrainWithSliders = this.currentStrain;
697
+ currentStrain = 0;
698
+ /**
699
+ * The current section's strain peak.
700
+ */
701
+ currentSectionPeak = 0;
702
+ /**
703
+ * Strain peaks are stored here.
704
+ */
705
+ strainPeaks = [];
706
+ sectionLength = 400;
707
+ currentSectionEnd = 0;
708
+ isFirstObject = true;
709
+ /**
710
+ * Calculates the strain value of a hitobject and stores the value in it. This value is affected by previously processed objects.
711
+ *
712
+ * @param current The hitobject to process.
713
+ */
714
+ process(current) {
715
+ // The first object doesn't generate a strain, so we begin with an incremented section end
716
+ if (this.isFirstObject) {
717
+ this.currentSectionEnd =
718
+ Math.ceil(current.startTime / this.sectionLength) *
719
+ this.sectionLength;
720
+ this.isFirstObject = false;
753
721
  }
754
- else {
755
- current.aimStrainWithoutSliders = this.currentStrain;
722
+ while (current.startTime > this.currentSectionEnd) {
723
+ this.saveCurrentPeak();
724
+ this.startNewSectionFrom(this.currentSectionEnd, current);
725
+ this.currentSectionEnd += this.sectionLength;
756
726
  }
727
+ // Ignore the first hitobject.
728
+ this.currentStrain = this.strainValueAt(current);
729
+ this.saveToHitObject(current);
730
+ this.currentSectionPeak = Math.max(this.currentStrain, this.currentSectionPeak);
757
731
  }
758
732
  /**
759
- * Calculates the bonus of wide angles.
733
+ * Saves the current peak strain level to the list of strain peaks, which will be used to calculate an overall difficulty.
760
734
  */
761
- calculateWideAngleBonus(angle) {
762
- return Math.pow(Math.sin((3 / 4) *
763
- (Math.min((5 / 6) * Math.PI, Math.max(Math.PI / 6, angle)) -
764
- Math.PI / 6)), 2);
735
+ saveCurrentPeak() {
736
+ this.strainPeaks.push(this.currentSectionPeak);
765
737
  }
766
738
  /**
767
- * Calculates the bonus of acute angles.
739
+ * Calculates strain decay for a specified time frame.
740
+ *
741
+ * @param ms The time frame to calculate.
768
742
  */
769
- calculateAcuteAngleBonus(angle) {
770
- return 1 - this.calculateWideAngleBonus(angle);
743
+ strainDecay(ms) {
744
+ return Math.pow(this.strainDecayBase, ms / 1000);
745
+ }
746
+ /**
747
+ * Sets the initial strain level for a new section.
748
+ *
749
+ * @param offset The beginning of the new section in milliseconds, adjusted by speed multiplier.
750
+ * @param current The current hitobject.
751
+ */
752
+ startNewSectionFrom(offset, current) {
753
+ // The maximum strain of the new section is not zero by default, strain decays as usual regardless of section boundaries.
754
+ // This means we need to capture the strain level at the beginning of the new section, and use that as the initial peak level.
755
+ this.currentSectionPeak =
756
+ this.currentStrain *
757
+ this.strainDecay(offset - current.previous(0).startTime);
771
758
  }
772
759
  }
773
760
 
774
761
  /**
775
- * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
762
+ * Used to processes strain values of difficulty hitobjects, keep track of strain levels caused by the processed objects
763
+ * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
776
764
  */
777
- class DroidFlashlight extends DroidSkill {
778
- historyLength = 10;
779
- skillMultiplier = 0.1;
765
+ class DroidSkill extends StrainSkill {
766
+ difficultyValue() {
767
+ const sortedStrains = this.strainPeaks
768
+ .slice()
769
+ .sort((a, b) => b - a);
770
+ // We are reducing the highest strains first to account for extreme difficulty spikes.
771
+ for (let i = 0; i < Math.min(sortedStrains.length, this.reducedSectionCount); ++i) {
772
+ const scale = Math.log10(osuBase.Interpolation.lerp(1, 10, osuBase.MathUtils.clamp(i / this.reducedSectionCount, 0, 1)));
773
+ sortedStrains[i] *= osuBase.Interpolation.lerp(this.reducedSectionBaseline, 1, scale);
774
+ }
775
+ // Math here preserves the property that two notes of equal difficulty x, we have their summed difficulty = x * starsPerDouble.
776
+ // This also applies to two sets of notes with equal difficulty.
777
+ return Math.pow(sortedStrains.reduce((a, v) => {
778
+ if (v <= 0) {
779
+ return a;
780
+ }
781
+ return a + Math.pow(v, 1 / Math.log2(this.starsPerDouble));
782
+ }, 0), Math.log2(this.starsPerDouble));
783
+ }
784
+ }
785
+
786
+ /**
787
+ * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
788
+ */
789
+ class DroidAim extends DroidSkill {
790
+ skillMultiplier = 23.25;
780
791
  strainDecayBase = 0.15;
781
792
  reducedSectionCount = 10;
782
793
  reducedSectionBaseline = 0.75;
783
794
  starsPerDouble = 1.05;
784
- maxOpacityBonus = 0.4;
785
- hiddenBonus = 0.2;
786
- isHidden;
787
- constructor(mods) {
795
+ withSliders;
796
+ constructor(mods, withSliders) {
788
797
  super(mods);
789
- this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
798
+ this.withSliders = withSliders;
799
+ }
800
+ /**
801
+ * @param current The hitobject to calculate.
802
+ */
803
+ strainValueAt(current) {
804
+ this.currentStrain *= this.strainDecay(current.deltaTime);
805
+ this.currentStrain +=
806
+ DroidAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
807
+ this.skillMultiplier;
808
+ return this.currentStrain;
809
+ }
810
+ /**
811
+ * @param current The hitobject to save to.
812
+ */
813
+ saveToHitObject(current) {
814
+ if (this.withSliders) {
815
+ current.aimStrainWithSliders = this.currentStrain;
816
+ }
817
+ else {
818
+ current.aimStrainWithoutSliders = this.currentStrain;
819
+ }
790
820
  }
791
- strainValueOf(current) {
821
+ }
822
+
823
+ /**
824
+ * An evaluator for calculating flashlight skill.
825
+ *
826
+ * This class should be considered an "evaluating" class and not persisted.
827
+ */
828
+ class FlashlightEvaluator {
829
+ static maxOpacityBonus = 0.4;
830
+ static hiddenBonus = 0.2;
831
+ }
832
+
833
+ /**
834
+ * An evaluator for calculating osu!droid Flashlight skill.
835
+ */
836
+ class DroidFlashlightEvaluator extends FlashlightEvaluator {
837
+ /**
838
+ * Evaluates the difficulty of memorizing and hitting the current object, based on:
839
+ *
840
+ * - distance between the previous and the current object,
841
+ * - the visual opacity of the current object,
842
+ * - and whether Hidden mod is enabled.
843
+ *
844
+ * @param current The current object.
845
+ * @param isHiddenMod Whether the Hidden mod is enabled.
846
+ */
847
+ static evaluateDifficultyOf(current, isHiddenMod) {
848
+ const actualLast = current.previous(0);
792
849
  if (current.object instanceof osuBase.Spinner ||
793
850
  // Exclude overlapping objects that can be tapped at once.
794
851
  (current.deltaTime < 5 &&
795
- (this.previous[0]?.object instanceof osuBase.Slider
796
- ? Math.min(this.previous[0].object.stackedEndPosition.getDistance(current.object.stackedPosition), this.previous[0].object.lazyEndPosition.getDistance(current.object.stackedPosition))
797
- : this.previous[0]?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) <=
852
+ ((actualLast?.object instanceof osuBase.Slider
853
+ ? Math.min(actualLast.object.stackedEndPosition.getDistance(current.object.stackedPosition), actualLast.object.lazyEndPosition.getDistance(current.object.stackedPosition))
854
+ : actualLast?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) ?? Number.POSITIVE_INFINITY) <=
798
855
  2 * current.object.radius)) {
799
856
  return 0;
800
857
  }
@@ -803,8 +860,8 @@ class DroidFlashlight extends DroidSkill {
803
860
  let cumulativeStrainTime = 0;
804
861
  let result = 0;
805
862
  let last = current;
806
- for (let i = 0; i < this.previous.length; ++i) {
807
- const currentObject = this.previous[i];
863
+ for (let i = 0; i < Math.min(current.index, 10); ++i) {
864
+ const currentObject = current.previous(i);
808
865
  if (!(currentObject.object instanceof osuBase.Spinner) &&
809
866
  // Exclude overlapping objects that can be tapped at once.
810
867
  currentObject.deltaTime >= 5) {
@@ -820,7 +877,7 @@ class DroidFlashlight extends DroidSkill {
820
877
  const opacityBonus = 1 +
821
878
  this.maxOpacityBonus *
822
879
  (1.0 -
823
- current.opacityAt(currentObject.startTime, this.isHidden));
880
+ current.opacityAt(currentObject.startTime, isHiddenMod));
824
881
  result +=
825
882
  (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
826
883
  cumulativeStrainTime;
@@ -828,18 +885,34 @@ class DroidFlashlight extends DroidSkill {
828
885
  last = currentObject;
829
886
  }
830
887
  // Additional bonus for Hidden due to there being no approach circles.
831
- if (this.isHidden) {
888
+ if (isHiddenMod) {
832
889
  result *= 1 + this.hiddenBonus;
833
890
  }
834
891
  return Math.pow(smallDistNerf * result, 2);
835
892
  }
893
+ }
894
+
895
+ /**
896
+ * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
897
+ */
898
+ class DroidFlashlight extends DroidSkill {
899
+ skillMultiplier = 0.1;
900
+ strainDecayBase = 0.15;
901
+ reducedSectionCount = 10;
902
+ reducedSectionBaseline = 0.75;
903
+ starsPerDouble = 1.05;
904
+ isHidden;
905
+ constructor(mods) {
906
+ super(mods);
907
+ this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
908
+ }
836
909
  /**
837
910
  * @param current The hitobject to calculate.
838
911
  */
839
912
  strainValueAt(current) {
840
913
  this.currentStrain *= this.strainDecay(current.deltaTime);
841
914
  this.currentStrain +=
842
- this.strainValueOf(current) * this.skillMultiplier;
915
+ DroidFlashlightEvaluator.evaluateDifficultyOf(current, this.isHidden) * this.skillMultiplier;
843
916
  return this.currentStrain;
844
917
  }
845
918
  saveToHitObject(current) {
@@ -847,6 +920,60 @@ class DroidFlashlight extends DroidSkill {
847
920
  }
848
921
  }
849
922
 
923
+ /**
924
+ * An evaluator for calculating speed or tap skill.
925
+ *
926
+ * This class should be considered an "evaluating" class and not persisted.
927
+ */
928
+ class SpeedEvaluator {
929
+ // ~200 1/4 BPM streams
930
+ static minSpeedBonus = 75;
931
+ }
932
+
933
+ /**
934
+ * An evaluator for calculating osu!droid tap skill.
935
+ */
936
+ class DroidTapEvaluator extends SpeedEvaluator {
937
+ /**
938
+ * Evaluates the difficulty of tapping the current object, based on:
939
+ *
940
+ * - time between pressing the previous and current object,
941
+ * - distance between those objects,
942
+ * - and how easily they can be cheesed.
943
+ *
944
+ * @param current The current object.
945
+ * @param greatWindow The great hit window of the current object.
946
+ * @param considerCheesability Whether to consider cheesability.
947
+ */
948
+ static evaluateDifficultyOf(current, greatWindow, considerCheesability) {
949
+ if (current.object instanceof osuBase.Spinner ||
950
+ // Exclude overlapping objects that can be tapped at once.
951
+ current.deltaTime < 5) {
952
+ return 0;
953
+ }
954
+ const prev = current.previous(0);
955
+ let strainTime = current.strainTime;
956
+ if (considerCheesability) {
957
+ const greatWindowFull = greatWindow * 2;
958
+ // Aim to nerf cheesy rhythms (very fast consecutive doubles with large deltatimes between).
959
+ if (prev &&
960
+ strainTime < greatWindowFull &&
961
+ prev.strainTime > strainTime) {
962
+ strainTime = osuBase.Interpolation.lerp(prev.strainTime, strainTime, strainTime / greatWindowFull);
963
+ }
964
+ // Cap deltatime to the OD 300 hitwindow.
965
+ // 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.
966
+ strainTime /= osuBase.MathUtils.clamp(strainTime / greatWindowFull / 0.58, 0.91, 1);
967
+ }
968
+ let speedBonus = 1;
969
+ if (strainTime < this.minSpeedBonus) {
970
+ speedBonus +=
971
+ 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
972
+ }
973
+ return speedBonus / strainTime;
974
+ }
975
+ }
976
+
850
977
  /**
851
978
  * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
852
979
  */
@@ -860,65 +987,25 @@ class DroidTap extends DroidSkill {
860
987
  minSpeedBonus = 75;
861
988
  currentTapStrain = 0;
862
989
  currentOriginalTapStrain = 0;
863
- hitWindow;
990
+ greatWindow;
864
991
  constructor(mods, overallDifficulty) {
865
992
  super(mods);
866
- this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
993
+ this.greatWindow = new osuBase.OsuHitWindow(overallDifficulty).hitWindowFor300();
867
994
  }
868
995
  /**
869
996
  * @param current The hitobject to calculate.
870
997
  */
871
- strainValueOf(current) {
872
- if (current.object instanceof osuBase.Spinner ||
873
- // Exclude overlapping objects that can be tapped at once.
874
- current.deltaTime < 5) {
875
- return 0;
876
- }
877
- let strainTime = current.strainTime;
878
- const greatWindowFull = this.hitWindow.hitWindowFor300() * 2;
879
- // Aim to nerf cheesy rhythms (very fast consecutive doubles with large deltatimes between).
880
- if (this.previous[0] &&
881
- strainTime < greatWindowFull &&
882
- this.previous[0].strainTime > strainTime) {
883
- strainTime = osuBase.Interpolation.lerp(this.previous[0].strainTime, strainTime, strainTime / greatWindowFull);
884
- }
885
- // Cap deltatime to the OD 300 hitwindow.
886
- // 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.
887
- strainTime /= osuBase.MathUtils.clamp(strainTime / greatWindowFull / 0.58, 0.91, 1);
888
- let speedBonus = 1;
889
- if (strainTime < this.minSpeedBonus) {
890
- speedBonus +=
891
- 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
892
- }
893
- let originalSpeedBonus = 1;
894
- if (current.strainTime < this.minSpeedBonus) {
895
- originalSpeedBonus +=
896
- 0.75 *
897
- Math.pow((this.minSpeedBonus - current.strainTime) / 40, 2);
898
- }
998
+ strainValueAt(current) {
899
999
  const decay = this.strainDecay(current.deltaTime);
900
1000
  this.currentTapStrain *= decay;
901
1001
  this.currentTapStrain +=
902
- this.tapStrainOf(speedBonus, strainTime) * this.skillMultiplier;
1002
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, true) * this.skillMultiplier;
903
1003
  this.currentOriginalTapStrain *= decay;
904
1004
  this.currentOriginalTapStrain +=
905
- this.tapStrainOf(originalSpeedBonus, current.strainTime) *
906
- this.skillMultiplier;
1005
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, false) * this.skillMultiplier;
907
1006
  this.currentOriginalTapStrain *= current.rhythmMultiplier;
908
1007
  return this.currentTapStrain * current.rhythmMultiplier;
909
1008
  }
910
- /**
911
- * Calculates the tap strain of a hitobject given a specific speed bonus and strain time.
912
- */
913
- tapStrainOf(speedBonus, strainTime) {
914
- return speedBonus / strainTime;
915
- }
916
- /**
917
- * @param current The hitobject to calculate.
918
- */
919
- strainValueAt(current) {
920
- return this.strainValueOf(current);
921
- }
922
1009
  /**
923
1010
  * @param current The hitobject to save to.
924
1011
  */
@@ -1028,7 +1115,7 @@ class StarRating {
1028
1115
  calculateSkills(...skills) {
1029
1116
  this.objects.slice(1).forEach((h, i) => {
1030
1117
  skills.forEach((skill) => {
1031
- skill.processInternal(h);
1118
+ skill.process(h);
1032
1119
  if (i === this.objects.length - 2) {
1033
1120
  // Don't forget to save the last strain peak, which would otherwise be ignored.
1034
1121
  skill.saveCurrentPeak();
@@ -1055,31 +1142,26 @@ class StarRating {
1055
1142
  }
1056
1143
 
1057
1144
  /**
1058
- * Represents the skill required to properly follow a beatmap's rhythm.
1145
+ * An evaluator for calculating rhythm skill.
1146
+ *
1147
+ * This class should be considered an "evaluating" class and not persisted.
1059
1148
  */
1060
- class DroidRhythm extends DroidSkill {
1061
- historyLength = 32;
1062
- skillMultiplier = 1;
1063
- reducedSectionCount = 5;
1064
- reducedSectionBaseline = 0.75;
1065
- strainDecayBase = 0.3;
1066
- starsPerDouble = 1.75;
1067
- rhythmMultiplier;
1068
- historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1069
- currentRhythm = 1;
1070
- hitWindow;
1071
- constructor(mods, overallDifficulty) {
1072
- super(mods);
1073
- this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1074
- const odScaling = Math.pow(this.hitWindow.overallDifficulty, 2) / 400;
1075
- this.rhythmMultiplier =
1076
- 0.75 +
1077
- (this.hitWindow.overallDifficulty >= 0 ? odScaling : -odScaling);
1078
- }
1149
+ class RhythmEvaluator {
1150
+ static historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1151
+ }
1152
+
1153
+ /**
1154
+ * An evaluator for calculating osu!droid Rhythm skill.
1155
+ */
1156
+ class DroidRhythmEvaluator extends RhythmEvaluator {
1079
1157
  /**
1080
- * Calculates a rhythm multiplier for the difficulty of the tap associated with historic data of the current object.
1158
+ * Calculates a rhythm multiplier for the difficulty of the tap associated
1159
+ * with historic data of the current object.
1160
+ *
1161
+ * @param current The current object.
1162
+ * @param greatWindow The great hit window of the current object.
1081
1163
  */
1082
- calculateRhythmBonus(current) {
1164
+ static evaluateDifficultyOf(current, greatWindow) {
1083
1165
  if (current.object instanceof osuBase.Spinner ||
1084
1166
  // Exclude overlapping objects that can be tapped at once.
1085
1167
  current.deltaTime < 5) {
@@ -1092,8 +1174,18 @@ class DroidRhythm extends DroidSkill {
1092
1174
  let startRatio = 0;
1093
1175
  let firstDeltaSwitch = false;
1094
1176
  let rhythmStart = 0;
1177
+ const historicalNoteCount = Math.min(current.index, 32);
1095
1178
  // Exclude overlapping objects that can be tapped at once.
1096
- const validPrevious = this.previous.filter((v) => v.deltaTime >= 5);
1179
+ const validPrevious = [];
1180
+ for (let i = 0; i < historicalNoteCount; ++i) {
1181
+ const object = current.previous(i);
1182
+ if (!object) {
1183
+ break;
1184
+ }
1185
+ if (object.deltaTime >= 5) {
1186
+ validPrevious.push(object);
1187
+ }
1188
+ }
1097
1189
  while (rhythmStart < validPrevious.length - 2 &&
1098
1190
  current.startTime - validPrevious[rhythmStart].startTime <
1099
1191
  this.historyTimeMax) {
@@ -1114,9 +1206,8 @@ class DroidRhythm extends DroidSkill {
1114
1206
  Math.min(0.5, Math.pow(Math.sin(Math.PI /
1115
1207
  (Math.min(prevDelta, currentDelta) /
1116
1208
  Math.max(prevDelta, currentDelta))), 2));
1117
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) -
1118
- this.hitWindow.hitWindowFor300() * 0.4) /
1119
- (this.hitWindow.hitWindowFor300() * 0.4));
1209
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - greatWindow * 0.4) /
1210
+ (greatWindow * 0.4));
1120
1211
  let effectiveRatio = windowPenalty * currentRatio;
1121
1212
  if (firstDeltaSwitch) {
1122
1213
  if (prevDelta <= 1.25 * currentDelta &&
@@ -1174,10 +1265,39 @@ class DroidRhythm extends DroidSkill {
1174
1265
  islandSize = 1;
1175
1266
  }
1176
1267
  }
1177
- return Math.sqrt(4 + rhythmComplexitySum * this.rhythmMultiplier) / 2;
1268
+ return (Math.sqrt(4 +
1269
+ rhythmComplexitySum *
1270
+ this.calculateRhythmMultiplier(greatWindow)) / 2);
1271
+ }
1272
+ /**
1273
+ * Calculates the rhythm multiplier of a given hit window.
1274
+ *
1275
+ * @param greatWindow The great hit window.
1276
+ */
1277
+ static calculateRhythmMultiplier(greatWindow) {
1278
+ const od = osuBase.OsuHitWindow.hitWindow300ToOD(greatWindow);
1279
+ const odScaling = Math.pow(od, 2) / 400;
1280
+ return 0.75 + (od >= 0 ? odScaling : -odScaling);
1281
+ }
1282
+ }
1283
+
1284
+ /**
1285
+ * Represents the skill required to properly follow a beatmap's rhythm.
1286
+ */
1287
+ class DroidRhythm extends DroidSkill {
1288
+ skillMultiplier = 1;
1289
+ reducedSectionCount = 5;
1290
+ reducedSectionBaseline = 0.75;
1291
+ strainDecayBase = 0.3;
1292
+ starsPerDouble = 1.75;
1293
+ currentRhythm = 1;
1294
+ hitWindow;
1295
+ constructor(mods, overallDifficulty) {
1296
+ super(mods);
1297
+ this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1178
1298
  }
1179
1299
  strainValueAt(current) {
1180
- this.currentRhythm = this.calculateRhythmBonus(current);
1300
+ this.currentRhythm = DroidRhythmEvaluator.evaluateDifficultyOf(current, this.hitWindow.hitWindowFor300());
1181
1301
  this.currentStrain *= this.strainDecay(current.deltaTime);
1182
1302
  this.currentStrain += this.currentRhythm - 1;
1183
1303
  return this.currentStrain;
@@ -1189,32 +1309,30 @@ class DroidRhythm extends DroidSkill {
1189
1309
  }
1190
1310
 
1191
1311
  /**
1192
- * Represents the skill required to read every object in the map.
1312
+ * An evaluator for calculating osu!droid Rhythm skill.
1193
1313
  */
1194
- class DroidVisual extends DroidSkill {
1195
- historyLength = 4;
1196
- starsPerDouble = 1.025;
1197
- reducedSectionCount = 10;
1198
- reducedSectionBaseline = 0.75;
1199
- skillMultiplier = 20;
1200
- strainDecayBase = 0.1;
1201
- preempt;
1202
- isHidden;
1203
- constructor(mods, preempt) {
1204
- super(mods);
1205
- this.preempt = preempt;
1206
- this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1207
- }
1314
+ class DroidVisualEvaluator {
1208
1315
  /**
1209
- * @param current The hitobject to calculate.
1316
+ * Evaluates the difficulty of reading the current object, based on:
1317
+ *
1318
+ * - note density of the current object,
1319
+ * - overlapping factor of the current object,
1320
+ * - the preempt time of the current object,
1321
+ * - the velocity of the current object if it's a slider,
1322
+ * - past objects' velocity if they are sliders,
1323
+ * - and whether the Hidden mod is enabled.
1324
+ *
1325
+ * @param current The current object.
1326
+ * @param isHiddenMod Whether the Hidden mod is enabled.
1210
1327
  */
1211
- strainValueOf(current) {
1328
+ static evaluateDifficultyOf(current, isHiddenMod) {
1329
+ const last = current.previous(0);
1212
1330
  if (current.object instanceof osuBase.Spinner ||
1213
1331
  // Exclude overlapping objects that can be tapped at once.
1214
1332
  (current.deltaTime < 5 &&
1215
- (this.previous[0]?.object instanceof osuBase.Slider
1216
- ? Math.min(this.previous[0].object.stackedEndPosition.getDistance(current.object.stackedPosition), this.previous[0].object.lazyEndPosition.getDistance(current.object.stackedPosition))
1217
- : this.previous[0]?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) <=
1333
+ ((last?.object instanceof osuBase.Slider
1334
+ ? Math.min(last.object.stackedEndPosition.getDistance(current.object.stackedPosition), last.object.lazyEndPosition.getDistance(current.object.stackedPosition))
1335
+ : last?.object.stackedEndPosition.getDistance(current.object.stackedPosition)) ?? Number.POSITIVE_INFINITY) <=
1218
1336
  2 * current.object.radius)) {
1219
1337
  return 0;
1220
1338
  }
@@ -1223,15 +1341,15 @@ class DroidVisual extends DroidSkill {
1223
1341
  let strain = Math.min(20, Math.pow(current.noteDensity, 2)) /
1224
1342
  10 /
1225
1343
  (1 + current.overlappingFactor);
1226
- if (this.isHidden) {
1344
+ if (isHiddenMod) {
1227
1345
  strain +=
1228
1346
  Math.min(25, Math.pow(current.noteDensity, 1.25)) /
1229
1347
  10 /
1230
1348
  (1 + current.overlappingFactor / 1.25);
1231
1349
  }
1232
1350
  // Give bonus for AR higher than 10.33.
1233
- if (this.preempt < 400) {
1234
- strain += Math.pow(400 - this.preempt, 1.3) / 135;
1351
+ if (current.timePreempt < 400) {
1352
+ strain += Math.pow(400 - current.timePreempt, 1.3) / 135;
1235
1353
  }
1236
1354
  if (current.object instanceof osuBase.Slider) {
1237
1355
  const scalingFactor = 50 / current.object.radius;
@@ -1243,8 +1361,8 @@ class DroidVisual extends DroidSkill {
1243
1361
  Math.min(1, current.travelDistance / scalingFactor / 125);
1244
1362
  let cumulativeStrainTime = 0;
1245
1363
  // Reward for velocity changes based on last few sliders.
1246
- for (let i = 0; i < this.previous.length; ++i) {
1247
- const last = this.previous[i];
1364
+ for (let i = 0; i < Math.min(current.index, 4); ++i) {
1365
+ const last = current.previous(i);
1248
1366
  cumulativeStrainTime += last.strainTime;
1249
1367
  if (!(last.object instanceof osuBase.Slider) ||
1250
1368
  // Exclude overlapping objects that can be tapped at once.
@@ -1264,10 +1382,27 @@ class DroidVisual extends DroidSkill {
1264
1382
  }
1265
1383
  return strain;
1266
1384
  }
1385
+ }
1386
+
1387
+ /**
1388
+ * Represents the skill required to read every object in the map.
1389
+ */
1390
+ class DroidVisual extends DroidSkill {
1391
+ starsPerDouble = 1.025;
1392
+ reducedSectionCount = 10;
1393
+ reducedSectionBaseline = 0.75;
1394
+ skillMultiplier = 20;
1395
+ strainDecayBase = 0.1;
1396
+ isHidden;
1397
+ constructor(mods) {
1398
+ super(mods);
1399
+ this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1400
+ }
1267
1401
  strainValueAt(current) {
1268
1402
  this.currentStrain *= this.strainDecay(current.deltaTime);
1269
1403
  this.currentStrain +=
1270
- this.strainValueOf(current) * this.skillMultiplier;
1404
+ DroidVisualEvaluator.evaluateDifficultyOf(current, this.isHidden) *
1405
+ this.skillMultiplier;
1271
1406
  return this.currentStrain * (1 + (current.rhythmMultiplier - 1) / 5);
1272
1407
  }
1273
1408
  saveToHitObject(current) {
@@ -1372,7 +1507,7 @@ class DroidStarRating extends StarRating {
1372
1507
  * Calculates the visual star rating of the beatmap and stores it in this instance.
1373
1508
  */
1374
1509
  calculateVisual() {
1375
- const visualSkill = new DroidVisual(this.mods, osuBase.MapStats.arToMS(this.stats.ar));
1510
+ const visualSkill = new DroidVisual(this.mods);
1376
1511
  this.calculateSkills(visualSkill);
1377
1512
  this.postCalculateVisual(visualSkill);
1378
1513
  }
@@ -1447,7 +1582,7 @@ class DroidStarRating extends StarRating {
1447
1582
  new DroidRhythm(this.mods, this.stats.od),
1448
1583
  new DroidTap(this.mods, this.stats.od),
1449
1584
  new DroidFlashlight(this.mods),
1450
- new DroidVisual(this.mods, osuBase.MapStats.arToMS(this.stats.ar)),
1585
+ new DroidVisual(this.mods),
1451
1586
  ];
1452
1587
  }
1453
1588
  /**
@@ -1872,9 +2007,7 @@ class OsuSkill extends StrainSkill {
1872
2007
  difficultyValue() {
1873
2008
  const sortedStrains = this.strainPeaks
1874
2009
  .slice()
1875
- .sort((a, b) => {
1876
- return b - a;
1877
- });
2010
+ .sort((a, b) => b - a);
1878
2011
  // We are reducing the highest strains first to account for extreme difficulty spikes.
1879
2012
  for (let i = 0; i < Math.min(sortedStrains.length, this.reducedSectionCount); ++i) {
1880
2013
  const scale = Math.log10(osuBase.Interpolation.lerp(1, 10, osuBase.MathUtils.clamp(i / this.reducedSectionCount, 0, 1)));
@@ -1882,9 +2015,7 @@ class OsuSkill extends StrainSkill {
1882
2015
  }
1883
2016
  // Difficulty is the weighted sum of the highest strains from every section.
1884
2017
  // We're sorting from highest to lowest strain.
1885
- sortedStrains.sort((a, b) => {
1886
- return b - a;
1887
- });
2018
+ sortedStrains.sort((a, b) => b - a);
1888
2019
  let difficulty = 0;
1889
2020
  let weight = 1;
1890
2021
  for (const strain of sortedStrains) {
@@ -1900,39 +2031,32 @@ class OsuSkill extends StrainSkill {
1900
2031
  }
1901
2032
 
1902
2033
  /**
1903
- * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
2034
+ * An evaluator for calculating osu!standard Aim skill.
1904
2035
  */
1905
- class OsuAim extends OsuSkill {
1906
- skillMultiplier = 23.25;
1907
- strainDecayBase = 0.15;
1908
- reducedSectionCount = 10;
1909
- reducedSectionBaseline = 0.75;
1910
- difficultyMultiplier = 1.06;
1911
- decayWeight = 0.9;
1912
- wideAngleMultiplier = 1.5;
1913
- acuteAngleMultiplier = 2;
1914
- sliderMultiplier = 1.5;
1915
- velocityChangeMultiplier = 0.75;
1916
- withSliders;
1917
- constructor(mods, withSliders) {
1918
- super(mods);
1919
- this.withSliders = withSliders;
1920
- }
2036
+ class OsuAimEvaluator extends AimEvaluator {
1921
2037
  /**
1922
- * @param current The hitobject to calculate.
2038
+ * Evaluates the difficulty of aiming the current object, based on:
2039
+ *
2040
+ * - cursor velocity to the current object,
2041
+ * - angle difficulty,
2042
+ * - sharp velocity increases,
2043
+ * - and slider difficulty.
2044
+ *
2045
+ * @param current The current object.
2046
+ * @param withSliders Whether to take slider difficulty into account.
1923
2047
  */
1924
- strainValueOf(current) {
2048
+ static evaluateDifficultyOf(current, withSliders) {
2049
+ const last = current.previous(0);
1925
2050
  if (current.object instanceof osuBase.Spinner ||
1926
- this.previous.length <= 1 ||
1927
- this.previous[0].object instanceof osuBase.Spinner) {
2051
+ current.index <= 1 ||
2052
+ last?.object instanceof osuBase.Spinner) {
1928
2053
  return 0;
1929
2054
  }
1930
- const last = this.previous[0];
1931
- const lastLast = this.previous[1];
2055
+ const lastLast = current.previous(1);
1932
2056
  // Calculate the velocity to the current hitobject, which starts with a base distance / time assuming the last object is a hitcircle.
1933
2057
  let currentVelocity = current.lazyJumpDistance / current.strainTime;
1934
2058
  // But if the last object is a slider, then we extend the travel velocity through the slider into the current object.
1935
- if (last.object instanceof osuBase.Slider && this.withSliders) {
2059
+ if (last.object instanceof osuBase.Slider && withSliders) {
1936
2060
  // Calculate the slider velocity from slider head to slider end.
1937
2061
  const travelVelocity = last.travelDistance / last.travelTime;
1938
2062
  // Calculate the movement velocity from slider end to current object.
@@ -1942,7 +2066,7 @@ class OsuAim extends OsuSkill {
1942
2066
  }
1943
2067
  // As above, do the same for the previous hitobject.
1944
2068
  let prevVelocity = last.lazyJumpDistance / last.strainTime;
1945
- if (lastLast.object instanceof osuBase.Slider && this.withSliders) {
2069
+ if (lastLast.object instanceof osuBase.Slider && withSliders) {
1946
2070
  const travelVelocity = lastLast.travelDistance / lastLast.travelTime;
1947
2071
  const movementVelocity = last.minimumJumpDistance / last.minimumJumpTime;
1948
2072
  prevVelocity = Math.max(prevVelocity, movementVelocity + travelVelocity);
@@ -2029,18 +2153,36 @@ class OsuAim extends OsuSkill {
2029
2153
  strain += Math.max(acuteAngleBonus * this.acuteAngleMultiplier, wideAngleBonus * this.wideAngleMultiplier +
2030
2154
  velocityChangeBonus * this.velocityChangeMultiplier);
2031
2155
  // Add in additional slider velocity bonus.
2032
- if (this.withSliders) {
2156
+ if (withSliders) {
2033
2157
  strain += sliderBonus * this.sliderMultiplier;
2034
2158
  }
2035
2159
  return strain;
2036
2160
  }
2161
+ }
2162
+
2163
+ /**
2164
+ * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
2165
+ */
2166
+ class OsuAim extends OsuSkill {
2167
+ skillMultiplier = 23.25;
2168
+ strainDecayBase = 0.15;
2169
+ reducedSectionCount = 10;
2170
+ reducedSectionBaseline = 0.75;
2171
+ difficultyMultiplier = 1.06;
2172
+ decayWeight = 0.9;
2173
+ withSliders;
2174
+ constructor(mods, withSliders) {
2175
+ super(mods);
2176
+ this.withSliders = withSliders;
2177
+ }
2037
2178
  /**
2038
2179
  * @param current The hitobject to calculate.
2039
2180
  */
2040
2181
  strainValueAt(current) {
2041
2182
  this.currentStrain *= this.strainDecay(current.deltaTime);
2042
2183
  this.currentStrain +=
2043
- this.strainValueOf(current) * this.skillMultiplier;
2184
+ OsuAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
2185
+ this.skillMultiplier;
2044
2186
  return this.currentStrain;
2045
2187
  }
2046
2188
  /**
@@ -2054,63 +2196,39 @@ class OsuAim extends OsuSkill {
2054
2196
  current.aimStrainWithoutSliders = this.currentStrain;
2055
2197
  }
2056
2198
  }
2057
- /**
2058
- * Calculates the bonus of wide angles.
2059
- */
2060
- calculateWideAngleBonus(angle) {
2061
- return Math.pow(Math.sin((3 / 4) *
2062
- (Math.min((5 / 6) * Math.PI, Math.max(Math.PI / 6, angle)) -
2063
- Math.PI / 6)), 2);
2064
- }
2065
- /**
2066
- * Calculates the bonus of acute angles.
2067
- */
2068
- calculateAcuteAngleBonus(angle) {
2069
- return 1 - this.calculateWideAngleBonus(angle);
2070
- }
2071
2199
  }
2072
2200
 
2073
2201
  /**
2074
- * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
2202
+ * An evaluator for calculating osu!standard speed skill.
2075
2203
  */
2076
- class OsuSpeed extends OsuSkill {
2204
+ class OsuSpeedEvaluator extends SpeedEvaluator {
2077
2205
  /**
2078
2206
  * Spacing threshold for a single hitobject spacing.
2079
2207
  */
2080
- SINGLE_SPACING_THRESHOLD = 125;
2081
- historyLength = 32;
2082
- skillMultiplier = 1375;
2083
- strainDecayBase = 0.3;
2084
- reducedSectionCount = 5;
2085
- reducedSectionBaseline = 0.75;
2086
- difficultyMultiplier = 1.04;
2087
- decayWeight = 0.9;
2088
- rhythmMultiplier = 0.75;
2089
- historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
2090
- currentSpeedStrain = 0;
2091
- currentRhythm = 0;
2092
- // ~200 1/4 BPM streams
2093
- minSpeedBonus = 75;
2094
- greatWindow;
2095
- constructor(mods, greatWindow) {
2096
- super(mods);
2097
- this.greatWindow = greatWindow;
2098
- }
2208
+ static SINGLE_SPACING_THRESHOLD = 125;
2099
2209
  /**
2100
- * @param current The hitobject to calculate.
2210
+ * Evaluates the difficulty of tapping the current object, based on:
2211
+ *
2212
+ * - time between pressing the previous and current object,
2213
+ * - distance between those objects,
2214
+ * - and how easily they can be cheesed.
2215
+ *
2216
+ * @param current The current object.
2217
+ * @param greatWindow The great hit window of the current object.
2101
2218
  */
2102
- strainValueOf(current) {
2219
+ static evaluateDifficultyOf(current, greatWindow) {
2103
2220
  if (current.object instanceof osuBase.Spinner) {
2104
2221
  return 0;
2105
2222
  }
2223
+ const prev = current.previous(0);
2106
2224
  let strainTime = current.strainTime;
2107
- const greatWindowFull = this.greatWindow * 2;
2225
+ const greatWindowFull = greatWindow * 2;
2108
2226
  const speedWindowRatio = strainTime / greatWindowFull;
2109
2227
  // Aim to nerf cheesy rhythms (very fast consecutive doubles with large deltatimes between).
2110
- if (this.previous[0] &&
2228
+ if (prev &&
2111
2229
  strainTime < greatWindowFull &&
2112
- this.previous[0].strainTime > strainTime) {
2113
- strainTime = osuBase.Interpolation.lerp(this.previous[0].strainTime, strainTime, speedWindowRatio);
2230
+ prev.strainTime > strainTime) {
2231
+ strainTime = osuBase.Interpolation.lerp(prev.strainTime, strainTime, speedWindowRatio);
2114
2232
  }
2115
2233
  // Cap deltatime to the OD 300 hitwindow.
2116
2234
  // 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.
@@ -2120,27 +2238,28 @@ class OsuSpeed extends OsuSkill {
2120
2238
  speedBonus +=
2121
2239
  0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
2122
2240
  }
2123
- const travelDistance = this.previous[0]?.travelDistance ?? 0;
2241
+ const travelDistance = prev?.travelDistance ?? 0;
2124
2242
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
2125
2243
  return ((speedBonus +
2126
2244
  speedBonus *
2127
2245
  Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.5)) /
2128
2246
  strainTime);
2129
2247
  }
2248
+ }
2249
+
2250
+ /**
2251
+ * An evaluator for calculating osu!standard Rhythm skill.
2252
+ */
2253
+ class OsuRhythmEvaluator extends RhythmEvaluator {
2254
+ static rhythmMultiplier = 0.75;
2130
2255
  /**
2131
- * @param current The hitobject to calculate.
2132
- */
2133
- strainValueAt(current) {
2134
- this.currentSpeedStrain *= this.strainDecay(current.deltaTime);
2135
- this.currentSpeedStrain +=
2136
- this.strainValueOf(current) * this.skillMultiplier;
2137
- this.currentRhythm = this.calculateRhythmBonus(current);
2138
- return this.currentSpeedStrain * this.currentRhythm;
2139
- }
2140
- /**
2141
- * Calculates a rhythm multiplier for the difficulty of the tap associated with historic data of the current object.
2256
+ * Calculates a rhythm multiplier for the difficulty of the tap associated
2257
+ * with historic data of the current object.
2258
+ *
2259
+ * @param current The current object.
2260
+ * @param greatWindow The great hit window of the current object.
2142
2261
  */
2143
- calculateRhythmBonus(current) {
2262
+ static evaluateDifficultyOf(current, greatWindow) {
2144
2263
  if (current.object instanceof osuBase.Spinner) {
2145
2264
  return 0;
2146
2265
  }
@@ -2150,29 +2269,33 @@ class OsuSpeed extends OsuSkill {
2150
2269
  // Store the ratio of the current start of an island to buff for tighter rhythms.
2151
2270
  let startRatio = 0;
2152
2271
  let firstDeltaSwitch = false;
2272
+ const historicalNoteCount = Math.min(current.index, 32);
2153
2273
  let rhythmStart = 0;
2154
- while (rhythmStart < this.previous.length - 2 &&
2155
- current.startTime - this.previous[rhythmStart].startTime <
2274
+ while (rhythmStart < historicalNoteCount - 2 &&
2275
+ current.startTime - current.previous(rhythmStart).startTime <
2156
2276
  this.historyTimeMax) {
2157
2277
  ++rhythmStart;
2158
2278
  }
2159
2279
  for (let i = rhythmStart; i > 0; --i) {
2280
+ const currentObject = current.previous(i - 1);
2281
+ const prevObject = current.previous(i);
2282
+ const lastObject = current.previous(i + 1);
2160
2283
  // Scale note 0 to 1 from history to now.
2161
2284
  let currentHistoricalDecay = (this.historyTimeMax -
2162
- (current.startTime - this.previous[i - 1].startTime)) /
2285
+ (current.startTime - currentObject.startTime)) /
2163
2286
  this.historyTimeMax;
2164
2287
  // Either we're limited by time or limited by object count.
2165
- currentHistoricalDecay = Math.min(currentHistoricalDecay, (this.previous.length - i) / this.previous.length);
2166
- const currentDelta = this.previous[i - 1].strainTime;
2167
- const prevDelta = this.previous[i].strainTime;
2168
- const lastDelta = this.previous[i + 1].strainTime;
2288
+ currentHistoricalDecay = Math.min(currentHistoricalDecay, (historicalNoteCount - i) / historicalNoteCount);
2289
+ const currentDelta = currentObject.strainTime;
2290
+ const prevDelta = prevObject.strainTime;
2291
+ const lastDelta = lastObject.strainTime;
2169
2292
  const currentRatio = 1 +
2170
2293
  6 *
2171
2294
  Math.min(0.5, Math.pow(Math.sin(Math.PI /
2172
2295
  (Math.min(prevDelta, currentDelta) /
2173
2296
  Math.max(prevDelta, currentDelta))), 2));
2174
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - this.greatWindow * 0.6) /
2175
- (this.greatWindow * 0.6));
2297
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - greatWindow * 0.6) /
2298
+ (greatWindow * 0.6));
2176
2299
  let effectiveRatio = windowPenalty * currentRatio;
2177
2300
  if (firstDeltaSwitch) {
2178
2301
  if (prevDelta <= 1.25 * currentDelta &&
@@ -2183,11 +2306,11 @@ class OsuSpeed extends OsuSkill {
2183
2306
  }
2184
2307
  }
2185
2308
  else {
2186
- if (this.previous[i - 1].object instanceof osuBase.Slider) {
2309
+ if (currentObject.object instanceof osuBase.Slider) {
2187
2310
  // BPM change is into slider, this is easy acc window.
2188
2311
  effectiveRatio /= 8;
2189
2312
  }
2190
- if (this.previous[i].object instanceof osuBase.Slider) {
2313
+ if (prevObject.object instanceof osuBase.Slider) {
2191
2314
  // BPM change was from a slider, this is typically easier than circle -> circle.
2192
2315
  effectiveRatio /= 4;
2193
2316
  }
@@ -2232,6 +2355,38 @@ class OsuSpeed extends OsuSkill {
2232
2355
  }
2233
2356
  return Math.sqrt(4 + rhythmComplexitySum * this.rhythmMultiplier) / 2;
2234
2357
  }
2358
+ }
2359
+
2360
+ /**
2361
+ * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
2362
+ */
2363
+ class OsuSpeed extends OsuSkill {
2364
+ skillMultiplier = 1375;
2365
+ strainDecayBase = 0.3;
2366
+ reducedSectionCount = 5;
2367
+ reducedSectionBaseline = 0.75;
2368
+ difficultyMultiplier = 1.04;
2369
+ decayWeight = 0.9;
2370
+ currentSpeedStrain = 0;
2371
+ currentRhythm = 0;
2372
+ // ~200 1/4 BPM streams
2373
+ minSpeedBonus = 75;
2374
+ greatWindow;
2375
+ constructor(mods, greatWindow) {
2376
+ super(mods);
2377
+ this.greatWindow = greatWindow;
2378
+ }
2379
+ /**
2380
+ * @param current The hitobject to calculate.
2381
+ */
2382
+ strainValueAt(current) {
2383
+ this.currentSpeedStrain *= this.strainDecay(current.deltaTime);
2384
+ this.currentSpeedStrain +=
2385
+ OsuSpeedEvaluator.evaluateDifficultyOf(current, this.greatWindow) *
2386
+ this.skillMultiplier;
2387
+ this.currentRhythm = OsuRhythmEvaluator.evaluateDifficultyOf(current, this.greatWindow);
2388
+ return this.currentSpeedStrain * this.currentRhythm;
2389
+ }
2235
2390
  /**
2236
2391
  * @param current The hitobject to save to.
2237
2392
  */
@@ -2242,24 +2397,20 @@ class OsuSpeed extends OsuSkill {
2242
2397
  }
2243
2398
 
2244
2399
  /**
2245
- * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
2400
+ * An evaluator for calculating osu!standard Flashlight skill.
2246
2401
  */
2247
- class OsuFlashlight extends OsuSkill {
2248
- historyLength = 10;
2249
- skillMultiplier = 0.05;
2250
- strainDecayBase = 0.15;
2251
- reducedSectionCount = 10;
2252
- reducedSectionBaseline = 0.75;
2253
- difficultyMultiplier = 1.06;
2254
- decayWeight = 1;
2255
- maxOpacityBonus = 0.4;
2256
- hiddenBonus = 0.2;
2257
- isHidden;
2258
- constructor(mods) {
2259
- super(mods);
2260
- this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
2261
- }
2262
- strainValueOf(current) {
2402
+ class OsuFlashlightEvaluator extends FlashlightEvaluator {
2403
+ /**
2404
+ * Evaluates the difficulty of memorizing and hitting the current object, based on:
2405
+ *
2406
+ * - distance between the previous and the current object,
2407
+ * - the visual opacity of the current object,
2408
+ * - and whether Hidden mod is enabled.
2409
+ *
2410
+ * @param current The current object.
2411
+ * @param isHiddenMod Whether the Hidden mod is enabled.
2412
+ */
2413
+ static evaluateDifficultyOf(current, isHiddenMod) {
2263
2414
  if (current.object instanceof osuBase.Spinner) {
2264
2415
  return 0;
2265
2416
  }
@@ -2268,8 +2419,8 @@ class OsuFlashlight extends OsuSkill {
2268
2419
  let cumulativeStrainTime = 0;
2269
2420
  let result = 0;
2270
2421
  let last = current;
2271
- for (let i = 0; i < this.previous.length; ++i) {
2272
- const currentObject = this.previous[i];
2422
+ for (let i = 0; i < Math.min(current.index, 10); ++i) {
2423
+ const currentObject = current.previous(i);
2273
2424
  if (!(currentObject.object instanceof osuBase.Spinner)) {
2274
2425
  const jumpDistance = current.object.stackedPosition.subtract(currentObject.object.endPosition).length;
2275
2426
  cumulativeStrainTime += last.strainTime;
@@ -2283,7 +2434,7 @@ class OsuFlashlight extends OsuSkill {
2283
2434
  const opacityBonus = 1 +
2284
2435
  this.maxOpacityBonus *
2285
2436
  (1.0 -
2286
- current.opacityAt(currentObject.startTime, this.isHidden));
2437
+ current.opacityAt(currentObject.startTime, isHiddenMod));
2287
2438
  result +=
2288
2439
  (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
2289
2440
  cumulativeStrainTime;
@@ -2291,18 +2442,35 @@ class OsuFlashlight extends OsuSkill {
2291
2442
  last = currentObject;
2292
2443
  }
2293
2444
  // Additional bonus for Hidden due to there being no approach circles.
2294
- if (this.isHidden) {
2445
+ if (isHiddenMod) {
2295
2446
  result *= 1 + this.hiddenBonus;
2296
2447
  }
2297
2448
  return Math.pow(smallDistNerf * result, 2);
2298
2449
  }
2450
+ }
2451
+
2452
+ /**
2453
+ * Represents the skill required to memorize and hit every object in a beatmap with the Flashlight mod enabled.
2454
+ */
2455
+ class OsuFlashlight extends OsuSkill {
2456
+ skillMultiplier = 0.05;
2457
+ strainDecayBase = 0.15;
2458
+ reducedSectionCount = 10;
2459
+ reducedSectionBaseline = 0.75;
2460
+ difficultyMultiplier = 1.06;
2461
+ decayWeight = 1;
2462
+ isHidden;
2463
+ constructor(mods) {
2464
+ super(mods);
2465
+ this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
2466
+ }
2299
2467
  /**
2300
2468
  * @param current The hitobject to calculate.
2301
2469
  */
2302
2470
  strainValueAt(current) {
2303
2471
  this.currentStrain *= this.strainDecay(current.deltaTime);
2304
2472
  this.currentStrain +=
2305
- this.strainValueOf(current) * this.skillMultiplier;
2473
+ OsuFlashlightEvaluator.evaluateDifficultyOf(current, this.isHidden) * this.skillMultiplier;
2306
2474
  return this.currentStrain;
2307
2475
  }
2308
2476
  saveToHitObject(current) {
@@ -2715,21 +2883,34 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2715
2883
  }
2716
2884
  }
2717
2885
 
2886
+ exports.AimEvaluator = AimEvaluator;
2718
2887
  exports.DifficultyHitObject = DifficultyHitObject;
2719
2888
  exports.DifficultyHitObjectCreator = DifficultyHitObjectCreator;
2720
2889
  exports.DroidAim = DroidAim;
2890
+ exports.DroidAimEvaluator = DroidAimEvaluator;
2721
2891
  exports.DroidFlashlight = DroidFlashlight;
2892
+ exports.DroidFlashlightEvaluator = DroidFlashlightEvaluator;
2722
2893
  exports.DroidPerformanceCalculator = DroidPerformanceCalculator;
2723
2894
  exports.DroidRhythm = DroidRhythm;
2895
+ exports.DroidRhythmEvaluator = DroidRhythmEvaluator;
2724
2896
  exports.DroidStarRating = DroidStarRating;
2725
2897
  exports.DroidTap = DroidTap;
2898
+ exports.DroidTapEvaluator = DroidTapEvaluator;
2726
2899
  exports.DroidVisual = DroidVisual;
2900
+ exports.DroidVisualEvaluator = DroidVisualEvaluator;
2901
+ exports.FlashlightEvaluator = FlashlightEvaluator;
2727
2902
  exports.MapStars = MapStars;
2728
2903
  exports.OsuAim = OsuAim;
2904
+ exports.OsuAimEvaluator = OsuAimEvaluator;
2729
2905
  exports.OsuFlashlight = OsuFlashlight;
2906
+ exports.OsuFlashlightEvaluator = OsuFlashlightEvaluator;
2730
2907
  exports.OsuPerformanceCalculator = OsuPerformanceCalculator;
2908
+ exports.OsuRhythmEvaluator = OsuRhythmEvaluator;
2731
2909
  exports.OsuSpeed = OsuSpeed;
2910
+ exports.OsuSpeedEvaluator = OsuSpeedEvaluator;
2732
2911
  exports.OsuStarRating = OsuStarRating;
2733
2912
  exports.PerformanceCalculator = PerformanceCalculator;
2913
+ exports.RhythmEvaluator = RhythmEvaluator;
2914
+ exports.SpeedEvaluator = SpeedEvaluator;
2734
2915
  exports.StarRating = StarRating;
2735
2916
  //# sourceMappingURL=index.js.map