Browse Source

lint src/ship/drops/*

pull/42/head
jake 3 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. 21
      src/ship/drops/rare_drop_table.rs

2
src/ship/drops/box_drop_table.rs

@ -170,7 +170,7 @@ impl BoxDropTable {
else {
None
}
}).nth(0)
}).next()
}
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] {
let mut percents = vec![
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| {
self.generate_attribute(&pattern_type, &attribute_rate, rng)
self.generate_attribute(&pattern_type, attribute_rate, rng)
}),
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| {
match p {
Some(a) => Some(a.attr),
None => None,
}
p.as_ref().map(|a| a.attr)
});
percents.dedup_by_key(|p| {
match p {
Some(a) => Some(a.attr),
None => None,
}
p.as_ref().map(|a| a.attr)
});
percents.iter()
.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 + 1)
}

2
src/ship/drops/mod.rs

@ -152,7 +152,7 @@ impl<R: Rng + SeedableRng> DropTable<R> {
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);
}

21
src/ship/drops/rare_drop_table.rs

@ -30,19 +30,18 @@ pub enum RareDropItem {
impl RareDropItem {
pub fn from_string(name: String) -> RareDropItem {
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() {
match parse(&name) {
Some(k) => return k,
None => {},
}
if let Some (k) = parse(&name) {
return k
}
}
panic!()
@ -151,7 +150,7 @@ impl RareDropTable {
else {
None
}
}).nth(0)
}).next()
})
}
}
Loading…
Cancel
Save