diff --git a/TODO.md b/TODO.md index 21bb138..b7ee5f8 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ =========== -- If first pokemon is fainted, don't set that one as active by default +- What happens if user saves within battle - Learning new moves on level up - Split out Pokemon Encounter into separate components or handlers - Add support for healing your pokemon at healing place @@ -12,7 +12,7 @@ - Fix these boolean props console errors, add `$` - Give enemy attack when switching pokemon - bug: Can move encounter menu while start menu is open -- Attack sounds +- battle sounds - Encounter frequency seems off - Implement one way walls (and add to route 1) - Change Menu to use new Arrow component diff --git a/src/components/PokemonEncounter.tsx b/src/components/PokemonEncounter.tsx index 1cd9b3a..46359aa 100644 --- a/src/components/PokemonEncounter.tsx +++ b/src/components/PokemonEncounter.tsx @@ -5,6 +5,7 @@ import { PokemonInstance, endEncounter, recoverFromFainting, + resetActivePokemon, selectActivePokemon, selectName, selectPokemon, @@ -525,7 +526,7 @@ const PokemonEncounter = () => { const endEncounter_ = () => { dispatch(endEncounter()); - dispatch(setActivePokemon(0)); + dispatch(resetActivePokemon()); }; useEffect(() => { diff --git a/src/state/gameSlice.ts b/src/state/gameSlice.ts index dc30dea..4b05237 100644 --- a/src/state/gameSlice.ts +++ b/src/state/gameSlice.ts @@ -261,6 +261,16 @@ export const gameSlice = createSlice({ state.map = map; state.pos = pos; }, + resetActivePokemon: (state) => { + let fistIndexWithHp = 0; + for (let i = 0; i < state.pokemon.length; i++) { + if (state.pokemon[i].hp > 0) { + fistIndexWithHp = i; + break; + } + } + state.activePokemonIndex = fistIndexWithHp; + }, }, }); @@ -285,6 +295,7 @@ export const { updatePokemonEncounter, updatePokemon, recoverFromFainting, + resetActivePokemon, } = gameSlice.actions; export const selectPos = (state: RootState) => state.game.pos;