From ed3d5c3f32a33fc71fca30037bbc1a7d5191fed2 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 11 Jul 2024 14:30:50 -0400 Subject: [PATCH] Fix sorting multiple times --- src/bot.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 0503f9a..6b8defc 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -4,16 +4,12 @@ use std::{ time::{Duration, Instant}, }; -use rand::{thread_rng, Rng}; use tokio::runtime::Runtime; use vek::Quaternion; use veloren_client::{addr::ConnectionArgs, Client, Event as VelorenEvent, WorldExt}; use veloren_common::{ clock::Clock, - comp::{ - invite::InviteKind, item::ItemDefinitionIdOwned, Agent, Anchor, ChatType, ControllerInputs, - Ori, Pos, - }, + comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos}, outcome::Outcome, time::DayPeriod, trade::{PendingTrade, TradeAction, TradeResult}, @@ -22,13 +18,6 @@ use veloren_common::{ DamageSource, ViewDistances, }; use veloren_common_net::sync::WorldSyncExt; -use veloren_world::{ - civ::WorldCivStage, - sim::Location, - site::{Settlement, SiteKindMeta}, - site2::Site, - SettlementKindMeta, -}; const COINS: &str = "common.items.utility.coins"; @@ -50,6 +39,7 @@ pub struct Bot { last_action: Instant, last_announcement: Instant, last_ouch: Instant, + sort_count: u8, } impl Bot { @@ -114,6 +104,7 @@ impl Bot { last_action: now, last_announcement: now, last_ouch: now, + sort_count: 0, }) } @@ -136,6 +127,12 @@ impl Bot { self.handle_position_and_orientation()?; self.handle_lantern(); + if self.sort_count > 0 { + self.client.sort_inventory(); + + self.sort_count -= 1; + } + if let Some((_, trade, _)) = self.client.pending_trade() { match self.trade_mode { TradeMode::AdminAccess => { @@ -205,9 +202,9 @@ impl Bot { log::debug!("Sorting inventory {sort_count} times"); - for _ in 0..sort_count { - self.client.sort_inventory(); - } + self.client.sort_inventory(); + + self.sort_count = sort_count.saturating_sub(1); } else { log::debug!("Sorting inventory"); self.client.sort_inventory();