Some more functionality for battling, check if choice is valid, implement target resolvers.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
use crate::dynamic_data::choices::TurnChoice;
|
||||
use crate::dynamic_data::event_hooks::event_hook::EventHook;
|
||||
use crate::dynamic_data::flow::choice_queue::ChoiceQueue;
|
||||
use crate::dynamic_data::flow::target_resolver::is_valid_target;
|
||||
use crate::dynamic_data::history::history_holder::HistoryHolder;
|
||||
use crate::dynamic_data::libraries::dynamic_library::DynamicLibrary;
|
||||
use crate::dynamic_data::models::battle_party::BattleParty;
|
||||
use crate::dynamic_data::models::battle_random::BattleRandom;
|
||||
use crate::dynamic_data::models::battle_result::BattleResult;
|
||||
use crate::dynamic_data::models::battle_side::BattleSide;
|
||||
use crate::dynamic_data::models::pokemon::Pokemon;
|
||||
use crate::dynamic_data::script_handling::script::Script;
|
||||
use crate::dynamic_data::script_handling::script_set::ScriptSet;
|
||||
use crate::dynamic_data::script_handling::volatile_scripts::VolatileScripts;
|
||||
@@ -123,6 +126,18 @@ impl<'a> Battle<'a> {
|
||||
&self.current_turn_queue
|
||||
}
|
||||
|
||||
pub fn get_pokemon(&self, side: u8, index: u8) -> &Option<Arc<RwLock<Pokemon<'a>>>> {
|
||||
let side = self.sides.get(side as usize);
|
||||
if side.is_none() {
|
||||
return &None;
|
||||
}
|
||||
let pokemon = side.unwrap().pokemon().get(index as usize);
|
||||
if pokemon.is_none() {
|
||||
return &None;
|
||||
}
|
||||
pokemon.unwrap()
|
||||
}
|
||||
|
||||
pub fn can_slot_be_filled(&self, side: u8, index: u8) -> bool {
|
||||
for party in &self.parties {
|
||||
if party.is_responsible_for_index(side, index) && party.has_pokemon_not_in_field() {
|
||||
@@ -165,6 +180,34 @@ impl<'a> Battle<'a> {
|
||||
}
|
||||
self.has_ended = true;
|
||||
}
|
||||
|
||||
pub fn can_use(&self, choice: &TurnChoice) -> bool {
|
||||
// If the user is not usable, we obviously can;t use the choice.
|
||||
if !choice.user().is_usable() {
|
||||
return false;
|
||||
}
|
||||
if let TurnChoice::Move {
|
||||
used_move,
|
||||
target_side,
|
||||
target_index,
|
||||
user,
|
||||
} = choice
|
||||
{
|
||||
// TODO: Hook to change number of PP needed.
|
||||
if used_move.remaining_pp() < 1 {
|
||||
return false;
|
||||
}
|
||||
if !is_valid_target(
|
||||
*target_side,
|
||||
*target_index,
|
||||
used_move.move_data().target(),
|
||||
user,
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VolatileScripts<'a> for Battle<'a> {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub struct ExecutingMove<'a, 'b> {
|
||||
number_of_hits: u8,
|
||||
hits: Vec<HitData>,
|
||||
user: &'a Pokemon<'b>,
|
||||
chosen_move: &'a LearnedMove,
|
||||
chosen_move: &'a LearnedMove<'a>,
|
||||
use_move: &'a MoveData,
|
||||
script: ScriptContainer,
|
||||
targets: Vec<Option<&'a Pokemon<'b>>>,
|
||||
|
||||
@@ -1,2 +1,40 @@
|
||||
use crate::static_data::MoveData;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LearnedMove {}
|
||||
pub struct LearnedMove<'a> {
|
||||
move_data: &'a MoveData,
|
||||
max_pp: u8,
|
||||
remaining_pp: u8,
|
||||
learn_method: MoveLearnMethod,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum MoveLearnMethod {
|
||||
Unknown = 0,
|
||||
Level = 1,
|
||||
}
|
||||
|
||||
impl<'a> LearnedMove<'a> {
|
||||
pub fn new(move_data: &'a MoveData, learn_method: MoveLearnMethod) -> Self {
|
||||
Self {
|
||||
move_data,
|
||||
max_pp: move_data.base_usages(),
|
||||
remaining_pp: move_data.base_usages(),
|
||||
learn_method,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_data(&self) -> &MoveData {
|
||||
self.move_data
|
||||
}
|
||||
|
||||
pub fn max_pp(&self) -> u8 {
|
||||
self.max_pp
|
||||
}
|
||||
pub fn remaining_pp(&self) -> u8 {
|
||||
self.remaining_pp
|
||||
}
|
||||
pub fn learn_method(&self) -> MoveLearnMethod {
|
||||
self.learn_method
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ pub struct Pokemon<'a> {
|
||||
|
||||
battle_data: Option<PokemonBattleData<'a>>,
|
||||
|
||||
moves: [Option<LearnedMove>; MAX_MOVES],
|
||||
moves: [Option<LearnedMove<'a>>; MAX_MOVES],
|
||||
allowed_experience: bool,
|
||||
|
||||
types: Vec<u8>,
|
||||
|
||||
Reference in New Issue
Block a user