Tweak and clean up
This commit is contained in:
parent
5ebf582538
commit
7c8267b598
48
src/bot.rs
48
src/bot.rs
@ -20,22 +20,21 @@ use veloren_common_net::sync::WorldSyncExt;
|
|||||||
|
|
||||||
const COINS: &str = "common.items.utility.coins";
|
const COINS: &str = "common.items.utility.coins";
|
||||||
|
|
||||||
enum TradeMode {
|
|
||||||
Take,
|
|
||||||
Trade,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Bot {
|
pub struct Bot {
|
||||||
position: [f32; 3],
|
position: [f32; 3],
|
||||||
orientation: String,
|
orientation: String,
|
||||||
|
|
||||||
client: Client,
|
client: Client,
|
||||||
clock: Clock,
|
clock: Clock,
|
||||||
|
|
||||||
buy_prices: HashMap<String, u32>,
|
buy_prices: HashMap<String, u32>,
|
||||||
sell_prices: HashMap<String, u32>,
|
sell_prices: HashMap<String, u32>,
|
||||||
|
trade_mode: TradeMode,
|
||||||
|
|
||||||
|
is_player_notified: bool,
|
||||||
last_action: Instant,
|
last_action: Instant,
|
||||||
last_announcement: Instant,
|
last_announcement: Instant,
|
||||||
is_player_notified: bool,
|
last_ouch: Instant,
|
||||||
trade_mode: TradeMode,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bot {
|
impl Bot {
|
||||||
@ -50,7 +49,8 @@ impl Bot {
|
|||||||
log::info!("Connecting to veloren");
|
log::info!("Connecting to veloren");
|
||||||
|
|
||||||
let client = connect_to_veloren(username, password)?;
|
let client = connect_to_veloren(username, password)?;
|
||||||
let clock = Clock::new(Duration::from_secs_f64(1.0 / 60.0));
|
let clock = Clock::new(Duration::from_secs_f64(1.0 / 30.0));
|
||||||
|
let now = Instant::now();
|
||||||
|
|
||||||
Ok(Bot {
|
Ok(Bot {
|
||||||
position,
|
position,
|
||||||
@ -59,10 +59,11 @@ impl Bot {
|
|||||||
clock,
|
clock,
|
||||||
buy_prices,
|
buy_prices,
|
||||||
sell_prices,
|
sell_prices,
|
||||||
last_action: Instant::now(),
|
|
||||||
last_announcement: Instant::now(),
|
|
||||||
is_player_notified: false,
|
|
||||||
trade_mode: TradeMode::Trade,
|
trade_mode: TradeMode::Trade,
|
||||||
|
is_player_notified: false,
|
||||||
|
last_action: now,
|
||||||
|
last_announcement: now,
|
||||||
|
last_ouch: now,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,15 +130,15 @@ impl Bot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.last_action = Instant::now();
|
self.last_action = Instant::now();
|
||||||
}
|
|
||||||
|
|
||||||
if self.last_announcement.elapsed() > Duration::from_secs(600) {
|
if self.last_announcement.elapsed() > Duration::from_secs(1200) {
|
||||||
self.client.send_command(
|
self.client.send_command(
|
||||||
"region".to_string(),
|
"region".to_string(),
|
||||||
vec!["I'm a bot. Trade with me or say 'prices' to see my offers.".to_string()],
|
vec!["I'm a bot. Trade with me or say 'prices' to see my offers.".to_string()],
|
||||||
);
|
);
|
||||||
|
|
||||||
self.last_announcement = Instant::now();
|
self.last_announcement = Instant::now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.clock.tick();
|
self.clock.tick();
|
||||||
@ -172,9 +173,11 @@ impl Bot {
|
|||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
if let Some(uid) = self.client.uid() {
|
if let Some(uid) = self.client.uid() {
|
||||||
if uid == target {
|
if uid == target && self.last_ouch.elapsed() > Duration::from_secs(1) {
|
||||||
self.client
|
self.client
|
||||||
.send_command("say".to_string(), vec!["Ouch!".to_string()])
|
.send_command("say".to_string(), vec!["Ouch!".to_string()]);
|
||||||
|
|
||||||
|
self.last_ouch = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,6 +544,11 @@ impl Bot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TradeMode {
|
||||||
|
Take,
|
||||||
|
Trade,
|
||||||
|
}
|
||||||
|
|
||||||
fn connect_to_veloren(username: &str, password: &str) -> Result<Client, String> {
|
fn connect_to_veloren(username: &str, password: &str) -> Result<Client, String> {
|
||||||
let runtime = Arc::new(Runtime::new().unwrap());
|
let runtime = Arc::new(Runtime::new().unwrap());
|
||||||
let runtime2 = Arc::clone(&runtime);
|
let runtime2 = Arc::clone(&runtime);
|
||||||
|
Loading…
Reference in New Issue
Block a user