174 lines
7.1 KiB
C#
174 lines
7.1 KiB
C#
using CalamityMod.Sounds;
|
|
using CalamityMod.Projectiles.BaseProjectiles;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using ReLogic.Content;
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Terraria;
|
|
using Terraria.Audio;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Rogue
|
|
{
|
|
public class SeraphimBeamLarge : BaseLaserbeamProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Rogue";
|
|
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
|
|
|
|
public int OwnerIndex
|
|
{
|
|
get => (int)Projectile.ai[1];
|
|
set => Projectile.ai[1] = value;
|
|
}
|
|
public override float MaxScale => 1f;
|
|
public override float MaxLaserLength => 1000f;
|
|
public override float Lifetime => 50;
|
|
public override Color LaserOverlayColor
|
|
{
|
|
get
|
|
{
|
|
Color c1 = Color.Goldenrod;
|
|
Color c2 = Color.Orange;
|
|
Color color = Color.Lerp(c1, c2, Projectile.identity % 5f / 5f) * 1.1f;
|
|
color.A = 25;
|
|
return color;
|
|
}
|
|
}
|
|
public override Color LightCastColor => Color.Transparent;
|
|
public override Texture2D LaserBeginTexture => ModContent.Request<Texture2D>("CalamityMod/Projectiles/Rogue/SeraphimBeamLarge", AssetRequestMode.ImmediateLoad).Value;
|
|
public override Texture2D LaserMiddleTexture => ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Lasers/SeraphimBeamLargeMiddle", AssetRequestMode.ImmediateLoad).Value;
|
|
public override Texture2D LaserEndTexture => ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Lasers/SeraphimBeamLargeEnd", AssetRequestMode.ImmediateLoad).Value;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projFrames[Projectile.type] = 10;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 30;
|
|
Projectile.height = 30;
|
|
Projectile.friendly = true;
|
|
Projectile.alpha = 255;
|
|
Projectile.penetrate = -1;
|
|
Projectile.tileCollide = false;
|
|
Projectile.timeLeft = 600;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = -1;
|
|
Projectile.DamageType = RogueDamageClass.Instance;
|
|
}
|
|
|
|
public override void SendExtraAI(BinaryWriter writer)
|
|
{
|
|
writer.Write(Projectile.localAI[0]);
|
|
writer.Write(Projectile.localAI[1]);
|
|
writer.Write(Projectile.scale);
|
|
}
|
|
|
|
public override void ReceiveExtraAI(BinaryReader reader)
|
|
{
|
|
Projectile.localAI[0] = reader.ReadSingle();
|
|
Projectile.localAI[1] = reader.ReadSingle();
|
|
Projectile.scale = reader.ReadSingle();
|
|
}
|
|
|
|
public override void AttachToSomething() { }
|
|
|
|
public override void UpdateLaserMotion()
|
|
{
|
|
// Update the direction and rotation of the laser.
|
|
Projectile.velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY);
|
|
Projectile.rotation = Projectile.velocity.ToRotation() - MathHelper.PiOver2;
|
|
}
|
|
|
|
public override float DetermineLaserLength()
|
|
{
|
|
float[] sampledLengths = new float[10];
|
|
Collision.LaserScan(Projectile.Center, Projectile.velocity, Projectile.width * Projectile.scale, MaxLaserLength, sampledLengths);
|
|
float newLaserLength = sampledLengths.Average();
|
|
|
|
if (Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height))
|
|
return MaxLaserLength;
|
|
|
|
return newLaserLength;
|
|
}
|
|
|
|
public override void PostAI()
|
|
{
|
|
if (Projectile.frameCounter == 0)
|
|
SoundEngine.PlaySound(CommonCalamitySounds.LaserCannonSound, Projectile.Center);
|
|
|
|
// Determine frames.
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter % 5f == 4f)
|
|
Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Projectile.type];
|
|
}
|
|
|
|
// Rapidly decrease damage every hit
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => Projectile.damage = Math.Max(1, (int)(Projectile.damage * 0.3));
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
// This should never happen, but just in case-
|
|
if (Projectile.velocity == Vector2.Zero)
|
|
return false;
|
|
|
|
Color beamColor = LaserOverlayColor;
|
|
Rectangle startFrameArea = LaserBeginTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
|
|
Rectangle middleFrameArea = LaserMiddleTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
|
|
Rectangle endFrameArea = LaserEndTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
|
|
|
|
// Start texture drawing.
|
|
Vector2 centerOnLaser = Projectile.Center + Projectile.velocity * Projectile.scale * 116f;
|
|
Main.EntitySpriteDraw(LaserBeginTexture,
|
|
centerOnLaser - Main.screenPosition,
|
|
startFrameArea,
|
|
beamColor,
|
|
Projectile.rotation,
|
|
LaserBeginTexture.Size() / 2f,
|
|
Projectile.scale,
|
|
SpriteEffects.None,
|
|
0);
|
|
|
|
// Prepare things for body drawing.
|
|
float laserBodyLength = LaserLength + middleFrameArea.Height;
|
|
|
|
// Body drawing.
|
|
if (laserBodyLength > 0f)
|
|
{
|
|
float laserOffset = middleFrameArea.Height * Projectile.scale;
|
|
float incrementalBodyLength = 0f;
|
|
while (incrementalBodyLength + 1f < laserBodyLength)
|
|
{
|
|
centerOnLaser += Projectile.velocity * laserOffset;
|
|
incrementalBodyLength += laserOffset;
|
|
Main.EntitySpriteDraw(LaserMiddleTexture,
|
|
centerOnLaser - Main.screenPosition,
|
|
middleFrameArea,
|
|
beamColor,
|
|
Projectile.rotation,
|
|
LaserMiddleTexture.Size() * 0.5f,
|
|
Projectile.scale,
|
|
SpriteEffects.None,
|
|
0);
|
|
}
|
|
}
|
|
|
|
Vector2 laserEndCenter = centerOnLaser + Projectile.velocity * endFrameArea.Height * Projectile.scale - Main.screenPosition;
|
|
Main.EntitySpriteDraw(LaserEndTexture,
|
|
laserEndCenter,
|
|
endFrameArea,
|
|
beamColor,
|
|
Projectile.rotation,
|
|
LaserEndTexture.Size() * 0.5f,
|
|
Projectile.scale,
|
|
SpriteEffects.None,
|
|
0);
|
|
return false;
|
|
}
|
|
}
|
|
}
|