using System.Collections.Generic; using System.Linq; using Cirno.Scripts.Actors; using Cirno.Scripts.Components; using Cirno.Scripts.Resources; using Godot; using Godot.Collections; using Array = System.Array; namespace Cirno.Scripts.AttackPatterns; [GlobalClass] public partial class SpiralPattern : AttackPattern { [Export] public BulletResource BulletResource { get; set; } [Export] public PackedScene BulletScene; [Export] private float _bulletLifeTime = 20f; // Switch to res [Export] private bool _destroyOnCollision = false; // Switch to res [Export] private float bulletSpeed = 5f; // Switch to res [Export] private int bulletCount = 16; [Export] private float rotationSpeed = 0f; [Export] private float _rotationOffset = 0f; [Export] private float duration = 5f; [Export] private float burstInterval = 0.5f; [Export] private float spread = 360f; [Export] private BulletOwner owner = BulletOwner.Enemy; // Switch to res [Export] private DamageType _damageType = DamageType.Neutral; // Switch to res [Export] private float _bulletDamage = 1f; // Switch to res [ExportGroup("Modifiers")] [Export] private BulletCreationModifier _modifier; [ExportGroup("Modifiers")] [Export] private Array _timeModifiers; [Export] private bool _targetPlayer = false; private double timer; private double burstTimer; private BulletSpawner spawner; public override void Start(Boss boss) { Boss = boss; timer = 0; burstTimer = burstInterval; // start immediately spawner = boss.GetNode("BulletSpawner"); } public override void UpdatePattern(double delta) { timer += delta; burstTimer += delta; if (timer < duration && burstTimer >= burstInterval) { float angleOffset = _rotationOffset + (float)(rotationSpeed * timer); Vector2 direction = BulletResource.Direction; if (_targetPlayer && Boss.GameManager.PlayerPosition.HasValue) { direction = (Boss.GameManager.PlayerPosition.Value - Boss.GlobalPosition).Normalized(); } var bullet = BulletResource.MakeBullet(Boss.GlobalPosition, bulletCount, spread, angleOffset); bullet.Direction = direction; //spawner.SpawnBullet(MakeBullet(Boss.GlobalPosition, direction, angleOffset)); spawner.SpawnBullet(bullet); // spawner.SpawnBullet(new BulletInfo() // { // Position = Boss.GlobalPosition, // Direction = direction, // Speed = bulletSpeed, // Owner = owner, // DamageType = _damageType, // Damage = _bulletDamage, // BulletCount = bulletCount, // Spread = spread, // BulletScene = BulletScene, // RotationOffset = angleOffset, // Modifier = _modifier, // TimeModifiers = ((_timeModifiers?.Where(mod => mod != null)) ?? Array.Empty()).Select(m => new ModifierWrapper() // { // TimeModifier = m, // Applied = false // }).ToList() // }); burstTimer = 0; } } protected virtual BulletInfo MakeBullet(Vector2 position, Vector2 direction, float angleOffset) { var bl = BulletResource.MakeBullet(position, bulletCount, angleOffset); bl.Direction = direction; return new BulletInfo() { Position = position, Direction = direction, LifeTime = _bulletLifeTime, DestroyOnCollision = _destroyOnCollision, Speed = bulletSpeed, Owner = owner, DamageType = _damageType, Damage = _bulletDamage, BulletCount = bulletCount, Spread = spread, BulletScene = BulletScene, RotationOffset = angleOffset, Modifier = _modifier, TimeModifiers = _timeModifiers.ToList()// _timeModifiers.Select(x => x.MakeClone()).ToList() // TimeModifiers = _timeModifiers?.Where(mod => mod != null).ToList() ?? new List() }; } public override bool IsComplete() { return timer >= duration; } }