mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
109 lines
3.6 KiB
C#
109 lines
3.6 KiB
C#
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 PackedScene BulletScene;
|
|
[Export] private float bulletSpeed = 5f;
|
|
[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;
|
|
[Export] private DamageType _damageType = DamageType.Neutral;
|
|
[Export] private float _bulletDamage = 1f;
|
|
[ExportGroup("Modifiers")]
|
|
[Export] private BulletCreationModifier _modifier;
|
|
[ExportGroup("Modifiers")]
|
|
[Export] private Array<TimeModifier> _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>("BulletSpawner");
|
|
}
|
|
|
|
public override void UpdatePattern(double delta)
|
|
{
|
|
timer += delta;
|
|
burstTimer += delta;
|
|
if (timer < duration && burstTimer >= burstInterval)
|
|
{
|
|
float angleOffset = _rotationOffset + (float)(rotationSpeed * timer);
|
|
|
|
Vector2 direction = Vector2.Right;
|
|
|
|
if (_targetPlayer && Boss.GameManager.PlayerPosition.HasValue)
|
|
{
|
|
direction = (Boss.GameManager.PlayerPosition.Value - Boss.GlobalPosition).Normalized();
|
|
}
|
|
|
|
spawner.SpawnBullet(MakeBullet(Boss.GlobalPosition, direction, angleOffset));
|
|
|
|
// 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)
|
|
{
|
|
return new BulletInfo()
|
|
{
|
|
Position = position,
|
|
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).ToList() ?? new List<TimeModifier>()
|
|
};
|
|
}
|
|
|
|
public override bool IsComplete()
|
|
{
|
|
return timer >= duration;
|
|
}
|
|
}
|