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

@ -0,0 +1,27 @@
[gd_resource type="Resource" script_class="BossPhase" load_steps=4 format=3 uid="uid://c2xhuinmhit15"]
[ext_resource type="Script" path="res://Scripts/Resources/BossPhase.cs" id="1_cxesb"]
[ext_resource type="Script" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="1_q8vp4"]
[sub_resource type="Resource" id="Resource_8caj3"]
script = ExtResource("1_q8vp4")
bulletSpeed = 5.0
bulletCount = 16
rotationSpeed = 0.0
_rotationOffset = 0.0
duration = 5.0
burstInterval = 0.5
spread = 360.0
owner = 2
_damageType = 0
_bulletDamage = 1.0
_timeModifiers = Array[Resource]([null])
_targetPlayer = false
WaitForCompletion = true
[resource]
script = ExtResource("1_cxesb")
PhaseName = "asdf"
Threshold = 0
PlayAnimation = false
Patterns = Array[Object]([SubResource("Resource_8caj3")])

View file

@ -22,7 +22,7 @@ public partial class SpiralPattern : AttackPattern
[Export] private BulletOwner owner = BulletOwner.Enemy; [Export] private BulletOwner owner = BulletOwner.Enemy;
[Export] private DamageType _damageType = DamageType.Neutral; [Export] private DamageType _damageType = DamageType.Neutral;
[Export] private float _bulletDamage = 1f; [Export] private float _bulletDamage = 1f;
[Export] private Resource _modifier; [Export] private BulletCreationModifier _modifier;
[Export] private Array<Resource> _timeModifiers; [Export] private Array<Resource> _timeModifiers;
[Export] private bool _targetPlayer = false; [Export] private bool _targetPlayer = false;
@ -69,7 +69,7 @@ public partial class SpiralPattern : AttackPattern
Spread = spread, Spread = spread,
BulletScene = BulletScene, BulletScene = BulletScene,
RotationOffset = angleOffset, RotationOffset = angleOffset,
Modifier = _modifier as IBulletModifier, Modifier = _modifier,
TimeModifiers = _timeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ?? new List<TimeModifier>() 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 int bulletsPerShot = 1;
[Export] private float spread = 0f; [Export] private float spread = 0f;
[Export] private BulletOwner owner = BulletOwner.Enemy; [Export] private BulletOwner owner = BulletOwner.Enemy;
[Export] private Resource modifier; [Export] private BulletCreationModifier modifier;
private double timer; private double timer;
private double burstTimer; private double burstTimer;
@ -42,7 +42,7 @@ public partial class TargetedPattern : AttackPattern
burstTimer += delta; burstTimer += delta;
if (timer < duration && burstTimer >= burstInterval && _gameManager.PlayerPosition.HasValue) 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; 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 DamageType DamageType = DamageType.Neutral;
[Export] [Export]
public Resource Modifier; public BulletCreationModifier Modifier;
[Export] public Array<Resource> TimeModifiers; [Export] public Array<Resource> TimeModifiers;
public BulletInfo MakeBullet(Vector2 position, int count = 1, float spread = 0f, float rotationOffset = 0f) 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, Spread = spread,
BulletScene = BulletScene, BulletScene = BulletScene,
RotationOffset = rotationOffset, RotationOffset = rotationOffset,
Modifier = Modifier as IBulletModifier, Modifier = Modifier,
LifeTime = LifeTime, LifeTime = LifeTime,
DestructionParticlesScene = DestructionParticlesScene, DestructionParticlesScene = DestructionParticlesScene,
TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ?? TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ??

View file

@ -3,11 +3,11 @@
namespace Cirno.Scripts.Resources; namespace Cirno.Scripts.Resources;
[GlobalClass] [GlobalClass]
public partial class DecreasingSpeedModifier : Resource, IBulletModifier public partial class DecreasingSpeedModifier : BulletCreationModifier, IBulletModifier
{ {
[Export] private float decreaseRate = 0.1f; [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)); return Mathf.Max(0, baseSpeed - (decreaseRate * bulletIndex));
} }

View file

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