Implements modifier and stats system

Adds a modifier and stats system to manage combat-related attributes.

Introduces StatsComponent for storing entity statistics and ModifierManager for applying dynamic modifiers. Recalculates stats based on modifier type and priority.

Updates projectile and weapon components to utilize the new stats system.
This commit is contained in:
Dan Baker 2025-05-07 11:52:30 +01:00
parent f97521decc
commit 19cc8cb573
13 changed files with 178 additions and 65 deletions

View file

@ -3,12 +3,26 @@ class_name ProjectileBaseTwo
var lifetime_timer: Timer
var direction: Vector2
var target_position: Vector2
var ELEMENTS = Global.ELEMENTS
var has_collided: bool = false
var stats = {
"speed": 500.0,
"damage": 10.0,
"element": ELEMENTS.NONE,
"lifetime": 2,
"pierce_count": 0
}
func set_stat(stat_name: String, value: Variant):
stats[stat_name] = value
func get_stat(stat_name: String) -> Variant:
return stats.get(stat_name, null)
func destroy():
emit_signal("on_destroyed", self)
queue_free()

View file

@ -4,9 +4,3 @@
[node name="RockProjectile" type="Node2D"]
script = ExtResource("1_8myby")
speed = null
damage = null
lifetime = null
direction = null
target_position = null
is_friendly = null

View file

@ -5,7 +5,7 @@ func _ready():
lifetime_timer = Timer.new()
add_child(lifetime_timer)
lifetime_timer.one_shot = true
lifetime_timer.wait_time = lifetime
lifetime_timer.wait_time = stats.lifetime
lifetime_timer.connect("timeout", _on_lifetime_timeout)
lifetime_timer.start()
@ -13,7 +13,19 @@ func _ready():
connect("body_entered", _on_body_entered)
func _physics_process(delta):
position += direction * speed * delta
position += direction * stats.speed * delta
func _on_body_entered(body):
if body.is_in_group("enemies"):
body.take_damage(stats.damage)
## Check if the projectile is piercing
if not get_stat("pierce_count"):
# If not piercing, destroy the projectile
destroy()
else:
# If piercing, reduce the pierce count
set_stat("pierce_count", get_stat("pierce_count") - 1)
func _on_lifetime_timeout():
super._on_lifetime_timeout()