lint src/ship/shop/tool.rs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
64a3a1ff97
commit
d42491095e
@ -302,7 +302,7 @@ impl ItemShops {
|
||||
|
||||
ItemShops {
|
||||
weapon_shop: weapon_shop,
|
||||
tool_shop: ToolShop::new(),
|
||||
tool_shop: ToolShop::default(),
|
||||
armor_shop: ArmorShop::default(),
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl ShopItem for ToolShopItem {
|
||||
fn price(&self) -> usize {
|
||||
match self {
|
||||
ToolShopItem::Tool(tool) => {
|
||||
TOOL_STATS.get(&tool)
|
||||
TOOL_STATS.get(tool)
|
||||
.map(|tool_stats| {
|
||||
tool_stats.price
|
||||
})
|
||||
@ -146,7 +146,7 @@ fn load_tool_table() -> ToolTable {
|
||||
|
||||
let mut table: HashMap<String, Vec<ToolType>> = toml::from_str(s.as_str()).unwrap();
|
||||
|
||||
ToolTable(table.remove("tools".into()).unwrap())
|
||||
ToolTable(table.remove("tools").unwrap())
|
||||
}
|
||||
|
||||
fn load_tech_table() -> TechTable {
|
||||
@ -156,7 +156,7 @@ fn load_tech_table() -> TechTable {
|
||||
f.read_to_string(&mut s).unwrap();
|
||||
|
||||
let mut table: HashMap<String, Vec<TechTierDeserialize>> = toml::from_str(s.as_str()).unwrap();
|
||||
let techniques = table.remove("techniques".into()).unwrap();
|
||||
let techniques = table.remove("techniques").unwrap();
|
||||
let techniques = techniques.into_iter()
|
||||
.map(|tech_tier| {
|
||||
TechTier {
|
||||
@ -194,15 +194,18 @@ pub struct ToolShop<R: Rng + SeedableRng> {
|
||||
rng: R,
|
||||
}
|
||||
|
||||
impl<R: Rng + SeedableRng> ToolShop<R> {
|
||||
pub fn new() -> ToolShop<R> {
|
||||
|
||||
impl<R: Rng + SeedableRng> Default for ToolShop<R> {
|
||||
fn default() -> ToolShop<R> {
|
||||
ToolShop {
|
||||
tools: load_tool_table(),
|
||||
techs: load_tech_table(),
|
||||
rng: R::from_entropy(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Rng + SeedableRng> ToolShop<R> {
|
||||
fn generate_tech_types(&mut self, character_level: usize) -> Vec<Technique> {
|
||||
let tier = self.techs.0.iter()
|
||||
.filter(|t| t.level <= character_level)
|
||||
@ -233,7 +236,7 @@ impl<R: Rng + SeedableRng> ToolShop<R> {
|
||||
let tech_choice = WeightedIndex::new(tier.iter().map(|(_, e)| e.probability)).unwrap();
|
||||
while techs.len() < number_of_techs {
|
||||
let tech_detail = tier.get(tech_choice.sample(&mut self.rng)).unwrap();
|
||||
if techs.iter().find(|t| *t == tech_detail.0).is_none() {
|
||||
if !techs.iter().any(|t| t == tech_detail.0) {
|
||||
techs.push(*tech_detail.0);
|
||||
}
|
||||
}
|
||||
@ -269,7 +272,7 @@ impl<R: Rng + SeedableRng> ToolShop<R> {
|
||||
|
||||
pub fn generate_tool_list(&mut self, character_level: usize) -> Vec<ToolShopItem> {
|
||||
let mut tools = Vec::new().into_iter()
|
||||
.chain(self.tools.0.clone().into_iter().map(|t| ToolShopItem::Tool(t)))
|
||||
.chain(self.tools.0.clone().into_iter().map(ToolShopItem::Tool))
|
||||
.chain(self.generate_techs(character_level).into_iter())
|
||||
.collect::<Vec<_>>();
|
||||
tools.sort();
|
||||
@ -284,12 +287,12 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_loading_tool_shop() {
|
||||
ToolShop::<rand_chacha::ChaCha20Rng>::new();
|
||||
ToolShop::<rand_chacha::ChaCha20Rng>::default();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generating_some_tools() {
|
||||
let mut ts = ToolShop::<rand_chacha::ChaCha20Rng>::new();
|
||||
let mut ts = ToolShop::<rand_chacha::ChaCha20Rng>::default();
|
||||
for i in 0..200 {
|
||||
ts.generate_tool_list(i);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user