248 lines
7.9 KiB
Rust
248 lines
7.9 KiB
Rust
// Workspace: weaponry
|
|
// File: weaponry/src/weaponry_structs/equipement_fields.rs
|
|
//! The inner fields used by the super structs
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use std::fmt::Display;
|
|
use std::ops::Add;
|
|
use strum::Display;
|
|
|
|
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
|
|
#[cfg_attr(test, derive(PartialEq))]
|
|
/// The special category, a vec of string, for display purposes only
|
|
// TODO: avoid pub make an impl ?
|
|
pub struct SpecialCategory(pub Vec<String>);
|
|
|
|
/// The kind of target this nature can apply to
|
|
#[derive(Clone)]
|
|
pub enum NatureTarget {
|
|
/// Can apply to a weapon and is unique
|
|
WeaponUnique,
|
|
/// Can apply to a weapon and must be combined with another
|
|
WeaponCombined,
|
|
/// Can apply to an armor (all armor nature are unique)
|
|
Armor,
|
|
}
|
|
|
|
/// Enum of all different physical weapon damage types
|
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
|
// #[cfg_attr(test, derive(PartialEq))]
|
|
pub enum PhysicalDamageType {
|
|
Blunt,
|
|
Slash,
|
|
Pierce,
|
|
}
|
|
|
|
// impl TryFrom<&str> for PhysicalDamageType {
|
|
// type Error = FatalEquipementError;
|
|
|
|
// fn try_from(value: &str) -> Result<Self, Self::Error> {
|
|
// match value.to_ascii_lowercase().as_str() {
|
|
// "blunt" => Ok(Self::Blunt),
|
|
// "slash" => Ok(Self::Slash),
|
|
// "pierce" => Ok(Self::Pierce),
|
|
// _ => Err(FatalEquipementError::Conversion {
|
|
// origin_type: std::any::type_name::<Self>().to_owned(),
|
|
// data: value.to_string(),
|
|
// }),
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
/// Weapon damage, combining the base weapon damage type and it's level
|
|
///
|
|
/// Signifying wether the damage is pure or [secondary] or [[tertiary]]
|
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#[derive(Clone, Debug, Display, Deserialize, Serialize)]
|
|
#[cfg_attr(test, derive(PartialEq))]
|
|
pub enum DamageMod {
|
|
Primary(PhysicalDamageType),
|
|
Secondary(PhysicalDamageType),
|
|
Tertiary(PhysicalDamageType),
|
|
}
|
|
|
|
/// Combined damage type, as a vector of all damage types
|
|
///
|
|
/// Meant to be serialised to tex and deserialized directly from the table
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
#[cfg_attr(test, derive(PartialEq))]
|
|
// TODO: avoid pub make an impl ?
|
|
pub struct DamageType(pub Vec<DamageMod>);
|
|
|
|
impl Display for DamageType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"{}",
|
|
self.0
|
|
.iter()
|
|
.fold(String::new(), |res, new| format!("{res}, {new}"))
|
|
)
|
|
}
|
|
}
|
|
|
|
// impl TryFrom<&str> for DamageType {
|
|
// type Error = FatalEquipementError;
|
|
|
|
// fn try_from(value: &str) -> Result<Self, Self::Error> {
|
|
// let re = regex::Regex::new(r"(?<tertiary>\[\[\w+\]\])|(?<secondary>\[\w+\])|(?<pure>\w+)")
|
|
// .unwrap();
|
|
// let v = value
|
|
// .split(",")
|
|
// .map(
|
|
// |v| {
|
|
// let groups = re.captures(v).unwrap();
|
|
// *groups
|
|
// }, // match v.trim() {
|
|
// // _ => Ok(DamageMod::Primary(PhysicalDamageType::Blunt)),
|
|
// // }
|
|
// )
|
|
// .collect::<Result<Vec<DamageMod>, FatalEquipementError>>();
|
|
// Ok(Self(v?))
|
|
// }
|
|
// }
|
|
// impl FromSql for DamageType {
|
|
// fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
|
|
// Ok(DamageType(vec![DamageMod::Secondary(
|
|
// PhysicalDamageType::Pierce,
|
|
// )]))
|
|
// }
|
|
// }
|
|
|
|
impl Add for DamageType {
|
|
type Output = Self;
|
|
|
|
fn add(self, rhs: Self) -> Self::Output {
|
|
Self(self.0.iter().chain(rhs.0.iter()).cloned().collect())
|
|
}
|
|
}
|
|
|
|
// TODO: Convert into this category at the end, depending on all important factors
|
|
/// List all the final weapon categories, this enum should be infered from <Size> and <BaseShape> if they were defined
|
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#[derive(Clone, Debug, PartialEq, Display, Deserialize, Serialize, strum::EnumString)]
|
|
// #[cfg_attr(test, derive(PartialEq))]
|
|
pub enum WeaponCategory {
|
|
Exotic,
|
|
Dagger,
|
|
Claws,
|
|
Blade,
|
|
Haroth,
|
|
Axe,
|
|
Kahml,
|
|
Hammer,
|
|
Rhodarak,
|
|
Staff,
|
|
Lance,
|
|
Landscapper,
|
|
Bow,
|
|
Crossbow,
|
|
Cannon,
|
|
// Armor,
|
|
// Shield,
|
|
}
|
|
|
|
// TODO[4]: Have a final weapon category tied to the speciality, if any appliable to the character
|
|
// : Since this is not needed for balencing, this will be left alone for a while
|
|
// impl WeaponCategory {
|
|
// fn from_category_and_size(macro_category: &WeaponBaseShape, size: &WeaponBaseSize) -> Self {
|
|
// match (macro_category, size) {
|
|
// (WeaponBaseShape::Axe, WeaponBaseSize::SuperHeavy) => Self::Kahml,
|
|
// (WeaponBaseShape::Blade, WeaponBaseSize::SuperHeavy) => Self::Haroth,
|
|
// (WeaponBaseShape::Hammer, WeaponBaseSize::SuperHeavy) => Self::Rhodarak,
|
|
// (WeaponBaseShape::Claws, WeaponBaseSize::SuperHeavy) => Self::Landscapper,
|
|
// (WeaponBaseShape::Staves, WeaponBaseSize::SuperHeavy) => Self::Landscapper,
|
|
// (WeaponBaseShape::Bow, WeaponBaseSize::SuperHeavy) => Self::Bow,
|
|
// (WeaponBaseShape::Crossbow, WeaponBaseSize::SuperHeavy) => Self::Crossbow,
|
|
// (WeaponBaseShape::Cannon, WeaponBaseSize::SuperHeavy) => Self::Cannon,
|
|
|
|
// (WeaponBaseShape::Exotic, WeaponBaseSize::SuperHeavy) => Self::Exotic,
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// TODO: This is the real initial category
|
|
/// The list of initial weapon meta categories
|
|
// TODO[!]: This enum should only include Weapons, Shields, Armors and no <BaseShape>
|
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
|
|
pub enum WeaponMacroCategory {
|
|
Staves,
|
|
Blunt,
|
|
Slash,
|
|
Ranged,
|
|
Armor,
|
|
Shields,
|
|
Exotic,
|
|
/// A custom weapon category, only used by the target
|
|
// TODO: Get rid of this category and make a custom category for target
|
|
Weapons,
|
|
/// A custom none category, used to forbid a part to be cast upon of from
|
|
// TODO: Check the soundness of this implementation
|
|
None,
|
|
}
|
|
|
|
/// The Base Shape of the weapon, used to infer the final category of the weapon
|
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
|
|
pub enum WeaponBaseShape {
|
|
Staves,
|
|
Blunt,
|
|
Slash,
|
|
Ranged,
|
|
Armor,
|
|
Shields,
|
|
Exotic,
|
|
// TODO[!]: Check the soundness of this
|
|
None,
|
|
}
|
|
|
|
/// The Base Size of the weapon, used to infer the final category of the weapon
|
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString)]
|
|
pub enum WeaponBaseSize {
|
|
Light,
|
|
Medium,
|
|
Heavy,
|
|
SuperHeavy,
|
|
}
|
|
|
|
// TODO: This is only needed as long as we dont have a special category for the target
|
|
impl PartialEq for WeaponMacroCategory {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
match (self, other) {
|
|
(&Self::None, _) => false,
|
|
(_, Self::None) => false,
|
|
(&Self::Armor, &Self::Armor) => true,
|
|
(&Self::Armor, _) => false,
|
|
(_, &Self::Armor) => false,
|
|
(&Self::Weapons, _) => true,
|
|
(_, &Self::Weapons) => true,
|
|
(&Self::Staves, &Self::Staves) => true,
|
|
(&Self::Blunt, &Self::Blunt) => true,
|
|
(&Self::Slash, &Self::Slash) => true,
|
|
(&Self::Ranged, &Self::Ranged) => true,
|
|
(&Self::Exotic, &Self::Exotic) => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
// use super::*;
|
|
|
|
#[ignore]
|
|
#[test]
|
|
fn test_fields_serialisation() {
|
|
unimplemented!()
|
|
}
|
|
|
|
#[ignore]
|
|
#[test]
|
|
fn test_fields_deserialisation() {
|
|
unimplemented!()
|
|
}
|
|
}
|