use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RollChance {
chance: u32,
result: String,
}
impl RollChance {
pub fn empty() -> Self {
Self {
chance: 0,
result: String::new(),
}
}
pub fn from_tag(tag_value: &str) -> Self {
let split = tag_value.split(':').collect::<Vec<&str>>();
if split.len() != 2 {
log::error!("Unable to parse metal and chance from {}", tag_value);
return RollChance::empty();
}
let result = String::from(split[0]);
match split[1].parse() {
Ok(n) => Self { chance: n, result },
Err(e) => {
log::warn!("Unable to parse chance from {},{:?}", split[1], e);
Self { chance: 0, result }
}
}
}
}