2024-02-22 06:22:22 +11:00
|
|
|
class_name HitscanWeapon extends Weapon
|
2023-11-15 15:19:40 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
@export var raycast: RayCast3D
|
|
|
|
@export var range_debug_indicator: CSGSphere3D
|
2023-11-15 15:19:40 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
var attack_range: float = 0.0
|
2023-11-15 15:19:40 +11:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
super._ready()
|
|
|
|
attack_range = stats.get_attribute("Range")
|
|
|
|
raycast.target_position = Vector3(0, 0, -attack_range)
|
|
|
|
range_debug_indicator.radius = attack_range
|
|
|
|
raycast.global_position = hero.camera.global_position
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func shoot() -> void:
|
2023-11-15 15:19:40 +11:00
|
|
|
super.shoot()
|
|
|
|
if raycast.is_colliding():
|
2024-02-22 06:22:22 +11:00
|
|
|
var target: CharacterBody3D = raycast.get_collider()
|
2023-11-15 15:19:40 +11:00
|
|
|
if target != null:
|
2024-02-22 06:22:22 +11:00
|
|
|
var target_hitbox: Hitbox = target.shape_owner_get_owner(raycast.get_collider_shape())
|
2023-11-15 15:19:40 +11:00
|
|
|
if target_hitbox is Hitbox:
|
|
|
|
hit(target, target_hitbox)
|
2023-11-16 00:07:41 +11:00
|
|
|
if Data.preferences.display_self_damage_indicators:
|
|
|
|
spawn_damage_indicator(raycast.get_collision_point())
|
2023-11-15 15:19:40 +11:00
|
|
|
networked_hit.rpc(get_tree().root.get_path_to(target), get_tree().root.get_path_to(target_hitbox))
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func hit(_target: CharacterBody3D, target_hitbox: Hitbox) -> void:
|
2023-11-15 15:19:40 +11:00
|
|
|
target_hitbox.damage(damage)
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable")
|
2024-02-22 06:22:22 +11:00
|
|
|
func networked_hit(target_path: String, target_hitbox_path: String) -> void:
|
|
|
|
var target: CharacterBody3D = get_tree().root.get_node(target_path)
|
|
|
|
var target_hitbox: Hitbox = get_tree().root.get_node(target_hitbox_path) as Hitbox
|
2023-11-15 15:19:40 +11:00
|
|
|
hit(target, target_hitbox)
|
2023-11-16 00:07:41 +11:00
|
|
|
if Data.preferences.display_party_damage_indicators:
|
|
|
|
spawn_damage_indicator(target.sprite.global_position)
|