Made bullet creation modifier generics

This commit is contained in:
Marco 2025-02-13 14:32:24 +01:00
commit 797e24d766
7 changed files with 46 additions and 10 deletions

View file

@ -22,7 +22,7 @@ public partial class SpiralPattern : AttackPattern
[Export] private BulletOwner owner = BulletOwner.Enemy;
[Export] private DamageType _damageType = DamageType.Neutral;
[Export] private float _bulletDamage = 1f;
[Export] private Resource _modifier;
[Export] private BulletCreationModifier _modifier;
[Export] private Array<Resource> _timeModifiers;
[Export] private bool _targetPlayer = false;
@ -69,7 +69,7 @@ public partial class SpiralPattern : AttackPattern
Spread = spread,
BulletScene = BulletScene,
RotationOffset = angleOffset,
Modifier = _modifier as IBulletModifier,
Modifier = _modifier,
TimeModifiers = _timeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ?? new List<TimeModifier>()
});

View file

@ -17,7 +17,7 @@ public partial class TargetedPattern : AttackPattern
[Export] private int bulletsPerShot = 1;
[Export] private float spread = 0f;
[Export] private BulletOwner owner = BulletOwner.Enemy;
[Export] private Resource modifier;
[Export] private BulletCreationModifier modifier;
private double timer;
private double burstTimer;
@ -42,7 +42,7 @@ public partial class TargetedPattern : AttackPattern
burstTimer += delta;
if (timer < duration && burstTimer >= burstInterval && _gameManager.PlayerPosition.HasValue)
{
spawner.SpawnTargetedBullet(Boss.GlobalPosition, _gameManager.PlayerPosition.Value, bulletSpeed, owner, BulletScene, bulletsPerShot, spread, modifier as IBulletModifier);
spawner.SpawnTargetedBullet(Boss.GlobalPosition, _gameManager.PlayerPosition.Value, bulletSpeed, owner, BulletScene, bulletsPerShot, spread, modifier);
burstTimer = 0;
}
}

View file

@ -0,0 +1,9 @@
using Godot;
namespace Cirno.Scripts.Resources;
[GlobalClass]
public abstract partial class BulletCreationModifier : Resource, IBulletModifier
{
public abstract float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
}

View file

@ -19,7 +19,7 @@ public partial class BulletResource : Resource
[Export] public DamageType DamageType = DamageType.Neutral;
[Export]
public Resource Modifier;
public BulletCreationModifier Modifier;
[Export] public Array<Resource> TimeModifiers;
public BulletInfo MakeBullet(Vector2 position, int count = 1, float spread = 0f, float rotationOffset = 0f)
@ -36,7 +36,7 @@ public partial class BulletResource : Resource
Spread = spread,
BulletScene = BulletScene,
RotationOffset = rotationOffset,
Modifier = Modifier as IBulletModifier,
Modifier = Modifier,
LifeTime = LifeTime,
DestructionParticlesScene = DestructionParticlesScene,
TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ??

View file

@ -3,11 +3,11 @@
namespace Cirno.Scripts.Resources;
[GlobalClass]
public partial class DecreasingSpeedModifier : Resource, IBulletModifier
public partial class DecreasingSpeedModifier : BulletCreationModifier, IBulletModifier
{
[Export] private float decreaseRate = 0.1f;
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
{
return Mathf.Max(0, baseSpeed - (decreaseRate * bulletIndex));
}

View file

@ -3,7 +3,7 @@
namespace Cirno.Scripts.Resources;
[GlobalClass]
public partial class SpeedModifier : Resource, IBulletModifier
public partial class SpeedModifier : BulletCreationModifier, IBulletModifier
{
[Export] public SpeedModifierType ModifierType;
[Export] public EasingType Easing;
@ -11,7 +11,7 @@ public partial class SpeedModifier : Resource, IBulletModifier
[Export] public float MinimumSpeed = 10f;
[Export] public float ScalingFactor = 10.0f;
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
{
if (totalBullets <= 1)
return baseSpeed;