From 54f7603dc26df63d04e1740e79a76bad74db2528 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Tue, 25 May 2021 08:40:52 +0300 Subject: [PATCH] check_ability_knockback: Add strengh check --- src/core/battle/check.rs | 15 +++++++++++---- src/core/battle/tests.rs | 23 ++--------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/core/battle/check.rs b/src/core/battle/check.rs index 9b7612bb..05639941 100644 --- a/src/core/battle/check.rs +++ b/src/core/battle/check.rs @@ -5,7 +5,7 @@ use crate::core::{ self, ability::{self, Ability}, command::{self, Command}, - state, Attacks, Id, Jokers, Moves, State, + state, Attacks, Id, Jokers, Moves, PushStrength, State, Weight, }, map::{self, Distance, PosHex}, }; @@ -24,9 +24,10 @@ pub fn check(state: &State, command: &Command) -> Result<(), Error> { } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Error { NotEnoughMovePoints, + NotEnoughStrength, BadActorId, BadTargetId, BadTargetType, @@ -125,11 +126,17 @@ fn check_command_use_ability(state: &State, command: &command::UseAbility) -> Re } fn check_ability_knockback(state: &State, id: Id, pos: PosHex) -> Result<(), Error> { + let strength = PushStrength(Weight::Normal); let selected_pos = state.parts().pos.get(id).0; check_min_distance(selected_pos, pos, Distance(1))?; check_max_distance(selected_pos, pos, Distance(1))?; - if state::blocker_id_at_opt(state, pos).is_none() { - return Err(Error::NoTarget); + let target_id = match state::agent_id_at_opt(state, pos) { + Some(id) => id, + None => return Err(Error::NoTarget), + }; + let target_weight = state.parts().blocker.get(target_id).weight; + if !strength.can_push(target_weight) { + return Err(Error::NotEnoughStrength); } Ok(()) } diff --git a/src/core/battle/tests.rs b/src/core/battle/tests.rs index b7605a29..c75f43c0 100644 --- a/src/core/battle/tests.rs +++ b/src/core/battle/tests.rs @@ -1509,34 +1509,15 @@ fn knockback_normal_vs_heavy() { .object(P0, "knockbacker", PosHex { q: 0, r: 0 }) .object(P1, "heavy_target", initial_heavy_position); let mut state = debug_state(prototypes, scenario); - exec_and_check( + let knockback_result = try_exec( &mut state, command::UseAbility { id: Id(0), pos: initial_heavy_position, ability: Ability::Knockback, }, - &[Event { - active_event: event::UseAbility { - id: Id(0), - pos: initial_heavy_position, - ability: Ability::Knockback, - } - .into(), - actor_ids: vec![Id(1), Id(0)], - instant_effects: vec![( - Id(1), - vec![effect::Knockback { - from: initial_heavy_position, - to: initial_heavy_position, - strength: PushStrength(Weight::Normal), - } - .into()], - )], - timed_effects: Vec::new(), - scheduled_abilities: Vec::new(), - }], ); + assert_eq!(knockback_result, Err(check::Error::NotEnoughStrength)); assert_eq!(state.parts().pos.get(Id(1)).0, initial_heavy_position); }