110 lines
5.1 KiB
C#
110 lines
5.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.Graphics.Shaders;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
using Terraria.Audio;
|
|
|
|
namespace CalamityMod.Projectiles.Ranged
|
|
{
|
|
public class TheMaelstromShark : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Ranged";
|
|
public PrimitiveTrail LightningTrailDrawer = null;
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projFrames[Projectile.type] = 6;
|
|
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 15;
|
|
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 44;
|
|
Projectile.height = 44;
|
|
Projectile.friendly = true;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.arrow = true;
|
|
Projectile.penetrate = 1;
|
|
Projectile.Opacity = 0f;
|
|
Projectile.DamageType = DamageClass.Ranged;
|
|
Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Projectile.frameCounter++;
|
|
Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type];
|
|
|
|
Projectile.rotation = Projectile.velocity.ToRotation();
|
|
Projectile.spriteDirection = (Math.Cos(Projectile.rotation) > 0f).ToDirectionInt();
|
|
if (Projectile.spriteDirection == -1)
|
|
Projectile.rotation += MathHelper.Pi;
|
|
|
|
Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity + 0.1f, 0f, 1f);
|
|
}
|
|
|
|
public override bool OnTileCollide(Vector2 oldVelocity)
|
|
{
|
|
Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height);
|
|
SoundEngine.PlaySound(SoundID.Dig, Projectile.position);
|
|
return true;
|
|
}
|
|
|
|
internal Color ColorFunction(float completionRatio)
|
|
{
|
|
float fadeOpacity = Utils.GetLerpValue(0.94f, 0.54f, completionRatio, true) * Projectile.Opacity;
|
|
return Color.Lerp(Color.Cyan, Color.White, 0.4f) * fadeOpacity;
|
|
}
|
|
|
|
internal float WidthFunction(float completionRatio)
|
|
{
|
|
float expansionCompletion = 1f - (float)Math.Pow(1f - Utils.GetLerpValue(0f, 0.3f, completionRatio, true), 2D);
|
|
return MathHelper.Lerp(0f, 12f * Projectile.Opacity, expansionCompletion);
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
// Create death effects for the shark, including a death sound, gore, and some blood.
|
|
SoundEngine.PlaySound(SoundID.NPCDeath1, Projectile.Center);
|
|
if (Main.netMode != NetmodeID.Server)
|
|
{
|
|
Gore.NewGore(Projectile.GetSource_Death(), Projectile.position, Projectile.velocity, Mod.Find<ModGore>("MaelstromReaperShark1").Type, Projectile.scale);
|
|
Gore.NewGore(Projectile.GetSource_Death(), Projectile.position, Projectile.velocity, Mod.Find<ModGore>("MaelstromReaperShark2").Type, Projectile.scale);
|
|
Gore.NewGore(Projectile.GetSource_Death(), Projectile.position, Projectile.velocity, Mod.Find<ModGore>("MaelstromReaperShark3").Type, Projectile.scale);
|
|
}
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
Dust blood = Dust.NewDustPerfect(Projectile.Center, 5);
|
|
blood.velocity = Main.rand.NextVector2Circular(6f, 6f);
|
|
blood.scale *= Main.rand.NextFloat(0.7f, 1.3f);
|
|
blood.noGravity = true;
|
|
}
|
|
|
|
if (Main.myPlayer != Projectile.owner)
|
|
return;
|
|
|
|
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType<TheMaelstromExplosion>(), Projectile.damage, 0f, Projectile.owner);
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
|
|
Rectangle frame = texture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
|
|
Vector2 origin = frame.Size() * 0.5f;
|
|
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
|
|
SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
|
|
|
if (LightningTrailDrawer is null)
|
|
LightningTrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
|
|
|
|
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
|
|
LightningTrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 60);
|
|
Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, direction, 0);
|
|
return false;
|
|
}
|
|
}
|
|
}
|