cirnogodot/Scripts/Resources/BulletResource.cs
2025-07-01 13:40:13 +02:00

75 lines
No EOL
2.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Components;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Resources;
[GlobalClass]
[Tool]
public partial class BulletResource : Resource
{
[Export]
public PackedScene BulletScene { get; set; }
[Export] public Texture2D BulletSprite { get; set; }
[Export] public float BulletSize { get; set; }
[Export] public PackedScene DestructionParticlesScene { get; set; }
[Export] public float BulletSpeed = 100f;
[Export] public Vector2 Direction = Vector2.Right;
[Export] public float BulletDamage = 1;
[Export] public float MaxDamage = 1;
[Export] public float Knockback = 1;
[Export] public float LifeTime = 10f;
[Export] public BulletOwner Owner = BulletOwner.None;
[Export] public DamageType DamageType = DamageType.Neutral;
[Export] public float GrazeValue { get; set; } = 0.2f;
[Export] public BulletFlags Attributes { get; set; }
[Export]
public BulletCreationModifier Modifier;
[Export] public Array<TimeModifier> TimeModifiers;
public BulletInfo MakeBullet(Vector2 position, int count = 1, float spread = 0f, float rotationOffset = 0f)
{
return new BulletInfo(this)
{
Position = position,
Direction = Direction,
Speed = BulletSpeed,
Owner = Owner,
DamageType = DamageType,
Damage = BulletDamage,
Knockback = Knockback,
BulletCount = count,
Spread = spread,
BulletScene = BulletScene,
RotationOffset = rotationOffset,
Modifier = Modifier,
LifeTime = LifeTime,
DestroyOnCollision = Attributes.HasNoFlags(BulletFlags.Piercing),
DestructionParticlesScene = DestructionParticlesScene,
RotateSprite = Attributes.HasFlag(BulletFlags.Rotateable),
Controllabe = Attributes.HasFlag(BulletFlags.Controllable),
Freezable = Attributes.HasFlag(BulletFlags.Freezable),
TimeModifiers = TimeModifiers.Select(x => x).ToList(),
Grazeable = Attributes.HasFlag(BulletFlags.Grazeable),
GrazeValue = GrazeValue,
Attributes = Attributes,
// TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().Select(m => new ModifierWrapper()
// {
// TimeModifier = m,
// Applied = false
// }).ToList()
// TimeModifiers = TimeModifiers?.Select(x => new ModifierWrapper()
// {
// Applied = false,
// TimeModifier = x
// })
// TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ??
// new List<TimeModifier>()
};
}
}