Skip to content

Commit

Permalink
fix: StrengthSap fails at -6 attack on defender
Browse files Browse the repository at this point in the history
  • Loading branch information
pmariglia committed Jan 12, 2025
1 parent 5eab0ec commit 5f7d149
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/choice_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,15 @@ pub fn modify_choice(
accuracy: 0,
},
});
let defender_attack =
defending_side.calculate_boosted_stat(PokemonBoostableStat::Attack);
let attacker_maxhp = attacking_side.get_active_immutable().maxhp;
attacker_choice.heal = Some(Heal {
target: MoveTarget::User,
amount: defender_attack as f32 / attacker_maxhp as f32,
});
if defending_side.attack_boost != -6 {
let defender_attack =
defending_side.calculate_boosted_stat(PokemonBoostableStat::Attack);
let attacker_maxhp = attacking_side.get_active_immutable().maxhp;
attacker_choice.heal = Some(Heal {
target: MoveTarget::User,
amount: defender_attack as f32 / attacker_maxhp as f32,
});
}
}
Choices::TERABLAST => {
let active = attacking_side.get_active_immutable();
Expand Down
20 changes: 20 additions & 0 deletions tests/test_battle_mechanics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9132,6 +9132,26 @@ fn test_strengthsap() {
assert_eq!(expected_instructions, vec_of_instructions);
}

#[test]
fn test_strengthsap_fails_at_negative_6_boost_on_opponent() {
let mut state = State::default();
state.side_one.get_active().maxhp = 500;
state.side_one.get_active().hp = 100;
state.side_two.attack_boost = -6;

let vec_of_instructions = set_moves_on_pkmn_and_call_generate_instructions(
&mut state,
Choices::STRENGTHSAP,
Choices::SPLASH,
);

let expected_instructions = vec![StateInstructions {
percentage: 100.0,
instruction_list: vec![],
}];
assert_eq!(expected_instructions, vec_of_instructions);
}

#[test]
fn test_yawn_gets_applied_and_swapped_with_next_turn_volatile() {
let mut state = State::default();
Expand Down

0 comments on commit 5f7d149

Please sign in to comment.