113 lines
4.2 KiB
C#
113 lines
4.2 KiB
C#
using CalamityMod.Buffs.Summon;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.DataStructures;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.Projectiles.Summon
|
|
{
|
|
public class BlackDragonTail : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Summon";
|
|
public int segmentIndex = 1;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
ProjectileID.Sets.MinionSacrificable[Type] = false;
|
|
ProjectileID.Sets.MinionTargettingFeature[Type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.timeLeft = 10;
|
|
Projectile.width = 26;
|
|
Projectile.height = 26;
|
|
Projectile.friendly = true;
|
|
Projectile.penetrate = -1;
|
|
Projectile.timeLeft = 180;
|
|
Projectile.localNPCHitCooldown = 30;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.tileCollide = false;
|
|
Projectile.extraUpdates = 0;
|
|
Projectile.aiStyle = -1;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
Projectile.netImportant = true;
|
|
Projectile.minion = true;
|
|
|
|
}
|
|
public override void AI()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
if (player.Calamity().celestialDragons)
|
|
{
|
|
Projectile.timeLeft = 2;
|
|
}
|
|
}
|
|
internal void SegmentMove()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
var live = false;
|
|
Projectile nextSegment = new Projectile();
|
|
BlackDragonHead head = new BlackDragonHead();
|
|
|
|
for (int i = 0; i < Main.maxProjectiles; i++)
|
|
{
|
|
var projectile = Main.projectile[i];
|
|
if (projectile.type == ModContent.ProjectileType<BlackDragonBody>() && projectile.owner == Projectile.owner && projectile.active)
|
|
{
|
|
if (projectile.ModProjectile<BlackDragonBody>().segmentIndex == segmentIndex - 1)
|
|
{
|
|
live = true;
|
|
nextSegment = projectile;
|
|
}
|
|
}
|
|
if (projectile.type == ModContent.ProjectileType<BlackDragonHead>() && projectile.owner == Projectile.owner && projectile.active)
|
|
{
|
|
if (segmentIndex == 1)
|
|
{
|
|
live = true;
|
|
nextSegment = projectile;
|
|
}
|
|
head = projectile.ModProjectile<BlackDragonHead>();
|
|
}
|
|
}
|
|
if (!live) Projectile.Kill();
|
|
Vector2 destinationOffset = nextSegment.Center - Projectile.Center;
|
|
if (nextSegment.rotation != Projectile.rotation)
|
|
{
|
|
float angle = MathHelper.WrapAngle(nextSegment.rotation - Projectile.rotation);
|
|
//destinationOffset = Projectile.Center.DirectionTo(nextSegment.Center);
|
|
destinationOffset = destinationOffset.RotatedBy(angle * 0.1f);
|
|
}
|
|
Projectile.rotation = destinationOffset.ToRotation();
|
|
if (destinationOffset != Vector2.Zero)
|
|
{
|
|
Projectile.Center = nextSegment.Center - destinationOffset.SafeNormalize(Vector2.Zero) * 20f;
|
|
}
|
|
Projectile.velocity = Vector2.Zero;
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType<BlackDragonHead>()] > 0)
|
|
{
|
|
for (int i = 0; i < Main.maxProjectiles; i++)
|
|
{
|
|
var projectile = Main.projectile[i];
|
|
if (projectile.type == ModContent.ProjectileType<BlackDragonHead>() && projectile.owner == Projectile.owner && projectile.active)
|
|
{
|
|
projectile.Kill();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.ShadowFlame, 300);
|
|
}
|
|
}
|