Files
CalamityModPublic/Projectiles/Magic/VividBeam.cs
T

142 lines
5.9 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class VividBeam : ModProjectile
{
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
private bool initialized = false;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Beam");
}
public override void SetDefaults()
{
Projectile.width = 4;
Projectile.height = 4;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Magic;
Projectile.ignoreWater = true;
Projectile.penetrate = 1;
Projectile.extraUpdates = 100;
Projectile.timeLeft = 240;
}
public override void AI()
{
if (!initialized)
{
initialized = true;
float dustAmt = 16f;
int d = 0;
while ((float)d < dustAmt)
{
Vector2 offset = Vector2.UnitX * 0f;
offset += -Vector2.UnitY.RotatedBy((double)((float)d * (MathHelper.TwoPi / dustAmt)), default) * new Vector2(1f, 4f);
offset = offset.RotatedBy((double)Projectile.velocity.ToRotation(), default);
int i = Dust.NewDust(Projectile.Center, 0, 0, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1f);
Main.dust[i].scale = 1.5f;
Main.dust[i].noGravity = true;
Main.dust[i].position = Projectile.Center + offset;
Main.dust[i].velocity = Projectile.velocity * 0f + offset.SafeNormalize(Vector2.UnitY) * 1f;
d++;
}
}
float pi = MathHelper.Pi;
Projectile.ai[0] += 1f;
if (Projectile.ai[0] == 48f)
{
Projectile.ai[0] = 0f;
}
else
{
for (int d = 0; d < 2; d++)
{
Vector2 offset = Vector2.UnitX * -12f;
offset = -Vector2.UnitY.RotatedBy((double)(Projectile.ai[0] * pi / 24f + (float)d * pi), default) * new Vector2(5f, 10f) - Projectile.rotation.ToRotationVector2() * 10f;
int i = Dust.NewDust(Projectile.Center, 0, 0, 66, 0f, 0f, 160, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1f);
Main.dust[i].scale = 0.75f;
Main.dust[i].noGravity = true;
Main.dust[i].position = Projectile.Center + offset;
Main.dust[i].velocity = Projectile.velocity;
}
}
Projectile.localAI[0] += 1f;
if (Projectile.localAI[0] > 4f)
{
for (int d = 0; d < 2; d++)
{
Vector2 source = Projectile.position;
source -= Projectile.velocity * ((float)d * 0.25f);
int i = Dust.NewDust(source, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1f);
Main.dust[i].noGravity = true;
Main.dust[i].position = source;
Main.dust[i].scale = Main.rand.NextFloat(0.91f, 1.417f);
Main.dust[i].velocity *= 0.1f;
}
}
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
if (Projectile.owner == Main.myPlayer)
{
SummonLasers();
}
return true;
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
if (Projectile.owner == Main.myPlayer)
{
SummonLasers();
}
target.AddBuff(ModContent.BuffType<MiracleBlight>(), 300);
}
public override void OnHitPvp(Player target, int damage, bool crit)
{
if (Projectile.owner == Main.myPlayer)
{
SummonLasers();
}
target.AddBuff(ModContent.BuffType<MiracleBlight>(), 300);
}
private void SummonLasers()
{
var source = Projectile.GetSource_FromThis();
switch (Projectile.ai[1])
{
case 0f:
CalamityUtils.ProjectileRain(source, Projectile.Center, 400f, 100f, 500f, 800f, 6f, ModContent.ProjectileType<VividClarityBeam>(), (int)(Projectile.damage * 0.7), Projectile.knockBack, Projectile.owner);
break;
case 1f:
Projectile.NewProjectile(source, Projectile.Center, Vector2.Zero, ModContent.ProjectileType<VividExplosion>(), Projectile.damage * 2, Projectile.knockBack, Projectile.owner);
break;
case 2f:
float spread = 30f * 0.01f * MathHelper.PiOver2;
double startAngle = Math.Atan2(Projectile.velocity.X, Projectile.velocity.Y) - spread / 2;
double deltaAngle = spread / 8f;
double offsetAngle;
for (int i = 0; i < 4; i++)
{
offsetAngle = startAngle + deltaAngle * (i + i * i) / 2f + 32f * i;
Projectile.NewProjectile(source, Projectile.Center.X, Projectile.Center.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), ModContent.ProjectileType<VividLaser2>(), Projectile.damage, Projectile.knockBack, Projectile.owner);
Projectile.NewProjectile(source, Projectile.Center.X, Projectile.Center.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), ModContent.ProjectileType<VividLaser2>(), Projectile.damage, Projectile.knockBack, Projectile.owner);
}
break;
}
}
}
}