2024-02-22 06:22:22 +11:00
|
|
|
class_name ShapecastTower extends Tower
|
2023-11-17 20:49:38 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
@export var shapecast: ShapeCast3D
|
|
|
|
@export var particlesystem: GPUParticles3D
|
|
|
|
@export var status_stats: StatusStats
|
2023-11-17 20:49:38 +11:00
|
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
super._process(delta)
|
|
|
|
if targeted_enemy:
|
|
|
|
particlesystem.emitting = true
|
|
|
|
else:
|
|
|
|
particlesystem.emitting = false
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func shoot() -> void:
|
|
|
|
for index: int in shapecast.get_collision_count():
|
|
|
|
var target: CharacterBody3D = shapecast.get_collider(index) as CharacterBody3D
|
2023-11-17 20:49:38 +11:00
|
|
|
hit(target)
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func aim() -> void:
|
2023-11-17 20:49:38 +11:00
|
|
|
yaw_model.look_at(targeted_enemy.global_position)
|
|
|
|
pitch_model.look_at(targeted_enemy.global_position)
|
|
|
|
pitch_model.rotation.x = 0.0
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func hit(target: CharacterBody3D) -> void:
|
2023-11-17 20:49:38 +11:00
|
|
|
if is_instance_valid(target) and target.alive:
|
|
|
|
target.damage(damage)
|
|
|
|
if Data.preferences.display_tower_damage_indicators:
|
|
|
|
spawn_damage_indicator(target.sprite.global_position)
|
|
|
|
target.status_manager.add_effect(build_status_object())
|
|
|
|
if is_multiplayer_authority():
|
|
|
|
networked_hit.rpc(get_tree().root.get_path_to(target))
|
|
|
|
|
|
|
|
|
|
|
|
func build_status_object() -> StatusEffect:
|
2024-02-22 06:22:22 +11:00
|
|
|
var status: StatusEffect = StatusEffect.new()
|
2023-11-17 20:49:38 +11:00
|
|
|
status.stats = status_stats
|
|
|
|
return status
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable")
|
2024-02-22 06:22:22 +11:00
|
|
|
func networked_hit(target_node_path: String) -> void:
|
|
|
|
var target: CharacterBody3D = get_tree().root.get_node(target_node_path) as CharacterBody3D
|
2023-11-17 20:49:38 +11:00
|
|
|
hit(target)
|