251 lines
11 KiB
C#
251 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CalamityMod.CalPlayer;
|
|
using CalamityMod.DataStructures;
|
|
using CalamityMod.Items.Materials;
|
|
using CalamityMod.Rarities;
|
|
using CalamityMod.Tiles.Furniture.CraftingStations;
|
|
using CalamityMod.World;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using ReLogic.Content;
|
|
using Terraria;
|
|
using Terraria.Audio;
|
|
using Terraria.DataStructures;
|
|
using Terraria.GameContent;
|
|
using Terraria.Graphics.Effects;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Items.Accessories
|
|
{
|
|
[LegacyName("Sponge")]
|
|
public class TheSponge : ModItem, ILocalizedModType, IDyeableShaderRenderer
|
|
{
|
|
public new string LocalizationCategory => "Items.Accessories";
|
|
|
|
public override string Texture => (DateTime.Now.Month == 4 && DateTime.Now.Day == 1) ? "CalamityMod/Items/Accessories/TheSpongeReal" : "CalamityMod/Items/Accessories/TheSponge";
|
|
|
|
public static Asset<Texture2D> NoiseTex;
|
|
// TODO -- Unique sounds for The Sponge
|
|
public static readonly SoundStyle ShieldHurtSound = new("CalamityMod/Sounds/Custom/RoverDriveHit") { PitchVariance = 0.6f, Volume = 0.6f, MaxInstances = 0 };
|
|
public static readonly SoundStyle ActivationSound = new("CalamityMod/Sounds/Custom/RoverDriveActivate") { Volume = 0.85f };
|
|
public static readonly SoundStyle BreakSound = new("CalamityMod/Sounds/Custom/RoverDriveBreak") { Volume = 0.75f };
|
|
|
|
public static int ShieldDurabilityMax = 180;
|
|
public static int ShieldRechargeDelay = CalamityUtils.SecondsToFrames(9); // was 6
|
|
public static int TotalShieldRechargeTime = CalamityUtils.SecondsToFrames(6);
|
|
|
|
// While active, The Sponge gives 30 defense and 10% DR
|
|
public static int ShieldActiveDefense = 30;
|
|
public static float ShieldActiveDamageReduction = 0.1f;
|
|
|
|
public int OwnerPlayer { get; set; }
|
|
public float RenderDepth => IDyeableShaderRenderer.SpongeShieldDepth;
|
|
|
|
public bool ShouldDrawDyeableShader
|
|
{
|
|
get
|
|
{
|
|
if (CalamityClientConfig.Instance.EnergyShieldOpacity <= 0.0f)
|
|
return false;
|
|
|
|
if (OwnerPlayer < 0 || OwnerPlayer >= Main.maxPlayers)
|
|
return false;
|
|
|
|
var player = Main.player[OwnerPlayer];
|
|
if (player is null)
|
|
return false;
|
|
|
|
if (player.outOfRange || player.dead)
|
|
return false;
|
|
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
if (modPlayer.drawingParameters.SpongeShieldCharge <= 0.0f)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.RegisterItemAnimation(Item.type, new DrawAnimationVertical(5, 30));
|
|
ItemID.Sets.AnimatesAsSoul[Type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Item.width = 20;
|
|
Item.height = 20;
|
|
Item.value = CalamityGlobalItem.RarityDarkBlueBuyPrice;
|
|
Item.accessory = true;
|
|
Item.rare = ModContent.RarityType<DarkBlue>();
|
|
}
|
|
|
|
public override void UpdateAccessory(Player player, bool hideVisual)
|
|
{
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
modPlayer.sponge = true;
|
|
modPlayer.spongeShieldVisible = !hideVisual;
|
|
|
|
if (modPlayer.SpongeShieldDurability > 0)
|
|
{
|
|
player.statDefense += ShieldActiveDefense;
|
|
player.endurance += ShieldActiveDamageReduction;
|
|
}
|
|
}
|
|
|
|
// In vanity, provides a visual shield but no actual functionality
|
|
public override void UpdateVanity(Player player) => player.Calamity().spongeShieldVisible = true;
|
|
|
|
public override void ModifyTooltips(List<TooltipLine> tooltips)
|
|
{
|
|
string adrenTooltip = CalamityWorld.revenge ? this.GetLocalizedValue("ShieldAdren") : "";
|
|
tooltips.FindAndReplace("[ADREN]", adrenTooltip);
|
|
}
|
|
|
|
// Renders the bubble shield over the item in the world.
|
|
public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
|
|
{
|
|
// Will not render a shield if the April Fool's sprite is active.
|
|
if (Texture == "CalamityMod/Items/Accessories/TheSponge")
|
|
{
|
|
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/Items/Accessories/TheSpongeShield").Value;
|
|
spriteBatch.Draw(tex, Item.Center - Main.screenPosition + new Vector2(0f, 0f), Main.itemAnimations[Item.type].GetFrame(tex), Color.Cyan * 0.5f, 0f, new Vector2(tex.Width / 2f, (tex.Height / 30f) * 0.8f), 1f, SpriteEffects.None, 0);
|
|
}
|
|
}
|
|
|
|
// TODO -- Is this necessary to block the shield in-inventory on April first?
|
|
public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
|
|
{
|
|
return Texture != "CalamityMod/Items/Accessories/TheSponge";
|
|
}
|
|
|
|
// Renders the bubble shield over the item in a player's inventory.
|
|
public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
|
|
{
|
|
// Will not render a shield if the April Fool's sprite is active.
|
|
if (Texture == "CalamityMod/Items/Accessories/TheSponge")
|
|
{
|
|
float wantedScale = 0.85f;
|
|
Vector2 drawOffset = new(-2f, -1f);
|
|
|
|
CalamityUtils.DrawInventoryCustomScale(
|
|
spriteBatch,
|
|
texture: TextureAssets.Item[Type].Value,
|
|
position,
|
|
frame,
|
|
drawColor,
|
|
itemColor,
|
|
origin,
|
|
scale,
|
|
wantedScale,
|
|
drawOffset
|
|
);
|
|
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/Items/Accessories/TheSpongeShield").Value;
|
|
CalamityUtils.DrawInventoryCustomScale(
|
|
spriteBatch,
|
|
texture: tex,
|
|
position,
|
|
Main.itemAnimations[Item.type].GetFrame(tex),
|
|
Color.Cyan * 0.4f,
|
|
itemColor,
|
|
origin,
|
|
scale,
|
|
wantedScale,
|
|
drawOffset
|
|
);
|
|
}
|
|
}
|
|
|
|
public override void AddRecipes()
|
|
{
|
|
CreateRecipe().
|
|
AddIngredient<RoverDrive>().
|
|
AddIngredient<MysteriousCircuitry>(10).
|
|
AddIngredient<DubiousPlating>(20).
|
|
AddIngredient<CosmiliteBar>(5).
|
|
AddIngredient<AscendantSpiritEssence>(4).
|
|
AddTile<CosmicAnvil>().
|
|
Register();
|
|
}
|
|
|
|
// Complex drawcode which draws Sponge shields on ALL players who have it available. Supposedly.
|
|
// This is applied as IL (On hook) which draws right before Inferno Ring.
|
|
public void DrawDyeableShader(SpriteBatch spriteBatch)
|
|
{
|
|
if (OwnerPlayer < 0 || OwnerPlayer >= Main.maxPlayers)
|
|
return;
|
|
|
|
var player = Main.player[OwnerPlayer];
|
|
if (player is null)
|
|
return;
|
|
|
|
if (player.outOfRange || player.dead)
|
|
return;
|
|
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
if (modPlayer.drawnAnyShieldThisFrame)
|
|
return;
|
|
|
|
if (modPlayer.drawingParameters.SpongeShieldCharge <= 0.0f)
|
|
return;
|
|
|
|
// Scale the shield is drawn at. The Sponge shield gently grows and shrinks; it should be largely imperceptible.
|
|
// The "i" parameter is to make different player's shields not be perfectly synced.
|
|
int i = player.whoAmI;
|
|
float baseScale = 0.155f;
|
|
float maxExtraScale = 0.025f;
|
|
float extraScalePulseInterpolant = MathF.Pow(4f, MathF.Sin(Main.GlobalTimeWrappedHourly * 0.791f + i) - 1);
|
|
float scale = baseScale + maxExtraScale * extraScalePulseInterpolant;
|
|
float visualShieldStrength = modPlayer.drawingParameters.SpongeShieldCharge;
|
|
|
|
// The scale used for the noise overlay also grows and shrinks
|
|
// This is intentionally out of sync with the shield, and intentionally desynced per player
|
|
// Don't put this anywhere less than 0.15f or higher than 0.75f. The higher it is, the denser / more zoomed out the noise overlay is.
|
|
// Changing this too quickly and/or too much makes the noise grow and shrink visibly, so be careful with that.
|
|
float noiseScale = MathHelper.Lerp(0.28f, 0.38f, 0.5f + 0.5f * MathF.Sin(Main.GlobalTimeWrappedHourly * 0.347f + i));
|
|
|
|
// Define shader parameters
|
|
Effect shieldEffect = Filters.Scene["CalamityMod:RoverDriveShield"].GetShader().Shader;
|
|
shieldEffect.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly * 0.0813f); // Scrolling speed of polygonal overlay
|
|
shieldEffect.Parameters["blowUpPower"].SetValue(3f);
|
|
shieldEffect.Parameters["blowUpSize"].SetValue(0.56f);
|
|
shieldEffect.Parameters["noiseScale"].SetValue(noiseScale);
|
|
|
|
// Shield opacity multiplier slightly changes, this is independent of current shield strength
|
|
float baseShieldOpacity = 0.9f + 0.1f * MathF.Sin(Main.GlobalTimeWrappedHourly * 1.95f);
|
|
float minShieldStrengthOpacityMultiplier = 0.25f;
|
|
float finalShieldOpacity = baseShieldOpacity * MathHelper.Lerp(minShieldStrengthOpacityMultiplier, 1f, visualShieldStrength);
|
|
finalShieldOpacity *= CalamityClientConfig.Instance.EnergyShieldOpacity;
|
|
|
|
shieldEffect.Parameters["shieldOpacity"].SetValue(finalShieldOpacity);
|
|
shieldEffect.Parameters["shieldEdgeBlendStrenght"].SetValue(4f);
|
|
|
|
Color shieldColor = new Color(24, 156, 204); // #189CCC
|
|
Color primaryEdgeColor = shieldColor;
|
|
Color secondaryEdgeColor = new Color(34, 224, 227); // #22E0E3
|
|
|
|
// Final shield edge color, which lerps about
|
|
Color edgeColor = CalamityUtils.MulticolorLerp(Main.GlobalTimeWrappedHourly * 0.2f, primaryEdgeColor, secondaryEdgeColor);
|
|
|
|
// Define shader parameters for shield color
|
|
shieldEffect.Parameters["shieldColor"].SetValue(shieldColor.ToVector3());
|
|
shieldEffect.Parameters["shieldEdgeColor"].SetValue(edgeColor.ToVector3());
|
|
|
|
var matrix = Main.GameViewMatrix.TransformationMatrix;
|
|
Main.spriteBatch.SafeBegin(SpriteSortMode.Immediate, BatchSetting.Additive, shieldEffect, matrix, () =>
|
|
{
|
|
// Fetch shield noise overlay texture (this is the polygons fed to the shader)
|
|
NoiseTex ??= ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/Neurons");
|
|
Vector2 pos = player.MountedCenter + player.gfxOffY * Vector2.UnitY - Main.screenPosition;
|
|
Texture2D tex = NoiseTex.Value;
|
|
Main.spriteBatch.Draw(tex, pos, null, Color.White, 0, tex.Size() / 2f, scale, 0, 0);
|
|
});
|
|
|
|
modPlayer.drawnAnyShieldThisFrame = true;
|
|
}
|
|
}
|
|
}
|