`
profileModal.before(filterMod);
const modalBody = document.querySelector('[id=filterModal] div div [class=modal-body]');
modalBody.innerHTML = `
`
// Re-assigning the previous document fragment
frag = new DocumentFragment();
window.filterTypes.forEach((Type, Index) => {
const typeName = PokemonType[Index];
const btn = document.createElement('button');
btn.innerText = `${typeName} ${Type ? '[ON]' : '[OFF]'}`;
btn.setAttribute('class', `btn btn-${Type ? 'success' : 'danger'}`);
btn.setAttribute('data-src', Index);
btn.addEventListener('click', (event) => { toggleTypeFilter(event); });
frag.appendChild(btn);
})
document.getElementById('filter-btn-cont').appendChild(frag);
document.getElementById('filter-load').addEventListener('click', () => { loadFilteredList(); });
document.getElementById('filter-route').addEventListener('click', (event) => { filterPokemonRoute(event); });
document.getElementById('filter-dungeon').addEventListener('click', (event) => { filterPokemonDungeon(event); });
document.getElementById('filter-all').addEventListener('click', () => { filterAllPoke(); });
document.getElementById('unfilter-all').addEventListener('click', () => { unfilterAllPoke(); });
document.getElementById('reset-ball-filter').addEventListener('click', () => { resetBallFilterAll(); });
document.getElementById('catch-filter').addEventListener('click', (event) => { toggleCatchFilter(event); });
document.getElementById('filter-search').addEventListener('input', (event) => { filterPokeSearch(event); });
overideDefeatPokemon();
loadFilteredList();
}
function toggleTypeFilter(event) {
const elem = event.target;
const index = +elem.getAttribute('data-src');
const typeName = PokemonType[index];
if (window.filterTypes[index]) {
window.filterTypes[index] = false;
} else {
window.filterTypes[index] = true;
}
elem.setAttribute('class', `btn btn-${window.filterTypes[index] ? 'success' : 'danger'}`);
elem.innerText = `${typeName} ${window.filterTypes[index] ? '[ON]' : '[OFF]'}`;
localStorage.setItem('filterTypes', JSON.stringify(window.filterTypes));
}
function loadFilteredList() {
if (window.catchFilter.length != 0) {
document.getElementById('filter-results').innerHTML = '';
const frag = new DocumentFragment();
for (const id of window.catchFilter) {
const findPoke = pokemonList.find(p => p.id == id);
const pokeIndex = pokemonList.indexOf(findPoke);
const ballPrefN = window.filterBallPref[pokeIndex].normal;
const ballPrefS = window.filterBallPref[pokeIndex].shiny;
const div = document.createElement('div');
div.innerHTML = `${findPoke.name}
✨
`;
div.setAttribute('data-src', findPoke.id);
if (window.catchFilter.includes(findPoke.id)) {
div.setAttribute('style', 'background-color: yellowgreen;');
}
div.addEventListener('click', (event) => { toggleFilteredPoke(event);loadFilteredList(); });
frag.appendChild(div);
}
document.getElementById('filter-results').appendChild(frag);
setRightClick();
} else {
document.getElementById('filter-results').innerHTML = '
Your filtered list is empty.';
}
}
function filterPokemonRoute(event) {
const elem = event.target;
document.getElementById('filter-results').innerHTML = '';
let routePoke;
try {routePoke = Routes.getRoute(player.region, player.route()).pokemon
const frag = new DocumentFragment();
for (const area in routePoke) {
const routeArea = routePoke[area];
if (routeArea.length > 0) {
const thisArea = routePoke[area];
for (const poke of thisArea) {
const findPoke = pokemonList.find(p => p.name == poke);
const pokeIndex = pokemonList.indexOf(findPoke);
const ballPrefN = window.filterBallPref[pokeIndex].normal;
const ballPrefS = window.filterBallPref[pokeIndex].shiny;
const div = document.createElement('div');
div.innerHTML = `${findPoke.name}
✨
`;
div.setAttribute('data-src', findPoke.id);
if (window.catchFilter.includes(findPoke.id)) {
div.setAttribute('style', 'background-color: yellowgreen;');
}
div.addEventListener('click', (event) => { toggleFilteredPoke(event); });
frag.appendChild(div);
}
document.getElementById('filter-results').appendChild(frag);
setRightClick();
}
}
} catch (err) {
document.getElementById('filter-results').innerHTML = '
You are not on a route.';
};
}
function filterPokemonDungeon(event) {
const elem = event.target;
document.getElementById('filter-results').innerHTML = '';
let validDungeon;
try {validDungeon = DungeonRunner.dungeon;
const dungeonPoke = validDungeon.enemyList;
const dungeonBoss = validDungeon.bossList;
const frag = new DocumentFragment();
for (const enemy of dungeonPoke) {
let pokeStr;
if (typeof enemy == 'string') {
pokeStr = enemy;
} else if (typeof enemy.pokemon == 'string') {
pokeStr = enemy.pokemon;
}
if (typeof pokeStr != 'undefined') {
const findPoke = pokemonList.find(p => p.name == pokeStr);
const pokeIndex = pokemonList.indexOf(findPoke);
const ballPrefN = window.filterBallPref[pokeIndex].normal;
const ballPrefS = window.filterBallPref[pokeIndex].shiny;
const div = document.createElement('div');
div.innerHTML = `${findPoke.name}
✨
`;
div.setAttribute('data-src', findPoke.id);
if (window.catchFilter.includes(findPoke.id)) {
div.setAttribute('style', 'background-color: yellowgreen;');
}
div.addEventListener('click', (event) => { toggleFilteredPoke(event); });
frag.appendChild(div);
}
}
for (const enemy of dungeonBoss) {
let pokeStr;
const construct = enemy.constructor.name;
if (construct == 'DungeonBossPokemon') {
pokeStr = enemy.name;
}
if (typeof pokeStr != 'undefined') {
const findPoke = pokemonList.find(p => p.name == pokeStr);
const pokeIndex = pokemonList.indexOf(findPoke);
const ballPrefN = window.filterBallPref[pokeIndex].normal;
const ballPrefS = window.filterBallPref[pokeIndex].shiny;
const div = document.createElement('div');
div.innerHTML = `${findPoke.name}
✨
`;
div.setAttribute('data-src', findPoke.id);
if (window.catchFilter.includes(findPoke.id)) {
div.setAttribute('style', 'background-color: yellowgreen;');
}
div.addEventListener('click', (event) => { toggleFilteredPoke(event); });
frag.appendChild(div);
}
}
document.getElementById('filter-results').appendChild(frag);
setRightClick();
} catch (err) {
console.log(err)
document.getElementById('filter-results').innerHTML = '
You are not in a dungeon or dungeon info cannot be found.';
};
}
function filterAllPoke() {
window.catchFilter = [];
for (const poke of pokemonList) {
window.catchFilter.push(poke.id);
}
localStorage.setItem('catchFilter', JSON.stringify(window.catchFilter));
filterPokeSearch(true);
}
function unfilterAllPoke() {
window.catchFilter = [];
localStorage.setItem('catchFilter', JSON.stringify(window.catchFilter));
filterPokeSearch(true);
}
function resetBallFilterAll() {
window.filterBallPref = new Array(pokemonList.length).fill({normal: 0, shiny: 0}, 0, pokemonList.length);
localStorage.setItem('filterBallPref', JSON.stringify(window.filterBallPref));
filterPokeSearch(true);
}
function toggleCatchFilter(event) {
const elem = event.target;
if (window.filterState) {
window.filterState = filterColor = false;
} else {
window.filterState = filterColor = true;
}
elem.setAttribute('class', `btn btn-${filterColor ? 'success' : 'danger'}`);
elem.innerText = `Catch Filter ${window.filterState ? "[ON]" : "[OFF]"}`;
localStorage.setItem('filterState', window.filterState);
}
function filterPokeSearch(event) {
document.getElementById('filter-results').innerHTML = '';
let pokeStr;
try { pokeStr = event.target.value.toLowerCase(); } catch (err) { pokeStr = document.getElementById('filter-search').value; };
console.log(pokeStr)
const filterList = pokemonList.filter(p => p.name.toLowerCase().includes(pokeStr));
console.log(filterList)
const frag = new DocumentFragment();
for (const poke of filterList) {
const findPoke = pokemonList.find(p => p.name == poke.name);
const pokeIndex = pokemonList.indexOf(findPoke);
const ballPrefN = window.filterBallPref[pokeIndex].normal;
const ballPrefS = window.filterBallPref[pokeIndex].shiny;
const div = document.createElement('div');
div.innerHTML = `${findPoke.name}
✨
`;
div.setAttribute('data-src', poke.id);
if (window.catchFilter.includes(poke.id)) {
div.setAttribute('style', 'background-color: yellowgreen;');
}
div.addEventListener('click', (event) => { toggleFilteredPoke(event); });
frag.appendChild(div);
}
document.getElementById('filter-results').appendChild(frag);
setRightClick();
}
function toggleFilteredPoke(event) {
const elem = event.target;
const id = +elem.getAttribute('data-src');
if (elem.hasAttribute('ball-pref')) {
const ballPref = +elem.getAttribute('ball-pref');
const prefType = elem.getAttribute('pref-type');
if (window.filterBallPref[ballPref][prefType] < ballNames.length - 1) {
window.filterBallPref[ballPref][prefType]++;
} else {
window.filterBallPref[ballPref][prefType] = 0;
}
elem.src = `assets/images/pokeball/${ballNames[window.filterBallPref[ballPref][prefType]]}.svg`
localStorage.setItem('filterBallPref', JSON.stringify(window.filterBallPref));
return;
}
console.log('still working')
const idExists = window.catchFilter.indexOf(id);
if (idExists == -1) {
window.catchFilter.push(id);
elem.setAttribute('style', 'background-color: yellowgreen;');
} else {
window.catchFilter.splice(idExists, 1);
elem.removeAttribute('style');
}
localStorage.setItem('catchFilter', JSON.stringify(window.catchFilter));
}
function setRightClick() {
const ballElemsN = document.getElementsByClassName('filter-pokeball-n');
const ballElemsS = document.getElementsByClassName('filter-pokeball-s');
for (let i = 0; i < ballElemsN.length; i++) {
ballElemsN[i].addEventListener('contextmenu', (event) => { event.preventDefault();resetBallFilter(event); });
}
for (let ii = 0; ii < ballElemsS.length; ii++) {
ballElemsS[ii].addEventListener('contextmenu', (event) => { event.preventDefault();resetBallFilter(event); });
}
}
function resetBallFilter(event) {
const elem = event.target;
const ballPref = +elem.getAttribute('ball-pref');
const prefType = elem.getAttribute('pref-type');
window.filterBallPref[ballPref][prefType] = 0;
elem.src = `assets/images/pokeball/${ballNames[window.filterBallPref[ballPref][prefType]]}.svg`
localStorage.setItem('filterBallPref', JSON.stringify(window.filterBallPref));
}
function overideDefeatPokemon() {
// Normal Battle
Battle.defeatPokemon = function() {
const enemyPokemon = this.enemyPokemon();
const type1 = enemyPokemon.type1;
const type2 = enemyPokemon.type2;
Battle.route = player.route();
enemyPokemon.defeat();
GameHelper.incrementObservable(App.game.statistics.routeKills[player.region][Battle.route]);
App.game.breeding.progressEggsBattle(Battle.route, player.region);
const findPoke = pokemonList.find(p => p.id == enemyPokemon.id);
const pokeIndex = pokemonList.indexOf(findPoke);
let ballPrefN = window.filterBallPref[pokeIndex].normal -1;
ballPrefN = Math.sign(ballPrefN) == -1 ? 0 : ballPrefN;
let ballPrefS = window.filterBallPref[pokeIndex].shiny - 1;
ballPrefS = Math.sign(ballPrefS) == -1 ? 0 : ballPrefS;
const ballQuantityN = App.game.pokeballs.pokeballs[ballPrefN].quantity();
const ballQuantityS = App.game.pokeballs.pokeballs[ballPrefS].quantity();
const isShiny = enemyPokemon.shiny;
let pokeBall;
if (ballQuantityS > 0 && window.filterState & isShiny) {
pokeBall = ballPrefS;
} else if (ballQuantityN > 0 && window.filterState) {
pokeBall = ballPrefN;
} else {
pokeBall = App.game.pokeballs.calculatePokeballToUse(enemyPokemon.id, isShiny);
}
if (pokeBall !== GameConstants.Pokeball.None && window.filterState && (window.catchFilter.includes(enemyPokemon.id) || (window.filterTypes[type1] || window.filterTypes[type2]))) {
this.prepareCatch(enemyPokemon, pokeBall);
setTimeout(
() => {
this.attemptCatch(enemyPokemon);
if (Battle.route != 0) {
this.generateNewEnemy();
}
},
App.game.pokeballs.calculateCatchTime(pokeBall)
)
;
} else if (pokeBall !== GameConstants.Pokeball.None && !window.filterState) {
this.prepareCatch(enemyPokemon, pokeBall);
setTimeout(
() => {
this.attemptCatch(enemyPokemon);
if (Battle.route != 0) {
this.generateNewEnemy();
}
},
App.game.pokeballs.calculateCatchTime(pokeBall)
)
;
} else {
this.generateNewEnemy();
}
this.gainItem();
player.lowerItemMultipliers(MultiplierDecreaser.Battle);
}
// Dungeon Battle
DungeonBattle.defeatPokemon = function() {
const enemyPokemon = this.enemyPokemon();
const type1 = enemyPokemon.type1;
const type2 = enemyPokemon.type2;
// Handle Trainer Pokemon defeat
if (this.trainer()) {
this.defeatTrainerPokemon();
return;
}
DungeonRunner.fighting(false);
if (DungeonRunner.fightingBoss()) {
DungeonRunner.fightingBoss(false);
DungeonRunner.defeatedBoss(true);
}
enemyPokemon.defeat();
App.game.breeding.progressEggsBattle(DungeonRunner.dungeon.difficultyRoute, player.region);
player.lowerItemMultipliers(MultiplierDecreaser.Battle);
// Clearing Dungeon tile
DungeonRunner.map.currentTile().type(GameConstants.DungeonTile.empty);
DungeonRunner.map.currentTile().calculateCssClass();
// Attempting to catch Pokemon
const findPoke = pokemonList.find(p => p.id == enemyPokemon.id);
const pokeIndex = pokemonList.indexOf(findPoke);
let ballPrefN = window.filterBallPref[pokeIndex].normal -1;
ballPrefN = Math.sign(ballPrefN) == -1 ? 0 : ballPrefN;
let ballPrefS = window.filterBallPref[pokeIndex].shiny - 1;
ballPrefS = Math.sign(ballPrefS) == -1 ? 0 : ballPrefS;
const ballQuantityN = App.game.pokeballs.pokeballs[ballPrefN].quantity();
const ballQuantityS = App.game.pokeballs.pokeballs[ballPrefS].quantity();
const isShiny = enemyPokemon.shiny;
let pokeBall;
if (ballQuantityS > 0 && window.filterState & isShiny) {
pokeBall = ballPrefS;
} else if (ballQuantityN > 0 && window.filterState) {
pokeBall = ballPrefN;
} else {
pokeBall = App.game.pokeballs.calculatePokeballToUse(enemyPokemon.id, isShiny);
}
if (pokeBall !== GameConstants.Pokeball.None && window.filterState && (window.catchFilter.includes(enemyPokemon.id) || (window.filterTypes[type1] || window.filterTypes[type2]))) {
this.prepareCatch(enemyPokemon, pokeBall);
setTimeout(
() => {
this.attemptCatch(enemyPokemon);
if (DungeonRunner.defeatedBoss()) {
DungeonRunner.dungeonWon();
}
},
App.game.pokeballs.calculateCatchTime(pokeBall)
);
} else if (pokeBall !== GameConstants.Pokeball.None && !window.filterState) {
this.prepareCatch(enemyPokemon, pokeBall);
setTimeout(
() => {
this.attemptCatch(enemyPokemon);
if (DungeonRunner.defeatedBoss()) {
DungeonRunner.dungeonWon();
}
},
App.game.pokeballs.calculateCatchTime(pokeBall)
);
} else if (DungeonRunner.defeatedBoss()) {
DungeonRunner.dungeonWon();
}
}
}
if (!localStorage.getItem('filterState')) {
localStorage.setItem('filterState', false);
}
if (!localStorage.getItem('filterTypes')) {
const typeArray = new Array(18).fill(false, 0, 18);
localStorage.setItem('filterTypes', JSON.stringify(typeArray));
}
if (!localStorage.getItem('filterBallPref')) {
const prefArray = new Array(pokemonList.length).fill({normal: 0, shiny: 0}, 0, pokemonList.length);
localStorage.setItem('filterBallPref', JSON.stringify(prefArray));
}
if (!localStorage.getItem('catchFilter')) {
localStorage.setItem('catchFilter', JSON.stringify([]));
}
window.filterState = JSON.parse(localStorage.getItem('filterState'));
window.filterTypes = JSON.parse(localStorage.getItem('filterTypes'));
window.catchFilter = JSON.parse(localStorage.getItem('catchFilter'));
window.filterBallPref = JSON.parse(localStorage.getItem('filterBallPref'));
function loadScript(){
const oldInit = Preload.hideSplashScreen;
Preload.hideSplashScreen = function(){
const result = oldInit.apply(this, arguments);
initCatchFilter();
return result;
}
}
const scriptName = 'catchfilterfantasia'
if (document.getElementById('scriptHandler') != undefined){
const scriptElement = document.createElement('div');
scriptElement.id = scriptName;
document.getElementById('scriptHandler').appendChild(scriptElement);
if (localStorage.getItem(scriptName) != null){
if (localStorage.getItem(scriptName) == 'true'){
loadScript();
}
}
else{
localStorage.setItem(scriptName, 'true')
loadScript();
}
}
else{
loadScript();
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}