-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
563 lines (516 loc) · 28.2 KB
/
Copy pathindex.html
File metadata and controls
563 lines (516 loc) · 28.2 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PvP Filter Generator v45</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 20px; background: #121212; color: #eee; }
.container { max-width: 950px; margin: auto; background: #1e1e1e; padding: 25px; border-radius: 12px; border: 1px solid #333; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
input, select { width: 100%; padding: 12px; margin: 10px 0; background: #2d2d2d; border: 1px solid #444; color: white; border-radius: 6px; box-sizing: border-box; }
.flex { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.options-row { background: #252525; padding: 15px; border-radius: 8px; margin-bottom: 15px; border: 1px solid #333; }
button { flex: 1; padding: 12px; cursor: pointer; border-radius: 6px; font-weight: bold; border: none; transition: 0.2s; font-size: 13px; }
.btn-blue { background: #2980b9; color: white; }
.btn-orange { background: #e67e22; color: white; }
.btn-green { background: #27ae60; color: white; margin-top: 10px; }
.btn-clear { background: #c0392b; color: white; max-width: 120px; }
.queue-box { background: #111; padding: 15px; border-radius: 8px; margin: 15px 0; border: 1px dashed #444; }
.queue-item { display: block; background: #2a2a2a; padding: 8px 12px; margin: 5px 0; border-radius: 4px; font-size: 13px; border-left: 4px solid #2980b9; position: relative; }
.type-slayer { border-left-color: #e67e22; }
.stat-badge { color: #f1c40f; font-weight: bold; margin-left: 10px; font-family: monospace; }
.remove-btn { position: absolute; right: 10px; top: 8px; color: #ff4d4d; cursor: pointer; font-weight: bold; }
label { font-size: 13px; color: #bbb; cursor: pointer; }
.guide { background: #1a1a1a; padding: 15px; border-radius: 8px; margin-bottom: 20px; border: 1px solid #333; font-size: 13px; color: #ccc; line-height: 1.6; }
.guide h3 { margin-top: 0; color: #2980b9; font-size: 16px; }
pre { background: #000; color: #00ff00; padding: 15px; border-radius: 8px; font-size: 11px; max-height: 300px; overflow-y: auto; border: 1px solid #333; }
.section-label { color: #3498db; font-weight: bold; font-size: 0.85em; display: block; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.toggle-group { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-toggle { background: #2d2d2d; color: #888; border: 1px solid #444 !important; flex: none; padding: 8px 16px; font-size: 13px; border-radius: 6px; cursor: pointer; transition: 0.2s; font-weight: bold; }
.btn-toggle:hover { border-color: #666 !important; color: #ccc; }
.btn-toggle.active { background: #2980b9; color: white; border-color: #2980b9 !important; }
.btn-toggle.active-gold { background: #f39c12; color: #1a1a1a; border-color: #f39c12 !important; }
.divider { border: none; border-top: 1px solid #333; margin: 12px 0; }
</style>
</head>
<body>
<div class="container">
<h2 style="text-align: center; color: #2980b9; margin-bottom: 5px;">PvP Filter Generator v45</h2>
<p style="text-align: center; color: #888; margin-bottom: 25px; font-size: 14px;">Optimized for PolygonX #Encounter-Filters</p>
<div class="guide">
<h3>📖 How to Use</h3>
<strong>1. Search:</strong> Type a Pokémon name. It targets the base form automatically.<br>
<strong>2. League:</strong> Choose your target CP limit (LL, GL, or UL).<br>
<strong>3. Options:</strong>
<ul>
<li><em>Include Family:</em> Adds the whole evolution line to the filter.</li>
<li><em>Only Shiny:</em> Bot will only catch the shiny version.</li>
</ul>
<strong>4. Archetypes:</strong> The <strong>Orange Button</strong> adds a Trio: <strong>Bulk</strong> (Rank 1), <strong>Mid</strong> (+5% Atk), and <strong>Breaker</strong> (+10% Atk, flips matchups via fast move damage).<br>
<strong>5. Download:</strong> Add your Pokémon, then hit the green download button and import to Polygon.
</div>
<div id="status" style="text-align:center; font-weight:bold; margin-bottom:15px; color:#aaa;">Connecting to GameData...</div>
<div class="options-row" style="background: #252525; padding: 15px; border-radius: 8px; border: 1px solid #333; margin-bottom: 10px; position: relative;">
<label style="color: #3498db; font-weight: bold; font-size: 0.9em; display: block; margin-bottom: 5px;">
Search for Pokémon here you want added:
</label>
<input type="text" id="pkmInput" placeholder="e.g. Dondozo..." autocomplete="off"
style="width: 100%; box-sizing: border-box; padding: 10px; border-radius: 6px; border: 1px solid #444; background: #1a1a1a; color: white; margin: 0;">
<div id="pkmSuggestions" style="display:none; position:absolute; left:15px; right:15px; background:#1a1a1a; border:1px solid #444; border-radius:0 0 6px 6px; max-height:200px; overflow-y:auto; z-index:200; box-shadow:0 4px 12px rgba(0,0,0,0.5);"></div>
</div>
<div class="options-row" style="background: #252525; border-radius: 8px; border: 1px solid #333; margin-bottom: 10px; overflow: hidden;">
<button onclick="toggleBulk()" style="width: 100%; background: #2d2d2d; color: #3498db; border: none; padding: 12px; text-align: left; cursor: pointer; font-weight: bold; display: flex; justify-content: space-between; align-items: center;">
<span>⚡ BULK ADD MENU</span>
<span id="bulkArrow">▼</span>
</button>
<div id="bulkContent" style="display: none; padding: 15px; background: #252525; border-top: 1px solid #333;">
<label style="color: #888; font-size: 0.8em; display: block; margin-bottom: 5px;">PASTE LIST (COMMA SEPARATED):</label>
<textarea id="bulkInput" placeholder="Lapras, Steelix, Dondozo..."
style="width: 100%; max-width: 100%; box-sizing: border-box; height: 60px; background: #1a1a1a; color: white; border-radius: 6px; padding: 10px; border: 1px solid #444; resize: none;"></textarea>
<button class="btn-blue" onclick="processBulk()" style="margin-top: 10px; width: 100%; font-weight: bold;">ADD ALL AS RANK 1</button>
</div>
</div>
<!-- LEAGUE -->
<div class="options-row">
<span class="section-label">🏆 League</span>
<div class="toggle-group">
<button class="btn-toggle" id="leagueLL" onclick="setLeague(500,this)">LL (500)</button>
<button class="btn-toggle active" id="leagueGL" onclick="setLeague(1500,this)">GL (1500)</button>
<button class="btn-toggle" id="leagueUL" onclick="setLeague(2500,this)">UL (2500)</button>
</div>
</div>
<!-- ITEMS -->
<div class="options-row">
<span class="section-label">🎒 Poké Ball</span>
<div class="toggle-group">
<button class="btn-toggle" id="ball1" onclick="setBall(1,this)">🔴 Poké Ball</button>
<button class="btn-toggle" id="ball2" onclick="setBall(2,this)">🔵 Great Ball</button>
<button class="btn-toggle active" id="ball3" onclick="setBall(3,this)">⚫ Ultra Ball</button>
</div>
<hr class="divider">
<span class="section-label">🍓 Berry</span>
<div class="toggle-group">
<button class="btn-toggle" id="berryNone" onclick="setBerry(0,this)">None</button>
<button class="btn-toggle" id="berry703" onclick="setBerry(703,this)">Razz</button>
<button class="btn-toggle" id="berry704" onclick="setBerry(704,this)">Nanab</button>
<button class="btn-toggle" id="berry705" onclick="setBerry(705,this)">Pinap</button>
<button class="btn-toggle active active-gold" id="berry706" onclick="setBerry(706,this)">⭐ Gold Razz</button>
<button class="btn-toggle" id="berry707" onclick="setBerry(707,this)">Silver Pinap</button>
</div>
</div>
<!-- OPTIONS -->
<div class="options-row">
<span class="section-label">⚙️ Options</span>
<div style="display:flex; gap:15px; flex-wrap:wrap;">
<label><input type="checkbox" id="isShiny"> Shiny Only</label>
<label><input type="checkbox" id="addEvolutions"> Include Family</label>
</div>
</div>
<div class="options-row">
<span class="section-label">➕ Add to Queue</span>
<div class="flex">
<button class="btn-blue" onclick="addRanks(1)">Rank 1</button>
<button class="btn-blue" onclick="addRanks(5)">Ranks 1-5</button>
<div style="display:flex; gap:5px; flex:2;">
<input type="number" id="customRank" placeholder="Max Rank (e.g. 10)" style="margin:0;">
<button class="btn-blue" onclick="addCustomRanks()">Add</button>
</div>
</div>
<div class="flex" style="margin-top:8px;">
<button class="btn-orange" onclick="addGenerateAll()">⚡ Generate All (LL / GL / UL)</button>
</div>
<button class="btn-orange" id="specialBtn" onclick="addArchetypes()" disabled style="margin-top:10px; width:100%;">+ Add Breakpoint Trio (Bulk / Mid / Breaker)</button>
</div>
<div class="queue-box">
<strong>Queue:</strong>
<div id="queueList"><i>Empty...</i></div>
</div>
<div class="flex">
<button class="btn-green" id="dlBtn" onclick="downloadJson()" disabled>⬇ Download .json</button>
<button class="btn-clear" onclick="clearQueue()">Clear All</button>
</div>
<div style="margin-top:12px; text-align:right;">
<button id="debugToggleBtn" onclick="toggleDebug()" style="flex:none; padding:6px 14px; font-size:12px; background:#2d2d2d; color:#888; border:1px solid #444; border-radius:6px; cursor:pointer; font-weight:bold;">🐛 Debug View: OFF</button>
</div>
<div id="debugPanel" style="display:none; margin-top:8px;">
<pre id="output">// Add Pokémon to see JSON preview...</pre>
</div>
</div>
<script>
// (Previous Script Logic remains exactly the same as v27)
const CPM = {1:0.094,1.5:0.13513743,2:0.16639787,2.5:0.19265092,3:0.21573247,3.5:0.23657266,4:0.25572005,4.5:0.27353038,5:0.29024988,5.5:0.30605737,6:0.3210876,6.5:0.33544501,7:0.34921903,7.5:0.36248612,8:0.37523559,8.5:0.38753336,9:0.39940354,9.5:0.41088741,10:0.42250001,10.5:0.43292641,11:0.44310755,11.5:0.45305995,12:0.46279839,12.5:0.47233608,13:0.48168495,13.5:0.4908558,14:0.49985844,14.5:0.50870178,15:0.51739395,15.5:0.52594251,16:0.53435433,16.5:0.54263576,17:0.55079269,17.5:0.55883057,18:0.56675452,18.5:0.57456915,19:0.58227891,19.5:0.5898879,20:0.59740001,20.5:0.60481881,21:0.61215731,21.5:0.61940412,22:0.62656713,22.5:0.63364917,23:0.64065295,23.5:0.64758097,24:0.65444234,24.5:0.6612148,25:0.667934,25.5:0.6746042,26:0.68121313,26.5:0.6877694,27:0.69427237,27.5:0.70072386,28:0.7071249,28.5:0.71347725,29:0.71978236,29.5:0.72604155,30:0.7317,30.5:0.734741,31:0.73776948,31.5:0.74078557,32:0.74378943,32.5:0.74678121,33:0.74976104,33.5:0.75272908,34:0.75568551,34.5:0.75863037,35:0.76156384,35.5:0.76448606,36:0.76739717,36.5:0.77029727,37:0.7731865,37.5:0.77606498,38:0.77892748,38.5:0.78177373,39:0.78460312,39.5:0.78741585,40:0.7903,40.5:0.7928,41:0.7953,41.5:0.7978,42:0.8003,42.5:0.8028,43:0.8053,43.5:0.8078,44:0.8103,44.5:0.8128,45:0.8153,45.5:0.8178,46:0.8203,46.5:0.8228,47:0.8253,47.5:0.8278,48:0.8303,48.5:0.8328,49:0.8353,49.5:0.8378,50:0.8403};
let masterFileData = null; // Declare this globally so getBaseIds can see it
let pokemonData = [];
let queue = [];
let selectedLeague = 1500;
let selectedBall = 3;
let selectedBerry = 706;
function setLeague(val, btn) {
selectedLeague = val;
document.querySelectorAll('#leagueLL,#leagueGL,#leagueUL').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
}
function setBall(val, btn) {
selectedBall = val;
document.querySelectorAll('#ball1,#ball2,#ball3').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
}
function setBerry(val, btn) {
selectedBerry = val;
document.querySelectorAll('#berryNone,#berry703,#berry704,#berry705,#berry706,#berry707').forEach(b => {
b.classList.remove('active');
b.classList.remove('active-gold');
});
if (val === 706) btn.classList.add('active-gold');
btn.classList.add('active');
}
function toggleDebug() {
const panel = document.getElementById('debugPanel');
const btn = document.getElementById('debugToggleBtn');
const opening = panel.style.display === 'none';
panel.style.display = opening ? 'block' : 'none';
btn.textContent = opening ? '🐛 Debug View: ON' : '🐛 Debug View: OFF';
btn.style.color = opening ? '#27ae60' : '#888';
btn.style.borderColor = opening ? '#27ae60' : '#444';
if (opening) updatePreview();
}
function updatePreview() {
if (document.getElementById('debugPanel').style.display === 'none') return;
document.getElementById('output').textContent = JSON.stringify({ encounterFilters: buildFilters() }, null, 2);
}
async function init() {
try {
document.getElementById('status').innerText = "FETCHING MASTERFILES...";
const [pvpokeRes, masterRes] = await Promise.all([
fetch('https://raw.githubusercontent.com/pvpoke/pvpoke/master/src/data/gamemaster.json'),
fetch('https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/refs/heads/master/master-latest-raw.json')
]);
const pvpokeData = await pvpokeRes.json();
masterFileData = await masterRes.json();
pokemonData = pvpokeData.pokemon;
initAutocomplete();
document.getElementById('status').innerText = "SYSTEM ARMED ✔️";
document.getElementById('specialBtn').disabled = false;
} catch (e) {
console.error(e);
document.getElementById('status').innerText = "CONNECTION ERROR!";
}
}
function initAutocomplete() {
const input = document.getElementById('pkmInput');
const box = document.getElementById('pkmSuggestions');
input.addEventListener('input', () => {
const val = input.value.toLowerCase().trim();
box.innerHTML = '';
if (val.length < 2) { box.style.display = 'none'; return; }
const matches = pokemonData
.filter(p => !p.speciesId.includes('_shadow') && !p.speciesId.includes('_mega') && p.speciesName.toLowerCase().includes(val))
.slice(0, 25);
if (!matches.length) { box.style.display = 'none'; return; }
matches.forEach(p => {
const div = document.createElement('div');
div.textContent = p.speciesName;
div.style.cssText = 'padding:8px 12px; cursor:pointer; border-bottom:1px solid #2a2a2a; color:#eee;';
div.addEventListener('mouseover', () => div.style.background = '#2d2d2d');
div.addEventListener('mouseout', () => div.style.background = '');
div.addEventListener('mousedown', e => {
e.preventDefault();
input.value = p.speciesName;
box.style.display = 'none';
});
box.appendChild(div);
});
box.style.display = 'block';
});
document.addEventListener('click', e => {
if (!box.contains(e.target) && e.target !== input) box.style.display = 'none';
});
}
// Helper to get selected berries/balls
function getSelectedItems(className) {
return Array.from(document.querySelectorAll('.' + className + ':checked')).map(cb => parseInt(cb.value));
}
// BULK PROCESSING FUNCTION
function processBulk() {
const input = document.getElementById('bulkInput').value;
if (!input.trim()) return alert("Please paste some names first!");
const names = input.split(',').map(n => n.trim());
let addedCount = 0;
const league = selectedLeague;
const code = league === 500 ? "LL" : league === 1500 ? "GL" : "UL";
const shiny = document.getElementById('isShiny').checked;
names.forEach(name => {
const pkm = pokemonData.find(x => x.speciesName.toLowerCase() === name.toLowerCase());
if (pkm) {
const all = calculateAllSpreads(pkm, league);
const ids = getBaseIds(pkm); // Your existing getBaseIds
queue.push({
name: pkm.speciesName,
label: "Rank 1",
ivText: `${all[0].a}/${all[0].d}/${all[0].s}`,
atk: all[0].realAtk.toFixed(1),
league: code,
ids: ids,
ivs: [all[0]],
shiny: shiny,
class: ""
});
addedCount++;
}
});
document.getElementById('bulkInput').value = '';
updateUI();
if(addedCount > 0) alert(`Added ${addedCount} Pokémon to the queue!`);
}
function toggleBulk() {
const content = document.getElementById('bulkContent');
const arrow = document.getElementById('bulkArrow');
if (content.style.display === "none") {
content.style.display = "block";
arrow.innerText = "▲";
} else {
content.style.display = "none";
arrow.innerText = "▼";
}
}
// Egg-only baby Pokémon that never appear in the wild — skip these when resolving first stage
const EGG_ONLY_DEX_IDS = new Set([
172, // Pichu
173, // Cleffa
174, // Igglybuff
175, // Togepi
236, // Tyrogue
238, // Smoochum
239, // Elekid
240, // Magby
298, // Azurill
360, // Wynaut
406, // Budew
433, // Chingling
438, // Bonsly
439, // Mime Jr.
440, // Happiny
446, // Munchlax
447, // Riolu
458, // Mantyke
848, // Toxel
]);
function resolveFormId(dexId, fullName) {
if (!masterFileData || !masterFileData.pokemon || !masterFileData.pokemon[dexId]) return 0;
const masterPkm = masterFileData.pokemon[dexId];
let detectedForm = masterPkm.defaultFormId || 0;
const formMatch = fullName.match(/\(([^)]+)\)/);
if (formMatch) {
let extracted = formMatch[1].toLowerCase().trim();
let normalized = extracted;
if (normalized === "alolan") normalized = "alola";
if (normalized === "galarian") normalized = "galar";
if (normalized === "hisuian") normalized = "hisui";
if (normalized === "paldean") normalized = "paldea";
let protoSuffix = extracted;
if (extracted === "alolan") protoSuffix = "alola";
if (extracted === "paldean") protoSuffix = "paldea";
if (masterPkm.forms) {
// Exact formName match first — prevents e.g. "pompom" substring-matching "baile"
for (const [fId, fData] of Object.entries(masterPkm.forms)) {
if ((fData.formName || "").toLowerCase() === normalized) {
detectedForm = parseInt(fId); break;
}
}
// Substring fallback if exact match found nothing
if (detectedForm === (masterPkm.defaultFormId || 0)) {
for (const [fId, fData] of Object.entries(masterPkm.forms)) {
const proto = fData.proto ? fData.proto.toLowerCase() : "";
const formName = fData.formName ? fData.formName.toLowerCase() : "";
if (proto.includes(normalized) || formName.includes(normalized)) {
detectedForm = parseInt(fId); break;
}
}
}
}
if (detectedForm === (masterPkm.defaultFormId || 0) && masterFileData.forms) {
const baseName = fullName.replace(/\s*\(.*\)/, '').trim().toUpperCase();
const expectedProto = `${baseName}_${protoSuffix.toUpperCase()}`;
for (const [fId, fData] of Object.entries(masterFileData.forms)) {
if (fData.proto && fData.proto.toUpperCase() === expectedProto) {
detectedForm = parseInt(fId);
console.log(`[DEBUG] ✅ Fallback matched formId ${detectedForm} (${expectedProto})`);
break;
}
}
}
}
console.log(`[ID MAPPER] Result -> ${fullName} | Form: ${detectedForm}`);
return detectedForm;
}
// Walk up family.parent chain to find the first *catchable* stage.
// Skips egg-only baby Pokémon that never spawn in the wild.
function getFirstStage(pkm) {
if (pkm.family && pkm.family.parent) {
const parent = pokemonData.find(p => p.speciesId === pkm.family.parent);
if (parent && !EGG_ONLY_DEX_IDS.has(parent.dex)) {
return getFirstStage(parent); // recurse up only if parent is catchable
}
}
return pkm;
}
function getBaseIds(targetPkm) {
const basePkm = getFirstStage(targetPkm);
const addEvos = document.getElementById('addEvolutions').checked;
let chain = [basePkm];
if (addEvos && basePkm.family && basePkm.family.evolutions) {
basePkm.family.evolutions.forEach(evoName => {
const evo = pokemonData.find(p => p.speciesId === evoName);
if (evo) chain.push(evo);
});
}
let pkmIds = chain.map(pkm => {
const formId = resolveFormId(pkm.dex, pkm.speciesName);
let gender = 0;
if (pkm.family && pkm.family.evolutions) {
for (const evoName of pkm.family.evolutions) {
const evo = pokemonData.find(p => p.speciesId === evoName);
if (evo) {
const evoMaster = masterFileData?.pokemon?.[evo.dex];
const genderReq = evoMaster?.genderRequirement ?? 0;
if (genderReq > 0) { gender = genderReq; break; }
}
}
}
return { pokedexId: pkm.dex, form: formId, costume: 0, gender };
});
// Always append Arceus as catch-all placeholder
pkmIds.push({ pokedexId: 493, form: 0, costume: 0, gender: 0 });
return pkmIds;
}
// Ensure your calculateAllSpreads includes the level property:
function calculateAllSpreads(pkm, limit) {
let spreads = [];
const bAtk = pkm.baseStats.atk, bDef = pkm.baseStats.def, bSta = pkm.baseStats.sta || pkm.baseStats.hp;
for (let a = 0; a <= 15; a++) {
for (let d = 0; d <= 15; d++) {
for (let s = 0; s <= 15; s++) {
let bestLvl = 1;
for (let l = 1; l <= 50; l += 0.5) {
let cp = Math.floor((bAtk+a) * Math.sqrt(bDef+d) * Math.sqrt(bSta+s) * Math.pow(CPM[l],2) / 10);
if (cp > limit) break;
bestLvl = l;
}
let cpm = CPM[bestLvl];
let realAtk = (bAtk + a) * cpm;
let prod = realAtk * ((bDef + d) * cpm) * Math.floor((bSta + s) * cpm);
let cp = Math.floor((bAtk+a) * Math.sqrt(bDef+d) * Math.sqrt(bSta+s) * Math.pow(cpm,2) / 10);
spreads.push({ a, d, s, prod, realAtk, level: bestLvl, cp });
}
}
}
// Sort by stat product desc, tie-break by CP desc
return spreads.sort((x, y) => y.prod !== x.prod ? y.prod - x.prod : y.cp - x.cp);
}
function addRanks(count) {
const pkm = pokemonData.find(x => x.speciesName === document.getElementById('pkmInput').value);
if (!pkm) return alert("Select Pokemon!");
const all = calculateAllSpreads(pkm, selectedLeague);
const ids = getBaseIds(pkm);
const shiny = document.getElementById('isShiny').checked;
const rank1 = all[0];
const ivDisplay = count === 1 ? `${rank1.a}/${rank1.d}/${rank1.s}` : `Rank 1-${count} Set`;
const label = count === 1 ? "Rank 1" : `Rank 1-${count}`;
const code = selectedLeague === 500 ? "LL" : selectedLeague === 1500 ? "GL" : "UL";
queue.push({ name: pkm.speciesName, label, ivText: ivDisplay, atk: rank1.realAtk.toFixed(1), league: code, ids, ivs: all.slice(0, count), shiny, class: "" });
updateUI();
}
function addCustomRanks() {
const val = parseInt(document.getElementById('customRank').value);
if (!val || val < 1) return alert("Enter a valid rank number.");
addRanks(val);
}
function addArchetypes() {
const pkm = pokemonData.find(x => x.speciesName === document.getElementById('pkmInput').value);
if (!pkm) return alert("Select Pokemon!");
const all = calculateAllSpreads(pkm, selectedLeague);
const ids = getBaseIds(pkm);
const shiny = document.getElementById('isShiny').checked;
const lc = selectedLeague === 500 ? "LL" : selectedLeague === 1500 ? "GL" : "UL";
const bulk = all[0];
const highestAtk = [...all].sort((a,b) => b.realAtk - a.realAtk)[0];
const mid = all.filter(x => x.realAtk >= (bulk.realAtk * 1.05) && x.prod >= (bulk.prod * 0.90) && x.s >= 5).sort((a,b) => b.prod - a.prod)[0] || highestAtk;
const breaker = all.filter(x => x.realAtk >= (bulk.realAtk * 1.10) && x.prod >= (bulk.prod * 0.80) && x.s >= 5).sort((a,b) => b.prod - a.prod)[0] || highestAtk;
[["BULK", bulk], ["MID", mid], ["BREAKER", breaker]].forEach(([label, item]) => {
queue.push({ name: pkm.speciesName, label, ivText: `${item.a}/${item.d}/${item.s}`, atk: item.realAtk.toFixed(1), league: lc, ids, ivs: [item], shiny, class: "type-slayer" });
});
updateUI();
}
function addGenerateAll() {
const pkm = pokemonData.find(x => x.speciesName === document.getElementById('pkmInput').value);
if (!pkm) return alert("Select a Pokémon first!");
const shiny = document.getElementById('isShiny').checked;
[[500,"LL"],[1500,"GL"],[2500,"UL"]].forEach(([league, code]) => {
const all = calculateAllSpreads(pkm, league);
queue.push({ name: pkm.speciesName, label: "Rank 1", ivText: `${all[0].a}/${all[0].d}/${all[0].s}`, atk: all[0].realAtk.toFixed(1), league: code, ids: getBaseIds(pkm), ivs: [all[0]], shiny, class: "" });
});
updateUI();
}
function updateUI() {
const container = document.getElementById('queueList');
if (!queue.length) {
container.innerHTML = '<i>Empty...</i>';
document.getElementById('dlBtn').disabled = true;
return;
}
container.innerHTML = queue.map((item, index) => `
<div class="queue-item ${item.class}">
<strong>${item.name}</strong> [${item.label}]
<span style="color:#aaa; margin-left:6px;">${item.ivText}</span>
<span class="stat-badge">ATK: ${item.atk}</span>
<span style="color:#888; font-size:11px; margin-left:6px;">Lvl ${item.ivs[0].level} · ${item.league}</span>
<span class="remove-btn" onclick="queue.splice(${index},1);updateUI()">×</span>
</div>
`).join('');
document.getElementById('dlBtn').disabled = false;
updatePreview();
}
function clearQueue() { queue = []; updateUI(); }
function buildFilters() {
const filters = {};
const balls = selectedBall > 0 ? [selectedBall] : [];
const berries = selectedBerry > 0 ? [selectedBerry] : [];
queue.forEach(item => {
const id = crypto.randomUUID();
filters[id] = {
catchOptionsBerries: berries,
catchOptionsPokeballs: balls,
cpMax: 0, cpMin: 0,
enabled: true,
encounterFilterId: id,
encounterFilterName: `${item.name.toUpperCase()} ${item.label} (${item.league})`,
filterCp: false, filterGreatLeagueTopRank: false, filterIvSum: false,
filterLevel: true, filterOnlyCatch: item.shiny, filterPokemonId: true,
filterShowcaseScore: false, filterSize: false, filterSpecificIv: true,
filterType: false, filterUltraLeagueTopRank: false,
ivSets: item.ivs.map(iv => ({ ivAtk: iv.a, ivDef: iv.d, ivSta: iv.s })),
ivSumMax: 0, ivSumMin: 0,
levelMax: Math.ceil(item.ivs[0].level), levelMin: 1,
minShowcaseScore: 0,
onlyApplyPurificationBonus: false, onlyBackground: false, onlyShiny: item.shiny,
pokemonDetailsCatchOriginDmax: false,
pokemonId: item.ids,
removePokemonIdFromListThreshold: 1, removePokemonIdFromListWhenCaught: true,
sizeXl: false, sizeXs: false, sizeXxl: false, sizeXxs: false,
targetTypes: []
};
});
return filters;
}
// UPDATED DOWNLOAD FUNCTION
function downloadJson() {
const blob = new Blob([JSON.stringify({ encounterFilters: buildFilters() }, null, 2)], { type: "application/json" });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'PolygonX_PvP_Filters.json';
a.click();
}
init();
</script>
</body>
</html>