diff --git a/src/db/bestiary_proxy.rs b/src/db/bestiary_proxy.rs index 665ca11..334302c 100644 --- a/src/db/bestiary_proxy.rs +++ b/src/db/bestiary_proxy.rs @@ -9,6 +9,7 @@ use crate::models::creature::creature_metadata::alignment_enum::AlignmentEnum; use crate::models::creature::creature_metadata::creature_role::CreatureRoleEnum; use crate::models::creature::creature_metadata::type_enum::CreatureTypeEnum; use crate::models::creature::creature_metadata::variant_enum::CreatureVariant; +use crate::models::pf_version_enum::PathfinderVersionEnum; use crate::models::response_data::OptionalData; use crate::models::routers_validator_structs::{CreatureFieldFilters, PaginatedRequest}; use crate::AppState; @@ -72,10 +73,9 @@ pub async fn get_creatures_passing_all_filters( fetch_elite: bool, ) -> Result> { let mut creature_vec = Vec::new(); - let empty_set = HashSet::new(); let level_vec = key_value_filters .get(&CreatureFilter::Level) - .unwrap_or(&empty_set) + .unwrap_or(&HashSet::new()) .clone(); let modified_filters = prepare_filters_for_db_communication(key_value_filters, fetch_weak, fetch_elite); @@ -123,6 +123,9 @@ pub async fn get_all_possible_values_of_filter( CreatureFilter::Level => runtime_fields_values.list_of_levels, CreatureFilter::CreatureTypes => CreatureTypeEnum::iter().map(|x| x.to_string()).collect(), CreatureFilter::CreatureRoles => CreatureRoleEnum::iter().map(|x| x.to_string()).collect(), + CreatureFilter::PathfinderVersion => PathfinderVersionEnum::iter() + .map(|x| x.to_string()) + .collect(), }; x.sort(); x diff --git a/src/db/data_providers/raw_query_builder.rs b/src/db/data_providers/raw_query_builder.rs index 5c0b91c..357eb12 100644 --- a/src/db/data_providers/raw_query_builder.rs +++ b/src/db/data_providers/raw_query_builder.rs @@ -11,6 +11,7 @@ pub fn prepare_filtered_get_creatures_core( for (key, value) in key_value_filters { match key { CreatureFilter::Level + | CreatureFilter::PathfinderVersion | CreatureFilter::Melee | CreatureFilter::Ranged | CreatureFilter::SpellCaster => { diff --git a/src/models/creature/creature_component/filter_struct.rs b/src/models/creature/creature_component/filter_struct.rs index ff50125..20c0a90 100644 --- a/src/models/creature/creature_component/filter_struct.rs +++ b/src/models/creature/creature_component/filter_struct.rs @@ -3,6 +3,7 @@ use crate::models::creature::creature_metadata::creature_role::CreatureRoleEnum; use crate::models::creature::creature_metadata::rarity_enum::RarityEnum; use crate::models::creature::creature_metadata::size_enum::SizeEnum; use crate::models::creature::creature_metadata::type_enum::CreatureTypeEnum; +use crate::models::pf_version_enum::PathfinderVersionEnum; use std::collections::HashSet; pub struct FilterStruct { @@ -14,4 +15,5 @@ pub struct FilterStruct { pub creature_types: Option>, pub creature_roles: Option>, pub lvl_combinations: HashSet, + pub pathfinder_version: PathfinderVersionEnum, } diff --git a/src/models/creature/creature_filter_enum.rs b/src/models/creature/creature_filter_enum.rs index 0d3de27..36ca0a9 100644 --- a/src/models/creature/creature_filter_enum.rs +++ b/src/models/creature/creature_filter_enum.rs @@ -27,6 +27,7 @@ pub enum CreatureFilter { CreatureTypes, #[serde(alias = "creature_roles", alias = "CREATURE_ROLE")] CreatureRoles, + PathfinderVersion, } impl fmt::Display for CreatureFilter { @@ -57,7 +58,7 @@ impl fmt::Display for CreatureFilter { write!(f, "traits") } CreatureFilter::CreatureTypes => { - write!(f, "creature_types") + write!(f, "cr_type") } CreatureFilter::CreatureRoles => { write!(f, "creature_roles") @@ -65,6 +66,9 @@ impl fmt::Display for CreatureFilter { CreatureFilter::Alignment => { write!(f, "alignment") } + CreatureFilter::PathfinderVersion => { + write!(f, "remaster") + } CreatureFilter::Sources => { write!(f, "sources") } diff --git a/src/models/creature/creature_struct.rs b/src/models/creature/creature_struct.rs index 146d4b7..7f031f3 100644 --- a/src/models/creature/creature_struct.rs +++ b/src/models/creature/creature_struct.rs @@ -5,6 +5,7 @@ use crate::models::creature::creature_component::creature_spell_caster::Creature use crate::models::creature::creature_component::creature_variant::CreatureVariantData; use crate::models::creature::creature_metadata::creature_role::CreatureRoleEnum; use crate::models::creature::creature_metadata::variant_enum::CreatureVariant; +use crate::models::pf_version_enum::PathfinderVersionEnum; use crate::models::routers_validator_structs::CreatureFieldFilters; use serde::{Deserialize, Serialize}; @@ -133,7 +134,11 @@ impl Creature { self.core_data.derived.spell_caster_percentage >= t } } - }) + }) && match filters.pathfinder_version.clone().unwrap_or_default() { + PathfinderVersionEnum::Legacy => !self.core_data.essential.remaster, + PathfinderVersionEnum::Remaster => self.core_data.essential.remaster, + PathfinderVersionEnum::Any => true, + } } fn check_creature_pass_string_filters(&self, filters: &CreatureFieldFilters) -> bool { diff --git a/src/models/encounter_structs.rs b/src/models/encounter_structs.rs index dcf97c4..9a9e20d 100644 --- a/src/models/encounter_structs.rs +++ b/src/models/encounter_structs.rs @@ -3,6 +3,7 @@ use crate::models::creature::creature_metadata::creature_role::CreatureRoleEnum; use crate::models::creature::creature_metadata::rarity_enum::RarityEnum; use crate::models::creature::creature_metadata::size_enum::SizeEnum; use crate::models::creature::creature_metadata::type_enum::CreatureTypeEnum; +use crate::models::pf_version_enum::PathfinderVersionEnum; use rand::distributions::{Distribution, Standard}; use rand::Rng; use serde::{Deserialize, Serialize}; @@ -36,6 +37,7 @@ pub struct RandomEncounterData { pub allow_elite_variants: Option, pub allow_weak_variants: Option, pub is_pwl_on: bool, + pub pathfinder_version: Option, } #[derive( diff --git a/src/models/mod.rs b/src/models/mod.rs index 64cb4dd..df22a30 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -2,6 +2,7 @@ pub mod creature; pub mod db; pub mod encounter_structs; pub mod item; +pub mod pf_version_enum; pub mod response_data; pub mod routers_validator_structs; pub mod scales_struct; diff --git a/src/models/pf_version_enum.rs b/src/models/pf_version_enum.rs new file mode 100644 index 0000000..e1b2ea9 --- /dev/null +++ b/src/models/pf_version_enum.rs @@ -0,0 +1,13 @@ +use serde::{Deserialize, Serialize}; +use strum::{Display, EnumIter}; +use utoipa::ToSchema; + +#[derive( + Serialize, Deserialize, Eq, PartialEq, Hash, Default, ToSchema, Clone, EnumIter, Display, +)] +pub enum PathfinderVersionEnum { + Legacy, + Remaster, + #[default] + Any, +} diff --git a/src/models/routers_validator_structs.rs b/src/models/routers_validator_structs.rs index 0faeb68..40bd7fd 100644 --- a/src/models/routers_validator_structs.rs +++ b/src/models/routers_validator_structs.rs @@ -4,6 +4,7 @@ use crate::models::creature::creature_metadata::rarity_enum::RarityEnum; use crate::models::creature::creature_metadata::size_enum::SizeEnum; use crate::models::creature::creature_metadata::type_enum::CreatureTypeEnum; use crate::models::item::item_metadata::type_enum::ItemTypeEnum; +use crate::models::pf_version_enum::PathfinderVersionEnum; use serde::{Deserialize, Serialize}; use utoipa::IntoParams; use validator::Validate; @@ -30,6 +31,7 @@ pub struct CreatureFieldFilters { pub is_melee_filter: Option, pub is_ranged_filter: Option, pub is_spell_caster_filter: Option, + pub pathfinder_version: Option, } #[derive(Serialize, Deserialize, IntoParams, Validate)] @@ -65,6 +67,7 @@ pub struct ItemFieldFilters { pub type_filter: Option, pub rarity_filter: Option, pub size_filter: Option, + pub pathfinder_version: Option, } #[derive(Serialize, Deserialize, IntoParams, Validate, Eq, PartialEq, Hash)] diff --git a/src/routes/bestiary.rs b/src/routes/bestiary.rs index 7f22c0f..246cbce 100644 --- a/src/routes/bestiary.rs +++ b/src/routes/bestiary.rs @@ -16,6 +16,7 @@ use crate::models::creature::creature_component::creature_extra::AbilityScores; use crate::models::creature::creature_component::creature_extra::CreatureExtraData; use crate::models::creature::creature_component::creature_spell_caster::CreatureSpellCasterData; use crate::models::creature::creature_component::creature_variant::CreatureVariantData; +use crate::models::pf_version_enum::PathfinderVersionEnum; use crate::models::creature::items::action::Action; use crate::models::creature::items::skill::Skill; @@ -88,7 +89,8 @@ pub fn init_docs(doc: &mut utoipa::openapi::OpenApi) { Action, Skill, CreatureRoleEnum, - SpellCasterEntry + SpellCasterEntry, + PathfinderVersionEnum )) )] struct ApiDoc; diff --git a/src/services/encounter_service.rs b/src/services/encounter_service.rs index ac88755..3a252ed 100644 --- a/src/services/encounter_service.rs +++ b/src/services/encounter_service.rs @@ -5,6 +5,7 @@ use crate::models::creature::creature_struct::Creature; use crate::models::encounter_structs::{ EncounterChallengeEnum, EncounterParams, RandomEncounterData, }; +use crate::models::pf_version_enum::PathfinderVersionEnum; use crate::models::response_data::ResponseCreature; use crate::services::encounter_handler::encounter_calculator; use crate::services::encounter_handler::encounter_calculator::calculate_encounter_scaling_difficulty; @@ -110,6 +111,7 @@ async fn calculate_random_encounter( creature_types: enc_data.creature_types, creature_roles: enc_data.creature_roles, lvl_combinations: unique_levels, + pathfinder_version: enc_data.pathfinder_version.unwrap_or_default(), }); let filtered_creatures = get_filtered_creatures( @@ -262,6 +264,18 @@ fn build_filter_map(filter_enum: FilterStruct) -> HashMap vec![String::from("FALSE")].into_iter(), + PathfinderVersionEnum::Remaster => vec![String::from("TRUE")].into_iter(), + PathfinderVersionEnum::Any => { + vec![String::from("TRUE"), String::from("FALSE")].into_iter() + } + }), + ); filter_map }