Add minor optimization
This commit is contained in:
parent
37e4c5c8d7
commit
c52613fa20
@ -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.
|
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
|
- 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.**
|
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
|
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.
|
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
|
- You are welcome to make changes to the code or fork the project. The author is open to
|
||||||
|
37
src/bot.rs
37
src/bot.rs
@ -443,25 +443,30 @@ impl Bot {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if let Some(announcement) = &self.announcement {
|
if let Some(announcement) = &self.announcement {
|
||||||
let location = self
|
let announcement = if announcement.contains("{location}") {
|
||||||
.client
|
let location = self
|
||||||
.sites()
|
.client
|
||||||
.into_iter()
|
.sites()
|
||||||
.find_map(|(_, SiteInfoRich { site, .. })| {
|
.into_iter()
|
||||||
let x_difference = self.position.0[0] - site.wpos[0] as f32;
|
.find_map(|(_, SiteInfoRich { site, .. })| {
|
||||||
let y_difference = self.position.0[1] - site.wpos[1] as f32;
|
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 {
|
if x_difference.abs() < 100.0 && y_difference.abs() < 100.0 {
|
||||||
site.name.clone()
|
site.name.clone()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or(format!("{:?}", self.position));
|
.unwrap_or(format!("{:?}", self.position));
|
||||||
let interpolated_announcement = announcement.replace("{location}", &location);
|
|
||||||
|
announcement.replace("{location}", &location)
|
||||||
|
} else {
|
||||||
|
announcement.clone()
|
||||||
|
};
|
||||||
|
|
||||||
self.client
|
self.client
|
||||||
.send_command("world".to_string(), vec![interpolated_announcement]);
|
.send_command("world".to_string(), vec![announcement]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user