-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
120 lines (115 loc) · 2.99 KB
/
utils.js
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
const _ = require("lodash");
// Util to retrieve an item's ID via a variety of spellings/shorthands
getItemID = item => {
if (!item) {
return null;
}
const searchTerm = item.toLowerCase();
switch (searchTerm) {
case "dex":
case "dext":
case "dex scroll":
case "dexterous prayer scroll":
return 21034;
case "arcane":
case "arc":
case "arcane scroll":
case "arcane prayer scroll":
return 21079;
case "twisted buckler":
case "buck":
case "buckler":
return 21000;
case "dragon hunter crossbow":
case "crossbow":
case "hunter":
case "cbow":
case "xbow":
case "dhcb":
return 21012;
case "dinh's bulwark":
case "dinhs bulwark":
case "dinh":
case "dinhs":
case "bulwark":
case "shield":
return 21015;
case "ancestral hat":
case "hat":
return 21018;
case "ancestral robe top":
case "top":
case "robe top":
return 21024;
case "ancestral robe bottom":
case "bottom":
case "bottoms":
case "robe bottom":
case "robe bottoms":
return 21021;
case "dragon claws":
case "claws":
case "claw":
return 13652;
case "elder maul":
case "maul":
case "elder":
return 21003;
case "kodai insignia":
case "kodai":
case "insignia":
case "insig":
return 21043;
case "tbow":
case "twisted bow":
case "bow":
case "t bow":
return 20997;
default:
return null;
}
};
// Calculates % chance of recieving a unique drop based on numuber of points accumulated: https://oldschool.runescape.wiki/w/Chambers_of_Xeric#Unique_drop_table
calculateUniqueProbability = points => {
const MAX_POINTS_PER_CHANCE = 570000;
const POINTS_PER_1_PERCENT_CHANCE = 8675;
const maxChance = (
MAX_POINTS_PER_CHANCE / POINTS_PER_1_PERCENT_CHANCE
).toFixed(2);
const formattedPoints = Number(points);
if (_.isNaN(formattedPoints) || formattedPoints < 0) {
return "ERROR: Incorrect number format";
}
if (formattedPoints <= MAX_POINTS_PER_CHANCE) {
const chance = (formattedPoints / POINTS_PER_1_PERCENT_CHANCE).toFixed(2);
return "Chance of unique: " + chance + "%";
} else if (formattedPoints <= MAX_POINTS_PER_CHANCE * 2) {
const chanceOfSecond = (
(formattedPoints - MAX_POINTS_PER_CHANCE) /
POINTS_PER_1_PERCENT_CHANCE
).toFixed(2);
return (
"Chance of 1st unique: " +
maxChance +
"%\nChance of 2nd unique: " +
chanceOfSecond +
"%"
);
} else {
const pointsForThirdItem = points - MAX_POINTS_PER_CHANCE * 2;
const chanceOfThird =
pointsForThirdItem > MAX_POINTS_PER_CHANCE
? maxChance
: (pointsForThirdItem / POINTS_PER_1_PERCENT_CHANCE).toFixed(2);
return (
"Chance of 1st unique: " +
maxChance +
"%\nChance of 2nd unique: " +
maxChance +
"%\nChance of 3rd unique: " +
chanceOfThird +
"%"
);
}
};
module.exports = { getItemID, calculateUniqueProbability };