Remade the metaball system entirely (#4)
* Remade the metaball system entirely * Rename additive metaball shader registration
No files matched your search
@@ -49,7 +49,6 @@ using CalamityMod.NPCs.StormWeaver;
|
||||
using CalamityMod.NPCs.SupremeCalamitas;
|
||||
using CalamityMod.NPCs.Yharon;
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Projectiles;
|
||||
using CalamityMod.Projectiles.BaseProjectiles;
|
||||
using CalamityMod.Schematics;
|
||||
@@ -345,7 +344,6 @@ namespace CalamityMod
|
||||
// However, render targets and certain other graphical objects can only be created on the main thread.
|
||||
Main.QueueMainThreadAction(() =>
|
||||
{
|
||||
FusableParticleManager.LoadParticleRenderSets();
|
||||
Main.OnPreDraw += PrepareRenderTargets;
|
||||
});
|
||||
|
||||
@@ -376,7 +374,7 @@ namespace CalamityMod
|
||||
GameShaders.Hair.BindShader(ModContent.ItemType<AdrenalineHairDye>(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(0, 255, 171), ((float)player.Calamity().adrenaline / (float)player.Calamity().adrenalineMax))));
|
||||
GameShaders.Hair.BindShader(ModContent.ItemType<RageHairDye>(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(255, 83, 48), ((float)player.Calamity().rage / (float)player.Calamity().rageMax))));
|
||||
GameShaders.Hair.BindShader(ModContent.ItemType<WingTimeHairDye>(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) =>
|
||||
{
|
||||
{
|
||||
float flightTimeInterpolant = player.wingTime / player.wingTimeMax;
|
||||
if (player.mount.Active)
|
||||
flightTimeInterpolant = 1f;
|
||||
@@ -449,7 +447,6 @@ namespace CalamityMod
|
||||
|
||||
Main.QueueMainThreadAction(() =>
|
||||
{
|
||||
FusableParticleManager.UnloadParticleRenderSets();
|
||||
Main.OnPreDraw -= PrepareRenderTargets;
|
||||
});
|
||||
|
||||
@@ -499,7 +496,6 @@ namespace CalamityMod
|
||||
|
||||
public static void PrepareRenderTargets(GameTime gameTime)
|
||||
{
|
||||
FusableParticleManager.PrepareFusableParticleTargets();
|
||||
DeathAshParticle.PrepareRenderTargets();
|
||||
FluidFieldManager.Update();
|
||||
}
|
||||
@@ -517,7 +513,8 @@ namespace CalamityMod
|
||||
saveMethodInfo.Invoke(null, new object[] { cfg });
|
||||
else
|
||||
Instance.Logger.Error("TML ConfigManager.Save reflection failed. Method signature has changed. Notify Calamity Devs if you see this in your log.");
|
||||
} catch
|
||||
}
|
||||
catch
|
||||
{
|
||||
Instance.Logger.Error("An error occurred while manually saving Calamity mod configuration. This may be due to a complex mod conflict. It is safe to ignore this error.");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using CalamityMod.Skies;
|
||||
using Iced.Intel;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using Terraria;
|
||||
@@ -124,14 +123,14 @@ namespace CalamityMod.Effects
|
||||
// Used by Devourer of Gods. Renders the portal that he escapes through at the end of phase 1.
|
||||
internal static Effect DoGPortalShader;
|
||||
|
||||
// Fusable particles. See the FusableParticleManager for comments on how this system works.
|
||||
// These shaders are leveraged to render the results of the fusable particle simulation to the screen.
|
||||
// Metaballs. See the MetaballManager class for comments on how this system works.
|
||||
// These shaders are leveraged to render the results of the metaball simulation to the screen.
|
||||
// The "Base" shader draws the particles themselves.
|
||||
// The "Additive" shader actually FUSES the particles into their blobby mess.
|
||||
//
|
||||
// Backing textures vary. The primary use of this system is Gruesome Eminence.
|
||||
internal static Effect BaseFusableParticleEdgeShader;
|
||||
internal static Effect AdditiveFusableParticleEdgeShader;
|
||||
internal static Effect MetaballEdgeShader;
|
||||
internal static Effect AdditiveMetaballEdgeShader;
|
||||
|
||||
// Used to render the results of Navier-Stokes fluid simulations.
|
||||
internal static Effect FluidShaders;
|
||||
@@ -178,7 +177,7 @@ namespace CalamityMod.Effects
|
||||
internal static Effect CircularGradientWithEdge;
|
||||
internal static Effect WavyOpacity;
|
||||
#endregion
|
||||
|
||||
|
||||
//
|
||||
// All below shaders were added by Amber
|
||||
// Authorship goes to Toasty
|
||||
@@ -187,7 +186,7 @@ namespace CalamityMod.Effects
|
||||
#region Amber's Shaders
|
||||
internal static Effect PrimitiveClearShader;
|
||||
#endregion
|
||||
|
||||
|
||||
// Shorthand to register a loaded shader in Terraria's graphics engine
|
||||
// All shaders registered this way are accessible under GameShaders.Misc
|
||||
// They will use the prefix described above
|
||||
@@ -340,11 +339,11 @@ namespace CalamityMod.Effects
|
||||
RegisterMiscShader(DoGPortalShader, "ScreenPass", "DoGPortal");
|
||||
|
||||
// These two shaders are often (but not always) used together.
|
||||
BaseFusableParticleEdgeShader = LoadShader("ParticleFusion/BaseFusableParticleEdgeShader");
|
||||
RegisterMiscShader(BaseFusableParticleEdgeShader, "ParticlePass", "BaseFusableParticleEdge");
|
||||
MetaballEdgeShader = LoadShader("Metaballs/MetaballEdgeShader");
|
||||
RegisterMiscShader(MetaballEdgeShader, "ParticlePass", "MetaballEdge");
|
||||
|
||||
AdditiveFusableParticleEdgeShader = LoadShader("ParticleFusion/AdditiveFusableParticleEdgeShader");
|
||||
RegisterMiscShader(AdditiveFusableParticleEdgeShader, "ParticlePass", "AdditiveFusableParticleEdge");
|
||||
AdditiveMetaballEdgeShader = LoadShader("Metaballs/AdditiveMetaballEdgeShader");
|
||||
RegisterMiscShader(AdditiveMetaballEdgeShader, "ParticlePass", "AdditiveMetaballEdge");
|
||||
|
||||
// This shader is not registered with the game but is invoked directly to render the results of fluid simulation.
|
||||
FluidShaders = LoadShader("FluidShaders");
|
||||
|
||||
@@ -12,25 +12,16 @@ float uDirection;
|
||||
float3 uLightSource;
|
||||
float2 uImageSize0;
|
||||
float2 uImageSize1;
|
||||
float edgeBorderSize;
|
||||
bool borderShouldBeSolid;
|
||||
float3 edgeBorderColor;
|
||||
float2 screenArea;
|
||||
float2 renderTargetArea;
|
||||
float2 screenMoveOffset;
|
||||
float2 generalBackgroundOffset;
|
||||
bool invertedScreen;
|
||||
float2 upscaleFactor;
|
||||
float4 uShaderSpecificData;
|
||||
|
||||
float2 screenArea;
|
||||
float2 layerOffset;
|
||||
float2 singleFrameScreenOffset;
|
||||
|
||||
float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float2 originalCoords = coords;
|
||||
if (invertedScreen)
|
||||
coords.y = 1 - coords.y;
|
||||
|
||||
// Account for screen movements. Not doing this causes the scene to move based on that.
|
||||
coords += screenMoveOffset / renderTargetArea;
|
||||
coords += layerOffset + singleFrameScreenOffset;
|
||||
|
||||
float2 offset = 3 / screenArea;
|
||||
float4 color = tex2D(uImage0, coords);
|
||||
@@ -0,0 +1,59 @@
|
||||
sampler metaballContents : register(s0);
|
||||
sampler overlayTexture : register(s1);
|
||||
|
||||
float2 screenSize;
|
||||
float2 layerSize;
|
||||
float2 layerOffset;
|
||||
float4 edgeColor;
|
||||
float2 singleFrameScreenOffset;
|
||||
|
||||
// The usage of these two methods seemingly prevents imprecision problems for some reason.
|
||||
float2 convertToScreenCoords(float2 coords)
|
||||
{
|
||||
return coords * screenSize;
|
||||
}
|
||||
|
||||
float2 convertFromScreenCoords(float2 coords)
|
||||
{
|
||||
return coords / screenSize;
|
||||
}
|
||||
|
||||
float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0
|
||||
{
|
||||
// Calculate the base color. This is the calculated from the raw objects in the metaball render target.
|
||||
float4 baseColor = tex2D(metaballContents, coords);
|
||||
|
||||
// Used to negate the need for an inverted if (baseColor.a > 0) by ensuring all of the edge checks fail.
|
||||
float alphaOffset = (1 - any(baseColor.a));
|
||||
|
||||
// Check if there are any empty pixels nearby. If there are, that means this pixel is at an edge, and should be colored accordingly.
|
||||
float left = tex2D(metaballContents, convertFromScreenCoords(convertToScreenCoords(coords) + float2(-2, 0))).a + alphaOffset;
|
||||
float right = tex2D(metaballContents, convertFromScreenCoords(convertToScreenCoords(coords) + float2(2, 0))).a + alphaOffset;
|
||||
float top = tex2D(metaballContents, convertFromScreenCoords(convertToScreenCoords(coords) + float2(0, -2))).a + alphaOffset;
|
||||
float bottom = tex2D(metaballContents, convertFromScreenCoords(convertToScreenCoords(coords) + float2(0, 2))).a + alphaOffset;
|
||||
|
||||
// Use step instead of branching in order to determine whether neighboring pixels are invisible.
|
||||
float leftHasNoAlpha = step(left, 0);
|
||||
float rightHasNoAlpha = step(right, 0);
|
||||
float topHasNoAlpha = step(top, 0);
|
||||
float bottomHasNoAlpha = step(bottom, 0);
|
||||
|
||||
// Use addition instead of the OR boolean operator to get a 0-1 value for whether an edge is invisible.
|
||||
// The equivalent for AND would be multiplication.
|
||||
float conditionOpacityFactor = 1 - saturate(leftHasNoAlpha + rightHasNoAlpha + topHasNoAlpha + bottomHasNoAlpha);
|
||||
|
||||
// Calculate layer colors.
|
||||
float4 layerColor = tex2D(overlayTexture, (coords + layerOffset + singleFrameScreenOffset) * screenSize / layerSize);
|
||||
float4 defaultColor = layerColor * tex2D(metaballContents, coords) * sampleColor;
|
||||
|
||||
// Lastly, use the aforementioned condition to switch between the colors. If conditionOpacityFactor is 1, the default color is
|
||||
// zeroed out and the edge is toggled, and vice versa.
|
||||
return (defaultColor * conditionOpacityFactor) + (edgeColor * sampleColor * (1 - conditionOpacityFactor));
|
||||
}
|
||||
technique Technique1
|
||||
{
|
||||
pass ParticlePass
|
||||
{
|
||||
PixelShader = compile ps_2_0 PixelShaderFunction();
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
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;
|
||||
float edgeBorderSize;
|
||||
bool borderShouldBeSolid;
|
||||
float3 edgeBorderColor;
|
||||
float2 screenArea;
|
||||
float2 renderTargetArea;
|
||||
float2 screenMoveOffset;
|
||||
float2 generalBackgroundOffset;
|
||||
bool invertedScreen;
|
||||
float2 upscaleFactor;
|
||||
float4 uShaderSpecificData;
|
||||
|
||||
float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float2 originalCoords = coords;
|
||||
if (invertedScreen)
|
||||
coords.y = 1 - coords.y;
|
||||
|
||||
// Account for screen movements. Not doing this causes the scene to move based on that.
|
||||
coords += screenMoveOffset / renderTargetArea;
|
||||
|
||||
float4 color = tex2D(uImage0, coords);
|
||||
|
||||
// Determine how much downscaling is required to reasonably zoom in on things.
|
||||
float downscaleFactor = float2(5, 5) / upscaleFactor / max(renderTargetArea.x, renderTargetArea.y) / 2;
|
||||
float2 backgroundCoords = frac((renderTargetArea * (originalCoords + generalBackgroundOffset * upscaleFactor) + uWorldPosition) * downscaleFactor);
|
||||
float4 backgroundColor = tex2D(uImage1, backgroundCoords);
|
||||
|
||||
// Equivalent to edgeBorderSize pixels in both the X and Y direction.
|
||||
float2 edgeOffset = float2(edgeBorderSize, edgeBorderSize) / renderTargetArea;
|
||||
|
||||
// Check if the cardinal directions are not intersecting with any other active parts of the render target.
|
||||
// If one of them isn't, that means that a border should be rendered.
|
||||
float4 aboveColor = tex2D(uImage0, coords + float2(0, edgeOffset.y));
|
||||
float4 belowColor = tex2D(uImage0, coords - float2(0, edgeOffset.y));
|
||||
float4 leftColor = tex2D(uImage0, coords + float2(edgeOffset.x, 0));
|
||||
float4 rightColor = tex2D(uImage0, coords - float2(edgeOffset.x, 0));
|
||||
|
||||
// Invert color check thresholds based on whether the border should be solid when drawing.
|
||||
float checkThreshold = 0.02;
|
||||
if (!borderShouldBeSolid)
|
||||
checkThreshold = 0.95;
|
||||
|
||||
// If any cardinal color is sufficiently close to transparency choose an edge border color.
|
||||
// Opacity multipliers ensure that this does not affect completely invisible areas of the render target.
|
||||
if (aboveColor.r < checkThreshold || belowColor.r < checkThreshold || leftColor.r < checkThreshold || rightColor.r < checkThreshold)
|
||||
{
|
||||
float borderOpacity = color.a;
|
||||
|
||||
// Use binary opacity if the border should be solid when drawing.
|
||||
if (borderOpacity > 0 && borderShouldBeSolid)
|
||||
borderOpacity = 1;
|
||||
|
||||
return float4(edgeBorderColor, 1) * borderOpacity;
|
||||
}
|
||||
|
||||
return backgroundColor;
|
||||
}
|
||||
technique Technique1
|
||||
{
|
||||
pass ParticlePass
|
||||
{
|
||||
PixelShader = compile ps_2_0 PixelShaderFunction();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 383 B |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
@@ -0,0 +1,144 @@
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
using CalamityMod.Projectiles.Magic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
public class GruesomeMetaball : Metaball
|
||||
{
|
||||
public class GruesomeParticle
|
||||
{
|
||||
public float Size;
|
||||
|
||||
public Vector2 Velocity;
|
||||
|
||||
public Vector2 Center;
|
||||
|
||||
public GruesomeParticle(Vector2 center, Vector2 velocity, float size)
|
||||
{
|
||||
Center = center;
|
||||
Velocity = velocity;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Size *= 0.94f;
|
||||
Center += Velocity;
|
||||
Velocity *= 0.96f;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Asset<Texture2D>> layerAssets;
|
||||
|
||||
public static List<GruesomeParticle> Particles
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
|
||||
// Check if there are any extraneous particles or if the Gruesome Eminence projectile is present when deciding if this particle should be drawn.
|
||||
public override bool AnythingToDraw => Particles.Any() || CalamityUtils.AnyProjectiles(ModContent.ProjectileType<SpiritCongregation>());
|
||||
|
||||
public override IEnumerable<Texture2D> Layers
|
||||
{
|
||||
get
|
||||
{
|
||||
for (int i = 0; i < layerAssets.Count; i++)
|
||||
yield return layerAssets[i].Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override MetaballDrawLayer DrawContext => MetaballDrawLayer.AfterProjectiles;
|
||||
|
||||
public override Color EdgeColor => new(61, 6, 2);
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
// Load layer assets.
|
||||
layerAssets = new();
|
||||
|
||||
for (int i = 1; i <= 5; i++)
|
||||
layerAssets.Add(ModContent.Request<Texture2D>($"CalamityMod/Graphics/Metaballs/GruesomeEminence_Ghost_Layer{i}", AssetRequestMode.ImmediateLoad));
|
||||
}
|
||||
|
||||
public override void ClearInstances() => Particles.Clear();
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// Update all particle instances.
|
||||
// Once sufficiently small, they vanish.
|
||||
for (int i = 0; i < Particles.Count; i++)
|
||||
Particles[i].Update();
|
||||
Particles.RemoveAll(p => p.Size <= 2.5f);
|
||||
}
|
||||
|
||||
public static void SpawnParticle(Vector2 position, Vector2 velocity, float size) =>
|
||||
Particles.Add(new(position, velocity, size));
|
||||
|
||||
public override Vector2 CalculateManualOffsetForLayer(int layerIndex)
|
||||
{
|
||||
switch (layerIndex)
|
||||
{
|
||||
// Background.
|
||||
case 0:
|
||||
return Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.03f;
|
||||
|
||||
// Gaseous skulls.
|
||||
case 1:
|
||||
Vector2 offset = Vector2.One * (float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.041f) * 2f;
|
||||
offset = offset.RotatedBy((float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.08f) * 0.97f);
|
||||
return offset;
|
||||
|
||||
// Spooky faces 1.
|
||||
case 2:
|
||||
offset = (Main.GlobalTimeWrappedHourly * 2.02f).ToRotationVector2() * 0.036f;
|
||||
offset.Y += (float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.161f) * 0.5f + 0.5f;
|
||||
return offset;
|
||||
|
||||
// Spooky faces 2.
|
||||
case 3:
|
||||
offset = Vector2.UnitX * Main.GlobalTimeWrappedHourly * -0.04f + (Main.GlobalTimeWrappedHourly * 1.89f).ToRotationVector2() * 0.03f;
|
||||
offset.Y += CalamityUtils.PerlinNoise2D(Main.GlobalTimeWrappedHourly * 0.187f, Main.GlobalTimeWrappedHourly * 0.193f, 2, 466920161) * 0.025f;
|
||||
return offset;
|
||||
|
||||
// Spooky faces 3.
|
||||
case 4:
|
||||
offset = Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.037f + (Main.GlobalTimeWrappedHourly * 1.77f).ToRotationVector2() * 0.04725f;
|
||||
offset.Y += CalamityUtils.PerlinNoise2D(Main.GlobalTimeWrappedHourly * 0.187f, Main.GlobalTimeWrappedHourly * 0.193f, 2, 577215664) * 0.05f;
|
||||
return offset;
|
||||
}
|
||||
|
||||
return Vector2.Zero;
|
||||
}
|
||||
|
||||
public override void DrawInstances()
|
||||
{
|
||||
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/BasicCircle").Value;
|
||||
|
||||
// Draw all particles.
|
||||
foreach (GruesomeParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = tex.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / tex.Size();
|
||||
Main.spriteBatch.Draw(tex, drawPosition, null, Color.White, 0f, origin, scale, 0, 0f);
|
||||
}
|
||||
|
||||
// Draw gruesome eminence ghost heads.
|
||||
foreach (Projectile eminence in CalamityUtils.AllProjectilesByID(ModContent.ProjectileType<SpiritCongregation>()))
|
||||
eminence.ModProjectile<SpiritCongregation>().DrawHeadForMetaball();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CalamityMod.Effects;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
public abstract class Metaball : ModType
|
||||
{
|
||||
internal List<ManagedRenderTarget> LayerTargets = new();
|
||||
|
||||
/// <summary>
|
||||
/// Required utility that is used to determine whether this metaball has anything to draw.<br></br>
|
||||
/// This exists for efficiency, ensuring that as few operations are executed as possible when not required.
|
||||
/// </summary>
|
||||
public abstract bool AnythingToDraw
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection of all textures to draw on top of the metaball contents.
|
||||
/// </summary>
|
||||
public abstract IEnumerable<Texture2D> Layers
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The draw layer in which metaballs should be drawn.
|
||||
/// </summary>
|
||||
public abstract MetaballDrawLayer DrawContext
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The color that metaballs should draw at the edge between air and particle contents.
|
||||
/// </summary>
|
||||
public abstract Color EdgeColor
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the layer overlay contents from <see cref="Layers"/> should be fixed to the screen.<br></br>
|
||||
/// When true, the texture will be statically drawn to the screen with no respect for world position.
|
||||
/// </summary>
|
||||
public virtual bool FixedToScreen => false;
|
||||
|
||||
/// <summary>
|
||||
/// Optionally overridable method for clearing particle instances as necessary. This is used automatically in contexts such as world unloads.
|
||||
/// </summary>
|
||||
public virtual void ClearInstances() { }
|
||||
|
||||
/// <summary>
|
||||
/// Optionally overridable method that can be used to update the metaball set. This can be useful for over-time update effects or for keeping special data particle types all updated.
|
||||
/// </summary>
|
||||
public virtual void Update() { }
|
||||
|
||||
/// <summary>
|
||||
/// Optionally overridable method that can be used to make layers offset when drawn, to allow for layer-specific animations. Defaults to <see cref="Vector2.Zero"/>, aka no animation.
|
||||
/// </summary>
|
||||
public virtual Vector2 CalculateManualOffsetForLayer(int layerIndex) => Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Optionally overridable method that allows for <see cref="SpriteBatch"/> preparations prior to the drawing of the individual raw metaball instances <i>(Not the final result)</i>.<br></br>
|
||||
/// An example of this could be having the metaball particles drawn with <see cref="BlendState.Additive"/>.
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">Shorthand parameter for <see cref="Main.spriteBatch"/>.</param>
|
||||
public virtual void PrepareSpriteBatch(SpriteBatch spriteBatch) { }
|
||||
|
||||
/// <summary>
|
||||
/// Optionally overridable method that defines for preparations for the render target. Defaults to using the typical texture overlay behavior.
|
||||
/// </summary>
|
||||
/// <param name="layerIndex">The layer index that should be prepared for.</param>
|
||||
public virtual void PrepareShaderForTarget(int layerIndex)
|
||||
{
|
||||
// Store the graphics device and shader in easy to use local variables.
|
||||
var metaballShader = CalamityShaders.MetaballEdgeShader;
|
||||
var gd = Main.instance.GraphicsDevice;
|
||||
|
||||
// Fetch the layer texture. This is the texture that will be overlayed over the greyscale contents on the screen.
|
||||
Texture2D layerTexture = Layers.ElementAt(layerIndex);
|
||||
|
||||
// Calculate the layer scroll offset. This is used to ensure that the texture contents of the given metaball have parallax, rather than being static over the screen
|
||||
// regardless of world position.
|
||||
// This may be toggled off optionally by the metaball.
|
||||
Vector2 screenSize = new(Main.screenWidth, Main.screenHeight);
|
||||
Vector2 layerScrollOffset = Main.screenPosition / screenSize + CalculateManualOffsetForLayer(layerIndex);
|
||||
if (FixedToScreen)
|
||||
layerScrollOffset = Vector2.Zero;
|
||||
|
||||
// Supply shader parameter values.
|
||||
metaballShader.Parameters["layerSize"]?.SetValue(layerTexture.Size());
|
||||
metaballShader.Parameters["screenSize"]?.SetValue(screenSize);
|
||||
metaballShader.Parameters["layerOffset"]?.SetValue(layerScrollOffset);
|
||||
metaballShader.Parameters["edgeColor"]?.SetValue(EdgeColor.ToVector4());
|
||||
metaballShader.Parameters["singleFrameScreenOffset"]?.SetValue((Main.screenLastPosition - Main.screenPosition) / screenSize);
|
||||
|
||||
// Supply the metaball's layer texture to the graphics device so that the shader can read it.
|
||||
gd.Textures[1] = layerTexture;
|
||||
gd.SamplerStates[1] = SamplerState.LinearWrap;
|
||||
|
||||
// Apply the metaball shader.
|
||||
metaballShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Required overridable that is intended to draw all metaball instances.
|
||||
/// </summary>
|
||||
public abstract void DrawInstances();
|
||||
|
||||
protected sealed override void Register()
|
||||
{
|
||||
// Register this metaball mod TML's inbuilt ModType handlers.
|
||||
ModTypeLookup<Metaball>.Register(this);
|
||||
|
||||
// Store this metaball instance in the personalized manager so that it can be kept track of for rendering purposes.
|
||||
if (!MetaballManager.metaballs.Contains(this))
|
||||
MetaballManager.metaballs.Add(this);
|
||||
|
||||
// Disallow render target creation on servers.
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
// Generate render targets.
|
||||
Main.QueueMainThreadAction(() =>
|
||||
{
|
||||
// Load render targets.
|
||||
int layerCount = Layers.Count();
|
||||
for (int i = 0; i < layerCount; i++)
|
||||
LayerTargets.Add(new(true, ManagedRenderTarget.CreateScreenSizedTarget));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes of all unmanaged GPU resources used up by the <see cref="LayerTargets"/>. This is called automatically on mod unload.<br></br>
|
||||
/// <i>It is your responsibility to recreate layer targets later if you call this method manually.</i>
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
for (int i = 0; i < LayerTargets.Count; i++)
|
||||
LayerTargets[i]?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
public enum MetaballDrawLayer
|
||||
{
|
||||
BeforeNPCs,
|
||||
BeforeProjectiles,
|
||||
AfterProjectiles,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
public class MetaballManager : ModSystem
|
||||
{
|
||||
internal static readonly List<Metaball> metaballs = new();
|
||||
|
||||
public override void OnModLoad()
|
||||
{
|
||||
// Prepare event subscribers.
|
||||
RenderTargetManager.RenderTargetUpdateLoopEvent += PrepareMetaballTargets;
|
||||
On_Main.DrawProjectiles += DrawMetaballsAfterProjectiles;
|
||||
On_Main.DrawNPCs += DrawMetaballsBeforeNPCs;
|
||||
}
|
||||
|
||||
public override void OnModUnload()
|
||||
{
|
||||
// Clear all unmanaged metaball target resources on the GPU on mod unload.
|
||||
Main.QueueMainThreadAction(() =>
|
||||
{
|
||||
foreach (Metaball metaball in metaballs)
|
||||
metaball?.Dispose();
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnWorldUnload()
|
||||
{
|
||||
foreach (Metaball metaball in metaballs)
|
||||
metaball.ClearInstances();
|
||||
}
|
||||
|
||||
private void PrepareMetaballTargets()
|
||||
{
|
||||
// Get a list of all metaballs currently in use.
|
||||
var activeMetaballs = metaballs.Where(m => m.AnythingToDraw);
|
||||
|
||||
// Don't bother wasting resources if metaballs are not in use at the moment.
|
||||
if (!activeMetaballs.Any())
|
||||
return;
|
||||
|
||||
// Prepare the sprite batch for drawing. Metaballs may restart the sprite batch via PrepareSpriteBatch if their implementation requires it.
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, Main.Rasterizer, null, Matrix.Identity);
|
||||
|
||||
var gd = Main.instance.GraphicsDevice;
|
||||
foreach (Metaball metaball in activeMetaballs)
|
||||
{
|
||||
// Update the metaball collection.
|
||||
if (!Main.gamePaused)
|
||||
metaball.Update();
|
||||
|
||||
// Prepare the sprite batch in accordance to the needs of the metaball instance. By default this does nothing,
|
||||
metaball.PrepareSpriteBatch(Main.spriteBatch);
|
||||
|
||||
// Draw the raw contents of the metaball to each of its render targets.
|
||||
foreach (ManagedRenderTarget target in metaball.LayerTargets)
|
||||
{
|
||||
gd.SetRenderTarget(target);
|
||||
gd.Clear(Color.Transparent);
|
||||
metaball.DrawInstances();
|
||||
|
||||
// Flush metaball contents to its render target and reset the sprite batch for the next iteration.
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, Main.Rasterizer, null, Matrix.Identity);
|
||||
}
|
||||
}
|
||||
|
||||
// Return to the backbuffer and end the sprite batch.
|
||||
gd.SetRenderTarget(null);
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
|
||||
private void DrawMetaballsAfterProjectiles(On_Main.orig_DrawProjectiles orig, Main self)
|
||||
{
|
||||
if (AnyActiveMetaballsAtLayer(MetaballDrawLayer.BeforeProjectiles))
|
||||
{
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
|
||||
DrawMetaballs(MetaballDrawLayer.BeforeProjectiles);
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
|
||||
orig(self);
|
||||
|
||||
if (AnyActiveMetaballsAtLayer(MetaballDrawLayer.AfterProjectiles))
|
||||
{
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
|
||||
DrawMetaballs(MetaballDrawLayer.AfterProjectiles);
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMetaballsBeforeNPCs(On_Main.orig_DrawNPCs orig, Main self, bool behindTiles)
|
||||
{
|
||||
if (!behindTiles && AnyActiveMetaballsAtLayer(MetaballDrawLayer.BeforeNPCs))
|
||||
{
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
|
||||
DrawMetaballs(MetaballDrawLayer.BeforeNPCs);
|
||||
Main.spriteBatch.ExitShaderRegion();
|
||||
}
|
||||
orig(self, behindTiles);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a metaball of a given layering type is currently in use. This is used to minimize needless <see cref="SpriteBatch"/> restarts when there is nothing to draw.
|
||||
/// </summary>
|
||||
/// <param name="layerType">The metaball layer type to check against.</param>
|
||||
internal static bool AnyActiveMetaballsAtLayer(MetaballDrawLayer layerType) =>
|
||||
metaballs.Any(m => m.AnythingToDraw && m.DrawContext == layerType);
|
||||
|
||||
/// <summary>
|
||||
/// Draws all metaballs of a given <see cref="MetaballDrawLayer"/>. Used for layer ordering reasons.
|
||||
/// </summary>
|
||||
/// <param name="layerType">The layer type to draw with.</param>
|
||||
public static void DrawMetaballs(MetaballDrawLayer layerType)
|
||||
{
|
||||
foreach (Metaball metaball in metaballs.Where(m => m.DrawContext == layerType && m.AnythingToDraw))
|
||||
{
|
||||
for (int i = 0; i < metaball.LayerTargets.Count; i++)
|
||||
{
|
||||
// Prepare shaders for the given layer target.
|
||||
metaball.PrepareShaderForTarget(i);
|
||||
|
||||
// Draw the metaball's raw contents with the shader.
|
||||
Main.spriteBatch.Draw(metaball.LayerTargets[i], Main.screenLastPosition - Main.screenPosition, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
using CalamityMod.Effects;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
public class CyanPaint : PaintMetaball
|
||||
{
|
||||
public override Color EdgeColor => Color.Cyan * 0.7f;
|
||||
}
|
||||
|
||||
public class BluePaint : PaintMetaball
|
||||
{
|
||||
public override Color EdgeColor => Color.Blue * 0.7f;
|
||||
}
|
||||
|
||||
public class MagentaPaint : PaintMetaball
|
||||
{
|
||||
public override Color EdgeColor => Color.Magenta * 0.7f;
|
||||
}
|
||||
|
||||
public class LimePaint : PaintMetaball
|
||||
{
|
||||
public override Color EdgeColor => Color.Lime * 0.7f;
|
||||
}
|
||||
|
||||
public class YellowPaint : PaintMetaball
|
||||
{
|
||||
public override Color EdgeColor => Color.Yellow * 0.7f;
|
||||
}
|
||||
|
||||
public abstract class PaintMetaball : Metaball
|
||||
{
|
||||
public class PaintParticle
|
||||
{
|
||||
public float Size;
|
||||
|
||||
public Vector2 Center;
|
||||
|
||||
public PaintParticle(Vector2 center, float size)
|
||||
{
|
||||
Center = center;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Size = MathHelper.Clamp(Size - 0.1f, 0f, 200f) * 0.997f;
|
||||
if (Size < 20f)
|
||||
Size = Size * 0.8f - 1f;
|
||||
}
|
||||
}
|
||||
|
||||
// This list is personalized between the various subclasses.
|
||||
public List<PaintParticle> Particles
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
|
||||
public override bool AnythingToDraw => Particles.Any();
|
||||
|
||||
public override MetaballDrawLayer DrawContext => MetaballDrawLayer.AfterProjectiles;
|
||||
|
||||
public override IEnumerable<Texture2D> Layers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return ModContent.Request<Texture2D>("CalamityMod/Projectiles/InvisibleProj").Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ClearInstances() => Particles.Clear();
|
||||
|
||||
public override void PrepareShaderForTarget(int layerIndex)
|
||||
{
|
||||
// Store the shader in an easy to use local variable.
|
||||
var metaballShader = CalamityShaders.AdditiveMetaballEdgeShader;
|
||||
|
||||
// Calculate the layer scroll offset. This is used to ensure that the texture contents of the given metaball have parallax, rather than being static over the screen
|
||||
// regardless of world position.
|
||||
Vector2 screenSize = new(Main.screenWidth, Main.screenHeight);
|
||||
|
||||
// Supply shader parameter values.
|
||||
metaballShader.Parameters["screenArea"]?.SetValue(screenSize);
|
||||
metaballShader.Parameters["layerOffset"]?.SetValue(Vector2.Zero);
|
||||
metaballShader.Parameters["singleFrameScreenOffset"]?.SetValue(Vector2.Zero);
|
||||
|
||||
// Apply the metaball shader.
|
||||
metaballShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public void SpawnParticle(Vector2 position, float size) =>
|
||||
Particles.Add(new(position, size));
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// Update all particle instances.
|
||||
// Once sufficiently small, they vanish.
|
||||
for (int i = 0; i < Particles.Count; i++)
|
||||
Particles[i].Update();
|
||||
Particles.RemoveAll(p => p.Size <= 3f);
|
||||
}
|
||||
|
||||
public override void PrepareSpriteBatch(SpriteBatch spriteBatch)
|
||||
{
|
||||
// Draw with additive blending.
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, Main.Rasterizer, null, Matrix.Identity);
|
||||
}
|
||||
|
||||
public override void DrawInstances()
|
||||
{
|
||||
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/SmallGreyscaleCircle").Value;
|
||||
|
||||
// Draw all particles.
|
||||
foreach (PaintParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = tex.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / tex.Size();
|
||||
Color paintColor = Color.Lerp(EdgeColor, new Color(0f, 0f, 1f), Utils.GetLerpValue(50f, 100f, particle.Size, true) * 0.1f) * 1.2f;
|
||||
|
||||
Main.spriteBatch.Draw(tex, drawPosition, null, paintColor, 0f, origin, scale, 0, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CalamityMod.Effects;
|
||||
using System;
|
||||
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
// CONSIDER -- Dominic 01NOV2023 This really should not be a metaball. Some sort of separately drawn fire effect would be far more suitable, and overall less awkward.
|
||||
// However, for consistency with the previous effect, I'll leave it as is.
|
||||
public class RancorLavaMetaball : Metaball
|
||||
{
|
||||
public class LavaParticle
|
||||
{
|
||||
public int Time;
|
||||
|
||||
public float Size;
|
||||
|
||||
public Vector2 Center;
|
||||
|
||||
public LavaParticle(Vector2 center, float size)
|
||||
{
|
||||
Center = center;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Time++;
|
||||
Size = MathHelper.Clamp(Size - 0.24f, 0f, 200f) * 0.9956f;
|
||||
if (Size < 15f)
|
||||
Size = Size * 0.95f - 0.9f;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<LavaParticle> Particles
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
|
||||
public override bool AnythingToDraw => Particles.Any();
|
||||
|
||||
public override MetaballDrawLayer DrawContext => MetaballDrawLayer.AfterProjectiles;
|
||||
|
||||
public override IEnumerable<Texture2D> Layers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return ModContent.Request<Texture2D>("CalamityMod/Projectiles/InvisibleProj").Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override Color EdgeColor => new(255, 56, 3);
|
||||
|
||||
public override void ClearInstances() => Particles.Clear();
|
||||
|
||||
public override void PrepareShaderForTarget(int layerIndex)
|
||||
{
|
||||
// Store the shader in an easy to use local variable.
|
||||
var metaballShader = CalamityShaders.AdditiveMetaballEdgeShader;
|
||||
|
||||
// Calculate the layer scroll offset. This is used to ensure that the texture contents of the given metaball have parallax, rather than being static over the screen
|
||||
// regardless of world position.
|
||||
Vector2 screenSize = new(Main.screenWidth, Main.screenHeight);
|
||||
|
||||
// Supply shader parameter values.
|
||||
metaballShader.Parameters["screenArea"]?.SetValue(screenSize);
|
||||
metaballShader.Parameters["layerOffset"]?.SetValue(Vector2.Zero);
|
||||
metaballShader.Parameters["singleFrameScreenOffset"]?.SetValue(Vector2.Zero);
|
||||
|
||||
// Apply the metaball shader.
|
||||
metaballShader.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public static void SpawnParticle(Vector2 position, float size) =>
|
||||
Particles.Add(new(position, size));
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// Update all particle instances.
|
||||
// Once sufficiently small, they vanish.
|
||||
for (int i = 0; i < Particles.Count; i++)
|
||||
Particles[i].Update();
|
||||
Particles.RemoveAll(p => p.Size <= 3f);
|
||||
}
|
||||
|
||||
public override void PrepareSpriteBatch(SpriteBatch spriteBatch)
|
||||
{
|
||||
// Draw with additive blending.
|
||||
Main.spriteBatch.End();
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, Main.Rasterizer, null, Matrix.Identity);
|
||||
}
|
||||
|
||||
public override void DrawInstances()
|
||||
{
|
||||
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/SmallGreyscaleCircle").Value;
|
||||
|
||||
// Draw all particles.
|
||||
foreach (LavaParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = tex.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / tex.Size();
|
||||
Color lavaColor = EdgeColor * 1.2f;
|
||||
|
||||
// Make the lava color vary slightly based on position, to make the effect less monotonous.
|
||||
lavaColor.B = (byte)(lavaColor.B + (int)(MathF.Cos(particle.Center.Y * 0.015f + Main.GlobalTimeWrappedHourly * 0.1f) * 3f));
|
||||
|
||||
// Make the lava color bright for the first few frames of its existence.
|
||||
float brightnessInterpolant = Utils.GetLerpValue(10f, 2f, particle.Time, true) * 0.67f;
|
||||
lavaColor = Color.Lerp(lavaColor, Color.Wheat, brightnessInterpolant);
|
||||
|
||||
Main.spriteBatch.Draw(tex, drawPosition, null, lavaColor, 0f, origin, scale, 0, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,103 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
public class StreamGougeMetaball : Metaball
|
||||
{
|
||||
public class CosmicParticle
|
||||
{
|
||||
public float Size;
|
||||
|
||||
public Vector2 Velocity;
|
||||
|
||||
public Vector2 Center;
|
||||
|
||||
public CosmicParticle(Vector2 center, Vector2 velocity, float size)
|
||||
{
|
||||
Center = center;
|
||||
Velocity = velocity;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Center += Velocity;
|
||||
Velocity *= 0.96f;
|
||||
Size *= 0.91f;
|
||||
}
|
||||
}
|
||||
|
||||
public static Asset<Texture2D> LayerAsset
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public static List<CosmicParticle> Particles
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
|
||||
public override bool AnythingToDraw => Particles.Any();
|
||||
|
||||
public override IEnumerable<Texture2D> Layers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return LayerAsset.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override MetaballDrawLayer DrawContext => MetaballDrawLayer.AfterProjectiles;
|
||||
|
||||
public override Color EdgeColor => Color.Lerp(Color.DarkBlue, Color.Black, 0.75f);
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
// Load the layer asset wrapper.
|
||||
LayerAsset = ModContent.Request<Texture2D>($"CalamityMod/Graphics/Metaballs/StreamGougeLayer", AssetRequestMode.ImmediateLoad);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// Update all particle instances.
|
||||
// Once sufficiently small, they vanish.
|
||||
for (int i = 0; i < Particles.Count; i++)
|
||||
Particles[i].Update();
|
||||
Particles.RemoveAll(p => p.Size <= 2f);
|
||||
}
|
||||
|
||||
public static void SpawnParticle(Vector2 position, Vector2 velocity, float size) =>
|
||||
Particles.Add(new(position, velocity, size));
|
||||
|
||||
// Make the texture scroll.
|
||||
public override Vector2 CalculateManualOffsetForLayer(int layerIndex)
|
||||
{
|
||||
return Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.037f;
|
||||
}
|
||||
|
||||
public override void DrawInstances()
|
||||
{
|
||||
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/BasicCircle").Value;
|
||||
|
||||
foreach (CosmicParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = tex.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / tex.Size();
|
||||
Main.spriteBatch.Draw(tex, drawPosition, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
using static CalamityMod.Graphics.Metaballs.StreamGougeMetaball;
|
||||
|
||||
namespace CalamityMod.Graphics.Metaballs
|
||||
{
|
||||
public class VoidGeneratorMetaball : Metaball
|
||||
{
|
||||
public static List<CosmicParticle> Particles
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
|
||||
public override bool AnythingToDraw => Particles.Any();
|
||||
|
||||
public override IEnumerable<Texture2D> Layers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return LayerAsset.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override MetaballDrawLayer DrawContext => MetaballDrawLayer.BeforeProjectiles;
|
||||
|
||||
public override Color EdgeColor => Color.Lerp(Color.Purple, Color.Black, 0.75f);
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// Update all particle instances.
|
||||
// Once sufficiently small, they vanish.
|
||||
for (int i = 0; i < Particles.Count; i++)
|
||||
Particles[i].Update();
|
||||
Particles.RemoveAll(p => p.Size <= 2f);
|
||||
}
|
||||
|
||||
public static CosmicParticle SpawnParticle(Vector2 position, Vector2 velocity, float size)
|
||||
{
|
||||
CosmicParticle particle = new(position, velocity, size);
|
||||
Particles.Add(particle);
|
||||
|
||||
return particle;
|
||||
}
|
||||
|
||||
// Make the texture scroll.
|
||||
public override Vector2 CalculateManualOffsetForLayer(int layerIndex)
|
||||
{
|
||||
return Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.037f;
|
||||
}
|
||||
|
||||
public override void DrawInstances()
|
||||
{
|
||||
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/BasicCircle").Value;
|
||||
|
||||
foreach (CosmicParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = tex.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / tex.Size();
|
||||
Main.spriteBatch.Draw(tex, drawPosition, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ using CalamityMod.NPCs.AstrumAureus;
|
||||
using CalamityMod.NPCs.Crabulon;
|
||||
using CalamityMod.NPCs.Ravager;
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Projectiles;
|
||||
using CalamityMod.Projectiles.Typeless;
|
||||
using CalamityMod.Systems;
|
||||
@@ -261,7 +260,7 @@ namespace CalamityMod.ILEditing
|
||||
self.dashTime = 15;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dashing = true;
|
||||
self.dashTime = 0;
|
||||
self.timeSinceLastDashStarted = 0;
|
||||
@@ -707,7 +706,6 @@ namespace CalamityMod.ILEditing
|
||||
private static void DrawFusableParticles(Terraria.On_Main.orig_SortDrawCacheWorms orig, Main self)
|
||||
{
|
||||
DeathAshParticle.DrawAll();
|
||||
FusableParticleManager.RenderAllFusableParticles();
|
||||
|
||||
if (Main.LocalPlayer.dye.Any(dyeItem => dyeItem.type == ModContent.ItemType<ProfanedMoonlightDye>()))
|
||||
Main.LocalPlayer.Calamity().ProfanedMoonlightAuroraDrawer?.Draw(Main.LocalPlayer.Center - Main.screenPosition, false, Main.GameViewMatrix.TransformationMatrix, Matrix.Identity);
|
||||
@@ -739,23 +737,23 @@ namespace CalamityMod.ILEditing
|
||||
Main.tileBatch.Draw(liquidTexture, position, liquidSize, colors, default(Vector2), 1f, SpriteEffects.None);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Texture2D slopeTexture = SelectLavaTexture(liquidType == 1 ? CustomLavaManagement.LavaSlopeTexture : TextureAssets.LiquidSlope[liquidType].Value, LiquidTileType.Slope);
|
||||
liquidSize.X += 18 * (slope - 1);
|
||||
switch (slope)
|
||||
{
|
||||
case 1:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
case 2:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
case 3:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
case 4:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
case 1:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
case 2:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
case 3:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
case 4:
|
||||
Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,7 +795,7 @@ namespace CalamityMod.ILEditing
|
||||
{
|
||||
initialColor = SelectLavaQuadColor(initialTexture, ref initialColor, liquidType == 1);
|
||||
|
||||
if (liquidType == ModContent.Find<ModWaterStyle>("CalamityMod/SunkenSeaWater").Slot ||
|
||||
if (liquidType == ModContent.Find<ModWaterStyle>("CalamityMod/SunkenSeaWater").Slot ||
|
||||
liquidType == ModContent.Find<ModWaterStyle>("CalamityMod/SulphuricWater").Slot ||
|
||||
liquidType == ModContent.Find<ModWaterStyle>("CalamityMod/SulphuricDepthsWater").Slot ||
|
||||
liquidType == ModContent.Find<ModWaterStyle>("CalamityMod/UpperAbyssWater").Slot ||
|
||||
@@ -923,7 +921,7 @@ namespace CalamityMod.ILEditing
|
||||
return;
|
||||
|
||||
Tile above = CalamityUtils.ParanoidTileRetrieval(x, y - 1);
|
||||
if (!Main.gamePaused && !above.HasTile && above.LiquidAmount <= 0 && Main.rand.NextBool(9) &&
|
||||
if (!Main.gamePaused && !above.HasTile && above.LiquidAmount <= 0 && Main.rand.NextBool(9) &&
|
||||
Main.waterStyle == SulphuricWater.Type)
|
||||
{
|
||||
MediumMistParticle acidFoam = new(new(x * 16f + Main.rand.NextFloat(16f), y * 16f + 8f), -Vector2.UnitY.RotatedByRandom(0.67f) * Main.rand.NextFloat(1f, 2.4f), Color.LightSeaGreen, Color.White, 0.16f, 128f, 0.02f);
|
||||
|
||||
@@ -8,7 +8,6 @@ using CalamityMod.ExtraJumps;
|
||||
using CalamityMod.Items;
|
||||
using CalamityMod.NPCs;
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Systems;
|
||||
using CalamityMod.UI;
|
||||
using CalamityMod.UI.CalamitasEnchants;
|
||||
@@ -579,13 +578,13 @@ namespace CalamityMod
|
||||
public static float AddMaxStealth(Player p, float add) => p is null ? 0f : (p.Calamity().rogueStealthMax += add);
|
||||
|
||||
public static bool CanStealthStrike(Player p) => p?.Calamity()?.StealthStrikeAvailable() ?? false;
|
||||
|
||||
|
||||
public static void SetStealthProjectile(Projectile projectile, bool enabled)
|
||||
{
|
||||
if (projectile != null)
|
||||
projectile.Calamity().stealthStrike = enabled;
|
||||
}
|
||||
|
||||
|
||||
public static bool GetStealthProjectile(Projectile projectile) => projectile?.Calamity()?.stealthStrike ?? false;
|
||||
#endregion
|
||||
|
||||
@@ -924,7 +923,7 @@ namespace CalamityMod
|
||||
#endregion
|
||||
|
||||
#region Summoner Cross Class Nerf Disabling
|
||||
public static bool SetSummonerNerfDisabledByMinion(int type, bool disableNerf)
|
||||
public static bool SetSummonerNerfDisabledByMinion(int type, bool disableNerf)
|
||||
{
|
||||
if (disableNerf && !CalamityLists.DisabledSummonerNerfMinions.Contains(type))
|
||||
{
|
||||
@@ -1098,7 +1097,7 @@ namespace CalamityMod
|
||||
case "AddDifficultyToUI":
|
||||
if (args.Length < 2)
|
||||
return new ArgumentException("ERROR: Not enough arguements provided");
|
||||
|
||||
|
||||
if (args[1] is not DifficultyMode mode)
|
||||
return new ArgumentException("ERROR: A class inheriting from 'DifficultyMode' must be provided.");
|
||||
AddCustomDifficulty(mode);
|
||||
@@ -1112,7 +1111,7 @@ namespace CalamityMod
|
||||
case "GetAbyssLightStrength":
|
||||
if (args.Length < 2)
|
||||
return new ArgumentNullException("ERROR: Must specify a Player object (or int index of a Player).");
|
||||
if(!isValidPlayerArg(args[1]))
|
||||
if (!isValidPlayerArg(args[1]))
|
||||
return new ArgumentException("ERROR: The argument to \"GetLightStrength\" must be a Player or an int.");
|
||||
return GetLightStrength(castPlayer(args[1]));
|
||||
|
||||
@@ -1153,7 +1152,7 @@ namespace CalamityMod
|
||||
case "GetWearingRogueArmor":
|
||||
if (args.Length < 2)
|
||||
return new ArgumentNullException("ERROR: Must specify a Player object (or int index of a Player).");
|
||||
if(!isValidPlayerArg(args[1]))
|
||||
if (!isValidPlayerArg(args[1]))
|
||||
return new ArgumentException("ERROR: The argument to \"GetRogueArmor\" must be a Player or an int.");
|
||||
return GetWearingRogueArmor(castPlayer(args[1]));
|
||||
|
||||
@@ -1181,7 +1180,7 @@ namespace CalamityMod
|
||||
case "GetWearingPostMoonLordSummonerArmor":
|
||||
if (args.Length < 2)
|
||||
return new ArgumentNullException("ERROR: Must specify a Player object (or int index of a Player).");
|
||||
if(!isValidPlayerArg(args[1]))
|
||||
if (!isValidPlayerArg(args[1]))
|
||||
return new ArgumentException("ERROR: The argument to \"GetPostMoonLordSummonerArmor\" must be a Player or an int.");
|
||||
return GetWearingPostMLSummonerArmor(castPlayer(args[1]));
|
||||
|
||||
@@ -1716,7 +1715,7 @@ namespace CalamityMod
|
||||
case "CanFirePointBlank":
|
||||
case "CanFirePointBlankShots":
|
||||
if (args.Length < 2)
|
||||
return new ArgumentNullException("ERROR: Must specify an Item object (or int index of an Item in the Main.item array).");;
|
||||
return new ArgumentNullException("ERROR: Must specify an Item object (or int index of an Item in the Main.item array)."); ;
|
||||
if (!isValidItemArg(args[1]))
|
||||
return new ArgumentException("ERROR: The first argument to \"CanFirePointBlank\" must be an Item or an int.");
|
||||
return CanFirePointBlank(castItem(args[1]));
|
||||
@@ -1924,8 +1923,6 @@ namespace CalamityMod
|
||||
return new ArgumentNullException("ERROR: Must specify a Mod instance to load particles from.");
|
||||
|
||||
GeneralParticleHandler.LoadModParticleInstances(args[1] as Mod);
|
||||
FusableParticleManager.ExtraModsToLoadSetsFrom.Add(args[1] as Mod);
|
||||
FusableParticleManager.LoadParticleRenderSets();
|
||||
return null;
|
||||
|
||||
case "RegisterModCooldowns":
|
||||
|
||||
@@ -3,13 +3,12 @@ using System.IO;
|
||||
using CalamityMod.BiomeManagers;
|
||||
using CalamityMod.Buffs.StatDebuffs;
|
||||
using CalamityMod.Dusts;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
using CalamityMod.Items.Materials;
|
||||
using CalamityMod.Items.Placeables.Banners;
|
||||
using CalamityMod.Items.Weapons.Summon;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Projectiles.Enemy;
|
||||
using CalamityMod.Projectiles.Magic;
|
||||
using CalamityMod.World;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.GameContent.Bestiary;
|
||||
@@ -76,9 +75,9 @@ namespace CalamityMod.NPCs.AcidRain
|
||||
|
||||
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
|
||||
{
|
||||
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
|
||||
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
|
||||
{
|
||||
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Orthocera")
|
||||
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Orthocera")
|
||||
});
|
||||
}
|
||||
|
||||
@@ -212,7 +211,7 @@ namespace CalamityMod.NPCs.AcidRain
|
||||
if (NPC.Calamity().newAI[0] % 5 == 0 && Main.netMode != NetmodeID.MultiplayerClient)
|
||||
{
|
||||
Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Bottom, Main.rand.NextVector2Circular(4f, 8f), ModContent.ProjectileType<RancorFog>(), 0, 0f, Main.myPlayer);
|
||||
FusableParticleManager.GetParticleSetByType<RancorGroundLavaParticleSet>().SpawnParticle(NPC.Bottom + Main.rand.NextVector2Circular(10f, 10f), 135f);
|
||||
RancorLavaMetaball.SpawnParticle(NPC.Bottom + Main.rand.NextVector2Circular(10f, 10f), 135f);
|
||||
}
|
||||
if (NPC.Calamity().newAI[0] % 30 == 0 && Main.netMode != NetmodeID.MultiplayerClient)
|
||||
{
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
using CalamityMod.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
public abstract class BaseFusableParticleSet
|
||||
{
|
||||
public class FusableParticleRenderCollection
|
||||
{
|
||||
public BaseFusableParticleSet ParticleSet;
|
||||
public List<ManagedRenderTarget> BackgroundTargets;
|
||||
public FusableParticleRenderCollection(BaseFusableParticleSet set, List<ManagedRenderTarget> backgroundTargets)
|
||||
{
|
||||
ParticleSet = set;
|
||||
BackgroundTargets = backgroundTargets;
|
||||
}
|
||||
}
|
||||
|
||||
public class FusableParticle
|
||||
{
|
||||
public Vector2 Center;
|
||||
public float Size;
|
||||
public Vector2 TopLeft => Center + new Vector2(-1f, -1f) * Size * 0.5f;
|
||||
public Vector2 TopRight => Center + new Vector2(1f, -1f) * Size * 0.5f;
|
||||
public Vector2 BottomLeft => Center + new Vector2(-1f, 1f) * Size * 0.5f;
|
||||
public Vector2 BottomRight => Center + new Vector2(1f, 1f) * Size * 0.5f;
|
||||
|
||||
public FusableParticle(Vector2 center, float size)
|
||||
{
|
||||
Center = center;
|
||||
Size = size;
|
||||
}
|
||||
}
|
||||
|
||||
public int LayerCount
|
||||
{
|
||||
get
|
||||
{
|
||||
// Not doing this will result in inevitable crashes down the line as the graphics engine fails.
|
||||
if (BackgroundShaders.Count != BackgroundTextures.Count)
|
||||
throw new InvalidOperationException("The number of texture maps and shaders are not equivalent.");
|
||||
|
||||
return BackgroundShaders.Count;
|
||||
}
|
||||
}
|
||||
|
||||
internal List<DrawData> DrawDataBuffer = new();
|
||||
|
||||
public List<FusableParticle> Particles = new();
|
||||
|
||||
public FusableParticleRenderCollection RenderCollection => FusableParticleManager.GetParticleRenderCollectionByType(GetType());
|
||||
|
||||
public List<ManagedRenderTarget> GetBackgroundTargets => RenderCollection.BackgroundTargets;
|
||||
|
||||
public void PrepareSpecialDrawingForNextFrame(params DrawData[] drawContents) => DrawDataBuffer.AddRange(drawContents);
|
||||
public virtual float BorderSize => 0f;
|
||||
public virtual bool BorderShouldBeSolid => false;
|
||||
public virtual Color BorderColor => Color.Transparent;
|
||||
public virtual void PrepareOptionalShaderData(Effect effect, int index) { }
|
||||
public abstract List<Effect> BackgroundShaders { get; }
|
||||
public abstract List<Texture2D> BackgroundTextures { get; }
|
||||
public abstract FusableParticle SpawnParticle(Vector2 center, float sizeStrength);
|
||||
public abstract void UpdateBehavior(FusableParticle particle);
|
||||
public abstract void DrawParticles();
|
||||
|
||||
/// <summary>
|
||||
/// Temporarily moves from the backbuffer to a specialized render target, draws all particles, and caches the resulting render target for drawing later.
|
||||
/// </summary>
|
||||
internal void PrepareRenderTargetForDrawing()
|
||||
{
|
||||
// Don't bother doing anything if this method is called serverside.
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
// Don't bother doing anything if the set has no particles to render at the moment, for the sake of optimization.
|
||||
if (Particles.Count <= 0)
|
||||
return;
|
||||
|
||||
// Go through each background render target in the set and clear the entire thing to use a base of transparent pixels.
|
||||
foreach (ManagedRenderTarget backgroundTarget in GetBackgroundTargets)
|
||||
{
|
||||
Main.instance.GraphicsDevice.SetRenderTarget(backgroundTarget.Target);
|
||||
Main.instance.GraphicsDevice.Clear(Color.Transparent);
|
||||
|
||||
// Clear away any particles that shouldn't exist anymore.
|
||||
Particles.RemoveAll(p => p.Size <= 5f);
|
||||
|
||||
// Prepare the sprite batch for specialized drawing in prepration that the graphics device will draw to new render targets.
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.EffectMatrix);
|
||||
|
||||
// Draw the surviving particles.
|
||||
DrawParticles();
|
||||
|
||||
// Draw all special contents in the draw buffer before clearing it.
|
||||
foreach (DrawData drawData in DrawDataBuffer)
|
||||
drawData.Draw(Main.spriteBatch);
|
||||
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
|
||||
// Clear the special draw data buffer.
|
||||
DrawDataBuffer.Clear();
|
||||
|
||||
// Return to using the backbuffer after done drawing everything to the background targets.
|
||||
Main.instance.GraphicsDevice.SetRenderTarget(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
using CalamityMod.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using static CalamityMod.Particles.Metaballs.BaseFusableParticleSet;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
// NOTE: A lot of the functionalities within this system cannot under really any circumstance be used serverside.
|
||||
// This system is entirely visual. However, servers do not have drawing capabilities, nor even a proper GraphicsDevice
|
||||
// instance. This system utilizes many things that require both of these things, such as shaders and render targets.
|
||||
// As such, it is littered with many netMode checks. While some may be overprotective in their nature it is critical that
|
||||
// failsafes exist there, as visual failures tend to result in engine crashes, which will kill a lot of MP servers.
|
||||
// If someone other than me for any reason attempts to notably expand upon this system you must keep this in mind. -Dominic
|
||||
|
||||
// TODO -- This can be made into a ModSystem. Its main thread load dependency with render targets is safe to put in OnModLoad.
|
||||
public static class FusableParticleManager
|
||||
{
|
||||
internal static List<FusableParticleRenderCollection> ParticleSets = new();
|
||||
internal static List<Mod> ExtraModsToLoadSetsFrom = new();
|
||||
internal static List<Type> ParticleSetTypes = new();
|
||||
internal static bool HasBeenFormallyDefined = false;
|
||||
|
||||
/// <summary>
|
||||
/// Loads all render sets.
|
||||
/// </summary>
|
||||
internal static void LoadParticleRenderSets()
|
||||
{
|
||||
// Don't attempt to prepare anything serverside.
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
ParticleSets = new();
|
||||
ParticleSetTypes = new();
|
||||
ExtraModsToLoadSetsFrom = new();
|
||||
HasBeenFormallyDefined = true;
|
||||
|
||||
FindParticleSetTypesInMod(CalamityMod.Instance);
|
||||
foreach (Mod m in ExtraModsToLoadSetsFrom)
|
||||
FindParticleSetTypesInMod(m);
|
||||
|
||||
foreach (Type t in ParticleSetTypes)
|
||||
CreateParticleSetOfType(t);
|
||||
}
|
||||
|
||||
internal static void FindParticleSetTypesInMod(Mod mod)
|
||||
{
|
||||
// Look through every type in the mod, and check if it's derived from BaseFusableParticleSet.
|
||||
// If it is, create a default instance of said particle and save it.
|
||||
foreach (Type type in mod.Code.GetTypes())
|
||||
{
|
||||
// Don't load abstract classes; they cannot have instances.
|
||||
if (type.IsAbstract)
|
||||
continue;
|
||||
|
||||
if (type.IsSubclassOf(typeof(BaseFusableParticleSet)))
|
||||
ParticleSetTypes.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void CreateParticleSetOfType(Type t)
|
||||
{
|
||||
BaseFusableParticleSet instance = Activator.CreateInstance(t) as BaseFusableParticleSet;
|
||||
List<ManagedRenderTarget> backgroundTargets = new List<ManagedRenderTarget>();
|
||||
|
||||
// Only generate render targets to use if this isn't called serverside.
|
||||
if (Main.netMode != NetmodeID.Server)
|
||||
{
|
||||
for (int i = 0; i < instance.LayerCount; i++)
|
||||
backgroundTargets.Add(new ManagedRenderTarget(true, ManagedRenderTarget.CreateScreenSizedTarget));
|
||||
}
|
||||
|
||||
FusableParticleRenderCollection particleRenderCollection = new FusableParticleRenderCollection(instance, backgroundTargets);
|
||||
ParticleSets.Add(particleRenderCollection);
|
||||
}
|
||||
|
||||
internal static void CreateParticleSetOfType<T>() where T : BaseFusableParticleSet =>
|
||||
CreateParticleSetOfType(typeof(T));
|
||||
|
||||
/// <summary>
|
||||
/// Unloads all render sets.
|
||||
/// </summary>
|
||||
internal static void UnloadParticleRenderSets()
|
||||
{
|
||||
foreach (FusableParticleRenderCollection particleRenderSet in ParticleSets)
|
||||
particleRenderSet.ParticleSet = null;
|
||||
|
||||
HasBeenFormallyDefined = false;
|
||||
ParticleSets = null;
|
||||
ExtraModsToLoadSetsFrom = null;
|
||||
ParticleSetTypes = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the render targets of each cached <see cref="FusableParticleRenderCollection"/> instance in advance.
|
||||
/// </summary>
|
||||
internal static void PrepareFusableParticleTargets()
|
||||
{
|
||||
// Don't attempt to prepare anything serverside, if the particle sets are unloaded, or if on the menu.
|
||||
if (Main.netMode == NetmodeID.Server || ParticleSets is null || Main.gameMenu)
|
||||
return;
|
||||
|
||||
// Prepare the render target for all fusable particles.
|
||||
for (int i = 0; i < ParticleSets.Count; i++)
|
||||
ParticleSets[i].ParticleSet.PrepareRenderTargetForDrawing();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders each cached <see cref="FusableParticleRenderCollection"/> instance with its connecting shader.
|
||||
/// </summary>
|
||||
internal static void RenderAllFusableParticles()
|
||||
{
|
||||
// Don't attempt to render anything serverside or on the menu.
|
||||
if (Main.netMode == NetmodeID.Server || Main.gameMenu)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < ParticleSets.Count; i++)
|
||||
{
|
||||
BaseFusableParticleSet particleSet = ParticleSets[i].ParticleSet;
|
||||
|
||||
// Don't bother rendering if the set has no particles to render at the moment, for the sake of optimization.
|
||||
if (particleSet.Particles.Count <= 0)
|
||||
continue;
|
||||
|
||||
List<ManagedRenderTarget> backgroundTargets = particleSet.GetBackgroundTargets;
|
||||
|
||||
// Restart the sprite batch. This must be done with an immediate sort mode since a shader is going to be applied.
|
||||
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
|
||||
|
||||
for (int j = 0; j < particleSet.LayerCount; j++)
|
||||
{
|
||||
Effect shader = particleSet.BackgroundShaders[j];
|
||||
Texture2D backgroundTexture = particleSet.BackgroundTextures[j];
|
||||
|
||||
// Draw the current target with the specified shader.
|
||||
shader.Parameters["edgeBorderSize"].SetValue(particleSet.BorderSize);
|
||||
shader.Parameters["borderShouldBeSolid"].SetValue(particleSet.BorderShouldBeSolid);
|
||||
shader.Parameters["edgeBorderColor"].SetValue(particleSet.BorderColor.ToVector3());
|
||||
shader.Parameters["screenArea"].SetValue(new Vector2(Main.screenWidth, Main.screenHeight) / Main.GameViewMatrix.Zoom);
|
||||
shader.Parameters["screenMoveOffset"].SetValue(Main.screenPosition - Main.screenLastPosition);
|
||||
shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition);
|
||||
shader.Parameters["renderTargetArea"].SetValue(new Vector2(backgroundTargets[j].Width, backgroundTargets[j].Height));
|
||||
shader.Parameters["invertedScreen"].SetValue(Main.LocalPlayer.gravDir == -1f);
|
||||
shader.Parameters["upscaleFactor"].SetValue(Vector2.One);
|
||||
shader.Parameters["generalBackgroundOffset"].SetValue(Vector2.Zero);
|
||||
|
||||
// Prepare the background texture for loading.
|
||||
Main.graphics.GraphicsDevice.Textures[1] = backgroundTexture;
|
||||
shader.Parameters["uImageSize1"].SetValue(backgroundTexture.Size());
|
||||
|
||||
// Do any optional shader operations prior to applying the shader.
|
||||
particleSet.PrepareOptionalShaderData(shader, j);
|
||||
|
||||
// Apply the shader. This is what is used to connect separated blobs together.
|
||||
shader.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
// And draw the particle set's render target with said shader.
|
||||
Main.spriteBatch.Draw(backgroundTargets[j].Target, Vector2.Zero, Color.White);
|
||||
}
|
||||
|
||||
Main.spriteBatch.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtains the <see cref="FusableParticleRenderCollection"/> instance from a given <see cref="Type"/> if it is a <see cref="BaseFusableParticleSet"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to check.</param>
|
||||
internal static FusableParticleRenderCollection GetParticleRenderCollectionByType(Type type)
|
||||
{
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return null;
|
||||
|
||||
return ParticleSets.First(s => s.ParticleSet.GetType() == type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtains the cached singleton instance of a given <see cref="BaseFusableParticleSet"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to check.</typeparam>
|
||||
public static T GetParticleSetByType<T>() where T : BaseFusableParticleSet
|
||||
{
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return null;
|
||||
|
||||
// Reload particle sets if they are completely unloaded for some reason.
|
||||
if (ParticleSets.Count <= 0)
|
||||
LoadParticleRenderSets();
|
||||
|
||||
return ParticleSets.First(s => s.ParticleSet.GetType() == typeof(T)).ParticleSet as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
public class GruesomeEminenceParticleSet : BaseFusableParticleSet
|
||||
{
|
||||
public override float BorderSize => 3f;
|
||||
public override bool BorderShouldBeSolid => false;
|
||||
public override Color BorderColor => Color.Lerp(Color.Fuchsia, Color.Black, 0.55f) * 0.85f;
|
||||
|
||||
public override List<Effect> BackgroundShaders => new()
|
||||
{
|
||||
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader,
|
||||
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader,
|
||||
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader,
|
||||
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader,
|
||||
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader,
|
||||
};
|
||||
public override List<Texture2D> BackgroundTextures => new()
|
||||
{
|
||||
ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/GruesomeEminence_Ghost_Layer1").Value,
|
||||
ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/GruesomeEminence_Ghost_Layer2").Value,
|
||||
ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/GruesomeEminence_Ghost_Layer3").Value,
|
||||
ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/GruesomeEminence_Ghost_Layer4").Value,
|
||||
ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/GruesomeEminence_Ghost_Layer5").Value,
|
||||
};
|
||||
public override FusableParticle SpawnParticle(Vector2 center, float sizeStrength)
|
||||
{
|
||||
Particles.Add(new FusableParticle(center, sizeStrength));
|
||||
return Particles.Last();
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(FusableParticle particle)
|
||||
{
|
||||
particle.Size = MathHelper.Clamp(particle.Size - 2.5f, 0f, 400f) * 0.97f;
|
||||
}
|
||||
|
||||
public override void PrepareOptionalShaderData(Effect effect, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
// Background.
|
||||
case 0:
|
||||
Vector2 offset = Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.03f;
|
||||
effect.Parameters["generalBackgroundOffset"].SetValue(offset);
|
||||
break;
|
||||
|
||||
// Gaseous skulls.
|
||||
case 1:
|
||||
offset = Vector2.One * (float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.041f) * 2f;
|
||||
offset = offset.RotatedBy((float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.08f) * 0.97f);
|
||||
effect.Parameters["generalBackgroundOffset"].SetValue(offset);
|
||||
break;
|
||||
|
||||
// Spooky faces 1.
|
||||
case 2:
|
||||
offset = (Main.GlobalTimeWrappedHourly * 2.02f).ToRotationVector2() * 0.036f;
|
||||
offset.Y += (float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.161f) * 0.5f + 0.5f;
|
||||
effect.Parameters["generalBackgroundOffset"].SetValue(offset);
|
||||
break;
|
||||
|
||||
// Spooky faces 2.
|
||||
case 3:
|
||||
offset = Vector2.UnitX * Main.GlobalTimeWrappedHourly * -0.04f + (Main.GlobalTimeWrappedHourly * 1.89f).ToRotationVector2() * 0.03f;
|
||||
offset.Y += CalamityUtils.PerlinNoise2D(Main.GlobalTimeWrappedHourly * 0.187f, Main.GlobalTimeWrappedHourly * 0.193f, 2, 466920161) * 0.025f;
|
||||
effect.Parameters["generalBackgroundOffset"].SetValue(offset);
|
||||
break;
|
||||
|
||||
// Spooky faces 3.
|
||||
case 4:
|
||||
offset = Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.037f + (Main.GlobalTimeWrappedHourly * 1.77f).ToRotationVector2() * 0.04725f;
|
||||
offset.Y += CalamityUtils.PerlinNoise2D(Main.GlobalTimeWrappedHourly * 0.187f, Main.GlobalTimeWrappedHourly * 0.193f, 2, 577215664) * 0.05f;
|
||||
effect.Parameters["generalBackgroundOffset"].SetValue(offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawParticles()
|
||||
{
|
||||
Texture2D fusableParticleBase = ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/FusableParticleBase").Value;
|
||||
foreach (FusableParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = fusableParticleBase.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / fusableParticleBase.Size();
|
||||
Main.spriteBatch.Draw(fusableParticleBase, drawPosition, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
public class CyanPaint : PaintParticleSet
|
||||
{
|
||||
public override Color BorderColor => Color.Cyan * 0.7f;
|
||||
}
|
||||
public class BluePaint : PaintParticleSet
|
||||
{
|
||||
public override Color BorderColor => Color.Blue * 0.7f;
|
||||
}
|
||||
public class MagentaPaint : PaintParticleSet
|
||||
{
|
||||
public override Color BorderColor => Color.Magenta * 0.7f;
|
||||
}
|
||||
public class LimePaint : PaintParticleSet
|
||||
{
|
||||
public override Color BorderColor => Color.Lime * 0.7f;
|
||||
}
|
||||
public class YellowPaint : PaintParticleSet
|
||||
{
|
||||
public override Color BorderColor => Color.Yellow * 0.7f;
|
||||
}
|
||||
|
||||
public abstract class PaintParticleSet : BaseFusableParticleSet
|
||||
{
|
||||
public override float BorderSize => 12f;
|
||||
public override bool BorderShouldBeSolid => false;
|
||||
|
||||
public override List<Effect> BackgroundShaders => new()
|
||||
{
|
||||
GameShaders.Misc["CalamityMod:AdditiveFusableParticleEdge"].Shader,
|
||||
};
|
||||
public override List<Texture2D> BackgroundTextures => new()
|
||||
{
|
||||
ModContent.Request<Texture2D>("CalamityMod/Projectiles/InvisibleProj").Value,
|
||||
};
|
||||
public override FusableParticle SpawnParticle(Vector2 center, float sizeStrength)
|
||||
{
|
||||
Particles.Add(new FusableParticle(center, sizeStrength));
|
||||
return Particles.Last();
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(FusableParticle particle)
|
||||
{
|
||||
particle.Size = MathHelper.Clamp(particle.Size - 0.1f, 0f, 200f) * 0.997f;
|
||||
if (particle.Size < 20f)
|
||||
particle.Size = particle.Size * 0.8f - 1f;
|
||||
}
|
||||
|
||||
public override void DrawParticles()
|
||||
{
|
||||
Texture2D fusableParticleBase = ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/FusableParticleBase").Value;
|
||||
foreach (FusableParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = fusableParticleBase.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / fusableParticleBase.Size();
|
||||
Color drawColor = Color.Lerp(BorderColor, new Color(0f, 0f, 1f), Utils.GetLerpValue(50f, 100f, particle.Size, true) * 0.1f) * 1.2f;
|
||||
Main.spriteBatch.Draw(fusableParticleBase, drawPosition, null, drawColor, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
public class RancorGroundLavaParticleSet : BaseFusableParticleSet
|
||||
{
|
||||
public override float BorderSize => 18f;
|
||||
public override bool BorderShouldBeSolid => false;
|
||||
public override Color BorderColor => Color.Lerp(Color.Yellow, Color.Red, 0.85f) * 0.85f;
|
||||
|
||||
public override List<Effect> BackgroundShaders => new()
|
||||
{
|
||||
GameShaders.Misc["CalamityMod:AdditiveFusableParticleEdge"].Shader,
|
||||
};
|
||||
public override List<Texture2D> BackgroundTextures => new()
|
||||
{
|
||||
ModContent.Request<Texture2D>("CalamityMod/Projectiles/InvisibleProj").Value,
|
||||
};
|
||||
public override FusableParticle SpawnParticle(Vector2 center, float sizeStrength)
|
||||
{
|
||||
Particles.Add(new FusableParticle(center, sizeStrength));
|
||||
return Particles.Last();
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(FusableParticle particle)
|
||||
{
|
||||
particle.Size = MathHelper.Clamp(particle.Size - 0.15f, 0f, 200f) * 0.997f;
|
||||
if (particle.Size < 20f)
|
||||
particle.Size = particle.Size * 0.95f - 0.9f;
|
||||
}
|
||||
|
||||
public override void DrawParticles()
|
||||
{
|
||||
Texture2D fusableParticleBase = ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/FusableParticleBase").Value;
|
||||
foreach (FusableParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = fusableParticleBase.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / fusableParticleBase.Size() * new Vector2(1f, 0.5f);
|
||||
Color drawColor = Color.Lerp(BorderColor, new Color(0f, 0f, 1f), Utils.GetLerpValue(120f, 135f, particle.Size, true) * 0.1f) * 1.4f;
|
||||
Main.spriteBatch.Draw(fusableParticleBase, drawPosition, null, drawColor, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
public class RancorLavaParticleSet : BaseFusableParticleSet
|
||||
{
|
||||
public override float BorderSize => 18f;
|
||||
public override bool BorderShouldBeSolid => false;
|
||||
public override Color BorderColor => Color.Lerp(Color.Yellow, Color.Red, 0.85f) * 0.85f;
|
||||
|
||||
public override List<Effect> BackgroundShaders => new()
|
||||
{
|
||||
GameShaders.Misc["CalamityMod:AdditiveFusableParticleEdge"].Shader,
|
||||
};
|
||||
public override List<Texture2D> BackgroundTextures => new()
|
||||
{
|
||||
ModContent.Request<Texture2D>("CalamityMod/Projectiles/InvisibleProj").Value,
|
||||
};
|
||||
public override FusableParticle SpawnParticle(Vector2 center, float sizeStrength)
|
||||
{
|
||||
Particles.Add(new FusableParticle(center, sizeStrength));
|
||||
return Particles.Last();
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(FusableParticle particle)
|
||||
{
|
||||
particle.Size = MathHelper.Clamp(particle.Size - 0.24f, 0f, 200f) * 0.9956f;
|
||||
if (particle.Size < 15f)
|
||||
particle.Size = particle.Size * 0.95f - 0.9f;
|
||||
}
|
||||
|
||||
public override void DrawParticles()
|
||||
{
|
||||
Texture2D fusableParticleBase = ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/FusableParticleBase").Value;
|
||||
foreach (FusableParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = fusableParticleBase.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / fusableParticleBase.Size();
|
||||
Main.spriteBatch.Draw(fusableParticleBase, drawPosition, null, BorderColor * 1.2f, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -1,61 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
public class StreamGougeParticleSet : BaseFusableParticleSet
|
||||
{
|
||||
public override float BorderSize => 3f;
|
||||
public override bool BorderShouldBeSolid => false;
|
||||
public override Color BorderColor => Color.Lerp(Color.DarkBlue, Color.Black, 0.75f) * 0.85f;
|
||||
|
||||
public override List<Effect> BackgroundShaders => new()
|
||||
{
|
||||
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader,
|
||||
};
|
||||
public override List<Texture2D> BackgroundTextures => new()
|
||||
{
|
||||
ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/StreamGougeLayer").Value,
|
||||
};
|
||||
public override FusableParticle SpawnParticle(Vector2 center, float sizeStrength)
|
||||
{
|
||||
Particles.Add(new FusableParticle(center, sizeStrength));
|
||||
return Particles.Last();
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(FusableParticle particle)
|
||||
{
|
||||
particle.Size = MathHelper.Clamp(particle.Size - 1f, 0f, 200f) * 0.98f;
|
||||
}
|
||||
|
||||
public override void PrepareOptionalShaderData(Effect effect, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
// Background.
|
||||
case 0:
|
||||
Vector2 offset = Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.045f;
|
||||
effect.Parameters["generalBackgroundOffset"].SetValue(offset);
|
||||
effect.Parameters["upscaleFactor"].SetValue(Vector2.One * -0.3f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawParticles()
|
||||
{
|
||||
Texture2D fusableParticleBase = ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/FusableParticleBase").Value;
|
||||
foreach (FusableParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = fusableParticleBase.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / fusableParticleBase.Size();
|
||||
Main.spriteBatch.Draw(fusableParticleBase, drawPosition, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles.Metaballs
|
||||
{
|
||||
//This is basically just the Stream Gouge set but purple
|
||||
public class VoidGeneratorParticleSet : BaseFusableParticleSet
|
||||
{
|
||||
public override float BorderSize => 3f;
|
||||
public override bool BorderShouldBeSolid => false;
|
||||
public override Color BorderColor => Color.Lerp(Color.Purple, Color.Black, 0.75f) * 0.85f;
|
||||
|
||||
public override List<Effect> BackgroundShaders => new List<Effect>()
|
||||
{
|
||||
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader,
|
||||
};
|
||||
public override List<Texture2D> BackgroundTextures => new List<Texture2D>()
|
||||
{
|
||||
ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/StreamGougeLayer").Value,
|
||||
};
|
||||
public override FusableParticle SpawnParticle(Vector2 center, float sizeStrength)
|
||||
{
|
||||
Particles.Add(new FusableParticle(center, sizeStrength));
|
||||
return Particles.Last();
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(FusableParticle particle)
|
||||
{
|
||||
particle.Size = MathHelper.Clamp(particle.Size - 1f, 0f, 200f) * 0.98f;
|
||||
}
|
||||
|
||||
public override void PrepareOptionalShaderData(Effect effect, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
// Background.
|
||||
case 0:
|
||||
Vector2 offset = Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.045f;
|
||||
effect.Parameters["generalBackgroundOffset"].SetValue(offset);
|
||||
effect.Parameters["upscaleFactor"].SetValue(Vector2.One * -0.3f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawParticles()
|
||||
{
|
||||
Texture2D fusableParticleBase = ModContent.Request<Texture2D>("CalamityMod/Particles/Metaballs/FusableParticleBase").Value;
|
||||
foreach (FusableParticle particle in Particles)
|
||||
{
|
||||
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
||||
Vector2 origin = fusableParticleBase.Size() * 0.5f;
|
||||
Vector2 scale = Vector2.One * particle.Size / fusableParticleBase.Size();
|
||||
Main.spriteBatch.Draw(fusableParticleBase, drawPosition, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
@@ -45,7 +44,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
Projectile.velocity.Y += 0.04f;
|
||||
|
||||
// Create lava particles.
|
||||
FusableParticleManager.GetParticleSetByType<RancorLavaParticleSet>().SpawnParticle(Projectile.Center + Main.rand.NextVector2Circular(6f, 6f), Projectile.scale * 36f);
|
||||
RancorLavaMetaball.SpawnParticle(Projectile.Center + Main.rand.NextVector2Circular(6f, 6f), Projectile.scale * 36f);
|
||||
|
||||
Time++;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using CalamityMod.Buffs.DamageOverTime;
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
using CalamityMod.World;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
@@ -147,7 +146,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
Projectile.NewProjectile(Projectile.GetSource_FromThis(), endOfLaser, cinderVelocity, type, damage, 0f, Projectile.owner);
|
||||
}
|
||||
|
||||
FusableParticleManager.GetParticleSetByType<RancorGroundLavaParticleSet>().SpawnParticle(endOfLaser + Main.rand.NextVector2Circular(10f, 10f) + Projectile.velocity * 40f, 135f);
|
||||
RancorLavaMetaball.SpawnParticle(endOfLaser + Main.rand.NextVector2Circular(10f, 10f) + Projectile.velocity * 40f, 135f);
|
||||
}
|
||||
|
||||
private float PrimitiveWidthFunction(float completionRatio) => Projectile.scale * 20f;
|
||||
@@ -163,8 +162,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
|
||||
public override bool PreDraw(ref Color lightColor)
|
||||
{
|
||||
if (RayDrawer is null)
|
||||
RayDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:Flame"]);
|
||||
RayDrawer ??= new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:Flame"]);
|
||||
|
||||
GameShaders.Misc["CalamityMod:Flame"].UseImage1("Images/Misc/Perlin");
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using Terraria;
|
||||
@@ -49,7 +48,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
float radius = MathHelper.SmoothStep(84f, 44f, (float)Math.Sqrt(1f - Projectile.timeLeft / 360f));
|
||||
float radius = MathHelper.SmoothStep(67f, 32f, (float)Math.Sqrt(1f - Projectile.timeLeft / 360f));
|
||||
|
||||
// Handle frames.
|
||||
Projectile.frameCounter++;
|
||||
@@ -68,7 +67,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
{
|
||||
Projectile.hostile = false;
|
||||
|
||||
radius += 54f;
|
||||
radius += 36f;
|
||||
|
||||
target = ProjectileOwner;
|
||||
flySpeed = 29f;
|
||||
@@ -109,7 +108,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
|
||||
// Emit particles.
|
||||
Vector2 spawnPosition = Projectile.Center + Main.rand.NextVector2Circular(5f, 5f) * radius / 130f;
|
||||
FusableParticleManager.GetParticleSetByType<GruesomeEminenceParticleSet>()?.SpawnParticle(spawnPosition, radius);
|
||||
GruesomeMetaball.SpawnParticle(spawnPosition, Main.rand.NextVector2Circular(6f, 6f), radius);
|
||||
}
|
||||
|
||||
public override Color? GetAlpha(Color lightColor) => Color.White * Projectile.Opacity;
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
using CalamityMod.Particles;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Terraria;
|
||||
using Terraria.Graphics.Shaders;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.Audio;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using Terraria.DataStructures;
|
||||
using System.Collections.Generic;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
|
||||
namespace CalamityMod.Projectiles.Magic
|
||||
{
|
||||
@@ -62,6 +60,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
Projectile.usesLocalNPCImmunity = true;
|
||||
Projectile.localNPCHitCooldown = 12;
|
||||
Projectile.timeLeft = 90000;
|
||||
Projectile.hide = true;
|
||||
}
|
||||
|
||||
public override void SendExtraAI(BinaryWriter writer)
|
||||
@@ -229,8 +228,8 @@ namespace CalamityMod.Projectiles.Magic
|
||||
particleSize += (Projectile.oldPosition - Projectile.position).Length() * 4.2f;
|
||||
|
||||
// Place a hard limit on particle sizes.
|
||||
if (particleSize > 500f)
|
||||
particleSize = 500f;
|
||||
if (particleSize > 210f)
|
||||
particleSize = 210f;
|
||||
|
||||
// Make particles shrink when dying.
|
||||
particleSize *= MathHelper.Lerp(1f, 0.5f, Utils.GetLerpValue(0f, 35f, DeathCounter, true));
|
||||
@@ -240,12 +239,15 @@ namespace CalamityMod.Projectiles.Magic
|
||||
{
|
||||
// Summon a base particle.
|
||||
Vector2 spawnPosition = Projectile.Center + Main.rand.NextVector2Circular(1f, 1f) * particleSize / 26f;
|
||||
FusableParticleManager.GetParticleSetByType<GruesomeEminenceParticleSet>()?.SpawnParticle(spawnPosition, particleSize);
|
||||
GruesomeMetaball.SpawnParticle(spawnPosition, Main.rand.NextVector2Circular(4.4f, 4.4f), particleSize);
|
||||
|
||||
// And an "ahead" particle that spawns based on current movement.
|
||||
// This causes the "head" of the overall thing to have bumps when moving.
|
||||
spawnPosition += Projectile.velocity.RotatedByRandom(1.38f) * particleSize / 105f;
|
||||
FusableParticleManager.GetParticleSetByType<GruesomeEminenceParticleSet>()?.SpawnParticle(spawnPosition, particleSize * 0.4f);
|
||||
GruesomeMetaball.SpawnParticle(spawnPosition, Main.rand.NextVector2Circular(i * 1.5f + 7f, i * 1.5f + 7f), particleSize * 0.3f);
|
||||
|
||||
// Make particle sizes exponentially decrease across loop iterations.
|
||||
particleSize *= 0.9f;
|
||||
}
|
||||
|
||||
// Release gas projectiles randomly. This does not happen when dying.
|
||||
@@ -263,41 +265,56 @@ namespace CalamityMod.Projectiles.Magic
|
||||
Projectile.frame = Projectile.frameCounter / 5 % maxFrame;
|
||||
}
|
||||
|
||||
public override void DrawBehind(int index, List<int> behindNPCsAndTiles, List<int> behindNPCs, List<int> behindProjectiles, List<int> overPlayers, List<int> overWiresUI)
|
||||
{
|
||||
// Ensure that the teeth draw over the metaballs.
|
||||
overPlayers.Add(index);
|
||||
}
|
||||
|
||||
public override bool PreDraw(ref Color lightColor)
|
||||
{
|
||||
int maxFrame = CurrentPower <= LargeMouthPowerLowerBound ? 6 : 9;
|
||||
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
|
||||
Texture2D backTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/SpiritCongregationBack").Value;
|
||||
Texture2D auraTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/SpiritCongregationAura").Value;
|
||||
if (CurrentPower > LargeMouthPowerLowerBound)
|
||||
{
|
||||
texture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/SpiritCongregationBig").Value;
|
||||
backTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/SpiritCongregationBackBig").Value;
|
||||
auraTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/SpiritCongregationAuraBig").Value;
|
||||
}
|
||||
|
||||
float offsetFactor = Projectile.scale * ((CongregationDiameter - 54f) / 90f + 1.5f);
|
||||
offsetFactor *= texture.Width / 90f;
|
||||
Vector2 drawPosition = Projectile.Center - Main.screenPosition + Projectile.rotation.ToRotationVector2() * offsetFactor * 15f;
|
||||
Rectangle frame = texture.Frame(1, maxFrame, 0, Projectile.frame);
|
||||
Vector2 origin = frame.Size() * 0.5f;
|
||||
SpriteEffects direction = Math.Cos(Projectile.rotation) > 0f ? SpriteEffects.None : SpriteEffects.FlipVertically;
|
||||
|
||||
DrawData backTextureDraw = new(backTexture, drawPosition, frame, Color.White, Projectile.rotation, origin, Projectile.scale, direction, 0);
|
||||
DrawData auraTextureDraw = new(auraTexture, drawPosition, frame, Color.White, Projectile.rotation, origin, Projectile.scale, direction, 0);
|
||||
FusableParticleManager.GetParticleSetByType<GruesomeEminenceParticleSet>()?.PrepareSpecialDrawingForNextFrame(backTextureDraw, auraTextureDraw);
|
||||
Main.EntitySpriteDraw(texture, drawPosition, frame, Color.White, Projectile.rotation, origin, Projectile.scale, direction, 0);
|
||||
DrawHead(texture);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Damage scales up over time as it grows
|
||||
public void DrawHead(Texture2D texture, float scaleFactor = 1f)
|
||||
{
|
||||
int maxFrame = CurrentPower <= LargeMouthPowerLowerBound ? 6 : 9;
|
||||
float offsetFactor = Projectile.scale * ((CongregationDiameter - 54f) / 90f + 1.5f);
|
||||
offsetFactor *= texture.Width / 90f;
|
||||
|
||||
Vector2 drawPosition = Projectile.Center - Main.screenPosition + Projectile.rotation.ToRotationVector2() * offsetFactor * 15f;
|
||||
Rectangle frame = texture.Frame(1, maxFrame, 0, Projectile.frame);
|
||||
Vector2 origin = frame.Size() * 0.5f;
|
||||
SpriteEffects direction = MathF.Cos(Projectile.rotation) > 0f ? SpriteEffects.None : SpriteEffects.FlipVertically;
|
||||
|
||||
Main.EntitySpriteDraw(texture, drawPosition, frame, Color.White, Projectile.rotation, origin, Projectile.scale * scaleFactor, direction, 0);
|
||||
}
|
||||
|
||||
public void DrawHeadForMetaball()
|
||||
{
|
||||
Texture2D backTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/SpiritCongregationBack").Value;
|
||||
if (CurrentPower > LargeMouthPowerLowerBound)
|
||||
backTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/SpiritCongregationBackBig").Value;
|
||||
|
||||
DrawHead(backTexture, 1.04f);
|
||||
}
|
||||
|
||||
// Damage scales up over time as it grows.
|
||||
public override void ModifyHitPlayer(Player target, ref Player.HurtModifiers modifiers)
|
||||
{
|
||||
float damageFactor = 0.25f + 0.75f * CurrentPower;
|
||||
int fullPowerDamage;
|
||||
if (Main.masterMode) fullPowerDamage = 540;
|
||||
else if (Main.expertMode) fullPowerDamage = 450;
|
||||
else fullPowerDamage = 360;
|
||||
if (Main.masterMode)
|
||||
fullPowerDamage = 540;
|
||||
else if (Main.expertMode)
|
||||
fullPowerDamage = 450;
|
||||
else
|
||||
fullPowerDamage = 360;
|
||||
|
||||
modifiers.SourceDamage *= 0f;
|
||||
modifiers.SourceDamage.Flat += (int)(damageFactor * fullPowerDamage);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
@@ -8,6 +8,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
public class SpiritDust : ModProjectile, ILocalizedModType
|
||||
{
|
||||
public new string LocalizationCategory => "Projectiles.Magic";
|
||||
|
||||
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
|
||||
|
||||
public override void SetDefaults()
|
||||
@@ -24,7 +25,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
{
|
||||
float radius = MathHelper.SmoothStep(80f, 48f, 1f - Projectile.timeLeft / 90f);
|
||||
Vector2 spawnPosition = Projectile.Center + Main.rand.NextVector2Circular(5f, 5f) * radius / 130f;
|
||||
FusableParticleManager.GetParticleSetByType<GruesomeEminenceParticleSet>()?.SpawnParticle(spawnPosition, radius);
|
||||
GruesomeMetaball.SpawnParticle(spawnPosition, Main.rand.NextVector2Circular(3f, 3f), radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,15 @@ using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.Audio;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
|
||||
namespace CalamityMod.Projectiles.Melee
|
||||
{
|
||||
public class StreamGougePortal : ModProjectile, ILocalizedModType
|
||||
{
|
||||
public new string LocalizationCategory => "Projectiles.Melee";
|
||||
public static readonly SoundStyle SpawnSound = new SoundStyle("CalamityMod/Sounds/Custom/SwiftSlice")
|
||||
|
||||
public static readonly SoundStyle SpawnSound = new("CalamityMod/Sounds/Custom/SwiftSlice")
|
||||
{
|
||||
PitchVariance = 0.1f
|
||||
};
|
||||
@@ -43,7 +44,8 @@ namespace CalamityMod.Projectiles.Melee
|
||||
// Play a slice sound when spawning.
|
||||
if (Projectile.localAI[0] == 0f)
|
||||
{
|
||||
SoundEngine.PlaySound(SpawnSound, Projectile.Center);
|
||||
float volume = Utils.Remap(Main.LocalPlayer.Distance(Projectile.Center), 600f, 100f, 0.12f, 0.5f);
|
||||
SoundEngine.PlaySound(SpawnSound with { Volume = volume }, Projectile.Center);
|
||||
Projectile.localAI[0] = 1f;
|
||||
}
|
||||
|
||||
@@ -106,11 +108,12 @@ namespace CalamityMod.Projectiles.Melee
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
Vector2 spawnPosition = target.Center + Main.rand.NextVector2Circular(30f, 30f);
|
||||
FusableParticleManager.GetParticleSetByType<StreamGougeParticleSet>()?.SpawnParticle(spawnPosition, 60f);
|
||||
StreamGougeMetaball.SpawnParticle(spawnPosition, Main.rand.NextVector2Circular(3f, 3f), 60f);
|
||||
|
||||
float scale = MathHelper.Lerp(24f, 64f, CalamityUtils.Convert01To010(i / 19f));
|
||||
spawnPosition = target.Center + Projectile.velocity.SafeNormalize(Vector2.UnitY) * MathHelper.Lerp(-40f, 90f, i / 19f);
|
||||
FusableParticleManager.GetParticleSetByType<StreamGougeParticleSet>()?.SpawnParticle(spawnPosition, scale);
|
||||
Vector2 particleVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(0.23f) * Main.rand.NextFloat(2.5f, 9f);
|
||||
StreamGougeMetaball.SpawnParticle(spawnPosition, particleVelocity, scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using CalamityMod.Items.Weapons.Ranged;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Audio;
|
||||
@@ -140,7 +137,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
{
|
||||
if (!DashShot)
|
||||
SoundEngine.PlaySound(ShotImpact, Projectile.position);
|
||||
|
||||
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
Dust dust = Dust.NewDustPerfect(Projectile.position, 192, Projectile.velocity.RotatedByRandom(MathHelper.ToRadians(20f)) * Main.rand.NextFloat(0.05f, 0.3f), 0, default, Main.rand.NextFloat(0.6f, 1.2f));
|
||||
@@ -154,23 +151,23 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
{
|
||||
Vector2 paintPos = Projectile.Center + Main.rand.NextVector2Circular(12f, 12f) + (Projectile.velocity.SafeNormalize(Vector2.UnitY)).RotatedByRandom(MathHelper.ToRadians(30f)) * Main.rand.NextFloat(4f, 20f);
|
||||
float paintSize = Main.rand.NextFloat(60f, 100f);
|
||||
switch(Projectile.ai[0])
|
||||
switch (Projectile.ai[0])
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
FusableParticleManager.GetParticleSetByType<CyanPaint>()?.SpawnParticle(paintPos, paintSize);
|
||||
ModContent.GetInstance<CyanPaint>().SpawnParticle(paintPos, paintSize);
|
||||
break;
|
||||
case 1:
|
||||
FusableParticleManager.GetParticleSetByType<BluePaint>()?.SpawnParticle(paintPos, paintSize);
|
||||
ModContent.GetInstance<BluePaint>().SpawnParticle(paintPos, paintSize);
|
||||
break;
|
||||
case 2:
|
||||
FusableParticleManager.GetParticleSetByType<MagentaPaint>()?.SpawnParticle(paintPos, paintSize);
|
||||
ModContent.GetInstance<MagentaPaint>().SpawnParticle(paintPos, paintSize);
|
||||
break;
|
||||
case 3:
|
||||
FusableParticleManager.GetParticleSetByType<LimePaint>()?.SpawnParticle(paintPos, paintSize);
|
||||
ModContent.GetInstance<LimePaint>().SpawnParticle(paintPos, paintSize);
|
||||
break;
|
||||
case 4:
|
||||
FusableParticleManager.GetParticleSetByType<YellowPaint>()?.SpawnParticle(paintPos, paintSize);
|
||||
ModContent.GetInstance<YellowPaint>().SpawnParticle(paintPos, paintSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using CalamityMod.CalPlayer;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.Audio;
|
||||
using CalamityMod.Graphics.Metaballs;
|
||||
|
||||
namespace CalamityMod.Projectiles.Typeless
|
||||
{
|
||||
@@ -12,7 +12,7 @@ namespace CalamityMod.Projectiles.Typeless
|
||||
{
|
||||
public new string LocalizationCategory => "Projectiles.Typeless";
|
||||
public bool start = true;
|
||||
public BaseFusableParticleSet.FusableParticle voidaura;
|
||||
public StreamGougeMetaball.CosmicParticle VoidAura;
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
@@ -78,14 +78,14 @@ namespace CalamityMod.Projectiles.Typeless
|
||||
}
|
||||
}
|
||||
|
||||
if (voidaura == null)
|
||||
if (VoidAura == null)
|
||||
{
|
||||
voidaura = FusableParticleManager.GetParticleSetByType<VoidGeneratorParticleSet>()?.SpawnParticle(Projectile.Center, 500);
|
||||
VoidAura = VoidGeneratorMetaball.SpawnParticle(Projectile.Center, Vector2.Zero, 120f);
|
||||
}
|
||||
else
|
||||
{
|
||||
voidaura.Center = Projectile.Center;
|
||||
voidaura.Size = 500;
|
||||
VoidAura.Center = Projectile.Center;
|
||||
VoidAura.Size = 120f;
|
||||
}
|
||||
}
|
||||
public override bool? CanCutTiles() => false;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using CalamityMod.NPCs;
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Particles.Metaballs;
|
||||
using CalamityMod.TileEntities;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
@@ -9,19 +8,6 @@ namespace CalamityMod.Systems
|
||||
{
|
||||
public class EntityUpdateInterceptionSystem : ModSystem
|
||||
{
|
||||
#region Fusable Particle Updating
|
||||
public override void PostUpdateProjectiles()
|
||||
{
|
||||
// Update all fusable particles.
|
||||
// These are really only visual and as such don't really need any complex netcode.
|
||||
foreach (BaseFusableParticleSet.FusableParticleRenderCollection particleSet in FusableParticleManager.ParticleSets)
|
||||
{
|
||||
foreach (BaseFusableParticleSet.FusableParticle particle in particleSet.ParticleSet.Particles)
|
||||
particleSet.ParticleSet.UpdateBehavior(particle);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Ash Drawing
|
||||
public override void PostUpdateDusts() => DeathAshParticle.UpdateAll();
|
||||
#endregion Ash Drawing
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CalamityMod.Projectiles.Magic;
|
||||
using CalamityMod.Projectiles.Melee.Yoyos;
|
||||
using CalamityMod.Projectiles.Ranged;
|
||||
using CalamityMod.Projectiles.Rogue;
|
||||
using CalamityMod.Projectiles.Typeless;
|
||||
using Microsoft.Xna.Framework;
|
||||
@@ -19,7 +18,36 @@ namespace CalamityMod
|
||||
{
|
||||
public static partial class CalamityUtils
|
||||
{
|
||||
public static int CountProjectiles(int Type) => Main.projectile.Count(proj => proj.type == Type && proj.active);
|
||||
public static bool AnyProjectiles(int projectileID)
|
||||
{
|
||||
// Efficiently loop through all projectiles, using a specially designed continue continue that attempts to minimize the amount of OR
|
||||
// checks per iteration.
|
||||
for (int i = 0; i < Main.maxProjectiles; i++)
|
||||
{
|
||||
Projectile p = Main.projectile[i];
|
||||
if (p.type != projectileID || !p.active)
|
||||
continue;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IEnumerable<Projectile> AllProjectilesByID(int projectileID)
|
||||
{
|
||||
// This uses the same efficient loop idea as AnyProjectiles.
|
||||
for (int i = 0; i < Main.maxProjectiles; i++)
|
||||
{
|
||||
Projectile p = Main.projectile[i];
|
||||
if (p.type != projectileID || !p.active)
|
||||
continue;
|
||||
|
||||
yield return p;
|
||||
}
|
||||
}
|
||||
|
||||
public static int CountProjectiles(int projectileID) => Main.projectile.Count(proj => proj.type == projectileID && proj.active);
|
||||
|
||||
public static int CountHookProj() => Main.projectile.Count(proj => Main.projHook[proj.type] && proj.ai[0] == 2f && proj.active && proj.owner == Main.myPlayer);
|
||||
|
||||
@@ -157,7 +185,7 @@ namespace CalamityMod
|
||||
public static Vector2 SuperhomeTowardsTarget(this Projectile projectile, NPC target, float homingSpeed, float inertia, float predictionStrength = 1f)
|
||||
{
|
||||
if (predictionStrength < 0.01f) { predictionStrength = 0.01f; }
|
||||
Vector2 idealVelocity = CalculatePredictiveAimToTarget(projectile.Center, target, homingSpeed/predictionStrength) * predictionStrength;
|
||||
Vector2 idealVelocity = CalculatePredictiveAimToTarget(projectile.Center, target, homingSpeed / predictionStrength) * predictionStrength;
|
||||
return (projectile.velocity * (inertia - 1f) + idealVelocity) / inertia;
|
||||
}
|
||||
#endregion
|
||||
|
||||