@rian8337/osu-rebalance-difficulty-calculator 4.0.0-beta.25 → 4.0.0-beta.27

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
@@ -32,6 +32,12 @@ AimEvaluator.velocityChangeMultiplier = 0.75;
32
32
  * The base of a difficulty calculator.
33
33
  */
34
34
  class DifficultyCalculator {
35
+ /**
36
+ * The difficulty objects of the beatmap.
37
+ */
38
+ get objects() {
39
+ return this._objects;
40
+ }
35
41
  /**
36
42
  * The total star rating of the beatmap.
37
43
  */
@@ -41,13 +47,13 @@ class DifficultyCalculator {
41
47
  /**
42
48
  * Constructs a new instance of the calculator.
43
49
  *
44
- * @param beatmap The beatmap to calculate. This beatmap will be deep-cloned to prevent reference changes.
50
+ * @param beatmap The beatmap to calculate.
45
51
  */
46
52
  constructor(beatmap) {
47
53
  /**
48
54
  * The difficulty objects of the beatmap.
49
55
  */
50
- this.objects = [];
56
+ this._objects = [];
51
57
  /**
52
58
  * The modifications applied.
53
59
  */
@@ -62,13 +68,6 @@ class DifficultyCalculator {
62
68
  flashlight: [],
63
69
  };
64
70
  this.beatmap = beatmap;
65
- this.difficultyStatistics = {
66
- circleSize: beatmap.difficulty.cs,
67
- approachRate: beatmap.difficulty.ar,
68
- overallDifficulty: beatmap.difficulty.od,
69
- healthDrain: beatmap.difficulty.hp,
70
- overallSpeedMultiplier: 1,
71
- };
72
71
  }
73
72
  /**
74
73
  * Calculates the star rating of the specified beatmap.
@@ -93,9 +92,9 @@ class DifficultyCalculator {
93
92
  mods: this.mods,
94
93
  customSpeedMultiplier: options === null || options === void 0 ? void 0 : options.customSpeedMultiplier,
95
94
  });
96
- this.difficultyStatistics = Object.seal(this.computeDifficultyStatistics(options));
97
- this.populateDifficultyAttributes();
98
- this.objects.push(...this.generateDifficultyHitObjects(playableBeatmap));
95
+ const clockRate = this.calculateClockRate(options);
96
+ this.populateDifficultyAttributes(playableBeatmap, clockRate);
97
+ this._objects = this.generateDifficultyHitObjects(playableBeatmap, clockRate);
99
98
  this.calculateAll();
100
99
  return this;
101
100
  }
@@ -112,20 +111,40 @@ class DifficultyCalculator {
112
111
  }
113
112
  }
114
113
  }
114
+ /**
115
+ * Obtains the clock rate of the beatmap.
116
+ *
117
+ * @param options The options to obtain the clock rate with.
118
+ * @returns The clock rate of the beatmap.
119
+ */
120
+ calculateClockRate(options) {
121
+ var _a, _b;
122
+ return (osuBase.ModUtil.calculateRateWithMods((_a = options === null || options === void 0 ? void 0 : options.mods) !== null && _a !== void 0 ? _a : []) *
123
+ ((_b = options === null || options === void 0 ? void 0 : options.customSpeedMultiplier) !== null && _b !== void 0 ? _b : 1));
124
+ }
115
125
  /**
116
126
  * Populates the stored difficulty attributes with necessary data.
127
+ *
128
+ * @param beatmap The beatmap to populate the attributes with.
129
+ * @param clockRate The clock rate of the beatmap.
117
130
  */
118
- populateDifficultyAttributes() {
119
- this.attributes.approachRate = this.difficultyStatistics.approachRate;
131
+ populateDifficultyAttributes(beatmap, clockRate) {
120
132
  this.attributes.hitCircleCount = this.beatmap.hitObjects.circles;
121
133
  this.attributes.maxCombo = this.beatmap.maxCombo;
122
134
  this.attributes.mods = this.mods.slice();
123
- this.attributes.overallDifficulty =
124
- this.difficultyStatistics.overallDifficulty;
125
135
  this.attributes.sliderCount = this.beatmap.hitObjects.sliders;
126
136
  this.attributes.spinnerCount = this.beatmap.hitObjects.spinners;
127
- this.attributes.clockRate =
128
- this.difficultyStatistics.overallSpeedMultiplier;
137
+ this.attributes.clockRate = clockRate;
138
+ let greatWindow;
139
+ switch (this.mode) {
140
+ case osuBase.Modes.droid:
141
+ greatWindow = new osuBase.DroidHitWindow(beatmap.difficulty.od).hitWindowFor300(this.mods.some((m) => m instanceof osuBase.ModPrecise));
142
+ break;
143
+ case osuBase.Modes.osu:
144
+ greatWindow = new osuBase.OsuHitWindow(beatmap.difficulty.od).hitWindowFor300();
145
+ break;
146
+ }
147
+ this.attributes.overallDifficulty = osuBase.OsuHitWindow.hitWindow300ToOD(greatWindow / clockRate);
129
148
  }
130
149
  /**
131
150
  * Calculates the star rating value of a difficulty.
@@ -668,11 +687,19 @@ class StrainSkill extends Skill {
668
687
  * Strain peaks are stored here.
669
688
  */
670
689
  this.strainPeaks = [];
690
+ this._objectStrains = [];
691
+ this.difficulty = 0;
671
692
  this.sectionLength = 400;
672
693
  this.currentStrain = 0;
673
694
  this.currentSectionPeak = 0;
674
695
  this.currentSectionEnd = 0;
675
696
  }
697
+ /**
698
+ * The strains of hitobjects.
699
+ */
700
+ get objectStrains() {
701
+ return this._objectStrains;
702
+ }
676
703
  process(current) {
677
704
  // The first object doesn't generate a strain, so we begin with an incremented section end
678
705
  if (current.index === 0) {
@@ -698,6 +725,21 @@ class StrainSkill extends Skill {
698
725
  saveCurrentPeak() {
699
726
  this.strainPeaks.push(this.currentSectionPeak);
700
727
  }
728
+ /**
729
+ * Returns the number of strains weighed against the top strain.
730
+ *
731
+ * The result is scaled by clock rate as it affects the total number of strains.
732
+ */
733
+ countDifficultStrains() {
734
+ if (this.difficulty === 0) {
735
+ return 0;
736
+ }
737
+ // This is what the top strain is if all strain values were identical.
738
+ const consistentTopStrain = this.difficulty / 10;
739
+ // Use a weighted sum of all strains.
740
+ return this._objectStrains.reduce((total, next) => total +
741
+ 1.1 / (1 + Math.exp(-10 * (next / consistentTopStrain - 0.88))), 0);
742
+ }
701
743
  /**
702
744
  * Calculates strain decay for a specified time frame.
703
745
  *
@@ -740,29 +782,6 @@ class DroidSkill extends StrainSkill {
740
782
  * The minimum number of strains to judge when computing for retryability.
741
783
  */
742
784
  this.minimumRetryabilityStrains = 500;
743
- this._objectStrains = [];
744
- this.difficulty = 0;
745
- }
746
- /**
747
- * The strains of hitobjects.
748
- */
749
- get objectStrains() {
750
- return this._objectStrains;
751
- }
752
- /**
753
- * Returns the number of strains weighed against the top strain.
754
- *
755
- * The result is scaled by clock rate as it affects the total number of strains.
756
- */
757
- countDifficultStrains() {
758
- if (this.difficulty === 0) {
759
- return 0;
760
- }
761
- // This is what the top strain is if all strain values were identical.
762
- const consistentTopStrain = this.difficulty / 10;
763
- // Use a weighted sum of all strains.
764
- return this._objectStrains.reduce((total, next) => total +
765
- 1.1 / (1 + Math.exp(-10 * (next / consistentTopStrain - 0.88))), 0);
766
785
  }
767
786
  /**
768
787
  * Computes the retryability of the beatmap based on the strains of the hitobjects.
@@ -1111,7 +1130,7 @@ class DroidFlashlight extends DroidSkill {
1111
1130
  this.reducedSectionCount = 0;
1112
1131
  this.reducedSectionBaseline = 1;
1113
1132
  this.starsPerDouble = 1.06;
1114
- this.skillMultiplier = 0.052;
1133
+ this.skillMultiplier = 0.02;
1115
1134
  this.currentFlashlightStrain = 0;
1116
1135
  this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
1117
1136
  this.withSliders = withSliders;
@@ -1140,64 +1159,42 @@ class DroidFlashlight extends DroidSkill {
1140
1159
  }
1141
1160
  }
1142
1161
  difficultyValue() {
1143
- return Math.pow(this.strainPeaks.reduce((a, v) => a + v, 0) * this.starsPerDouble, 0.8);
1162
+ return (this.strainPeaks.reduce((a, v) => a + v, 0) * this.starsPerDouble);
1144
1163
  }
1145
1164
  }
1146
1165
 
1147
- /**
1148
- * An evaluator for calculating rhythm skill.
1149
- *
1150
- * This class should be considered an "evaluating" class and not persisted.
1151
- */
1152
- class RhythmEvaluator {
1153
- }
1154
- RhythmEvaluator.rhythmMultiplier = 0.75;
1155
- RhythmEvaluator.historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1156
-
1157
- class Island {
1158
- constructor(firstDelta, epsilon) {
1159
- this.deltas = [];
1160
- if (epsilon === undefined) {
1161
- this.deltaDifferenceEpsilon = firstDelta;
1162
- return;
1166
+ let Island$1 = class Island {
1167
+ constructor(delta, deltaDifferenceEpsilon) {
1168
+ this.delta = Number.MAX_SAFE_INTEGER;
1169
+ this.deltaCount = 0;
1170
+ if (deltaDifferenceEpsilon === undefined) {
1171
+ this.deltaDifferenceEpsilon = delta;
1172
+ }
1173
+ else {
1174
+ this.deltaDifferenceEpsilon = deltaDifferenceEpsilon;
1175
+ this.addDelta(delta);
1163
1176
  }
1164
- this.deltaDifferenceEpsilon = epsilon;
1165
- this.addDelta(firstDelta);
1166
1177
  }
1167
1178
  addDelta(delta) {
1168
- // Convert to integer
1169
- delta = Math.trunc(delta);
1170
- const existingDelta = this.deltas.find((v) => Math.abs(v - delta) >= this.deltaDifferenceEpsilon);
1171
- this.deltas.push(existingDelta !== null && existingDelta !== void 0 ? existingDelta : delta);
1172
- }
1173
- get averageDelta() {
1174
- return this.deltas.length > 0
1175
- ? Math.max(this.deltas.reduce((a, b) => a + b) / this.deltas.length, DifficultyHitObject.minDeltaTime)
1176
- : 0;
1179
+ if (this.delta === Number.MAX_SAFE_INTEGER) {
1180
+ this.delta = Math.max(Math.trunc(delta), DifficultyHitObject.minDeltaTime);
1181
+ }
1182
+ ++this.deltaCount;
1177
1183
  }
1178
1184
  isSimilarPolarity(other) {
1179
- // Consider islands to be of similar polarity only if they're having the same
1180
- // average delta (we don't want to consider 3 singletaps similar to a triple)
1181
- return (Math.abs(this.averageDelta - other.averageDelta) <
1182
- this.deltaDifferenceEpsilon &&
1183
- this.deltas.length % 2 === other.deltas.length % 2);
1185
+ // TODO: consider islands to be of similar polarity only if they're having the same average delta (we don't want to consider 3 singletaps similar to a triple)
1186
+ // naively adding delta check here breaks _a lot_ of maps because of the flawed ratio calculation
1187
+ return this.deltaCount % 2 == other.deltaCount % 2;
1184
1188
  }
1185
1189
  equals(other) {
1186
- if (this.deltas.length !== other.deltas.length) {
1187
- return false;
1188
- }
1189
- for (let i = 0; i < this.deltas.length; ++i) {
1190
- if (this.deltas[i] !== other.deltas[i]) {
1191
- return false;
1192
- }
1193
- }
1194
- return true;
1190
+ return (Math.abs(this.delta - other.delta) < this.deltaDifferenceEpsilon &&
1191
+ this.deltaCount === other.deltaCount);
1195
1192
  }
1196
- }
1193
+ };
1197
1194
  /**
1198
1195
  * An evaluator for calculating osu!droid Rhythm skill.
1199
1196
  */
1200
- class DroidRhythmEvaluator extends RhythmEvaluator {
1197
+ class DroidRhythmEvaluator {
1201
1198
  /**
1202
1199
  * Calculates a rhythm multiplier for the difficulty of the tap associated
1203
1200
  * with historic data of the current object.
@@ -1205,15 +1202,13 @@ class DroidRhythmEvaluator extends RhythmEvaluator {
1205
1202
  * @param current The current object.
1206
1203
  */
1207
1204
  static evaluateDifficultyOf(current) {
1208
- if (current.object instanceof osuBase.Spinner ||
1209
- // Exclude overlapping objects that can be tapped at once.
1210
- current.isOverlapping(false)) {
1205
+ if (current.object instanceof osuBase.Spinner) {
1211
1206
  return 1;
1212
1207
  }
1213
1208
  const deltaDifferenceEpsilon = current.fullGreatWindow * 0.3;
1214
1209
  let rhythmComplexitySum = 0;
1215
- let island = new Island(deltaDifferenceEpsilon);
1216
- let previousIsland = new Island(deltaDifferenceEpsilon);
1210
+ let island = new Island$1(deltaDifferenceEpsilon);
1211
+ let previousIsland = new Island$1(deltaDifferenceEpsilon);
1217
1212
  const islandCounts = new Map();
1218
1213
  // Store the ratio of the current start of an island to buff for tighter rhythms.
1219
1214
  let startRatio = 0;
@@ -1237,47 +1232,50 @@ class DroidRhythmEvaluator extends RhythmEvaluator {
1237
1232
  ++rhythmStart;
1238
1233
  }
1239
1234
  for (let i = rhythmStart; i > 0; --i) {
1240
- // Scale note 0 to 1 from history to now.
1241
- let currentHistoricalDecay = (this.historyTimeMax -
1242
- (current.startTime - validPrevious[i - 1].startTime)) /
1243
- this.historyTimeMax;
1244
- // Either we're limited by time or limited by object count.
1245
- currentHistoricalDecay = Math.min(currentHistoricalDecay, (validPrevious.length - i) / validPrevious.length);
1246
1235
  const currentObject = validPrevious[i - 1];
1247
1236
  const prevObject = validPrevious[i];
1248
1237
  const lastObject = validPrevious[i + 1];
1238
+ // Scale note 0 to 1 from history to now.
1239
+ const timeDecay = (this.historyTimeMax -
1240
+ (current.startTime - currentObject.startTime)) /
1241
+ this.historyTimeMax;
1242
+ const noteDecay = (validPrevious.length - i) / validPrevious.length;
1243
+ // Either we're limited by time or limited by object count.
1244
+ const currentHistoricalDecay = Math.min(timeDecay, noteDecay);
1249
1245
  const currentDelta = currentObject.strainTime;
1250
1246
  const prevDelta = prevObject.strainTime;
1251
1247
  const lastDelta = lastObject.strainTime;
1248
+ // Calculate how much current delta difference deserves a rhythm bonus
1249
+ // This function is meant to reduce rhythm bonus for deltas that are multiples of each other (i.e. 100 and 200)
1250
+ const deltaDifferenceRatio = Math.min(prevDelta, currentDelta) /
1251
+ Math.max(prevDelta, currentDelta);
1252
1252
  const currentRatio = 1 +
1253
- 10 *
1254
- Math.min(0.5, Math.pow(Math.sin(Math.PI /
1255
- (Math.min(prevDelta, currentDelta) /
1256
- Math.max(prevDelta, currentDelta))), 2));
1257
- const windowPenalty = osuBase.MathUtils.clamp((Math.abs(prevDelta - currentDelta) - deltaDifferenceEpsilon) /
1258
- deltaDifferenceEpsilon, 0, 1);
1259
- let effectiveRatio = windowPenalty * currentRatio;
1253
+ this.rhythmRatioMultiplier *
1254
+ Math.min(0.5, Math.pow(Math.sin(Math.PI / deltaDifferenceRatio), 2));
1255
+ // Reduce ratio bonus if delta difference is too big
1256
+ const fraction = Math.max(prevDelta / currentDelta, currentDelta / prevDelta);
1257
+ const fractionMultiplier = osuBase.MathUtils.clamp(2 - fraction / 8, 0, 1);
1258
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - deltaDifferenceEpsilon) / deltaDifferenceEpsilon);
1259
+ let effectiveRatio = windowPenalty * currentRatio * fractionMultiplier;
1260
1260
  if (firstDeltaSwitch) {
1261
- if (Math.abs(prevDelta - currentDelta) <= deltaDifferenceEpsilon) {
1262
- if (island.deltas.length < this.maxIslandSize) {
1263
- // Island is still progressing.
1264
- island.addDelta(currentDelta);
1265
- }
1261
+ if (Math.abs(prevDelta - currentDelta) < deltaDifferenceEpsilon) {
1262
+ // Island is still progressing, count size.
1263
+ island.addDelta(currentDelta);
1266
1264
  }
1267
1265
  else {
1268
1266
  // BPM change is into slider, this is easy acc window.
1269
1267
  if (currentObject.object instanceof osuBase.Slider) {
1270
1268
  effectiveRatio /= 8;
1271
1269
  }
1272
- // BPM change was from a slider, this is typically easier than circle -> circle.
1273
- // Unintentional side effect is that bursts with kicksliders at the ends might
1274
- // have lower difficulty than bursts without sliders.
1270
+ // BPM change was from a slider, this is easier typically than circle -> circle.
1271
+ // Unintentional side effect is that bursts with kicksliders at the ends might have lower difficulty
1272
+ // than bursts without sliders.
1275
1273
  if (prevObject.object instanceof osuBase.Slider) {
1276
- effectiveRatio /= 4;
1274
+ effectiveRatio *= 0.3;
1277
1275
  }
1278
1276
  // Repeated island polarity (2 -> 4, 3 -> 5).
1279
1277
  if (island.isSimilarPolarity(previousIsland)) {
1280
- effectiveRatio *= 0.3;
1278
+ effectiveRatio /= 2;
1281
1279
  }
1282
1280
  // Previous increase happened a note ago.
1283
1281
  // Albeit this is a 1/1 -> 1/2-1/4 type of transition, we don't want to buff this.
@@ -1285,8 +1283,9 @@ class DroidRhythmEvaluator extends RhythmEvaluator {
1285
1283
  prevDelta > currentDelta + deltaDifferenceEpsilon) {
1286
1284
  effectiveRatio /= 8;
1287
1285
  }
1288
- // Singletaps are easier to control.
1289
- if (island.deltas.length === 1) {
1286
+ // Repeated island size (ex: triplet -> triplet).
1287
+ // TODO: remove this nerf since its staying here only for balancing purposes because of the flawed ratio calculation
1288
+ if (previousIsland.deltaCount == island.deltaCount) {
1290
1289
  effectiveRatio /= 2;
1291
1290
  }
1292
1291
  let islandFound = false;
@@ -1303,9 +1302,7 @@ class DroidRhythmEvaluator extends RhythmEvaluator {
1303
1302
  }
1304
1303
  // Repeated island (ex: triplet -> triplet).
1305
1304
  // Graph: https://www.desmos.com/calculator/pj7an56zwf
1306
- effectiveRatio *= Math.min(1 / islandCount, Math.pow(1 / islandCount, 4 /
1307
- (1 +
1308
- Math.exp(10 - 0.165 * island.averageDelta))));
1305
+ effectiveRatio *= Math.min(3 / islandCount, Math.pow(1 / islandCount, 2.75 / (1 + Math.exp(14 - 0.24 * island.delta))));
1309
1306
  break;
1310
1307
  }
1311
1308
  if (!islandFound) {
@@ -1323,28 +1320,35 @@ class DroidRhythmEvaluator extends RhythmEvaluator {
1323
1320
  // If we're speeding up, this stays as is and we keep counting island size.
1324
1321
  firstDeltaSwitch = false;
1325
1322
  }
1326
- island = new Island(Math.trunc(currentDelta), deltaDifferenceEpsilon);
1323
+ island = new Island$1(currentDelta, deltaDifferenceEpsilon);
1327
1324
  }
1328
1325
  }
1329
- else if (prevDelta > deltaDifferenceEpsilon + currentDelta) {
1330
- // We're speeding up.
1326
+ else if (prevDelta > currentDelta + deltaDifferenceEpsilon) {
1327
+ // We are speeding up.
1331
1328
  // Begin counting island until we change speed again.
1332
1329
  firstDeltaSwitch = true;
1333
- // Reduce ratio if we're starting after a slider.
1330
+ // BPM change is into slider, this is easy acc window.
1331
+ if (currentObject.object instanceof osuBase.Slider) {
1332
+ effectiveRatio *= 0.6;
1333
+ }
1334
+ // BPM change was from a slider, this is easier typically than circle -> circle
1335
+ // Unintentional side effect is that bursts with kicksliders at the ends might have lower difficulty
1336
+ // than bursts without sliders
1334
1337
  if (prevObject.object instanceof osuBase.Slider) {
1335
- effectiveRatio *= 0.3;
1338
+ effectiveRatio *= 0.6;
1336
1339
  }
1337
1340
  startRatio = effectiveRatio;
1338
- island = new Island(Math.trunc(currentDelta), deltaDifferenceEpsilon);
1341
+ island = new Island$1(currentDelta, deltaDifferenceEpsilon);
1339
1342
  }
1340
1343
  }
1341
- return Math.sqrt(4 + rhythmComplexitySum * this.rhythmMultiplier) / 2;
1344
+ return (Math.sqrt(4 + rhythmComplexitySum * this.rhythmOverallMultiplier) /
1345
+ 2);
1342
1346
  }
1343
1347
  }
1344
- DroidRhythmEvaluator.rhythmMultiplier = 1.2;
1345
- DroidRhythmEvaluator.historyTimeMax = 4000;
1346
- DroidRhythmEvaluator.maxIslandSize = 7;
1347
- DroidRhythmEvaluator.historyObjectsMax = 24;
1348
+ DroidRhythmEvaluator.historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
1349
+ DroidRhythmEvaluator.historyObjectsMax = 32;
1350
+ DroidRhythmEvaluator.rhythmOverallMultiplier = 0.95;
1351
+ DroidRhythmEvaluator.rhythmRatioMultiplier = 12;
1348
1352
 
1349
1353
  /**
1350
1354
  * Represents the skill required to properly follow a beatmap's rhythm.
@@ -1546,9 +1550,8 @@ class DroidDifficultyHitObject extends DifficultyHitObject {
1546
1550
  * @param difficultyHitObjects All difficulty hitobjects in the processed beatmap.
1547
1551
  * @param clockRate The clock rate of the beatmap.
1548
1552
  * @param greatWindow The great window of the hitobject.
1549
- * @param isForceAR Whether force AR is enabled.
1550
1553
  */
1551
- constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate, greatWindow, isForceAR) {
1554
+ constructor(object, lastObject, lastLastObject, difficultyHitObjects, clockRate, greatWindow) {
1552
1555
  super(object, lastObject, lastLastObject, difficultyHitObjects, clockRate, greatWindow);
1553
1556
  /**
1554
1557
  * The tap strain generated by the hitobject.
@@ -1592,10 +1595,7 @@ class DroidDifficultyHitObject extends DifficultyHitObject {
1592
1595
  this.radiusBuffThreshold = 70;
1593
1596
  this.mode = osuBase.Modes.droid;
1594
1597
  this.maximumSliderRadius = this.normalizedRadius * 2;
1595
- this.timePreempt = object.timePreempt;
1596
- if (!isForceAR) {
1597
- this.timePreempt /= clockRate;
1598
- }
1598
+ this.timePreempt = object.timePreempt / clockRate;
1599
1599
  }
1600
1600
  computeProperties(clockRate, hitObjects) {
1601
1601
  super.computeProperties(clockRate, hitObjects);
@@ -1607,6 +1607,9 @@ class DroidDifficultyHitObject extends DifficultyHitObject {
1607
1607
  * Keep in mind that "overlapping" in this case is overlapping to the point where both hitobjects
1608
1608
  * can be hit with just a single tap in osu!droid.
1609
1609
  *
1610
+ * In the case of sliders, it is considered overlapping if all nested hitobjects can be hit with
1611
+ * one aim motion.
1612
+ *
1610
1613
  * @param considerDistance Whether to consider the distance between both hitobjects.
1611
1614
  * @returns Whether the hitobject is considered overlapping.
1612
1615
  */
@@ -1614,23 +1617,48 @@ class DroidDifficultyHitObject extends DifficultyHitObject {
1614
1617
  if (this.object instanceof osuBase.Spinner) {
1615
1618
  return false;
1616
1619
  }
1617
- const previous = this.previous(0);
1618
- if (!previous || previous.object instanceof osuBase.Spinner) {
1620
+ const prev = this.previous(0);
1621
+ if (!prev || prev.object instanceof osuBase.Spinner) {
1622
+ return false;
1623
+ }
1624
+ if (this.object.startTime !== prev.object.startTime) {
1619
1625
  return false;
1620
1626
  }
1621
- if (this.deltaTime >= 5) {
1627
+ if (!considerDistance) {
1628
+ return true;
1629
+ }
1630
+ const distanceThreshold = 2 * this.object.radius;
1631
+ const startPosition = this.object.getStackedPosition(osuBase.Modes.droid);
1632
+ const prevStartPosition = prev.object.getStackedPosition(osuBase.Modes.droid);
1633
+ // We need to consider two cases:
1634
+ //
1635
+ // Case 1: Current object is a circle, or previous object is a circle.
1636
+ // In this case, we only need to check if their positions are close enough to be tapped together.
1637
+ //
1638
+ // Case 2: Both objects are sliders.
1639
+ // In this case, we need to check if all nested hitobjects can be hit together.
1640
+ // To start with, check if the starting positions can be tapped together.
1641
+ if (startPosition.getDistance(prevStartPosition) > distanceThreshold) {
1622
1642
  return false;
1623
1643
  }
1624
- if (considerDistance) {
1625
- const endPosition = this.object.getStackedPosition(osuBase.Modes.droid);
1626
- let distance = previous.object
1627
- .getStackedEndPosition(osuBase.Modes.droid)
1628
- .getDistance(endPosition);
1629
- if (previous.object instanceof osuBase.Slider &&
1630
- previous.object.lazyEndPosition) {
1631
- distance = Math.min(distance, previous.object.lazyEndPosition.getDistance(endPosition));
1644
+ if (this.object instanceof osuBase.Circle || prev.object instanceof osuBase.Circle) {
1645
+ return true;
1646
+ }
1647
+ // Check if all nested hitobjects can be hit together.
1648
+ for (let i = 1; i < this.object.nestedHitObjects.length; ++i) {
1649
+ const position = this.object.nestedHitObjects[i].getStackedPosition(osuBase.Modes.droid);
1650
+ const prevPosition = prevStartPosition.add(prev.object.curvePositionAt(i / (this.object.nestedHitObjects.length - 1)));
1651
+ if (position.getDistance(prevPosition) > distanceThreshold) {
1652
+ return false;
1653
+ }
1654
+ }
1655
+ // Do the same for the previous slider as well.
1656
+ for (let i = 1; i < prev.object.nestedHitObjects.length; ++i) {
1657
+ const prevPosition = prev.object.nestedHitObjects[i].getStackedPosition(osuBase.Modes.droid);
1658
+ const position = startPosition.add(this.object.curvePositionAt(i / (prev.object.nestedHitObjects.length - 1)));
1659
+ if (prevPosition.getDistance(position) > distanceThreshold) {
1660
+ return false;
1632
1661
  }
1633
- return distance <= 2 * this.object.radius;
1634
1662
  }
1635
1663
  return true;
1636
1664
  }
@@ -1714,7 +1742,6 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1714
1742
  speedNoteCount: 0,
1715
1743
  sliderFactor: 0,
1716
1744
  clockRate: 1,
1717
- approachRate: 0,
1718
1745
  overallDifficulty: 0,
1719
1746
  hitCircleCount: 0,
1720
1747
  sliderCount: 0,
@@ -1764,30 +1791,11 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1764
1791
  return this.attributes.visualDifficulty;
1765
1792
  }
1766
1793
  get cacheableAttributes() {
1767
- return {
1768
- tapDifficulty: this.tap,
1769
- rhythmDifficulty: this.rhythm,
1770
- visualDifficulty: this.visual,
1771
- mods: osuBase.ModUtil.modsToOsuString(this.attributes.mods),
1772
- starRating: this.total,
1773
- maxCombo: this.attributes.maxCombo,
1774
- aimDifficulty: this.aim,
1775
- flashlightDifficulty: this.flashlight,
1776
- speedNoteCount: this.attributes.speedNoteCount,
1777
- sliderFactor: this.attributes.sliderFactor,
1778
- clockRate: this.attributes.clockRate,
1779
- approachRate: this.attributes.approachRate,
1780
- overallDifficulty: this.attributes.overallDifficulty,
1781
- hitCircleCount: this.attributes.hitCircleCount,
1782
- sliderCount: this.attributes.sliderCount,
1783
- spinnerCount: this.attributes.spinnerCount,
1784
- aimDifficultStrainCount: this.attributes.aimDifficultStrainCount,
1785
- tapDifficultStrainCount: this.attributes.tapDifficultStrainCount,
1786
- flashlightDifficultStrainCount: this.attributes.flashlightDifficultStrainCount,
1787
- visualDifficultStrainCount: this.attributes.visualDifficultStrainCount,
1788
- averageSpeedDeltaTime: this.attributes.averageSpeedDeltaTime,
1789
- vibroFactor: this.attributes.vibroFactor,
1790
- };
1794
+ return Object.assign(Object.assign({}, this.attributes), { mods: osuBase.ModUtil.modsToOsuString(this.attributes.mods) });
1795
+ }
1796
+ // Override to use DroidDifficultyCalculationOptions
1797
+ calculate(options) {
1798
+ return super.calculate(options);
1791
1799
  }
1792
1800
  /**
1793
1801
  * Calculates the aim star rating of the beatmap and stores it in this instance.
@@ -1896,31 +1904,19 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1896
1904
  this.visual.toFixed(2) +
1897
1905
  " visual)");
1898
1906
  }
1899
- generateDifficultyHitObjects(convertedBeatmap) {
1907
+ generateDifficultyHitObjects(beatmap, clockRate) {
1900
1908
  var _a, _b;
1901
1909
  const difficultyObjects = [];
1902
- const { objects } = convertedBeatmap.hitObjects;
1903
- const difficultyAdjustMod = this.mods.find((m) => m instanceof osuBase.ModDifficultyAdjust);
1904
- const greatWindow = new osuBase.OsuHitWindow(this.difficultyStatistics.overallDifficulty).hitWindowFor300();
1910
+ const { objects } = beatmap.hitObjects;
1911
+ const isPrecise = this.mods.some((m) => m instanceof osuBase.ModPrecise);
1912
+ const greatWindow = new osuBase.DroidHitWindow(beatmap.difficulty.od).hitWindowFor300(isPrecise) / clockRate;
1905
1913
  for (let i = 0; i < objects.length; ++i) {
1906
- const difficultyObject = new DroidDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, this.difficultyStatistics.overallSpeedMultiplier, greatWindow, (difficultyAdjustMod === null || difficultyAdjustMod === void 0 ? void 0 : difficultyAdjustMod.ar) !== undefined);
1907
- difficultyObject.computeProperties(this.difficultyStatistics.overallSpeedMultiplier, objects);
1914
+ const difficultyObject = new DroidDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, clockRate, greatWindow);
1915
+ difficultyObject.computeProperties(clockRate, objects);
1908
1916
  difficultyObjects.push(difficultyObject);
1909
1917
  }
1910
1918
  return difficultyObjects;
1911
1919
  }
1912
- computeDifficultyStatistics(options) {
1913
- const { difficulty } = this.beatmap;
1914
- return osuBase.calculateDroidDifficultyStatistics({
1915
- circleSize: difficulty.cs,
1916
- approachRate: difficulty.ar,
1917
- overallDifficulty: difficulty.od,
1918
- healthDrain: difficulty.hp,
1919
- mods: this.mods,
1920
- customSpeedMultiplier: options === null || options === void 0 ? void 0 : options.customSpeedMultiplier,
1921
- oldStatistics: options === null || options === void 0 ? void 0 : options.oldStatistics,
1922
- });
1923
- }
1924
1920
  createSkills() {
1925
1921
  return [
1926
1922
  new DroidAim(this.mods, true),
@@ -1937,6 +1933,10 @@ class DroidDifficultyCalculator extends DifficultyCalculator {
1937
1933
  new DroidVisual(this.mods, false),
1938
1934
  ];
1939
1935
  }
1936
+ calculateClockRate(options) {
1937
+ var _a, _b;
1938
+ return (osuBase.ModUtil.calculateRateWithMods((_a = options === null || options === void 0 ? void 0 : options.mods) !== null && _a !== void 0 ? _a : [], options === null || options === void 0 ? void 0 : options.oldStatistics) * ((_b = options === null || options === void 0 ? void 0 : options.customSpeedMultiplier) !== null && _b !== void 0 ? _b : 1));
1939
+ }
1940
1940
  /**
1941
1941
  * Called after aim skill calculation.
1942
1942
  *
@@ -2149,10 +2149,6 @@ class PerformanceCalculator {
2149
2149
  * The calculated accuracy.
2150
2150
  */
2151
2151
  this.computedAccuracy = new osuBase.Accuracy({});
2152
- /**
2153
- * Penalty for combo breaks.
2154
- */
2155
- this.comboPenalty = 0;
2156
2152
  /**
2157
2153
  * The amount of misses that are filtered out from sliderbreaks.
2158
2154
  */
@@ -2212,7 +2208,6 @@ class PerformanceCalculator {
2212
2208
  const maxCombo = this.difficultyAttributes.maxCombo;
2213
2209
  const miss = this.computedAccuracy.nmiss;
2214
2210
  const combo = (_a = options === null || options === void 0 ? void 0 : options.combo) !== null && _a !== void 0 ? _a : maxCombo - miss;
2215
- this.comboPenalty = Math.min(Math.pow(combo / maxCombo, 0.8), 1);
2216
2211
  if ((options === null || options === void 0 ? void 0 : options.accPercent) instanceof osuBase.Accuracy) {
2217
2212
  // Copy into new instance to not modify the original
2218
2213
  this.computedAccuracy = new osuBase.Accuracy(options.accPercent);
@@ -2275,6 +2270,22 @@ class PerformanceCalculator {
2275
2270
  this.difficultyAttributes.sliderFactor;
2276
2271
  }
2277
2272
  }
2273
+ /**
2274
+ * Calculates a strain-based miss penalty.
2275
+ *
2276
+ * Strain-based miss penalty assumes that a player will miss on the hardest parts of a map,
2277
+ * so we use the amount of relatively difficult sections to adjust miss penalty
2278
+ * to make it more punishing on maps with lower amount of hard sections.
2279
+ */
2280
+ calculateStrainBasedMissPenalty(difficultStrainCount) {
2281
+ if (this.effectiveMissCount === 0) {
2282
+ return 1;
2283
+ }
2284
+ return (0.96 /
2285
+ (this.effectiveMissCount /
2286
+ (4 * Math.pow(Math.log(difficultStrainCount), 0.94)) +
2287
+ 1));
2288
+ }
2278
2289
  /**
2279
2290
  * Calculates the amount of misses + sliderbreaks from combo.
2280
2291
  */
@@ -2618,22 +2629,6 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2618
2629
  visualValue *= 0.98 + Math.pow(5, 2) / 2500;
2619
2630
  return visualValue;
2620
2631
  }
2621
- /**
2622
- * Calculates a strain-based miss penalty.
2623
- *
2624
- * Strain-based miss penalty assumes that a player will miss on the hardest parts of a map,
2625
- * so we use the amount of relatively difficult sections to adjust miss penalty
2626
- * to make it more punishing on maps with lower amount of hard sections.
2627
- */
2628
- calculateStrainBasedMissPenalty(difficultStrainCount) {
2629
- if (this.effectiveMissCount === 0) {
2630
- return 1;
2631
- }
2632
- return (0.96 /
2633
- (this.effectiveMissCount /
2634
- (4 * Math.pow(Math.log(difficultStrainCount), 0.94)) +
2635
- 1));
2636
- }
2637
2632
  /**
2638
2633
  * The object-based proportional miss penalty.
2639
2634
  */
@@ -2844,13 +2839,6 @@ class DroidPerformanceCalculator extends PerformanceCalculator {
2844
2839
  * and to calculate a final difficulty value representing the difficulty of hitting all the processed objects.
2845
2840
  */
2846
2841
  class OsuSkill extends StrainSkill {
2847
- constructor() {
2848
- super(...arguments);
2849
- /**
2850
- * The final multiplier to be applied to the final difficulty value after all other calculations.
2851
- */
2852
- this.difficultyMultiplier = OsuSkill.defaultDifficultyMultiplier;
2853
- }
2854
2842
  difficultyValue() {
2855
2843
  const strains = this.strainPeaks
2856
2844
  .slice()
@@ -2865,25 +2853,19 @@ class OsuSkill extends StrainSkill {
2865
2853
  }
2866
2854
  // Difficulty is the weighted sum of the highest strains from every section.
2867
2855
  // We're sorting from highest to lowest strain.
2868
- let difficulty = 0;
2856
+ this.difficulty = 0;
2869
2857
  let weight = 1;
2870
2858
  for (const strain of strains) {
2871
2859
  const addition = strain * weight;
2872
- if (difficulty + addition === difficulty) {
2860
+ if (this.difficulty + addition === this.difficulty) {
2873
2861
  break;
2874
2862
  }
2875
- difficulty += addition;
2863
+ this.difficulty += addition;
2876
2864
  weight *= this.decayWeight;
2877
2865
  }
2878
- return difficulty * this.difficultyMultiplier;
2866
+ return this.difficulty;
2879
2867
  }
2880
2868
  }
2881
- /**
2882
- * The default multiplier applied to the final difficulty value after all other calculations.
2883
- *
2884
- * May be overridden via {@link difficultyMultiplier}.
2885
- */
2886
- OsuSkill.defaultDifficultyMultiplier = 1.06;
2887
2869
 
2888
2870
  /**
2889
2871
  * An evaluator for calculating osu!standard Aim skill.
@@ -3018,7 +3000,7 @@ class OsuAim extends OsuSkill {
3018
3000
  this.reducedSectionBaseline = 0.75;
3019
3001
  this.decayWeight = 0.9;
3020
3002
  this.currentAimStrain = 0;
3021
- this.skillMultiplier = 23.55;
3003
+ this.skillMultiplier = 25.18;
3022
3004
  this.withSliders = withSliders;
3023
3005
  }
3024
3006
  strainValueAt(current) {
@@ -3026,6 +3008,7 @@ class OsuAim extends OsuSkill {
3026
3008
  this.currentAimStrain +=
3027
3009
  OsuAimEvaluator.evaluateDifficultyOf(current, this.withSliders) *
3028
3010
  this.skillMultiplier;
3011
+ this._objectStrains.push(this.currentAimStrain);
3029
3012
  return this.currentAimStrain;
3030
3013
  }
3031
3014
  calculateInitialStrain(time, current) {
@@ -3071,29 +3054,65 @@ class OsuSpeedEvaluator extends SpeedEvaluator {
3071
3054
  // Cap deltatime to the OD 300 hitwindow.
3072
3055
  // 0.93 is derived from making sure 260 BPM 1/4 OD8 streams aren't nerfed harshly, whilst 0.92 limits the effect of the cap.
3073
3056
  strainTime /= osuBase.MathUtils.clamp(strainTime / current.fullGreatWindow / 0.93, 0.92, 1);
3074
- let speedBonus = 1;
3057
+ // speedBonus will be 0.0 for BPM < 200
3058
+ let speedBonus = 0;
3059
+ // Add additional scaling bonus for streams/bursts higher than 200bpm
3075
3060
  if (strainTime < this.minSpeedBonus) {
3076
- speedBonus +=
3061
+ speedBonus =
3077
3062
  0.75 * Math.pow((this.minSpeedBonus - strainTime) / 40, 2);
3078
3063
  }
3079
3064
  const travelDistance = (_a = prev === null || prev === void 0 ? void 0 : prev.travelDistance) !== null && _a !== void 0 ? _a : 0;
3065
+ // Cap distance at spacing threshold
3080
3066
  const distance = Math.min(this.SINGLE_SPACING_THRESHOLD, travelDistance + current.minimumJumpDistance);
3081
- return (((speedBonus +
3082
- speedBonus *
3083
- Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.5)) *
3084
- doubletapness) /
3085
- strainTime);
3067
+ // Max distance bonus is 1 * `distance_multiplier` at single_spacing_threshold
3068
+ const distanceBonus = Math.pow(distance / this.SINGLE_SPACING_THRESHOLD, 3.95) *
3069
+ this.DISTANCE_MULTIPLIER;
3070
+ // Base difficulty with all bonuses
3071
+ const difficulty = ((1 + speedBonus + distanceBonus) * 1000) / strainTime;
3072
+ // Apply penalty if there's doubletappable doubles
3073
+ return difficulty * doubletapness;
3086
3074
  }
3087
3075
  }
3088
3076
  /**
3089
3077
  * Spacing threshold for a single hitobject spacing.
3078
+ *
3079
+ * About 1.25 circles distance between hitobject centers.
3090
3080
  */
3091
3081
  OsuSpeedEvaluator.SINGLE_SPACING_THRESHOLD = 125;
3082
+ OsuSpeedEvaluator.DISTANCE_MULTIPLIER = 0.94;
3092
3083
 
3084
+ class Island {
3085
+ constructor(delta, deltaDifferenceEpsilon) {
3086
+ this.delta = Number.MAX_SAFE_INTEGER;
3087
+ this.deltaCount = 0;
3088
+ if (deltaDifferenceEpsilon === undefined) {
3089
+ this.deltaDifferenceEpsilon = delta;
3090
+ }
3091
+ else {
3092
+ this.deltaDifferenceEpsilon = deltaDifferenceEpsilon;
3093
+ this.addDelta(delta);
3094
+ }
3095
+ }
3096
+ addDelta(delta) {
3097
+ if (this.delta === Number.MAX_SAFE_INTEGER) {
3098
+ this.delta = Math.max(Math.trunc(delta), DifficultyHitObject.minDeltaTime);
3099
+ }
3100
+ ++this.deltaCount;
3101
+ }
3102
+ isSimilarPolarity(other) {
3103
+ // TODO: consider islands to be of similar polarity only if they're having the same average delta (we don't want to consider 3 singletaps similar to a triple)
3104
+ // naively adding delta check here breaks _a lot_ of maps because of the flawed ratio calculation
3105
+ return this.deltaCount % 2 == other.deltaCount % 2;
3106
+ }
3107
+ equals(other) {
3108
+ return (Math.abs(this.delta - other.delta) < this.deltaDifferenceEpsilon &&
3109
+ this.deltaCount === other.deltaCount);
3110
+ }
3111
+ }
3093
3112
  /**
3094
3113
  * An evaluator for calculating osu!standard Rhythm skill.
3095
3114
  */
3096
- class OsuRhythmEvaluator extends RhythmEvaluator {
3115
+ class OsuRhythmEvaluator {
3097
3116
  /**
3098
3117
  * Calculates a rhythm multiplier for the difficulty of the tap associated
3099
3118
  * with historic data of the current object.
@@ -3104,14 +3123,16 @@ class OsuRhythmEvaluator extends RhythmEvaluator {
3104
3123
  if (current.object instanceof osuBase.Spinner) {
3105
3124
  return 0;
3106
3125
  }
3107
- let previousIslandSize = 0;
3126
+ const deltaDifferenceEpsilon = current.fullGreatWindow * 0.3;
3108
3127
  let rhythmComplexitySum = 0;
3109
- let islandSize = 1;
3128
+ let island = new Island(deltaDifferenceEpsilon);
3129
+ let previousIsland = new Island(deltaDifferenceEpsilon);
3130
+ const islandCounts = new Map();
3110
3131
  // Store the ratio of the current start of an island to buff for tighter rhythms.
3111
3132
  let startRatio = 0;
3112
3133
  let firstDeltaSwitch = false;
3113
- const historicalNoteCount = Math.min(current.index, 32);
3114
3134
  let rhythmStart = 0;
3135
+ const historicalNoteCount = Math.min(current.index, this.historyObjectsMax);
3115
3136
  while (rhythmStart < historicalNoteCount - 2 &&
3116
3137
  current.startTime - current.previous(rhythmStart).startTime <
3117
3138
  this.historyTimeMax) {
@@ -3122,82 +3143,119 @@ class OsuRhythmEvaluator extends RhythmEvaluator {
3122
3143
  const prevObject = current.previous(i);
3123
3144
  const lastObject = current.previous(i + 1);
3124
3145
  // Scale note 0 to 1 from history to now.
3125
- let currentHistoricalDecay = (this.historyTimeMax -
3146
+ const timeDecay = (this.historyTimeMax -
3126
3147
  (current.startTime - currentObject.startTime)) /
3127
3148
  this.historyTimeMax;
3149
+ const noteDecay = (historicalNoteCount - i) / historicalNoteCount;
3128
3150
  // Either we're limited by time or limited by object count.
3129
- currentHistoricalDecay = Math.min(currentHistoricalDecay, (historicalNoteCount - i) / historicalNoteCount);
3151
+ const currentHistoricalDecay = Math.min(timeDecay, noteDecay);
3130
3152
  const currentDelta = currentObject.strainTime;
3131
3153
  const prevDelta = prevObject.strainTime;
3132
3154
  const lastDelta = lastObject.strainTime;
3155
+ // Calculate how much current delta difference deserves a rhythm bonus
3156
+ // This function is meant to reduce rhythm bonus for deltas that are multiples of each other (i.e. 100 and 200)
3157
+ const deltaDifferenceRatio = Math.min(prevDelta, currentDelta) /
3158
+ Math.max(prevDelta, currentDelta);
3133
3159
  const currentRatio = 1 +
3134
- 6 *
3135
- Math.min(0.5, Math.pow(Math.sin(Math.PI /
3136
- (Math.min(prevDelta, currentDelta) /
3137
- Math.max(prevDelta, currentDelta))), 2));
3138
- const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) -
3139
- current.fullGreatWindow * 0.3) /
3140
- (current.fullGreatWindow * 0.3));
3141
- let effectiveRatio = windowPenalty * currentRatio;
3160
+ this.rhythmRatioMultiplier *
3161
+ Math.min(0.5, Math.pow(Math.sin(Math.PI / deltaDifferenceRatio), 2));
3162
+ // Reduce ratio bonus if delta difference is too big
3163
+ const fraction = Math.max(prevDelta / currentDelta, currentDelta / prevDelta);
3164
+ const fractionMultiplier = osuBase.MathUtils.clamp(2 - fraction / 8, 0, 1);
3165
+ const windowPenalty = Math.min(1, Math.max(0, Math.abs(prevDelta - currentDelta) - deltaDifferenceEpsilon) / deltaDifferenceEpsilon);
3166
+ let effectiveRatio = windowPenalty * currentRatio * fractionMultiplier;
3142
3167
  if (firstDeltaSwitch) {
3143
- if (prevDelta <= 1.25 * currentDelta &&
3144
- prevDelta * 1.25 >= currentDelta) {
3168
+ if (Math.abs(prevDelta - currentDelta) < deltaDifferenceEpsilon) {
3145
3169
  // Island is still progressing, count size.
3146
- if (islandSize < 7) {
3147
- ++islandSize;
3148
- }
3170
+ island.addDelta(currentDelta);
3149
3171
  }
3150
3172
  else {
3173
+ // BPM change is into slider, this is easy acc window.
3151
3174
  if (currentObject.object instanceof osuBase.Slider) {
3152
- // BPM change is into slider, this is easy acc window.
3153
3175
  effectiveRatio /= 8;
3154
3176
  }
3177
+ // BPM change was from a slider, this is easier typically than circle -> circle.
3178
+ // Unintentional side effect is that bursts with kicksliders at the ends might have lower difficulty
3179
+ // than bursts without sliders.
3155
3180
  if (prevObject.object instanceof osuBase.Slider) {
3156
- // BPM change was from a slider, this is typically easier than circle -> circle.
3157
- effectiveRatio /= 4;
3158
- }
3159
- if (previousIslandSize === islandSize) {
3160
- // Repeated island size (ex: triplet -> triplet).
3161
- effectiveRatio /= 4;
3181
+ effectiveRatio *= 0.3;
3162
3182
  }
3163
- if (previousIslandSize % 2 === islandSize % 2) {
3164
- // Repeated island polarity (2 -> 4, 3 -> 5).
3183
+ // Repeated island polarity (2 -> 4, 3 -> 5).
3184
+ if (island.isSimilarPolarity(previousIsland)) {
3165
3185
  effectiveRatio /= 2;
3166
3186
  }
3167
- if (lastDelta > prevDelta + 10 &&
3168
- prevDelta > currentDelta + 10) {
3169
- // Previous increase happened a note ago.
3170
- // Albeit this is a 1/1 -> 1/2-1/4 type of transition, we don't want to buff this.
3187
+ // Previous increase happened a note ago.
3188
+ // Albeit this is a 1/1 -> 1/2-1/4 type of transition, we don't want to buff this.
3189
+ if (lastDelta > prevDelta + deltaDifferenceEpsilon &&
3190
+ prevDelta > currentDelta + deltaDifferenceEpsilon) {
3171
3191
  effectiveRatio /= 8;
3172
3192
  }
3193
+ // Repeated island size (ex: triplet -> triplet).
3194
+ // TODO: remove this nerf since its staying here only for balancing purposes because of the flawed ratio calculation
3195
+ if (previousIsland.deltaCount == island.deltaCount) {
3196
+ effectiveRatio /= 2;
3197
+ }
3198
+ let islandFound = false;
3199
+ for (const [currentIsland, count] of islandCounts) {
3200
+ if (!island.equals(currentIsland)) {
3201
+ continue;
3202
+ }
3203
+ islandFound = true;
3204
+ let islandCount = count;
3205
+ if (previousIsland.equals(island)) {
3206
+ // Only add island to island counts if they're going one after another.
3207
+ ++islandCount;
3208
+ islandCounts.set(currentIsland, islandCount);
3209
+ }
3210
+ // Repeated island (ex: triplet -> triplet).
3211
+ // Graph: https://www.desmos.com/calculator/pj7an56zwf
3212
+ effectiveRatio *= Math.min(3 / islandCount, Math.pow(1 / islandCount, 2.75 / (1 + Math.exp(14 - 0.24 * island.delta))));
3213
+ break;
3214
+ }
3215
+ if (!islandFound) {
3216
+ islandCounts.set(island, 1);
3217
+ }
3218
+ // Scale down the difficulty if the object is doubletappable.
3219
+ effectiveRatio *= 1 - prevObject.doubletapness * 0.75;
3173
3220
  rhythmComplexitySum +=
3174
- (((Math.sqrt(effectiveRatio * startRatio) *
3175
- currentHistoricalDecay *
3176
- Math.sqrt(4 + islandSize)) /
3177
- 2) *
3178
- Math.sqrt(4 + previousIslandSize)) /
3179
- 2;
3221
+ Math.sqrt(effectiveRatio * startRatio) *
3222
+ currentHistoricalDecay;
3180
3223
  startRatio = effectiveRatio;
3181
- previousIslandSize = islandSize;
3182
- if (prevDelta * 1.25 < currentDelta) {
3224
+ previousIsland = island;
3225
+ if (prevDelta + deltaDifferenceEpsilon < currentDelta) {
3183
3226
  // We're slowing down, stop counting.
3184
3227
  // If we're speeding up, this stays as is and we keep counting island size.
3185
3228
  firstDeltaSwitch = false;
3186
3229
  }
3187
- islandSize = 1;
3230
+ island = new Island(currentDelta, deltaDifferenceEpsilon);
3188
3231
  }
3189
3232
  }
3190
- else if (prevDelta > 1.25 * currentDelta) {
3191
- // We want to be speeding up.
3233
+ else if (prevDelta > currentDelta + deltaDifferenceEpsilon) {
3234
+ // We are speeding up.
3192
3235
  // Begin counting island until we change speed again.
3193
3236
  firstDeltaSwitch = true;
3237
+ // BPM change is into slider, this is easy acc window.
3238
+ if (currentObject.object instanceof osuBase.Slider) {
3239
+ effectiveRatio *= 0.6;
3240
+ }
3241
+ // BPM change was from a slider, this is easier typically than circle -> circle
3242
+ // Unintentional side effect is that bursts with kicksliders at the ends might have lower difficulty
3243
+ // than bursts without sliders
3244
+ if (prevObject.object instanceof osuBase.Slider) {
3245
+ effectiveRatio *= 0.6;
3246
+ }
3194
3247
  startRatio = effectiveRatio;
3195
- islandSize = 1;
3248
+ island = new Island(currentDelta, deltaDifferenceEpsilon);
3196
3249
  }
3197
3250
  }
3198
- return Math.sqrt(4 + rhythmComplexitySum * this.rhythmMultiplier) / 2;
3251
+ return (Math.sqrt(4 + rhythmComplexitySum * this.rhythmOverallMultiplier) /
3252
+ 2);
3199
3253
  }
3200
3254
  }
3255
+ OsuRhythmEvaluator.historyTimeMax = 5000; // 5 seconds of calculateRhythmBonus max.
3256
+ OsuRhythmEvaluator.historyObjectsMax = 32;
3257
+ OsuRhythmEvaluator.rhythmOverallMultiplier = 0.95;
3258
+ OsuRhythmEvaluator.rhythmRatioMultiplier = 12;
3201
3259
 
3202
3260
  /**
3203
3261
  * Represents the skill required to press keys or tap with regards to keeping up with the speed at which objects need to be hit.
@@ -3208,11 +3266,10 @@ class OsuSpeed extends OsuSkill {
3208
3266
  this.strainDecayBase = 0.3;
3209
3267
  this.reducedSectionCount = 5;
3210
3268
  this.reducedSectionBaseline = 0.75;
3211
- this.difficultyMultiplier = 1.04;
3212
3269
  this.decayWeight = 0.9;
3213
3270
  this.currentSpeedStrain = 0;
3214
3271
  this.currentRhythm = 0;
3215
- this.skillMultiplier = 1375;
3272
+ this.skillMultiplier = 1.43;
3216
3273
  }
3217
3274
  /**
3218
3275
  * @param current The hitobject to calculate.
@@ -3223,7 +3280,9 @@ class OsuSpeed extends OsuSkill {
3223
3280
  OsuSpeedEvaluator.evaluateDifficultyOf(current) *
3224
3281
  this.skillMultiplier;
3225
3282
  this.currentRhythm = OsuRhythmEvaluator.evaluateDifficultyOf(current);
3226
- return this.currentSpeedStrain * this.currentRhythm;
3283
+ const strain = this.currentSpeedStrain * this.currentRhythm;
3284
+ this._objectStrains.push(strain);
3285
+ return strain;
3227
3286
  }
3228
3287
  calculateInitialStrain(time, current) {
3229
3288
  var _a, _b;
@@ -3333,9 +3392,12 @@ class OsuFlashlight extends OsuSkill {
3333
3392
  this.reducedSectionBaseline = 1;
3334
3393
  this.decayWeight = 1;
3335
3394
  this.currentFlashlightStrain = 0;
3336
- this.skillMultiplier = 0.052;
3395
+ this.skillMultiplier = 0.05512;
3337
3396
  this.isHidden = mods.some((m) => m instanceof osuBase.ModHidden);
3338
3397
  }
3398
+ difficultyValue() {
3399
+ return this.strainPeaks.reduce((a, b) => a + b, 0);
3400
+ }
3339
3401
  strainValueAt(current) {
3340
3402
  this.currentFlashlightStrain *= this.strainDecay(current.deltaTime);
3341
3403
  this.currentFlashlightStrain +=
@@ -3403,6 +3465,8 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3403
3465
  hitCircleCount: 0,
3404
3466
  sliderCount: 0,
3405
3467
  spinnerCount: 0,
3468
+ aimDifficultStrainCount: 0,
3469
+ speedDifficultStrainCount: 0,
3406
3470
  };
3407
3471
  this.difficultyMultiplier = 0.0675;
3408
3472
  this.mode = osuBase.Modes.osu;
@@ -3441,6 +3505,10 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3441
3505
  * Calculates the speed star rating of the beatmap and stores it in this instance.
3442
3506
  */
3443
3507
  calculateSpeed() {
3508
+ if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3509
+ this.attributes.speedDifficulty = 0;
3510
+ return;
3511
+ }
3444
3512
  const speedSkill = new OsuSpeed(this.mods);
3445
3513
  this.calculateSkills(speedSkill);
3446
3514
  this.postCalculateSpeed(speedSkill);
@@ -3467,7 +3535,7 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3467
3535
  // Document for formula derivation:
3468
3536
  // https://docs.google.com/document/d/10DZGYYSsT_yjz2Mtp6yIJld0Rqx4E-vVHupCqiM4TNI/edit
3469
3537
  this.attributes.starRating =
3470
- Math.cbrt(1.14) *
3538
+ Math.cbrt(1.15) *
3471
3539
  0.027 *
3472
3540
  (Math.cbrt((100000 / Math.pow(2, 1 / 1.1)) * basePerformanceValue) +
3473
3541
  4);
@@ -3478,13 +3546,19 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3478
3546
  }
3479
3547
  calculateAll() {
3480
3548
  const skills = this.createSkills();
3549
+ const isRelax = this.mods.some((m) => m instanceof osuBase.ModRelax);
3481
3550
  this.calculateSkills(...skills);
3482
3551
  const aimSkill = skills[0];
3483
3552
  const aimSkillWithoutSliders = skills[1];
3484
3553
  const speedSkill = skills[2];
3485
3554
  const flashlightSkill = skills[3];
3486
3555
  this.postCalculateAim(aimSkill, aimSkillWithoutSliders);
3487
- this.postCalculateSpeed(speedSkill);
3556
+ if (isRelax) {
3557
+ this.attributes.speedDifficulty = 0;
3558
+ }
3559
+ else {
3560
+ this.postCalculateSpeed(speedSkill);
3561
+ }
3488
3562
  this.calculateSpeedAttributes();
3489
3563
  this.postCalculateFlashlight(flashlightSkill);
3490
3564
  this.calculateTotal();
@@ -3499,29 +3573,19 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3499
3573
  this.flashlight.toFixed(2) +
3500
3574
  " flashlight)");
3501
3575
  }
3502
- generateDifficultyHitObjects(convertedBeatmap) {
3576
+ generateDifficultyHitObjects(beatmap, clockRate) {
3503
3577
  var _a, _b;
3504
3578
  const difficultyObjects = [];
3505
- const { objects } = convertedBeatmap.hitObjects;
3506
- const greatWindow = new osuBase.OsuHitWindow(this.difficultyStatistics.overallDifficulty).hitWindowFor300();
3579
+ const { objects } = beatmap.hitObjects;
3580
+ const greatWindow = new osuBase.OsuHitWindow(beatmap.difficulty.od).hitWindowFor300() /
3581
+ clockRate;
3507
3582
  for (let i = 0; i < objects.length; ++i) {
3508
- const difficultyObject = new OsuDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, this.difficultyStatistics.overallSpeedMultiplier, greatWindow);
3509
- difficultyObject.computeProperties(this.difficultyStatistics.overallSpeedMultiplier, objects);
3583
+ const difficultyObject = new OsuDifficultyHitObject(objects[i], (_a = objects[i - 1]) !== null && _a !== void 0 ? _a : null, (_b = objects[i - 2]) !== null && _b !== void 0 ? _b : null, difficultyObjects, clockRate, greatWindow);
3584
+ difficultyObject.computeProperties(clockRate, objects);
3510
3585
  difficultyObjects.push(difficultyObject);
3511
3586
  }
3512
3587
  return difficultyObjects;
3513
3588
  }
3514
- computeDifficultyStatistics(options) {
3515
- const { difficulty } = this.beatmap;
3516
- return osuBase.calculateOsuDifficultyStatistics({
3517
- circleSize: difficulty.cs,
3518
- approachRate: difficulty.ar,
3519
- overallDifficulty: difficulty.od,
3520
- healthDrain: difficulty.hp,
3521
- mods: options === null || options === void 0 ? void 0 : options.mods,
3522
- customSpeedMultiplier: options === null || options === void 0 ? void 0 : options.customSpeedMultiplier,
3523
- });
3524
- }
3525
3589
  createSkills() {
3526
3590
  return [
3527
3591
  new OsuAim(this.mods, true),
@@ -3530,6 +3594,11 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3530
3594
  new OsuFlashlight(this.mods),
3531
3595
  ];
3532
3596
  }
3597
+ populateDifficultyAttributes(beatmap, clockRate) {
3598
+ super.populateDifficultyAttributes(beatmap, clockRate);
3599
+ const preempt = osuBase.BeatmapDifficulty.difficultyRange(beatmap.difficulty.ar, osuBase.HitObject.preemptMax, osuBase.HitObject.preemptMid, osuBase.HitObject.preemptMin) / clockRate;
3600
+ this.attributes.approachRate = osuBase.BeatmapDifficulty.inverseDifficultyRange(preempt, osuBase.HitObject.preemptMax, osuBase.HitObject.preemptMid, osuBase.HitObject.preemptMin);
3601
+ }
3533
3602
  /**
3534
3603
  * Called after aim skill calculation.
3535
3604
  *
@@ -3551,6 +3620,8 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3551
3620
  if (this.mods.some((m) => m instanceof osuBase.ModRelax)) {
3552
3621
  this.attributes.aimDifficulty *= 0.9;
3553
3622
  }
3623
+ this.attributes.aimDifficultStrainCount =
3624
+ aimSkill.countDifficultStrains();
3554
3625
  }
3555
3626
  /**
3556
3627
  * Called after speed skill calculation.
@@ -3559,10 +3630,9 @@ class OsuDifficultyCalculator extends DifficultyCalculator {
3559
3630
  */
3560
3631
  postCalculateSpeed(speedSkill) {
3561
3632
  this.strainPeaks.speed = speedSkill.strainPeaks;
3562
- this.attributes.speedDifficulty = this.mods.some((m) => m instanceof osuBase.ModRelax)
3563
- ? 0
3564
- : this.starValue(speedSkill.difficultyValue());
3565
- this.calculateSpeedAttributes();
3633
+ this.attributes.speedDifficulty = this.starValue(speedSkill.difficultyValue());
3634
+ this.attributes.speedDifficultStrainCount =
3635
+ speedSkill.countDifficultStrains();
3566
3636
  }
3567
3637
  /**
3568
3638
  * Calculates speed-related attributes.
@@ -3613,8 +3683,9 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
3613
3683
  * The flashlight performance value.
3614
3684
  */
3615
3685
  this.flashlight = 0;
3616
- this.finalMultiplier = 1.14;
3686
+ this.finalMultiplier = 1.15;
3617
3687
  this.mode = osuBase.Modes.osu;
3688
+ this.comboPenalty = 1;
3618
3689
  }
3619
3690
  calculateValues() {
3620
3691
  this.aim = this.calculateAimValue();
@@ -3628,6 +3699,14 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
3628
3699
  Math.pow(this.accuracy, 1.1) +
3629
3700
  Math.pow(this.flashlight, 1.1), 1 / 1.1) * this.finalMultiplier);
3630
3701
  }
3702
+ handleOptions(options) {
3703
+ var _a;
3704
+ super.handleOptions(options);
3705
+ const maxCombo = this.difficultyAttributes.maxCombo;
3706
+ const miss = this.computedAccuracy.nmiss;
3707
+ const combo = (_a = options === null || options === void 0 ? void 0 : options.combo) !== null && _a !== void 0 ? _a : maxCombo - miss;
3708
+ this.comboPenalty = Math.min(Math.pow(combo / maxCombo, 0.8), 1);
3709
+ }
3631
3710
  /**
3632
3711
  * Calculates the aim performance value of the beatmap.
3633
3712
  */
@@ -3647,8 +3726,7 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
3647
3726
  Math.pow(1 -
3648
3727
  Math.pow(this.effectiveMissCount / this.totalHits, 0.775), this.effectiveMissCount);
3649
3728
  }
3650
- // Combo scaling
3651
- aimValue *= this.comboPenalty;
3729
+ aimValue *= this.calculateStrainBasedMissPenalty(this.difficultyAttributes.aimDifficultStrainCount);
3652
3730
  const calculatedAR = this.difficultyAttributes.approachRate;
3653
3731
  if (!this.difficultyAttributes.mods.some((m) => m instanceof osuBase.ModRelax)) {
3654
3732
  // AR scaling
@@ -3689,16 +3767,7 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
3689
3767
  lengthBonus += Math.log10(this.totalHits / 2000) * 0.5;
3690
3768
  }
3691
3769
  speedValue *= lengthBonus;
3692
- if (this.effectiveMissCount > 0) {
3693
- // Penalize misses by assessing # of misses relative to the total # of objects.
3694
- // Default a 3% reduction for any # of misses.
3695
- speedValue *=
3696
- 0.97 *
3697
- Math.pow(1 -
3698
- Math.pow(this.effectiveMissCount / this.totalHits, 0.775), Math.pow(this.effectiveMissCount, 0.875));
3699
- }
3700
- // Combo scaling
3701
- speedValue *= this.comboPenalty;
3770
+ speedValue *= this.calculateStrainBasedMissPenalty(this.difficultyAttributes.speedDifficultStrainCount);
3702
3771
  // AR scaling
3703
3772
  const calculatedAR = this.difficultyAttributes.approachRate;
3704
3773
  if (calculatedAR > 10.33) {
@@ -3729,9 +3798,7 @@ class OsuPerformanceCalculator extends PerformanceCalculator {
3729
3798
  750) *
3730
3799
  Math.pow((this.computedAccuracy.value() +
3731
3800
  relevantAccuracy.value(this.difficultyAttributes.speedNoteCount)) /
3732
- 2, (14.5 -
3733
- Math.max(this.difficultyAttributes.overallDifficulty, 8)) /
3734
- 2);
3801
+ 2, (14.5 - this.difficultyAttributes.overallDifficulty) / 2);
3735
3802
  // Scale the speed value with # of 50s to punish doubletapping.
3736
3803
  speedValue *= Math.pow(0.99, Math.max(0, this.computedAccuracy.n50 - this.totalHits / 500));
3737
3804
  return speedValue;
@@ -3839,6 +3906,5 @@ exports.OsuRhythmEvaluator = OsuRhythmEvaluator;
3839
3906
  exports.OsuSpeed = OsuSpeed;
3840
3907
  exports.OsuSpeedEvaluator = OsuSpeedEvaluator;
3841
3908
  exports.PerformanceCalculator = PerformanceCalculator;
3842
- exports.RhythmEvaluator = RhythmEvaluator;
3843
3909
  exports.SpeedEvaluator = SpeedEvaluator;
3844
3910
  //# sourceMappingURL=index.js.map