Files
CalamityModPublic/Projectiles/Rogue/ProfanedPartisanFlare.cs
T

187 lines
8.3 KiB
C#

using System;
using System.Linq;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.Rogue;
using CalamityMod.NPCs.Providence;
using CalamityMod.Particles;
using CalamityMod.Utilities.Daybreak;
using CalamityMod.Utilities.Daybreak.Buffers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Audio;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Rogue
{
public class ProfanedPartisanFlare : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
public int timer = 0;
public override string Texture => "CalamityMod/Projectiles/Boss/HolyFire";
public override void SetStaticDefaults()
{
Main.projFrames[Type] = 4;
ProjectileID.Sets.CultistIsResistantTo[Type] = true;
}
public override void SetDefaults()
{
ProjectileID.Sets.TrailCacheLength[Type] = 8;
ProjectileID.Sets.TrailingMode[Type] = 2;
Projectile.width = 20;
Projectile.height = 20;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.DamageType = RogueDamageClass.Instance;
Projectile.penetrate = 3;
Projectile.extraUpdates = 0;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 30;
Projectile.timeLeft = 600;
Projectile.tileCollide = false;
Projectile.scale = 0.75f;
}
public override bool? CanHitNPC(NPC target)
{
return true;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
target.AddBuff(ModContent.BuffType<HolyFlames>(), 120);
}
NPC target = null;
public override void AI()
{
Projectile.frameCounter++;
if (Projectile.frameCounter > 3)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame >= Main.projFrames[Type])
Projectile.frame = 0;
if (Projectile.originalDamage == 0)
{
Projectile.originalDamage = ProfanedPartisan.ShardBaseDamage;
Projectile.ContinuouslyUpdateDamageStats = true;
}
if (target != null && Projectile.localNPCImmunity[target.whoAmI] <= 0 && target.active && !target.dontTakeDamage)
{
Projectile.Calamity().HomingTarget = target.whoAmI;
var dis = Projectile.Distance(target.Center);
Projectile.velocity = Projectile.velocity.ToRotation().AngleLerp(Projectile.DirectionTo(target.Center).ToRotation(), (Projectile.Distance(target.Center) < 160 ? 0.1f + (1 - dis / 160) * 0.4f : 0.1f)).ToRotationVector2() * Projectile.velocity.Length();
}
else
{
target = GetTargetInRange(2000);
}
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
}
public override void OnKill(int timeLeft)
{
Color hiColor = new Color(255, 155, 25, 255);
Color loColor = new Color(255, 0, 0, 0);
for (int i = 0; i < 25; i++)
{
GeneralParticleHandler.SpawnParticle(new GlowOrbParticle(Projectile.Center, new Vector2(Main.rand.NextFloat(10), 0).RotatedByRandom(MathHelper.TwoPi), false, 10, Main.rand.NextFloat(0.8f, 1.2f), hiColor));
}
GeneralParticleHandler.SpawnParticle(new CustomPulse(Projectile.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomCircle", Vector2.One, 0f, 0.5f, 0.1f, 4));
for (float i = 0; i < 1; i += 0.25f)
{
GeneralParticleHandler.SpawnParticle(new CustomPulse(Projectile.Center, Vector2.Zero, hiColor, "CalamityMod/Particles/SoftRoundExplosion", Vector2.One, Main.rand.NextFloat(MathHelper.TwoPi), 0.02f * i, 0.075f * i, 24));
}
GeneralParticleHandler.SpawnParticle(new CustomPulse(Projectile.Center, Vector2.Zero, hiColor, "CalamityMod/Particles/ShatteredExplosion", Vector2.One, Main.rand.NextFloat(MathHelper.TwoPi), 0.02f, 0.045f, 16));
SoundEngine.PlaySound(SoundID.DD2_BetsyFireballImpact.WithPitchOffset(0.6f), Projectile.Center);
SoundEngine.PlaySound(SoundID.Item100.WithPitchOffset(0.4f), Projectile.Center);
}
public override bool PreDraw(ref Color lightColor)
{
Main.spriteBatch.End(out var ss);
var device = Main.instance.GraphicsDevice;
using var lease = RenderTargetPool.Shared.Rent(
device,
Main.screenWidth / 2,
Main.screenHeight / 2,
RenderTargetDescriptor.Default
);
using (lease.Scope(clearColor: Color.Transparent))
{
var list = Projectile.oldPos.Take(8).ToList();
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
PrimitiveRenderer.RenderTrail(list.ToArray(), new(FireWidthFunction, FireColorFunction, (_, _) => Projectile.Size * 0.5f, smoothen: true, pixelate: false, shader: GameShaders.Misc["CalamityMod:ImpFlameTrail"], useUnscaledMatrices: true), Projectile.oldPos.Length + 32);
}
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.Transform);
Main.spriteBatch.Draw(lease.Target, Vector2.Zero, null, Color.White * 0.75f, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f);
Main.spriteBatch.End();
Main.spriteBatch.Begin(ss);
Texture2D tex = Terraria.GameContent.TextureAssets.Projectile[Type].Value;
var frame = tex.Frame(1, Main.projFrames[Type], 0, Projectile.frame);
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, frame, Color.White, Projectile.rotation, frame.Size() *0.5f, Projectile.scale, SpriteEffects.None, 0);
return false;
}
public float FireWidthFunction(float completion, Vector2 pos)
{
float width;
float maxBodyWidth = 16f * Projectile.scale;
float curveRatio = 0.2f;
var positions = Projectile.oldPos.ToList();
positions.RemoveAll(x => x == Vector2.Zero);
// Crop the tip of the trail into a conic shape.
if (completion < curveRatio)
width = MathF.Pow(completion / curveRatio, 0.5f) * maxBodyWidth;
else
width = Utils.Remap(completion, curveRatio, 1f, maxBodyWidth, 0f);
// Pulse inwards and outwards over time.
float pulseInterpolant = MathF.Cos(MathHelper.Pi * completion - Main.GlobalTimeWrappedHourly * 20f) * 0.5f + 0.5f;
float additionalPulseWidth = MathHelper.Lerp(0f, 12f, pulseInterpolant);
return (width + additionalPulseWidth) * positions.Count() / (float)ProjectileID.Sets.TrailCacheLength[Type];
}
public Color FireColorFunction(float completion, Vector2 pos)
{
Color mainColor = ProvUtils.GetProjectileColor(255);
Color endColor = Color.Lerp(mainColor, Color.Transparent, Utils.GetLerpValue(0.8f, 1f, completion, true));
return Color.Lerp(mainColor, endColor, completion) * Projectile.Opacity;
}
NPC GetTargetInRange(float range)
{
var player = Main.player[Projectile.owner];
{
NPC gotTarget = null;
float currentDistance = range;
foreach (var npc in Main.ActiveNPCs)
{
if (Projectile.localNPCImmunity[npc.whoAmI] > 0)
continue;
var myDistance = npc.Distance(Projectile.Center);
if (npc.CanBeChasedBy() && myDistance < currentDistance)
{
currentDistance = myDistance;
gotTarget = npc;
}
}
return gotTarget;
}
}
}
}