144 lines
5.9 KiB
C#
144 lines
5.9 KiB
C#
using CalamityMod.Events;
|
|
using CalamityMod.World;
|
|
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 AresDeathBeamTelegraph : 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 deathrayTelegraphDuration_Normal = 150f;
|
|
public const float deathrayTelegraphDuration_Expert = 120f;
|
|
public const float deathrayTelegraphDuration_Rev = 105f;
|
|
public const float deathrayTelegraphDuration_Death = 90f;
|
|
public const float deathrayTelegraphDuration_BossRush = 60f;
|
|
public const float TelegraphFadeTime = 15f;
|
|
public const float TelegraphWidth = 2400f;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
// Telegraph for Ares' eight-pointed-star laser beams
|
|
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;
|
|
|
|
// Difficulty modes
|
|
bool bossRush = BossRushEvent.BossRushActive;
|
|
bool death = CalamityWorld.death || bossRush;
|
|
bool revenge = CalamityWorld.revenge || bossRush;
|
|
bool expertMode = Main.expertMode || bossRush;
|
|
|
|
Projectile.timeLeft = (int)(bossRush ? deathrayTelegraphDuration_BossRush : death ? deathrayTelegraphDuration_Death :
|
|
revenge ? deathrayTelegraphDuration_Rev : expertMode ? deathrayTelegraphDuration_Expert : deathrayTelegraphDuration_Normal);
|
|
}
|
|
|
|
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 + new Vector2(-1f, 23f) + (Vector2.Normalize(OldVelocity) * 17f);
|
|
|
|
// 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)
|
|
{
|
|
// Difficulty modes
|
|
bool bossRush = BossRushEvent.BossRushActive;
|
|
bool death = CalamityWorld.death || bossRush;
|
|
bool revenge = CalamityWorld.revenge || bossRush;
|
|
bool expertMode = Main.expertMode || bossRush;
|
|
|
|
float TelegraphTotalTime = bossRush ? deathrayTelegraphDuration_BossRush : death ? deathrayTelegraphDuration_Death :
|
|
revenge ? deathrayTelegraphDuration_Rev : expertMode ? deathrayTelegraphDuration_Expert : deathrayTelegraphDuration_Normal;
|
|
|
|
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.Cyan, Color.LightGreen, TelegraphDelay / TelegraphTotalTime * 2f % 1f); // Iterate through light green and cyan 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;
|
|
}
|
|
}
|
|
}
|