diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-29 17:37:30 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-29 17:37:30 +0200 |
commit | 76712852d30df670741c836a8e705e7482a8a2ac (patch) | |
tree | 98edf9cf3c86228e14969e1d9621c1d22b896589 | |
parent | 824771fd53fc9cff2388d6f3baae3380debad81f (diff) | |
parent | 81aa0b5fff9d6d77ccc23129c23e8c50818c3188 (diff) | |
download | hurrycurry-76712852d30df670741c836a8e705e7482a8a2ac.tar hurrycurry-76712852d30df670741c836a8e705e7482a8a2ac.tar.bz2 hurrycurry-76712852d30df670741c836a8e705e7482a8a2ac.tar.zst |
Merge branch 'dishwasher-bot'
-rw-r--r-- | locale/en.ini | 1 | ||||
-rw-r--r-- | server/bot/src/algos/dishwasher.rs | 110 | ||||
-rw-r--r-- | server/bot/src/algos/mod.rs | 3 |
3 files changed, 114 insertions, 0 deletions
diff --git a/locale/en.ini b/locale/en.ini index 3e48e5c6..0c5fd096 100644 --- a/locale/en.ini +++ b/locale/en.ini @@ -194,6 +194,7 @@ c.setup.user_signature=Click to sign s.bot.frank=Frank Miller s.bot.simple=Simple chef s.bot.waiter=Waiter +s.bot.dishwasher=Dish washer s.campaign.condition.stars=Reach at least {0} stars in {1} s.campaign.list_helper=- {0}%n - {1} s.campaign.unlock_condition=To unlock: %n%n{0} diff --git a/server/bot/src/algos/dishwasher.rs b/server/bot/src/algos/dishwasher.rs new file mode 100644 index 00000000..bfe57d0c --- /dev/null +++ b/server/bot/src/algos/dishwasher.rs @@ -0,0 +1,110 @@ +/* + Hurry Curry! - a game about cooking + Copyright 2024 Miner34 + Copyright 2024 metamuffin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License only. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ +use super::simple::State; +use crate::{algos::simple::Context, pathfinding::Path, BotAlgo, BotInput}; +use hurrycurry_client_lib::Game; +use hurrycurry_protocol::{glam::IVec2, ItemIndex, PlayerID}; + +#[derive(Default)] +pub struct DishWasher { + path: Option<(Path, IVec2, f32)>, + cooldown: f32, + dirty_plate: Option<ItemIndex>, +} + +type LogicRes<Out = ()> = Result<Out, ()>; + +impl BotAlgo for DishWasher { + fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput { + if let None = self.dirty_plate { + self.dirty_plate = game.data.get_item_by_name("dirty-plate"); + if let None = self.dirty_plate { + return BotInput::default(); + } + } + + let Some(player) = game.players.get(&me) else { + return BotInput::default(); + }; + let pos = player.movement.position; + + if self.cooldown > 0. { + self.cooldown -= dt; + return BotInput::default(); + } + + if let Some((path, target, down)) = &mut self.path { + let direction = path.next_direction(pos, dt); + let arrived = path.is_done(); + let target = *target; + if arrived { + *down -= dt; + if *down < 0. { + self.path = None; + self.cooldown = 0.2; + } + } + return BotInput { + direction, + boost: false, + interact: if arrived { Some(target) } else { None }, + ..Default::default() + }; + } + Context { + game, + own_position: pos.as_ivec2(), + me, + state: self, + recursion_abort: 0, + } + .update() + .ok(); + + BotInput::default() + } +} + +impl State for DishWasher { + fn cooldown(&mut self, dur: f32) { + self.cooldown += dur + } + fn queue_segment(&mut self, path: Path, tile: IVec2, duration: f32) { + self.path = Some((path, tile, duration)); + } + fn get_empty_tile_priority(&self) -> &'static [&'static str] { + &["counter-window", "counter"] + } +} + +impl Context<'_, DishWasher> { + fn update(&mut self) -> LogicRes { + if let Some(pos) = self.find_item_on_map(self.state.dirty_plate.unwrap()) { + self.assert_tile_is_clear(pos)?; + } + if self.is_hand_item(self.state.dirty_plate.unwrap()) { + self.interact_with( + self.find_empty_interactable_tile_by_name("sink").unwrap(), + 2.0, + )?; + } + self.assert_hand_is_clear()?; + Ok(()) + } +} diff --git a/server/bot/src/algos/mod.rs b/server/bot/src/algos/mod.rs index dea31406..0b8e4339 100644 --- a/server/bot/src/algos/mod.rs +++ b/server/bot/src/algos/mod.rs @@ -20,18 +20,21 @@ mod frank; mod simple; mod test; mod waiter; +mod dishwasher; pub use customer::Customer; pub use frank::Frank; pub use simple::Simple; pub use test::Test; pub use waiter::Waiter; +pub use dishwasher::DishWasher; #[allow(clippy::type_complexity)] pub const ALGO_CONSTRUCTORS: &[(&str, fn() -> crate::DynBotAlgo)] = &[ ("test", || Box::new(Test::default())), ("simple", || Box::new(Simple::default())), ("waiter", || Box::new(Waiter::default())), + ("dishwasher", || Box::new(DishWasher::default())), ("customer", || Box::new(Customer::default())), ("frank", || Box::new(Frank::default())), ]; |