diff options
Diffstat (limited to 'server/bot/src/algos/customer.rs')
-rw-r--r-- | server/bot/src/algos/customer.rs | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index 6a45e379..0c38c79d 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -21,7 +21,8 @@ use crate::{ }; use hurrycurry_client_lib::Game; use hurrycurry_protocol::{ - glam::IVec2, DemandIndex, Message, PacketS, PlayerClass, PlayerID, Score, + glam::{IVec2, Vec2}, + DemandIndex, Message, PacketS, PlayerClass, PlayerID, Score, }; use log::info; use rand::{random, seq::IndexedRandom, thread_rng}; @@ -39,6 +40,7 @@ pub enum Customer { Waiting { demand: DemandIndex, chair: IVec2, + facing: Vec2, timeout: f32, origin: IVec2, check: u8, @@ -46,13 +48,13 @@ pub enum Customer { }, Eating { demand: DemandIndex, - target: IVec2, + table: IVec2, progress: f32, chair: IVec2, origin: IVec2, }, Finishing { - target: IVec2, + table: IVec2, origin: IVec2, cooldown: f32, }, @@ -103,10 +105,21 @@ impl BotAlgo for Customer { let demand = DemandIndex(random::<u32>() as usize % game.data.demands.len()); info!("{me:?} -> waiting"); let timeout = 90. + random::<f32>() * 60.; + let mut facing = Vec2::ZERO; + for off in [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] { + if game + .tiles + .get(&(off + *chair)) + .map_or(false, |t| game.data.is_tile_interactable(t.kind)) + { + facing = off.as_vec2(); + } + } *self = Customer::Waiting { chair: *chair, timeout, demand, + facing, origin: *origin, check: 0, pinned: false, @@ -153,6 +166,7 @@ impl BotAlgo for Customer { origin, check, pinned, + facing, } => { *timeout -= dt; *check += 1; @@ -234,7 +248,7 @@ impl BotAlgo for Customer { info!("{me:?} -> eating"); *self = Customer::Eating { demand: *demand, - target: pos, + table: pos, progress: 0., chair: *chair, origin: *origin, @@ -271,14 +285,14 @@ impl BotAlgo for Customer { } } BotInput { - direction: (chair.as_vec2() + 0.5) - pos, + direction: (chair.as_vec2() + 0.5) - pos + *facing * 0.3, ..Default::default() } } Customer::Eating { demand, - target, + table, progress, chair, origin, @@ -298,7 +312,7 @@ impl BotAlgo for Customer { })); info!("{me:?} -> finishing"); *self = Customer::Finishing { - target: *target, + table: *table, origin: *origin, cooldown: 0.5, }; @@ -308,12 +322,12 @@ impl BotAlgo for Customer { }; } BotInput { - direction: (chair.as_vec2() + 0.5) - pos, + direction: (chair.as_vec2() + 0.5) - pos + (*table - *chair).as_vec2() * 0.3, ..Default::default() } } Customer::Finishing { - target, + table, origin, cooldown, } => { @@ -324,14 +338,14 @@ impl BotAlgo for Customer { } BotInput::default() } else { - let direction = (target.as_vec2() + 0.5) - pos; + let direction = (table.as_vec2() + 0.5) - pos; if *cooldown < 0. { *cooldown += 1.; BotInput { extra: vec![ PacketS::Interact { player: me, - pos: Some(*target), + pos: Some(*table), }, PacketS::Interact { player: me, |