Skip to main content

steel_core/entity/ai/goal/
interact.rs

1use super::look_at_player::LookAtPlayerGoal;
2use super::selector::{Goal, GoalControls};
3use crate::entity::PathfinderMob;
4
5pub struct InteractGoal {
6    look_at: LookAtPlayerGoal,
7}
8
9impl InteractGoal {
10    #[must_use]
11    pub(crate) fn new_player(look_distance: f64, probability: f32) -> Self {
12        Self {
13            look_at: LookAtPlayerGoal::new_for_players_with_controls(
14                look_distance,
15                probability,
16                false,
17                GoalControls::LOOK | GoalControls::MOVE,
18            ),
19        }
20    }
21}
22
23impl Goal for InteractGoal {
24    fn controls(&self) -> GoalControls {
25        self.look_at.controls()
26    }
27
28    fn can_use(&mut self, mob: &dyn PathfinderMob) -> bool {
29        self.look_at.can_use(mob)
30    }
31
32    fn can_continue_to_use(&mut self, mob: &dyn PathfinderMob) -> bool {
33        self.look_at.can_continue_to_use(mob)
34    }
35
36    fn start(&mut self, mob: &dyn PathfinderMob) {
37        self.look_at.start(mob);
38    }
39
40    fn stop(&mut self, mob: &dyn PathfinderMob) {
41        self.look_at.stop(mob);
42    }
43
44    fn tick(&mut self, mob: &dyn PathfinderMob) {
45        self.look_at.tick(mob);
46    }
47}
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn interact_goal_claims_look_and_move_controls_like_vanilla() {
55        let goal = InteractGoal::new_player(3.0, 1.0);
56
57        assert_eq!(goal.controls(), GoalControls::LOOK | GoalControls::MOVE);
58    }
59}