Improves projectile handling and modifiers
Refactors projectile spawning to allow for customized spawn locations and stat assignment. Applies modifiers to projectiles at the time of spawning, enabling dynamic adjustments to projectile behavior.
This commit is contained in:
parent
70839387ca
commit
fac3327c22
6 changed files with 74 additions and 11 deletions
|
|
@ -5,6 +5,9 @@ signal on_hit(projectile, target)
|
|||
signal on_spawned(projectile)
|
||||
signal on_destroyed(projectile)
|
||||
|
||||
var stats = StatsComponent
|
||||
var modifier_manager: ModifierManager
|
||||
|
||||
@export var speed: float = 500.0
|
||||
@export var damage: float = 10.0
|
||||
@export var lifetime: float = 2
|
||||
|
|
@ -26,6 +29,38 @@ var lifetime_timer: Timer
|
|||
# Add a variable to track the entity that triggered the explosion
|
||||
var ignore_target = []
|
||||
|
||||
func _init() -> void:
|
||||
Log.pr('Setting up ModifierManager for projectile...')
|
||||
modifier_manager = ModifierManager.new()
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func set_stats(setting_stats: StatsComponent) -> void:
|
||||
Log.pr('Snapshotting stats for projectile:', setting_stats)
|
||||
self.stats = setting_stats
|
||||
modifier_manager.set_stats(stats)
|
||||
|
||||
# Set up the lifetime timer
|
||||
lifetime_timer = Timer.new()
|
||||
add_child(lifetime_timer)
|
||||
lifetime_timer.one_shot = true
|
||||
lifetime_timer.wait_time = lifetime
|
||||
#lifetime_timer.connect("timeout", self, "_on_lifetime_timeout")
|
||||
lifetime_timer.start()
|
||||
|
||||
# Ensure we have a collision shape
|
||||
#ensure_collision_shape()
|
||||
|
||||
emit_signal("on_spawned", self)
|
||||
#connect("body_entered", self, "_on_body_entered")
|
||||
|
||||
func add_modifier(modifier: Modifier) -> void:
|
||||
modifier_manager.add_modifier(modifier)
|
||||
|
||||
func remove_modifier(modifier_id: String) -> void:
|
||||
modifier_manager.remove_modifier(modifier_id)
|
||||
|
||||
func _on_body_entered(body):
|
||||
if ignore_target.has(body):
|
||||
Log.pr("Ignoring body: ", body.name)
|
||||
|
|
@ -98,4 +133,4 @@ func destroy():
|
|||
queue_free()
|
||||
|
||||
func _on_lifetime_timeout():
|
||||
destroy()
|
||||
destroy()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue