Add loop to wait for recently logged out characters

This commit is contained in:
Jeff 2024-07-13 04:37:31 -04:00
parent 29e3178eba
commit 86a579714e
2 changed files with 22 additions and 9 deletions

View File

@ -54,7 +54,7 @@ podman run \
--detach \
--name trade_bot \
--secret secrets.toml \
-v ./config/:/root/config/ \
--volume ./config/:/root/config/ \
--env CONFIG=/root/config/config.toml \
--env SECRETS=/run/secrets/secrets.toml \
--env RUST_LOG=trade_bot \

View File

@ -17,8 +17,12 @@ use tokio::runtime::Runtime;
use vek::Quaternion;
use veloren_client::{addr::ConnectionArgs, Client, Event as VelorenEvent, SiteInfoRich, WorldExt};
use veloren_common::{
character::Character,
clock::Clock,
comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos},
comp::{
invite::InviteKind, item::ItemDefinitionIdOwned, CharacterState, ChatType,
ControllerInputs, Health, Ori, Pos,
},
outcome::Outcome,
time::DayPeriod,
trade::{PendingTrade, TradeAction, TradeResult},
@ -96,13 +100,22 @@ impl Bot {
.id
.ok_or("Failed to get character ID")?;
client.request_character(
character_id,
ViewDistances {
terrain: 4,
entity: 4,
},
);
// This loop waits and retries requesting the character in the case that the character has
// logged out to recently.
while client.position().is_none() {
client.request_character(
character_id,
ViewDistances {
terrain: 4,
entity: 4,
},
);
client
.tick(ControllerInputs::default(), clock.dt())
.map_err(|error| format!("{error:?}"))?;
clock.tick();
}
let now = Instant::now();