Implements modifier system for weapons
Adds a modifier system allowing dynamic modification of weapon stats and behavior. This includes: - Creating ModifierLibrary to manage available modifiers. - Adds ModifierManager to handle equipping and unequipping modifiers - Adds a new RangedWeaponComponent to handle firing projectiles and managing modifiers. - Introduces a DebugUI for in-game modifier management. - Introduces an "Unlimited Power" modifier that changes the projectile scene. - Modifies stats components to work with the new modifier system. This system allows for more flexible and customizable weapon functionality.
This commit is contained in:
parent
9f66ab0a73
commit
70839387ca
22 changed files with 432 additions and 40 deletions
|
|
@ -3,15 +3,68 @@ extends Node2D
|
|||
class_name RangedWeaponComponent
|
||||
|
||||
@export var stats: StatsComponent
|
||||
@export var basic_projectile: PackedScene = preload("res://assets/projectiles/basic_projectile.tscn")
|
||||
|
||||
@onready var modifier_manager = $ModifierManager
|
||||
@onready var projectile_scene: PackedScene = basic_projectile
|
||||
|
||||
var can_fire: bool = true
|
||||
var cooldown: Timer
|
||||
|
||||
func _init() -> void:
|
||||
cooldown = Timer.new()
|
||||
add_child(cooldown)
|
||||
cooldown.one_shot = true
|
||||
|
||||
func _ready() -> void:
|
||||
Log.pr("RangedWeaponComponent initialized")
|
||||
modifier_manager.set_stats(stats)
|
||||
modifier_manager.connect("modifier_added", _on_modifier_added)
|
||||
modifier_manager.connect("modifier_removed", _on_modifier_removed)
|
||||
cooldown.connect("timeout", _on_fire_timer_timeout)
|
||||
|
||||
func add_modifier(modifier: Modifier) -> void:
|
||||
modifier_manager.add_modifier(modifier)
|
||||
|
||||
func remove_modifier(modifier_id: String) -> void:
|
||||
modifier_manager.remove_modifier(modifier_id)
|
||||
modifier_manager.remove_modifier(modifier_id)
|
||||
|
||||
func fire(direction: Vector2, target_position: Vector2) -> void:
|
||||
if !can_fire:
|
||||
return
|
||||
|
||||
spawn_projectile(global_position, direction, target_position)
|
||||
|
||||
can_fire = false
|
||||
cooldown.start(1 / stats.get_stat("ranged.attack_rate"))
|
||||
|
||||
func set_projectile_scene() -> void:
|
||||
projectile_scene = basic_projectile
|
||||
modifier_manager.check_and_call("set_projectile_scene", [self])
|
||||
|
||||
func spawn_projectile(spawn_position: Vector2, spawn_direction: Vector2, target_position: Vector2) -> void:
|
||||
Log.pr("Spawning projectile")
|
||||
modifier_manager.check_and_call("spawn_projectile", [self])
|
||||
|
||||
## TODO: Handle multiple shots per fire
|
||||
|
||||
var projectile = projectile_scene.instantiate()
|
||||
projectile.global_position = spawn_position
|
||||
projectile.target_position = target_position
|
||||
projectile.speed = 200 # stats.get_stat("projectile_speed")
|
||||
projectile.damage = 10 # stats.get_stat("damage")
|
||||
projectile.lifetime = 2 # stats.get_stat("projectile_lifetime")
|
||||
projectile.source_weapon = self
|
||||
var size = stats.get_stat("ranged.projectile_size")
|
||||
projectile.set_projectile_scale(Vector2(size, size))
|
||||
if get_tree() and get_tree().get_root():
|
||||
get_tree().get_root().add_child(projectile)
|
||||
|
||||
func _on_modifier_added(_modifier: Modifier) -> void:
|
||||
set_projectile_scene()
|
||||
|
||||
func _on_modifier_removed(_modifier: Modifier) -> void:
|
||||
set_projectile_scene()
|
||||
|
||||
func _on_fire_timer_timeout() -> void:
|
||||
can_fire = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue