diff options
| author | alex <[email protected]> | 2026-07-24 23:33:46 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-24 23:33:46 +0200 |
| commit | 91fd5d80808fd177f97c4cc7e78b704efb5d6ce3 (patch) | |
| tree | fc0dee06eae293afb5e429fa0956455aee585f01 /Weapon.cs | |
| parent | 6b666c7f25121e61bf1c58ee65cb2cd0f254b887 (diff) | |
| download | godot-testing-91fd5d80808fd177f97c4cc7e78b704efb5d6ce3.tar.xz godot-testing-91fd5d80808fd177f97c4cc7e78b704efb5d6ce3.zip | |
improved stats resource, weapon now uses dmg from player stats
Diffstat (limited to 'Weapon.cs')
| -rw-r--r-- | Weapon.cs | 39 |
1 files changed, 39 insertions, 0 deletions
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>("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 |
