diff --git a/src/ship/shops/weapon.rs b/src/ship/shops/weapon.rs index 877ce52..90ba410 100644 --- a/src/ship/shops/weapon.rs +++ b/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; 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 { + Some(self.cmp(other)) + } +} + fn special_stars(special: &WeaponSpecial) -> usize { match special { @@ -500,11 +528,13 @@ impl WeaponShop { } pub fn generate_weapon_list(&mut self, level: usize) -> Vec { - (0..number_of_weapons_to_generate(level)) + let mut x = (0..number_of_weapons_to_generate(level)) .map(|_| { self.generate_weapon(level) }) - .collect() + .collect::>(); + x.sort(); + x } }