Skip to content

Commit

Permalink
Merge pull request #236 from WatWowMap/mega-filters
Browse files Browse the repository at this point in the history
Mega Evolution Quest Filters
  • Loading branch information
versx authored Sep 29, 2020
2 parents 2a8fbe3 + b8adea4 commit 38a17b7
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 12 deletions.
39 changes: 34 additions & 5 deletions src/data/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const getPokemon = async (minLat, maxLat, minLon, maxLon, showPVP, showIV, updat
WHERE expire_timestamp >= UNIX_TIMESTAMP() AND lat >= ? AND lat <= ? AND lon >= ? AND lon <= ? AND updated > ? ${onlyVerifiedTimersSQL}`;
const args = [minLat, maxLat, minLon, maxLon, updated];
const results = await db.query(sql, args).catch(err => {
console.error('Failed to execute query:', sql, 'with arguments:', args, '\r\n:Error:', err);
console.error('Failed to execute query:', sql, 'with arguments:', args, '\r\nError:', err);
});
let pokemon = [];
if (results && results.length > 0) {
Expand Down Expand Up @@ -381,6 +381,7 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPokestops = true, showQuests = false, showLures = false, showInvasions = false, questFilterExclude = null, pokestopFilterExclude = null, invasionFilterExclude = null) => {
let excludedTypes = []; //int
let excludedPokemon = []; //int
let excludedEvolutions = [];
let excludedItems = []; //int
let excludedLures = []; //int
let excludedInvasions = [];
Expand All @@ -401,6 +402,9 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
} else if (id < 0) {
excludedTypes.push(-id);
}
} else if (filter.includes('e')) {
const id = parseInt(filter.replace('e', ''));
excludedEvolutions.push(id);
} else if (filter.includes('candy')) {
minimumCandyCount = parseInt(filter.replace('candy', ''));
} else if (filter.includes('stardust')) {
Expand Down Expand Up @@ -434,16 +438,17 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
let args = [minLat, maxLat, minLon, maxLon, updated];
let excludeTypeSQL = '';
let excludePokemonSQL = '';
let excludeEvolutionSQL = '';
let excludeItemSQL = '';
let excludeInvasionSQL = '';
let excludePokestopSQL = '';

if (showQuests) {
if (excludedTypes.length === 0) {
// exclude pokemon/item quests; they will be included in subsequent clauses
excludeTypeSQL = 'OR (quest_reward_type IS NOT NULL AND quest_reward_type NOT IN (2, 7)';
excludeTypeSQL = 'OR (quest_reward_type IS NOT NULL AND quest_reward_type NOT IN (2, 7, 12)';
} else {
let sqlExcludeCreate = 'OR ((quest_reward_type IS NOT NULL AND quest_reward_type NOT IN (2, 7, ';
let sqlExcludeCreate = 'OR ((quest_reward_type IS NOT NULL AND quest_reward_type NOT IN (2, 7, 12, ';
for (let i = 0; i < excludedTypes.length; i++) {
if (i === excludedTypes.length - 1) {
sqlExcludeCreate += '?))';
Expand Down Expand Up @@ -483,6 +488,22 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
excludePokemonSQL = sqlExcludeCreate;
}

if (excludedEvolutions.length === 0) {
excludeEvolutionSQL = 'OR (quest_reward_type IS NOT NULL AND quest_reward_type = 12 AND json_extract(json_extract(quest_rewards, "$[*].info.pokemon_id"), "$[0]") IS NOT NULL)';
} else {
let sqlExcludeCreate = 'OR (quest_reward_type IS NOT NULL AND quest_reward_type = 12 AND json_extract(json_extract(quest_rewards, "$[*].info.pokemon_id"), "$[0]") NOT IN (';
for (let i = 0; i < excludedEvolutions.length; i++) {
if (i === excludedEvolutions.length - 1) {
sqlExcludeCreate += '?))';
} else {
sqlExcludeCreate += '?, ';
}
const id = parseInt(excludedEvolutions[i]);
args.push(id);
}
excludeEvolutionSQL = sqlExcludeCreate;
}

if (excludedItems.length === 0) {
excludeItemSQL = 'OR (quest_reward_type IS NOT NULL AND quest_reward_type = 2 AND quest_item_id IS NOT NULL)';
} else {
Expand Down Expand Up @@ -556,7 +577,7 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
incident_expire_timestamp, grunt_type, sponsor_id
FROM pokestop
WHERE lat >= ? AND lat <= ? AND lon >= ? AND lon <= ? AND updated > ? AND deleted = false AND
(false ${excludeTypeSQL} ${excludePokemonSQL} ${excludeItemSQL} ${excludePokestopSQL} ${excludeInvasionSQL})
(false ${excludeTypeSQL} ${excludePokemonSQL} ${excludeEvolutionSQL} ${excludeItemSQL} ${excludePokestopSQL} ${excludeInvasionSQL})
`;
const results = await db.query(sql, args);
let pokestops = [];
Expand Down Expand Up @@ -1320,9 +1341,17 @@ const getAvailableQuests = async () => {
const itemResults = await db.query(sql);
sql = 'SELECT quest_pokemon_id AS id FROM pokestop WHERE quest_reward_type=7 GROUP BY quest_pokemon_id';
const pokemonResults = await db.query(sql);
sql = `
SELECT
DISTINCT json_extract(json_extract(quest_rewards, "$[*].info.pokemon_id"), "$[0]") AS id
FROM pokestop
WHERE quest_reward_type = 12
`;
const evoResults = await db.query(sql);
return {
pokemon: pokemonResults.map(x => x.id),
items: itemResults.map(x => x.id)
items: itemResults.map(x => x.id),
evolutions: evoResults
};
};

Expand Down
33 changes: 26 additions & 7 deletions src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ const getData = async (perms, filter) => {
if ((showGyms || showRaids || showPokestops || showQuests || showInvasions || showPokemon || showSpawnpoints ||
showCells || showSubmissionTypeCells || showSubmissionPlacementCells || showWeather || showNests || showPortals || showActiveDevices) &&
(minLat === null || maxLat === null || minLon === null || maxLon === null)) {
//res.respondWithError(BadRequest);
return;
}

Expand Down Expand Up @@ -350,8 +349,8 @@ const getData = async (perms, filter) => {
for (let j = 0; j < forms.length; j++) {
const formId = forms[j];
const types = JSON.stringify(pkmn.types);
//const form = pkmn.forms[formId];
let formName = pkmn.forms[formId].name;//i18n.__('form_' + formId);
// Grab form from masterfile for consistent language
let formName = pkmn.forms[formId].name;
if (skipForms.includes(formName.toLowerCase())) {
// Skip Shadow and Purified forms
continue;
Expand Down Expand Up @@ -597,7 +596,7 @@ const getData = async (perms, filter) => {
'filter_quest',
'filter_pokecoin',
'filter_sticker',
'filter_mega_resource',
//'filter_mega_resource',
];
for (let i = 1; i <= itemNames.length; i++) {
questData.push({
Expand All @@ -623,9 +622,9 @@ const getData = async (perms, filter) => {
questData.push({
'id': {
'formatted': utils.zeroPad(itemId, 3),
'sort': itemId + 100
'sort': itemId + 10
},
'name': i18n.__('item_' + itemId) ,
'name': i18n.__('item_' + itemId),
'image': {
type: 'img',
path: `/item/${itemId}.png`
Expand All @@ -636,13 +635,33 @@ const getData = async (perms, filter) => {
});
}

// Mega energy
for (let i = 0; i < rewards.evolutions.length; i++) {
const pokemonId = parseInt(rewards.evolutions[i].id);
//const amount = rewards.mega[i].amount;
questData.push({
'id': {
'formatted': utils.zeroPad(pokemonId, 3),
'sort': pokemonId + 2000
},
'name': i18n.__('poke_' + pokemonId) ,
'image': {
type: 'pokemon',
pokemonId: pokemonId
},
'filter': generateShowHideButtons(pokemonId, 'quest-evolution'),
'size': generateSizeButtons(pokemonId, 'quest-evolution'),
'type': i18n.__('filter_quest_mega_energy')
});
}

// Pokemon
for (let i = 0; i < rewards.pokemon.length; i++) {
const pokeId = rewards.pokemon[i];
questData.push({
'id': {
'formatted': utils.zeroPad(pokeId, 3),
'sort': pokeId + 2000
'sort': pokeId + 5000
},
'name': i18n.__('poke_' + pokeId),
'image': {
Expand Down
66 changes: 66 additions & 0 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ function loadStorage () {
let id = availableQuestRewards.items[i];
defaultQuestFilter['i' + id] = { show: true, size: 'normal' };
}
for (i = 0; i < availableQuestRewards.evolutions.length; i++) {
let id = availableQuestRewards.evolutions[i].id;
defaultQuestFilter['e' + id] = { show: true, size: 'normal' };
}

store('quest_filter', JSON.stringify(defaultQuestFilter));
questFilter = defaultQuestFilter;
Expand Down Expand Up @@ -729,6 +733,12 @@ function loadStorage () {
questFilter['i' + id] = { show: true, size: 'normal' };
}
}
for (i = 0; i < availableQuestRewards.evolutions.length; i++) {
let id = availableQuestRewards.evolutions[i].id;
if (questFilter['e' + id] === undefined) {
questFilter['e' + id] = { show: true, size: 'normal' };
}
}
store('quest_filter', JSON.stringify(questFilter));
}

Expand Down Expand Up @@ -1771,6 +1781,12 @@ function loadData () {
questFilterExclude.push('i' + id);
}
}
for (i = 0; i < availableQuestRewards.evolutions.length; i++) {
let id = availableQuestRewards.evolutions[i].id;
if (questFilter['e' + id].show === false) {
questFilterExclude.push('e' + id);
}
}
}

const raidFilterExclude = [];
Expand Down Expand Up @@ -4443,6 +4459,27 @@ function manageSelectButton (e, isNew) {
shouldShow = questFilterNew['i' + id].size === 'huge';
break;
}
} else if (type === 'quest-evolution') {
switch (info) {
case 'hide':
shouldShow = questFilterNew['e' + id].show === false;
break;
case 'show':
shouldShow = questFilterNew['e' + id].show === true;
break;
case 'small':
shouldShow = questFilterNew['e' + id].size === 'small';
break;
case 'normal':
shouldShow = questFilterNew['e' + id].size === 'normal';
break;
case 'large':
shouldShow = questFilterNew['e' + id].size === 'large';
break;
case 'huge':
shouldShow = questFilterNew['e' + id].size === 'huge';
break;
}
} else if (type === 'quest-pokemon') {
switch (info) {
case 'hide':
Expand Down Expand Up @@ -4921,6 +4958,27 @@ function manageSelectButton (e, isNew) {
questFilterNew['i' + -id].size = 'huge';
break;
}
} else if (type === 'quest-evolution') {
switch (info) {
case 'hide':
questFilterNew['e' + id].show = false;
break;
case 'show':
questFilterNew['e' + id].show = true;
break;
case 'small':
questFilterNew['e' + id].size = 'small';
break;
case 'normal':
questFilterNew['e' + id].size = 'normal';
break;
case 'large':
questFilterNew['e' + id].size = 'large';
break;
case 'huge':
questFilterNew['e' + id].size = 'huge';
break;
}
} else if (type === 'quest-pokemon') {
switch (info) {
case 'hide':
Expand Down Expand Up @@ -7242,6 +7300,10 @@ function registerFilterButtonCallbacks() {
let id = availableQuestRewards.items[i];
defaultQuestFilter['i' + id] = { show: true, size: 'normal' };
}
for (i = 0; i < availableQuestRewards.evolutions.length; i++) {
let id = availableQuestRewards.evolutions[i].id;
defaultQuestFilter['e' + id] = { show: true, size: 'normal' };
}

store('quest_filter', JSON.stringify(defaultQuestFilter));
questFilterNew = defaultQuestFilter;
Expand All @@ -7265,6 +7327,10 @@ function registerFilterButtonCallbacks() {
let id = availableQuestRewards.items[i];
defaultQuestFilter['i' + id] = { show: false, size: questFilterNew['i' + id].size };
}
for (i = 0; i < availableQuestRewards.evolutions.length; i++) {
let id = availableQuestRewards.evolutions[i].id;
defaultQuestFilter['e' + id] = { show: false, size: questFilterNew['e' + id].size };
}

store('quest_filter', JSON.stringify(defaultQuestFilter));
questFilterNew = defaultQuestFilter;
Expand Down
1 change: 1 addition & 0 deletions static/locales/_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"filter_devices": "Devices",
"filter_scanareas": "Scan Areas",
"settings_title": "Settings",
"filter_quest_mega_energy": "Mega Energy",
"filter_raid_timers": "Raid Timers",
"filter_raid_level_1": "Level 1",
"filter_raid_level_2": "Level 2",
Expand Down

0 comments on commit 38a17b7

Please sign in to comment.