diff --git a/Cargo.toml b/Cargo.toml index a22fe0b..e5f8e80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] lazy_static = "1.4.0" +regex = "1.5.4" rltk = { version = "0.8.0", features=["serde"] } specs = { version = "0.16.1", features=["serde"] } specs-derive = "0.4.1" diff --git a/src/components.rs b/src/components.rs index f13bdef..a841393 100644 --- a/src/components.rs +++ b/src/components.rs @@ -178,9 +178,19 @@ pub struct Equipped { pub slot: EquipmentSlot, } +#[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] +pub enum WeaponAttribute { + Might, + Quickness, +} + #[derive(Component, ConvertSaveload, Clone)] -pub struct MeleePowerBonus { - pub power: i32, +pub struct MeleeWeapon { + pub attribute: WeaponAttribute, + pub damage_n_dice: i32, + pub damage_die_type: i32, + pub damage_bonus: i32, + pub hit_bonus: i32, } #[derive(Component, ConvertSaveload, Clone)] diff --git a/src/main.rs b/src/main.rs index ac2b0ad..ca8d5be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -518,7 +518,7 @@ fn main() -> ::rltk::BError { SerializationHelper, Equippable, Equipped, - MeleePowerBonus, + MeleeWeapon, DefenseBonus, WantsToRemoveItem, ParticleLifetime, diff --git a/src/raws/item_structs.rs b/src/raws/item_structs.rs index 8b9c1b3..36cb922 100644 --- a/src/raws/item_structs.rs +++ b/src/raws/item_structs.rs @@ -27,7 +27,9 @@ pub struct Consumable { #[derive(Deserialize, Debug)] pub struct Weapon { pub range: String, - pub power_bonus: i32, + pub attribute: String, + pub base_damage: String, + pub hit_bonus: i32, } #[derive(Deserialize, Debug)] diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index 1fddae3..aadb19b 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -1,5 +1,6 @@ use std::collections::{HashMap, HashSet}; +use ::regex::Regex; use ::specs::prelude::*; use crate::components::*; @@ -7,6 +8,29 @@ use crate::gamesystem::{mana_at_level, npc_hp}; use crate::random_table::RandomTable; use crate::raws::Raws; +pub fn parse_dice_string(dice: &str) -> (i32, i32, i32) { + lazy_static! { + static ref DICE_RE: Regex = Regex::new(r"(\d+)d(\d+)([\+\-]\d+)?").unwrap(); + } + let mut n_dice = 1; + let mut die_type = 4; + let mut die_bonus = 0; + + for cap in DIC_RE.captures_iter(dice) { + if let Some(group) = cap.get(1) { + n_dice = group.as_str().parse::().expect("Not a digit"); + } + if let Some(group) = cap.get(2) { + die_type = group.as_str().parse::().expect("Not a digit"); + } + if let Some(group) = cap.get(3) { + die_bonus = group.as_str().parse::().expect("Not a digit"); + } + } + + (n_dice, die_type, die_bonus) +} + pub enum SpawnType { AtPosition { x: i32, y: i32 }, } diff --git a/src/saveload_system.rs b/src/saveload_system.rs index be26580..483a2c2 100644 --- a/src/saveload_system.rs +++ b/src/saveload_system.rs @@ -75,7 +75,7 @@ pub fn save_game(ecs: &mut World) { SerializationHelper, Equippable, Equipped, - MeleePowerBonus, + MeleeWeapon, DefenseBonus, WantsToRemoveItem, ParticleLifetime, @@ -171,7 +171,7 @@ pub fn load_game(ecs: &mut World) { SerializationHelper, Equippable, Equipped, - MeleePowerBonus, + MeleeWeapon, DefenseBonus, WantsToRemoveItem, ParticleLifetime,