using System; using Decimation.Lib.Items; using Decimation.Lib.Util; 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 { get { if (Sibling >= 0 && Sibling < Main.projectile.Length) { Projectile sibling = Main.projectile[Sibling]; if (sibling.active) { Main.NewText("test"); return sibling; } } return 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; private readonly Vector3 _dustColor = LightingUtils.Rgb255ToRgb1(106, 232, 184); 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) { DustUtils.NewDustCircle(8, projectile.position, projectile.width, projectile.height, 229, 1.5f * projectile.scale, gravity: true); } public override void AI() { if (!IsChild) { if (SiblingProjectile == null) { 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 if (SiblingProjectile != null) { 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, _dustColor); Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 229, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default, 1f * projectile.scale); dust.noGravity = true; } } }