summaryrefslogtreecommitdiff
path: root/Weapon.cs
diff options
context:
space:
mode:
authoralex <[email protected]>2026-11-23 12:00:20 +0100
committeralex <[email protected]>2026-11-23 12:00:20 +0100
commit7f4bd1856869d7ae10fa8f07708fbd75c5bb7b1e (patch)
treee1fa2d87a79bc8bae87da9e62b19521fe27643e5 /Weapon.cs
parent45326f4f10ba2af92ff5d35f0f63e1dc35a4f8eb (diff)
downloadgodot-testing-items.tar.xz
godot-testing-items.zip
Diffstat (limited to 'Weapon.cs')
-rw-r--r--Weapon.cs33
1 files changed, 26 insertions, 7 deletions
diff --git a/Weapon.cs b/Weapon.cs
index d987d68..2e75f55 100644
--- a/Weapon.cs
+++ b/Weapon.cs
@@ -2,7 +2,7 @@ using Godot;
public partial class Weapon : Node2D
{
- [Export] public PackedScene BulletScene { get; set; }
+ [Export] public PackedScene? BulletScene { get; set; }
[Export] public bool PierceEntity { get; set; } = false;
[Export] public bool PierceTerrain { get; set; } = false;
// Future-proofing: Different weapons can have different damage multipliers!
@@ -17,7 +17,8 @@ public partial class Weapon : Node2D
// 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().GetParent().GetNodeOrNull<StatsComponent>("StatsComponent");
+ var statsComponent = GetParent()?.GetParent()?.GetNodeOrNull<StatsComponent>("StatsComponent");
+ var buildComponent = GetParent()?.GetParent()?.GetNodeOrNull<PlayerBuildComponent>("PlayerBuildComponent");
float finalDamage = 10.0f; // Fallback default
@@ -28,14 +29,32 @@ public partial class Weapon : Node2D
}
// 3. Instantiate and configure the bullet
- Bullet bullet = (Bullet)BulletScene.Instantiate();
+ Bullet bullet = BulletScene.Instantiate<Bullet>();
bullet.GlobalPosition = GlobalPosition; // Spawns right where the weapon node is!
bullet.Direction = Vector2.Right.Rotated(GlobalRotation);
- bullet.Damage = finalDamage;
- bullet.PierceEntity = PierceEntity;
- bullet.PierceTerrain = PierceTerrain;
+
+ ProjectileBuildData projectileData = buildComponent?.BuildProjectileData(
+ finalDamage,
+ bullet.Speed,
+ PierceEntity,
+ PierceTerrain) ?? new ProjectileBuildData
+ {
+ Damage = finalDamage,
+ Speed = bullet.Speed,
+ PierceEntity = PierceEntity,
+ PierceTerrain = PierceTerrain,
+ EntityPierceCount = 0,
+ BounceLimitBonus = 0
+ };
+
+ bullet.Damage = projectileData.Damage;
+ bullet.Speed = projectileData.Speed;
+ bullet.PierceEntity = projectileData.PierceEntity;
+ bullet.PierceTerrain = projectileData.PierceTerrain;
+ bullet.EntityPierceCount = projectileData.EntityPierceCount;
+ bullet.BounceLimit += projectileData.BounceLimitBonus;
// 4. Add it to the world
GetTree().Root.AddChild(bullet);
}
-} \ No newline at end of file
+}