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
|
|
@ -18,6 +18,12 @@ func _ready() -> void:
|
|||
func set_stats(stats: StatsComponent) -> void:
|
||||
self.stats_component = stats
|
||||
|
||||
func has_modifier(modifier_id: String) -> bool:
|
||||
for modifier in modifiers:
|
||||
if modifier.id == modifier_id:
|
||||
return true
|
||||
return false
|
||||
|
||||
func add_modifier(modifier: Modifier) -> void:
|
||||
modifiers.append(modifier)
|
||||
modifier.on_equip(get_parent())
|
||||
|
|
@ -63,6 +69,29 @@ func recalculate_stats() -> void:
|
|||
|
||||
emit_signal("stats_updated")
|
||||
|
||||
func check_callable(func_name: String) -> Callable:
|
||||
# Create a default callable that does nothing and returns null
|
||||
var default_callable = func(): return null
|
||||
|
||||
# Check each modifier in priority order
|
||||
for modifier in modifiers:
|
||||
if modifier.has_method(func_name):
|
||||
# Return the callable from this modifier
|
||||
return Callable(modifier, func_name)
|
||||
|
||||
# Return the default callable if no modifier has the function
|
||||
return default_callable
|
||||
|
||||
# Convenience method to check and call in one step
|
||||
func check_and_call(func_name: String, args := []):
|
||||
var callable = check_callable(func_name)
|
||||
if callable.is_valid():
|
||||
if args.size() > 0:
|
||||
return callable.callv(args)
|
||||
else:
|
||||
return callable.call()
|
||||
return null
|
||||
|
||||
func _apply_modifier_stats(modifier: Modifier) -> void:
|
||||
if modifier.has_method("apply_stats_modification"):
|
||||
modifier.apply_stats_modification(stats_component)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue