|
@ -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)
|
|
|
}
|
|
|
}
|
|
|