/
armorMitigation.ts
95 lines (85 loc) · 2.8 KB
/
armorMitigation.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
import { WCLFight } from 'parser/core/Fight';
import DIFFICULTIES from 'game/DIFFICULTIES';
import { DamageEvent } from 'parser/core/Events';
const maximumArmorMitigation = 0.85;
enum ArmorCoefficientKey {
BASE = 'base',
MYTHIC_PLUS = 'm+',
RAID_LFR = 'raid_lfr',
RAID_NORMAL = 'raid_n',
RAID_HEROIC = 'raid_h',
RAID_MYTHIC = 'raid_m',
}
// These were pulled from Peak of Serenity theorycrafting channel and need to be updated every tier.
const armorCoefficients = {
[ArmorCoefficientKey.BASE]: 11766.0,
[ArmorCoefficientKey.MYTHIC_PLUS]: 18672.64,
[ArmorCoefficientKey.RAID_LFR]: 19155.05,
[ArmorCoefficientKey.RAID_NORMAL]: 20872.88,
[ArmorCoefficientKey.RAID_HEROIC]: 22814.27,
[ArmorCoefficientKey.RAID_MYTHIC]: 25014.52,
};
/**
* Gets the {@link ArmorCoefficientKey} for a given fight.
*/
const getArmorCoefficientKey = (fight: WCLFight) => {
switch (fight.difficulty) {
case DIFFICULTIES.LFR_RAID:
return ArmorCoefficientKey.RAID_LFR;
case DIFFICULTIES.NORMAL_RAID:
return ArmorCoefficientKey.RAID_NORMAL;
case DIFFICULTIES.HEROIC_RAID:
return ArmorCoefficientKey.RAID_HEROIC;
case DIFFICULTIES.MYTHIC_RAID:
return ArmorCoefficientKey.RAID_MYTHIC;
case DIFFICULTIES.MYTHIC_PLUS_DUNGEON:
return ArmorCoefficientKey.MYTHIC_PLUS;
default:
return ArmorCoefficientKey.BASE;
}
};
/**
* Gets the armor coefficient for a given fight.
*/
const getArmorCoefficient = (fight: WCLFight) => armorCoefficients[getArmorCoefficientKey(fight)];
const clamp = (actual: number, min: number, max: number) => Math.min(max, Math.max(min, actual));
const debug = false;
interface GetArmorMitigationParams {
armor: number;
fight: WCLFight;
unmitigatedAmount?: number;
}
interface ArmorMitigationResult {
amount: number;
percentage: number;
}
/**
* Gets armor mitigation values for a given amount of armor, fight, and unmitigated amount of damage.
*/
const getArmorMitigation = ({
armor,
fight,
unmitigatedAmount = 0,
}: GetArmorMitigationParams): ArmorMitigationResult => {
const armorMitigatedPercentage = clamp(
armor / (armor + getArmorCoefficient(fight)),
0,
maximumArmorMitigation,
);
const armorMitigatedAmount = armorMitigatedPercentage * unmitigatedAmount;
debug &&
console.log(
`getArmorMitigation - percentage=${armorMitigatedPercentage} unmitigatedAmount=${unmitigatedAmount} amount=${armorMitigatedAmount}`,
);
return { amount: armorMitigatedAmount, percentage: armorMitigatedPercentage };
};
export const getArmorMitigationForEvent = (
{ armor, unmitigatedAmount }: DamageEvent,
fight: WCLFight,
) => {
if (!armor) {
debug && console.log('getArmorMitigationPercentage - armor was undefined on damage event');
return undefined;
}
return getArmorMitigation({ armor, fight, unmitigatedAmount });
};