Basic implementation of evolutions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-07-29 12:57:52 +02:00
parent 3f91f80982
commit d8b8559c2e
25 changed files with 437 additions and 115 deletions

View File

@@ -16,11 +16,12 @@ use pkmn_lib::dynamic_data::Gen7MiscLibrary;
use pkmn_lib::dynamic_data::{DynamicLibrary, DynamicLibraryImpl};
use pkmn_lib::dynamic_data::{Gen7BattleStatCalculator, ScriptResolver};
use pkmn_lib::static_data::{
AbilityImpl, AbilityLibrary, AbilityLibraryImpl, BattleItemCategory, DataLibrary, EffectParameter, Form, FormImpl,
GrowthRateLibrary, GrowthRateLibraryImpl, ItemImpl, ItemLibrary, ItemLibraryImpl, LearnableMoves,
LearnableMovesImpl, LibrarySettingsImpl, LookupGrowthRate, MoveDataImpl, MoveLibrary, MoveLibraryImpl, NatureImpl,
NatureLibrary, NatureLibraryImpl, SecondaryEffect, SecondaryEffectImpl, SpeciesImpl, SpeciesLibrary,
SpeciesLibraryImpl, StaticDataImpl, StaticStatisticSet, Statistic, TimeOfDay, TypeLibrary, TypeLibraryImpl,
AbilityImpl, AbilityLibrary, AbilityLibraryImpl, BattleItemCategory, DataLibrary, EvolutionData, EvolutionMethod,
Form, FormImpl, Gender, GrowthRateLibrary, GrowthRateLibraryImpl, ItemImpl, ItemLibrary, ItemLibraryImpl,
LearnableMoves, LearnableMovesImpl, LibrarySettingsImpl, LookupGrowthRate, MoveDataImpl, MoveLibrary,
MoveLibraryImpl, NatureImpl, NatureLibrary, NatureLibraryImpl, Parameter, SecondaryEffect, SecondaryEffectImpl,
SpeciesImpl, SpeciesLibrary, SpeciesLibraryImpl, StaticDataImpl, StaticStatisticSet, Statistic, TimeOfDay,
TypeLibrary, TypeLibraryImpl,
};
use pkmn_lib::StringKey;
@@ -225,7 +226,7 @@ pub fn load_abilities(path: &String) -> Arc<dyn AbilityLibrary> {
let mut parameters = Vec::new();
if let Some(p) = value.get("parameters") {
for par in p.as_array().unwrap() {
parameters.push(parse_effect_parameter(par));
parameters.push(parse_parameter(par));
}
}
@@ -261,7 +262,7 @@ pub fn load_moves(path: &String, types: &Arc<dyn TypeLibrary>) -> Arc<dyn MoveLi
if let Some(pars) = v.get("parameters") {
let pars = pars.as_array().unwrap();
for par in pars {
parameters.push(parse_effect_parameter(par));
parameters.push(parse_parameter(par));
}
}
@@ -321,7 +322,7 @@ pub fn load_species(
let id = value.get("id").unwrap().as_i64().unwrap();
let gender_rate = value.get("genderRatio").unwrap().as_f64().unwrap();
let growth_rate_name = value.get("growthRate").unwrap().as_str().unwrap().into();
let _base_happiness = value.get("baseHappiness").unwrap().as_i64().unwrap();
let base_happiness = value.get("baseHappiness").unwrap().as_i64().unwrap();
let catch_rate = value.get("catchRate").unwrap().as_i64().unwrap();
let _color = value.get("color").unwrap().as_str().unwrap();
// let egg_groups = value.get("eggGroups").unwrap()
@@ -332,7 +333,11 @@ pub fn load_species(
// .collect();
let _egg_cycle = value.get("eggCycles").unwrap().as_i64().unwrap();
// TODO: tags
// TODO: evolutions
let evolutions = if let Some(evolutions) = value.get("evolutions") {
evolutions.as_array().unwrap().iter().map(parse_evolution).collect()
} else {
Vec::new()
};
let forms = value.get("formes").unwrap().as_object().unwrap();
let default_form_value = forms.get("default").unwrap();
@@ -344,14 +349,108 @@ pub fn load_species(
gender_rate as f32,
&growth_rate_name,
catch_rate as u8,
base_happiness as u8,
default_form,
Default::default(),
evolutions,
);
species_library.add(&name, Arc::new(species));
}
Arc::new(species_library)
}
fn parse_evolution(value: &Value) -> EvolutionData {
let species = StringKey::new(value.get("species").unwrap().as_str().unwrap());
let method = value.get("method").unwrap().as_str().unwrap();
let method = match method {
"level" => {
let level = value.get("data").unwrap().as_i64().unwrap() as LevelInt;
EvolutionMethod::Level { level }
}
"levelfemale" => {
let level = value.get("data").unwrap().as_i64().unwrap() as LevelInt;
EvolutionMethod::LevelGender {
level,
gender: Gender::Female,
}
}
"levelmale" => {
let level = value.get("data").unwrap().as_i64().unwrap() as LevelInt;
EvolutionMethod::LevelGender {
level,
gender: Gender::Male,
}
}
"happiness" => {
let happiness = value.get("data").unwrap().as_i64().unwrap() as u8;
EvolutionMethod::Happiness { happiness }
}
"happinessday" => {
let happiness = value.get("data").unwrap().as_i64().unwrap() as u8;
EvolutionMethod::HappinessDay { happiness }
}
"happinessnight" => {
let happiness = value.get("data").unwrap().as_i64().unwrap() as u8;
EvolutionMethod::HappinessNight { happiness }
}
"item" => {
let item = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::Item { item }
}
"itemmale" => {
let item = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::ItemGender {
item,
gender: Gender::Male,
}
}
"itemfemale" => {
let item = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::ItemGender {
item,
gender: Gender::Female,
}
}
"holditem" => {
let item = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::HoldItem { item }
}
"dayholditem" => {
let item = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::DayHoldItem { item }
}
"nightholditem" => {
let item = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::NightHoldItem { item }
}
"hasmove" => {
let move_name = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::HasMove { move_name }
}
"trade" => EvolutionMethod::Trade,
"tradespecies" => {
let species = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::TradeSpecies { species }
}
"tradeitem" => {
let item = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::TradeItem { item }
}
"location" => {
let location = StringKey::new(value.get("data").unwrap().as_str().unwrap());
EvolutionMethod::Location { location }
}
"custom" => {
let data = value.get("data").unwrap().as_array().unwrap();
let name = StringKey::new(data[0].as_str().unwrap());
let params = data[1..].iter().map(parse_parameter).collect();
EvolutionMethod::Custom { name, params }
}
_ => panic!("Unknown evolution method: {}", method),
};
EvolutionData::new(method, species)
}
#[cfg(not(feature = "wasm"))]
fn load_script_resolver(path: &String) -> Arc<dyn ScriptResolver> {
Arc::new(EmptyScriptResolver::default())
@@ -471,7 +570,7 @@ fn parse_moves(value: &Value, move_library: &Arc<dyn MoveLibrary>) -> Arc<dyn Le
Arc::new(moves)
}
fn parse_effect_parameter(value: &Value) -> Arc<EffectParameter> {
fn parse_parameter(value: &Value) -> Arc<Parameter> {
Arc::new(match value {
Value::Null => {
panic!("Unexpected type")

View File

@@ -8390,8 +8390,16 @@
}
},
"evolutions": [
{ "species": "wormadam", "method": "levelfemale", "data": "20" },
{ "species": "mothim", "method": "levelmale", "data": "20" }
{
"species": "wormadam",
"method": "levelfemale",
"data": 20
},
{
"species": "mothim",
"method": "levelmale",
"data": 20
}
]
},
"butterfree": {
@@ -12710,7 +12718,11 @@
}
},
"evolutions": [
{ "species": "vespiquen", "method": "levelfemale", "data": "21" }
{
"species": "vespiquen",
"method": "levelfemale",
"data": 21
}
]
},
"combusken": {