-
Notifications
You must be signed in to change notification settings - Fork 2
/
TaikoDifficultyCalculator.ts
146 lines (119 loc) · 4.44 KB
/
TaikoDifficultyCalculator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { DifficultyCalculator, DifficultyHitObject, HitResult, IBeatmap, IMod, Skill } from 'osu-classes';
import { TaikoDifficultyAttributes } from './Attributes';
import { Peaks } from './Skills/Peaks';
import { TaikoHitWindows } from '../Scoring';
import { Hit } from '../Objects';
import {
TaikoColourDifficultyPreprocessor,
TaikoDifficultyHitObject,
} from './Preprocessing';
import {
TaikoDoubleTime,
TaikoEasy,
TaikoHalfTime,
TaikoHardRock,
TaikoModCombination,
} from '../Mods';
/**
* A taiko difficulty calculator.
*/
export class TaikoDifficultyCalculator extends DifficultyCalculator<TaikoDifficultyAttributes> {
private static readonly DIFFICULTY_MULTIPLIER = 1.35;
protected _createSkills(_: IBeatmap, mods: TaikoModCombination): Skill[] {
return [
new Peaks(mods),
];
}
get difficultyMods(): IMod[] {
return [
new TaikoDoubleTime(),
new TaikoHalfTime(),
new TaikoEasy(),
new TaikoHardRock(),
];
}
protected _createDifficultyHitObjects(beatmap: IBeatmap, clockRate: number): DifficultyHitObject[] {
const difficultyObjects: DifficultyHitObject[] = [];
const centreObjects: TaikoDifficultyHitObject[] = [];
const rimObjects: TaikoDifficultyHitObject[] = [];
const noteObjects: TaikoDifficultyHitObject[] = [];
for (let i = 2; i < beatmap.hitObjects.length; ++i) {
const hitObject = beatmap.hitObjects[i];
const lastObject = beatmap.hitObjects[i - 1];
const lastLastObject = beatmap.hitObjects[i - 2];
const difficultyObject = new TaikoDifficultyHitObject(
hitObject,
lastObject,
lastLastObject,
clockRate,
difficultyObjects,
centreObjects,
rimObjects,
noteObjects,
difficultyObjects.length,
);
difficultyObjects.push(difficultyObject);
}
TaikoColourDifficultyPreprocessor.processAndAssign(difficultyObjects);
return difficultyObjects;
}
protected _createDifficultyAttributes(
beatmap: IBeatmap,
mods: TaikoModCombination,
skills: Skill[],
clockRate: number,
): TaikoDifficultyAttributes {
if (beatmap.hitObjects.length === 0) {
return new TaikoDifficultyAttributes(mods, 0);
}
const combined = skills[0] as Peaks;
const multiplier = TaikoDifficultyCalculator.DIFFICULTY_MULTIPLIER;
const colourRating = combined.colourDifficultyValue * multiplier;
const rhythmRating = combined.rhythmDifficultyValue * multiplier;
const staminaRating = combined.staminaDifficultyValue * multiplier;
const combinedRating = combined.difficultyValue * multiplier;
let starRating = this._rescale(combinedRating * 1.4);
/**
* TODO: This is temporary measure as we don't detect abuse
* of multiple-input playstyles of converts within the current system.
*/
if (beatmap.originalMode === 0) {
starRating *= 0.925;
/**
* For maps with low colour variance and high stamina requirement,
* multiple inputs are more likely to be abused.
*/
if (colourRating < 2 && staminaRating > 8) {
starRating *= 0.8;
}
}
const hitWindows = new TaikoHitWindows();
hitWindows.setDifficulty(beatmap.difficulty.overallDifficulty);
const attributes = new TaikoDifficultyAttributes(mods, starRating);
attributes.staminaDifficulty = staminaRating;
attributes.rhythmDifficulty = rhythmRating;
attributes.colourDifficulty = colourRating;
attributes.peakDifficulty = combinedRating;
attributes.greatHitWindow = hitWindows.windowFor(HitResult.Great) / clockRate;
attributes.maxCombo = beatmap.hitObjects.reduce((s, c) => s + (c instanceof Hit ? 1 : 0), 0);
return attributes;
}
/**
* Calculates the penalty for the stamina skill for maps with low colour difficulty.
* Some maps (especially converts) can be easy to read despite a high note density.
* This penalty aims to reduce the star rating of such maps
* by factoring in colour difficulty to the stamina skill.
*/
private static _simpleColourPenalty(staminaDifficulty: number, colorDifficulty: number) {
if (colorDifficulty <= 0) return 0.79 - 0.25;
return 0.79 - Math.atan(staminaDifficulty / colorDifficulty - 12) / Math.PI / 2;
}
/**
* Applies a final re-scaling of the star rating.
* @param sr The raw star rating value before re-scaling.
*/
private _rescale(sr: number): number {
if (sr < 0) return sr;
return 10.43 * Math.log(sr / 8 + 1);
}
}