summaryrefslogtreecommitdiff
path: root/Weapon.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Weapon.cs')
-rw-r--r--Weapon.cs39
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