Files
CalamityModPublic/Projectiles/Magic/PlasmaRay.cs
T

93 lines
3.9 KiB
C#

using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class PlasmaRay : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetDefaults()
{
Projectile.width = 4;
Projectile.height = 4;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Magic;
Projectile.penetrate = 1;
Projectile.extraUpdates = 100;
Projectile.timeLeft = 80;
}
public override void AI()
{
Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 65, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f);
if (Projectile.velocity.X != Projectile.velocity.X)
{
Projectile.position.X = Projectile.position.X + Projectile.velocity.X;
Projectile.velocity.X = -Projectile.velocity.X;
}
if (Projectile.velocity.Y != Projectile.velocity.Y)
{
Projectile.position.Y = Projectile.position.Y + Projectile.velocity.Y;
Projectile.velocity.Y = -Projectile.velocity.Y;
}
Projectile.localAI[0] += 1f;
if (Projectile.localAI[0] > 9f)
{
for (int i = 0; i < 4; i++)
{
Vector2 projPos = Projectile.position;
projPos -= Projectile.velocity * ((float)i * 0.25f);
Projectile.alpha = 255;
int purpDust = Dust.NewDust(projPos, 1, 1, 173, 0f, 0f, 0, default, 0.75f);
Main.dust[purpDust].position = projPos;
Main.dust[purpDust].scale = (float)Main.rand.Next(70, 110) * 0.013f;
Main.dust[purpDust].velocity *= 0.2f;
}
}
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
float random = Main.rand.Next(30, 90);
float spread = random * 0.0174f;
double startAngle = Math.Atan2(Projectile.velocity.X, Projectile.velocity.Y) - spread / 2;
double deltaAngle = spread / 8f;
double offsetAngle;
int i;
if (Projectile.owner == Main.myPlayer)
{
for (i = 0; i < 4; i++)
{
offsetAngle = startAngle + deltaAngle * (i + i * i) / 2f + 32f * i;
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), ModContent.ProjectileType<PlasmaRay2>(), (int)(Projectile.damage * 1.75), Projectile.knockBack, Projectile.owner, 0f, 0f);
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), ModContent.ProjectileType<PlasmaRay2>(), (int)(Projectile.damage * 1.75), Projectile.knockBack, Projectile.owner, 0f, 0f);
}
}
Projectile.penetrate--;
if (Projectile.penetrate <= 0)
{
Projectile.Kill();
}
return false;
}
public override void OnKill(int timeLeft)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 173, Projectile.oldVelocity.X * 0.5f, Projectile.oldVelocity.Y * 0.5f);
}
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
target.AddBuff(BuffID.ShadowFlame, 180);
}
}
}