@@ -25,7 +25,7 @@ interface DexOrGroup {
25
25
types : { [ k : string ] : boolean } ;
26
26
resists : { [ k : string ] : boolean } ;
27
27
weak : { [ k : string ] : boolean } ;
28
- stats : { [ k : string ] : { [ k in Direction ] : number | string } } ;
28
+ stats : { [ k : string ] : { [ k in Direction ] : { [ s : string ] : number | boolean } } } ;
29
29
skip : boolean ;
30
30
}
31
31
@@ -1162,38 +1162,48 @@ function runDexsearch(target: string, cmd: string, canAll: boolean, message: str
1162
1162
inequalityString = target . charAt ( inequality ) ;
1163
1163
}
1164
1164
const targetParts = target . replace ( / \s / g, '' ) . split ( inequalityString ) ;
1165
- let compareTo ;
1166
- let stat ;
1165
+ let compareType : string ;
1166
+ let statKey : string ;
1167
+ let value : number | boolean ;
1167
1168
const directions : Direction [ ] = [ ] ;
1168
1169
if ( ! isNaN ( parseFloat ( targetParts [ 0 ] ) ) ) {
1169
1170
// e.g. 100 < spe
1170
- compareTo = parseFloat ( targetParts [ 0 ] ) ;
1171
- stat = targetParts [ 1 ] ;
1171
+ value = parseFloat ( targetParts [ 0 ] ) ;
1172
+ statKey = targetParts [ 1 ] ;
1173
+ compareType = 'numeric' ;
1172
1174
if ( inequalityString . startsWith ( '>' ) ) directions . push ( 'less' ) ;
1173
1175
if ( inequalityString . startsWith ( '<' ) ) directions . push ( 'greater' ) ;
1174
1176
} else if ( ! isNaN ( parseFloat ( targetParts [ 1 ] ) ) ) {
1175
1177
// e.g. spe > 100
1176
- compareTo = parseFloat ( targetParts [ 1 ] ) ;
1177
- stat = targetParts [ 0 ] ;
1178
+ value = parseFloat ( targetParts [ 1 ] ) ;
1179
+ statKey = targetParts [ 0 ] ;
1180
+ compareType = 'numeric' ;
1178
1181
if ( inequalityString . startsWith ( '<' ) ) directions . push ( 'less' ) ;
1179
1182
if ( inequalityString . startsWith ( '>' ) ) directions . push ( 'greater' ) ;
1180
1183
} else {
1181
1184
// e.g. atk = spatk
1182
- compareTo = targetParts [ 0 ] ;
1183
- stat = targetParts [ 1 ] ;
1184
- if ( inequalityString . startsWith ( '>' ) ) directions . push ( 'less' ) ;
1185
- if ( inequalityString . startsWith ( '<' ) ) directions . push ( 'greater' ) ;
1186
-
1187
- if ( compareTo in allStatAliases ) compareTo = allStatAliases [ compareTo ] ;
1188
- if ( ! allStats . includes ( compareTo ) ) return { error : `'${ target } ' did not contain a valid stat.` } ;
1185
+ value = true ;
1186
+ statKey = targetParts [ 0 ] ;
1187
+ compareType = targetParts [ 1 ] ;
1188
+ if ( inequalityString . startsWith ( '<' ) ) directions . push ( 'less' ) ;
1189
+ if ( inequalityString . startsWith ( '>' ) ) directions . push ( 'greater' ) ;
1190
+ if ( statKey in allStatAliases ) statKey = allStatAliases [ statKey ] ;
1191
+ if ( compareType in allStatAliases ) compareType = allStatAliases [ compareType ] ;
1192
+ if ( ! allStats . slice ( 0 , 6 ) . includes ( statKey ) || ! allStats . slice ( 0 , 6 ) . includes ( compareType ) )
1193
+ return { error : `'${ target } ' did not contain a valid stat to compare with another stat.` } ;
1189
1194
}
1190
1195
if ( inequalityString . endsWith ( '=' ) ) directions . push ( 'equal' ) ;
1191
- if ( stat in allStatAliases ) stat = allStatAliases [ stat ] ;
1192
- if ( ! allStats . includes ( stat ) ) return { error : `'${ target } ' did not contain a valid stat.` } ;
1193
- if ( ! orGroup . stats [ stat ] ) orGroup . stats [ stat ] = Object . create ( null ) ;
1196
+ if ( statKey in allStatAliases ) statKey = allStatAliases [ statKey ] ;
1197
+ if ( ! allStats . includes ( statKey ) ) return { error : `'${ target } ' contained an invalid stat.` } ;
1198
+ if ( typeof value === 'number' && value <= 0 ) return { error : `Specify a positive value for numeric comparison.` } ;
1199
+ if ( ! orGroup . stats [ statKey ] ) orGroup . stats [ statKey ] = Object . create ( null ) ;
1200
+ // Prevents numeric searches from being overwritten and prevent duplicate searches of other types.
1194
1201
for ( const direction of directions ) {
1195
- if ( orGroup . stats [ stat ] [ direction ] ) return { error : `Invalid stat range for ${ stat } .` } ;
1196
- orGroup . stats [ stat ] [ direction ] = compareTo ;
1202
+ if ( ! orGroup . stats [ statKey ] [ direction ] )
1203
+ orGroup . stats [ statKey ] [ direction ] = Object . create ( null ) ;
1204
+ else if ( orGroup . stats [ statKey ] [ direction ] [ compareType ] )
1205
+ return { error : `Duplicate stat inequality and type for ${ statKey } .` } ;
1206
+ orGroup . stats [ statKey ] [ direction ] [ compareType ] = value ;
1197
1207
}
1198
1208
continue ;
1199
1209
}
@@ -1402,11 +1412,9 @@ function runDexsearch(target: string, cmd: string, canAll: boolean, message: str
1402
1412
}
1403
1413
if ( matched ) continue ;
1404
1414
1405
- function retrieveStat ( species : Species , stat : string | number ) {
1415
+ function retrieveStat ( species : Species , stat : string ) {
1406
1416
let monStat = 0 ;
1407
- if ( typeof stat === 'number' ) {
1408
- monStat = stat ;
1409
- } else if ( stat === 'bst' ) {
1417
+ if ( stat === 'bst' ) {
1410
1418
monStat = species . bst ;
1411
1419
} else if ( stat === 'weight' ) {
1412
1420
monStat = species . weighthg / 10 ;
@@ -1422,27 +1430,22 @@ function runDexsearch(target: string, cmd: string, canAll: boolean, message: str
1422
1430
1423
1431
for ( const stat in alts . stats ) {
1424
1432
const monStat = retrieveStat ( dex [ mon ] , stat ) ;
1425
- if ( alts . stats [ stat ] . less ) {
1426
- const compareTo = retrieveStat ( dex [ mon ] , alts . stats [ stat ] . less ) ;
1427
- if ( monStat < compareTo ) {
1428
- matched = true ;
1429
- break ;
1430
- }
1431
- }
1432
- if ( alts . stats [ stat ] . greater ) {
1433
- const compareTo = retrieveStat ( dex [ mon ] , alts . stats [ stat ] . greater ) ;
1434
- if ( monStat > compareTo ) {
1435
- matched = true ;
1436
- break ;
1437
- }
1438
- }
1439
- if ( alts . stats [ stat ] . equal ) {
1440
- const compareTo = retrieveStat ( dex [ mon ] , alts . stats [ stat ] . equal ) ;
1441
- if ( monStat === compareTo ) {
1442
- matched = true ;
1443
- break ;
1433
+ for ( const direction in alts . stats [ stat ] ) {
1434
+ for ( const comparisonStat in alts . stats [ stat ] [ direction as Direction ] ) {
1435
+ const checkStat = alts . stats [ stat ] [ direction as Direction ] [ comparisonStat ] ;
1436
+ if ( ! checkStat ) continue ;
1437
+ const compareTo = typeof checkStat === 'number' ?
1438
+ checkStat : retrieveStat ( dex [ mon ] , comparisonStat ) ;
1439
+ if ( ( direction === 'less' && monStat < compareTo ) ||
1440
+ ( direction === 'greater' && monStat > compareTo ) ||
1441
+ ( direction === 'equal' && monStat === compareTo ) ) {
1442
+ matched = true ;
1443
+ break ;
1444
+ }
1444
1445
}
1446
+ if ( matched ) break ;
1445
1447
}
1448
+ if ( matched ) break ;
1446
1449
}
1447
1450
if ( matched ) continue ;
1448
1451
0 commit comments