-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.html
305 lines (285 loc) · 15.3 KB
/
index.html
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>D2 and D2R Boss and Monster Drop Simulator</title>
<meta name="author" content="github.com/pairofdocs">
<meta name="description" content="Simulate Diablo 2's random loot drop mechanic">
<!-- TODO: <meta property="og:image" content=""> -->
<meta property="og:description" content="Simulate Diablo 2's random loot drop mechanic">
<meta property="og:title" content="D2 and D2R Boss and Monster Drop Simulator">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="icon" href="./img/favicon.ico" type="image/x-icon">
<style type="text/css">
body {font-family: Arial, sans-serif; background-color: #312f40; color:#b7cee2}
.tooltip {
position: relative;
}
.tooltip .tooltiptext {
visibility: hidden;
background-color: rgb(33, 15, 85);
color: #e3effa;
border-radius: 3px;
padding: 3px 3px;
position: absolute;
z-index: 1;
bottom: -10%;
left: 0%;
margin-left: 50%;
opacity: 0;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
white-space:nowrap;
max-width:none;
}
</style>
<script type="text/javascript" src="./data_util.js"></script>
</head>
<body>
<h1> D2 and D2R Bossq and Monster Drop Simulator </h1>
<p id="par-1"> Loading data takes a couple of seconds... </p>
<table> <!-- selections/controls and grail track cols -->
<tr>
<td>
<div>
<select id="selectMon" onchange="changeImg()" style="padding: 1px 2px;">
<option value="Andarielq">Andarielq</option>
<option value="Andariel">Andariel</option>
<option value="Durielq">Durielq</option>
<option value="Duriel">Duriel</option>
<option value="Mephistoq">Mephistoq</option>
<option value="Mephisto">Mephisto</option>
<option value="Diabloq">Diabloq</option>
<option value="Diablo">Diablo</option>
<option value="Baalq">Baalq</option>
<option value="Baal">Baal</option>
<option value="Cow">Cow</option>
<option value="Cow King">Cow King</option>
<option value="Countess">Countess</option>
<option value="Council">Council</option>
<option value="Nihlathak">Nihlathak</option>
<option value="Eldritch">Eldritch</option>
<option value="Pindleskin">Pindleskin</option>
</select>
<select id="selectDiff" style="padding: 1px 2px;">
<option value="Normal">Normal</option>
<option value="Nightmare">Nightmare</option>
<option value="Hell">Hell</option>
</select>
<select id="selectPlayers" style="padding: 1px 2px;">
<option value="players 1">players 1</option>
<option value="players 2">players 2</option>
<option value="players 3">players 3</option>
<option value="players 4">players 4</option>
<option value="players 5">players 5</option>
<option value="players 6">players 6</option>
<option value="players 7">players 7</option>
<option value="players 8">players 8</option>
</select>
<input type="text" id="mftext" name="mftext" size="5" value="0" style="text-align: center;"> Magic Find
<input type="text" id="seedtext" name="seedtext" size="2" value="" style="text-align: center; margin: 0 0 0 10em ; visibility: hidden;">
<!-- RNG Seed. hidden since JS doesnt have a random.seed set function like py -->
</div>
<button id="run" style="margin: 1em 0 1em;"> Run x times </button>
<input type="text" id="xtimes" name="xtimes" size="2" value="1" style="text-align: center; width: 2.5em;"> If x > 1 only uniques, sets and runes/essences/uber keys are kept as loot
</td>
<td style="padding: 0 0 0 4em;">
<div id="grailUniques" style="color: #b77f00; text-align: center;"> Uniques Found: 0/379</div>
<div id="grailSets" style="color: #11c511; text-align: center;"> Sets Found: 0/127 </div>
</td>
</tr>
</table>
<!-- organize divs into rows and columns. set display to table. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_images_side_by_side -->
<div id="monimg-and-loot" style="height: 440px; display: table;">
<div style="float: left;"> <img id="monimg" src="./img/andy-d2r-resize.png" alt="Drop simulator boss or monster environment" style="padding: 0 1em 0 0; width: auto;"> </div>
<div id="loottxt-and-stash" style="float: left;">
<div class="row">
<div id="loottxt" style="float: left; height: 230px; width: 257px; margin: 0px 0px 0.68em; overflow: auto;"> Loot: <br> </div>
</div>
<div class="row"> <!-- loot scrollable textbox -->
<div id="stash" style="float: left; height: 200px; width: 257px; overflow: auto;"> Stash: <br> </div>
</div>
</div>
</div>
<br>
<div style="display: table;">
<p> Code available on <i class="fa fa-github"></i> <a href="https://github.com/pairofdocs/d2-dropsim-web/" style="color:#3392e6">github</a> </p>
</div>
<input type="checkbox" id="d2iosearch" name="d2iosearch"> <label for="d2iosearch">Search with diablo2.io only</label>
<script type="text/javascript">
var monStrImg = {
...{"Andarielq":"./img/andy-d2r-resize.png", "Durielq":"./img/duri-d2r-resize2.png", "Mephistoq":"./img/meph-d2r-resize2.png", "Diabloq":"./img/diab-d2r-resize2.png", "Baalq":"./img/baal-d2r-resize2.png", "Cow":"./img/cowlvl-d2r-resize2.png", "Countess":"./img/countess-d2r-resize2.png", "Council":"./img/council-d2r-resize2.png"},
...{"Andariel":"./img/andy-d2r-resize.png", "Duriel":"./img/duri-d2r-resize2.png", "Mephisto":"./img/meph-d2r-resize2.png", "Diablo":"./img/diab-d2r-resize2.png", "Baal":"./img/baal-d2r-resize2.png", "Cow King":"./img/cowlvl-d2r-resize2.png", "Nihlathak":"./img/nihla-d2lod-resize2.png", "Eldritch":"./img/eldritch-d2lod-resize2.png", "Pindleskin":"./img/pindle-d2lod-resize2.png"}
}
function changeImg() {
document.getElementById("monimg").src = monStrImg[document.getElementById("selectMon").value];
document.getElementById("loottxt").innerHTML = "Loot: <br><br>";
}
</script>
<script type="text/javascript">
var DIFFICULTIES = {'Normal': '', 'Nightmare': ' (N)', 'Hell': ' (H)'};
var TCPicks = {"Andarielq": 7, "Durielq": 5, "Mephistoq": 7, "Diabloq": 7, "Baalq": 7, "Cow": 1, "Countess": 1, "Council": 3}; // data from TreasureClassEx.txt
var TCPicks2 = {"Andariel": 7, "Duriel": 5, "Mephisto": 7, "Diablo": 7, "Baal": 7, "Cow King": 5, "Nihlathak": 5, "Eldritch": 1, "Pindleskin": 1}; // 1 --> -4 for superuniques
var TCPicks = {...TCPicks, ...TCPicks2 };
var unis = new Set(); // 379 uniques total. a uni jewel is counted once. Hellfire torch is not counted
var sets = new Set(); // 127 set items total
function addToStash(e) {
if (!e.target.hasAttribute("target") && !(e.target.className === "tooltiptext")) {
// append loot item with style.color. id ~ 'drop5-0'
var stashdiv = document.createElement("div");
stashdiv.innerHTML = e.target.innerHTML;
stashdiv.style.cssText = `color:${e.target.style.color}; cursor:pointer`;
stashdiv.className = "tooltip";
document.getElementById("stash").appendChild(stashdiv);
document.getElementById(e.target.id).remove();
// add confirmation window to stash item on click
stashdiv.addEventListener("click", removeFromStash);
};
};
function removeFromStash(e) {
if (!e.target.hasAttribute("target") && !(e.target.className === "tooltiptext")) {
if (confirm("Click 'OK' to remove this item")) {
e.target.remove()
}; };
};
function runx(e) {
// reset loot text area and prepare variables
document.getElementById("loottxt").innerHTML = "Loot: <br><br>";
var monstr = document.getElementById("selectMon").value + DIFFICULTIES[document.getElementById("selectDiff").value];
var players_str = (document.getElementById("selectPlayers").value).split(' ')[1];
var mf_str = document.getElementById("mftext").value;
var seed_str = document.getElementById("seedtext").value;
var tot_loot = {}; // alternative is to use a list. then take list.count(item). both cases are ~k*o(n) complexity. the number of items is limited since only unis, sets, runes are kept
try {
var xtimes = Math.max(parseInt(document.getElementById("xtimes").value || 1), 1);
}catch(e) {
var xtimes = 1;
}
var d2iosearch_bool = document.getElementById("d2iosearch").checked;
for (var xt = 0; xt < xtimes; xt++) {
var drops = [];
for (var i = 0; i < TCPicks[document.getElementById("selectMon").value]; i++) {
if (drops.length === 6) {
break;
}
var loot_items = final_rolls_from_tc(monstr, players_str, seed_str); // Hell difficulty hard-coded
for (var j = 0; j < loot_items.length; j++) {
loot_items[j] = name_from_armo_weap_misc(loot_items[j]['rolleditemtc'], mf_str, loot_items[j]['rootclass']); // expanded item names
}
if (loot_items.length > 0) {
for (var loot_item of loot_items) {
if (drops.length < 6) {
drops.push(loot_item.replace("Charm Large", "Grand Charm").replace("Charm Medium", "Large Charm").replace("Charm Small", "Small Charm"));
}; }; };
};
for (const [i, drop] of drops.entries()) {
if (drop.includes("uni~")) {
if (drop.includes("failed uni~")) {
if (drop.toLowerCase().includes('potion')) {
var color = "#e8f4ff"; // default light
} else {
var color = "#e8e83a"; // yellow
if (drop.toLowerCase().includes("charm")) {
color = "#4f7cfb"; // blue
}; };
} else {
unis.add(drop);
document.getElementById("grailUniques").innerHTML = "Uniques Found: " + unis.size.toString() + "/379";
var color = "#b77f00"; // gold
}
}else if (drop.includes("set~")) {
if (drop.includes("failed set~")) {
if (drop.toLowerCase().includes('potion')) {
var color = "#e8f4ff"; // default light
} else {
var color = "#4f7cfb"; // blue
}
} else {
sets.add(drop);
document.getElementById("grailSets").innerHTML = "Sets Found: " + sets.size.toString() + "/127";
var color = "#11c511"; // green
}
}else if (drop.includes("rare~")) {
if (drop.toLowerCase().includes('potion')) {
var color = "#e8f4ff"; // default light
} else {
var color = "#e8e83a"; // yellow
if (drop.toLowerCase().includes("charm")) {
color = "#4f7cfb"; // blue
}; };
}else if (drop.includes("magic~")) {
if (drop.toLowerCase().includes('potion')) {
var color = "#e8f4ff"; // default light
} else {
var color = "#4f7cfb"; // blue
}
}else if (drop.includes("normal~")) {
var color = "#e8f4ff"; // default light
}else if (drop.toLowerCase().includes("essence of") || drop.toLowerCase().includes(" rune") || drop.toLowerCase().includes("key of") || drop.toLowerCase().includes("puzzlebox")) {
var color = "#dc7409"; // orange
}else {
// reset color
var color = "#e8f4ff"; // default light
}
// if xtimes > 1, add unique, set, and rune color
if (d2iosearch_bool) {
linkstr = "https://duckduckgo.com/?q=site:diablo2.io+" + drop.split('~').slice(-1)[0].split(' ').join("+"); // JS .slice(-1)[0] like python's list[-1]
}else {
linkstr = "https://duckduckgo.com/?q=diablo2.io+" + drop.split('~').slice(-1)[0].split(' ').join("+");
}
var tooltip = '<span class="tooltiptext"> <a href="' + linkstr + '" target="_blank" style="color:#3392e6"> Search Item </a> </span>';
if (xtimes > 1) {
if (document.getElementById("selectMon").value === 'Cow' && !(drop.includes('Gold') || drop.includes('Potion') || drop.includes('Arrows') || drop.includes('Bolts') || drop.includes('Scroll') || drop.includes('Skeleton Key'))) {
var div_str = '<div class="tooltip" id="drop' + "-" + drop.split('~').slice(-1)[0] + '" style="cursor: pointer; color:' + color + '">' + drop.split('~').slice(-1)[0] + tooltip + '</div>';
if (!Object.keys(tot_loot).includes(div_str)) {
tot_loot[div_str] = 1;
}else {
tot_loot[div_str] += 1;
}
}else {
// add drop if color is uni,set,orange
if (["#b77f00", "#11c511", "#dc7409"].includes(color)) {
var div_str = '<div class="tooltip" id="drop' + "-" + drop.split('~').slice(-1)[0] + '" style="cursor: pointer; color:' + color + '">' + drop.split('~').slice(-1)[0] + tooltip + '</div>';
// document["loottxt"].html += div_str // div_str has id ~ id="drop-Tal Rune". not like 'drop0-0' below
// add to total loot dict. alternative is to use a list and list.append(). comp. cost is then shifted to list.count(item) afterwards
if (!Object.keys(tot_loot).includes(div_str)) {
tot_loot[div_str] = 1;
}else {
tot_loot[div_str] += 1;
}; }; };
}else {
var div_str = '<div class="tooltip" id="drop' + xt.toString() + "-" + i.toString() + '" style="cursor: pointer; color:' + color + '">' + drop.split('~').slice(-1)[0] + tooltip + '</div>';
document.getElementById("loottxt").innerHTML += div_str;
}
}
}
if (xtimes > 1) {
// sorted divs by drop name -v' categories uni+set (have extra space at the start of string), then runes/keys
// create array for JS. https://stackoverflow.com/questions/25500316/sort-a-dictionary-by-value-in-javascript and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
var count = Object.keys(tot_loot).map( key => { return [key, tot_loot[key]]; } );
// compare elements a,b of tor array and take the [0-th] index which includes the name . a == b ? 0 : a > b ? 1 : -1; (https://www.javascripttutorial.net/javascript-array-sort/)
count.sort((a, b) => {
a = a[0].split('">')[1].split('<span')[0];
b = b[0].split('">')[1].split('<span')[0];
return a == b ? 0 : a > b ? 1 : -1;
});
for (var [k,v] of count) {
var namestr = k.split('">')[1].split('<span')[0]; // get loot name between html tags
document.getElementById("loottxt").innerHTML += k.replace('>' + namestr, '>' + namestr + ' - ' + v.toString()); // replace 1st occurrence and add to html
}; // NOTE*** the default .replace() behavior is to replace only the first match, to replace all occurrences need replace('/ /g', _)
}
var children = document.getElementById("loottxt").children;
for (var i = 0; i < children.length; i++) {
// bind to id drop+str(i)
children[i].addEventListener("click", addToStash);
}
};
document.getElementById("run").addEventListener("click", runx);
// document["run"].bind("click", runx)
document.getElementById("par-1").innerHTML = "<em>Loaded</em>. Ready to farm? click 'Run'. Click an item to add it to the Stash. Click it in the Stash to remove it";
// document["par-1"].html = "<em>Loaded</em>. Ready to farm? click 'Run'. Click an item to add it to the Stash. Click it in the Stash to remove it"
</script>
</body>
</html>