122 lines
4.6 KiB
C#
122 lines
4.6 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 WhiteDragonBody : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Summon";
|
|
public int segmentIndex = 1;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projPet[Projectile.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.idStaticNPCHitCooldown = 4;
|
|
Projectile.usesIDStaticNPCImmunity = true;
|
|
Projectile.tileCollide = false;
|
|
Projectile.extraUpdates = 0;
|
|
Projectile.aiStyle = -1;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
Projectile.netImportant = true;
|
|
Projectile.minion = true;
|
|
}
|
|
|
|
public override void OnSpawn(IEntitySource source)
|
|
{
|
|
foreach (var projectile in Main.projectile)
|
|
{
|
|
if (projectile.type == ModContent.ProjectileType<WhiteDragonTail>() && projectile.owner == Projectile.owner && projectile.active)
|
|
{
|
|
segmentIndex = projectile.ModProjectile<WhiteDragonTail>().segmentIndex;
|
|
projectile.ModProjectile<WhiteDragonTail>().segmentIndex++;
|
|
}
|
|
}
|
|
}
|
|
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();
|
|
WhiteDragonHead head = new WhiteDragonHead();
|
|
for (int i = 0; i < Main.maxProjectiles; i++)
|
|
{
|
|
var projectile = Main.projectile[i];
|
|
if (projectile.type == Type && projectile.owner == Projectile.owner && projectile.active)
|
|
{
|
|
if (projectile.ModProjectile<WhiteDragonBody>().segmentIndex == segmentIndex - 1)
|
|
{
|
|
live = true;
|
|
nextSegment = projectile;
|
|
}
|
|
}
|
|
if (projectile.type == ModContent.ProjectileType<WhiteDragonHead>() && projectile.owner == Projectile.owner && projectile.active)
|
|
{
|
|
if (segmentIndex == 1)
|
|
{
|
|
live = true;
|
|
nextSegment = projectile;
|
|
}
|
|
head = projectile.ModProjectile<WhiteDragonHead>();
|
|
}
|
|
}
|
|
if (!live) Projectile.Kill();
|
|
Vector2 destinationOffset = nextSegment.Center+nextSegment.velocity - 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+nextSegment.velocity - destinationOffset.SafeNormalize(Vector2.Zero) * 20f;
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
return false;
|
|
}
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType<WhiteDragonHead>()] > 0)
|
|
{
|
|
for (int i = 0; i < Main.maxProjectiles; i++)
|
|
{
|
|
var projectile = Main.projectile[i];
|
|
if (projectile.type == ModContent.ProjectileType<WhiteDragonHead>() && projectile.owner == Projectile.owner && projectile.active)
|
|
{
|
|
projectile.Kill();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.Frostburn2, 300);
|
|
}
|
|
}
|