Add minor optimization

This commit is contained in:
Jeff 2024-07-16 11:36:11 -04:00
parent 37e4c5c8d7
commit c52613fa20
2 changed files with 22 additions and 17 deletions

View File

@ -15,7 +15,7 @@ you are familiar with Rust.
intended to be a fun addition to the game that can help players trade items with each other.
- This project may have bugs. You are encouraged to report them to the author but the author takes
no responsibility for any lost items. **No such incidents have been reported so far.**
- This program **handles your password securely** and does nothing with it expect connecting to the
- This program **handles your password securely** and does nothing with it except connecting to the
veloren server during launch. However, third-party video game software is often infected with
malware. You should **review the source code** or ask someone you trust to do so for you.
- You are welcome to make changes to the code or fork the project. The author is open to

View File

@ -443,25 +443,30 @@ impl Bot {
);
if let Some(announcement) = &self.announcement {
let location = self
.client
.sites()
.into_iter()
.find_map(|(_, SiteInfoRich { site, .. })| {
let x_difference = self.position.0[0] - site.wpos[0] as f32;
let y_difference = self.position.0[1] - site.wpos[1] as f32;
let announcement = if announcement.contains("{location}") {
let location = self
.client
.sites()
.into_iter()
.find_map(|(_, SiteInfoRich { site, .. })| {
let x_difference = self.position.0[0] - site.wpos[0] as f32;
let y_difference = self.position.0[1] - site.wpos[1] as f32;
if x_difference.abs() < 100.0 && y_difference.abs() < 100.0 {
site.name.clone()
} else {
None
}
})
.unwrap_or(format!("{:?}", self.position));
let interpolated_announcement = announcement.replace("{location}", &location);
if x_difference.abs() < 100.0 && y_difference.abs() < 100.0 {
site.name.clone()
} else {
None
}
})
.unwrap_or(format!("{:?}", self.position));
announcement.replace("{location}", &location)
} else {
announcement.clone()
};
self.client
.send_command("world".to_string(), vec![interpolated_announcement]);
.send_command("world".to_string(), vec![announcement]);
}
Ok(())