Merge Dom's Subsuming Vortex rework

This commit is contained in:
Cameron Ewell authored and GitHub committed 2022-08-24 23:05:09 -04:00
commit 69db79d892
14 files changed
+379 -482

No files matched your search

+6
View File
@@ -38,6 +38,8 @@ namespace CalamityMod.Effects
public static Effect ArtemisLaserShader;
public static Effect ExobladeSlashShader;
public static Effect ExobladePierceShader;
public static Effect ExoVortexShader;
public static Effect SideStreakTrailShader;
public static Effect HeavenlyGaleTrailShader;
public static Effect HeavenlyGaleLightningShader;
@@ -81,6 +83,8 @@ namespace CalamityMod.Effects
ArtemisLaserShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ArtemisLaserShader", AssetRequestMode.ImmediateLoad).Value;
ExobladeSlashShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ExobladeSlashShader", AssetRequestMode.ImmediateLoad).Value;
ExobladePierceShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ExobladePierceShader", AssetRequestMode.ImmediateLoad).Value;
ExoVortexShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ExoVortexShader", AssetRequestMode.ImmediateLoad).Value;
SideStreakTrailShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/SideStreakTrail", AssetRequestMode.ImmediateLoad).Value;
HeavenlyGaleTrailShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/HeavenlyGaleTrailShader", AssetRequestMode.ImmediateLoad).Value;
HeavenlyGaleLightningShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/HeavenlyGaleLightningShader", AssetRequestMode.ImmediateLoad).Value;
@@ -121,6 +125,8 @@ namespace CalamityMod.Effects
GameShaders.Misc["CalamityMod:ArtemisLaser"] = new MiscShaderData(new Ref<Effect>(ArtemisLaserShader), "TrailPass");
GameShaders.Misc["CalamityMod:ExobladeSlash"] = new MiscShaderData(new Ref<Effect>(ExobladeSlashShader), "TrailPass");
GameShaders.Misc["CalamityMod:ExobladePierce"] = new MiscShaderData(new Ref<Effect>(ExobladePierceShader), "PiercePass");
GameShaders.Misc["CalamityMod:ExoVortex"] = new MiscShaderData(new Ref<Effect>(ExoVortexShader), "VortexPass");
GameShaders.Misc["CalamityMod:SideStreakTrail"] = new MiscShaderData(new Ref<Effect>(SideStreakTrailShader), "TrailPass");
GameShaders.Misc["CalamityMod:HeavenlyGaleTrail"] = new MiscShaderData(new Ref<Effect>(HeavenlyGaleTrailShader), "PiercePass");
GameShaders.Misc["CalamityMod:HeavenlyGaleLightningArc"] = new MiscShaderData(new Ref<Effect>(HeavenlyGaleLightningShader), "TrailPass");
+35
View File
@@ -0,0 +1,35 @@
sampler uImage0 : register(s0);
sampler uImage1 : register(s1);
float3 uColor;
float3 uSecondaryColor;
float uOpacity;
float uSaturation;
float uRotation;
float uTime;
float4 uSourceRect;
float2 uWorldPosition;
float uDirection;
float3 uLightSource;
float2 uImageSize0;
float2 uImageSize1;
float4 uShaderSpecificData;
float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
// Calculate the swirl coordinates.
float2 centeredCoords = coords - 0.5;
float swirlRotation = length(centeredCoords) * 17.2 - uTime * 6;
float swirlColorFade = 1 - saturate(length(centeredCoords) * 1.8);
float swirlSine = sin(swirlRotation);
float swirlCosine = sin(swirlRotation + 1.5707);
float2x2 swirlRotationMatrix = float2x2(swirlCosine, -swirlSine, swirlSine, swirlCosine);
float2 swirlCoordinates = mul(centeredCoords, swirlRotationMatrix) + 0.5;
return tex2D(uImage0, swirlCoordinates) * sampleColor * swirlColorFade;
}
technique Technique1
{
pass VortexPass
{
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Binary file not shown.
+72
View File
@@ -0,0 +1,72 @@
sampler uImage0 : register(s0);
sampler uImage1 : register(s1);
float3 uColor;
float3 uSecondaryColor;
float uOpacity;
float uSaturation;
float uRotation;
float uTime;
float4 uSourceRect;
float2 uWorldPosition;
float uDirection;
float3 uLightSource;
float2 uImageSize0;
float2 uImageSize1;
matrix uWorldViewProjection;
float4 uShaderSpecificData;
struct VertexShaderInput
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;
float4 pos = mul(input.Position, uWorldViewProjection);
output.Position = pos;
output.Color = input.Color;
output.TextureCoordinates = input.TextureCoordinates;
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float innerBrightnessIntensity = 2.7;
float4 color = input.Color;
float2 coords = input.TextureCoordinates;
float bloomOpacity = pow(cos(coords.y * 4.8 - 0.8), 55 + pow(coords.x, 4) * 700);
// Create some noisy opaque blotches in the inner part of the trail.
if (coords.y > 0.15 && coords.y < 0.85)
{
float minOpacity = pow(1 - sin(coords.y * 3.141) + tex2D(uImage1, coords * 1.1 + float2(uTime * -0.6, 0)).r * 2.2, 0.2);
bloomOpacity += pow(coords.x, 0.3) * lerp(0.04, 0.4, minOpacity);
}
// Make the front half of the trail have a strong bloom effect.
if (coords.x < 0.5)
bloomOpacity *= (1 - coords.x * 2) * innerBrightnessIntensity + 1;
return color * lerp(0, 3.6, bloomOpacity * pow(coords.x, 0.1)) * pow(1 - coords.x, 1.1);
}
technique Technique1
{
pass TrailPass
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Binary file not shown.
+15 -5
View File
@@ -12,20 +12,27 @@ namespace CalamityMod.Items.Weapons.Magic
{
public class SubsumingVortex : ModItem
{
public const int VortexReleaseRate = 32;
public const int VortexShootDelay = 56;
public const float SmallVortexTargetRange = 1300f;
public const float GiantVortexMouseDriftFactor = 0.35f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Subsuming Vortex");
Tooltip.SetDefault("Releases a gigantic, slow-moving vortex\n" +
"The vortex releases exo tentacles that thrash at nearby enemies\n" +
"After a few seconds the vortex slows down, becomes unstable, and explodes");
Tooltip.SetDefault("Casts a gigantic vortex above your head with a bias towards the mouse\n" +
"When enemies are near the vortex, it sends multiple fast-moving smaller vortices towards them");
SacrificeTotal = 1;
}
public override void SetDefaults()
{
Item.damage = 242;
Item.damage = 397;
Item.DamageType = DamageClass.Magic;
Item.mana = 78;
Item.mana = 12;
Item.width = 38;
Item.height = 48;
Item.UseSound = SoundID.Item84;
@@ -37,10 +44,13 @@ namespace CalamityMod.Items.Weapons.Magic
Item.Calamity().customRarity = CalamityRarity.Violet;
Item.value = CalamityGlobalItem.Rarity15BuyPrice;
Item.autoReuse = true;
Item.channel = true;
Item.shoot = ModContent.ProjectileType<EnormousConsumingVortex>();
Item.shootSpeed = 7f;
}
public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0;
public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
{
Item.DrawItemGlowmaskSingleFrame(spriteBatch, rotation, ModContent.Request<Texture2D>("CalamityMod/Items/Weapons/Magic/SubsumingVortexGlow").Value);
+113 -155
View File
@@ -6,34 +6,29 @@ using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
using Terraria.Graphics.Shaders;
using CalamityMod.Particles;
using CalamityMod.Items.Weapons.Magic;
namespace CalamityMod.Projectiles.Magic
{
public class EnormousConsumingVortex : ModProjectile
{
public Player Owner => Main.player[Projectile.owner];
public float Time
{
get => Projectile.ai[0];
set => Projectile.ai[0] = value;
}
public float IdealScale
{
get => Projectile.ai[1];
set => Projectile.ai[1] = value;
}
public const int TentacleSpawnRate = 20;
public const int PulseInterval = 18;
public const float PulseHitboxExpandRatio = 2.5f;
public const float RadialOffsetVarianceFactor = 0.1f;
public const float StartingScale = 0.0004f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Subsuming Vortex");
ProjectileID.Sets.NeedsUUID[Projectile.type] = true;
}
public const float IdealScale = 2.7f;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetStaticDefaults() => DisplayName.SetDefault("Subsuming Vortex");
public override void SetDefaults()
{
@@ -43,171 +38,134 @@ namespace CalamityMod.Projectiles.Magic
Projectile.alpha = 255;
Projectile.penetrate = -1;
Projectile.scale = StartingScale;
Projectile.timeLeft = 540;
Projectile.timeLeft = 90000;
Projectile.tileCollide = false;
Projectile.netImportant = true;
Projectile.DamageType = DamageClass.Magic;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 8;
Projectile.localNPCHitCooldown = 7;
}
// Vanilla Terraria does not sync projectile scale by default.
public override void SendExtraAI(BinaryWriter writer) => writer.Write(Projectile.scale);
public override void ReceiveExtraAI(BinaryReader reader) => Projectile.scale = reader.ReadSingle();
public override void AI()
{
Projectile.rotation += MathHelper.ToRadians(8f); // Spin 2 win.
Projectile.alpha = (int)MathHelper.Lerp(255, 0, Utils.GetLerpValue(0f, 20f, Time, true)); // Fade in completely after 20 frames.
Projectile.scale = MathHelper.Lerp(StartingScale, IdealScale, Utils.GetLerpValue(0f, 30f, Time, true)); // Expand completely after 30 frames.
// Determine the ideal scale in the first frame.
if (IdealScale == 0f)
// If the player is no longer able to channel the vortex, kill it.
if (!Owner.channel || Owner.noItems || Owner.CCed)
{
IdealScale = Main.rand.NextFloat(2.2f, 3f);
Projectile.Kill();
return;
}
// Release energy from the book.
if (Time >= SubsumingVortex.VortexShootDelay)
{
Vector2 bookPosition = Owner.Center + Vector2.UnitX * Owner.direction * 22f;
if (Main.rand.NextBool())
{
Vector2 energyVelocity = Main.rand.NextVector2Circular(3f, 3f);
Color energyColor = CalamityUtils.MulticolorLerp(Main.rand.NextFloat(), CalamityUtils.ExoPalette);
SquishyLightParticle exoEnergy = new(bookPosition, energyVelocity, 0.55f, energyColor, 40, 1f, 1.5f);
GeneralParticleHandler.SpawnParticle(exoEnergy);
}
// Fire vortices at nearby target.
NPC potentialTarget = Projectile.Center.ClosestNPCAt(SubsumingVortex.SmallVortexTargetRange - 100f);
if (potentialTarget != null && Time % SubsumingVortex.VortexReleaseRate == SubsumingVortex.VortexReleaseRate - 1)
{
// CheckMana returns true if the mana cost can be paid..
bool allowContinuedUse = Owner.CheckMana(Owner.ActiveItem(), -1, true, false);
bool vortexStillInUse = Owner.channel && allowContinuedUse && !Owner.noItems && !Owner.CCed;
if (vortexStillInUse)
{
SoundEngine.PlaySound(SoundID.Item84, Projectile.Center);
if (Main.netMode != NetmodeID.MultiplayerClient)
{
float hue = (Time - SubsumingVortex.VortexShootDelay) / 125f;
Vector2 vortexVelocity = Projectile.SafeDirectionTo(potentialTarget.Center) * 8f;
Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, vortexVelocity, ModContent.ProjectileType<ExoVortex>(), Projectile.damage, Projectile.knockBack, Projectile.owner, hue);
}
Projectile.netUpdate = true;
}
else if (!vortexStillInUse)
Projectile.Kill();
}
}
// Create swirling exo energy.
if (Main.rand.NextBool())
{
float dustSpawnChance = Utils.Remap(Time, 12f, SubsumingVortex.VortexShootDelay + 8f, 0.25f, 0.7f);
for (int i = 0; i < 3; i++)
{
if (Main.rand.NextFloat() < dustSpawnChance)
{
float spawnOffsetAngle = Main.rand.NextFloat(MathHelper.TwoPi);
float hue = (float)Math.Sin(spawnOffsetAngle + Time / 26f) * 0.5f + 0.5f;
float spawnOffsetFactor = Main.rand.NextFloat(0.3f, 0.95f);
Vector2 energySpawnPosition = Projectile.Center + spawnOffsetAngle.ToRotationVector2() * Projectile.Size * spawnOffsetFactor;
Vector2 energyVelocity = (spawnOffsetAngle - MathHelper.PiOver2).ToRotationVector2() * (Main.rand.NextFloat(5f, 10f) * spawnOffsetFactor) * dustSpawnChance;
Color energyColor = CalamityUtils.MulticolorLerp(hue, CalamityUtils.ExoPalette);
SquishyLightParticle exoEnergy = new(energySpawnPosition, energyVelocity, Projectile.scale * Main.rand.NextFloat(0.18f, 0.3f), energyColor, 32, 1f, 1.5f);
GeneralParticleHandler.SpawnParticle(exoEnergy);
}
}
}
// Hover above the target.
if (Main.myPlayer == Projectile.owner)
{
// Smoothly approach a sinusoidal offset as time goes on.
float verticalOffset = Utils.Remap(Time, 0f, 90f, -30f, (float)Math.Cos(Projectile.timeLeft / 32f) * 30f - 325f);
Vector2 hoverDestination = Owner.Top + Vector2.UnitY * verticalOffset;
hoverDestination += (Main.MouseWorld - hoverDestination) * SubsumingVortex.GiantVortexMouseDriftFactor;
Vector2 idealVelocity = Vector2.Zero.MoveTowards(hoverDestination - Projectile.Center, 32f);
Projectile.velocity = Vector2.Lerp(Projectile.velocity, idealVelocity, 0.04f);
Projectile.netSpam = 0;
Projectile.netUpdate = true;
}
// Target enemy if possible and idly spawn tentacles.
if (Time < 150)
{
TargetingMovement();
if (Time % TentacleSpawnRate == TentacleSpawnRate - 1 && Main.myPlayer == Projectile.owner)
{
ProduceSubsumingHentai();
}
}
// Slow down and pulse frequently.
else if (Time < 220)
{
Projectile.velocity *= 0.96f;
if (Time % PulseInterval == 0f)
{
PulseEffect();
}
}
else if (Time >= 240)
{
ExplodeEffect();
Projectile.Kill();
}
Projectile.ExpandHitboxBy((int)(Projectile.scale * 62));
// Re-determine the hitbox size.
Projectile.Opacity = Utils.GetLerpValue(0f, 20f, Time, true);
Projectile.scale = Utils.Remap(Time, 0f, 45f, StartingScale, IdealScale);
Projectile.ExpandHitboxBy((int)(Projectile.scale * 62f));
AdjustPlayerValues();
Time++;
}
public void ProduceSubsumingHentai()
public void AdjustPlayerValues()
{
int tentacleDamage = (int)(Projectile.damage * 0.25f);
float xStartingAcceleration = Main.rand.NextFloat(0.001f, 0.04f) * Main.rand.NextBool(2).ToDirectionInt();
float yStartingAcceleration = Main.rand.NextFloat(0.001f, 0.04f) * Main.rand.NextBool(2).ToDirectionInt();
Projectile subsumingHentai = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(),
Projectile.Center,
Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(9f, 13f),
ModContent.ProjectileType<SubsumingTentacle>(),
tentacleDamage,
Projectile.knockBack * 0.5f,
Projectile.owner,
xStartingAcceleration,
yStartingAcceleration
);
subsumingHentai.tileCollide = false;
}
public void TargetingMovement()
{
NPC potentialTarget = Projectile.Center.ClosestNPCAt(600f, true, true);
if (potentialTarget != null)
Projectile.velocity = (Projectile.velocity * 5f + Projectile.SafeDirectionTo(potentialTarget.Center) * 7f) / 6f;
}
public void PulseEffect()
{
Projectile.ExpandHitboxBy(PulseHitboxExpandRatio);
Projectile.Damage();
if (!Main.dedServ)
{
SoundEngine.PlaySound(SoundID.Item43, Projectile.Center);
for (int i = 0; (float)i < 85; i++)
{
float angle = i / 85f * MathHelper.TwoPi;
Vector2 spawnPosition = Projectile.Center + angle.ToRotationVector2() * (500f + Main.rand.NextFloat(-8f, 8f));
Vector2 velocity = (angle - (float)Math.PI).ToRotationVector2() * Main.rand.NextFloat(27f, 38.5f);
Dust dust = Dust.NewDustPerfect(spawnPosition, 264, velocity);
dust.scale = 0.9f;
dust.fadeIn = 1.25f;
dust.color = Main.hslToRgb(i / 85f, 1f, 0.8f);
dust.noGravity = true;
}
}
Projectile.ExpandHitboxBy(1f / PulseHitboxExpandRatio);
}
public void ExplodeEffect()
{
SoundEngine.PlaySound(SoundID.Zombie104, Projectile.Center);
if (!Main.dedServ)
{
for (int i = 0; i < 200; i++)
{
Vector2 velocity = Main.rand.NextVector2Circular(50f, 50f);
Dust dust = Dust.NewDustPerfect(Projectile.Center, 264, velocity);
dust.color = Main.hslToRgb(i / 100f % 1f, 1f, 0.8f);
dust.fadeIn = 1.25f;
dust.noGravity = true;
}
}
if (Main.myPlayer == Projectile.owner)
{
int vortexDamage = (int)(Projectile.damage * 0.75f);
NPC closestTarget = Projectile.Center.ClosestNPCAt(1600f, true, true);
for (int i = 0; i < 12; i++)
{
float rotation = Main.rand.NextFloat(MathHelper.TwoPi);
Vector2 velocity = Vector2.UnitY.RotatedBy(rotation);
if (closestTarget != null)
velocity = Projectile.SafeDirectionTo(closestTarget.Center, -Vector2.UnitY).RotatedByRandom(0.4f);
velocity *= Main.rand.NextFloat(3f, 5f);
Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), Projectile.Center,
velocity,
ModContent.ProjectileType<Vortex>(),
vortexDamage,
Projectile.knockBack,
Projectile.owner,
0f,
Main.rand.NextFloat(0.5f, 1.8f));
}
}
Projectile.spriteDirection = Projectile.direction = Owner.direction;
Owner.heldProj = Projectile.whoAmI;
Owner.itemTime = 2;
Owner.itemAnimation = 2;
}
public override bool PreDraw(ref Color lightColor)
{
int vortexesToDraw = 27;
for (int i = 0; i < vortexesToDraw; i++)
Main.spriteBatch.EnterShaderRegion(BlendState.Additive);
Texture2D worleyNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/BlobbyNoise").Value;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
Vector2 scale = Projectile.Size / worleyNoise.Size() * 2f;
float spinRotation = Main.GlobalTimeWrappedHourly * 2.4f;
GameShaders.Misc["CalamityMod:ExoVortex"].Apply();
// Draw the vortex.
for (int i = 0; i < CalamityUtils.ExoPalette.Length; i++)
{
float rotation = MathHelper.TwoPi / i * vortexesToDraw + Projectile.rotation;
float drawScale = Projectile.scale * 0.66f;
drawScale *= (float)(Math.Cos(Time / 18f + rotation * 2f) + 1f) * 0.3f + 0.7f; // Range of 0.7 to 1. Used to give variance with the scale.
float offsetFactor = (float)(Math.Sin(Time / 18f + rotation * 2f) + 1f) * 0.2f + 0.8f; // Range of 0.8 to 1.
// Due to the way RotatedBy works, the offset can be negative, giving the projectile a
// dual buzzsaw look.
Vector2 drawOffset = Vector2.UnitX.RotatedBy(rotation) * 30f * offsetFactor * drawScale;
Vector2 drawPosition = Projectile.Center + drawOffset - Main.screenPosition;
Color colorToDraw = Main.hslToRgb((i / (float)vortexesToDraw + Time / 40f) % 1f, 1f, 0.75f);
Main.EntitySpriteDraw(ModContent.Request<Texture2D>(Texture).Value,
drawPosition,
null,
colorToDraw * 0.7f,
rotation,
ModContent.Request<Texture2D>(Texture).Size() * 0.5f,
drawScale,
SpriteEffects.None,
0);
float spinDirection = (i % 2f == 0f).ToDirectionInt();
Vector2 drawOffset = (MathHelper.TwoPi * i / CalamityUtils.ExoPalette.Length + Main.GlobalTimeWrappedHourly * spinDirection * 4f).ToRotationVector2() * Projectile.scale * 15f;
Main.spriteBatch.Draw(worleyNoise, drawPosition + drawOffset, null, CalamityUtils.ExoPalette[i], spinDirection * spinRotation, worleyNoise.Size() * 0.5f, scale, 0, 0f);
}
Main.spriteBatch.ExitShaderRegion();
return false;
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

+137
View File
@@ -0,0 +1,137 @@
using System.Collections.Generic;
using CalamityMod.Items.Weapons.Magic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class ExoVortex : ModProjectile
{
public PrimitiveTrail EnergyTrail = null;
public float Hue => Projectile.ai[0];
public ref float Time => ref Projectile.ai[1];
public const float HueShiftAcrossAfterimages = 0.2f;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Subsuming Vortex");
ProjectileID.Sets.TrailingMode[Projectile.type] = 2;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 35;
}
public override void SetDefaults()
{
Projectile.width = 60;
Projectile.height = 60;
Projectile.alpha = 255;
Projectile.scale = 0.01f;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Magic;
Projectile.penetrate = -1;
Projectile.tileCollide = false;
Projectile.MaxUpdates = 4;
Projectile.timeLeft = Projectile.MaxUpdates * 120;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = Projectile.MaxUpdates * 18;
Projectile.ignoreWater = true;
Projectile.hide = true;
}
public override void AI()
{
Time++;
// Move sharply towards nearby targets.
NPC potentialTarget = Projectile.Center.ClosestNPCAt(SubsumingVortex.SmallVortexTargetRange);
if (potentialTarget != null)
{
float flySpeed = 40f / Projectile.MaxUpdates;
Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(potentialTarget.Center) * flySpeed, 0.02f);
}
// Rotate.
Projectile.rotation += Projectile.velocity.X * 0.04f;
// Re-determine the hitbox size.
Projectile.Opacity = Utils.GetLerpValue(0f, 20f, Time, true);
Projectile.scale = Utils.Remap(Time, 0f, Projectile.MaxUpdates * 15f, 0.01f, 1.5f) * Utils.GetLerpValue(0f, Projectile.MaxUpdates * 16f, Projectile.timeLeft, true);
Projectile.ExpandHitboxBy((int)(Projectile.scale * 62f));
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.ExoDebuffs();
}
public override void OnHitPvp(Player target, int damage, bool crit)
{
target.ExoDebuffs();
}
// Draw these vortices behind other projectiles to ensure that it does not draw on top of the big vortex.
public override void DrawBehind(int index, List<int> behindNPCsAndTiles, List<int> behindNPCs, List<int> behindProjectiles, List<int> overPlayers, List<int> overWiresUI)
{
behindProjectiles.Add(index);
}
public float PrimitiveWidthFunction(float completionRatio)
{
float width = Projectile.width * 0.6f;
width *= MathHelper.SmoothStep(0.6f, 1f, Utils.GetLerpValue(0f, 0.3f, completionRatio, true));
return width;
}
public Color PrimitiveTrailColor(float completionRatio)
{
float hue = Hue % 1f + HueShiftAcrossAfterimages;
if (hue >= 0.99f)
hue = 0.99f;
float velocityOpacityFadeout = Utils.GetLerpValue(2f, 5f, Projectile.velocity.Length(), true);
Color c = CalamityUtils.MulticolorLerp(hue, CalamityUtils.ExoPalette) * Projectile.Opacity * (1f - completionRatio);
return c * Utils.GetLerpValue(0.04f, 0.2f, completionRatio, true) * velocityOpacityFadeout;
}
public override bool PreDraw(ref Color lightColor)
{
Main.spriteBatch.EnterShaderRegion(BlendState.Additive);
Texture2D worleyNoise = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/BlobbyNoise").Value;
float spinRotation = Main.GlobalTimeWrappedHourly * 5.2f;
Main.spriteBatch.EnterShaderRegion();
// Draw the streak trail.
EnergyTrail ??= new(PrimitiveWidthFunction, PrimitiveTrailColor, null, GameShaders.Misc["CalamityMod:SideStreakTrail"]);
GameShaders.Misc["CalamityMod:SideStreakTrail"].UseImage1("Images/Misc/Perlin");
EnergyTrail.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + Projectile.velocity.SafeNormalize(Vector2.Zero) * Projectile.scale * 2f, 51);
Main.spriteBatch.EnterShaderRegion(BlendState.Additive);
GameShaders.Misc["CalamityMod:ExoVortex"].Apply();
// Draw the vortex, along with some afterimages.
for (int i = 0; i < 5; i++)
{
float hue = Hue % 1f + i / 4f * HueShiftAcrossAfterimages;
Vector2 scale = MathHelper.Lerp(1f, 0.6f, i / 4f) * Projectile.Size / worleyNoise.Size() * 2f;
Vector2 drawOffset = Vector2.UnitY * Projectile.scale * 6f;
Color c = CalamityUtils.MulticolorLerp(hue, CalamityUtils.ExoPalette) * Projectile.Opacity;
Vector2 drawPosition = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition;
Main.spriteBatch.Draw(worleyNoise, drawPosition - drawOffset, null, c, -spinRotation, worleyNoise.Size() * 0.5f, scale, 0, 0f);
Main.spriteBatch.Draw(worleyNoise, drawPosition + drawOffset, null, c, spinRotation, worleyNoise.Size() * 0.5f, scale, 0, 0f);
}
Main.spriteBatch.ExitShaderRegion();
return false;
}
}
}
-159
View File
@@ -1,159 +0,0 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class SubsumingTentacle : ModProjectile
{
public int AlphaFade
{
get => (int)Projectile.localAI[0];
set => Projectile.localAI[0] = value;
}
public Vector2 OffsetAcceleration
{
get => new Vector2(Projectile.ai[0], Projectile.ai[1]);
set
{
Projectile.ai[0] = value.X;
Projectile.ai[1] = value.Y;
}
}
public const float SegmentOffset = 5f;
public const float MaxArcingSpeed = 16f;
public const float MaxHomingSpeed = 18f;
public const float MaxEnemyDistance = 1450f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Exo Tentacle");
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 75;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 20;
Projectile.friendly = true;
Projectile.penetrate = 2;
Projectile.MaxUpdates = 2;
Projectile.DamageType = DamageClass.Magic;
Projectile.penetrate = -1;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 16;
}
public override void AI()
{
if (!Projectile.tileCollide)
{
AlphaFade++;
Projectile.alpha = AlphaFade;
if (Projectile.alpha >= 255)
{
Projectile.Kill();
return;
}
}
// Here, the old positions act more like "control points" than old postions, and will be referred as such henceforth.
// Each control point should have a set offset, to give a "chain" effect.
for (int i = 1; i < Projectile.oldPos.Length; i++)
{
Projectile.oldPos[i] = Projectile.oldPos[i - 1] + Vector2.Normalize(Projectile.oldPos[i] - Projectile.oldPos[i - 1]) * SegmentOffset;
}
Projectile.ExpandHitboxBy((int)(20f * Projectile.scale));
if (Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height) && Projectile.tileCollide)
{
Projectile.tileCollide = false;
}
NPC closestTarget = Projectile.Center.ClosestNPCAt(MaxEnemyDistance, true, true);
if (closestTarget != null)
{
HomingMovement(closestTarget);
}
else
{
ArcingMovement();
}
Projectile.scale -= closestTarget is null ? 0.007f : 0.004f;
if (Projectile.scale <= 0.05f)
{
Projectile.Kill();
}
}
public void ArcingMovement()
{
// Cause the tentacle to arc around at an increasingly fast rate.
Projectile.velocity += OffsetAcceleration;
if (Projectile.velocity.Length() > MaxArcingSpeed)
{
Projectile.velocity.Normalize();
Projectile.velocity *= MaxArcingSpeed;
}
// Accelerate the arc.
OffsetAcceleration *= 1.035f;
}
public void HomingMovement(NPC closestTarget)
{
float angleOffset = MathHelper.WrapAngle(Projectile.AngleTo(closestTarget.Center) - Projectile.velocity.ToRotation());
angleOffset = MathHelper.Clamp(angleOffset, -0.2f, 0.2f);
if (Projectile.Distance(closestTarget.Center) > 65f)
{
Projectile.velocity = Projectile.velocity.RotatedBy(angleOffset);
Projectile.velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * MaxHomingSpeed;
}
}
public override bool PreDraw(ref Color lightColor)
{
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
if (Projectile.scale < 1f)
{
for (int i = 10; i < Projectile.oldPos.Length; i++)
{
var tentacleShader = GameShaders.Misc["CalamityMod:SubsumingTentacle"];
tentacleShader.UseImage1("Images/Misc/Perlin");
Vector2 drawPos = Projectile.oldPos[i] + ModContent.Request<Texture2D>(Texture).Size() / 2f - Main.screenPosition + Projectile.gfxOffY * Vector2.UnitY;
float scale = MathHelper.Lerp(0.05f, 1.3f, i / (float)Projectile.oldPos.Length) * Projectile.scale;
scale = MathHelper.Clamp(scale, 0f, 2f);
Color color = Projectile.GetAlpha(lightColor) * ((Projectile.oldPos.Length - i) / Projectile.oldPos.Length);
Main.EntitySpriteDraw(ModContent.Request<Texture2D>(Texture).Value, drawPos, null, color, Projectile.rotation, ModContent.Request<Texture2D>(Texture).Size() / 2f, scale, SpriteEffects.None, 0);
tentacleShader.UseSaturation(i / (float)Projectile.oldPos.Length); // A "completion ratio" for the shader. Used to make the entire tentacle appear multi-colored.
tentacleShader.UseOpacity(1f / Projectile.oldPos.Length); // A "step value" for the shader. Used to give variance in color at each individual segment.
tentacleShader.Apply(null);
}
}
return false;
}
public override void PostDraw(Color drawColor)
{
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
}
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
{
for (int i = 1; i < Projectile.oldPos.Length; i++)
{
float scale = MathHelper.Lerp(0.05f, 1f, i / (float)Projectile.oldPos.Length) * Projectile.scale * 0.85f;
if (targetHitbox.Intersects(new Rectangle((int)Projectile.oldPos[i].X, (int)Projectile.oldPos[i].Y, (int)(Projectile.width * scale), (int)(Projectile.height * scale))))
return true;
}
return false;
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
Projectile.velocity = oldVelocity;
return false;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

-163
View File
@@ -1,163 +0,0 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class Vortex : ModProjectile
{
public float TargetCheckCooldown
{
get => Projectile.localAI[0];
set => Projectile.localAI[0] = value;
}
public float Time
{
get => Projectile.localAI[1];
set => Projectile.localAI[1] = value;
}
public int TargetIndex
{
get => (int)Projectile.ai[0];
set => Projectile.ai[0] = value;
}
public const float AngularMovementSpeed = 0.1f;
public const float Acceleration = 0.0025f;
public const float TargetCheckInterval = 30f;
public const float MaximumTargetDistance = 600f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Subsuming Vortex");
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 60;
Projectile.height = 60;
Projectile.alpha = 255;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Magic;
Projectile.penetrate = 1;
Projectile.tileCollide = true;
Projectile.extraUpdates = 4;
Projectile.timeLeft = 115 * Projectile.extraUpdates;
Projectile.ignoreWater = true;
}
public override void AI()
{
// At the very beginning, start without a target.
if (Time == 0f)
{
TargetIndex = -1;
}
Time++;
if (Projectile.localAI[1] > 10f && Main.rand.NextBool(3))
{
VisualEffects();
}
Movement(HandleTargeting());
Projectile.rotation += Projectile.velocity.X * 0.1f;
}
public bool HandleTargeting()
{
float targetCheckDistance = 350f * Projectile.ai[1];
// Reduce a cooldown. Nothing special here.
if (TargetCheckCooldown > 0f)
{
TargetCheckCooldown--;
}
// Attempt to find a target if the projectile has none.
if (TargetIndex == -1 && TargetCheckCooldown <= 0f)
{
NPC potentialTarget = Projectile.Center.ClosestNPCAt(targetCheckDistance, true, true);
if (potentialTarget != null)
TargetIndex = potentialTarget.whoAmI;
Projectile.netUpdate = true;
}
if (TargetCheckCooldown <= 0f && TargetIndex == -1)
{
TargetCheckCooldown = TargetCheckInterval;
}
bool stillCanReachTarget = false;
// Ensure that the target is still in reach if there is indeed a target.
if (TargetIndex != -1)
{
stillCanReachTarget = Projectile.Distance(Main.npc[TargetIndex].Center) < MaximumTargetDistance;
if (!stillCanReachTarget)
{
TargetIndex = -1;
Projectile.netUpdate = true;
}
}
return stillCanReachTarget;
}
public void VisualEffects()
{
// Generate idle circular dust and light after 10 frames.
if (!Main.dedServ)
{
int dustCount = 5;
for (int i = 0; i < dustCount; i++)
{
Vector2 spawnPosition = Projectile.Center + Projectile.Size.RotatedBy(i / (float)dustCount * MathHelper.TwoPi) * 0.333f;
Vector2 velocity = Main.rand.NextFloat(MathHelper.TwoPi).ToRotationVector2() * Main.rand.NextFloat(6f, 16f);
Dust dust = Dust.NewDustPerfect(spawnPosition, 66, velocity, 0, Main.DiscoColor, 0.7f);
dust.noGravity = true;
dust.noLight = true;
dust.velocity = -Projectile.velocity;
}
}
// Fade in.
Projectile.alpha -= 5;
if (Projectile.alpha < 50)
{
Projectile.alpha = 50;
}
// And make rainbow light.
Lighting.AddLight(Projectile.Center / 16, Main.DiscoColor.ToVector3());
}
public void Movement(bool stillCanReachTarget)
{
// Homing sharply towards the target in a circular fashion.
// The way this type of homing is by determining the offset between the angle to the target and the velocity's angle.
// This offset can be thought of as how much, in radians, the velocity would need to rotate to move towards the target.
// Then, the velocity is rotated by that offset (which, as established, would give perfect homing) multiplied by a <1 factor.
// This causes the velocity to constantly rotate sharply towards the target.
if (stillCanReachTarget)
{
float angleOffsetToTarget = Projectile.AngleTo(Main.npc[TargetIndex].Center) - Projectile.velocity.ToRotation();
angleOffsetToTarget = MathHelper.WrapAngle(angleOffsetToTarget); // Ensure the offset is in the range of -pi to pi.
Projectile.velocity = Projectile.velocity.RotatedBy(angleOffsetToTarget * AngularMovementSpeed);
}
// Accelerate constantly with time.
float oldSpeed = Projectile.velocity.Length();
Projectile.velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * (oldSpeed + Acceleration);
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.ExoDebuffs();
}
public override void OnHitPvp(Player target, int damage, bool crit)
{
target.ExoDebuffs();
}
public override bool PreDraw(ref Color lightColor)
{
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1);
return false;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

+1
View File
@@ -65,6 +65,7 @@ namespace CalamityMod
projectile.position -= projectile.Size * 0.5f;
}
public static void ExpandHitboxBy(this Projectile projectile, int newSize) => projectile.ExpandHitboxBy(newSize, newSize);
public static void ExpandHitboxBy(this Projectile projectile, Vector2 newSize) => projectile.ExpandHitboxBy((int)newSize.X, (int)newSize.Y);
public static void ExpandHitboxBy(this Projectile projectile, float expandRatio) => projectile.ExpandHitboxBy((int)(projectile.width * expandRatio), (int)(projectile.height * expandRatio));
public static void HomeInOnNPC(Projectile projectile, bool ignoreTiles, float distanceRequired, float homingVelocity, float N)