aboutsummaryrefslogtreecommitdiff
path: root/server/bot
diff options
context:
space:
mode:
Diffstat (limited to 'server/bot')
-rw-r--r--server/bot/src/algos/customer.rs94
1 files changed, 64 insertions, 30 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs
index c3d72d49..592d0574 100644
--- a/server/bot/src/algos/customer.rs
+++ b/server/bot/src/algos/customer.rs
@@ -47,6 +47,11 @@ pub enum Customer {
chair: IVec2,
origin: IVec2,
},
+ Finishing {
+ target: IVec2,
+ origin: IVec2,
+ cooldown: f32,
+ },
Exiting {
path: Path,
},
@@ -127,7 +132,7 @@ impl BotAlgo for Customer {
BotInput::default()
} else {
BotInput {
- direction: path.next_direction(pos, dt) * 0.5,
+ direction: path.next_direction(pos, dt) * 0.6,
..Default::default()
}
}
@@ -234,40 +239,69 @@ impl BotAlgo for Customer {
let demand = &game.data.demands[demand.0];
*progress += dt / demand.duration;
if *progress >= 1. {
- if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), *origin) {
- let mut packets = Vec::new();
- packets.push(PacketS::ReplaceHand {
- player: me,
- item: demand.output,
- });
- if demand.output.is_some() {
- packets.push(PacketS::Interact {
- player: me,
- pos: Some(*target),
- });
- packets.push(PacketS::Interact {
- player: me,
- pos: None,
- });
- }
- packets.push(PacketS::ApplyScore(Score {
- demands_completed: 1,
- points: demand.points,
- ..Default::default()
- }));
- info!("{me:?} -> exiting");
- *self = Customer::Exiting { path };
- return BotInput {
- extra: packets,
- ..Default::default()
- };
- }
+ let mut packets = Vec::new();
+ packets.push(PacketS::ReplaceHand {
+ player: me,
+ item: demand.output,
+ });
+ packets.push(PacketS::ApplyScore(Score {
+ demands_completed: 1,
+ points: demand.points,
+ ..Default::default()
+ }));
+ info!("{me:?} -> finishing");
+ *self = Customer::Finishing {
+ target: *target,
+ origin: *origin,
+ cooldown: 0.5,
+ };
+ return BotInput {
+ extra: packets,
+ ..Default::default()
+ };
}
BotInput {
direction: (chair.as_vec2() + 0.5) - pos,
..Default::default()
}
}
+ Customer::Finishing {
+ target,
+ origin,
+ cooldown,
+ } => {
+ *cooldown -= dt;
+ if game.players.get(&me).map_or(false, |pl| pl.item.is_none()) {
+ if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), *origin) {
+ *self = Customer::Exiting { path };
+ }
+ BotInput::default()
+ } else {
+ let direction = (target.as_vec2() + 0.5) - pos;
+ if *cooldown < 0. {
+ *cooldown += 1.;
+ BotInput {
+ extra: vec![
+ PacketS::Interact {
+ player: me,
+ pos: Some(*target),
+ },
+ PacketS::Interact {
+ player: me,
+ pos: None,
+ },
+ ],
+ direction,
+ ..Default::default()
+ }
+ } else {
+ BotInput {
+ direction,
+ ..Default::default()
+ }
+ }
+ }
+ }
Customer::Exiting { path } => {
if path.is_done() || path.is_stuck() {
info!("{me:?} -> leave");
@@ -277,7 +311,7 @@ impl BotAlgo for Customer {
}
} else {
BotInput {
- direction: path.next_direction(pos, dt) * 0.5,
+ direction: path.next_direction(pos, dt) * 0.6,
..Default::default()
}
}