mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-05 23:55:54 +00:00
Remade resource script system
This commit is contained in:
parent
4261009c33
commit
029128c8b8
17 changed files with 576 additions and 386 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Actors;
|
||||
using Cirno.Scripts.Components;
|
||||
|
|
@ -13,82 +14,28 @@ namespace Cirno.Scripts.AttackPatterns;
|
|||
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] public int bulletCount = 16;
|
||||
[Export] public float rotationSpeed = 0f;
|
||||
[Export] public float _rotationOffset = 0f;
|
||||
[Export] public float duration = 5f;
|
||||
[Export] public float spread = 360f;
|
||||
[Export] public float burstInterval = 0.5f;
|
||||
|
||||
[ExportCategory("Burst")] [Export] public int ShotsPerBurst { get; private set; } = 100;
|
||||
|
||||
[Export] public float BurstRate { get; private set; } = 0f;
|
||||
|
||||
//[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<TimeModifier> _timeModifiers;
|
||||
|
||||
[Export] private bool _targetPlayer = false;
|
||||
|
||||
private double timer;
|
||||
private double burstTimer;
|
||||
private BulletSpawner spawner;
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
{
|
||||
Parent = parent;
|
||||
timer = 0;
|
||||
burstTimer = burstInterval; // start immediately
|
||||
spawner = parent.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 = BulletResource.Direction;
|
||||
|
||||
if (_targetPlayer && GameManager.Instance.PlayerPosition.HasValue)
|
||||
{
|
||||
direction = (GameManager.Instance.PlayerPosition.Value - Parent.GlobalPosition).Normalized();
|
||||
}
|
||||
|
||||
var bullet = BulletResource.MakeBullet(Parent.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<TimeModifier>()).Select(m => new ModifierWrapper()
|
||||
// {
|
||||
// TimeModifier = m,
|
||||
// Applied = false
|
||||
// }).ToList()
|
||||
// });
|
||||
|
||||
burstTimer = 0;
|
||||
}
|
||||
}
|
||||
// [ExportGroup("Modifiers")] [Export] private BulletCreationModifier _modifier;
|
||||
// [ExportGroup("Modifiers")] [Export] private Array<TimeModifier> _timeModifiers;
|
||||
[ExportCategory("Other")] [Export] public bool _targetPlayer = false;
|
||||
|
||||
protected virtual BulletInfo MakeBullet(Vector2 position, Vector2 direction, float angleOffset)
|
||||
{
|
||||
|
|
@ -96,7 +43,7 @@ public partial class SpiralPattern : AttackPattern
|
|||
bl.Direction = direction;
|
||||
|
||||
return bl;
|
||||
|
||||
|
||||
// return new BulletInfo()
|
||||
// {
|
||||
// Position = position,
|
||||
|
|
@ -117,8 +64,148 @@ public partial class SpiralPattern : AttackPattern
|
|||
// };
|
||||
}
|
||||
|
||||
public override bool IsComplete()
|
||||
public override IPatternMachine MakeMachine(Node2D parent)
|
||||
{
|
||||
return timer >= duration;
|
||||
return new SpiralPatternMachine(this, parent);
|
||||
}
|
||||
}
|
||||
|
||||
public class SpiralPatternMachine(SpiralPattern pattern, Node2D parent) : IPatternMachine
|
||||
{
|
||||
public Node2D Parent => parent;
|
||||
private double timer;
|
||||
private double burstTimer;
|
||||
//private double _burstRateTimer;
|
||||
private BulletSpawner spawner;
|
||||
|
||||
private ShootStatus _state = ShootStatus.Idle;
|
||||
|
||||
private int _burstBullets;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
timer = 0;
|
||||
_burstBullets = pattern.ShotsPerBurst;
|
||||
burstTimer = pattern.burstInterval; // start immediately
|
||||
//_burstRateTimer = pattern.burstInterval;
|
||||
spawner = parent.GetNode<BulletSpawner>("BulletSpawner");
|
||||
|
||||
_state = ShootStatus.Shooting;
|
||||
}
|
||||
|
||||
private void WaitingBurstUpdate(double delta)
|
||||
{
|
||||
timer += delta;
|
||||
burstTimer += delta;
|
||||
|
||||
if (burstTimer >= pattern.burstInterval)
|
||||
{
|
||||
_state = ShootStatus.Shooting;
|
||||
}
|
||||
}
|
||||
|
||||
private void WaitingReloadUpdate(double delta)
|
||||
{
|
||||
timer += delta;
|
||||
burstTimer += delta;
|
||||
|
||||
if (burstTimer >= pattern.BurstRate)
|
||||
{
|
||||
_burstBullets = pattern.ShotsPerBurst;
|
||||
_state = ShootStatus.Shooting;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShootingUpdate(double delta)
|
||||
{
|
||||
timer += delta;
|
||||
burstTimer = 0;
|
||||
Shoot();
|
||||
_burstBullets--;
|
||||
|
||||
if (_burstBullets <= 0)
|
||||
{
|
||||
_state = ShootStatus.WaitingReload;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state = ShootStatus.WaitingBurst;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePattern(double delta)
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case ShootStatus.Idle:
|
||||
case ShootStatus.Done:
|
||||
return;
|
||||
case ShootStatus.Shooting:
|
||||
ShootingUpdate(delta);
|
||||
break;
|
||||
case ShootStatus.WaitingBurst:
|
||||
WaitingBurstUpdate(delta);
|
||||
break;
|
||||
case ShootStatus.WaitingReload:
|
||||
WaitingReloadUpdate(delta);
|
||||
break;
|
||||
}
|
||||
|
||||
if (timer >= pattern.duration)
|
||||
{
|
||||
_state = ShootStatus.Done;
|
||||
}
|
||||
|
||||
// timer += delta;
|
||||
// burstTimer += delta;
|
||||
// //_burstRateTimer += delta;
|
||||
//
|
||||
// if (timer > pattern.duration)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (burstTimer < pattern.burstInterval) return;
|
||||
//
|
||||
// Shoot();
|
||||
//
|
||||
//
|
||||
//
|
||||
// burstTimer = 0;
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
float angleOffset = pattern._rotationOffset + (float)(pattern.rotationSpeed * timer);
|
||||
|
||||
Vector2 direction = pattern.BulletResource.Direction;
|
||||
|
||||
if (pattern._targetPlayer && GameManager.Instance.PlayerPosition.HasValue)
|
||||
{
|
||||
direction = (GameManager.Instance.PlayerPosition.Value - Parent.GlobalPosition).Normalized();
|
||||
}
|
||||
|
||||
var bullet = pattern.BulletResource.MakeBullet(Parent.GlobalPosition, pattern.bulletCount,
|
||||
pattern.spread, angleOffset);
|
||||
bullet.Direction = direction;
|
||||
|
||||
//spawner.SpawnBullet(MakeBullet(Boss.GlobalPosition, direction, angleOffset));
|
||||
spawner.SpawnBullet(bullet);
|
||||
}
|
||||
|
||||
|
||||
public bool IsComplete()
|
||||
{
|
||||
//return timer >= pattern.duration;
|
||||
return _state is ShootStatus.Done;
|
||||
}
|
||||
|
||||
private enum ShootStatus
|
||||
{
|
||||
Idle,
|
||||
Shooting,
|
||||
WaitingBurst,
|
||||
WaitingReload,
|
||||
Done
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue