diff --git a/.rustfmt.toml b/.rustfmt.toml index e620ab2..bf9f189 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -6,3 +6,4 @@ group_imports = "StdExternalCrate" use_field_init_shorthand = true normalize_comments = true empty_item_single_line = false +use_small_heuristics = "max" \ No newline at end of file diff --git a/benches/battle_benchmark.rs b/benches/battle_benchmark.rs index 377cc48..d42c63c 100644 --- a/benches/battle_benchmark.rs +++ b/benches/battle_benchmark.rs @@ -19,9 +19,7 @@ fn battle_benchmark(c: &mut Criterion) { for (name, class, dungeon, finished) in cases { group.bench_function(name, |b| { - let progress = DungeonProgress::Open { - finished: finished - 1, - }; + let progress = DungeonProgress::Open { finished: finished - 1 }; let monster = Fighter::from(get_dungeon_monster(dungeon, progress).unwrap()); @@ -112,10 +110,7 @@ fn init_squad(class: Class, init_companions: bool) -> PlayerFighterSquad { belt.type_specific_val = armor; } - PlayerFighterSquad { - character: account, - companions, - } + PlayerFighterSquad { character: account, companions } } fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { @@ -138,11 +133,8 @@ fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { let mut equipment = Equipment::default(); - equipment.0[EquipmentSlot::Hat] = Some(create_rune_item( - ItemType::Hat, - RuneType::FireResistance, - 75, - )); + equipment.0[EquipmentSlot::Hat] = + Some(create_rune_item(ItemType::Hat, RuneType::FireResistance, 75)); equipment.0[EquipmentSlot::BreastPlate] = Some(create_rune_item( ItemType::BreastPlate, RuneType::ColdResistence, @@ -166,10 +158,7 @@ fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { let weapon = Item { typ: ItemType::Weapon { min_dmg, max_dmg }, - rune: Some(Rune { - typ: RuneType::FireDamage, - value: 60, - }), + rune: Some(Rune { typ: RuneType::FireDamage, value: 60 }), enchantment: Some(Enchantment::SwordOfVengeance), // Defaults model_id: 1, @@ -219,10 +208,7 @@ fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { fn create_rune_item(typ: ItemType, rune_typ: RuneType, value: u8) -> Item { Item { typ, - rune: Some(Rune { - typ: rune_typ, - value, - }), + rune: Some(Rune { typ: rune_typ, value }), // Defaults model_id: 1, price: 0, diff --git a/build.rs b/build.rs index 74be824..e38412a 100644 --- a/build.rs +++ b/build.rs @@ -50,16 +50,10 @@ fn main() { "The_3rd_League_of_Superheroes", "LightDungeon::ThirdLeagueOfSuperheroes", ), - ( - "Dojo_of_Childhood_Heroes", - "LightDungeon::DojoOfChildhoodHeroes", - ), + ("Dojo_of_Childhood_Heroes", "LightDungeon::DojoOfChildhoodHeroes"), ("Monster_Grotto", "LightDungeon::MonsterGrotto"), ("City_of_Intrigues", "LightDungeon::CityOfIntrigues"), - ( - "School_of_magic_Express", - "LightDungeon::SchoolOfMagicExpress", - ), + ("School_of_magic_Express", "LightDungeon::SchoolOfMagicExpress"), ("Ash_Mountain", "LightDungeon::AshMountain"), ("Playa_HQ", "LightDungeon::PlayaGamesHQ"), ("Training_Camp", "LightDungeon::TrainingCamp"), @@ -78,31 +72,16 @@ fn main() { ]; let shadow_dungeons = [ - ( - "Shadow_Desecrated_Catacombs", - "ShadowDungeon::DesecratedCatacombs", - ), + ("Shadow_Desecrated_Catacombs", "ShadowDungeon::DesecratedCatacombs"), ("Shadow_Mines_of_Gloria", "ShadowDungeon::MinesOfGloria"), ("Shadow_Ruins_of_Gnark", "ShadowDungeon::RuinsOfGnark"), ("Shadow_Cutthroat_Grotto", "ShadowDungeon::CutthroatGrotto"), - ( - "Shadow_Emerald_Scale_Altar", - "ShadowDungeon::EmeraldScaleAltar", - ), + ("Shadow_Emerald_Scale_Altar", "ShadowDungeon::EmeraldScaleAltar"), ("Shadow_Toxic_Tree", "ShadowDungeon::ToxicTree"), ("Shadow_Magma_Stream", "ShadowDungeon::MagmaStream"), - ( - "Shadow_Frost_Blood_Temple", - "ShadowDungeon::FrostBloodTemple", - ), - ( - "Shadow_Pyramids_of_Madness", - "ShadowDungeon::PyramidsOfMadness", - ), - ( - "Shadow_Black_Skull_Fortress", - "ShadowDungeon::BlackSkullFortress", - ), + ("Shadow_Frost_Blood_Temple", "ShadowDungeon::FrostBloodTemple"), + ("Shadow_Pyramids_of_Madness", "ShadowDungeon::PyramidsOfMadness"), + ("Shadow_Black_Skull_Fortress", "ShadowDungeon::BlackSkullFortress"), ("Shadow_Circus_of_Horror", "ShadowDungeon::CircusOfHorror"), ("Shadow_Hell", "ShadowDungeon::Hell"), ("Shadow_The_13th_Floor", "ShadowDungeon::The13thFloor"), @@ -113,10 +92,7 @@ fn main() { "ShadowDungeon::TimeHonoredSchoolOfMagic", ), ("Shadow_Hemorridor", "ShadowDungeon::Hemorridor"), - ( - "Continuous_Loop_of_Idols", - "ShadowDungeon::ContinuousLoopofIdols", - ), + ("Continuous_Loop_of_Idols", "ShadowDungeon::ContinuousLoopofIdols"), ("Shadow_Nordic", "ShadowDungeon::NordicGods"), ("Shadow_Mount_Olympus", "ShadowDungeon::MountOlympus"), ( @@ -355,24 +331,21 @@ fn append_monsters( code.push_str(" Monster {\n"); let name = - m.name - .as_ref() - .map(|n| n.replace('_', " ")) - .unwrap_or_else(|| { - if is_shadow { - format!( - "Shadow {} monster #{}", - enum_variant.split("::").last().unwrap(), - idx - ) - } else { - format!( - "{} monster #{}", - enum_variant.split("::").last().unwrap(), - idx - ) - } - }); + m.name.as_ref().map(|n| n.replace('_', " ")).unwrap_or_else(|| { + if is_shadow { + format!( + "Shadow {} monster #{}", + enum_variant.split("::").last().unwrap(), + idx + ) + } else { + format!( + "{} monster #{}", + enum_variant.split("::").last().unwrap(), + idx + ) + } + }); code.push_str(&format!(" name: {:?},\n", name)); code.push_str(&format!(" level: {},\n", level)); code.push_str(&format!(" class: {},\n", class_enum)); diff --git a/examples/cached_testing.rs b/examples/cached_testing.rs index 20338ec..2b1804f 100644 --- a/examples/cached_testing.rs +++ b/examples/cached_testing.rs @@ -4,9 +4,7 @@ use sf_api::{gamestate::GameState, session::*, sso::SFAccount}; #[tokio::main] pub async fn main() { - env_logger::builder() - .filter_level(log::LevelFilter::Info) - .init(); + env_logger::builder().filter_level(log::LevelFilter::Info).init(); let args = Args::parse(); diff --git a/examples/dungeons.rs b/examples/dungeons.rs index 91444f2..79bc041 100644 --- a/examples/dungeons.rs +++ b/examples/dungeons.rs @@ -107,7 +107,5 @@ pub async fn login_with_env() -> SimpleSession { let username = std::env::var("USERNAME").unwrap(); let password = std::env::var("PASSWORD").unwrap(); let server = std::env::var("SERVER").unwrap(); - SimpleSession::login(&username, &password, &server) - .await - .unwrap() + SimpleSession::login(&username, &password, &server).await.unwrap() } diff --git a/examples/expedition.rs b/examples/expedition.rs index 4666882..a9b1867 100644 --- a/examples/expedition.rs +++ b/examples/expedition.rs @@ -122,9 +122,7 @@ pub async fn main() { let remaining = time_remaining(busy_until); if remaining.as_secs() > 60 && gs.tavern.quicksand_glasses > 0 { println!("Skipping the {}s wait", remaining.as_secs()); - Command::ExpeditionSkipWait { - typ: TimeSkip::Glass, - } + Command::ExpeditionSkipWait { typ: TimeSkip::Glass } } else { println!( "Waiting {}s until next expedition step", @@ -149,7 +147,5 @@ pub async fn login_with_env() -> SimpleSession { let username = std::env::var("USERNAME").unwrap(); let password = std::env::var("PASSWORD").unwrap(); let server = std::env::var("SERVER").unwrap(); - SimpleSession::login(&username, &password, &server) - .await - .unwrap() + SimpleSession::login(&username, &password, &server).await.unwrap() } diff --git a/examples/gamble.rs b/examples/gamble.rs index 07390fa..542caff 100644 --- a/examples/gamble.rs +++ b/examples/gamble.rs @@ -45,7 +45,5 @@ pub async fn login_with_env() -> SimpleSession { let username = std::env::var("USERNAME").unwrap(); let password = std::env::var("PASSWORD").unwrap(); let server = std::env::var("SERVER").unwrap(); - SimpleSession::login(&username, &password, &server) - .await - .unwrap() + SimpleSession::login(&username, &password, &server).await.unwrap() } diff --git a/examples/hellevator.rs b/examples/hellevator.rs index baa97f6..3b2dea9 100644 --- a/examples/hellevator.rs +++ b/examples/hellevator.rs @@ -37,10 +37,7 @@ pub async fn main() { continue; } HellevatorStatus::NotEntered => { - session - .send_command(Command::HellevatorEnter) - .await - .unwrap(); + session.send_command(Command::HellevatorEnter).await.unwrap(); continue; } HellevatorStatus::NotAvailable => { @@ -60,7 +57,5 @@ pub async fn login_with_env() -> SimpleSession { let username = std::env::var("USERNAME").unwrap(); let password = std::env::var("PASSWORD").unwrap(); let server = std::env::var("SERVER").unwrap(); - SimpleSession::login(&username, &password, &server) - .await - .unwrap() + SimpleSession::login(&username, &password, &server).await.unwrap() } diff --git a/examples/questing.rs b/examples/questing.rs index 2b04597..bba802d 100644 --- a/examples/questing.rs +++ b/examples/questing.rs @@ -93,10 +93,7 @@ pub async fn main() { continue; } }, - CurrentAction::Quest { - quest_idx, - busy_until, - } => { + CurrentAction::Quest { quest_idx, busy_until } => { let remaining = time_remaining(busy_until); let mut skip = None; @@ -161,7 +158,5 @@ pub async fn login_with_env() -> SimpleSession { let username = std::env::var("USERNAME").unwrap(); let password = std::env::var("PASSWORD").unwrap(); let server = std::env::var("SERVER").unwrap(); - SimpleSession::login(&username, &password, &server) - .await - .unwrap() + SimpleSession::login(&username, &password, &server).await.unwrap() } diff --git a/examples/world_boss.rs b/examples/world_boss.rs index d0d60ca..665d4c9 100644 --- a/examples/world_boss.rs +++ b/examples/world_boss.rs @@ -57,9 +57,7 @@ pub async fn main() -> Result<(), SFError> { if world_boss.available_daily_chests.values().any(|a| *a > 0) { // Automatically collect all daily chests, since that is what the // game also does - session - .send_command(Command::WorldBossCollectDailyChests) - .await?; + session.send_command(Command::WorldBossCollectDailyChests).await?; continue; } diff --git a/src/command.rs b/src/command.rs index 6200771..5d2ad13 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1074,17 +1074,10 @@ impl Command { }; Ok(match self { - Command::Custom { - cmd_name, - arguments: values, - } => { + Command::Custom { cmd_name, arguments: values } => { format!("{cmd_name}:{}", values.join("/")) } - Command::Login { - username, - pw_hash, - login_count, - } => { + Command::Login { username, pw_hash, login_count } => { let full_hash = sha1_hash(&format!("{pw_hash}{login_count}")); format!( "AccountLogin:{username}/{full_hash}/{login_count}/\ @@ -1092,19 +1085,11 @@ impl Command { ) } #[cfg(feature = "sso")] - Command::SSOLogin { - uuid, character_id, .. - } => format!( + Command::SSOLogin { uuid, character_id, .. } => format!( "SFAccountCharLogin:{uuid}/{character_id}/unity3d_webglplayer/\ /{APP_VERSION}" ), - Command::Register { - username, - password, - gender, - race, - class, - } => { + Command::Register { username, password, gender, race, class } => { // TODO: Custom portrait format!( "AccountCreate:{username}/{password}/{username}@playa.sso/\ @@ -1142,10 +1127,7 @@ impl Command { } Command::ViewPlayer { ident } => format!("PlayerLookAt:{ident}"), Command::BuyBeer => format!("PlayerBeerBuy:"), - Command::StartQuest { - quest_pos, - overwrite_inv, - } => { + Command::StartQuest { quest_pos, overwrite_inv } => { format!( "PlayerAdventureStart:{}/{}", quest_pos + 1, @@ -1168,10 +1150,7 @@ impl Command { Command::BuyMount { mount } => { format!("PlayerMountBuy:{}", *mount as usize) } - Command::IncreaseAttribute { - attribute, - increase_to, - } => format!( + Command::IncreaseAttribute { attribute, increase_to } => format!( "PlayerAttributIncrease:{}/{increase_to}", *attribute as u8 ), @@ -1183,10 +1162,7 @@ impl Command { format!("PlayerArenaFight:{name}/{}", u8::from(*use_mushroom)) } Command::CollectCalendar => format!("PlayerOpenCalender:"), - Command::UpgradeSkill { - attribute, - next_attribute, - } => format!( + Command::UpgradeSkill { attribute, next_attribute } => format!( "PlayerAttributIncrease:{}/{next_attribute}", *attribute as i64 ), @@ -1223,10 +1199,7 @@ impl Command { Command::GuildRaid => format!("GroupRaidDeclare:"), Command::ToiletFlush => format!("PlayerToilettFlush:"), Command::ToiletOpen => format!("PlayerToilettOpenWithKey:"), - Command::FightTower { - current_level: progress, - use_mush, - } => { + Command::FightTower { current_level: progress, use_mush } => { format!("PlayerTowerBattle:{progress}/{}", u8::from(*use_mush)) } Command::ToiletDrop { item_pos } => { @@ -1251,21 +1224,13 @@ impl Command { Command::ViewPet { pet_id: pet_index } => { format!("PetsGetStats:{pet_index}") } - Command::BuyShop { - shop_pos, - new_pos, - item_ident, - } => format!("PlayerItemMove:{shop_pos}/{new_pos}/{item_ident}"), - Command::SellShop { - item_pos, - item_ident, - } => { + Command::BuyShop { shop_pos, new_pos, item_ident } => { + format!("PlayerItemMove:{shop_pos}/{new_pos}/{item_ident}") + } + Command::SellShop { item_pos, item_ident } => { let mut rng = fastrand::Rng::new(); - let shop = if rng.bool() { - ShopType::Magic - } else { - ShopType::Weapon - }; + let shop = + if rng.bool() { ShopType::Magic } else { ShopType::Weapon }; let shop_pos = rng.u32(0..6); format!( "PlayerItemMove:{item_pos}/{}/{}/{item_ident}", @@ -1273,16 +1238,12 @@ impl Command { shop_pos + 1, ) } - Command::PlayerItemMove { - from, - to, - item_ident, - } => format!("PlayerItemMove:{from}/{to}/{item_ident}"), - Command::ItemMove { - from, - to, - item_ident, - } => format!("PlayerItemMove:{from}/{to}/{item_ident}"), + Command::PlayerItemMove { from, to, item_ident } => { + format!("PlayerItemMove:{from}/{to}/{item_ident}") + } + Command::ItemMove { from, to, item_ident } => { + format!("PlayerItemMove:{from}/{to}/{item_ident}") + } Command::UsePotion { from, item_ident } => { format!("PlayerItemMove:{from}/1/0/{item_ident}") } @@ -1290,10 +1251,7 @@ impl Command { "UnlockFeature:{}/{}", unlockable.main_ident, unlockable.sub_ident ), - Command::GuildSetInfo { - description, - emblem, - } => format!( + Command::GuildSetInfo { description, emblem } => format!( "GroupSetDescription:{}§{}", emblem.server_encode(), to_sf_string(description) @@ -1316,21 +1274,14 @@ impl Command { Command::WitchDropCauldron { item_pos } => { format!("PlayerWitchSpendItem:{item_pos}") } - Command::Blacksmith { - item_pos, - action, - item_ident, - } => format!( + Command::Blacksmith { item_pos, action, item_ident } => format!( "PlayerItemMove:{item_pos}/{}/-1/{item_ident}", *action as usize ), Command::WitchEnchant { enchantment } => { format!("PlayerWitchEnchantItem:{}/1", enchantment.0) } - Command::WitchEnchantCompanion { - enchantment, - companion, - } => { + Command::WitchEnchantCompanion { enchantment, companion } => { format!( "PlayerWitchEnchantItem:{}/{}", enchantment.0, @@ -1340,9 +1291,7 @@ impl Command { Command::UpdateLureSuggestion => { format!("PlayerGetHallOfFame:-4//0/0") } - Command::SpinWheelOfFortune { - payment: fortune_payment, - } => { + Command::SpinWheelOfFortune { payment: fortune_payment } => { format!("WheelOfFortune:{}", *fortune_payment as usize) } Command::FortressGather { resource } => { @@ -1351,11 +1300,7 @@ impl Command { Command::FortressGatherSecretStorage { stone, wood } => { format!("FortressGatherTreasure:{wood}/{stone}") } - Command::Equip { - from_pos, - to_slot, - item_ident, - } => format!( + Command::Equip { from_pos, to_slot, item_ident } => format!( "PlayerItemMove:{from_pos}/1/{}/{item_ident}", *to_slot as usize ), @@ -1409,10 +1354,7 @@ impl Command { Command::FortressUpgradeUnit { unit } => { format!("FortressUpgrade:{}", *unit as u8 + 1) } - Command::Whisper { - player_name: player, - message, - } => format!( + Command::Whisper { player_name: player, message } => format!( "PlayerMessageWhisper:{}/{}", player, to_sf_string(message) @@ -1423,20 +1365,14 @@ impl Command { Command::UnderworldUnitUpgrade { unit: unit_t } => { format!("UnderworldUpgradeUnit:{}", *unit_t as usize + 1) } - Command::UnderworldUpgradeStart { - building, - mushrooms, - } => format!( + Command::UnderworldUpgradeStart { building, mushrooms } => format!( "UnderworldBuildStart:{}/{mushrooms}", *building as usize + 1 ), Command::UnderworldUpgradeCancel { building } => { format!("UnderworldBuildStop:{}", *building as usize + 1) } - Command::UnderworldUpgradeFinish { - building, - mushrooms, - } => { + Command::UnderworldUpgradeFinish { building, mushrooms } => { format!( "UnderworldBuildFinished:{}/{mushrooms}", *building as usize + 1 @@ -1460,10 +1396,7 @@ impl Command { } format!("RollDice:{}/{}", *payment as usize, dices) } - Command::PetFeed { - pet_id, - total_fruit_count, - } => { + Command::PetFeed { pet_id, total_fruit_count } => { format!("PlayerPetFeed:{pet_id}/{total_fruit_count}") } Command::GuildPetBattle { use_mushroom } => { @@ -1510,10 +1443,7 @@ impl Command { Command::SetLanguage { language } => { format!("AccountSetLanguage:{language}") } - Command::SetPlayerRelation { - player_id, - relation, - } => { + Command::SetPlayerRelation { player_id, relation } => { format!("PlayerFriendSet:{player_id}/{}", *relation as i32) } Command::SetPortraitFrame { portrait_id } => { @@ -1525,12 +1455,7 @@ impl Command { Command::CollectEventTaskReward { pos } => { format!("DailyTaskClaim:2/{}", pos + 1) } - Command::SwapRunes { - from, - from_pos, - to, - to_pos, - } => { + Command::SwapRunes { from, from_pos, to, to_pos } => { format!( "PlayerSmithSwapRunes:{}/{}/{}/{}", *from as usize, @@ -1539,11 +1464,7 @@ impl Command { *to_pos + 1 ) } - Command::ChangeItemLook { - inv, - pos, - raw_model_id: model_id, - } => { + Command::ChangeItemLook { inv, pos, raw_model_id: model_id } => { format!( "ItemChangePicture:{}/{}/{}", *inv as usize, @@ -1641,10 +1562,7 @@ impl Command { item_idx + 1 ) } - Command::FightDungeon { - dungeon, - use_mushroom, - } => match dungeon { + Command::FightDungeon { dungeon, use_mushroom } => match dungeon { Dungeon::Light(name) => { if *name == LightDungeon::Tower { return Err(SFError::InvalidRequest( @@ -1674,10 +1592,7 @@ impl Command { } } }, - Command::FightPetOpponent { - opponent_id, - habitat: element, - } => { + Command::FightPetOpponent { opponent_id, habitat: element } => { format!("PetsPvPFight:0/{opponent_id}/{}", *element as u32 + 1) } Command::BrewPotion { fruit_type } => { @@ -1712,12 +1627,7 @@ impl Command { Command::HellevatorFight { use_mushroom } => { format!("GroupTournamentBattle:{}", u8::from(*use_mushroom)) } - Command::HellevatorBuy { - position, - typ, - price, - use_mushroom, - } => { + Command::HellevatorBuy { position, typ, price, use_mushroom } => { format!( "GroupTournamentMerchantBuy:{position}/{}/{price}/{}", *typ as u32, @@ -1732,10 +1642,7 @@ impl Command { let pos = 26 + (per_page * page); format!("GroupTournamentRankingAllGroups:{pos}//25/25") } - Command::HellevatorJoinHellAttack { - use_mushroom, - plain: pos, - } => { + Command::HellevatorJoinHellAttack { use_mushroom, plain: pos } => { format!( "GroupTournamentRaidParticipant:{}/{}", u8::from(*use_mushroom), @@ -1782,10 +1689,7 @@ impl Command { Command::WorldBossRemoveCatapult => { "WorldBossUpgradeDestroy:".into() } - Command::WorldBossBuyUpgrade { - offer_idx, - use_mushrooms, - } => { + Command::WorldBossBuyUpgrade { offer_idx, use_mushrooms } => { format!( "WorldBossUpgradeBuy:{}/{}", offer_idx + 1, diff --git a/src/gamestate/character.rs b/src/gamestate/character.rs index 37127ad..15c4af2 100644 --- a/src/gamestate/character.rs +++ b/src/gamestate/character.rs @@ -328,22 +328,10 @@ impl Mount { #[must_use] pub fn cost(&self) -> NormalCost { match self { - Mount::Cow => NormalCost { - silver: 100, - mushrooms: 0, - }, - Mount::Horse => NormalCost { - silver: 500, - mushrooms: 0, - }, - Mount::Tiger => NormalCost { - silver: 1000, - mushrooms: 1, - }, - Mount::Dragon => NormalCost { - silver: 0, - mushrooms: 25, - }, + Mount::Cow => NormalCost { silver: 100, mushrooms: 0 }, + Mount::Horse => NormalCost { silver: 500, mushrooms: 0 }, + Mount::Tiger => NormalCost { silver: 1000, mushrooms: 1 }, + Mount::Dragon => NormalCost { silver: 0, mushrooms: 25 }, } } } diff --git a/src/gamestate/event.rs b/src/gamestate/event.rs index 54d895d..a58a499 100644 --- a/src/gamestate/event.rs +++ b/src/gamestate/event.rs @@ -87,18 +87,12 @@ impl EventStatus { 3 => SpecialEventType::DrivingDungeon, 4 => SpecialEventType::TravelingCircus, 6 => SpecialEventType::WorldBoss( - data.cfpget(1, "world boss theme", |a| a)? - .unwrap_or_default(), + data.cfpget(1, "world boss theme", |a| a)?.unwrap_or_default(), ), _ => SpecialEventType::Unknown, }; - Ok(Self { - typ, - start, - end, - extra_end, - }) + Ok(Self { typ, start, end, extra_end }) } } @@ -420,10 +414,8 @@ impl WorldBossCatapult { let mut upgrades: [Option; 4] = Default::default(); - for (chunk, upgrade) in data - .skip(1, "wb catapult")? - .chunks_exact(4) - .zip(&mut upgrades) + for (chunk, upgrade) in + data.skip(1, "wb catapult")?.chunks_exact(4).zip(&mut upgrades) { if chunk.iter().all(|a| *a == 0) { continue; diff --git a/src/gamestate/guild.rs b/src/gamestate/guild.rs index 0c0dff5..2ad3f11 100644 --- a/src/gamestate/guild.rs +++ b/src/gamestate/guild.rs @@ -173,11 +173,7 @@ impl ChatMessage { let (name, msg) = rest.split_once(':')?; let msg = from_sf_string(msg.trim_start_matches(['§', ' '])); let time = NaiveTime::parse_from_str(time, "%H:%M").ok()?; - Some(ChatMessage { - user: name.to_string(), - time, - message: msg, - }) + Some(ChatMessage { user: name.to_string(), time, message: msg }) }) .collect() } @@ -196,8 +192,7 @@ impl Guild { let member_count = data.csiget(3, "member count", 0)?; self.member_count = member_count; - self.members - .resize_with(member_count as usize, Default::default); + self.members.resize_with(member_count as usize, Default::default); for (offset, member) in self.members.iter_mut().enumerate() { member.battles_joined = @@ -273,10 +268,8 @@ impl Guild { } pub(crate) fn update_member_names(&mut self, val: &str) { - let names: Vec<_> = val - .split(',') - .map(std::string::ToString::to_string) - .collect(); + let names: Vec<_> = + val.split(',').map(std::string::ToString::to_string).collect(); self.members.resize_with(names.len(), Default::default); for (member, name) in self.members.iter_mut().zip(names) { member.name = name; @@ -284,11 +277,8 @@ impl Guild { } pub(crate) fn update_group_knights(&mut self, val: &str) { - let data: Vec = val - .trim_end_matches(',') - .split(',') - .flat_map(str::parse) - .collect(); + let data: Vec = + val.trim_end_matches(',').split(',').flat_map(str::parse).collect(); self.members.resize_with(data.len(), Default::default); for (member, count) in self.members.iter_mut().zip(data) { @@ -390,9 +380,7 @@ impl Guild { self.fightable_guilds.push(FightableGuild { id: entries[offset].parse().unwrap_or_default(), name: from_sf_string(entries[offset + 1]), - emblem: Emblem { - raw: entries[offset + 2].to_string(), - }, + emblem: Emblem { raw: entries[offset + 2].to_string() }, number_of_members: entries[offset + 3] .parse() .unwrap_or_default(), diff --git a/src/gamestate/items.rs b/src/gamestate/items.rs index 7e2b6f4..5520da1 100644 --- a/src/gamestate/items.rs +++ b/src/gamestate/items.rs @@ -140,10 +140,7 @@ impl std::fmt::Display for PlayerItemPosition { impl From for ItemPosition { fn from(value: PlayerItemPosition) -> Self { - Self { - place: value.place.item_position(), - position: value.position, - } + Self { place: value.place.item_position(), position: value.position } } } @@ -163,10 +160,7 @@ impl From for ItemPosition { impl From for ItemPosition { fn from(value: ShopPosition) -> Self { - Self { - place: value.typ.into(), - position: value.pos, - } + Self { place: value.typ.into(), position: value.pos } } } @@ -182,19 +176,13 @@ impl From for ItemPlace { impl From for PlayerItemPosition { fn from(value: BagPosition) -> Self { let p = value.inventory_pos(); - Self { - place: p.0.player_item_position(), - position: p.1, - } + Self { place: p.0.player_item_position(), position: p.1 } } } impl From for PlayerItemPosition { fn from(value: EquipmentSlot) -> Self { - Self { - place: PlayerItemPlace::Equipment, - position: value as usize - 1, - } + Self { place: PlayerItemPlace::Equipment, position: value as usize - 1 } } } @@ -381,10 +369,9 @@ impl Item { let mut attribute_val = f64::from(*self.attributes.values().max().unwrap_or(&0)); let item_stats = self.attributes.values().filter(|a| **a > 0).count(); - let is_scout_or_mage_weapon = self - .class - .is_some_and(|a| a == Class::Scout || a == Class::Mage) - && self.typ.is_weapon(); + let is_scout_or_mage_weapon = + self.class.is_some_and(|a| a == Class::Scout || a == Class::Mage) + && self.typ.is_weapon(); if self.price != 0 { for _ in 0..self.upgrade_count { @@ -434,10 +421,7 @@ impl Item { metal_result *= 2; arcane_result *= 2; } - BlacksmithPayment { - metal: metal_result * 2, - arcane: arcane_result * 2, - } + BlacksmithPayment { metal: metal_result * 2, arcane: arcane_result * 2 } } /// Calculates the amount of metal & arcane it would cost to upgrade this @@ -455,10 +439,9 @@ impl Item { } let item_stats = self.attributes.values().filter(|a| **a > 0).count(); - let is_scout_or_mage_weapon = self - .class - .is_some_and(|a| a == Class::Scout || a == Class::Mage) - && self.typ.is_weapon(); + let is_scout_or_mage_weapon = + self.class.is_some_and(|a| a == Class::Scout || a == Class::Mage) + && self.typ.is_weapon(); // Highest attribue is the base price let mut price = @@ -1022,8 +1005,7 @@ impl ItemType { /// Checks, if this item type can be enchanted #[must_use] pub fn is_enchantable(&self) -> bool { - self.equipment_slot() - .is_some_and(|e| e.enchantment().is_some()) + self.equipment_slot().is_some_and(|e| e.enchantment().is_some()) } pub(crate) fn parse( @@ -1061,15 +1043,13 @@ impl ItemType { return unknown_item("unique sub ident"); }; match id { - 1..=11 | 17 | 19 | 22 | 69 | 70 => ItemType::DungeonKey { - id, - shadow_key: false, - }, + 1..=11 | 17 | 19 | 22 | 69 | 70 => { + ItemType::DungeonKey { id, shadow_key: false } + } 20 => ItemType::ToiletKey, - 51..=64 | 67..=68 => ItemType::DungeonKey { - id, - shadow_key: true, - }, + 51..=64 | 67..=68 => { + ItemType::DungeonKey { id, shadow_key: true } + } 10000 => ItemType::EpicItemBag, piece => ItemType::Shard { piece }, } @@ -1112,10 +1092,7 @@ impl ItemType { let Some(typ) = GemType::parse(sub_ident, gem_value) else { return unknown_item("gem type"); }; - let gem = Gem { - typ, - value: gem_value, - }; + let gem = Gem { typ, value: gem_value }; ItemType::Gem(gem) } 16 => { diff --git a/src/gamestate/legendary_dungeon.rs b/src/gamestate/legendary_dungeon.rs index efb8c1f..c87c90f 100644 --- a/src/gamestate/legendary_dungeon.rs +++ b/src/gamestate/legendary_dungeon.rs @@ -69,10 +69,9 @@ impl LegendaryDungeonEvent { match active.stage { Stage::NotEntered => Status::NotEntered(theme), - Stage::DoorSelect => Status::DoorSelect { - dungeon: active, - doors: &active.doors, - }, + Stage::DoorSelect => { + Status::DoorSelect { dungeon: active, doors: &active.doors } + } Stage::RoomSpecial if active.room_type == RoomType::BossRoom => { Status::PickGem { dungeon: active, @@ -742,12 +741,7 @@ impl DungeonEffect { let max_uses: u32 = max_uses.try_into().unwrap_or(0); let strength: u32 = strength.try_into().unwrap_or(0); - Some(DungeonEffect { - typ, - remaining_uses, - max_uses, - strength, - }) + Some(DungeonEffect { typ, remaining_uses, max_uses, strength }) } } diff --git a/src/gamestate/mod.rs b/src/gamestate/mod.rs index acde1f3..3198288 100644 --- a/src/gamestate/mod.rs +++ b/src/gamestate/mod.rs @@ -134,10 +134,7 @@ impl Default for Shop { full_model_id: 0, }); - Self { - items, - typ: ShopType::Magic, - } + Self { items, typ: ShopType::Magic } } } @@ -325,10 +322,8 @@ impl GameState { pub(crate) fn updatete_relation_list(&mut self, val: &str) { self.character.relations.clear(); - for entry in val - .trim_end_matches(';') - .split(';') - .filter(|a| !a.is_empty()) + for entry in + val.trim_end_matches(';').split(';').filter(|a| !a.is_empty()) { let mut parts = entry.split(','); let ( @@ -388,14 +383,10 @@ impl GameState { bs.metal = res.csiget(9, "bs metal", 0)?; bs.arcane = res.csiget(10, "bs arcane", 0)?; let fortress = self.fortress.get_or_insert_with(Default::default); - fortress - .resources - .get_mut(FortressResourceType::Wood) - .current = res.csiget(5, "saved wood ", 0)?; - fortress - .resources - .get_mut(FortressResourceType::Stone) - .current = res.csiget(7, "saved stone", 0)?; + fortress.resources.get_mut(FortressResourceType::Wood).current = + res.csiget(5, "saved wood ", 0)?; + fortress.resources.get_mut(FortressResourceType::Stone).current = + res.csiget(7, "saved stone", 0)?; let pets = self.pets.get_or_insert_with(Default::default); for (e_pos, element) in HabitatType::iter().enumerate() { @@ -403,9 +394,8 @@ impl GameState { res.csiget(12 + e_pos, "fruits", 0)?; } - self.underworld - .get_or_insert_with(Default::default) - .souls_current = res.csiget(11, "uu souls saved", 0)?; + self.underworld.get_or_insert_with(Default::default).souls_current = + res.csiget(11, "uu souls saved", 0)?; Ok(()) } @@ -869,9 +859,8 @@ impl GameState { val.into("max pet lvl")?; } "otherdescription" => { - other_player - .get_or_insert_with(Default::default) - .description = from_sf_string(val.as_str()); + other_player.get_or_insert_with(Default::default).description = + from_sf_string(val.as_str()); } "otherplayergroupname" => { let guild = diff --git a/src/gamestate/rewards.rs b/src/gamestate/rewards.rs index ad8b2e4..56a187d 100644 --- a/src/gamestate/rewards.rs +++ b/src/gamestate/rewards.rs @@ -301,10 +301,7 @@ macro_rules! impl_tasks { /// Returns all uncompleted tasks #[must_use] pub fn get_uncompleted(&self) -> Vec<&Task> { - self.tasks - .iter() - .filter(|task| !task.is_completed()) - .collect() + self.tasks.iter().filter(|task| !task.is_completed()).collect() } /// Checks if the chest at the given index can be opened @@ -767,11 +764,7 @@ impl RewardChest { let data = data.skip(3 + pos * 2, "rchest rewards")?; rewards.push(Reward::parse(data)?); } - Ok(RewardChest { - opened, - required_points, - rewards, - }) + Ok(RewardChest { opened, required_points, rewards }) } } diff --git a/src/gamestate/social.rs b/src/gamestate/social.rs index c24b2eb..49fb0b7 100644 --- a/src/gamestate/social.rs +++ b/src/gamestate/social.rs @@ -182,15 +182,7 @@ impl HallOfFamePlayer { let raw_flag = data.get(6).copied().unwrap_or_default(); let flag = Flag::parse(raw_flag); - Ok(HallOfFamePlayer { - rank, - name, - guild, - level, - honor, - class, - flag, - }) + Ok(HallOfFamePlayer { rank, name, guild, level, honor, class, flag }) } } @@ -245,14 +237,7 @@ impl HallOfFamePets { let honor = data.cfsuget(4, "hof pets fame")?; let unknown = data.cfsuget(5, "hof pets uk")?; - Ok(HallOfFamePets { - name, - rank, - guild, - collected, - honor, - unknown, - }) + Ok(HallOfFamePets { name, rank, guild, collected, honor, unknown }) } } @@ -266,13 +251,7 @@ impl HallOfFameFortress { let upgrade = data.cfsuget(3, "hof ft collected")?; let honor = data.cfsuget(4, "hof ft fame")?; - Ok(HallOfFameFortress { - name, - rank, - guild, - upgrade, - honor, - }) + Ok(HallOfFameFortress { name, rank, guild, upgrade, honor }) } } @@ -287,14 +266,7 @@ impl HallOfFameUnderworld { let honor = data.cfsuget(4, "hof ft fame")?; let unknown = data.cfsuget(5, "hof pets uk")?; - Ok(HallOfFameUnderworld { - rank, - name, - guild, - upgrade, - honor, - unknown, - }) + Ok(HallOfFameUnderworld { rank, name, guild, upgrade, honor, unknown }) } } diff --git a/src/gamestate/tavern.rs b/src/gamestate/tavern.rs index e38a652..c8cf8d4 100644 --- a/src/gamestate/tavern.rs +++ b/src/gamestate/tavern.rs @@ -208,9 +208,8 @@ impl Quest { pub(crate) fn update(&mut self, data: &[i64]) -> Result<(), SFError> { // NOTE: I think [0], [1] was just flavor text self.monster_id = data.csimget(2, "quest monster id", 0, |a| -a)?; - self.location_id = data - .cfpget(3, "quest location id", |a| a)? - .unwrap_or_default(); + self.location_id = + data.cfpget(3, "quest location id", |a| a)?.unwrap_or_default(); self.base_length = data.csiget(4, "quest length", 100_000)?; self.base_experience = data.csiget(5, "quest xp", 0)?; self.base_silver = data.csiget(6, "quest silver", 0)?; diff --git a/src/gamestate/unlockables.rs b/src/gamestate/unlockables.rs index 6938f9c..58b5842 100644 --- a/src/gamestate/unlockables.rs +++ b/src/gamestate/unlockables.rs @@ -589,10 +589,8 @@ impl Pets { }) .sum::(); - let habitat_idx = habitat_pets - .iter() - .position(|a| a.id == pet.id) - .unwrap_or(0); + let habitat_idx = + habitat_pets.iter().position(|a| a.id == pet.id).unwrap_or(0); let base_stat = PET_BASE_STAT_ARRAY.get(habitat_idx).copied().unwrap_or(0); @@ -1097,12 +1095,7 @@ fn parse_scrapbook_item(item_idx: i64) -> Option { () => relative_pos / 5, } as u16; - return Some(EquipmentIdent { - class, - typ, - model_id, - color, - }); + return Some(EquipmentIdent { class, typ, model_id, color }); } None } diff --git a/src/misc.rs b/src/misc.rs index 7601e56..89e07b5 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -164,13 +164,11 @@ fn raw_cget( pos: usize, name: &'static str, ) -> Result { - val.get(pos) - .copied() - .ok_or_else(|| SFError::TooShortResponse { - name, - pos, - array: format!("{val:?}"), - }) + val.get(pos).copied().ok_or_else(|| SFError::TooShortResponse { + name, + pos, + array: format!("{val:?}"), + }) } pub(crate) trait CGet { @@ -246,8 +244,7 @@ impl> CCGet for [T] { fn ciget(&self, pos: usize, name: &'static str) -> Result { let raw = raw_cget(self, pos, name)?; - raw.try_into() - .map_err(|_| SFError::ParsingError(name, raw.to_string())) + raw.try_into().map_err(|_| SFError::ParsingError(name, raw.to_string())) } fn cimget( @@ -258,8 +255,7 @@ impl> CCGet for [T] { ) -> Result { let raw = raw_cget(self, pos, name)?; let raw = fun(raw); - raw.try_into() - .map_err(|_| SFError::ParsingError(name, raw.to_string())) + raw.try_into().map_err(|_| SFError::ParsingError(name, raw.to_string())) } } diff --git a/src/session.rs b/src/session.rs index d81cbc1..ecf9ef7 100644 --- a/src/session.rs +++ b/src/session.rs @@ -89,10 +89,7 @@ impl Session { pw_hash: PWHash, server: ServerConnection, ) -> Self { - let ld = LoginData::Basic { - username: username.to_string(), - pw_hash, - }; + let ld = LoginData::Basic { username: username.to_string(), pw_hash }; Self::new_full(ld, server.client, server.options, server.url) } @@ -159,11 +156,7 @@ impl Session { login_count: self.login_count, }, #[cfg(feature = "sso")] - LoginData::SSO { - character_id, - session, - .. - } => Command::SSOLogin { + LoginData::SSO { character_id, session, .. } => Command::SSOLogin { uuid: session.uuid, character_id, bearer_token: session.bearer_token, @@ -262,10 +255,8 @@ impl Session { })?; #[allow(unused_mut)] - let mut req = self - .client - .get(&url) - .header(REFERER, &self.server_url.to_string()); + let mut req = + self.client.get(&url).header(REFERER, &self.server_url.to_string()); #[cfg(feature = "sso")] if let LoginData::SSO { session, .. } = &self.login_data { @@ -388,10 +379,7 @@ impl Session { match &self.login_data { LoginData::Basic { username, .. } => username, #[cfg(feature = "sso")] - LoginData::SSO { - username: character_name, - .. - } => character_name, + LoginData::SSO { username: character_name, .. } => character_name, } } @@ -406,9 +394,7 @@ impl Session { /// credentials #[cfg(feature = "sso")] pub async fn renew_sso_creds(&mut self) -> Result<(), SFError> { - let LoginData::SSO { - account, session, .. - } = &mut self.login_data + let LoginData::SSO { account, session, .. } = &mut self.login_data else { return Err(SFError::InvalidRequest( "Can not renew sso credentials for a non-sso account", @@ -587,10 +573,7 @@ impl SimpleSession { let resp = session.login().await?; let gs = GameState::new(resp)?; Self::short_sleep().await; - Ok(Self { - session, - gamestate: Some(gs), - }) + Ok(Self { session, gamestate: Some(gs) }) } /// Creates new `SimpleSession`s, by logging in the S&S SSO account and @@ -614,10 +597,7 @@ impl SimpleSession { .await? .into_iter() .flatten() - .map(|a| Self { - session: a, - gamestate: None, - }) + .map(|a| Self { session: a, gamestate: None }) .collect()) } diff --git a/src/simulate/damage.rs b/src/simulate/damage.rs index 0dcd5ec..ed6b1d8 100644 --- a/src/simulate/damage.rs +++ b/src/simulate/damage.rs @@ -15,10 +15,7 @@ impl std::ops::Mul for DamageRange { type Output = DamageRange; fn mul(self, rhs: f64) -> DamageRange { - DamageRange { - min: self.min * rhs, - max: self.max * rhs, - } + DamageRange { min: self.min * rhs, max: self.max * rhs } } } diff --git a/src/simulate/fighter.rs b/src/simulate/fighter.rs index b3cff20..1e79dc4 100644 --- a/src/simulate/fighter.rs +++ b/src/simulate/fighter.rs @@ -805,10 +805,7 @@ impl InBattleFighter { true } - ClassData::Paladin { - stance, - initial_armor_reduction, - } => { + ClassData::Paladin { stance, initial_armor_reduction } => { let current_armor_reduction = match stance { Stance::Regular | Stance::Defensive => 1.0, Stance::Offensive => { @@ -835,9 +832,7 @@ impl InBattleFighter { *health -= actual_damage; *health <= 0.0 } - ClassData::BloodWeaver { - death_seal_active, .. - } => { + ClassData::BloodWeaver { death_seal_active, .. } => { let health = &mut self.health; *health -= damage; if *health > 0.0 { @@ -867,11 +862,7 @@ impl InBattleFighter { rng.i32(1..=100) > *block_chance } ClassData::Assassin { .. } | ClassData::Scout => rng.bool(), - ClassData::Druid { - is_in_bear_form, - has_just_dodged, - .. - } => { + ClassData::Druid { is_in_bear_form, has_just_dodged, .. } => { if !*is_in_bear_form && rng.u8(1..=100) <= 35 { // evade_chance hardcoded to 35 in original *has_just_dodged = true; @@ -892,10 +883,7 @@ impl InBattleFighter { *stance == Stance::Defensive || rng.u8(1..=100) > stance.block_chance() } - ClassData::PlagueDoctor { - poison_remaining_round, - .. - } => { + ClassData::PlagueDoctor { poison_remaining_round, .. } => { let chance = match poison_remaining_round { 3 => 65, 2 => 50, @@ -904,9 +892,7 @@ impl InBattleFighter { }; rng.u8(1..=100) > chance } - ClassData::BloodWeaver { - death_seal_active, .. - } => { + ClassData::BloodWeaver { death_seal_active, .. } => { if self.opponent_is_mage { return true; } @@ -1046,14 +1032,10 @@ impl ClassData { ClassData::BattleMage { fireball_dmg, .. } => { *fireball_dmg = calculate_fire_ball_damage(main, opponent); } - ClassData::Berserker { - frenzy_attacks: chain_attack_counter, - } => *chain_attack_counter = 0, - ClassData::Druid { - rage_crit_chance, - swoop_dmg_multi, - .. - } => { + ClassData::Berserker { frenzy_attacks: chain_attack_counter } => { + *chain_attack_counter = 0 + } + ClassData::Druid { rage_crit_chance, swoop_dmg_multi, .. } => { *rage_crit_chance = calculate_crit_chance(main, opponent, 0.75, 0.1); *swoop_dmg_multi = calculate_swoop_damage(main, opponent); @@ -1062,16 +1044,11 @@ impl ClassData { ClassData::Necromancer { damage_multi, .. } => { *damage_multi = calculate_damage_multiplier(main, opponent); } - ClassData::Paladin { - initial_armor_reduction, - .. - } => { + ClassData::Paladin { initial_armor_reduction, .. } => { *initial_armor_reduction = calculate_damage_reduction(opponent, main); } - ClassData::PlagueDoctor { - poison_dmg_multis, .. - } => { + ClassData::PlagueDoctor { poison_dmg_multis, .. } => { let base_dmg_multi = calculate_damage_multiplier(main, opponent); @@ -1085,10 +1062,7 @@ impl ClassData { ]; // TODO: Do we reset poison round? } - ClassData::BloodWeaver { - dot_remaining_rounds, - .. - } => { + ClassData::BloodWeaver { dot_remaining_rounds, .. } => { *dot_remaining_rounds = 0; } } @@ -1102,9 +1076,9 @@ impl ClassData { Class::Warrior => ClassData::Warrior { block_chance: 25 }, Class::Mage => ClassData::Mage, Class::Scout => ClassData::Scout, - Class::Assassin => ClassData::Assassin { - secondary_damage: DamageRange::default(), - }, + Class::Assassin => { + ClassData::Assassin { secondary_damage: DamageRange::default() } + } Class::BattleMage => ClassData::BattleMage { fireball_dmg: 0.0 }, Class::Berserker => ClassData::Berserker { frenzy_attacks: 0 }, Class::DemonHunter => ClassData::DemonHunter { revive_count: 0 }, diff --git a/src/simulate/mod.rs b/src/simulate/mod.rs index 98c85eb..f30ae03 100644 --- a/src/simulate/mod.rs +++ b/src/simulate/mod.rs @@ -122,10 +122,7 @@ fn simulate_fight( } let win_ratio = f64::from(won_fights) / f64::from(iterations); - FightSimulationResult { - win_ratio, - won_fights, - } + FightSimulationResult { win_ratio, won_fights } } struct InBattleCache(Vec<((FighterIdent, FighterIdent), InBattleFighter)>); @@ -284,11 +281,7 @@ fn perform_fight<'a>( } fn outcome_from_bool(result: bool) -> FightOutcome { - if result { - FightOutcome::LeftSideWin - } else { - FightOutcome::RightSideWin - } + if result { FightOutcome::LeftSideWin } else { FightOutcome::RightSideWin } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/src/simulate/upgradeable.rs b/src/simulate/upgradeable.rs index ece8b17..2fd1492 100644 --- a/src/simulate/upgradeable.rs +++ b/src/simulate/upgradeable.rs @@ -78,9 +78,7 @@ impl UpgradeableFighter { potion: Potion, slot: usize, ) -> Option { - self.active_potions - .get_mut(slot) - .and_then(|a| a.replace(potion)) + self.active_potions.get_mut(slot).and_then(|a| a.replace(potion)) } /// Removes the potion at the provided slot and returns the old potion, if @@ -205,11 +203,8 @@ impl UpgradeableFighter { for (k, v) in &mut total { let class_bonus = (f64::from(*v) * class_bonus).trunc() as u32; *v += class_bonus + self.attribute_basis.get(k); - if let Some(potion) = self - .active_potions - .iter() - .flatten() - .find(|a| a.typ == k.into()) + if let Some(potion) = + self.active_potions.iter().flatten().find(|a| a.typ == k.into()) { *v += (f64::from(*v) * potion.size.effect()) as u32; } @@ -245,12 +240,8 @@ impl UpgradeableFighter { total += portal_bonus; let mut rune_multi = 0; - for rune in self - .equipment - .0 - .iter() - .flat_map(|a| a.1) - .filter_map(|a| a.rune) + for rune in + self.equipment.0.iter().flat_map(|a| a.1).filter_map(|a| a.rune) { if rune.typ == RuneType::ExtraHitPoints { rune_multi += u32::from(rune.value); @@ -353,9 +344,6 @@ impl PlayerFighterSquad { companions = Some(EnumMap::from_array(res)); } - PlayerFighterSquad { - character, - companions, - } + PlayerFighterSquad { character, companions } } } diff --git a/src/sso.rs b/src/sso.rs index 63c2ff4..4799df3 100644 --- a/src/sso.rs +++ b/src/sso.rs @@ -44,10 +44,7 @@ pub struct AccountSession { #[derive(Debug)] enum APIRequest { Get, - Post { - parameters: Vec<&'static str>, - form_data: HashMap, - }, + Post { parameters: Vec<&'static str>, form_data: HashMap }, } #[derive(Debug, Default, Serialize, Deserialize)] @@ -268,10 +265,7 @@ async fn send_api_request( let mut request = match method { APIRequest::Get => client.get(url.as_str()), - APIRequest::Post { - parameters, - form_data, - } => { + APIRequest::Post { parameters, form_data } => { url.set_query(Some(¶meters.join("&"))); client.post(url.as_str()).form(&form_data) } @@ -524,10 +518,7 @@ impl SSOAuth { Ok(AuthResponse::Success(SFAccount { username, client: self.client, - session: AccountSession { - uuid, - bearer_token: access_token, - }, + session: AccountSession { uuid, bearer_token: access_token }, options: self.options, auth: match self.provider { SSOProvider::Google => SSOAuthData::Google, @@ -574,12 +565,6 @@ impl SSOAuth { .ok_or(SFError::ConnectionError)?; let auth_id = val_to_string(&resp["id"]).ok_or(SFError::ConnectionError)?; - Ok(Self { - client, - options, - auth_url, - auth_id, - provider, - }) + Ok(Self { client, options, auth_url, auth_id, provider }) } } diff --git a/tests/battle_simulation.rs b/tests/battle_simulation.rs index d2a42ce..5faff23 100644 --- a/tests/battle_simulation.rs +++ b/tests/battle_simulation.rs @@ -32,9 +32,7 @@ fn test_simulate_battle( #[case] finished: u16, #[case] expected_wr: f64, ) { - let progress = DungeonProgress::Open { - finished: finished - 1, - }; + let progress = DungeonProgress::Open { finished: finished - 1 }; let monster = Fighter::from(get_dungeon_monster(dungeon, progress).unwrap()); @@ -122,10 +120,7 @@ fn init_squad(class: Class, init_companions: bool) -> PlayerFighterSquad { belt.type_specific_val = armor; } - PlayerFighterSquad { - character: account, - companions, - } + PlayerFighterSquad { character: account, companions } } fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { @@ -148,11 +143,8 @@ fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { let mut equipment = Equipment::default(); - equipment.0[EquipmentSlot::Hat] = Some(create_rune_item( - ItemType::Hat, - RuneType::FireResistance, - 75, - )); + equipment.0[EquipmentSlot::Hat] = + Some(create_rune_item(ItemType::Hat, RuneType::FireResistance, 75)); equipment.0[EquipmentSlot::BreastPlate] = Some(create_rune_item( ItemType::BreastPlate, RuneType::ColdResistence, @@ -176,10 +168,7 @@ fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { let weapon = Item { typ: ItemType::Weapon { min_dmg, max_dmg }, - rune: Some(Rune { - typ: RuneType::FireDamage, - value: 60, - }), + rune: Some(Rune { typ: RuneType::FireDamage, value: 60 }), enchantment: Some(Enchantment::SwordOfVengeance), // Defaults model_id: 1, @@ -229,10 +218,7 @@ fn create_fighter(class: Class, is_companion: bool) -> UpgradeableFighter { fn create_rune_item(typ: ItemType, rune_typ: RuneType, value: u8) -> Item { Item { typ, - rune: Some(Rune { - typ: rune_typ, - value, - }), + rune: Some(Rune { typ: rune_typ, value }), // Defaults model_id: 1, price: 0,