use super::ItemUID; use data::tables::{self, WeaponTemplate}; use proto::{WeaponBin, WeaponInfo}; pub struct Weapon { pub uid: ItemUID, pub template_id: u32, pub star: u32, pub level: u32, pub exp: u32, pub refine_level: u32, } impl Weapon { pub fn new(template_id: u32, uid: ItemUID) -> Self { let template = Self::get_template(template_id).unwrap(); Self { template_id, uid, level: (template.star_limit + 1) * 10, star: template.star_limit, refine_level: template.refine_limit, exp: 0, } } pub fn from_bin(bin: WeaponBin) -> Self { Self { template_id: bin.template_id, uid: bin.uid.into(), star: bin.star, level: bin.level, exp: bin.exp, refine_level: bin.refine_level, } } pub fn to_bin(&self) -> WeaponBin { WeaponBin { template_id: self.template_id, uid: self.uid.value(), star: self.star, level: self.level, exp: self.exp, refine_level: self.refine_level, } } pub fn to_client(&self) -> WeaponInfo { WeaponInfo { template_id: self.template_id, uid: self.uid.value(), star: self.star, level: self.level, exp: self.exp, refine_level: self.refine_level, ..Default::default() } } fn get_template(template_id: u32) -> Option<&'static WeaponTemplate> { tables::weapon_template_tb::iter().find(|tmpl| tmpl.item_id == template_id) } }