Skip to content

Commit

Permalink
feat: filter by Gigantamax Stationed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Nov 18, 2024
1 parent dcb00ab commit 122f7ad
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 40 deletions.
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@
"enabled": false,
"pokemon": false,
"battleTier": "all",
"battles": false
"battles": false,
"gmaxStationed": false
},
"s2cells": {
"enabled": false,
Expand Down
3 changes: 3 additions & 0 deletions server/src/filters/builder/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ function buildDefaultFilters(perms) {
? defaultFilters.stations.battles
: undefined,
filter: pokemon.stations,
gmaxStationed: perms.dynamax
? defaultFilters.stations.gmaxStationed
: undefined,
}
: undefined,
pokemon:
Expand Down
79 changes: 44 additions & 35 deletions server/src/models/Station.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ class Station extends Model {
static async getAll(perms, args, { isMad }) {
const { areaRestrictions } = perms
const { stationUpdateLimit } = config.getSafe('api')
const { onlyAreas, onlyAllStations, onlyMaxBattles, onlyBattleTier } =
args.filters
const {
onlyAreas,
onlyAllStations,
onlyMaxBattles,
onlyBattleTier,
onlyGmaxStationed,
} = args.filters
const ts = getEpoch()

const select = [
Expand All @@ -34,8 +39,6 @@ class Station extends Model {
'updated',
'start_time',
'end_time',
'total_stationed_pokemon',
'total_stationed_gmax',
]

const query = this.query()
Expand All @@ -49,7 +52,7 @@ class Station extends Model {
)
// .where('is_inactive', false)

if (perms.dynamax && onlyMaxBattles) {
if (perms.dynamax && (onlyMaxBattles || onlyGmaxStationed)) {
select.push(
'is_battle_available',
'battle_level',
Expand All @@ -63,45 +66,51 @@ class Station extends Model {
'battle_pokemon_bread_mode',
'battle_pokemon_move_1',
'battle_pokemon_move_2',
'total_stationed_pokemon',
'total_stationed_gmax',
)

if (!onlyAllStations) {
query.whereNotNull('battle_pokemon_id').andWhere('battle_end', '>', ts)

if (onlyBattleTier === 'all') {
const battleBosses = new Set()
const battleForms = new Set()
const battleLevels = new Set()
query.andWhere((station) => {
station.where((battle) => {
if (onlyBattleTier === 'all') {
const battleBosses = new Set()
const battleForms = new Set()
const battleLevels = new Set()

Object.keys(args.filters).forEach((key) => {
switch (key.charAt(0)) {
case 'o':
break
case 'j':
battleLevels.add(key.slice(1))
break
default:
{
const [id, form] = key.split('-')
if (id) battleBosses.add(id)
if (form) battleForms.add(form)
Object.keys(args.filters).forEach((key) => {
switch (key.charAt(0)) {
case 'o':
break
case 'j':
battleLevels.add(key.slice(1))
break
default:
{
const [id, form] = key.split('-')
if (id) battleBosses.add(id)
if (form) battleForms.add(form)
}
break
}
break
})
if (battleBosses.size) {
battle.andWhere('battle_pokemon_id', 'in', [...battleBosses])
}
if (battleForms.size) {
battle.andWhere('battle_pokemon_form', 'in', [...battleForms])
}
if (battleLevels.size) {
battle.andWhere('battle_level', 'in', [...battleLevels])
}
} else {
battle.andWhere('battle_level', onlyBattleTier)
}
})

if (battleBosses.size) {
query.andWhere('battle_pokemon_id', 'in', [...battleBosses])
}
if (battleForms.size) {
query.andWhere('battle_pokemon_form', 'in', [...battleForms])
}
if (battleLevels.size) {
query.andWhere('battle_level', 'in', [...battleLevels])
}
} else {
query.andWhere('battle_level', onlyBattleTier)
}
if (onlyGmaxStationed) station.orWhere('total_stationed_gmax', '>', 0)
})
}
}

Expand Down
1 change: 1 addition & 0 deletions server/src/ui/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function drawer(req, perms) {
? {
allStations: perms.stations || BLOCKED,
maxBattles: perms.dynamax || BLOCKED,
gmaxStationed: perms.dynamax || BLOCKED,
}
: BLOCKED,
pokemon:
Expand Down
3 changes: 2 additions & 1 deletion src/pages/map/hooks/usePermCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export function usePermCheck(category) {
case 'stations':
if (
(filters?.allStations && perms?.stations) ||
(filters?.maxBattles && perms?.dynamax)
(filters?.maxBattles && perms?.dynamax) ||
(filters?.gmaxStationed && perms?.dynamax)
) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/queries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class Query {
static stations(filters) {
const { perms } = useMemory.getState().auth
let query = 'GET_ALL_STATIONS'
if (filters.maxBattles && perms.dynamax) {
if ((filters.maxBattles || filters.gmaxStationed) && perms.dynamax) {
query += '_BATTLE'
}
return stationIndex[query]
Expand Down
4 changes: 2 additions & 2 deletions src/services/queries/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const core = gql`
updated
start_time
end_time
total_stationed_pokemon
total_stationed_gmax
}
`

Expand All @@ -31,6 +29,8 @@ const battle = gql`
battle_pokemon_bread_mode
battle_pokemon_move_1
battle_pokemon_move_2
total_stationed_pokemon
total_stationed_gmax
}
`

Expand Down

0 comments on commit 122f7ad

Please sign in to comment.