#include "actor_body.h" #include "core/object/class_db.h" #include "core/string/print_string.h" void ActorBody::_bind_methods() { ClassDB::bind_method(D_METHOD("request_attack"), &self_type::request_attack, "target"); } void ActorBody::_notification(int what) { if(Engine::get_singleton()->is_editor_hint()) { return; } switch(what) { case NOTIFICATION_READY: this->equipment = Object::cast_to(this->get_node(NodePath("Equipment"))); break; } } void ActorBody::_attack() { if(this->attack_requested != nullptr) { this->attack_requested->receive_damage(this->equipment->apply(this->equipment->get_weapon()->create_base_damage_event(this), this)); this->attack_requested = nullptr; } } bool ActorBody::is_attack_requested() { return this->attack_requested != nullptr; } void ActorBody::receive_damage(DamageEvent event) { this->health -= this->equipment->apply(event, this).compound_damage; print_line(vformat("Damage dealth (%d to %s, %d remaining", event.compound_damage, this->get_name(), this->health)); if(this->health < 0) { this->queue_free(); } } void ActorBody::request_attack(ActorBody *target) { this->attack_requested = target; } void ActorBody::set_health(int health) { this->health = health; } int ActorBody::get_health() const { return this->health; }