From 02c9cdc276fabf9197f166530f573120c814fff2 Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 27 Apr 2020 06:55:18 -0600 Subject: [PATCH] drop techs --- src/entity/character.rs | 25 ++----------------------- src/entity/item/tech.rs | 32 +++++++++++++++++++++++++++++++- src/ship/drops/tech_table.rs | 2 +- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/entity/character.rs b/src/entity/character.rs index 5d898b0..4c7f140 100644 --- a/src/entity/character.rs +++ b/src/entity/character.rs @@ -153,29 +153,8 @@ impl CharacterTechniques { pub fn as_bytes(&self) -> [u8; 20] { self.techs.iter() .fold([0xFF; 20], |mut techlist, (tech, level)| { - let index = match tech { - Technique::Foie => 0, - Technique::Gifoie => 1, - Technique::Rafoie => 2, - Technique::Barta => 3, - Technique::Gibarta => 4, - Technique::Rabarta => 5, - Technique::Zonde => 6, - Technique::Gizonde => 7, - Technique::Razonde => 8, - Technique::Grants => 9, - Technique::Deband => 10, - Technique::Jellen => 11, - Technique::Zalure => 12, - Technique::Shifta => 13, - Technique::Ryuker => 14, - Technique::Resta => 15, - Technique::Anti => 16, - Technique::Reverser => 17, - Technique::Megid => 18, - }; - - techlist[index] = level.0 - 1; + let index = tech.as_value(); + techlist[index as usize] = level.0 - 1; techlist }) } diff --git a/src/entity/item/tech.rs b/src/entity/item/tech.rs index b7faeaa..326aab7 100644 --- a/src/entity/item/tech.rs +++ b/src/entity/item/tech.rs @@ -24,6 +24,31 @@ pub enum Technique { Megid, } +impl Technique { + pub fn as_value(&self) -> u8 { + match self { + Technique::Foie => 0, + Technique::Gifoie => 1, + Technique::Rafoie => 2, + Technique::Barta => 3, + Technique::Gibarta => 4, + Technique::Rabarta => 5, + Technique::Zonde => 6, + Technique::Gizonde => 7, + Technique::Razonde => 8, + Technique::Grants => 9, + Technique::Deband => 10, + Technique::Jellen => 11, + Technique::Zalure => 12, + Technique::Shifta => 13, + Technique::Ryuker => 14, + Technique::Resta => 15, + Technique::Anti => 16, + Technique::Reverser => 17, + Technique::Megid => 18, + } + } +} #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct TechniqueDisk { @@ -33,6 +58,11 @@ pub struct TechniqueDisk { impl TechniqueDisk { pub fn as_bytes(&self) -> [u8; 16] { - [0; 16] + let mut result = [0; 16]; + result[0] = 3; + result[1] = 2; + result[2] = self.level as u8 - 1; + result[4] = self.tech.as_value(); + result } } diff --git a/src/ship/drops/tech_table.rs b/src/ship/drops/tech_table.rs index 370f9c5..7e40ae6 100644 --- a/src/ship/drops/tech_table.rs +++ b/src/ship/drops/tech_table.rs @@ -100,7 +100,7 @@ impl TechniqueTable { let tech_weights = WeightedIndex::new(tech_rates.clone().map(|(_, stat)| stat.rate)).unwrap(); let (tech, stat) = tech_rates.nth(tech_weights.sample(rng)).unwrap(); - let level = rng.gen_range(stat.min, stat.max+1); + let level = rng.gen_range(stat.min, stat.max+1) + 1; Some(ItemDropType::TechniqueDisk(TechniqueDisk { tech: *tech,