From f583b25176545033bc389cdf84fc74cfbdef4b97 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 20 Aug 2020 22:59:40 -0600 Subject: [PATCH] hide mag struct internals --- src/entity/item/mag.rs | 29 ++++++++++++++++++++++------- src/login/character.rs | 14 +------------- src/ship/drops/rare_drop_table.rs | 13 +------------ 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/entity/item/mag.rs b/src/entity/item/mag.rs index cd3d002..0669789 100644 --- a/src/entity/item/mag.rs +++ b/src/entity/item/mag.rs @@ -326,19 +326,34 @@ pub enum PhotonBlast { #[derive(Debug, Clone, PartialEq)] pub struct Mag { pub mag: MagType, - pub def: u16, - pub pow: u16, - pub dex: u16, - pub mnd: u16, + def: u16, + pow: u16, + dex: u16, + mnd: u16, pub synchro: u8, - pub iq: u8, - pub photon_blast: [Option; 3], + iq: u8, + photon_blast: [Option; 3], pub color: u8, - pub modifiers: Vec, + modifiers: Vec, } impl Mag { + pub fn baby_mag(skin: u16) -> Mag { + Mag { + mag: MagType::Mag, + def: 500, + pow: 0, + dex: 0, + mnd: 0, + synchro: 20, + iq: 0, + photon_blast: [None; 3], + color: (skin % 18) as u8, + modifiers: Vec::new(), + } + } + pub fn as_bytes(&self) -> [u8; 16] { let mut result = [0; 16]; result[0..3].copy_from_slice(&self.mag.value()); diff --git a/src/login/character.rs b/src/login/character.rs index cade993..91b38b8 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -226,19 +226,7 @@ async fn new_character(entity_gateway: &mut EG, user: &UserAc entity_gateway.create_item( NewItemEntity { - item: ItemDetail::Mag( - Mag { - mag: MagType::Mag, - def: 500, - pow: 0, - dex: 0, - mnd: 0, - synchro: 20, - iq: 0, - photon_blast: [None; 3], - color: (character.appearance.skin % 18) as u8, - modifiers: Vec::new(), - }), + item: ItemDetail::Mag(Mag::baby_mag(character.appearance.skin)), location: ItemLocation::Inventory { character_id: character.id, slot: 2, diff --git a/src/ship/drops/rare_drop_table.rs b/src/ship/drops/rare_drop_table.rs index dc3dd47..fae0175 100644 --- a/src/ship/drops/rare_drop_table.rs +++ b/src/ship/drops/rare_drop_table.rs @@ -136,18 +136,7 @@ impl RareDropTable { }) }, RareDropItem::Mag(mag) => { - ItemDropType::Mag(Mag { - mag: mag, - def: 500, - pow: 0, - dex: 0, - mnd: 0, - iq: 0, - synchro: 20, - photon_blast: [None; 3], - color: rng.gen_range(0, 18), - modifiers: Vec::new(), - }) + ItemDropType::Mag(Mag::baby_mag(rng.gen_range(0, 18))) } } }