#include "beacon_powerup.hpp"
#include "godot_cpp/variant/utility_functions.hpp"
#include "turret.hpp"
#include "utils/godot_macros.h"

namespace godot {
void BeaconPowerup::_bind_methods() {}

void BeaconPowerup::_enter_tree() { GDGAMEONLY();
    this->connect("body_entered", callable_mp(this, &BeaconPowerup::body_entered));
}

void BeaconPowerup::_exit_tree() { GDGAMEONLY();
    for(Turret *turret : this->affected) {
        turret->set_invert_targets(false);
    }
}

void BeaconPowerup::body_entered(Node3D *node) {
    UtilityFunctions::print(this->get_path(), " overlapped ", node->get_path());
    Turret *turret = Object::cast_to<Turret>(node);
    if(!turret) return;
    turret->set_invert_targets(true);
    this->affected.push_back(turret);
    UtilityFunctions::print(this->get_path(), " ", node->get_path(), " is a turret");
}
}
