@rian8337/osu-rebalance-difficulty-calculator 1.0.0 → 1.0.5

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/README.md CHANGED
@@ -1,11 +1,106 @@
1
- # `osu-rebalance-difficulty-calculator`
1
+ # About
2
2
 
3
- > TODO: description
3
+ The difficulty and performance calculator portion of my osu! module that uses the latest osu!lazer difficulty and performance algorithm.
4
4
 
5
- ## Usage
5
+ # Features
6
6
 
7
+ This module provides an osu! difficulty and performance calculator that uses the latest osu!lazer difficulty and performance algorithm for osu!standard gamemode.
8
+
9
+ An error margin should be expected from difficulty and performance calculator due to differences between C# and TypeScript.
10
+
11
+ # Specific Requirements
12
+
13
+ This module has no specific requirements, however installed modules in installation may have specific requirements. It's advised to check them.
14
+
15
+ # Installation
16
+
17
+ ```
18
+ npm i @rian8337/osu-base @rian8337/osu-rebalance-difficulty-calculator
19
+ ```
20
+
21
+ or
22
+
23
+ ```
24
+ yarn add @rian8337/osu-base @rian8337/osu-rebalance-difficulty-calculator
7
25
  ```
8
- const osuRebalanceDifficultyCalculator = require('osu-rebalance-difficulty-calculator');
9
26
 
10
- // TODO: DEMONSTRATE API
27
+ # Usage
28
+
29
+ ## General usage
30
+
31
+ ```js
32
+ import { MapInfo } from "@rian8337/osu-base";
33
+ import {
34
+ DroidStarRating,
35
+ MapStars,
36
+ OsuStarRating,
37
+ } from "@rian8337/osu-rebalance-difficulty-calculator";
38
+
39
+ const beatmapInfo = await MapInfo.getInformation({ beatmapID: 901854 });
40
+
41
+ if (!beatmapInfo.title) {
42
+ return console.log("Beatmap not found");
43
+ }
44
+
45
+ // Calculate osu!droid difficulty
46
+ const droidRating = new DroidStarRating().calculate({
47
+ map: beatmapInfo.map,
48
+ });
49
+
50
+ console.log(droidRating);
51
+
52
+ // Calculate osu!standard difficulty
53
+ const osuRating = new OsuStarRating().calculate({
54
+ map: beatmapInfo.map,
55
+ });
56
+
57
+ console.log(osuRating);
58
+
59
+ // Calculate both osu!droid and osu!standard difficulty
60
+ const rating = new MapStars().calculate({
61
+ map: beatmapInfo.map,
62
+ });
63
+
64
+ // osu!droid difficulty
65
+ console.log(rating.droidStars);
66
+ // osu!standard difficulty
67
+ console.log(rating.pcStars);
68
+ ```
69
+
70
+ ## Specifying parameters
71
+
72
+ Parameters can be applied to alter the result of the calculation:
73
+
74
+ - Mods: Modifications that will be considered when calculating the difficulty of a beatmap. Defaults to none.
75
+ - Custom statistics: Used to apply a custom speed multiplier and force AR. Defaults to none.
76
+
77
+ ```js
78
+ import { MapInfo, MapStats, ModUtil } from "@rian8337/osu-base";
79
+ import { MapStars } from "@rian8337/osu-rebalance-difficulty-calculator";
80
+
81
+ const beatmapInfo = await MapInfo.getInformation({ beatmapID: 901854 });
82
+
83
+ if (!beatmapInfo.title) {
84
+ return console.log("Beatmap not found");
85
+ }
86
+
87
+ const mods = ModUtil.pcStringToMods("HDHR");
88
+
89
+ const stats = new MapStats({
90
+ ar: 9,
91
+ isForceAR: true,
92
+ speedMultiplier: 1.5,
93
+ });
94
+
95
+ // Also available for `DroidStarRating` and `OsuStarRating`
96
+ const rating = new MapStars().calculate({
97
+ map: beatmapInfo.map,
98
+ mods: mods,
99
+ stats: stats,
100
+ });
101
+
102
+ // osu!droid difficulty
103
+ console.log(rating.droidStars);
104
+ // osu!standard difficulty
105
+ console.log(rating.pcStars);
11
106
  ```
@@ -73,18 +73,16 @@ class DroidPerformanceCalculator extends PerformanceCalculator_1.PerformanceCalc
73
73
  // Combo scaling
74
74
  this.aim *= this.comboPenalty;
75
75
  // We want to give more reward for lower AR when it comes to aim and HD. This nerfs high AR and buffs lower AR.
76
- let hiddenBonus = 1;
77
76
  if (this.stars.mods.some((m) => m instanceof osu_base_1.ModHidden)) {
78
77
  // The bonus starts decreasing twice as fast
79
78
  // beyond AR10 and reaches 1 at AR11.
80
79
  if (calculatedAR > 10) {
81
- hiddenBonus += Math.max(0, 0.08 * (11 - calculatedAR));
80
+ this.aim *= 1 + Math.max(0, 0.08 * (11 - calculatedAR));
82
81
  }
83
82
  else {
84
- hiddenBonus += 0.04 * (12 - calculatedAR);
83
+ this.aim *= 1 + 0.04 * (12 - calculatedAR);
85
84
  }
86
85
  }
87
- this.aim *= hiddenBonus;
88
86
  // AR scaling
89
87
  let arFactor = 0;
90
88
  if (calculatedAR > 10.33) {
@@ -121,7 +119,7 @@ class DroidPerformanceCalculator extends PerformanceCalculator_1.PerformanceCalc
121
119
  // Penalize misses by assessing # of misses relative to the total # of objects. Default a 3% reduction for any # of misses.
122
120
  this.tap *=
123
121
  0.97 *
124
- Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), this.effectiveMissCount);
122
+ Math.pow(1 - Math.pow(this.effectiveMissCount / objectCount, 0.775), Math.pow(this.effectiveMissCount, 0.875));
125
123
  }
126
124
  // Combo scaling
127
125
  this.tap *= this.comboPenalty;
@@ -115,7 +115,7 @@ class DroidStarRating extends StarRating_1.StarRating {
115
115
  }
116
116
  this.calculateSkills(...skills);
117
117
  const aimSkill = skills[0];
118
- const aimSkillWithoutSliders = (skills[1]);
118
+ const aimSkillWithoutSliders = skills[1];
119
119
  let tapSkill;
120
120
  let flashlightSkill;
121
121
  if (!isRelax) {
@@ -77,11 +77,9 @@ class OsuPerformanceCalculator extends PerformanceCalculator_1.PerformanceCalcul
77
77
  // Buff for longer maps with high AR.
78
78
  this.aim *= 1 + arFactor * lengthBonus;
79
79
  // We want to give more reward for lower AR when it comes to aim and HD. This nerfs high AR and buffs lower AR.
80
- let hiddenBonus = 1;
81
80
  if (this.stars.mods.some((m) => m instanceof osu_base_1.ModHidden)) {
82
- hiddenBonus += 0.04 * (12 - calculatedAR);
81
+ this.aim *= 1 + 0.04 * (12 - calculatedAR);
83
82
  }
84
- this.aim *= hiddenBonus;
85
83
  // Scale the aim value with slider factor to nerf very likely dropped sliderends.
86
84
  this.aim *= this.sliderNerfFactor;
87
85
  // Scale the aim value with accuracy.
@@ -93,7 +93,7 @@ class OsuStarRating extends StarRating_1.StarRating {
93
93
  }
94
94
  this.calculateSkills(...skills);
95
95
  const aimSkill = skills[0];
96
- const aimSkillWithoutSliders = (skills[1]);
96
+ const aimSkillWithoutSliders = skills[1];
97
97
  let speedSkill;
98
98
  let flashlightSkill;
99
99
  if (isRelax) {
@@ -62,8 +62,9 @@ class PerformanceCalculator {
62
62
  nmiss: params.miss || 0,
63
63
  });
64
64
  }
65
+ this.effectiveMissCount = this.calculateEffectiveMissCount(combo, maxCombo);
65
66
  if (this.stars.mods.some((m) => m instanceof osu_base_1.ModNoFail)) {
66
- this.finalMultiplier *= Math.max(0.9, 1 - 0.02 * this.computedAccuracy.nmiss);
67
+ this.finalMultiplier *= Math.max(0.9, 1 - 0.02 * this.effectiveMissCount);
67
68
  }
68
69
  if (this.stars.mods.some((m) => m instanceof osu_base_1.ModSpunOut)) {
69
70
  this.finalMultiplier *=
@@ -71,22 +72,24 @@ class PerformanceCalculator {
71
72
  Math.pow(this.stars.map.spinners / this.stars.objects.length, 0.85);
72
73
  }
73
74
  if (this.stars.mods.some((m) => m instanceof osu_base_1.ModRelax)) {
74
- this.computedAccuracy.nmiss +=
75
- this.computedAccuracy.n100 + this.computedAccuracy.n50;
75
+ // As we're adding 100s and 50s to an approximated number of combo breaks, the result can be higher
76
+ // than total hits in specific scenarios (which breaks some calculations), so we need to clamp it.
77
+ this.effectiveMissCount = Math.min(this.effectiveMissCount +
78
+ this.computedAccuracy.n100 +
79
+ this.computedAccuracy.n50, this.stars.objects.length);
76
80
  this.finalMultiplier *= 0.6;
77
81
  }
78
- this.effectiveMissCount = this.calculateEffectiveMissCount(combo, maxCombo);
79
82
  this.mapStatistics = new osu_base_1.MapStats({
80
83
  ar: baseAR,
81
84
  od: baseOD,
82
85
  mods: mod,
83
86
  });
84
- // We assume 15% of sliders in a beatmap are difficult since there's no way to tell from the performance calculator.
85
- const estimateDifficultSliders = this.stars.map.sliders * 0.15;
86
- const estimateSliderEndsDropped = osu_base_1.MathUtils.clamp(Math.min(this.computedAccuracy.n300 +
87
- this.computedAccuracy.n50 +
88
- this.computedAccuracy.nmiss, maxCombo - combo), 0, estimateDifficultSliders);
89
87
  if (this.stars.map.sliders > 0) {
88
+ // We assume 15% of sliders in a beatmap are difficult since there's no way to tell from the performance calculator.
89
+ const estimateDifficultSliders = this.stars.map.sliders * 0.15;
90
+ const estimateSliderEndsDropped = osu_base_1.MathUtils.clamp(Math.min(this.computedAccuracy.n300 +
91
+ this.computedAccuracy.n50 +
92
+ this.computedAccuracy.nmiss, maxCombo - combo), 0, estimateDifficultSliders);
90
93
  this.sliderNerfFactor =
91
94
  (1 - this.stars.attributes.sliderFactor) *
92
95
  Math.pow(1 -
@@ -119,7 +122,7 @@ class PerformanceCalculator {
119
122
  comboBasedMissCount = Math.min(fullComboThreshold / Math.max(1, combo), this.stars.objects.length);
120
123
  }
121
124
  }
122
- return Math.max(this.computedAccuracy.nmiss, Math.floor(comboBasedMissCount));
125
+ return Math.max(this.computedAccuracy.nmiss, comboBasedMissCount);
123
126
  }
124
127
  }
125
128
  exports.PerformanceCalculator = PerformanceCalculator;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rian8337/osu-rebalance-difficulty-calculator",
3
- "version": "1.0.0",
4
- "description": "A module for calculating osu!standard beatmap difficulty and performance with respect to the latest osu!lazer algorithm.",
3
+ "version": "1.0.5",
4
+ "description": "A module for calculating osu!standard beatmap difficulty and performance value with respect to the latest osu!lazer difficulty and performance algorithm.",
5
5
  "keywords": [
6
6
  "osu",
7
7
  "osu-difficulty-calculator"
@@ -21,6 +21,8 @@
21
21
  },
22
22
  "scripts": {
23
23
  "build": "tsc",
24
+ "generate-docs": "typedoc src/index.ts",
25
+ "lint": "eslint --ext ts",
24
26
  "prepare": "npm run build",
25
27
  "test": "jest -i"
26
28
  },
@@ -28,10 +30,10 @@
28
30
  "url": "https://github.com/Rian8337/osu-droid-module/issues"
29
31
  },
30
32
  "dependencies": {
31
- "@rian8337/osu-base": "^1.0.0"
33
+ "@rian8337/osu-base": "^1.0.5"
32
34
  },
33
35
  "publishConfig": {
34
36
  "access": "public"
35
37
  },
36
- "gitHead": "e4fdb9c1ed6f90e70651c1aedfdb964b61cb240d"
38
+ "gitHead": "c8c092485a5ae3be16f2bfa0a3defb00163918d7"
37
39
  }
@@ -1,5 +1,15 @@
1
1
  declare module "@rian8337/osu-rebalance-difficulty-calculator" {
2
- import { Accuracy, Beatmap, HitObject, MapStats, Mod, modes, OsuHitWindow, Slider, Vector2 } from "@rian8337/osu-base";
2
+ import {
3
+ Accuracy,
4
+ Beatmap,
5
+ HitObject,
6
+ MapStats,
7
+ Mod,
8
+ modes,
9
+ OsuHitWindow,
10
+ Slider,
11
+ Vector2,
12
+ } from "@rian8337/osu-base";
3
13
 
4
14
  //#region Classes
5
15
 
@@ -38,7 +48,7 @@ declare module "@rian8337/osu-rebalance-difficulty-calculator" {
38
48
  flashlightStrain: number;
39
49
  /**
40
50
  * The normalized distance from the "lazy" end position of the previous hitobject to the start position of this hitobject.
41
- *
51
+ *
42
52
  * The "lazy" end position is the position at which the cursor ends up if the previous hitobject is followed with as minimal movement as possible (i.e. on the edge of slider follow circles).
43
53
  */
44
54
  lazyJumpDistance: number;
@@ -854,7 +864,10 @@ declare module "@rian8337/osu-rebalance-difficulty-calculator" {
854
864
  /**
855
865
  * Calculates the amount of misses + sliderbreaks from combo.
856
866
  */
857
- private calculateEffectiveMissCount(combo: number, maxCombo: number): number;
867
+ private calculateEffectiveMissCount(
868
+ combo: number,
869
+ maxCombo: number
870
+ ): number;
858
871
  }
859
872
 
860
873
  /**
@@ -1060,16 +1073,6 @@ declare module "@rian8337/osu-rebalance-difficulty-calculator" {
1060
1073
  * Calculates every star rating of the beatmap and stores it in this instance.
1061
1074
  */
1062
1075
  abstract calculateAll(): void;
1063
- /**
1064
- * Generates the strain chart of this beatmap and returns the chart as a buffer.
1065
- *
1066
- * @param beatmapsetID The beatmapset ID to get background image from. If omitted, the background will be plain white.
1067
- * @param color The color of the graph.
1068
- */
1069
- getStrainChart(
1070
- beatmapsetID?: number,
1071
- color?: string
1072
- ): Promise<Buffer | null>;
1073
1076
  /**
1074
1077
  * Returns a string representative of the class.
1075
1078
  */