#include "enemy_rifleman.h" #include "core/os/memory.h" #include "scene/animation/animation_player.h" #include "wave_survival/macros.h" #include "wave_survival/npc_unit.h" #include "wave_survival/player_detector.h" #include "wave_survival/state_machine.h" void EnemyRifleman::_bind_methods() { BIND_PROPERTY(Variant::FLOAT, chase_speed); } void EnemyRifleman::on_child_entered(Node *node) { if (StateMachine * fsm{ cast_to(node) }) { this->fsm = fsm; } if (node->has_node(NodePath("AnimationPlayer"))) { this->anim = cast_to(node->get_node(NodePath("AnimationPlayer"))); } } void EnemyRifleman::ready() { this->fsm->add_state(memnew(RiflemanPatrolState)); this->fsm->add_state(memnew(RiflemanChaseState)); this->fsm->add_state(memnew(RiflemanFireState)); } void EnemyRifleman::_notification(int what) { if (Engine::get_singleton()->is_editor_hint()) { return; } switch (what) { default: return; case NOTIFICATION_ENTER_TREE: if (!is_ready()) { connect("child_entered", callable_mp(this, &self_type::on_child_entered)); } return; case NOTIFICATION_READY: ready(); return; } } void EnemyRifleman::set_chase_speed(float speed) { this->chase_speed = speed; } float EnemyRifleman::get_chase_speed() const { return this->chase_speed; } AnimationPlayer *EnemyRifleman::get_anim() const { return this->anim; } EnemyRifleman *RiflemanState::get_target() const { return cast_to(get_body()); } String RiflemanPatrolState::get_next_state() const { if (get_body()->get_unit()->is_aware_of_player()) { return RiflemanChaseState::get_class_static(); } return get_class(); } String RiflemanChaseState::get_next_state() const { if (get_body()->get_detector()->line_of_sight_exists()) { } return get_class(); }