First chunk of battling is now fully working, along with integration tests! 🎉
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -6,23 +6,22 @@ use crate::static_data::StatisticSet;
|
||||
use crate::Random;
|
||||
use crate::StringKey;
|
||||
use hashbrown::HashSet;
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Form<'a> {
|
||||
pub struct Form {
|
||||
name: StringKey,
|
||||
height: f32,
|
||||
weight: f32,
|
||||
base_experience: u32,
|
||||
types: Vec<u8>,
|
||||
base_stats: StatisticSet<u16>,
|
||||
abilities: Vec<&'a Ability>,
|
||||
hidden_abilities: Vec<&'a Ability>,
|
||||
moves: LearnableMoves<'a>,
|
||||
abilities: Vec<StringKey>,
|
||||
hidden_abilities: Vec<StringKey>,
|
||||
moves: LearnableMoves,
|
||||
flags: HashSet<StringKey>,
|
||||
}
|
||||
|
||||
impl<'a> Form<'a> {
|
||||
impl Form {
|
||||
pub fn new(
|
||||
name: &StringKey,
|
||||
height: f32,
|
||||
@@ -30,11 +29,11 @@ impl<'a> Form<'a> {
|
||||
base_experience: u32,
|
||||
types: Vec<u8>,
|
||||
base_stats: StatisticSet<u16>,
|
||||
abilities: Vec<&'a Ability>,
|
||||
hidden_abilities: Vec<&'a Ability>,
|
||||
moves: LearnableMoves<'a>,
|
||||
abilities: Vec<StringKey>,
|
||||
hidden_abilities: Vec<StringKey>,
|
||||
moves: LearnableMoves,
|
||||
flags: HashSet<StringKey>,
|
||||
) -> Form<'a> {
|
||||
) -> Form {
|
||||
Form {
|
||||
name: name.clone(),
|
||||
height,
|
||||
@@ -67,13 +66,13 @@ impl<'a> Form<'a> {
|
||||
pub fn base_stats(&self) -> StatisticSet<u16> {
|
||||
self.base_stats
|
||||
}
|
||||
pub fn abilities(&self) -> &Vec<&'a Ability> {
|
||||
pub fn abilities(&self) -> &Vec<StringKey> {
|
||||
&self.abilities
|
||||
}
|
||||
pub fn hidden_abilities(&self) -> &Vec<&'a Ability> {
|
||||
pub fn hidden_abilities(&self) -> &Vec<StringKey> {
|
||||
&self.hidden_abilities
|
||||
}
|
||||
pub fn moves(&self) -> &LearnableMoves<'a> {
|
||||
pub fn moves(&self) -> &LearnableMoves {
|
||||
&self.moves
|
||||
}
|
||||
pub fn flags(&self) -> &HashSet<StringKey> {
|
||||
@@ -90,7 +89,7 @@ impl<'a> Form<'a> {
|
||||
|
||||
pub fn find_ability_index(&self, ability: &Ability) -> Option<AbilityIndex> {
|
||||
for (index, a) in self.abilities.iter().enumerate() {
|
||||
if std::ptr::eq(a.deref(), ability as *const Ability) {
|
||||
if a == ability.name() {
|
||||
return Some(AbilityIndex {
|
||||
hidden: false,
|
||||
index: index as u8,
|
||||
@@ -98,7 +97,7 @@ impl<'a> Form<'a> {
|
||||
}
|
||||
}
|
||||
for (index, a) in self.hidden_abilities.iter().enumerate() {
|
||||
if std::ptr::eq(a.deref(), ability as *const Ability) {
|
||||
if a == ability.name() {
|
||||
return Some(AbilityIndex {
|
||||
hidden: true,
|
||||
index: index as u8,
|
||||
@@ -108,19 +107,19 @@ impl<'a> Form<'a> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_ability(&self, index: AbilityIndex) -> &Ability {
|
||||
pub fn get_ability(&self, index: AbilityIndex) -> &StringKey {
|
||||
if index.hidden {
|
||||
self.hidden_abilities[index.index as usize]
|
||||
&self.hidden_abilities[index.index as usize]
|
||||
} else {
|
||||
self.abilities[index.index as usize]
|
||||
&self.abilities[index.index as usize]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_random_ability(&self, rand: &mut Random) -> &Ability {
|
||||
self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize]
|
||||
pub fn get_random_ability(&self, rand: &mut Random) -> &StringKey {
|
||||
&self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize]
|
||||
}
|
||||
pub fn get_random_hidden_ability(&self, rand: &mut Random) -> &Ability {
|
||||
self.hidden_abilities[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize]
|
||||
pub fn get_random_hidden_ability(&self, rand: &mut Random) -> &StringKey {
|
||||
&self.hidden_abilities[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize]
|
||||
}
|
||||
|
||||
pub fn has_flag(&self, key: &StringKey) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user