Browse Source

genuflect towards the great clippy

pull/141/head
jake 1 year ago
parent
commit
fbeaf5e93e
  1. 2
      maps/src/enemy.rs
  2. 4
      src/bin/patch.rs
  3. 6
      src/common/mainloop/interserver.rs
  4. 3
      src/ship/drops/box_drop_table.rs
  5. 4
      src/ship/drops/generic_armor.rs
  6. 2
      src/ship/drops/generic_shield.rs
  7. 6
      src/ship/drops/generic_weapon.rs
  8. 2
      src/ship/items/apply_item.rs
  9. 12
      src/ship/items/bank.rs
  10. 1
      src/ship/packet/builder/room.rs
  11. 4
      src/ship/shops/armor.rs
  12. 13
      src/ship/shops/tool.rs
  13. 4
      src/ship/shops/weapon.rs

2
maps/src/enemy.rs

@ -81,7 +81,7 @@ pub fn load_rare_monster_file<T: serde::de::DeserializeOwned>(episode: Episode)
let mut f = File::open(path).unwrap(); let mut f = File::open(path).unwrap();
let mut s = String::new(); let mut s = String::new();
f.read_to_string(&mut s);
f.read_to_string(&mut s).unwrap();
toml::from_str::<T>(s.as_str()).unwrap() toml::from_str::<T>(s.as_str()).unwrap()
} }

4
src/bin/patch.rs

@ -12,7 +12,5 @@ fn main() {
elseware::common::mainloop::run_server(patch_state, patch_config.port).await; elseware::common::mainloop::run_server(patch_state, patch_config.port).await;
}); });
async_std::task::block_on(async move {
patch_loop.await
});
async_std::task::block_on(patch_loop);
} }

6
src/common/mainloop/interserver.rs

@ -219,12 +219,8 @@ where
let mut buf = [0u8; 1]; let mut buf = [0u8; 1];
loop { loop {
let peek = socket.peek(&mut buf).await; let peek = socket.peek(&mut buf).await;
match peek {
Ok(len) if len == 0 => {
if let Ok(0) = peek {
break break
},
_ => {
}
} }
} }
} }

3
src/ship/drops/box_drop_table.rs

@ -13,7 +13,6 @@ use crate::ship::drops::generic_armor::GenericArmorTable;
use crate::ship::drops::generic_shield::GenericShieldTable; use crate::ship::drops::generic_shield::GenericShieldTable;
use crate::ship::drops::generic_unit::GenericUnitTable; use crate::ship::drops::generic_unit::GenericUnitTable;
use crate::ship::drops::tool_table::ToolTable; use crate::ship::drops::tool_table::ToolTable;
use entity::item::ItemDetail;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct BoxDropRate { struct BoxDropRate {
@ -176,7 +175,7 @@ impl BoxDropTable {
fn random_box_drop<R: Rng>(&self, map_area: &MapArea, rng: &mut R) -> Option<ItemDropType> { fn random_box_drop<R: Rng>(&self, map_area: &MapArea, rng: &mut R) -> Option<ItemDropType> {
self.rare_drop(map_area, rng).or_else(|| { self.rare_drop(map_area, rng).or_else(|| {
let rate = self.box_rates.rates_by_area(map_area); let rate = self.box_rates.rates_by_area(map_area);
let type_weights = WeightedIndex::new(&[rate.weapon_rate, rate.armor_rate, rate.shield_rate, rate.unit_rate,
let type_weights = WeightedIndex::new([rate.weapon_rate, rate.armor_rate, rate.shield_rate, rate.unit_rate,
rate.tool_rate, rate.meseta_rate, rate.nothing_rate]).unwrap(); rate.tool_rate, rate.meseta_rate, rate.nothing_rate]).unwrap();
let btype = type_weights.sample(rng); let btype = type_weights.sample(rng);
match btype { match btype {

4
src/ship/drops/generic_armor.rs

@ -46,7 +46,7 @@ impl GenericArmorTable {
} }
fn armor_type<R: Rng>(&self, area_map: &MapArea, rng: &mut R) -> ArmorType { fn armor_type<R: Rng>(&self, area_map: &MapArea, rng: &mut R) -> ArmorType {
let rank_weights = WeightedIndex::new(&[self.rank_rates.rank0, self.rank_rates.rank1, self.rank_rates.rank2,
let rank_weights = WeightedIndex::new([self.rank_rates.rank0, self.rank_rates.rank1, self.rank_rates.rank2,
self.rank_rates.rank3, self.rank_rates.rank4]).unwrap(); self.rank_rates.rank3, self.rank_rates.rank4]).unwrap();
let rank = rank_weights.sample(rng) as i32; let rank = rank_weights.sample(rng) as i32;
let armor_level = std::cmp::max(0i32, self.armor_set as i32 - 3i32 + rank + area_map.drop_area_value().unwrap_or(0) as i32); let armor_level = std::cmp::max(0i32, self.armor_set as i32 - 3i32 + rank + area_map.drop_area_value().unwrap_or(0) as i32);
@ -80,7 +80,7 @@ impl GenericArmorTable {
} }
pub fn slots<R: Rng>(&self, _area_map: &MapArea, rng: &mut R) -> usize { pub fn slots<R: Rng>(&self, _area_map: &MapArea, rng: &mut R) -> usize {
let slot_weights = WeightedIndex::new(&[self.slot_rates.slot0, self.slot_rates.slot1, self.slot_rates.slot2,
let slot_weights = WeightedIndex::new([self.slot_rates.slot0, self.slot_rates.slot1, self.slot_rates.slot2,
self.slot_rates.slot3, self.slot_rates.slot4]).unwrap(); self.slot_rates.slot3, self.slot_rates.slot4]).unwrap();
slot_weights.sample(rng) slot_weights.sample(rng)
} }

2
src/ship/drops/generic_shield.rs

@ -36,7 +36,7 @@ impl GenericShieldTable {
} }
fn shield_type<R: Rng>(&self, area_map: &MapArea, rng: &mut R) -> ShieldType { fn shield_type<R: Rng>(&self, area_map: &MapArea, rng: &mut R) -> ShieldType {
let rank_weights = WeightedIndex::new(&[self.rank_rates.rank0, self.rank_rates.rank1, self.rank_rates.rank2,
let rank_weights = WeightedIndex::new([self.rank_rates.rank0, self.rank_rates.rank1, self.rank_rates.rank2,
self.rank_rates.rank3, self.rank_rates.rank4]).unwrap(); self.rank_rates.rank3, self.rank_rates.rank4]).unwrap();
let rank = rank_weights.sample(rng) as i32; let rank = rank_weights.sample(rng) as i32;
let shield_level = std::cmp::max(0i32, self.shield_set as i32 - 3i32 + rank + area_map.drop_area_value().unwrap_or(0) as i32); let shield_level = std::cmp::max(0i32, self.shield_set as i32 - 3i32 + rank + area_map.drop_area_value().unwrap_or(0) as i32);

6
src/ship/drops/generic_weapon.rs

@ -240,7 +240,7 @@ impl AttributeTable {
fn generate_attribute<R: Rng>(&self, pattern: &PercentPatternType, rates: &AttributeRate, rng: &mut R) -> Option<WeaponAttribute> { fn generate_attribute<R: Rng>(&self, pattern: &PercentPatternType, rates: &AttributeRate, rng: &mut R) -> Option<WeaponAttribute> {
let attribute_weights = WeightedIndex::new(&[rates.none, rates.native, rates.abeast, rates.machine, rates.dark, rates.hit]).unwrap();
let attribute_weights = WeightedIndex::new([rates.none, rates.native, rates.abeast, rates.machine, rates.dark, rates.hit]).unwrap();
let attr = match attribute_weights.sample(rng) { let attr = match attribute_weights.sample(rng) {
0 => return None, 0 => return None,
1 => Attribute::Native, 1 => Attribute::Native,
@ -253,7 +253,7 @@ impl AttributeTable {
let percents = self.percent_rates.get_by_pattern(pattern); let percents = self.percent_rates.get_by_pattern(pattern);
let value_weights = WeightedIndex::new(&percents.as_array()).unwrap();
let value_weights = WeightedIndex::new(percents.as_array()).unwrap();
let value = value_weights.sample(rng); let value = value_weights.sample(rng);
let percent = ((value + 1) * 5) as i8; let percent = ((value + 1) * 5) as i8;
@ -477,7 +477,7 @@ impl GenericWeaponTable {
let pattern = std::cmp::min(area % ratio.inc, 3); let pattern = std::cmp::min(area % ratio.inc, 3);
let weights = self.grind_rates.grind_rate[pattern as usize]; let weights = self.grind_rates.grind_rate[pattern as usize];
let grind_choice = WeightedIndex::new(&weights).unwrap();
let grind_choice = WeightedIndex::new(weights).unwrap();
grind_choice.sample(rng) grind_choice.sample(rng)
} }

2
src/ship/items/apply_item.rs

@ -226,7 +226,7 @@ pub async fn liberta_kit<EG: EntityGateway>(entity_gateway: &mut EG, used_cell:
fn jack_o_lantern() -> Result<Vec<ApplyItemAction>, anyhow::Error> fn jack_o_lantern() -> Result<Vec<ApplyItemAction>, anyhow::Error>
{ {
let mag_rate = WeightedIndex::new(&[13, 13, 13, 13, 12, 12, 12, 12]).unwrap();
let mag_rate = WeightedIndex::new([13, 13, 13, 13, 12, 12, 12, 12]).unwrap();
let mag_type = match mag_rate.sample(&mut rand_chacha::ChaChaRng::from_entropy()) { let mag_type = match mag_rate.sample(&mut rand_chacha::ChaChaRng::from_entropy()) {
0 => ToolType::CellOfMag502, 0 => ToolType::CellOfMag502,
1 => ToolType::CellOfMag213, 1 => ToolType::CellOfMag213,

12
src/ship/items/bank.rs

@ -325,15 +325,7 @@ impl std::cmp::Eq for BankItemDetail {}
impl std::cmp::PartialOrd for BankItemDetail { impl std::cmp::PartialOrd for BankItemDetail {
fn partial_cmp(&self, other: &BankItemDetail) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &BankItemDetail) -> Option<std::cmp::Ordering> {
let mut self_bytes = [0u8; 4];
let mut other_bytes = [0u8; 4];
self_bytes.copy_from_slice(&self.as_client_bytes()[0..4]);
other_bytes.copy_from_slice(&other.as_client_bytes()[0..4]);
let self_value = u32::from_be_bytes(self_bytes);
let other_value = u32::from_be_bytes(other_bytes);
self_value.partial_cmp(&other_value)
Some(self.cmp(other))
} }
} }
@ -362,7 +354,7 @@ impl std::cmp::Eq for BankItem {}
impl std::cmp::PartialOrd for BankItem { impl std::cmp::PartialOrd for BankItem {
fn partial_cmp(&self, other: &BankItem) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &BankItem) -> Option<std::cmp::Ordering> {
self.item.partial_cmp(&other.item)
Some(self.cmp(other))
} }
} }

1
src/ship/packet/builder/room.rs

@ -17,6 +17,7 @@ pub async fn join_room(id: ClientId,
event: ShipEvent) event: ShipEvent)
-> Result<JoinRoom, anyhow::Error> { -> Result<JoinRoom, anyhow::Error> {
let all_clients = client_location.get_clients_in_room(room_id).await.map_err(|err| -> ClientLocationError { err.into() })?; let all_clients = client_location.get_clients_in_room(room_id).await.map_err(|err| -> ClientLocationError { err.into() })?;
#[allow(clippy::manual_try_fold)] // I don't think its even possible to make this work here
let players = futures::stream::iter(all_clients.iter()) let players = futures::stream::iter(all_clients.iter())
.enumerate() .enumerate()
.fold::<Result<_, anyhow::Error>, _, _>(Ok([PlayerHeader::default(); 4]), |acc, (i, c)| async move { .fold::<Result<_, anyhow::Error>, _, _>(Ok([PlayerHeader::default(); 4]), |acc, (i, c)| async move {

4
src/ship/shops/armor.rs

@ -342,8 +342,8 @@ impl<R: Rng + SeedableRng> ArmorShop<R> {
pub fn generate_armor_list(&mut self, character_level: usize) -> Vec<ArmorShopItem> { pub fn generate_armor_list(&mut self, character_level: usize) -> Vec<ArmorShopItem> {
self.generate_frame_list(character_level).into_iter() self.generate_frame_list(character_level).into_iter()
.chain(self.generate_barrier_list(character_level).into_iter())
.chain(self.generate_unit_list(character_level).into_iter())
.chain(self.generate_barrier_list(character_level))
.chain(self.generate_unit_list(character_level))
.collect() .collect()
} }
} }

13
src/ship/shops/tool.rs

@ -36,16 +36,7 @@ impl Ord for ToolShopItem {
impl PartialOrd for ToolShopItem { impl PartialOrd for ToolShopItem {
fn partial_cmp(&self, other: &ToolShopItem) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &ToolShopItem) -> Option<std::cmp::Ordering> {
let a = match self {
ToolShopItem::Tool(t) => Tool{tool : *t}.as_individual_bytes(),
ToolShopItem::Tech(t) => t.as_bytes(),
};
let b = match other {
ToolShopItem::Tool(t) => Tool{tool : *t}.as_individual_bytes(),
ToolShopItem::Tech(t) => t.as_bytes(),
};
a.partial_cmp(&b)
Some(self.cmp(other))
} }
} }
@ -285,7 +276,7 @@ impl<R: Rng + SeedableRng> ToolShop<R> {
pub fn generate_tool_list(&mut self, character_level: usize) -> Vec<ToolShopItem> { pub fn generate_tool_list(&mut self, character_level: usize) -> Vec<ToolShopItem> {
let mut tools = Vec::new().into_iter() let mut tools = Vec::new().into_iter()
.chain(self.tools.0.clone().into_iter().map(ToolShopItem::Tool)) .chain(self.tools.0.clone().into_iter().map(ToolShopItem::Tool))
.chain(self.generate_techs(character_level).into_iter())
.chain(self.generate_techs(character_level))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
tools.sort(); tools.sort();
tools tools

4
src/ship/shops/weapon.rs

@ -412,7 +412,7 @@ impl<R: Rng + SeedableRng> WeaponShop<R> {
.last() .last()
.unwrap(); .unwrap();
let attr_choice = WeightedIndex::new(&[tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap();
let attr_choice = WeightedIndex::new([tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap();
let attr = match attr_choice.sample(&mut self.rng) { let attr = match attr_choice.sample(&mut self.rng) {
0 => return None, 0 => return None,
1 => Attribute::Native, 1 => Attribute::Native,
@ -439,7 +439,7 @@ impl<R: Rng + SeedableRng> WeaponShop<R> {
.last() .last()
.unwrap(); .unwrap();
let attr_choice = WeightedIndex::new(&[tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap();
let attr_choice = WeightedIndex::new([tier.none, tier.native, tier.abeast, tier.machine, tier.dark, tier.hit]).unwrap();
let attr = match attr_choice.sample(&mut self.rng) { let attr = match attr_choice.sample(&mut self.rng) {
0 => return None, 0 => return None,
1 => Attribute::Native, 1 => Attribute::Native,

Loading…
Cancel
Save