2024-02-22 06:22:22 +11:00
|
|
|
class_name RangeAffectingTower extends StatusApplyingTower
|
2023-11-17 20:49:38 +11:00
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
if !is_multiplayer_authority():
|
|
|
|
return
|
2024-02-22 06:22:22 +11:00
|
|
|
var enemies_in_range: Array = []
|
|
|
|
for enemy: EnemyController in get_tree().get_nodes_in_group("Enemies"):
|
2023-11-17 20:49:38 +11:00
|
|
|
if !is_instance_valid(enemy) or !enemy.alive or global_position.distance_to(enemy.global_position) > target_range:
|
|
|
|
continue
|
2023-11-18 00:01:04 +11:00
|
|
|
if enemy.stats.target_type & stats.target_type:
|
|
|
|
enemies_in_range.append(enemy)
|
2023-11-17 20:49:38 +11:00
|
|
|
if time_since_firing >= time_between_shots:
|
|
|
|
time_since_firing -= time_between_shots
|
2024-02-22 06:22:22 +11:00
|
|
|
for enemy: EnemyController in enemies_in_range:
|
2023-11-17 20:49:38 +11:00
|
|
|
fire(enemy)
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func aim() -> void:
|
2023-11-19 18:47:52 +11:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func fire(target: EnemyController) -> void:
|
2023-11-17 20:49:38 +11:00
|
|
|
if is_instance_valid(target) and target.alive:
|
|
|
|
target.damage(damage)
|
|
|
|
target.status_manager.add_effect(build_status_object())
|
|
|
|
if Data.preferences.display_tower_damage_indicators:
|
|
|
|
spawn_damage_indicator(target.sprite.global_position)
|
|
|
|
if is_multiplayer_authority():
|
|
|
|
networked_fire.rpc(get_tree().root.get_path_to(target))
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable")
|
2024-02-22 06:22:22 +11:00
|
|
|
func networked_fire(target_node_path: String) -> void:
|
|
|
|
var target: EnemyController = get_tree().root.get_node(target_node_path)
|
2023-11-17 20:49:38 +11:00
|
|
|
fire(target)
|