185 lines
6.3 KiB
C#
185 lines
6.3 KiB
C#
using CalamityMod.CalPlayer;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.Projectiles.Pets
|
|
{
|
|
public class RadiatorPet : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Pets";
|
|
private bool fly = false;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projFrames[Projectile.type] = 4;
|
|
Main.projPet[Projectile.type] = true;
|
|
ProjectileID.Sets.LightPet[Projectile.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.netImportant = true;
|
|
Projectile.width = 34;
|
|
Projectile.height = 22;
|
|
Projectile.friendly = true;
|
|
Projectile.penetrate = -1;
|
|
Projectile.timeLeft *= 5;
|
|
Projectile.tileCollide = true;
|
|
}
|
|
|
|
public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac)
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
Vector2 center2 = Projectile.Center;
|
|
Vector2 vector48 = player.Center - center2;
|
|
float playerDistance = vector48.Length();
|
|
fallThrough = playerDistance > 200f;
|
|
return true;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
if (!player.active)
|
|
{
|
|
Projectile.active = false;
|
|
return;
|
|
}
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
if (player.dead)
|
|
{
|
|
modPlayer.radiator = false;
|
|
}
|
|
if (modPlayer.radiator)
|
|
{
|
|
Projectile.timeLeft = 2;
|
|
}
|
|
if (Projectile.position.X == Projectile.oldPosition.X && Projectile.position.Y == Projectile.oldPosition.Y && Projectile.velocity.X == 0)
|
|
{
|
|
Projectile.frame = 0;
|
|
}
|
|
else if (Projectile.velocity.Y > 0.3f && Projectile.position.Y != Projectile.oldPosition.Y)
|
|
{
|
|
Projectile.frame = 1;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
else
|
|
{
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter > 6)
|
|
{
|
|
Projectile.frame++;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
if (Projectile.frame > 3)
|
|
{
|
|
Projectile.frame = 0;
|
|
}
|
|
}
|
|
Lighting.AddLight(Projectile.Center, 0.4f, 1f, 0.5f);
|
|
Vector2 vector46 = Projectile.position;
|
|
if (!fly)
|
|
{
|
|
Projectile.rotation = 0;
|
|
Vector2 center2 = Projectile.Center;
|
|
Vector2 vector48 = player.Center - center2;
|
|
float playerDistance = vector48.Length();
|
|
if (Projectile.velocity.Y == 0 && (HoleBelow() || (playerDistance > 110f && Projectile.position.X == Projectile.oldPosition.X)))
|
|
{
|
|
Projectile.velocity.Y = -5f;
|
|
}
|
|
Projectile.velocity.Y += 0.20f;
|
|
if (Projectile.velocity.Y > 7f)
|
|
{
|
|
Projectile.velocity.Y = 7f;
|
|
}
|
|
if (playerDistance > 600f)
|
|
{
|
|
fly = true;
|
|
Projectile.velocity.X = 0f;
|
|
Projectile.velocity.Y = 0f;
|
|
}
|
|
if (playerDistance > 100f)
|
|
{
|
|
if (player.position.X - Projectile.position.X > 0f)
|
|
{
|
|
Projectile.velocity.X += 0.10f;
|
|
if (Projectile.velocity.X > 7f)
|
|
{
|
|
Projectile.velocity.X = 7f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Projectile.velocity.X -= 0.10f;
|
|
if (Projectile.velocity.X < -7f)
|
|
{
|
|
Projectile.velocity.X = -7f;
|
|
}
|
|
}
|
|
}
|
|
if (playerDistance < 100f)
|
|
{
|
|
if (Projectile.velocity.X != 0f)
|
|
{
|
|
if (Projectile.velocity.X > 0.5f)
|
|
{
|
|
Projectile.velocity.X -= 0.15f;
|
|
}
|
|
else if (Projectile.velocity.X < -0.5f)
|
|
{
|
|
Projectile.velocity.X += 0.15f;
|
|
}
|
|
else if (Projectile.velocity.X < 0.5f && Projectile.velocity.X > -0.5f)
|
|
{
|
|
Projectile.velocity.X = 0f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (fly)
|
|
{
|
|
Projectile.alpha += 15;
|
|
if (Projectile.alpha >= 255)
|
|
{
|
|
Projectile.position.X = player.position.X;
|
|
Projectile.position.Y = player.position.Y;
|
|
fly = false;
|
|
Projectile.alpha = 0;
|
|
}
|
|
}
|
|
if (Projectile.velocity.X > 0.25f)
|
|
{
|
|
Projectile.spriteDirection = -1;
|
|
}
|
|
else if (Projectile.velocity.X < -0.25f)
|
|
{
|
|
Projectile.spriteDirection = 1;
|
|
}
|
|
}
|
|
|
|
private bool HoleBelow() //pretty much the same as the one used in mantis
|
|
{
|
|
int tileWidth = 4;
|
|
int tileX = (int)(Projectile.Center.X / 16f) - tileWidth;
|
|
if (Projectile.velocity.X > 0)
|
|
{
|
|
tileX += tileWidth;
|
|
}
|
|
int tileY = (int)((Projectile.position.Y + Projectile.height) / 16f);
|
|
for (int y = tileY; y < tileY + 2; y++)
|
|
{
|
|
for (int x = tileX; x < tileX + tileWidth; x++)
|
|
{
|
|
if (Main.tile[x, y].HasTile)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|