Many changes

Handle it
This commit is contained in:
Dan Baker 2025-05-04 09:30:14 +01:00
parent bf09402bc5
commit 214e0aa5e0
366 changed files with 24353 additions and 2096 deletions

View file

@ -0,0 +1,84 @@
class_name ModifierManager extends Node
signal modifier_added(modifier)
signal modifier_removed(modifier)
signal stats_updated()
# Stores all active modifiers
var modifiers: Array[Modifier] = []
# Base stats (before modifiers)
var base_stats: Dictionary = {}
# Final calculated stats
var final_stats: Dictionary = {}
func _init(initial_base_stats: Dictionary = {}):
base_stats = initial_base_stats.duplicate()
final_stats = initial_base_stats.duplicate()
func add_modifier(modifier: Modifier) -> void:
modifiers.append(modifier)
modifier.on_equip(get_parent())
emit_signal("modifier_added", modifier)
recalculate_stats()
func remove_modifier(modifier_id: String) -> void:
for i in range(modifiers.size()):
if modifiers[i].id == modifier_id:
var modifier = modifiers[i]
modifier.on_unequip(get_parent())
modifiers.remove_at(i)
emit_signal("modifier_removed", modifier)
recalculate_stats()
break
func recalculate_stats() -> void:
# Reset stats to base values
final_stats = base_stats.duplicate()
# Sort modifiers by priority
modifiers.sort_custom(func(a, b): return a.priority > b.priority)
# First pass: Apply OVERRIDE modifiers (highest priority first)
for modifier in modifiers:
if modifier.modifier_type == Modifier.ModifierType.OVERRIDE:
_apply_modifier_stats(modifier)
# Second pass: Apply ADDITIVE modifiers
for modifier in modifiers:
if modifier.modifier_type == Modifier.ModifierType.ADDITIVE:
_apply_modifier_stats(modifier)
# Third pass: Apply MULTIPLICATIVE modifiers
for modifier in modifiers:
if modifier.modifier_type == Modifier.ModifierType.MULTIPLICATIVE:
_apply_modifier_stats(modifier)
# Last pass: Apply CONDITIONAL modifiers
for modifier in modifiers:
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:
# 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)

View file

@ -0,0 +1 @@
uid://cvklefr50qhfb

View file

@ -0,0 +1 @@
uid://bw6kcdfiq3ugv

47
player/scripts/player.gd Normal file
View file

@ -0,0 +1,47 @@
extends CharacterBody2D
@export var speed = 200
@export var weapon: RangedWeapon
@export var special_ability: Ability
@export var movement: PlayerMovement
# Last direction for idle state
var last_direction = Vector2.DOWN
@onready var animated_sprite = $PlayerSprite
func _ready():
weapon = RangedWeapon.new()
Log.pr("Weapon", weapon)
# Initialize the movement resource with references
if movement:
movement.player = self
movement.animated_sprite = animated_sprite
movement.last_direction = Vector2.DOWN # Default direction
else:
# Create a new resource instance if none was assigned in the editor
movement = PlayerMovement.new()
movement.player = self
movement.animated_sprite = animated_sprite
Log.pr("Adding projectile size additive modifier")
weapon.add_modifier(ProjectileSizeAdditive.new())
Log.pr(weapon.stats.get_stat("projectile_size")) # Size is now 1.0 + 0.5 = 1.5
# Size is now 1.0 + 0.5 = 1.5
# Add the multiplicative size modifier (1.5x multiplier)
Log.pr("Adding projectile size multiplicative modifier")
weapon.add_modifier(ProjectileSizeMultiplicative.new())
Log.pr(weapon.stats.get_stat("projectile_size"))
# Size is now 1.5 * 1.5 = 2.25
# Add another additive size modifier (+0.7 or 70% increase)
Log.pr("Adding another projectile size additive modifier", 0.7)
var another_size_mod = ProjectileSizeAdditive.new()
another_size_mod.size_increase = 0.7
weapon.add_modifier(another_size_mod)
Log.pr(weapon.stats.get_stat("projectile_size"))
func _physics_process(delta):
movement.process(delta)

View file

@ -0,0 +1 @@
uid://bq038uo4cm6nv

View file

@ -0,0 +1,48 @@
# PlayerMovement.gd
extends Resource
class_name PlayerMovement
var player: CharacterBody2D
var animated_sprite: AnimatedSprite2D
var speed: float = 300.0
var last_direction: Vector2 = Vector2.ZERO
func process(_delta):
# Get input direction
var direction = Vector2.ZERO
if Input.is_action_pressed("move_right"):
direction.x += 1
if Input.is_action_pressed("move_left"):
direction.x -= 1
if Input.is_action_pressed("move_down"):
direction.y += 1
if Input.is_action_pressed("move_up"):
direction.y -= 1
# Normalize the direction
if direction.length() > 0:
direction = direction.normalized()
last_direction = direction
# Set velocity
player.velocity = direction * speed
# Move the character
player.move_and_slide()
# Update animation
update_animation(direction)
func update_animation(direction):
var anim_name = "idle" # Default animation
if direction == Vector2.ZERO:
# Character is idle
anim_name = "idle"
else:
# Character is moving
anim_name = "walk"
if animated_sprite.animation != anim_name:
animated_sprite.play(anim_name)

View file

@ -0,0 +1 @@
uid://b3wtxr3udscoa