Refactors modifier system to use StatsComponent
Moves modifier logic to utilize a central StatsComponent for managing and applying stat modifications. This change centralizes stat management and simplifies the application of modifiers, enhancing code maintainability and reducing redundancy. It also moves modifier files to the correct directory.
This commit is contained in:
parent
19cc8cb573
commit
9f66ab0a73
21 changed files with 135 additions and 97 deletions
|
|
@ -1,28 +1,22 @@
|
|||
@icon("res://assets/editor/64x64/fc1098.png")
|
||||
extends Node2D
|
||||
class_name ModifierManagerTwo
|
||||
class_name ModifierManager
|
||||
|
||||
signal modifier_added(modifier)
|
||||
signal modifier_removed(modifier)
|
||||
signal stats_updated()
|
||||
|
||||
var stats: StatsComponent
|
||||
var stats_component: StatsComponent
|
||||
|
||||
# Stores all active modifiers
|
||||
var modifiers: Array[Modifier] = []
|
||||
|
||||
# Base stats (before modifiers)
|
||||
var base_stats: Dictionary = {}
|
||||
|
||||
# Final calculated stats
|
||||
var final_stats: Dictionary = {}
|
||||
|
||||
func _ready() -> void:
|
||||
Log.pr("ModifierManager initialized")
|
||||
Log.pr("Stats: ", stats)
|
||||
Log.pr("StatsComponent: ", stats_component)
|
||||
|
||||
func set_stats(stats_component: StatsComponent) -> void:
|
||||
self.stats = stats_component
|
||||
func set_stats(stats: StatsComponent) -> void:
|
||||
self.stats_component = stats
|
||||
|
||||
func add_modifier(modifier: Modifier) -> void:
|
||||
modifiers.append(modifier)
|
||||
|
|
@ -42,7 +36,7 @@ func remove_modifier(modifier_id: String) -> void:
|
|||
|
||||
func recalculate_stats() -> void:
|
||||
# Reset stats to base values
|
||||
final_stats = base_stats.duplicate()
|
||||
stats_component.reset_stats()
|
||||
|
||||
# Sort modifiers by priority
|
||||
modifiers.sort_custom(func(a, b): return a.priority > b.priority)
|
||||
|
|
@ -67,26 +61,8 @@ func recalculate_stats() -> void:
|
|||
if modifier.modifier_type == Modifier.ModifierType.CONDITIONAL:
|
||||
_apply_modifier_stats(modifier)
|
||||
|
||||
# Apply caps and floors to stats
|
||||
_apply_stat_limits()
|
||||
|
||||
emit_signal("stats_updated")
|
||||
|
||||
func _apply_modifier_stats(modifier: Modifier) -> void:
|
||||
if modifier.has_method("apply_stats_modification"):
|
||||
modifier.apply_stats_modification(final_stats, base_stats)
|
||||
|
||||
func _apply_stat_limits() -> void:
|
||||
pass
|
||||
# Example: Cap fire rate
|
||||
#if final_stats.has("fire_rate"):
|
||||
# final_stats.fire_rate = min(final_stats.fire_rate, 20.0) # Max 20 shots per second
|
||||
# final_stats.fire_rate = max(final_stats.fire_rate, 0.5) # Min 0.5 shots per second
|
||||
|
||||
# Example: Cap projectile size
|
||||
#if final_stats.has("projectile_size"):
|
||||
# final_stats.projectile_size = min(final_stats.projectile_size, 5.0) # Max 5x normal size
|
||||
# final_stats.projectile_size = max(final_stats.projectile_size, 0.2) # Min 0.2x normal size
|
||||
|
||||
func get_stat(stat_name: String, default_value = 0):
|
||||
return final_stats.get(stat_name, default_value)
|
||||
modifier.apply_stats_modification(stats_component)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue