using System; using Cirno.Scripts.Components; using Cirno.Scripts.Resources; using Godot; namespace Cirno.Scripts.Activables; public partial class BulletEmitter : Node2D, IActivable { [Export] public BulletResource BulletResource { get; set; } [Export] public bool EmitOnStart { get; set; } = false; [Export] public float EmitCoolDown { get; private set; } = 1f; [Export] public float Spread { get; set; } = 0f; [Export] public int Count { get; set; } = 1; [Export] public float EmissionRotation { get; set; } = 0f; private BulletSpawner _bulletSpawner; protected bool IsEmitting = false; private double _emitTimer = 0f; public override void _Ready() { _bulletSpawner = GetNode("BulletSpawner"); if (EmitOnStart) { IsEmitting = true; CallDeferred(MethodName.Shoot); } } public override void _Process(double delta) { if (!IsEmitting) return; _emitTimer += delta; if (_emitTimer >= EmitCoolDown) { Shoot(); _emitTimer = 0f; } } public void Shoot() { _bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, Count, Spread, EmissionRotation)); } public bool Activate(ActivationType activationType = ActivationType.Toggle) { switch (activationType) { case ActivationType.Open: case ActivationType.Enable: IsEmitting = true; _emitTimer = 0; break; case ActivationType.Close: case ActivationType.Disable: IsEmitting = false; _emitTimer = 0; break; case ActivationType.Use: case ActivationType.Toggle: IsEmitting = !IsEmitting; _emitTimer = 0; break; case ActivationType.Destroy: break; } return true; } }