feat: reworked enemy wretched logic
This commit is contained in:
parent
2cd1cba04f
commit
74aead946c
2 changed files with 48 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "enemy_wretched.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "wave_survival/npc_unit.h"
|
||||
#include "wave_survival/patrol_path.h"
|
||||
#include "wave_survival/player_body.h"
|
||||
|
|
@ -7,12 +8,19 @@
|
|||
void EnemyWretched::_bind_methods() {
|
||||
}
|
||||
|
||||
void EnemyWretched::ready() {
|
||||
if (StateMachine * fsm{ cast_to<StateMachine>(get_node(NodePath("%StateMachine"))) }) {
|
||||
fsm->add_state(memnew(WretchedPatrolState));
|
||||
fsm->add_state(memnew(WretchedChaseState));
|
||||
fsm->add_state(memnew(WretchedAttackState));
|
||||
void EnemyWretched::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 EnemyWretched::ready() {
|
||||
print_line("ready");
|
||||
fsm->add_state(memnew(WretchedPatrolState));
|
||||
fsm->add_state(memnew(WretchedChaseState));
|
||||
fsm->add_state(memnew(WretchedAttackState));
|
||||
}
|
||||
|
||||
void EnemyWretched::_notification(int what) {
|
||||
|
|
@ -22,16 +30,21 @@ void EnemyWretched::_notification(int what) {
|
|||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
connect("child_entered_tree", callable_mp(this, &self_type::on_child_entered));
|
||||
return;
|
||||
case NOTIFICATION_READY:
|
||||
ready();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AnimationPlayer *EnemyWretched::get_anim() const {
|
||||
return this->anim;
|
||||
}
|
||||
|
||||
void WretchedState::set_target(Node *node) {
|
||||
this->target = cast_to<EnemyWretched>(node);
|
||||
this->nav = this->target->get_nav();
|
||||
this->unit = this->target->get_unit();
|
||||
}
|
||||
|
||||
EnemyWretched *WretchedState::get_target() const {
|
||||
|
|
@ -39,11 +52,15 @@ EnemyWretched *WretchedState::get_target() const {
|
|||
}
|
||||
|
||||
NpcUnit *WretchedState::get_unit() const {
|
||||
return this->unit;
|
||||
return this->target->get_unit();
|
||||
}
|
||||
|
||||
NavigationAgent3D *WretchedState::get_nav() const {
|
||||
return this->nav;
|
||||
return this->target->get_nav();
|
||||
}
|
||||
|
||||
AnimationPlayer *WretchedState::get_anim() const {
|
||||
return this->target->get_anim();
|
||||
}
|
||||
|
||||
void WretchedPatrolState::set_patrol_target(Vector3 path_point) {
|
||||
|
|
@ -85,6 +102,7 @@ void WretchedChaseState::enter_state() {
|
|||
get_target()->set_movement_speed(get_unit()->get_patrol_speed() * 2.f);
|
||||
get_nav()->set_max_speed(get_unit()->get_patrol_speed() * 2.f);
|
||||
get_nav()->set_target_position(PlayerBody::get_singleton()->get_global_position());
|
||||
get_anim()->play("ready"); // TODO: replace this with "run"
|
||||
}
|
||||
|
||||
void WretchedChaseState::process(double delta) {
|
||||
|
|
@ -101,6 +119,13 @@ String WretchedChaseState::get_next_state() const {
|
|||
return get_class();
|
||||
}
|
||||
|
||||
String WretchedAttackState::get_next_state() const {
|
||||
return WretchedChaseState::get_class_static();
|
||||
void WretchedAttackState::enter_state() {
|
||||
get_anim()->play("attack");
|
||||
}
|
||||
|
||||
String WretchedAttackState::get_next_state() const {
|
||||
if (get_anim()->get_current_animation().is_empty()) {
|
||||
return WretchedChaseState::get_class_static();
|
||||
}
|
||||
return get_class();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue