Browse Source

lint src/ship/drops/*

pull/42/head
jake 4 years ago
parent
commit
f6bf34e193
  1. 2
      src/ship/drops/box_drop_table.rs
  2. 18
      src/ship/drops/generic_weapon.rs
  3. 2
      src/ship/drops/mod.rs
  4. 19
      src/ship/drops/rare_drop_table.rs

2
src/ship/drops/box_drop_table.rs

@ -170,7 +170,7 @@ impl BoxDropTable {
else { else {
None None
} }
}).nth(0)
}).next()
} }
fn random_box_drop<R: Rng>(&self, map_area: &MapArea, rng: &mut R) -> Option<ItemDropType> { fn random_box_drop<R: Rng>(&self, map_area: &MapArea, rng: &mut R) -> Option<ItemDropType> {

18
src/ship/drops/generic_weapon.rs

@ -266,30 +266,24 @@ impl AttributeTable {
fn attributes<R: Rng>(&self, percent_pattern: &AttributePercentPattern, attribute_rate: &AttributeRate, rng: &mut R) -> [Option<WeaponAttribute>; 3] { fn attributes<R: Rng>(&self, percent_pattern: &AttributePercentPattern, attribute_rate: &AttributeRate, rng: &mut R) -> [Option<WeaponAttribute>; 3] {
let mut percents = vec![ let mut percents = vec![
percent_pattern.attribute1.and_then(|pattern_type| { percent_pattern.attribute1.and_then(|pattern_type| {
self.generate_attribute(&pattern_type, &attribute_rate, rng)
self.generate_attribute(&pattern_type, attribute_rate, rng)
}), }),
percent_pattern.attribute2.and_then(|pattern_type| { percent_pattern.attribute2.and_then(|pattern_type| {
self.generate_attribute(&pattern_type, &attribute_rate, rng)
self.generate_attribute(&pattern_type, attribute_rate, rng)
}), }),
percent_pattern.attribute3.and_then(|pattern_type| { percent_pattern.attribute3.and_then(|pattern_type| {
self.generate_attribute(&pattern_type, &attribute_rate, rng)
self.generate_attribute(&pattern_type, attribute_rate, rng)
}), }),
]; ];
percents.sort_by_key(|p| { percents.sort_by_key(|p| {
match p {
Some(a) => Some(a.attr),
None => None,
}
p.as_ref().map(|a| a.attr)
}); });
percents.dedup_by_key(|p| { percents.dedup_by_key(|p| {
match p {
Some(a) => Some(a.attr),
None => None,
}
p.as_ref().map(|a| a.attr)
}); });
percents.iter() percents.iter()
.fold(([None; 3], 0), |(mut acc, index), p| { // one day I'll be able to collece into an array .fold(([None; 3], 0), |(mut acc, index), p| { // one day I'll be able to collece into an array
if let Some(_) = p {
if p.is_some() {
acc[index] = *p; acc[index] = *p;
(acc, index + 1) (acc, index + 1)
} }

2
src/ship/drops/mod.rs

@ -152,7 +152,7 @@ impl<R: Rng + SeedableRng> DropTable<R> {
return None; return None;
} }
if let Some(item) = self.rare_table.get_drop(map_area, &monster, &mut self.rng) {
if let Some(item) = self.rare_table.get_drop(map_area, monster, &mut self.rng) {
return Some(item); return Some(item);
} }

19
src/ship/drops/rare_drop_table.rs

@ -30,18 +30,17 @@ pub enum RareDropItem {
impl RareDropItem { impl RareDropItem {
pub fn from_string(name: String) -> RareDropItem { pub fn from_string(name: String) -> RareDropItem {
let parse_funcs: [Box<dyn Fn(&String) -> Option<RareDropItem>>; 6] = [ let parse_funcs: [Box<dyn Fn(&String) -> Option<RareDropItem>>; 6] = [
Box::new(|i| Some(RareDropItem::Weapon(str::parse::<WeaponType>(&i).ok()?))),
Box::new(|i| Some(RareDropItem::Armor(str::parse::<ArmorType>(&i).ok()?))),
Box::new(|i| Some(RareDropItem::Shield(str::parse::<ShieldType>(&i).ok()?))),
Box::new(|i| Some(RareDropItem::Unit(str::parse::<UnitType>(&i).ok()?))),
Box::new(|i| Some(RareDropItem::Tool(str::parse::<ToolType>(&i).ok()?))),
Box::new(|i| Some(RareDropItem::Mag(str::parse::<MagType>(&i).ok()?))),
Box::new(|i| Some(RareDropItem::Weapon(str::parse::<WeaponType>(i).ok()?))),
Box::new(|i| Some(RareDropItem::Armor(str::parse::<ArmorType>(i).ok()?))),
Box::new(|i| Some(RareDropItem::Shield(str::parse::<ShieldType>(i).ok()?))),
Box::new(|i| Some(RareDropItem::Unit(str::parse::<UnitType>(i).ok()?))),
Box::new(|i| Some(RareDropItem::Tool(str::parse::<ToolType>(i).ok()?))),
Box::new(|i| Some(RareDropItem::Mag(str::parse::<MagType>(i).ok()?))),
]; ];
for parse in parse_funcs.iter() { for parse in parse_funcs.iter() {
match parse(&name) {
Some(k) => return k,
None => {},
if let Some (k) = parse(&name) {
return k
} }
} }
@ -151,7 +150,7 @@ impl RareDropTable {
else { else {
None None
} }
}).nth(0)
}).next()
}) })
} }
} }
Loading…
Cancel
Save