Skip to content

Commit 31dd0b7

Browse files
committed
fix: moves targetting yourself like protect do not fail in psychicterrain
whoops
1 parent 6a7bf43 commit 31dd0b7

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/genx/generate_instructions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ fn move_has_no_effect(state: &State, choice: &Choice, attacking_side_ref: &SideR
14531453
};
14541454
} else if state.terrain_is_active(&Terrain::PSYCHICTERRAIN)
14551455
&& defender.is_grounded()
1456+
&& choice.target == MoveTarget::Opponent
14561457
&& choice.priority > 0
14571458
{
14581459
return true;

tests/test_battle_mechanics.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ use poke_engine::instruction::{
2323
ToggleTrickRoomInstruction,
2424
};
2525
use poke_engine::pokemon::PokemonName;
26-
use poke_engine::state::LastUsedMove;
2726
use poke_engine::state::{
28-
pokemon_index_iter, Move, PokemonBoostableStat, PokemonIndex, PokemonMoveIndex,
27+
pokemon_index_iter, LastUsedMove, Move, PokemonBoostableStat, PokemonIndex, PokemonMoveIndex,
2928
PokemonSideCondition, PokemonStatus, PokemonType, SideReference, State, StateWeather,
3029
};
3130

3231
#[cfg(feature = "terastallization")]
3332
use poke_engine::instruction::ToggleTerastallizedInstruction;
3433

35-
#[cfg(not(feature = "terastallization"))]
36-
use poke_engine::state::LastUsedMove;
37-
3834
pub fn generate_instructions_with_state_assertion(
3935
state: &mut State,
4036
side_one_move: &MoveChoice,
@@ -11983,6 +11979,40 @@ fn test_priority_move_on_grounded_pkmn_in_psychicterrain() {
1198311979
assert_eq!(expected_instructions, vec_of_instructions);
1198411980
}
1198511981

11982+
#[test]
11983+
fn test_protect_in_psychicterrain() {
11984+
let mut state = State::default();
11985+
state.terrain.terrain_type = Terrain::PSYCHICTERRAIN;
11986+
state.terrain.turns_remaining = 5;
11987+
11988+
let vec_of_instructions = set_moves_on_pkmn_and_call_generate_instructions(
11989+
&mut state,
11990+
Choices::PROTECT,
11991+
Choices::SPLASH,
11992+
);
11993+
11994+
let expected_instructions = vec![StateInstructions {
11995+
percentage: 100.0,
11996+
instruction_list: vec![
11997+
Instruction::ApplyVolatileStatus(ApplyVolatileStatusInstruction {
11998+
side_ref: SideReference::SideOne,
11999+
volatile_status: PokemonVolatileStatus::PROTECT,
12000+
}),
12001+
Instruction::DecrementTerrainTurnsRemaining,
12002+
Instruction::RemoveVolatileStatus(RemoveVolatileStatusInstruction {
12003+
side_ref: SideReference::SideOne,
12004+
volatile_status: PokemonVolatileStatus::PROTECT,
12005+
}),
12006+
Instruction::ChangeSideCondition(ChangeSideConditionInstruction {
12007+
side_ref: SideReference::SideOne,
12008+
side_condition: PokemonSideCondition::Protect,
12009+
amount: 1,
12010+
}),
12011+
],
12012+
}];
12013+
assert_eq!(expected_instructions, vec_of_instructions);
12014+
}
12015+
1198612016
#[test]
1198712017
fn test_priority_move_on_non_grounded_pkmn_in_psychicterrain() {
1198812018
let mut state = State::default();

0 commit comments

Comments
 (0)