@@ -8,6 +8,7 @@ import type { EnemyPokemon, PlayerPokemon, Pokemon } from "#field/pokemon";
88import { GameManagerHelper } from "#test/helpers/game-manager-helper" ;
99import type { MoveHelper } from "#test/helpers/move-helper" ;
1010import { getEnumStr } from "#test/utils/string-utils" ;
11+ import { sortInSpeedOrder } from "#utils/speed-order" ;
1112import { expect , type MockInstance , vi } from "vitest" ;
1213
1314/** Helper to manage pokemon */
@@ -64,36 +65,27 @@ export class FieldHelper extends GameManagerHelper {
6465
6566 /**
6667 * Helper function to return all on-field {@linkcode Pokemon} in speed order (fastest first).
67- * @param indices - Whether to only return {@linkcode BattlerIndex}es instead of full Pokemon objects
68- * (such as for comparison with other speed order-related mechanisms); default `false`
69- * @returns An array containing all on-field {@linkcode Pokemon} in order of descending Speed. \
70- * Speed ties are returned in increasing order of index.
71- *
72- * @remarks
73- * This does not account for Trick Room as it does not modify the _speed_ of Pokemon on the field,
74- * only their turn order.
68+ * @param indices - (Default `false`) Whether to only return {@linkcode BattlerIndex}es instead of full Pokemon objects
69+ * (such as for comparison with other speed order-related mechanisms)
70+ * @param ignoreOverride - (Default `true`) Whether to ignore preset turn orders and speed-reversing effects (like Trick Room)
71+ * @returns An array containing all on-field `Pokemon` in order of **descending** speed.
7572 */
76- public getSpeedOrder ( indices ?: false ) : Pokemon [ ] ;
77-
73+ public getSpeedOrder ( indices ?: false , ignoreOverride ?: boolean ) : Pokemon [ ] ;
7874 /**
7975 * Helper function to return all on-field {@linkcode Pokemon} in speed order (fastest first).
80- * @param indices - Whether to only return {@linkcode BattlerIndex}es instead of full Pokemon objects
81- * (such as for comparison with other speed order-related mechanisms); default `false`
82- * @returns An array containing the {@linkcode BattlerIndex}es of all on-field {@linkcode Pokemon} on the field in order of descending Speed. \
83- * Speed ties are returned in increasing order of index.
84- *
85- * @remarks
86- * This does not account for Trick Room as it does not modify the _speed_ of Pokemon on the field,
87- * only their turn order.
76+ * @param indices - (Default `false`) Whether to only return {@linkcode BattlerIndex}es instead of full Pokemon objects
77+ * (such as for comparison with other speed order-related mechanisms)
78+ * @param ignoreOverride - (Default `true`) Whether to ignore preset turn orders and speed-reversing effects (like Trick Room)
79+ * @returns An array containing the `BattlerIndex`es of all on-field `Pokemon` in order of **descending** speed.
8880 */
89- public getSpeedOrder ( indices : true ) : BattlerIndex [ ] ;
90- public getSpeedOrder ( indices = false ) : BattlerIndex [ ] | Pokemon [ ] {
91- const ret = this . game . scene
92- . getField ( true )
93- . sort (
94- ( pA , pB ) =>
95- pB . getEffectiveStat ( Stat . SPD ) - pA . getEffectiveStat ( Stat . SPD ) || pA . getBattlerIndex ( ) - pB . getBattlerIndex ( ) ,
96- ) ;
81+ public getSpeedOrder ( indices : true , ignoreOverride ?: boolean ) : BattlerIndex [ ] ;
82+ public getSpeedOrder ( indices = false , ignoreOverride = true ) : BattlerIndex [ ] | Pokemon [ ] {
83+ let ret = this . game . scene . getField ( true ) ;
84+ if ( ignoreOverride ) {
85+ ret . sort ( ( pA , pB ) => pB . getEffectiveStat ( Stat . SPD ) - pA . getEffectiveStat ( Stat . SPD ) ) ;
86+ } else {
87+ ret = sortInSpeedOrder ( ret ) ;
88+ }
9789
9890 return indices ? ret . map ( p => p . getBattlerIndex ( ) ) : ret ;
9991 }
0 commit comments