-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
578 lines (482 loc) · 17.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="Newton Ni">
<meta name="description" content="Lost Ark ability stone optimal faceting calculator">
<meta name="keywords" content="ability stone, calculator, engraving, facet, Lost Ark">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
<title>Ability Stone Facet Calculator</title>
<style>
.parameter {
display: block;
font-size: 20px;
margin: 10px 0;
}
select {
font-size: 20px;
max-width: 200px;
}
input {
font-size: 20px;
max-width: 100px;
}
#grid {
display: grid;
justify-items: center;
align-items: center;
grid-template-rows: repeat(3, 50px);
}
#grid.rarity-6 { grid-template-columns: repeat(6, 50px) 260px; }
#grid.rarity-8 { grid-template-columns: repeat(8, 50px) 260px; }
#grid.rarity-9 { grid-template-columns: repeat(9, 50px) 260px; }
#grid.rarity-10 { grid-template-columns: repeat(10, 50px) 260px; }
.grid-row-0 {
grid-row-start: 1;
}
.grid-row-1 {
grid-row-start: 2;
}
.grid-row-2 {
grid-row-start: 3;
}
.grid-col {
color: Gainsboro;
font-size: 50px;
}
.grid-row-0.grid-success { color: rgb(87, 156, 201); }
.grid-row-1.grid-success { color: rgb(87, 156, 201); }
.grid-row-2.grid-success { color: rgb(214, 69, 59); }
.grid-row-0.grid-failure { color: rgb(87, 156, 201); }
.grid-row-1.grid-failure { color: rgb(87, 156, 201); }
.grid-row-2.grid-failure { color: rgb(214, 69, 59); }
.button-action {
font-size: 20px;
min-height: 40px;
min-width: 110px;
padding: 0;
margin: 0 10px;
background-color: white;
border-radius: 8px;
border-style: solid;
}
.button-action:hover {
background-color: Gainsboro;
}
.grid-row-0 .button-action { color: rgb(87, 156, 201); }
.grid-row-1 .button-action { color: rgb(87, 156, 201); }
.grid-row-2 .button-action { color: rgb(214, 69, 59);; }
.button-action.button-facet {
min-width: 220px;
}
.button-action.button-facet.button-facet-max {
border-color: rgb(204, 173, 0);
background-color: Gold;
}
.button-action.button-facet.button-facet-max:hover {
background-color: rgb(204, 173, 0);
}
.control {
font-size: 20px;
min-width: 120px;
min-height: 40px;
margin: 10px;
}
#instructions-toggle { color: Black; }
#instructions-toggle:hover { color: rgb(87, 156, 201); }
#instructions { max-width: 510px; }
#instructions ol li { margin: 10px 0; }
.hidden {
display: none;
overflow: hidden;
}
</style>
</head>
<body>
<div class="parameter">
<b><a href="https://github.com/nwtnni/facet">Ability Stone Facet Calculator</a></b>
</div>
<div class="parameter">
<div id="instructions-toggle">Expand instructions: ►</div>
<div id="instructions" class="hidden">
<p>
This calculator shows the <b>maximum probability</b> of achieving a <b>completed</b> stone
that satisfies <b>all</b> chosen minimum and maximum values. This probability is only accurate
if you select the calculator's optimal choice at <b>every</b> step. For basic usage:
</p>
<ol>
<li>Select rarity tier (number of slots per line).</li>
<li>Select target values for each line.</li>
<li>If your stone already has filled slots, facet the grid to match it using the hammer buttons on the right.</li>
<li><b>Click the Start button to begin calculating probabilities.</b></li>
<li>Each hammer shows the maximum probability of achieving the goal if you facet that line next.</li>
<li>Record the in-game outcome (success or failure) after clicking a hammer.</li>
<li>Repeat (5) - (6) with updated probabilities.</li>
</ol>
<p>
For example, clicking <b>Start</b> with the default settings shows that
there is a 4.81% chance of ending up with a 7+/7+/4- ability stone if you
choose line one first, but only a 2.86% chance if you choose line three first.
</p>
</div>
</div>
<div class="parameter">
<label for="rarity">Ability stone rarity:</label>
<select id="rarity">
<option value="6">Rare (6)</option>
<option value="8">Epic (8)</option>
<option value="9">Legendary (9)</option>
<option value="10" selected="selected">Relic (10)</option>
</select>
</div>
<div class="parameter">
<label for="target-line-0">Target minimum for first line:</label>
<input type="number" class="target" id="target-line-0" min="0" max="10" value="7">
</div>
<div class="parameter">
<label for="target-line-1">Target minimum for second line:</label>
<input type="number" class="target" id="target-line-1" min="0" max="10" value="7">
</div>
<div class="parameter">
<label for="target-line-2">Target maximum for third line:</label>
<input type="number" class="target" id="target-line-2" min="0" max="10" value="4">
</div>
<div class="parameter">
<label for="chance">Current chance of success:</label>
<input type="number" id="chance" min="25" max="75" step="10" value="75">
</div>
<div class="parameter">
<label for="chance">Probability precision (decimal places to display):</label>
<input type="number" id="precision" min="0" max="10" step="1" value="2">
</div>
<div id="grid">
</div>
<button id="start" class="control">Start</button>
<button id="undo" class="control">Undo</button>
<button id="reset" class="control">Reset</button>
<script type="module">
import * as facet from "./pkg/facet.js";
facet.default().then(() => {
const instructionsToggle = document.getElementById("instructions-toggle")
const instructions = document.getElementById("instructions")
const rarity = document.getElementById("rarity");
const target = document.querySelectorAll(".target");
const chance = document.getElementById("chance");
const precision = document.getElementById("precision");
const start = document.getElementById("start");
const grid = document.getElementById("grid");
const undo = [];
const facetButtons = [];
const successButtons = [];
const failureButtons = [];
const stone = [[], [], []];
const probability = [null, null, null];
let faceting = false;
function getRarity() {
return parseInt(rarity.value);
}
// Get next slot to roll in row.
function getCurrent(row) {
if (stone[row].length >= getRarity()) {
return null;
}
return grid.children[row * (getRarity() + 1) + stone[row].length];
}
// Get `div` containing action buttons (facet, success, failure) in row.
function getAction(row) {
if (stone[row].length >= getRarity()) {
return null;
}
return grid.children[row * (getRarity() + 1) + getRarity()];
}
// Return an ordinal within [0, 1, ..., 5] for compatibility with the Rust ABI.
function getChance() {
return Math.floor((parseInt(chance.value) - 25) / 10);
}
function getPrecision() {
return parseInt(precision.value);
}
function getStart() {
return start.textContent === "Stop";
}
function getTarget(row) {
return parseInt(target[row].value);
}
// Ensure chance is within [25, 35, ..., 75].
function clampChance(value) {
const clamped = Math.min(75, Math.max(25, value));
return Math.floor((clamped - 25) / 10) * 10 + 25;
}
// Ensure target is within [0, 1, ... rarity].
function clampTarget(value) {
return Math.max(0, Math.min(getRarity(), value));
}
function clampPrecision(value) {
return Math.max(0, Math.min(10, value));
}
function resetButtons() {
facetButtons.length = 0;
successButtons.length = 0;
failureButtons.length = 0;
}
function resetChance() {
chance.value = 75;
chance.previous = 75;
}
function resetTarget() {
for (let row = 0; row < 3; row++) {
target[row].value = clampTarget(parseInt(target[row].value));
target[row].previous = target[row].value;
}
}
function resetProbability() {
for (let row = 0; row < 3; row++) {
probability[row] = null;
if (facetButtons[row]) {
facetButtons[row].textContent = "🔨";
facetButtons[row].classList.remove("button-facet-max");
}
}
}
function resetStart() {
start.textContent = "Start";
}
function resetStone() {
for (let row of stone) {
row.length = 0;
}
}
function resetUndo() {
undo.length = 0;
}
// On a successful roll, the chance decreases by 10% to a minimum of 25%.
// On a failed roll, the chance increases by 10% to a maximum of 75%.
function updateChance(success) {
if (success) {
chance.value = Math.max(25, parseInt(chance.value) - 10);
} else {
chance.value = Math.min(75, parseInt(chance.value) + 10);
}
}
function updateUndo(row) {
undo.push([
[target[0].previous, target[1].previous, target[2].previous],
chance.previous,
row,
[...probability],
]);
chance.previous = chance.value;
for (let _row = 0; _row < 3; _row++) {
target[_row].previous = target[_row].value;
}
}
function computeProbability() {
if (!getStart()) {
return;
}
const _stone = new facet.Stone(
getChance(),
stone[0].reduce((a, b) => a + b, 0),
stone[1].reduce((a, b) => a + b, 0),
stone[2].reduce((a, b) => a + b, 0),
stone[0].length,
stone[1].length,
stone[2].length,
);
const _probability = facet.expectimax_wasm(
_stone,
getTarget(0),
getTarget(1),
getTarget(2),
getRarity(),
getRarity(),
getRarity(),
12,
);
for (let row = 0; row < 3; row++) {
probability[row] = _probability[row];
}
}
function updateProbability() {
if (!getStart()) {
return;
}
let max = probability.reduce((a, b) => Math.max(a, b));
for (let row = 0; row < 3; row++) {
const percentage = probability[row] * 100.0;
facetButtons[row].textContent = "🔨 (" + percentage.toFixed(getPrecision()) + "%)";
if (probability[row] === max && getAction(row)) {
facetButtons[row].classList.add("button-facet-max");
max = null;
} else {
facetButtons[row].classList.remove("button-facet-max");
}
}
}
function onFacet(row) {
const action = getAction(row);
action.appendChild(successButtons[row]);
action.appendChild(failureButtons[row]);
faceting = true;
for (let any = 0; any < 3; any++) {
if (getAction(any)) {
getAction(any).removeChild(facetButtons[any]);
}
}
}
function onRecord(row, success) {
const action = getAction(row);
action.removeChild(successButtons[row]);
action.removeChild(failureButtons[row]);
faceting = false;
const current = getCurrent(row);
if (success) {
current.classList.add("grid-success");
current.textContent = "◆";
} else {
current.classList.add("grid-failure");
}
stone[row].push(success);
updateChance(success);
updateUndo(row);
computeProbability();
updateProbability();
for (let any = 0; any < 3; any++) {
if (getAction(any)) {
getAction(any).appendChild(facetButtons[any]);
}
}
}
function onUndo() {
if (undo.length === 0) {
return;
}
const [_target, _chance, row, _probability] = undo.pop();
if (row !== null) {
stone[row].pop();
const current = getCurrent(row);
current.textContent = "◇";
current.classList.remove("grid-success");
current.classList.remove("grid-failure");
if (!faceting) {
getAction(row).appendChild(facetButtons[row]);
}
}
chance.value = _chance;
chance.previous = _chance;
for (let row = 0; row < 3; row++) {
target[row].value = _target[row];
target[row].previous = _target[row];
}
if (_probability.every(defined => defined)) {
for (let row = 0; row < 3; row++) {
probability[row] = _probability[row];
}
} else {
computeProbability();
}
updateProbability();
}
function resetGrid() {
resetButtons();
resetChance();
resetProbability();
resetStart();
resetStone();
resetTarget();
resetUndo();
grid.textContent = "";
grid.className = "rarity-" + getRarity();
for (let row = 0; row < 3; row++) {
for (let col = 0; col < getRarity(); col++) {
const div = document.createElement("div");
div.className = "grid-col";
div.classList.add("grid-row-" + row);
div.textContent = "◇";
grid.appendChild(div);
}
const action = document.createElement("div");
action.classList.add("grid-row-" + row);
action.classList.add("grid-action");
const facet = document.createElement("button");
facet.textContent = "🔨";
facet.classList.add("button-facet");
facet.classList.add("button-action");
facet.onclick = () => onFacet(row);
facetButtons.push(facet);
action.appendChild(facet);
const success = document.createElement("button");
success.textContent = "◆";
success.classList.add("button-action");
success.onclick = () => onRecord(row, true);
successButtons.push(success);
const failure = document.createElement("button");
failure.textContent = "◇";
failure.classList.add("button-action");
failure.onclick = () => onRecord(row, false);
failureButtons.push(failure);
grid.appendChild(action);
}
}
start.onclick = () => {
start.textContent = (start.textContent === "Start") ? "Stop" : "Start";
if (getStart()) {
computeProbability();
updateProbability();
} else {
resetProbability();
}
};
chance.previous = 75;
chance.onchange = change => {
const previous = parseInt(chance.previous);
chance.value = clampChance(parseInt(chance.value));
if (previous === chance.value) {
return;
}
updateUndo(null);
computeProbability();
updateProbability();
};
for (let row = 0; row < 3; row++) {
target[row].previous = (row === 2) ? 4 : 7;
target[row].onchange = () => {
const previous = parseInt(target[row].previous);
target[row].value = clampTarget(parseInt(target[row].value));
if (previous === target[row].value) {
return;
}
updateUndo(null);
computeProbability();
updateProbability();
}
}
precision.onchange = () => {
precision.value = clampPrecision(getPrecision());
updateProbability();
}
rarity.previous = rarity.value;
rarity.onchange = () => {
if (stone.every(line => line.length === 0) || confirm("This will clear the grid. Are you sure you want to reset?")) {
rarity.previous = rarity.value;
resetGrid();
} else {
rarity.value = rarity.previous;
}
};
document.getElementById("undo").onclick = () => onUndo();
document.getElementById("reset").onclick = rarity.onchange;
instructionsToggle.onclick = () => {
if (instructionsToggle.textContent.startsWith("Expand")) {
instructions.classList.remove("hidden");
instructionsToggle.textContent = "Collapse instructions: ▼"
} else {
instructions.classList.add("hidden");
instructionsToggle.textContent = "Expand instructions: ►"
}
};
resetGrid();
});
</script>
</body>
</html>