2024-02-22 06:22:22 +11:00
|
|
|
class_name ShapecastWeapon extends Weapon
|
2023-11-17 20:49:38 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
@export var shapecast: ShapeCast3D
|
|
|
|
@export var range_debug_indicator: CSGSphere3D
|
|
|
|
@export var status_stats: StatusStats
|
|
|
|
@export var particles: GPUParticles3D
|
2023-11-17 20:49:38 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
var attack_range: float = 0.0
|
2023-11-17 20:49:38 +11:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
super._ready()
|
|
|
|
attack_range = stats.get_attribute("Range")
|
|
|
|
range_debug_indicator.radius = attack_range
|
|
|
|
shapecast.shape.size.z = attack_range
|
|
|
|
shapecast.target_position = -hero.camera.basis.z * (attack_range / 2.0)
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
super._process(delta)
|
|
|
|
particles.emitting = trigger_held
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func shoot() -> void:
|
2023-11-17 20:49:38 +11:00
|
|
|
super.shoot()
|
2024-02-22 06:22:22 +11:00
|
|
|
for index: int in shapecast.get_collision_count():
|
|
|
|
var target: CharacterBody3D = shapecast.get_collider(index)
|
2023-11-17 20:49:38 +11:00
|
|
|
if target:
|
2024-02-22 06:22:22 +11:00
|
|
|
var target_hitbox: Hitbox = target.shape_owner_get_owner(shapecast.get_collider_shape(index))
|
2023-11-17 20:49:38 +11:00
|
|
|
if target_hitbox is Hitbox:
|
|
|
|
hit(target, target_hitbox)
|
|
|
|
if Data.preferences.display_self_damage_indicators:
|
|
|
|
spawn_damage_indicator(target.sprite.global_position)
|
|
|
|
networked_hit.rpc(get_tree().root.get_path_to(target), get_tree().root.get_path_to(target_hitbox))
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func hit(target: CharacterBody3D, target_hitbox: Hitbox) -> void:
|
2023-11-17 20:49:38 +11:00
|
|
|
target_hitbox.damage(damage)
|
|
|
|
target.status_manager.add_effect(build_status_object())
|
|
|
|
|
|
|
|
|
|
|
|
@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) as CharacterBody3D
|
|
|
|
var target_hitbox: Hitbox = get_tree().root.get_node(target_hitbox_path) as Hitbox
|
2023-11-17 20:49:38 +11:00
|
|
|
hit(target, target_hitbox)
|
|
|
|
if Data.preferences.display_party_damage_indicators:
|
|
|
|
spawn_damage_indicator(target.sprite.global_position)
|