Add regex crate to parse dice specs for equipment
This commit is contained in:
parent
2e02e30bc6
commit
d96d1ce003
@ -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"
|
||||
|
@ -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)]
|
||||
|
@ -518,7 +518,7 @@ fn main() -> ::rltk::BError {
|
||||
SerializationHelper,
|
||||
Equippable,
|
||||
Equipped,
|
||||
MeleePowerBonus,
|
||||
MeleeWeapon,
|
||||
DefenseBonus,
|
||||
WantsToRemoveItem,
|
||||
ParticleLifetime,
|
||||
|
@ -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)]
|
||||
|
@ -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::<i32>().expect("Not a digit");
|
||||
}
|
||||
if let Some(group) = cap.get(2) {
|
||||
die_type = group.as_str().parse::<i32>().expect("Not a digit");
|
||||
}
|
||||
if let Some(group) = cap.get(3) {
|
||||
die_bonus = group.as_str().parse::<i32>().expect("Not a digit");
|
||||
}
|
||||
}
|
||||
|
||||
(n_dice, die_type, die_bonus)
|
||||
}
|
||||
|
||||
pub enum SpawnType {
|
||||
AtPosition { x: i32, y: i32 },
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user