167 lines
8.1 KiB
C#
167 lines
8.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Magic
|
|
{
|
|
public class ShiftingSandsProj : ModProjectile
|
|
{
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Shifting Sands");
|
|
ProjectileID.Sets.TrailCacheLength[projectile.type] = 4;
|
|
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
projectile.width = 18;
|
|
projectile.height = 18;
|
|
projectile.friendly = true;
|
|
projectile.penetrate = 5;
|
|
projectile.magic = true;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (projectile.soundDelay == 0 && Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y) > 2f)
|
|
{
|
|
projectile.soundDelay = 10;
|
|
Main.PlaySound(SoundID.Item20, projectile.position);
|
|
}
|
|
int num114 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 85, 0f, 0f, 100, default, 2f);
|
|
Dust dust = Main.dust[num114];
|
|
dust.velocity *= 0.3f;
|
|
Main.dust[num114].position.X = projectile.position.X + (float)(projectile.width / 2) + 4f + (float)Main.rand.Next(-4, 5);
|
|
Main.dust[num114].position.Y = projectile.position.Y + (float)(projectile.height / 2) + (float)Main.rand.Next(-4, 5);
|
|
Main.dust[num114].noGravity = true;
|
|
if (Main.myPlayer == projectile.owner && projectile.ai[0] <= 0f)
|
|
{
|
|
if (Main.player[projectile.owner].channel)
|
|
{
|
|
float num115 = 18f;
|
|
Vector2 vector10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
|
|
float num116 = (float)Main.mouseX + Main.screenPosition.X - vector10.X;
|
|
float num117 = (float)Main.mouseY + Main.screenPosition.Y - vector10.Y;
|
|
if (Main.player[projectile.owner].gravDir == -1f)
|
|
{
|
|
num117 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector10.Y;
|
|
}
|
|
float num118 = (float)Math.Sqrt((double)(num116 * num116 + num117 * num117));
|
|
num118 = (float)Math.Sqrt((double)(num116 * num116 + num117 * num117));
|
|
if (projectile.ai[0] < 0f)
|
|
{
|
|
projectile.ai[0] += 1f;
|
|
}
|
|
if (num118 > num115)
|
|
{
|
|
num118 = num115 / num118;
|
|
num116 *= num118;
|
|
num117 *= num118;
|
|
int num119 = (int)(num116 * 1000f);
|
|
int num120 = (int)(projectile.velocity.X * 1000f);
|
|
int num121 = (int)(num117 * 1000f);
|
|
int num122 = (int)(projectile.velocity.Y * 1000f);
|
|
if (num119 != num120 || num121 != num122)
|
|
{
|
|
projectile.netUpdate = true;
|
|
}
|
|
projectile.velocity.X = num116;
|
|
projectile.velocity.Y = num117;
|
|
}
|
|
else
|
|
{
|
|
int num123 = (int)(num116 * 1000f);
|
|
int num124 = (int)(projectile.velocity.X * 1000f);
|
|
int num125 = (int)(num117 * 1000f);
|
|
int num126 = (int)(projectile.velocity.Y * 1000f);
|
|
if (num123 != num124 || num125 != num126)
|
|
{
|
|
projectile.netUpdate = true;
|
|
}
|
|
projectile.velocity.X = num116;
|
|
projectile.velocity.Y = num117;
|
|
}
|
|
}
|
|
else if (projectile.ai[0] <= 0f)
|
|
{
|
|
projectile.netUpdate = true;
|
|
float num127 = 12f;
|
|
Vector2 vector11 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
|
|
float num128 = (float)Main.mouseX + Main.screenPosition.X - vector11.X;
|
|
float num129 = (float)Main.mouseY + Main.screenPosition.Y - vector11.Y;
|
|
if (Main.player[projectile.owner].gravDir == -1f)
|
|
{
|
|
num129 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector11.Y;
|
|
}
|
|
float num130 = (float)Math.Sqrt((double)(num128 * num128 + num129 * num129));
|
|
if (num130 == 0f || projectile.ai[0] < 0f)
|
|
{
|
|
vector11 = new Vector2(Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2), Main.player[projectile.owner].position.Y + (float)(Main.player[projectile.owner].height / 2));
|
|
num128 = projectile.position.X + (float)projectile.width * 0.5f - vector11.X;
|
|
num129 = projectile.position.Y + (float)projectile.height * 0.5f - vector11.Y;
|
|
num130 = (float)Math.Sqrt((double)(num128 * num128 + num129 * num129));
|
|
}
|
|
num130 = num127 / num130;
|
|
num128 *= num130;
|
|
num129 *= num130;
|
|
projectile.velocity.X = num128;
|
|
projectile.velocity.Y = num129;
|
|
if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f)
|
|
{
|
|
projectile.Kill();
|
|
}
|
|
projectile.ai[0] = 1f;
|
|
}
|
|
}
|
|
if (projectile.velocity.X != 0f || projectile.velocity.Y != 0f)
|
|
{
|
|
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
|
|
}
|
|
if (projectile.velocity.Y > 16f)
|
|
{
|
|
projectile.velocity.Y = 16f;
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
|
|
{
|
|
CalamityGlobalProjectile.DrawCenteredAndAfterimage(projectile, lightColor, ProjectileID.Sets.TrailingMode[projectile.type], 1);
|
|
return false;
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
projectile.position = projectile.Center;
|
|
projectile.width = projectile.height = 64;
|
|
projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
|
|
projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
|
|
projectile.maxPenetrate = -1;
|
|
projectile.penetrate = -1;
|
|
projectile.usesLocalNPCImmunity = true;
|
|
projectile.localNPCHitCooldown = 10;
|
|
projectile.Damage();
|
|
Main.PlaySound(2, (int)projectile.Center.X, (int)projectile.Center.Y, 14);
|
|
int num226 = 36;
|
|
for (int num227 = 0; num227 < num226; num227++)
|
|
{
|
|
Vector2 vector6 = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.75f;
|
|
vector6 = vector6.RotatedBy((double)((float)(num227 - (num226 / 2 - 1)) * 6.28318548f / (float)num226), default) + projectile.Center;
|
|
Vector2 vector7 = vector6 - projectile.Center;
|
|
int num228 = Dust.NewDust(vector6 + vector7, 0, 0, 85, vector7.X * 1.5f, vector7.Y * 1.5f, 100, default, 1.2f);
|
|
Main.dust[num228].noGravity = true;
|
|
Main.dust[num228].noLight = true;
|
|
Main.dust[num228].velocity = vector7;
|
|
}
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
|
{
|
|
target.immune[projectile.owner] = 5;
|
|
}
|
|
}
|
|
}
|