100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.Projectiles.Ranged
|
|
{
|
|
public class TriploonProj : ModProjectile
|
|
{
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Triploon");
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 4;
|
|
Projectile.height = 4;
|
|
Projectile.friendly = true;
|
|
Projectile.penetrate = 1;
|
|
Projectile.alpha = 255;
|
|
Projectile.DamageType = DamageClass.Ranged;
|
|
Projectile.extraUpdates = 0;
|
|
Projectile.timeLeft = 300;
|
|
Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.basePointBlankShotDuration;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
if (player.dead)
|
|
{
|
|
Projectile.Kill();
|
|
return;
|
|
}
|
|
if (Projectile.alpha == 0)
|
|
{
|
|
if (Projectile.Center.X > player.Center.X)
|
|
{
|
|
player.ChangeDir(1);
|
|
}
|
|
else
|
|
{
|
|
player.ChangeDir(-1);
|
|
}
|
|
}
|
|
if (Projectile.ai[0] == 0f)
|
|
{
|
|
Projectile.extraUpdates = 0;
|
|
}
|
|
else
|
|
{
|
|
Projectile.extraUpdates = 1;
|
|
}
|
|
Vector2 playerVector = player.Center - Projectile.Center;
|
|
float playerDist = playerVector.Length();
|
|
if (Projectile.ai[0] == 0f)
|
|
{
|
|
if (playerDist > 700f)
|
|
{
|
|
Projectile.ai[0] = 1f;
|
|
}
|
|
else if (playerDist > 350f)
|
|
{
|
|
Projectile.ai[0] = 1f;
|
|
}
|
|
Projectile.rotation = (float)Math.Atan2((double)Projectile.velocity.Y, (double)Projectile.velocity.X) + MathHelper.PiOver2;
|
|
Projectile.ai[1] += 1f;
|
|
if (Projectile.ai[1] > 5f)
|
|
{
|
|
Projectile.alpha = 0;
|
|
}
|
|
if (Projectile.ai[1] > 8f)
|
|
{
|
|
Projectile.ai[1] = 8f;
|
|
}
|
|
if (Projectile.ai[1] >= 10f)
|
|
{
|
|
Projectile.ai[1] = 15f;
|
|
Projectile.velocity.Y += 0.3f;
|
|
}
|
|
}
|
|
else if (Projectile.ai[0] == 1f)
|
|
{
|
|
Projectile.tileCollide = false;
|
|
Projectile.rotation = (float)Math.Atan2((double)playerVector.Y, (double)playerVector.X) - MathHelper.PiOver2;
|
|
float returnSpeed = 20f;
|
|
if (playerDist < 50f)
|
|
{
|
|
Projectile.Kill();
|
|
}
|
|
playerDist = returnSpeed / playerDist;
|
|
playerVector.X *= playerDist;
|
|
playerVector.Y *= playerDist;
|
|
Projectile.velocity.X = playerVector.X;
|
|
Projectile.velocity.Y = playerVector.Y;
|
|
}
|
|
}
|
|
}
|
|
}
|