Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for total_stationed_gmax #1074

Merged
merged 7 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@
"stations_filters": "Power Spots Filter Settings",
"stations_options": "Power Spot Options",
"all_stations": "All Power Spots",
"gmax_stationed": "Gigantamax Placed",
"search_battles": "Search Max Battles",
"started": "Started",
"ended": "Ended",
Expand Down
1 change: 1 addition & 0 deletions packages/types/lib/scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export interface Station<Parsed extends boolean = false> {
battle_pokemon_move_2: number

total_stationed_pokemon: number
total_stationed_gmax: number
stationed_pokemon: Parsed extends true
? StationPokemon[]
: string | StationPokemon[]
Expand Down
1 change: 1 addition & 0 deletions packages/types/lib/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface DbContext {
hasShowcaseData: boolean
hasShowcaseForm: boolean
hasShowcaseType: boolean
hasStationedGmax: boolean
}

export interface ExpressUser extends User {
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
1 change: 1 addition & 0 deletions server/src/graphql/typeDefs/scanner.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ type Station {
end_time: Int
cooldown_complete: Int
total_stationed_pokemon: Int
total_stationed_gmax: Int
is_battle_available: Boolean
is_inactive: Boolean
battle_level: Int
Expand Down
132 changes: 80 additions & 52 deletions server/src/models/Station.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ class Station extends Model {
* @param {import("@rm/types").DbContext} ctx
* @returns {Promise<import("@rm/types").FullStation[]>}
*/
static async getAll(perms, args, { isMad }) {
static async getAll(perms, args, { isMad, hasStationedGmax }) {
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,7 +39,6 @@ class Station extends Model {
'updated',
'start_time',
'end_time',
'total_stationed_pokemon',
]

const query = this.query()
Expand All @@ -48,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 @@ -62,48 +66,55 @@ class Station extends Model {
'battle_pokemon_bread_mode',
'battle_pokemon_move_1',
'battle_pokemon_move_2',
'total_stationed_pokemon',
)
select.push(
hasStationedGmax ? 'total_stationed_gmax' : 'stationed_pokemon',
)

if (!onlyAllStations) {
query
.whereNotNull('battle_pokemon_id')
.andWhere('is_battle_available', true)
.andWhere('battle_end', '>', ts)
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) => {
if (hasStationedGmax || !onlyGmaxStationed)
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
}
})
if (battleBosses.size) {
battle.andWhere('battle_pokemon_id', 'in', [...battleBosses])
}
break
}
})

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 (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 (hasStationedGmax && onlyGmaxStationed)
station.orWhere('total_stationed_gmax', '>', 0)
})
}
}

Expand All @@ -114,26 +125,43 @@ class Station extends Model {
const results = await query.select(select)

return results
.filter(
(station) =>
onlyAllStations ||
!perms.dynamax ||
args.filters[`j${station.battle_level}`] ||
args.filters[
`${station.battle_pokemon_id}-${station.battle_pokemon_form}`
] ||
onlyBattleTier === 'all' ||
onlyBattleTier === station.battle_level,
)
.map((station) => {
if (station.is_battle_available && station.battle_pokemon_id === null) {
station.is_battle_available = false
}
if (station.total_stationed_pokemon === null) {
station.total_stationed_pokemon = 0
}
if (
station.stationed_pokemon &&
(station.total_stationed_gmax === undefined ||
station.total_stationed_gmax === null)
) {
const list =
typeof station.stationed_pokemon === 'string'
? JSON.parse(station.stationed_pokemon)
: station.stationed_pokemon || []
let count = 0
if (list)
for (let i = 0; i < list.length; ++i)
if (list[i].bread_mode === 2 || list[i].bread_mode === 3) ++count
station.total_stationed_gmax = count
}
return station
})
.filter(
(station) =>
onlyAllStations ||
(perms.dynamax &&
((onlyMaxBattles &&
(args.filters[`j${station.battle_level}`] ||
args.filters[
`${station.battle_pokemon_id}-${station.battle_pokemon_form}`
] ||
onlyBattleTier === 'all' ||
onlyBattleTier === station.battle_level)) ||
(onlyGmaxStationed && station.total_stationed_gmax))),
)
}

/**
Expand Down
3 changes: 3 additions & 0 deletions server/src/services/DbManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class DbManager extends Logger {
'showcase_pokemon_form_id' in columns,
'showcase_pokemon_type_id' in columns,
])
const hasStationedGmax =
'total_stationed_gmax' in (await schema('station').columnInfo())
const [hasLayerColumn] = isMad
? await schema('trs_quest')
.columnInfo()
Expand Down Expand Up @@ -200,6 +202,7 @@ class DbManager extends Logger {
hasShowcaseData,
hasShowcaseForm,
hasShowcaseType,
hasStationedGmax,
}
}

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
11 changes: 7 additions & 4 deletions src/features/station/StationPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export function StationPopup(station) {
<StationRating {...station} />
)}
<StationMedia {...station} />
{!!station.is_battle_available &&
station.battle_start < Date.now() / 1000 &&
{station.battle_start < Date.now() / 1000 &&
station.battle_end > Date.now() / 1000 && (
<ExpandCollapse>
<StationAttackBonus {...station} />
Expand Down Expand Up @@ -348,7 +347,7 @@ function StationMedia({
}

/** @param {import('@rm/types').Station} station */
function StationAttackBonus({ total_stationed_pokemon }) {
function StationAttackBonus({ total_stationed_pokemon, total_stationed_gmax }) {
const { t } = useTranslation()
return (
<Stack alignItems="center">
Expand All @@ -360,7 +359,11 @@ function StationAttackBonus({ total_stationed_pokemon }) {
max={4}
/>
<Typography variant="caption">
{t('battle_bonus')} &nbsp;({total_stationed_pokemon} / 40)
{t('battle_bonus')} &nbsp;(
{total_stationed_gmax === undefined || total_stationed_gmax === null
? ''
: `${total_stationed_gmax} / `}
{total_stationed_pokemon} / 40)
</Typography>
</Stack>
)
Expand Down
7 changes: 3 additions & 4 deletions src/features/station/useStationMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function useStationMarker({
battle_pokemon_form,
battle_pokemon_gender,
battle_pokemon_id,
is_battle_available,
battle_pokemon_bread_mode,
start_time,
end_time,
Expand Down Expand Up @@ -49,12 +48,12 @@ export function useStationMarker({
}, basicEqualFn)
const [stationMod, battleMod] = Icons.getModifiers('station', 'dynamax')
const opacity = useOpacity('stations')(end_time)
const isActive = start_time < Date.now() / 1000
const isActive = !!battle_pokemon_id && start_time < Date.now() / 1000

return divIcon({
popupAnchor: [
0 + stationMod.popupX + stationMod.offsetX,
(-baseSize - (is_battle_available && isActive ? battleSize : 0)) * 0.67 +
(-baseSize - (isActive ? battleSize : 0)) * 0.67 +
stationMod.popupY +
stationMod.offsetY +
(-5 + battleMod.offsetY + battleMod.popupY),
Expand All @@ -75,7 +74,7 @@ export function useStationMarker({
"
/>
${
is_battle_available && isActive
isActive
? /* html */ `
<img
src="${battleIcon}"
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
3 changes: 2 additions & 1 deletion src/services/queries/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const core = gql`
updated
start_time
end_time
total_stationed_pokemon
}
`

Expand All @@ -30,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
Loading