111 lines
3.5 KiB
C#
111 lines
3.5 KiB
C#
using System;
|
|
using Decimation.Lib.Items;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
|
|
namespace Decimation.Content.Projectiles.Boss.DuneWyrm
|
|
{
|
|
public class Timekeeper : DecimationProjectile
|
|
{
|
|
protected override int Damages => 45;
|
|
protected override DecimationWeapon.DamageType DamageType => DecimationWeapon.DamageType.Ranged;
|
|
|
|
private int Sibling
|
|
{
|
|
get => (int) projectile.localAI[0];
|
|
set => projectile.localAI[0] = value;
|
|
}
|
|
|
|
private float Rotation
|
|
{
|
|
get => projectile.localAI[1];
|
|
set => projectile.localAI[1] = value;
|
|
}
|
|
|
|
private Projectile SiblingProjectile =>
|
|
Sibling >= 0 && Sibling < Main.projectile.Length ? Main.projectile[Sibling] : null;
|
|
|
|
private int Counter
|
|
{
|
|
get => (int) projectile.ai[0];
|
|
set => projectile.ai[0] = value;
|
|
}
|
|
|
|
private bool IsChild => projectile.ai[1] == 1f;
|
|
|
|
private float Speed { get; set; }
|
|
private bool Initialization { get; set; } = true;
|
|
|
|
protected override void Init()
|
|
{
|
|
projectile.width = 12;
|
|
projectile.height = 12;
|
|
projectile.penetrate = -1;
|
|
projectile.aiStyle = -1;
|
|
projectile.timeLeft = 600;
|
|
|
|
Sibling = -1;
|
|
}
|
|
|
|
public override bool PreKill(int timeLeft)
|
|
{
|
|
SiblingProjectile?.Kill();
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
Dust.NewDust(projectile.position, projectile.width, projectile.height, 135, 0,
|
|
0, 100, default, 4f * projectile.scale);
|
|
}
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (!IsChild)
|
|
{
|
|
if (Sibling == -1)
|
|
{
|
|
projectile.position.Y -= 8f;
|
|
|
|
Rotation = projectile.velocity.ToRotation();
|
|
Speed = projectile.velocity.Length();
|
|
|
|
Sibling = Projectile.NewProjectile(projectile.position, new Vector2(Speed, Rotation),
|
|
projectile.type,
|
|
projectile.damage, projectile.knockBack, projectile.owner, 0, 1);
|
|
}
|
|
|
|
// Parent
|
|
Vector2 parentVelocity = new Vector2(0, 1) * (float) (1.5f * Math.Sin(Counter * (1 / 8f)));
|
|
parentVelocity.X = Speed;
|
|
projectile.velocity = parentVelocity.RotatedBy(Rotation);
|
|
|
|
// Sibling
|
|
Vector2 siblingVelocity = parentVelocity * new Vector2(1, -1);
|
|
SiblingProjectile.velocity = siblingVelocity.RotatedBy(Rotation);
|
|
|
|
if (Initialization)
|
|
{
|
|
Vector2 offset = new Vector2(projectile.position.X - SiblingProjectile.position.X, -16);
|
|
projectile.velocity += offset.RotatedBy(Rotation);
|
|
|
|
Initialization = false;
|
|
}
|
|
|
|
Counter++;
|
|
}
|
|
else if (IsChild && Sibling == -1)
|
|
{
|
|
Sibling = projectile.owner;
|
|
}
|
|
|
|
Lighting.AddLight(projectile.Center, 0f, 0f, 1f);
|
|
Dust.NewDust(projectile.position, projectile.width, projectile.height, 135, projectile.velocity.X * 0.2f,
|
|
projectile.velocity.Y * 0.2f, 100, default, 2f * projectile.scale);
|
|
}
|
|
}
|
|
} |