Skip to content

Commit

Permalink
fix: gen4 lifeorb does not do recoil when hitting a substitute
Browse files Browse the repository at this point in the history
  • Loading branch information
pmariglia committed Jan 2, 2025
1 parent 6065bd1 commit fc240f6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use crate::state::{PokemonBoostableStat, State, Terrain};
use crate::state::{PokemonStatus, SideReference};
use std::cmp;

#[cfg(feature = "gen4")]
use crate::state::PokemonVolatileStatus;

define_enum_with_from_str! {
#[repr(u8)]
#[derive(Debug, PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -1106,6 +1109,21 @@ pub fn item_modify_attack_being_used(
Items::LIFEORB => {
if attacking_choice.category != MoveCategory::Status {
attacking_choice.base_power *= 1.3;

#[cfg(feature = "gen4")]
if !defending_side
.volatile_statuses
.contains(&PokemonVolatileStatus::SUBSTITUTE)
&& attacking_side.get_active_immutable().ability != Abilities::MAGICGUARD
{
attacking_choice.add_or_create_secondaries(Secondary {
chance: 100.0,
effect: Effect::Heal(-0.1),
target: MoveTarget::User,
});
}

#[cfg(not(feature = "gen4"))]
if attacking_side.get_active_immutable().ability != Abilities::MAGICGUARD {
attacking_choice.add_or_create_secondaries(Secondary {
chance: 100.0,
Expand Down
51 changes: 51 additions & 0 deletions tests/test_battle_mechanics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11757,6 +11757,57 @@ fn test_scaleshot_only_boosts_once() {
assert_eq!(expected_instructions, vec_of_instructions);
}

#[test]
fn test_lifeorb_hitting_sub() {
let mut state = State::default();
state.side_one.get_active().item = Items::LIFEORB;
state
.side_two
.volatile_statuses
.insert(PokemonVolatileStatus::SUBSTITUTE);
state.side_two.substitute_health = 10;

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

#[cfg(feature = "gen4")]
let expected_instructions = vec![StateInstructions {
percentage: 100.0,
instruction_list: vec![
Instruction::DamageSubstitute(DamageInstruction {
side_ref: SideReference::SideTwo,
damage_amount: 10,
}),
Instruction::RemoveVolatileStatus(RemoveVolatileStatusInstruction {
side_ref: SideReference::SideTwo,
volatile_status: PokemonVolatileStatus::SUBSTITUTE,
}),
],
}];
#[cfg(not(feature = "gen4"))]
let expected_instructions = vec![StateInstructions {
percentage: 100.0,
instruction_list: vec![
Instruction::DamageSubstitute(DamageInstruction {
side_ref: SideReference::SideTwo,
damage_amount: 10,
}),
Instruction::RemoveVolatileStatus(RemoveVolatileStatusInstruction {
side_ref: SideReference::SideTwo,
volatile_status: PokemonVolatileStatus::SUBSTITUTE,
}),
Instruction::Heal(HealInstruction {
side_ref: SideReference::SideOne,
heal_amount: -10,
}),
],
}];
assert_eq!(expected_instructions, vec_of_instructions);
}

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

0 comments on commit fc240f6

Please sign in to comment.