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

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,183 +503,190 @@ 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.
573
- const movementVelocity = current.minimumJumpDistance / current.minimumJumpTime;
687
+ const movementVelocity = current.minimumJumpTime !== 0
688
+ ? current.minimumJumpDistance / current.minimumJumpTime
689
+ : 0;
574
690
  // Take the larger total combined velocity.
575
691
  currentVelocity = Math.max(currentVelocity, movementVelocity + travelVelocity);
576
692
  }
@@ -578,9 +694,11 @@ class DroidAim extends DroidSkill {
578
694
  let prevVelocity = last.lazyJumpDistance / last.strainTime;
579
695
  if (lastLast.object instanceof osuBase.Slider &&
580
696
  lastLast.object.ticks > 0 &&
581
- this.withSliders) {
697
+ withSliders) {
582
698
  const travelVelocity = lastLast.travelDistance / lastLast.travelTime;
583
- const movementVelocity = last.minimumJumpDistance / last.minimumJumpTime;
699
+ const movementVelocity = last.minimumJumpTime !== 0
700
+ ? last.minimumJumpDistance / last.minimumJumpTime
701
+ : 0;
584
702
  prevVelocity = Math.max(prevVelocity, movementVelocity + travelVelocity);
585
703
  }
586
704
  let wideAngleBonus = 0;
@@ -665,7 +783,7 @@ class DroidAim extends DroidSkill {
665
783
  strain += Math.max(acuteAngleBonus * this.acuteAngleMultiplier, wideAngleBonus * this.wideAngleMultiplier +
666
784
  velocityChangeBonus * this.velocityChangeMultiplier);
667
785
  // Add in additional slider velocity bonus.
668
- if (this.withSliders) {
786
+ if (withSliders) {
669
787
  strain += sliderBonus * this.sliderMultiplier;
670
788
  }
671
789
  return strain;
@@ -673,93 +791,145 @@ class DroidAim extends DroidSkill {
673
791
  /**
674
792
  * Calculates the movement strain of a hitobject.
675
793
  */
676
- movementStrainOf(current) {
794
+ static movementStrainOf(current) {
677
795
  let speedBonus = 1;
678
796
  if (current.strainTime < this.minSpeedBonus) {
679
797
  speedBonus +=
680
798
  0.75 *
681
799
  Math.pow((this.minSpeedBonus - current.strainTime) / 45, 2);
682
800
  }
683
- const travelDistance = this.previous[0]?.travelDistance ?? 0;
801
+ const travelDistance = current.previous(0)?.travelDistance ?? 0;
684
802
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
685
803
  return ((50 *
686
804
  speedBonus *
687
805
  Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 5)) /
688
806
  current.strainTime);
689
807
  }
808
+ }
809
+
810
+ /**
811
+ * A bare minimal abstract skill for fully custom skill implementations.
812
+ */
813
+ class Skill {
690
814
  /**
691
- * @param current The hitobject to calculate.
815
+ * The mods that this skill processes.
692
816
  */
693
- strainValueAt(current) {
694
- this.currentStrain *= this.strainDecay(current.deltaTime);
695
- this.currentStrain +=
696
- this.strainValueOf(current) * this.skillMultiplier;
697
- return this.currentStrain;
817
+ mods;
818
+ constructor(mods) {
819
+ this.mods = mods;
698
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 {
699
828
  /**
700
- * @param current The hitobject to save to.
829
+ * The strain of currently calculated hitobject.
701
830
  */
702
- saveToHitObject(current) {
703
- if (this.withSliders) {
704
- current.aimStrainWithSliders = this.currentStrain;
705
- }
706
- else {
707
- current.aimStrainWithoutSliders = this.currentStrain;
708
- }
709
- }
831
+ currentStrain = 0;
710
832
  /**
711
- * Calculates the bonus of wide angles.
833
+ * The current section's strain peak.
712
834
  */
713
- calculateWideAngleBonus(angle) {
714
- return Math.pow(Math.sin((3 / 4) *
715
- (Math.min((5 / 6) * Math.PI, Math.max(Math.PI / 6, angle)) -
716
- Math.PI / 6)), 2);
835
+ currentSectionPeak = 0;
836
+ /**
837
+ * Strain peaks are stored here.
838
+ */
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);
717
865
  }
718
866
  /**
719
- * Calculates the bonus of acute angles.
867
+ * Saves the current peak strain level to the list of strain peaks, which will be used to calculate an overall difficulty.
720
868
  */
721
- calculateAcuteAngleBonus(angle) {
722
- return 1 - this.calculateWideAngleBonus(angle);
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);
723
892
  }
724
893
  }
725
894
 
726
895
  /**
727
- * 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.
728
898
  */
729
- class DroidFlashlight extends DroidSkill {
730
- historyLength = 10;
731
- 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;
732
925
  strainDecayBase = 0.15;
733
926
  reducedSectionCount = 10;
734
927
  reducedSectionBaseline = 0.75;
735
928
  starsPerDouble = 1.05;
736
- strainValueOf(current) {
737
- if (current.object instanceof osuBase.Spinner) {
738
- return 0;
739
- }
740
- const scalingFactor = 52 / current.object.radius;
741
- let smallDistNerf = 1;
742
- let cumulativeStrainTime = 0;
743
- let result = 0;
744
- let last = current;
745
- for (let i = 0; i < this.previous.length; ++i) {
746
- const currentObject = this.previous[i];
747
- if (!(currentObject.object instanceof osuBase.Spinner)) {
748
- const jumpDistance = current.object.stackedPosition.subtract(currentObject.object.endPosition).length;
749
- cumulativeStrainTime += last.strainTime;
750
- // We want to nerf objects that can be easily seen within the Flashlight circle radius.
751
- if (i === 0) {
752
- smallDistNerf = Math.min(1, jumpDistance / 75);
753
- }
754
- // We also want to nerf stacks so that only the first object of the stack is accounted for.
755
- const stackNerf = Math.min(1, currentObject.lazyJumpDistance / scalingFactor / 25);
756
- result +=
757
- (stackNerf * scalingFactor * jumpDistance) /
758
- cumulativeStrainTime;
759
- }
760
- last = currentObject;
761
- }
762
- return Math.pow(smallDistNerf * result, 2);
929
+ withSliders;
930
+ constructor(mods, withSliders) {
931
+ super(mods);
932
+ this.withSliders = withSliders;
763
933
  }
764
934
  /**
765
935
  * @param current The hitobject to calculate.
@@ -767,11 +937,79 @@ class DroidFlashlight extends DroidSkill {
767
937
  strainValueAt(current) {
768
938
  this.currentStrain *= this.strainDecay(current.deltaTime);
769
939
  this.currentStrain +=
770
- this.strainValueOf(current) * this.skillMultiplier;
940
+ DroidAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
941
+ this.skillMultiplier;
771
942
  return this.currentStrain;
772
943
  }
944
+ /**
945
+ * @param current The hitobject to save to.
946
+ */
773
947
  saveToHitObject(current) {
774
- 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;
775
1013
  }
776
1014
  }
777
1015
 
@@ -788,63 +1026,25 @@ class DroidTap extends DroidSkill {
788
1026
  minSpeedBonus = 75;
789
1027
  currentTapStrain = 0;
790
1028
  currentOriginalTapStrain = 0;
791
- hitWindow;
1029
+ greatWindow;
792
1030
  constructor(mods, overallDifficulty) {
793
1031
  super(mods);
794
- this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1032
+ this.greatWindow = new osuBase.OsuHitWindow(overallDifficulty).hitWindowFor300();
795
1033
  }
796
1034
  /**
797
1035
  * @param current The hitobject to calculate.
798
1036
  */
799
- strainValueOf(current) {
800
- if (current.object instanceof osuBase.Spinner) {
801
- return 0;
802
- }
803
- let strainTime = current.strainTime;
804
- const greatWindowFull = this.hitWindow.hitWindowFor300() * 2;
805
- // Aim to nerf cheesy rhythms (very fast consecutive doubles with large deltatimes between).
806
- if (this.previous[0] &&
807
- strainTime < greatWindowFull &&
808
- this.previous[0].strainTime > strainTime) {
809
- strainTime = osuBase.Interpolation.lerp(this.previous[0].strainTime, strainTime, strainTime / greatWindowFull);
810
- }
811
- // Cap deltatime to the OD 300 hitwindow.
812
- // 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.
813
- strainTime /= osuBase.MathUtils.clamp(strainTime / greatWindowFull / 0.58, 0.91, 1);
814
- let speedBonus = 1;
815
- if (strainTime < this.minSpeedBonus) {
816
- speedBonus +=
817
- 0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
818
- }
819
- let originalSpeedBonus = 1;
820
- if (current.strainTime < this.minSpeedBonus) {
821
- originalSpeedBonus +=
822
- 0.75 *
823
- Math.pow((this.minSpeedBonus - current.strainTime) / 40, 2);
824
- }
825
- const decay = this.strainDecay(current.deltaTime);
1037
+ strainValueAt(current) {
1038
+ const decay = this.strainDecay(current.strainTime);
826
1039
  this.currentTapStrain *= decay;
827
1040
  this.currentTapStrain +=
828
- this.tapStrainOf(speedBonus, strainTime) * this.skillMultiplier;
1041
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, true) * this.skillMultiplier;
829
1042
  this.currentOriginalTapStrain *= decay;
830
1043
  this.currentOriginalTapStrain +=
831
- this.tapStrainOf(originalSpeedBonus, current.strainTime) *
832
- this.skillMultiplier;
1044
+ DroidTapEvaluator.evaluateDifficultyOf(current, this.greatWindow, false) * this.skillMultiplier;
833
1045
  this.currentOriginalTapStrain *= current.rhythmMultiplier;
834
1046
  return this.currentTapStrain * current.rhythmMultiplier;
835
1047
  }
836
- /**
837
- * Calculates the tap strain of a hitobject given a specific speed bonus and strain time.
838
- */
839
- tapStrainOf(speedBonus, strainTime) {
840
- return speedBonus / strainTime;
841
- }
842
- /**
843
- * @param current The hitobject to calculate.
844
- */
845
- strainValueAt(current) {
846
- return this.strainValueOf(current);
847
- }
848
1048
  /**
849
1049
  * @param current The hitobject to save to.
850
1050
  */
@@ -855,158 +1055,129 @@ class DroidTap extends DroidSkill {
855
1055
  }
856
1056
 
857
1057
  /**
858
- * 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.
859
1061
  */
860
- class StarRating {
861
- /**
862
- * The calculated beatmap.
863
- */
864
- map = new osuBase.Beatmap();
865
- /**
866
- * The difficulty objects of the beatmap.
867
- */
868
- objects = [];
869
- /**
870
- * The modifications applied.
871
- */
872
- mods = [];
873
- /**
874
- * The total star rating of the beatmap.
875
- */
876
- total = 0;
877
- /**
878
- * The map statistics of the beatmap after modifications are applied.
879
- */
880
- stats = new osuBase.MapStats();
881
- /**
882
- * The strain peaks of various calculated difficulties.
883
- */
884
- strainPeaks = {
885
- aimWithSliders: [],
886
- aimWithoutSliders: [],
887
- speed: [],
888
- flashlight: [],
889
- };
890
- /**
891
- * Additional data that is used in performance calculation.
892
- */
893
- attributes = {
894
- speedNoteCount: 0,
895
- sliderFactor: 1,
896
- aimDifficultStrainCount: 0,
897
- speedDifficultStrainCount: 0,
898
- };
899
- sectionLength = 400;
900
- /**
901
- * Calculates the star rating of the specified beatmap.
902
- *
903
- * The beatmap is analyzed in chunks of `sectionLength` duration.
904
- * For each chunk the highest hitobject strains are added to
905
- * a list which is then collapsed into a weighted sum, much
906
- * like scores are weighted on a user's profile.
907
- *
908
- * For subsequent chunks, the initial max strain is calculated
909
- * by decaying the previous hitobject's strain until the
910
- * beginning of the new chunk.
911
- *
912
- * The first object doesn't generate a strain
913
- * so we begin calculating from the second object.
914
- *
915
- * Also don't forget to manually add the peak strain for the last
916
- * section which would otherwise be ignored.
917
- */
918
- calculate(params, mode) {
919
- const map = (this.map = osuBase.Utils.deepCopy(params.map));
920
- const mod = (this.mods = params.mods ?? this.mods);
921
- this.stats = new osuBase.MapStats({
922
- cs: map.difficulty.cs,
923
- ar: map.difficulty.ar,
924
- od: map.difficulty.od,
925
- hp: map.difficulty.hp,
926
- mods: mod,
927
- speedMultiplier: params.stats?.speedMultiplier ?? 1,
928
- oldStatistics: params.stats?.oldStatistics ?? false,
929
- }).calculate({ mode: mode });
930
- this.generateDifficultyHitObjects(mode);
931
- this.calculateAll();
932
- return this;
933
- }
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 {
934
1071
  /**
935
- * Generates difficulty hitobjects for this calculator.
1072
+ * Evaluates the difficulty of memorizing and hitting the current object, based on:
936
1073
  *
937
- * @param mode The gamemode to generate difficulty hitobjects for.
938
- */
939
- generateDifficultyHitObjects(mode) {
940
- this.objects.length = 0;
941
- this.objects.push(...new DifficultyHitObjectCreator().generateDifficultyObjects({
942
- objects: this.map.hitObjects.objects,
943
- circleSize: this.stats.cs,
944
- speedMultiplier: this.stats.speedMultiplier,
945
- mode: mode,
946
- preempt: osuBase.MapStats.arToMS(this.stats.ar),
947
- }));
948
- }
949
- /**
950
- * 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.
951
1077
  *
952
- * @param skills The skills to calculate.
1078
+ * @param current The current object.
1079
+ * @param isHiddenMod Whether the Hidden mod is enabled.
953
1080
  */
954
- calculateSkills(...skills) {
955
- this.objects.slice(1).forEach((h, i) => {
956
- skills.forEach((skill) => {
957
- skill.processInternal(h);
958
- if (i === this.objects.length - 2) {
959
- // Don't forget to save the last strain peak, which would otherwise be ignored.
960
- 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);
961
1107
  }
962
- });
963
- });
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);
964
1126
  }
965
- /**
966
- * Calculates the star rating value of a difficulty.
967
- *
968
- * @param difficulty The difficulty to calculate.
969
- */
970
- starValue(difficulty) {
971
- 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);
972
1142
  }
973
1143
  /**
974
- * Calculates the base performance value of a difficulty rating.
975
- *
976
- * @param rating The difficulty rating.
1144
+ * @param current The hitobject to calculate.
977
1145
  */
978
- basePerformanceValue(rating) {
979
- 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;
980
1154
  }
981
1155
  }
982
1156
 
983
1157
  /**
984
- * 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.
985
1161
  */
986
- class DroidRhythm extends DroidSkill {
987
- historyLength = 32;
988
- skillMultiplier = 1;
989
- reducedSectionCount = 5;
990
- reducedSectionBaseline = 0.75;
991
- strainDecayBase = 0.3;
992
- starsPerDouble = 1.75;
993
- rhythmMultiplier;
994
- historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
995
- currentRhythm = 1;
996
- hitWindow;
997
- constructor(mods, overallDifficulty) {
998
- super(mods);
999
- this.hitWindow = new osuBase.OsuHitWindow(overallDifficulty);
1000
- const odScaling = Math.pow(this.hitWindow.overallDifficulty, 2) / 400;
1001
- this.rhythmMultiplier =
1002
- 0.75 +
1003
- (this.hitWindow.overallDifficulty >= 0 ? odScaling : -odScaling);
1004
- }
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 {
1005
1170
  /**
1006
- * 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.
1007
1176
  */
1008
- calculateRhythmBonus(current) {
1009
- 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) {
1010
1181
  return 1;
1011
1182
  }
1012
1183
  let previousIslandSize = 0;
@@ -1016,29 +1187,40 @@ class DroidRhythm extends DroidSkill {
1016
1187
  let startRatio = 0;
1017
1188
  let firstDeltaSwitch = false;
1018
1189
  let rhythmStart = 0;
1019
- while (rhythmStart < this.previous.length - 2 &&
1020
- 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 <
1021
1204
  this.historyTimeMax) {
1022
1205
  ++rhythmStart;
1023
1206
  }
1024
1207
  for (let i = rhythmStart; i > 0; --i) {
1025
1208
  // Scale note 0 to 1 from history to now.
1026
1209
  let currentHistoricalDecay = (this.historyTimeMax -
1027
- (current.startTime - this.previous[i - 1].startTime)) /
1210
+ (current.startTime - validPrevious[i - 1].startTime)) /
1028
1211
  this.historyTimeMax;
1029
1212
  // Either we're limited by time or limited by object count.
1030
- currentHistoricalDecay = Math.min(currentHistoricalDecay, (this.previous.length - i) / this.previous.length);
1031
- const currentDelta = this.previous[i - 1].strainTime;
1032
- const prevDelta = this.previous[i].strainTime;
1033
- 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;
1034
1217
  const currentRatio = 1 +
1035
1218
  6 *
1036
1219
  Math.min(0.5, Math.pow(Math.sin(Math.PI /
1037
1220
  (Math.min(prevDelta, currentDelta) /
1038
1221
  Math.max(prevDelta, currentDelta))), 2));
1039
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) -
1040
- this.hitWindow.hitWindowFor300() * 0.4) /
1041
- (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));
1042
1224
  let effectiveRatio = windowPenalty * currentRatio;
1043
1225
  if (firstDeltaSwitch) {
1044
1226
  if (prevDelta <= 1.25 * currentDelta &&
@@ -1049,11 +1231,11 @@ class DroidRhythm extends DroidSkill {
1049
1231
  }
1050
1232
  }
1051
1233
  else {
1052
- if (this.previous[i - 1].object instanceof osuBase.Slider) {
1234
+ if (validPrevious[i - 1].object instanceof osuBase.Slider) {
1053
1235
  // BPM change is into slider, this is easy acc window.
1054
1236
  effectiveRatio /= 8;
1055
1237
  }
1056
- if (this.previous[i].object instanceof osuBase.Slider) {
1238
+ if (validPrevious[i].object instanceof osuBase.Slider) {
1057
1239
  // BPM change was from a slider, this is typically easier than circle -> circle.
1058
1240
  effectiveRatio /= 4;
1059
1241
  }
@@ -1096,10 +1278,39 @@ class DroidRhythm extends DroidSkill {
1096
1278
  islandSize = 1;
1097
1279
  }
1098
1280
  }
1099
- 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);
1100
1311
  }
1101
1312
  strainValueAt(current) {
1102
- this.currentRhythm = this.calculateRhythmBonus(current);
1313
+ this.currentRhythm = DroidRhythmEvaluator.evaluateDifficultyOf(current, this.hitWindow.hitWindowFor300());
1103
1314
  this.currentStrain *= this.strainDecay(current.deltaTime);
1104
1315
  this.currentStrain += this.currentRhythm - 1;
1105
1316
  return this.currentStrain;
@@ -1111,27 +1322,31 @@ class DroidRhythm extends DroidSkill {
1111
1322
  }
1112
1323
 
1113
1324
  /**
1114
- * Represents the skill required to read every object in the map.
1325
+ * An evaluator for calculating osu!droid Rhythm skill.
1115
1326
  */
1116
- class DroidVisual extends DroidSkill {
1117
- historyLength = 4;
1118
- starsPerDouble = 1.025;
1119
- reducedSectionCount = 10;
1120
- reducedSectionBaseline = 0.75;
1121
- skillMultiplier = 20;
1122
- strainDecayBase = 0.1;
1123
- preempt;
1124
- isHidden;
1125
- constructor(mods, preempt) {
1126
- super(mods);
1127
- this.preempt = preempt;
1128
- this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1129
- }
1327
+ class DroidVisualEvaluator {
1130
1328
  /**
1131
- * @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.
1132
1340
  */
1133
- strainValueOf(current) {
1134
- 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)) {
1135
1350
  return 0;
1136
1351
  }
1137
1352
  // Start with base density and give global bonus for Hidden.
@@ -1139,15 +1354,20 @@ class DroidVisual extends DroidSkill {
1139
1354
  let strain = Math.min(20, Math.pow(current.noteDensity, 2)) /
1140
1355
  10 /
1141
1356
  (1 + current.overlappingFactor);
1142
- if (this.isHidden) {
1357
+ if (isHiddenMod) {
1143
1358
  strain +=
1144
1359
  Math.min(25, Math.pow(current.noteDensity, 1.25)) /
1145
1360
  10 /
1146
1361
  (1 + current.overlappingFactor / 1.25);
1147
1362
  }
1148
- // Give bonus for AR higher than 10.33.
1149
- if (this.preempt < 400) {
1150
- 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;
1151
1371
  }
1152
1372
  if (current.object instanceof osuBase.Slider) {
1153
1373
  const scalingFactor = 50 / current.object.radius;
@@ -1159,10 +1379,14 @@ class DroidVisual extends DroidSkill {
1159
1379
  Math.min(1, current.travelDistance / scalingFactor / 125);
1160
1380
  let cumulativeStrainTime = 0;
1161
1381
  // Reward for velocity changes based on last few sliders.
1162
- for (let i = 0; i < this.previous.length; ++i) {
1163
- const last = this.previous[i];
1382
+ for (let i = 0; i < Math.min(current.index, 4); ++i) {
1383
+ const last = current.previous(i);
1164
1384
  cumulativeStrainTime += last.strainTime;
1165
- 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)) {
1166
1390
  continue;
1167
1391
  }
1168
1392
  strain +=
@@ -1176,10 +1400,27 @@ class DroidVisual extends DroidSkill {
1176
1400
  }
1177
1401
  return strain;
1178
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
+ }
1179
1419
  strainValueAt(current) {
1180
1420
  this.currentStrain *= this.strainDecay(current.deltaTime);
1181
1421
  this.currentStrain +=
1182
- this.strainValueOf(current) * this.skillMultiplier;
1422
+ DroidVisualEvaluator.evaluateDifficultyOf(current, this.isHidden) *
1423
+ this.skillMultiplier;
1183
1424
  return this.currentStrain * (1 + (current.rhythmMultiplier - 1) / 5);
1184
1425
  }
1185
1426
  saveToHitObject(current) {
@@ -1188,9 +1429,9 @@ class DroidVisual extends DroidSkill {
1188
1429
  }
1189
1430
 
1190
1431
  /**
1191
- * Difficulty calculator for osu!droid gamemode.
1432
+ * A difficulty calculator for osu!droid gamemode.
1192
1433
  */
1193
- class DroidStarRating extends StarRating {
1434
+ class DroidDifficultyCalculator extends DifficultyCalculator {
1194
1435
  /**
1195
1436
  * The aim star rating of the beatmap.
1196
1437
  */
@@ -1212,33 +1453,7 @@ class DroidStarRating extends StarRating {
1212
1453
  */
1213
1454
  visual = 0;
1214
1455
  difficultyMultiplier = 0.18;
1215
- /**
1216
- * Calculates the star rating of the specified beatmap.
1217
- *
1218
- * The beatmap is analyzed in chunks of `sectionLength` duration.
1219
- * For each chunk the highest hitobject strains are added to
1220
- * a list which is then collapsed into a weighted sum, much
1221
- * like scores are weighted on a user's profile.
1222
- *
1223
- * For subsequent chunks, the initial max strain is calculated
1224
- * by decaying the previous hitobject's strain until the
1225
- * beginning of the new chunk.
1226
- *
1227
- * The first object doesn't generate a strain
1228
- * so we begin calculating from the second object.
1229
- *
1230
- * Also don't forget to manually add the peak strain for the last
1231
- * section which would otherwise be ignored.
1232
- */
1233
- calculate(params) {
1234
- return super.calculate(params, osuBase.modes.droid);
1235
- }
1236
- /**
1237
- * Generates difficulty hitobjects for this calculator.
1238
- */
1239
- generateDifficultyHitObjects() {
1240
- super.generateDifficultyHitObjects(osuBase.modes.droid);
1241
- }
1456
+ mode = osuBase.modes.droid;
1242
1457
  /**
1243
1458
  * Calculates the aim star rating of the beatmap and stores it in this instance.
1244
1459
  */
@@ -1249,17 +1464,23 @@ class DroidStarRating extends StarRating {
1249
1464
  this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
1250
1465
  }
1251
1466
  /**
1252
- * 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.
1253
1468
  */
1254
1469
  calculateTap() {
1255
1470
  const tapSkill = new DroidTap(this.mods, this.stats.od);
1256
1471
  this.calculateSkills(tapSkill);
1257
- this.postCalculateTap(tapSkill);
1472
+ if (!this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1473
+ this.postCalculateTap(tapSkill);
1474
+ }
1475
+ this.calculateSpeedAttributes();
1258
1476
  }
1259
1477
  /**
1260
1478
  * Calculates the rhythm star rating of the beatmap and stores it in this instance.
1261
1479
  */
1262
1480
  calculateRhythm() {
1481
+ if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
1482
+ return;
1483
+ }
1263
1484
  const rhythmSkill = new DroidRhythm(this.mods, this.stats.od);
1264
1485
  this.calculateSkills(rhythmSkill);
1265
1486
  this.postCalculateRhythm(rhythmSkill);
@@ -1276,7 +1497,7 @@ class DroidStarRating extends StarRating {
1276
1497
  * Calculates the visual star rating of the beatmap and stores it in this instance.
1277
1498
  */
1278
1499
  calculateVisual() {
1279
- const visualSkill = new DroidVisual(this.mods, osuBase.MapStats.arToMS(this.stats.ar));
1500
+ const visualSkill = new DroidVisual(this.mods);
1280
1501
  this.calculateSkills(visualSkill);
1281
1502
  this.postCalculateVisual(visualSkill);
1282
1503
  }
@@ -1313,9 +1534,7 @@ class DroidStarRating extends StarRating {
1313
1534
  if (!isRelax) {
1314
1535
  this.postCalculateTap(tapSkill);
1315
1536
  }
1316
- else {
1317
- this.calculateSpeedAttributes();
1318
- }
1537
+ this.calculateSpeedAttributes();
1319
1538
  if (!isRelax) {
1320
1539
  this.postCalculateRhythm(rhythmSkill);
1321
1540
  }
@@ -1351,7 +1570,7 @@ class DroidStarRating extends StarRating {
1351
1570
  new DroidRhythm(this.mods, this.stats.od),
1352
1571
  new DroidTap(this.mods, this.stats.od),
1353
1572
  new DroidFlashlight(this.mods),
1354
- new DroidVisual(this.mods, osuBase.MapStats.arToMS(this.stats.ar)),
1573
+ new DroidVisual(this.mods),
1355
1574
  ];
1356
1575
  }
1357
1576
  /**
@@ -1378,7 +1597,6 @@ class DroidStarRating extends StarRating {
1378
1597
  postCalculateTap(tapSkill) {
1379
1598
  this.strainPeaks.speed = tapSkill.strainPeaks;
1380
1599
  this.tap = this.starValue(tapSkill.difficultyValue());
1381
- this.calculateSpeedAttributes();
1382
1600
  }
1383
1601
  /**
1384
1602
  * Calculates speed-related attributes.
@@ -1429,6 +1647,10 @@ class PerformanceCalculator {
1429
1647
  * The calculated accuracy.
1430
1648
  */
1431
1649
  computedAccuracy = new osuBase.Accuracy({});
1650
+ /**
1651
+ * The difficulty calculator that is being calculated.
1652
+ */
1653
+ difficultyCalculator;
1432
1654
  /**
1433
1655
  * The map statistics after applying modifications.
1434
1656
  */
@@ -1446,12 +1668,21 @@ class PerformanceCalculator {
1446
1668
  */
1447
1669
  sliderNerfFactor = 1;
1448
1670
  /**
1449
- * 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.
1450
1681
  */
1451
- calculateInternal(params, mode) {
1452
- this.handleParams(params, mode);
1682
+ calculate(options) {
1683
+ this.handleOptions(options);
1453
1684
  this.calculateValues();
1454
- this.total = this.calculateTotalValue();
1685
+ this.calculateTotalValue();
1455
1686
  return this;
1456
1687
  }
1457
1688
  /**
@@ -1461,45 +1692,44 @@ class PerformanceCalculator {
1461
1692
  return Math.pow(5 * Math.max(1, stars / 0.0675) - 4, 3) / 100000;
1462
1693
  }
1463
1694
  /**
1464
- * Processes given parameters for usage in performance calculation.
1695
+ * Processes given options for usage in performance calculation.
1465
1696
  */
1466
- handleParams(params, mode) {
1467
- this.stars = params.stars;
1468
- const maxCombo = this.stars.map.maxCombo;
1697
+ handleOptions(options) {
1698
+ const maxCombo = this.difficultyCalculator.beatmap.maxCombo;
1469
1699
  const miss = this.computedAccuracy.nmiss;
1470
- const combo = params.combo ?? maxCombo - miss;
1471
- const mod = this.stars.mods;
1472
- const baseAR = this.stars.map.difficulty.ar;
1473
- 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;
1474
1704
  // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
1475
1705
  this.comboPenalty = Math.min(Math.pow(combo / maxCombo, 0.8), 1);
1476
- if (params.accPercent instanceof osuBase.Accuracy) {
1706
+ if (options?.accPercent instanceof osuBase.Accuracy) {
1477
1707
  // Copy into new instance to not modify the original
1478
- this.computedAccuracy = new osuBase.Accuracy(params.accPercent);
1708
+ this.computedAccuracy = new osuBase.Accuracy(options?.accPercent);
1479
1709
  }
1480
1710
  else {
1481
1711
  this.computedAccuracy = new osuBase.Accuracy({
1482
- percent: params.accPercent,
1483
- nobjects: this.stars.objects.length,
1484
- nmiss: params.miss || 0,
1712
+ percent: options?.accPercent,
1713
+ nobjects: this.difficultyCalculator.objects.length,
1714
+ nmiss: options?.miss || 0,
1485
1715
  });
1486
1716
  }
1487
1717
  this.effectiveMissCount = this.calculateEffectiveMissCount(combo, maxCombo);
1488
- if (this.stars.mods.some((m) => m instanceof osuBase.ModNoFail)) {
1718
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModNoFail)) {
1489
1719
  this.finalMultiplier *= Math.max(0.9, 1 - 0.02 * this.effectiveMissCount);
1490
1720
  }
1491
- if (this.stars.mods.some((m) => m instanceof osuBase.ModSpunOut)) {
1721
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModSpunOut)) {
1492
1722
  this.finalMultiplier *=
1493
1723
  1 -
1494
- Math.pow(this.stars.map.hitObjects.spinners /
1495
- this.stars.objects.length, 0.85);
1724
+ Math.pow(this.difficultyCalculator.beatmap.hitObjects.spinners /
1725
+ this.difficultyCalculator.objects.length, 0.85);
1496
1726
  }
1497
- if (this.stars.mods.some((m) => m instanceof osuBase.ModRelax)) {
1727
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModRelax)) {
1498
1728
  // As we're adding 100s and 50s to an approximated number of combo breaks, the result can be higher
1499
1729
  // than total hits in specific scenarios (which breaks some calculations), so we need to clamp it.
1500
1730
  this.effectiveMissCount = Math.min(this.effectiveMissCount +
1501
1731
  this.computedAccuracy.n100 +
1502
- this.computedAccuracy.n50, this.stars.objects.length);
1732
+ this.computedAccuracy.n50, this.difficultyCalculator.objects.length);
1503
1733
  this.finalMultiplier *= 0.6;
1504
1734
  }
1505
1735
  this.mapStatistics = new osuBase.MapStats({
@@ -1507,42 +1737,44 @@ class PerformanceCalculator {
1507
1737
  od: baseOD,
1508
1738
  mods: mod,
1509
1739
  });
1510
- if (this.stars.map.hitObjects.sliders > 0) {
1740
+ if (this.difficultyCalculator.beatmap.hitObjects.sliders > 0) {
1511
1741
  // We assume 15% of sliders in a beatmap are difficult since there's no way to tell from the performance calculator.
1512
- const estimateDifficultSliders = this.stars.map.hitObjects.sliders * 0.15;
1742
+ const estimateDifficultSliders = this.difficultyCalculator.beatmap.hitObjects.sliders * 0.15;
1513
1743
  const estimateSliderEndsDropped = osuBase.MathUtils.clamp(Math.min(this.computedAccuracy.n300 +
1514
1744
  this.computedAccuracy.n50 +
1515
1745
  this.computedAccuracy.nmiss, maxCombo - combo), 0, estimateDifficultSliders);
1516
1746
  this.sliderNerfFactor =
1517
- (1 - this.stars.attributes.sliderFactor) *
1747
+ (1 - this.difficultyCalculator.attributes.sliderFactor) *
1518
1748
  Math.pow(1 -
1519
1749
  estimateSliderEndsDropped /
1520
1750
  estimateDifficultSliders, 3) +
1521
- this.stars.attributes.sliderFactor;
1751
+ this.difficultyCalculator.attributes.sliderFactor;
1522
1752
  }
1523
- if (params.stats) {
1524
- this.mapStatistics.ar = params.stats.ar ?? this.mapStatistics.ar;
1753
+ if (options?.stats) {
1754
+ this.mapStatistics.ar = options?.stats.ar ?? this.mapStatistics.ar;
1525
1755
  this.mapStatistics.isForceAR =
1526
- params.stats.isForceAR ?? this.mapStatistics.isForceAR;
1756
+ options?.stats.isForceAR ?? this.mapStatistics.isForceAR;
1527
1757
  this.mapStatistics.speedMultiplier =
1528
- params.stats.speedMultiplier ??
1758
+ options?.stats.speedMultiplier ??
1529
1759
  this.mapStatistics.speedMultiplier;
1530
1760
  this.mapStatistics.oldStatistics =
1531
- params.stats.oldStatistics ?? this.mapStatistics.oldStatistics;
1761
+ options?.stats.oldStatistics ??
1762
+ this.mapStatistics.oldStatistics;
1532
1763
  }
1533
- this.mapStatistics.calculate({ mode: mode });
1764
+ this.mapStatistics.calculate({ mode: this.mode });
1534
1765
  }
1535
1766
  /**
1536
1767
  * Calculates the amount of misses + sliderbreaks from combo.
1537
1768
  */
1538
1769
  calculateEffectiveMissCount(combo, maxCombo) {
1539
1770
  let comboBasedMissCount = 0;
1540
- if (this.stars.map.hitObjects.sliders > 0) {
1541
- 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;
1542
1774
  if (combo < fullComboThreshold) {
1543
1775
  // We're clamping miss count because since it's derived from combo, it can
1544
1776
  // be higher than the amount of objects and that breaks some calculations.
1545
- 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);
1546
1778
  }
1547
1779
  }
1548
1780
  return Math.max(this.computedAccuracy.nmiss, comboBasedMissCount);
@@ -1553,8 +1785,6 @@ class PerformanceCalculator {
1553
1785
  * A performance points calculator that calculates performance points for osu!droid gamemode.
1554
1786
  */
1555
1787
  class DroidPerformanceCalculator extends PerformanceCalculator {
1556
- stars = new DroidStarRating();
1557
- finalMultiplier = 1.24;
1558
1788
  /**
1559
1789
  * The aim performance value.
1560
1790
  */
@@ -1575,36 +1805,38 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1575
1805
  * The visual performance value.
1576
1806
  */
1577
1807
  visual = 0;
1808
+ finalMultiplier = 1.24;
1809
+ mode = osuBase.modes.droid;
1578
1810
  tapPenalty = 1;
1579
- calculate(params) {
1580
- this.tapPenalty = params.tapPenalty ?? 1;
1581
- return this.calculateInternal(params, osuBase.modes.droid);
1582
- }
1583
1811
  calculateValues() {
1584
1812
  this.calculateAimValue();
1585
1813
  this.calculateTapValue();
1586
1814
  this.calculateAccuracyValue();
1587
1815
  this.calculateFlashlightValue();
1588
1816
  this.calculateVisualValue();
1589
- // Apply tap penalty for penalized plays.
1590
- this.tap /= this.tapPenalty;
1591
1817
  }
1592
1818
  calculateTotalValue() {
1593
- return (Math.pow(Math.pow(this.aim, 1.1) +
1594
- Math.pow(this.tap, 1.1) +
1595
- Math.pow(this.accuracy, 1.1) +
1596
- Math.pow(this.flashlight, 1.1) +
1597
- 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);
1598
1829
  }
1599
1830
  /**
1600
1831
  * Calculates the aim performance value of the beatmap.
1601
1832
  */
1602
1833
  calculateAimValue() {
1603
1834
  // Global variables
1604
- const objectCount = this.stars.objects.length;
1605
- 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));
1606
1837
  if (this.effectiveMissCount > 0) {
1607
- // 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.
1608
1840
  this.aim *=
1609
1841
  0.97 *
1610
1842
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), this.effectiveMissCount);
@@ -1625,10 +1857,11 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1625
1857
  */
1626
1858
  calculateTapValue() {
1627
1859
  // Global variables
1628
- const objectCount = this.stars.objects.length;
1629
- this.tap = this.baseValue(this.stars.tap);
1860
+ const objectCount = this.difficultyCalculator.objects.length;
1861
+ this.tap = this.baseValue(this.difficultyCalculator.tap);
1630
1862
  if (this.effectiveMissCount > 0) {
1631
- // 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.
1632
1865
  this.tap *=
1633
1866
  0.97 *
1634
1867
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), Math.pow(this.effectiveMissCount, 0.875));
@@ -1639,36 +1872,39 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1639
1872
  const countGreat = this.computedAccuracy.n300;
1640
1873
  const countOk = this.computedAccuracy.n100;
1641
1874
  const countMeh = this.computedAccuracy.n50;
1642
- const relevantTotalDiff = objectCount - this.stars.attributes.speedNoteCount;
1875
+ const relevantTotalDiff = objectCount - this.difficultyCalculator.attributes.speedNoteCount;
1643
1876
  const relevantAccuracy = new osuBase.Accuracy({
1644
1877
  n300: Math.max(0, countGreat - relevantTotalDiff),
1645
1878
  n100: Math.max(0, countOk - Math.max(0, relevantTotalDiff - countGreat)),
1646
1879
  n50: Math.max(0, countMeh - Math.max(0, relevantTotalDiff - countGreat - countOk)),
1647
1880
  nmiss: this.effectiveMissCount,
1648
1881
  });
1649
- // Scale the speed value with accuracy and OD.
1882
+ // Scale the tap value with accuracy and OD.
1650
1883
  const od = this.mapStatistics.od;
1651
1884
  const odScaling = Math.pow(od, 2) / 750;
1652
1885
  this.tap *=
1653
1886
  (0.95 + (od > 0 ? odScaling : -odScaling)) *
1654
1887
  Math.pow((this.computedAccuracy.value(objectCount) +
1655
- relevantAccuracy.value(this.stars.attributes.speedNoteCount)) /
1888
+ relevantAccuracy.value(this.difficultyCalculator.attributes.speedNoteCount)) /
1656
1889
  2, (14 - Math.max(od, 2.5)) / 2);
1657
- // Scale the speed value with # of 50s to punish doubletapping.
1890
+ // Scale the tap value with # of 50s to punish doubletapping.
1658
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;
1659
1894
  }
1660
1895
  /**
1661
1896
  * Calculates the accuracy performance value of the beatmap.
1662
1897
  */
1663
1898
  calculateAccuracyValue() {
1664
- if (this.stars.mods.some((m) => m instanceof osuBase.ModRelax)) {
1899
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModRelax)) {
1665
1900
  return;
1666
1901
  }
1667
1902
  // Global variables
1668
- const objectCount = this.stars.objects.length;
1669
- const ncircles = this.stars.mods.some((m) => m instanceof osuBase.ModScoreV2)
1670
- ? objectCount - this.stars.map.hitObjects.spinners
1671
- : 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;
1672
1908
  if (ncircles === 0) {
1673
1909
  return;
1674
1910
  }
@@ -1685,11 +1921,12 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1685
1921
  // Bonus for many hitcircles - it's harder to keep good accuracy up for longer
1686
1922
  this.accuracy *= Math.min(1.15, Math.pow(ncircles / 1000, 0.3));
1687
1923
  // Scale the accuracy value with rhythm complexity.
1688
- this.accuracy *= 1.5 / (1 + Math.exp(-(this.stars.rhythm - 1) / 2));
1689
- 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)) {
1690
1927
  this.accuracy *= 1.08;
1691
1928
  }
1692
- if (this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1929
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1693
1930
  this.accuracy *= 1.02;
1694
1931
  }
1695
1932
  }
@@ -1697,17 +1934,14 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1697
1934
  * Calculates the flashlight performance value of the beatmap.
1698
1935
  */
1699
1936
  calculateFlashlightValue() {
1700
- if (!this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1937
+ if (!this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
1701
1938
  return;
1702
1939
  }
1703
1940
  // Global variables
1704
- const objectCount = this.stars.objects.length;
1941
+ const objectCount = this.difficultyCalculator.objects.length;
1705
1942
  this.flashlight =
1706
- Math.pow(Math.pow(this.stars.flashlight, 0.8), 2) * 25;
1707
- // Add an additional bonus for HDFL.
1708
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
1709
- this.flashlight *= 1.3;
1710
- }
1943
+ Math.pow(Math.pow(this.difficultyCalculator.flashlight, 0.8), 2) *
1944
+ 25;
1711
1945
  // Combo scaling
1712
1946
  this.flashlight *= this.comboPenalty;
1713
1947
  if (this.effectiveMissCount > 0) {
@@ -1735,8 +1969,9 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
1735
1969
  */
1736
1970
  calculateVisualValue() {
1737
1971
  // Global variables
1738
- const objectCount = this.stars.objects.length;
1739
- 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;
1740
1975
  if (this.effectiveMissCount > 0) {
1741
1976
  // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
1742
1977
  this.visual *=
@@ -1780,9 +2015,7 @@ class OsuSkill extends StrainSkill {
1780
2015
  difficultyValue() {
1781
2016
  const sortedStrains = this.strainPeaks
1782
2017
  .slice()
1783
- .sort((a, b) => {
1784
- return b - a;
1785
- });
2018
+ .sort((a, b) => b - a);
1786
2019
  // We are reducing the highest strains first to account for extreme difficulty spikes.
1787
2020
  for (let i = 0; i < Math.min(sortedStrains.length, this.reducedSectionCount); ++i) {
1788
2021
  const scale = Math.log10(osuBase.Interpolation.lerp(1, 10, osuBase.MathUtils.clamp(i / this.reducedSectionCount, 0, 1)));
@@ -1790,9 +2023,7 @@ class OsuSkill extends StrainSkill {
1790
2023
  }
1791
2024
  // Difficulty is the weighted sum of the highest strains from every section.
1792
2025
  // We're sorting from highest to lowest strain.
1793
- sortedStrains.sort((a, b) => {
1794
- return b - a;
1795
- });
2026
+ sortedStrains.sort((a, b) => b - a);
1796
2027
  let difficulty = 0;
1797
2028
  let weight = 1;
1798
2029
  for (const strain of sortedStrains) {
@@ -1808,39 +2039,32 @@ class OsuSkill extends StrainSkill {
1808
2039
  }
1809
2040
 
1810
2041
  /**
1811
- * 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.
1812
2043
  */
1813
- class OsuAim extends OsuSkill {
1814
- skillMultiplier = 23.25;
1815
- strainDecayBase = 0.15;
1816
- reducedSectionCount = 10;
1817
- reducedSectionBaseline = 0.75;
1818
- difficultyMultiplier = 1.06;
1819
- decayWeight = 0.9;
1820
- wideAngleMultiplier = 1.5;
1821
- acuteAngleMultiplier = 2;
1822
- sliderMultiplier = 1.5;
1823
- velocityChangeMultiplier = 0.75;
1824
- withSliders;
1825
- constructor(mods, withSliders) {
1826
- super(mods);
1827
- this.withSliders = withSliders;
1828
- }
2044
+ class OsuAimEvaluator extends AimEvaluator {
1829
2045
  /**
1830
- * @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.
1831
2055
  */
1832
- strainValueOf(current) {
2056
+ static evaluateDifficultyOf(current, withSliders) {
2057
+ const last = current.previous(0);
1833
2058
  if (current.object instanceof osuBase.Spinner ||
1834
- this.previous.length <= 1 ||
1835
- this.previous[0].object instanceof osuBase.Spinner) {
2059
+ current.index <= 1 ||
2060
+ last?.object instanceof osuBase.Spinner) {
1836
2061
  return 0;
1837
2062
  }
1838
- const last = this.previous[0];
1839
- const lastLast = this.previous[1];
2063
+ const lastLast = current.previous(1);
1840
2064
  // Calculate the velocity to the current hitobject, which starts with a base distance / time assuming the last object is a hitcircle.
1841
2065
  let currentVelocity = current.lazyJumpDistance / current.strainTime;
1842
2066
  // But if the last object is a slider, then we extend the travel velocity through the slider into the current object.
1843
- if (last.object instanceof osuBase.Slider && this.withSliders) {
2067
+ if (last.object instanceof osuBase.Slider && withSliders) {
1844
2068
  // Calculate the slider velocity from slider head to slider end.
1845
2069
  const travelVelocity = last.travelDistance / last.travelTime;
1846
2070
  // Calculate the movement velocity from slider end to current object.
@@ -1850,7 +2074,7 @@ class OsuAim extends OsuSkill {
1850
2074
  }
1851
2075
  // As above, do the same for the previous hitobject.
1852
2076
  let prevVelocity = last.lazyJumpDistance / last.strainTime;
1853
- if (lastLast.object instanceof osuBase.Slider && this.withSliders) {
2077
+ if (lastLast.object instanceof osuBase.Slider && withSliders) {
1854
2078
  const travelVelocity = lastLast.travelDistance / lastLast.travelTime;
1855
2079
  const movementVelocity = last.minimumJumpDistance / last.minimumJumpTime;
1856
2080
  prevVelocity = Math.max(prevVelocity, movementVelocity + travelVelocity);
@@ -1937,18 +2161,36 @@ class OsuAim extends OsuSkill {
1937
2161
  strain += Math.max(acuteAngleBonus * this.acuteAngleMultiplier, wideAngleBonus * this.wideAngleMultiplier +
1938
2162
  velocityChangeBonus * this.velocityChangeMultiplier);
1939
2163
  // Add in additional slider velocity bonus.
1940
- if (this.withSliders) {
2164
+ if (withSliders) {
1941
2165
  strain += sliderBonus * this.sliderMultiplier;
1942
2166
  }
1943
2167
  return strain;
1944
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
+ }
1945
2186
  /**
1946
2187
  * @param current The hitobject to calculate.
1947
2188
  */
1948
2189
  strainValueAt(current) {
1949
2190
  this.currentStrain *= this.strainDecay(current.deltaTime);
1950
2191
  this.currentStrain +=
1951
- this.strainValueOf(current) * this.skillMultiplier;
2192
+ OsuAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
2193
+ this.skillMultiplier;
1952
2194
  return this.currentStrain;
1953
2195
  }
1954
2196
  /**
@@ -1962,63 +2204,43 @@ class OsuAim extends OsuSkill {
1962
2204
  current.aimStrainWithoutSliders = this.currentStrain;
1963
2205
  }
1964
2206
  }
1965
- /**
1966
- * Calculates the bonus of wide angles.
1967
- */
1968
- calculateWideAngleBonus(angle) {
1969
- return Math.pow(Math.sin((3 / 4) *
1970
- (Math.min((5 / 6) * Math.PI, Math.max(Math.PI / 6, angle)) -
1971
- Math.PI / 6)), 2);
1972
- }
1973
- /**
1974
- * Calculates the bonus of acute angles.
1975
- */
1976
- calculateAcuteAngleBonus(angle) {
1977
- return 1 - this.calculateWideAngleBonus(angle);
1978
- }
1979
2207
  }
1980
2208
 
1981
2209
  /**
1982
- * 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.
1983
2211
  */
1984
- class OsuSpeed extends OsuSkill {
2212
+ class OsuSpeedEvaluator extends SpeedEvaluator {
1985
2213
  /**
1986
2214
  * Spacing threshold for a single hitobject spacing.
1987
2215
  */
1988
- SINGLE_SPACING_THRESHOLD = 125;
1989
- historyLength = 32;
1990
- skillMultiplier = 1375;
1991
- strainDecayBase = 0.3;
1992
- reducedSectionCount = 5;
1993
- reducedSectionBaseline = 0.75;
1994
- difficultyMultiplier = 1.04;
1995
- decayWeight = 0.9;
1996
- rhythmMultiplier = 0.75;
1997
- historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1998
- currentSpeedStrain = 0;
1999
- currentRhythm = 0;
2000
- // ~200 1/4 BPM streams
2001
- minSpeedBonus = 75;
2002
- greatWindow;
2003
- constructor(mods, greatWindow) {
2004
- super(mods);
2005
- this.greatWindow = greatWindow;
2006
- }
2216
+ static SINGLE_SPACING_THRESHOLD = 125;
2007
2217
  /**
2008
- * @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.
2009
2226
  */
2010
- strainValueOf(current) {
2227
+ static evaluateDifficultyOf(current, greatWindow) {
2011
2228
  if (current.object instanceof osuBase.Spinner) {
2012
2229
  return 0;
2013
2230
  }
2231
+ const prev = current.previous(0);
2014
2232
  let strainTime = current.strainTime;
2015
- const greatWindowFull = this.greatWindow * 2;
2016
- const speedWindowRatio = strainTime / greatWindowFull;
2017
- // Aim to nerf cheesy rhythms (very fast consecutive doubles with large deltatimes between).
2018
- if (this.previous[0] &&
2019
- strainTime < greatWindowFull &&
2020
- this.previous[0].strainTime > strainTime) {
2021
- 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);
2022
2244
  }
2023
2245
  // Cap deltatime to the OD 300 hitwindow.
2024
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.
@@ -2028,27 +2250,29 @@ class OsuSpeed extends OsuSkill {
2028
2250
  speedBonus +=
2029
2251
  0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
2030
2252
  }
2031
- const travelDistance = this.previous[0]?.travelDistance ?? 0;
2253
+ const travelDistance = prev?.travelDistance ?? 0;
2032
2254
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
2033
- return ((speedBonus +
2255
+ return (((speedBonus +
2034
2256
  speedBonus *
2035
- Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.5)) /
2257
+ Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.5)) *
2258
+ doubletapness) /
2036
2259
  strainTime);
2037
2260
  }
2261
+ }
2262
+
2263
+ /**
2264
+ * An evaluator for calculating osu!standard Rhythm skill.
2265
+ */
2266
+ class OsuRhythmEvaluator extends RhythmEvaluator {
2267
+ static rhythmMultiplier = 0.75;
2038
2268
  /**
2039
- * @param current The hitobject to calculate.
2040
- */
2041
- strainValueAt(current) {
2042
- this.currentSpeedStrain *= this.strainDecay(current.deltaTime);
2043
- this.currentSpeedStrain +=
2044
- this.strainValueOf(current) * this.skillMultiplier;
2045
- this.currentRhythm = this.calculateRhythmBonus(current);
2046
- return this.currentSpeedStrain * this.currentRhythm;
2047
- }
2048
- /**
2049
- * 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.
2050
2274
  */
2051
- calculateRhythmBonus(current) {
2275
+ static evaluateDifficultyOf(current, greatWindow) {
2052
2276
  if (current.object instanceof osuBase.Spinner) {
2053
2277
  return 0;
2054
2278
  }
@@ -2058,29 +2282,33 @@ class OsuSpeed extends OsuSkill {
2058
2282
  // Store the ratio of the current start of an island to buff for tighter rhythms.
2059
2283
  let startRatio = 0;
2060
2284
  let firstDeltaSwitch = false;
2285
+ const historicalNoteCount = Math.min(current.index, 32);
2061
2286
  let rhythmStart = 0;
2062
- while (rhythmStart < this.previous.length - 2 &&
2063
- current.startTime - this.previous[rhythmStart].startTime <
2287
+ while (rhythmStart < historicalNoteCount - 2 &&
2288
+ current.startTime - current.previous(rhythmStart).startTime <
2064
2289
  this.historyTimeMax) {
2065
2290
  ++rhythmStart;
2066
2291
  }
2067
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);
2068
2296
  // Scale note 0 to 1 from history to now.
2069
2297
  let currentHistoricalDecay = (this.historyTimeMax -
2070
- (current.startTime - this.previous[i - 1].startTime)) /
2298
+ (current.startTime - currentObject.startTime)) /
2071
2299
  this.historyTimeMax;
2072
2300
  // Either we're limited by time or limited by object count.
2073
- currentHistoricalDecay = Math.min(currentHistoricalDecay, (this.previous.length - i) / this.previous.length);
2074
- const currentDelta = this.previous[i - 1].strainTime;
2075
- const prevDelta = this.previous[i].strainTime;
2076
- 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;
2077
2305
  const currentRatio = 1 +
2078
2306
  6 *
2079
2307
  Math.min(0.5, Math.pow(Math.sin(Math.PI /
2080
2308
  (Math.min(prevDelta, currentDelta) /
2081
2309
  Math.max(prevDelta, currentDelta))), 2));
2082
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - this.greatWindow * 0.6) /
2083
- (this.greatWindow * 0.6));
2310
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - greatWindow * 0.6) /
2311
+ (greatWindow * 0.6));
2084
2312
  let effectiveRatio = windowPenalty * currentRatio;
2085
2313
  if (firstDeltaSwitch) {
2086
2314
  if (prevDelta <= 1.25 * currentDelta &&
@@ -2091,11 +2319,11 @@ class OsuSpeed extends OsuSkill {
2091
2319
  }
2092
2320
  }
2093
2321
  else {
2094
- if (this.previous[i - 1].object instanceof osuBase.Slider) {
2322
+ if (currentObject.object instanceof osuBase.Slider) {
2095
2323
  // BPM change is into slider, this is easy acc window.
2096
2324
  effectiveRatio /= 8;
2097
2325
  }
2098
- if (this.previous[i].object instanceof osuBase.Slider) {
2326
+ if (prevObject.object instanceof osuBase.Slider) {
2099
2327
  // BPM change was from a slider, this is typically easier than circle -> circle.
2100
2328
  effectiveRatio /= 4;
2101
2329
  }
@@ -2140,6 +2368,38 @@ class OsuSpeed extends OsuSkill {
2140
2368
  }
2141
2369
  return Math.sqrt(4 + rhythmComplexitySum * this.rhythmMultiplier) / 2;
2142
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
+ }
2143
2403
  /**
2144
2404
  * @param current The hitobject to save to.
2145
2405
  */
@@ -2150,17 +2410,20 @@ class OsuSpeed extends OsuSkill {
2150
2410
  }
2151
2411
 
2152
2412
  /**
2153
- * 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.
2154
2414
  */
2155
- class OsuFlashlight extends OsuSkill {
2156
- historyLength = 10;
2157
- skillMultiplier = 0.07;
2158
- strainDecayBase = 0.15;
2159
- reducedSectionCount = 10;
2160
- reducedSectionBaseline = 0.75;
2161
- difficultyMultiplier = 1.06;
2162
- decayWeight = 1;
2163
- 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) {
2164
2427
  if (current.object instanceof osuBase.Spinner) {
2165
2428
  return 0;
2166
2429
  }
@@ -2169,8 +2432,8 @@ class OsuFlashlight extends OsuSkill {
2169
2432
  let cumulativeStrainTime = 0;
2170
2433
  let result = 0;
2171
2434
  let last = current;
2172
- for (let i = 0; i < this.previous.length; ++i) {
2173
- const currentObject = this.previous[i];
2435
+ for (let i = 0; i < Math.min(current.index, 10); ++i) {
2436
+ const currentObject = current.previous(i);
2174
2437
  if (!(currentObject.object instanceof osuBase.Spinner)) {
2175
2438
  const jumpDistance = current.object.stackedPosition.subtract(currentObject.object.endPosition).length;
2176
2439
  cumulativeStrainTime += last.strainTime;
@@ -2180,21 +2443,47 @@ class OsuFlashlight extends OsuSkill {
2180
2443
  }
2181
2444
  // We also want to nerf stacks so that only the first object of the stack is accounted for.
2182
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));
2183
2451
  result +=
2184
- (stackNerf * scalingFactor * jumpDistance) /
2452
+ (stackNerf * opacityBonus * scalingFactor * jumpDistance) /
2185
2453
  cumulativeStrainTime;
2186
2454
  }
2187
2455
  last = currentObject;
2188
2456
  }
2457
+ // Additional bonus for Hidden due to there being no approach circles.
2458
+ if (isHiddenMod) {
2459
+ result *= 1 + this.hiddenBonus;
2460
+ }
2189
2461
  return Math.pow(smallDistNerf * result, 2);
2190
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
+ }
2191
2480
  /**
2192
2481
  * @param current The hitobject to calculate.
2193
2482
  */
2194
2483
  strainValueAt(current) {
2195
2484
  this.currentStrain *= this.strainDecay(current.deltaTime);
2196
2485
  this.currentStrain +=
2197
- this.strainValueOf(current) * this.skillMultiplier;
2486
+ OsuFlashlightEvaluator.evaluateDifficultyOf(current, this.isHidden) * this.skillMultiplier;
2198
2487
  return this.currentStrain;
2199
2488
  }
2200
2489
  saveToHitObject(current) {
@@ -2203,9 +2492,9 @@ class OsuFlashlight extends OsuSkill {
2203
2492
  }
2204
2493
 
2205
2494
  /**
2206
- * Difficulty calculator for osu!standard gamemode.
2495
+ * A difficulty calculator for osu!standard gamemode.
2207
2496
  */
2208
- class OsuStarRating extends StarRating {
2497
+ class OsuDifficultyCalculator extends DifficultyCalculator {
2209
2498
  /**
2210
2499
  * The aim star rating of the beatmap.
2211
2500
  */
@@ -2219,15 +2508,7 @@ class OsuStarRating extends StarRating {
2219
2508
  */
2220
2509
  flashlight = 0;
2221
2510
  difficultyMultiplier = 0.0675;
2222
- calculate(params) {
2223
- return super.calculate(params, osuBase.modes.osu);
2224
- }
2225
- /**
2226
- * Generates difficulty hitobjects for this calculator.
2227
- */
2228
- generateDifficultyHitObjects() {
2229
- super.generateDifficultyHitObjects(osuBase.modes.osu);
2230
- }
2511
+ mode = osuBase.modes.osu;
2231
2512
  /**
2232
2513
  * Calculates the aim star rating of the beatmap and stores it in this instance.
2233
2514
  */
@@ -2362,44 +2643,43 @@ class OsuStarRating extends StarRating {
2362
2643
  }
2363
2644
 
2364
2645
  /**
2365
- * 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.
2366
2647
  */
2367
2648
  class MapStars {
2368
2649
  /**
2369
- * The osu!droid star rating of the beatmap.
2650
+ * The osu!droid difficulty calculator of the beatmap.
2370
2651
  */
2371
- droidStars = new DroidStarRating();
2652
+ droid;
2372
2653
  /**
2373
- * The osu!standard star rating of the beatmap.
2654
+ * The osu!standard difficulty calculator of the beatmap.
2374
2655
  */
2375
- pcStars = new OsuStarRating();
2656
+ osu;
2376
2657
  /**
2377
- * 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.
2378
2662
  */
2379
- calculate(params) {
2380
- const mod = params.mods ?? [];
2663
+ constructor(beatmap, options) {
2381
2664
  const stats = new osuBase.MapStats({
2382
- speedMultiplier: params.stats?.speedMultiplier ?? 1,
2383
- isForceAR: params.stats?.isForceAR ?? false,
2384
- oldStatistics: params.stats?.oldStatistics ?? false,
2665
+ speedMultiplier: options?.stats?.speedMultiplier ?? 1,
2666
+ isForceAR: options?.stats?.isForceAR ?? false,
2667
+ oldStatistics: options?.stats?.oldStatistics ?? false,
2385
2668
  });
2386
- this.droidStars.calculate({
2387
- map: params.map,
2388
- mods: mod,
2669
+ this.droid = new DroidDifficultyCalculator(beatmap).calculate({
2670
+ ...options,
2389
2671
  stats,
2390
2672
  });
2391
- this.pcStars.calculate({
2392
- map: params.map,
2393
- mods: mod,
2673
+ this.osu = new OsuDifficultyCalculator(beatmap).calculate({
2674
+ ...options,
2394
2675
  stats,
2395
2676
  });
2396
- return this;
2397
2677
  }
2398
2678
  /**
2399
2679
  * Returns a string representative of the class.
2400
2680
  */
2401
2681
  toString() {
2402
- return `${this.droidStars.toString()}\n${this.pcStars.toString()}`;
2682
+ return `${this.droid.toString()}\n${this.osu.toString()}`;
2403
2683
  }
2404
2684
  }
2405
2685
 
@@ -2407,8 +2687,6 @@ class MapStars {
2407
2687
  * A performance points calculator that calculates performance points for osu!standard gamemode.
2408
2688
  */
2409
2689
  class OsuPerformanceCalculator extends PerformanceCalculator {
2410
- stars = new OsuStarRating();
2411
- finalMultiplier = 1.12;
2412
2690
  /**
2413
2691
  * The aim performance value.
2414
2692
  */
@@ -2425,9 +2703,8 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2425
2703
  * The flashlight performance value.
2426
2704
  */
2427
2705
  flashlight = 0;
2428
- calculate(params) {
2429
- return this.calculateInternal(params, osuBase.modes.osu);
2430
- }
2706
+ finalMultiplier = 1.12;
2707
+ mode = osuBase.modes.osu;
2431
2708
  calculateValues() {
2432
2709
  this.calculateAimValue();
2433
2710
  this.calculateSpeedValue();
@@ -2435,19 +2712,20 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2435
2712
  this.calculateFlashlightValue();
2436
2713
  }
2437
2714
  calculateTotalValue() {
2438
- return (Math.pow(Math.pow(this.aim, 1.1) +
2439
- Math.pow(this.speed, 1.1) +
2440
- Math.pow(this.accuracy, 1.1) +
2441
- 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;
2442
2720
  }
2443
2721
  /**
2444
2722
  * Calculates the aim performance value of the beatmap.
2445
2723
  */
2446
2724
  calculateAimValue() {
2447
2725
  // Global variables
2448
- const objectCount = this.stars.objects.length;
2726
+ const objectCount = this.difficultyCalculator.objects.length;
2449
2727
  const calculatedAR = this.mapStatistics.ar;
2450
- 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)
2451
2729
  ? 0.8
2452
2730
  : 1));
2453
2731
  // Longer maps are worth more
@@ -2457,7 +2735,8 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2457
2735
  }
2458
2736
  this.aim *= lengthBonus;
2459
2737
  if (this.effectiveMissCount > 0) {
2460
- // 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.
2461
2740
  this.aim *=
2462
2741
  0.97 *
2463
2742
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), this.effectiveMissCount);
@@ -2475,7 +2754,7 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2475
2754
  // Buff for longer maps with high AR.
2476
2755
  this.aim *= 1 + arFactor * lengthBonus;
2477
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.
2478
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2757
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModHidden)) {
2479
2758
  this.aim *= 1 + 0.04 * (12 - calculatedAR);
2480
2759
  }
2481
2760
  // Scale the aim value with slider factor to nerf very likely dropped sliderends.
@@ -2491,10 +2770,10 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2491
2770
  */
2492
2771
  calculateSpeedValue() {
2493
2772
  // Global variables
2494
- const objectCount = this.stars.objects.length;
2773
+ const objectCount = this.difficultyCalculator.objects.length;
2495
2774
  const calculatedAR = this.mapStatistics.ar;
2496
2775
  const n50 = this.computedAccuracy.n50;
2497
- this.speed = this.baseValue(this.stars.speed);
2776
+ this.speed = this.baseValue(this.difficultyCalculator.speed);
2498
2777
  // Longer maps are worth more
2499
2778
  let lengthBonus = 0.95 + 0.4 * Math.min(1, objectCount / 2000);
2500
2779
  if (objectCount > 2000) {
@@ -2502,7 +2781,8 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2502
2781
  }
2503
2782
  this.speed *= lengthBonus;
2504
2783
  if (this.effectiveMissCount > 0) {
2505
- // 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.
2506
2786
  this.speed *=
2507
2787
  0.97 *
2508
2788
  Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), Math.pow(this.effectiveMissCount, 0.875));
@@ -2514,7 +2794,7 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2514
2794
  // Buff for longer maps with high AR.
2515
2795
  this.speed *= 1 + 0.3 * (calculatedAR - 10.33) * lengthBonus;
2516
2796
  }
2517
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2797
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModHidden)) {
2518
2798
  this.speed *= 1 + 0.04 * (12 - calculatedAR);
2519
2799
  }
2520
2800
  // Scale the speed value with accuracy and OD.
@@ -2528,21 +2808,21 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2528
2808
  * Calculates the accuracy performance value of the beatmap.
2529
2809
  */
2530
2810
  calculateAccuracyValue() {
2531
- if (this.stars.mods.some((m) => m instanceof osuBase.ModRelax)) {
2811
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModRelax)) {
2532
2812
  return;
2533
2813
  }
2534
2814
  // Global variables
2535
- const nobjects = this.stars.objects.length;
2536
- const ncircles = this.stars.mods.some((m) => m instanceof osuBase.ModScoreV2)
2537
- ? nobjects - this.stars.map.hitObjects.spinners
2538
- : 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;
2539
2819
  if (ncircles === 0) {
2540
2820
  return;
2541
2821
  }
2542
2822
  const realAccuracy = new osuBase.Accuracy({
2543
2823
  ...this.computedAccuracy,
2544
2824
  n300: this.computedAccuracy.n300 -
2545
- (this.stars.objects.length - ncircles),
2825
+ (this.difficultyCalculator.objects.length - ncircles),
2546
2826
  });
2547
2827
  // Lots of arbitrary values from testing.
2548
2828
  // Considering to use derivation from perfect accuracy in a probabilistic manner - assume normal distribution
@@ -2552,10 +2832,10 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2552
2832
  2.83;
2553
2833
  // Bonus for many hitcircles - it's harder to keep good accuracy up for longer
2554
2834
  this.accuracy *= Math.min(1.15, Math.pow(ncircles / 1000, 0.3));
2555
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2835
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModHidden)) {
2556
2836
  this.accuracy *= 1.08;
2557
2837
  }
2558
- if (this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2838
+ if (this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2559
2839
  this.accuracy *= 1.02;
2560
2840
  }
2561
2841
  }
@@ -2563,19 +2843,15 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2563
2843
  * Calculates the flashlight performance value of the beatmap.
2564
2844
  */
2565
2845
  calculateFlashlightValue() {
2566
- if (!this.stars.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2846
+ if (!this.difficultyCalculator.mods.some((m) => m instanceof osuBase.ModFlashlight)) {
2567
2847
  return;
2568
2848
  }
2569
2849
  // Global variables
2570
- const objectCount = this.stars.objects.length;
2850
+ const objectCount = this.difficultyCalculator.objects.length;
2571
2851
  this.flashlight =
2572
- 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)
2573
2853
  ? 0.8
2574
2854
  : 1), 2) * 25;
2575
- // Add an additional bonus for HDFL.
2576
- if (this.stars.mods.some((m) => m instanceof osuBase.ModHidden)) {
2577
- this.flashlight *= 1.3;
2578
- }
2579
2855
  // Combo scaling
2580
2856
  this.flashlight *= this.comboPenalty;
2581
2857
  if (this.effectiveMissCount > 0) {
@@ -2611,21 +2887,34 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
2611
2887
  }
2612
2888
  }
2613
2889
 
2890
+ exports.AimEvaluator = AimEvaluator;
2891
+ exports.DifficultyCalculator = DifficultyCalculator;
2614
2892
  exports.DifficultyHitObject = DifficultyHitObject;
2615
2893
  exports.DifficultyHitObjectCreator = DifficultyHitObjectCreator;
2616
2894
  exports.DroidAim = DroidAim;
2895
+ exports.DroidAimEvaluator = DroidAimEvaluator;
2896
+ exports.DroidDifficultyCalculator = DroidDifficultyCalculator;
2617
2897
  exports.DroidFlashlight = DroidFlashlight;
2898
+ exports.DroidFlashlightEvaluator = DroidFlashlightEvaluator;
2618
2899
  exports.DroidPerformanceCalculator = DroidPerformanceCalculator;
2619
2900
  exports.DroidRhythm = DroidRhythm;
2620
- exports.DroidStarRating = DroidStarRating;
2901
+ exports.DroidRhythmEvaluator = DroidRhythmEvaluator;
2621
2902
  exports.DroidTap = DroidTap;
2903
+ exports.DroidTapEvaluator = DroidTapEvaluator;
2622
2904
  exports.DroidVisual = DroidVisual;
2905
+ exports.DroidVisualEvaluator = DroidVisualEvaluator;
2906
+ exports.FlashlightEvaluator = FlashlightEvaluator;
2623
2907
  exports.MapStars = MapStars;
2624
2908
  exports.OsuAim = OsuAim;
2909
+ exports.OsuAimEvaluator = OsuAimEvaluator;
2910
+ exports.OsuDifficultyCalculator = OsuDifficultyCalculator;
2625
2911
  exports.OsuFlashlight = OsuFlashlight;
2912
+ exports.OsuFlashlightEvaluator = OsuFlashlightEvaluator;
2626
2913
  exports.OsuPerformanceCalculator = OsuPerformanceCalculator;
2914
+ exports.OsuRhythmEvaluator = OsuRhythmEvaluator;
2627
2915
  exports.OsuSpeed = OsuSpeed;
2628
- exports.OsuStarRating = OsuStarRating;
2916
+ exports.OsuSpeedEvaluator = OsuSpeedEvaluator;
2629
2917
  exports.PerformanceCalculator = PerformanceCalculator;
2630
- exports.StarRating = StarRating;
2918
+ exports.RhythmEvaluator = RhythmEvaluator;
2919
+ exports.SpeedEvaluator = SpeedEvaluator;
2631
2920
  //# sourceMappingURL=index.js.map