From a8cbd708847b6c960555a9f287fea176f086f834 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 8 Jul 2024 13:59:35 -0400 Subject: [PATCH] Use lantern only at night --- src/bot.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 4d23f78..7f914ca 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -11,6 +11,7 @@ use veloren_common::{ clock::Clock, comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos}, outcome::Outcome, + time::DayPeriod, trade::{PendingTrade, TradeAction}, uid::Uid, ViewDistances, @@ -113,10 +114,7 @@ impl Bot { self.client.respawn(); } - if !self.client.is_lantern_enabled() { - self.client.enable_lantern(); - } - + self.handle_lantern(); self.handle_position_and_orientation()?; if let Some((_, trade, _)) = self.client.pending_trade() { @@ -193,6 +191,23 @@ impl Bot { Ok(()) } + fn handle_lantern(&mut self) { + let day_period = self.client.state().get_day_period(); + + match day_period { + DayPeriod::Night => { + if !self.client.is_lantern_enabled() { + self.client.enable_lantern(); + } + } + DayPeriod::Morning | DayPeriod::Noon | DayPeriod::Evening => { + if self.client.is_lantern_enabled() { + self.client.disable_lantern(); + } + } + } + } + fn handle_trade(&mut self, trade: PendingTrade) -> Result<(), String> { let my_offer_index = trade .which_party(self.client.uid().ok_or("Failed to get uid")?) @@ -490,10 +505,13 @@ impl Bot { } fn handle_position_and_orientation(&mut self) -> Result<(), String> { - let current_position = self.client.position(); - - if current_position == Some(self.position.into()) { - return Ok(()); + match self.client.position() { + Some(current_position) => { + if current_position == self.position.into() { + return Ok(()); + } + } + None => return Ok(()), } let entity = self.client.entity().clone();