cirnogodot/Scripts/AttackPatterns/SpiralPattern.cs

122 lines
4.4 KiB
C#
Raw Normal View History

2025-02-09 11:48:30 +01:00
using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Actors;
2025-02-05 19:41:49 +01:00
using Cirno.Scripts.Components;
using Cirno.Scripts.Resources;
using Godot;
2025-02-09 11:48:30 +01:00
using Godot.Collections;
2025-02-13 18:25:55 +01:00
using Array = System.Array;
2025-02-05 19:41:49 +01:00
namespace Cirno.Scripts.AttackPatterns;
[GlobalClass]
public partial class SpiralPattern : AttackPattern
{
2025-02-20 17:43:05 +01:00
[Export] public BulletResource BulletResource { get; set; }
2025-02-05 19:41:49 +01:00
[Export] public PackedScene BulletScene;
2025-02-20 17:43:05 +01:00
[Export] private float _bulletLifeTime = 20f; // Switch to res
[Export] private bool _destroyOnCollision = false; // Switch to res
[Export] private float bulletSpeed = 5f; // Switch to res
2025-02-05 19:41:49 +01:00
[Export] private int bulletCount = 16;
2025-02-09 09:37:43 +01:00
[Export] private float rotationSpeed = 0f;
[Export] private float _rotationOffset = 0f;
2025-02-05 19:41:49 +01:00
[Export] private float duration = 5f;
[Export] private float burstInterval = 0.5f;
[Export] private float spread = 360f;
2025-02-20 17:43:05 +01:00
[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
2025-02-14 10:59:32 +01:00
[ExportGroup("Modifiers")]
2025-02-13 14:32:24 +01:00
[Export] private BulletCreationModifier _modifier;
2025-02-14 10:59:32 +01:00
[ExportGroup("Modifiers")]
2025-02-13 18:25:55 +01:00
[Export] private Array<TimeModifier> _timeModifiers;
2025-02-05 19:41:49 +01:00
2025-02-12 16:51:00 +01:00
[Export] private bool _targetPlayer = false;
2025-02-05 19:41:49 +01:00
private double timer;
private double burstTimer;
private BulletSpawner spawner;
2025-02-12 16:51:00 +01:00
2025-02-05 19:41:49 +01:00
public override void Start(Boss boss)
{
Boss = boss;
timer = 0;
burstTimer = burstInterval; // start immediately
spawner = boss.GetNode<BulletSpawner>("BulletSpawner");
}
public override void UpdatePattern(double delta)
{
timer += delta;
burstTimer += delta;
if (timer < duration && burstTimer >= burstInterval)
{
2025-02-12 16:51:00 +01:00
float angleOffset = _rotationOffset + (float)(rotationSpeed * timer);
2025-02-20 17:43:05 +01:00
Vector2 direction = BulletResource.Direction;
2025-02-12 16:51:00 +01:00
if (_targetPlayer && Boss.GameManager.PlayerPosition.HasValue)
{
direction = (Boss.GameManager.PlayerPosition.Value - Boss.GlobalPosition).Normalized();
}
2025-02-20 17:43:05 +01:00
var bullet = BulletResource.MakeBullet(Boss.GlobalPosition, bulletCount, spread, angleOffset);
bullet.Direction = direction;
2025-02-09 09:37:43 +01:00
2025-02-20 17:43:05 +01:00
//spawner.SpawnBullet(MakeBullet(Boss.GlobalPosition, direction, angleOffset));
spawner.SpawnBullet(bullet);
2025-02-14 10:59:32 +01:00
// 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<TimeModifier>()).Select(m => new ModifierWrapper()
// {
// TimeModifier = m,
// Applied = false
// }).ToList()
// });
burstTimer = 0;
}
}
protected virtual BulletInfo MakeBullet(Vector2 position, Vector2 direction, float angleOffset)
{
2025-02-20 17:43:05 +01:00
var bl = BulletResource.MakeBullet(position, bulletCount, angleOffset);
bl.Direction = direction;
2025-02-14 10:59:32 +01:00
return new BulletInfo()
{
Position = position,
Direction = direction,
2025-02-20 16:22:05 +01:00
LifeTime = _bulletLifeTime,
DestroyOnCollision = _destroyOnCollision,
2025-02-14 10:59:32 +01:00
Speed = bulletSpeed,
Owner = owner,
DamageType = _damageType,
Damage = _bulletDamage,
BulletCount = bulletCount,
Spread = spread,
BulletScene = BulletScene,
RotationOffset = angleOffset,
Modifier = _modifier,
2025-02-14 16:18:33 +01:00
TimeModifiers = _timeModifiers.ToList()// _timeModifiers.Select(x => x.MakeClone()).ToList()
2025-02-14 14:24:26 +01:00
// TimeModifiers = _timeModifiers?.Where(mod => mod != null).ToList() ?? new List<TimeModifier>()
2025-02-14 10:59:32 +01:00
};
2025-02-05 19:41:49 +01:00
}
public override bool IsComplete()
{
return timer >= duration;
}
}