Browse Source

professional rusting

pbs
andy 4 years ago
parent
commit
6611f2b3a8
  1. 34
      src/ship/shops/weapon.rs

34
src/ship/shops/weapon.rs

@ -3,6 +3,7 @@ use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::convert::TryInto;
use std::cmp::Ordering;
use serde::Deserialize;
use rand::{Rng, SeedableRng};
use rand::distributions::{WeightedIndex, Distribution};
@ -29,6 +30,33 @@ pub struct WeaponShopItem {
attributes: [Option<WeaponAttribute>; 2],
}
impl PartialEq for WeaponShopItem {
fn eq(&self, other: &Self) -> bool {
if self.weapon == other.weapon &&
self.special == other.special &&
self.grind == other.grind &&
self.attributes == other.attributes {
true
} else {
false
}
}
}
impl Eq for WeaponShopItem {}
impl Ord for WeaponShopItem {
fn cmp(&self, other: &Self) -> Ordering {
self.weapon.value().cmp(&other.weapon.value())
}
}
impl PartialOrd for WeaponShopItem {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
fn special_stars(special: &WeaponSpecial) -> usize {
match special {
@ -500,11 +528,13 @@ impl<R: Rng + SeedableRng> WeaponShop<R> {
}
pub fn generate_weapon_list(&mut self, level: usize) -> Vec<WeaponShopItem> {
(0..number_of_weapons_to_generate(level))
let mut x = (0..number_of_weapons_to_generate(level))
.map(|_| {
self.generate_weapon(level)
})
.collect()
.collect::<Vec<WeaponShopItem>>();
x.sort();
x
}
}

Loading…
Cancel
Save