From 91fd5d80808fd177f97c4cc7e78b704efb5d6ce3 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 24 Jul 2026 23:33:46 +0200 Subject: improved stats resource, weapon now uses dmg from player stats --- Weapon.cs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Weapon.cs (limited to 'Weapon.cs') diff --git a/Weapon.cs b/Weapon.cs new file mode 100644 index 0000000..6050cc7 --- /dev/null +++ b/Weapon.cs @@ -0,0 +1,39 @@ +using Godot; + +public partial class Weapon : Node2D +{ + [Export] public PackedScene BulletScene { get; set; } + + // Future-proofing: Different weapons can have different damage multipliers! + [Export] public float DamageMultiplier { get; set; } = 1.0f; + public override void _Process(double delta) + { + LookAt(GetGlobalMousePosition()); + GD.Print("Weapon rotation is running!"); // Add this line + } + public void Fire(Vector2 targetPosition) + { + if (BulletScene == null) return; + + // 1. The weapon itself looks up to find the player's stats component + // (Assuming the weapon is a child of the Player, GetParent() gets the Player) + var statsComponent = GetParent().GetNodeOrNull("StatsComponent"); + + float finalDamage = 10.0f; // Fallback default + + if (statsComponent?.RuntimeStats != null) + { + // 2. The weapon reads the player's base damage and applies its own modifier + finalDamage = statsComponent.RuntimeStats.Damage * DamageMultiplier; + } + + // 3. Instantiate and configure the bullet + Bullet bullet = (Bullet)BulletScene.Instantiate(); + bullet.GlobalPosition = GlobalPosition; // Spawns right where the weapon node is! + bullet.Direction = Vector2.Right.Rotated(GlobalRotation); + bullet.Damage = finalDamage; + + // 4. Add it to the world + GetTree().Root.AddChild(bullet); + } +} \ No newline at end of file -- cgit v1.2.3