mtd/Scripts/Towers/range_affecting_tower.gd

37 lines
1.2 KiB
GDScript3
Raw Normal View History

2024-02-22 06:22:22 +11:00
class_name RangeAffectingTower extends StatusApplyingTower
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"):
if !is_instance_valid(enemy) or !enemy.alive or global_position.distance_to(enemy.global_position) > target_range:
continue
if enemy.stats.target_type & stats.target_type:
enemies_in_range.append(enemy)
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:
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:
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)
fire(target)