using ColdMint.scripts.projectile;
using ColdMint.scripts.utils;
using ColdMint.scripts.weapon;
using Godot;
namespace ColdMint.scripts.spell;
///
/// MultipleFireSpell
/// 多重射击法术
///
///
///Use this spell to create shotgun effects
///通过此法术打造霰弹枪的效果
///
public partial class MultipleFireSpell : SpellPickAble
{
///
/// How many projectiles are generated per fire
/// 每次开火生成多少个抛射体
///
[Export]
public int NumberOfProjectiles { get; set; } = 3;
///
/// RandomAngle
/// 随机角度
///
[Export]
public bool RandomAngle { get; set; }
///
/// Unit radian
/// 单位弧度
///
///
///Unit radian of correction for the projectile Angle.Suppose there are three bullets fired at once, and this is the arc between the two bullets.
///对抛射体角度修正的单位弧度。假定有三颗子弹一次发射,这是两颗子弹之间的弧度。
///
[Export]
public float UnitRadian { get; set; } = 0.069813f;
///
/// initial Radian
/// 起始弧度
///
///
///The Angle of the first bullet, and subsequent bullets will be offset in unit radians.
///第一颗子弹的角度,随后的子弹会以单位弧度偏移。
///
private float _initialRadian;
private float _maxRadian;
private int _oldNumberOfProjectiles;
public override void ModifyWeapon(ProjectileWeapon projectileWeapon)
{
base.ModifyWeapon(projectileWeapon);
_oldNumberOfProjectiles = projectileWeapon.NumberOfProjectiles;
projectileWeapon.NumberOfProjectiles = NumberOfProjectiles;
_initialRadian = -(NumberOfProjectiles / 2f * UnitRadian);
_maxRadian = NumberOfProjectiles * UnitRadian;
}
public override void RestoreWeapon(ProjectileWeapon projectileWeapon)
{
base.RestoreWeapon(projectileWeapon);
projectileWeapon.NumberOfProjectiles = _oldNumberOfProjectiles;
}
public override void ModifyProjectile(int index, Projectile projectile, ref Vector2 velocity)
{
base.ModifyProjectile(index, projectile, ref velocity);
if (RandomAngle)
{
velocity = velocity.Rotated(_initialRadian + _maxRadian * RandomUtils.Instance.NextSingle());
}
else
{
velocity = velocity.Rotated(_initialRadian + UnitRadian * index);
}
}
}