Skip to content

Commit

Permalink
feat: Implement gen3 stuff
Browse files Browse the repository at this point in the history
A bunch of stuff for gen3, like:
- effectspore differences

non gen3 stuff also implemented:
- reversal
- earlier gen grass not being immune to powder moves
- solarbeam halves damage in weather that isnt sun
- older gens binding moves are 1/16 hp per turn instead of 1/8
- petaya/liechi/salac berries
- berries activate at 1/4 instead of 1/2 unless gluttony
  • Loading branch information
pmariglia committed Nov 19, 2024
1 parent 9ed3888 commit 68eed49
Show file tree
Hide file tree
Showing 11 changed files with 790 additions and 256 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lazy_static = "1.4.0"

[features]
remove_low_chance_instructions = []
gen3 = []
gen4 = []
gen5 = []
gen6 = []
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ fmt:
cargo fmt
ruff format poke-engine-py

gen3:
cargo build --release --features gen3 --no-default-features

gen4:
cargo build --release --features gen4 --no-default-features

Expand Down Expand Up @@ -46,6 +49,7 @@ test: pytest
cargo test --no-default-features --features "gen6"
cargo test --no-default-features --features "gen5"
cargo test --no-default-features --features "gen4"
cargo test --no-default-features --features "gen3"

install_ci:
pip install -r poke-engine-py/requirements.txt
Expand All @@ -64,5 +68,6 @@ test_ci:
cargo test --no-default-features --features "gen6"
cargo test --no-default-features --features "gen5"
cargo test --no-default-features --features "gen4"
cargo test --no-default-features --features "gen3"

ci: install_ci fmt_ci test_ci
36 changes: 35 additions & 1 deletion src/abilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,12 @@ pub fn ability_after_damage_hit(
}
Abilities::ROUGHSKIN | Abilities::IRONBARBS => {
if damage_dealt > 0 && choice.flags.contact {
#[cfg(feature = "gen3")]
let damage_dealt = cmp::min(attacking_pkmn.maxhp / 16, attacking_pkmn.hp);

#[cfg(not(feature = "gen3"))]
let damage_dealt = cmp::min(attacking_pkmn.maxhp / 8, attacking_pkmn.hp);

instructions
.instruction_list
.push(Instruction::Damage(DamageInstruction {
Expand Down Expand Up @@ -2058,6 +2063,28 @@ pub fn ability_modify_attack_against(
attacker_choice.base_power /= 1.5;
}
}
#[cfg(feature = "gen3")]
Abilities::EFFECTSPORE => {
if attacker_choice.flags.contact {
attacker_choice.add_or_create_secondaries(Secondary {
chance: 3.30,
target: MoveTarget::User,
effect: Effect::Status(PokemonStatus::Poison),
});
attacker_choice.add_or_create_secondaries(Secondary {
chance: 3.30,
target: MoveTarget::User,
effect: Effect::Status(PokemonStatus::Paralyze),
});
attacker_choice.add_or_create_secondaries(Secondary {
chance: 3.30,
target: MoveTarget::User,
effect: Effect::Status(PokemonStatus::Sleep),
});
}
}

#[cfg(not(feature = "gen3"))]
Abilities::EFFECTSPORE => {
if attacker_choice.flags.contact {
attacker_choice.add_or_create_secondaries(Secondary {
Expand Down Expand Up @@ -2394,7 +2421,14 @@ pub fn ability_modify_attack_against(
}
}
Abilities::VOLTABSORB => {
if attacker_choice.move_type == PokemonType::Electric {
#[cfg(feature = "gen3")]
let activate = attacker_choice.move_type == PokemonType::Electric
&& attacker_choice.category != MoveCategory::Status;

#[cfg(not(feature = "gen3"))]
let activate = attacker_choice.move_type == PokemonType::Electric;

if activate {
attacker_choice.remove_all_effects();
attacker_choice.accuracy = 100.0;
attacker_choice.base_power = 0.0;
Expand Down
25 changes: 23 additions & 2 deletions src/choice_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ pub fn modify_choice(
) {
let (attacking_side, defending_side) = state.get_both_sides_immutable(attacking_side_ref);
match attacker_choice.move_id {
Choices::REVERSAL => {
let attacker = attacking_side.get_active_immutable();
let hp_ratio = attacker.hp as f32 / attacker.maxhp as f32;
if hp_ratio >= 0.688 {
attacker_choice.base_power = 20.0;
} else if hp_ratio >= 0.354 {
attacker_choice.base_power = 40.0;
} else if hp_ratio >= 0.208 {
attacker_choice.base_power = 80.0;
} else if hp_ratio >= 0.104 {
attacker_choice.base_power = 100.0;
} else if hp_ratio >= 0.042 {
attacker_choice.base_power = 150.0;
} else {
attacker_choice.base_power = 200.0;
}
}
Choices::AURAWHEEL => {
if attacking_side.get_active_immutable().id == PokemonName::MORPEKOHANGRY {
attacker_choice.move_type = PokemonType::Dark;
Expand Down Expand Up @@ -172,7 +189,7 @@ pub fn modify_choice(
attacker_choice.base_power *= 1.5;
}
}
#[cfg(any(feature = "gen4"))]
#[cfg(any(feature = "gen3", feature = "gen4"))]
Choices::EXPLOSION | Choices::SELFDESTRUCT => {
attacker_choice.base_power *= 2.0;
}
Expand Down Expand Up @@ -326,6 +343,10 @@ pub fn modify_choice(
if state.weather_is_active(&Weather::Sun) || state.weather_is_active(&Weather::HarshSun)
{
attacker_choice.flags.charge = false;
} else if !state.weather_is_active(&Weather::Sun)
&& state.weather.weather_type != Weather::None
{
attacker_choice.base_power /= 2.0;
}
}
Choices::BLIZZARD => {
Expand Down Expand Up @@ -400,7 +421,7 @@ pub fn modify_choice(
}
}

#[cfg(any(feature = "gen4"))]
#[cfg(any(feature = "gen3", feature = "gen4"))]
Choices::PAYBACK => {
if !attacker_choice.first_move {
attacker_choice.base_power *= 2.0;
Expand Down
Loading

0 comments on commit 68eed49

Please sign in to comment.