SupaLidlGame/Items/Weapons/ProjectileSpawner.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2023-08-05 23:50:08 -07:00
using Godot;
namespace SupaLidlGame.Items.Weapons;
public partial class ProjectileSpawner : Ranged
{
[Export]
public PackedScene Projectile { get; set; }
[Export]
public bool ShouldOverrideProjectileDamage { get; set; } = true;
2023-08-08 00:54:00 -07:00
[Export]
public bool ShouldOverrideVelocity { get; set; } = true;
2023-08-05 23:50:08 -07:00
[Export]
public bool ShouldRotate { get; set; } = true;
public override void Attack()
{
var map = Utils.World.Instance.CurrentMap;
var projectile = map.SpawnEntity<Entities.Projectile>(Projectile);
projectile.Hitbox.Faction = Character.Faction;
projectile.Direction = Character.Target.Normalized();
projectile.GlobalPosition = GlobalPosition;
2023-08-14 14:07:57 -07:00
if (ShouldOverrideVelocity)
{
projectile.Speed = InitialVelocity;
}
2023-08-05 23:50:08 -07:00
if (ShouldRotate)
{
projectile.GlobalRotation = projectile.Direction.Angle();
}
if (ShouldOverrideProjectileDamage)
{
if (projectile.Hitbox is not null)
{
projectile.Hitbox.Damage = Damage;
}
}
if (projectile is Utils.ITarget target)
{
if (Character is Characters.NPC npc)
{
target.CharacterTarget = npc.FindBestTarget();
}
}
2023-08-14 14:07:57 -07:00
Character.Inventory.EmitSignal("UsedItem", this);
2023-08-05 23:50:08 -07:00
}
}