wave-survival/modules/wave_survival/enemies/enemy_rifleman.cpp

76 lines
1.7 KiB
C++

#include "enemy_rifleman.h"
#include "core/os/memory.h"
#include "scene/animation/animation_player.h"
#include "wave_survival/macros.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<StateMachine>(node) }) {
this->fsm = fsm;
}
if (node->has_node(NodePath("AnimationPlayer"))) {
this->anim = cast_to<AnimationPlayer>(node->get_node(NodePath("AnimationPlayer")));
}
}
void EnemyRifleman::ready() {
this->fsm->add_state(memnew(RiflemanPatrolState));
this->fsm->add_state(memnew(RiflemanSeekState));
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;
}
void RiflemanState::set_target(Node *node) {
this->target = cast_to<EnemyRifleman>(node);
}
EnemyRifleman *RiflemanState::get_target() const {
return this->target;
}
NpcUnit *RiflemanState::get_unit() const {
return this->target->get_unit();
}
NavigationAgent3D *RiflemanState::get_nav() const {
return this->target->get_nav();
}
AnimationPlayer *RiflemanState::get_anim() const {
return this->target->get_anim();
}
void