Files
CalamityModPublic/Projectiles/Boss/ArtemisDeathrayTelegraph.cs
T

120 lines
4.4 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Boss
{
public class ArtemisDeathrayTelegraph : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Boss";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public float TelegraphDelay
{
get => Projectile.ai[0];
set => Projectile.ai[0] = value;
}
public NPC ThingToAttachTo => Main.npc.IndexInRange((int)Projectile.ai[1]) ? Main.npc[(int)Projectile.ai[1]] : null;
public Vector2 OldVelocity;
public const float TelegraphTotalTime = 60f;
public const float TelegraphFadeTime = 15f;
public const float TelegraphWidth = 4800f;
public override void SetStaticDefaults()
{
ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 10000;
}
public override void SetDefaults()
{
Projectile.width = 10;
Projectile.height = 10;
Projectile.hostile = true;
Projectile.ignoreWater = true;
Projectile.tileCollide = false;
Projectile.alpha = 255;
Projectile.penetrate = -1;
Projectile.timeLeft = 60;
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.WriteVector2(OldVelocity);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
OldVelocity = reader.ReadVector2();
}
public override void AI()
{
// Determine the relative opacities for each player based on their distance.
if (Projectile.localAI[0] == 0f)
{
Projectile.localAI[0] = 1f;
Projectile.netUpdate = true;
}
// Die if the thing to attach to disappears.
if (ThingToAttachTo is null || !ThingToAttachTo.active)
{
Projectile.Kill();
return;
}
// Set start of telegraph to the npc center.
Projectile.Center = ThingToAttachTo.Center + Vector2.Normalize(OldVelocity) * 70f;
// Be sure to save the velocity the projectile started with. It will be set again when the telegraph is over.
if (OldVelocity == Vector2.Zero)
{
OldVelocity = Projectile.velocity;
Projectile.velocity = Vector2.Zero;
Projectile.netUpdate = true;
Projectile.rotation = OldVelocity.ToRotation() + MathHelper.PiOver2;
}
TelegraphDelay++;
}
public override Color? GetAlpha(Color lightColor)
{
return new Color(255, 255, 255, Projectile.alpha);
}
public override bool PreDraw(ref Color lightColor)
{
if (TelegraphDelay >= TelegraphTotalTime)
return true;
Texture2D laserTelegraph = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/LaserWallTelegraphBeam").Value;
float yScale = 2f;
if (TelegraphDelay < TelegraphFadeTime)
yScale = MathHelper.Lerp(0f, 2f, TelegraphDelay / 15f);
if (TelegraphDelay > TelegraphTotalTime - TelegraphFadeTime)
yScale = MathHelper.Lerp(2f, 0f, (TelegraphDelay - (TelegraphTotalTime - TelegraphFadeTime)) / 15f);
Vector2 scaleInner = new Vector2(TelegraphWidth / laserTelegraph.Width, yScale);
Vector2 origin = laserTelegraph.Size() * new Vector2(0f, 0.5f);
Vector2 scaleOuter = scaleInner * new Vector2(1f, 1.6f);
Color colorOuter = Color.Lerp(Color.Red, Color.Crimson, TelegraphDelay / TelegraphTotalTime * 2f % 1f); // Iterate through crimson and red once and then flash.
Color colorInner = Color.Lerp(colorOuter, Color.White, 0.75f);
colorOuter *= 0.7f;
colorInner *= 0.7f;
Main.EntitySpriteDraw(laserTelegraph, Projectile.Center - Main.screenPosition, null, colorInner, OldVelocity.ToRotation(), origin, scaleInner, SpriteEffects.None, 0);
Main.EntitySpriteDraw(laserTelegraph, Projectile.Center - Main.screenPosition, null, colorOuter, OldVelocity.ToRotation(), origin, scaleOuter, SpriteEffects.None, 0);
return false;
}
}
}