Files
CalamityModPublic/Projectiles/Boss/BrimstoneFireblast.cs
T

133 lines
5.8 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Dusts;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Terraria.Audio;
namespace CalamityMod.Projectiles.Boss
{
public class BrimstoneFireblast : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Brimstone Gigablast");
Main.projFrames[Projectile.type] = 6;
}
public override void SetDefaults()
{
Projectile.Calamity().canBreakPlayerDefense = true;
Projectile.width = 50;
Projectile.height = 50;
Projectile.hostile = true;
Projectile.ignoreWater = true;
Projectile.penetrate = 1;
Projectile.timeLeft = 120;
Projectile.Opacity = 0f;
CooldownSlot = 1;
}
public override void AI()
{
Projectile.frameCounter++;
if (Projectile.frameCounter > 4)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame > 5)
Projectile.frame = 0;
if (Projectile.ai[1] == 1f)
Projectile.Opacity = MathHelper.Clamp(Projectile.timeLeft / 60f, 0f, 1f);
else
Projectile.Opacity = MathHelper.Clamp(1f - ((Projectile.timeLeft - 60) / 60f), 0f, 1f);
Lighting.AddLight(Projectile.Center, 0.9f * Projectile.Opacity, 0f, 0f);
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
if (Projectile.localAI[0] == 0f)
{
Projectile.localAI[0] = 1f;
SoundEngine.PlaySound(SoundID.Item, (int)Projectile.position.X, (int)Projectile.position.Y, 20);
}
int target = Player.FindClosest(Projectile.Center, 1, 1);
float projSpeed = Projectile.velocity.Length();
Vector2 playerVec = Main.player[target].Center - Projectile.Center;
playerVec.Normalize();
playerVec *= projSpeed;
Projectile.velocity = (Projectile.velocity * 24f + playerVec) / 25f;
Projectile.velocity.Normalize();
Projectile.velocity *= projSpeed;
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
int frameHeight = texture.Height / Main.projFrames[Projectile.type];
int drawStart = frameHeight * Projectile.frame;
lightColor.R = (byte)(255 * Projectile.Opacity);
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, drawStart, texture.Width, frameHeight)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2(texture.Width / 2f, frameHeight / 2f), Projectile.scale, SpriteEffects.None, 0);
return false;
}
public override bool CanHitPlayer(Player target) => Projectile.Opacity == 1f;
public override void OnHitPlayer(Player target, int damage, bool crit)
{
if (Projectile.Opacity != 1f)
return;
target.AddBuff(ModContent.BuffType<AbyssalFlames>(), 240);
target.AddBuff(ModContent.BuffType<VulnerabilityHex>(), 180, true);
}
public override void Kill(int timeLeft)
{
SoundEngine.PlaySound(SoundLoader.GetLegacySoundSlot(Mod, "Sounds/Custom/SCalSounds/BrimstoneGigablastImpact"), Projectile.Center);
if (Projectile.ai[1] == 0f)
{
float spread = 12f * MathHelper.PiOver2 * 0.01f;
double startAngle = Math.Atan2(Projectile.velocity.X, Projectile.velocity.Y) - spread / 2;
double deltaAngle = spread / 30f;
double offsetAngle;
if (Projectile.owner == Main.myPlayer)
{
for (int i = 0; i < 30; 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<BrimstoneBarrage>(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 1f);
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), ModContent.ProjectileType<BrimstoneBarrage>(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 1f);
}
}
}
for (int j = 0; j < 2; j++)
{
Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, (int)CalamityDusts.Brimstone, 0f, 0f, 50, default, 1f);
}
for (int k = 0; k < 20; k++)
{
int redFire = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, (int)CalamityDusts.Brimstone, 0f, 0f, 0, default, 1.5f);
Main.dust[redFire].noGravity = true;
Main.dust[redFire].velocity *= 3f;
redFire = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, (int)CalamityDusts.Brimstone, 0f, 0f, 50, default, 1f);
Main.dust[redFire].velocity *= 2f;
Main.dust[redFire].noGravity = true;
}
}
public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit)
{
target.Calamity().lastProjectileHit = Projectile;
}
}
}