From 58d5908bc1db719c3b59b8cf783d91908bda97f1 Mon Sep 17 00:00:00 2001 From: DominicKarma <51094361+DominicKarma@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:52:24 -0500 Subject: [PATCH] Stream Gouge rework (rebased and resolved shader conflicts) --- Effects/CalamityShaders.cs | 3 + Effects/IntersectionClipShader.fx | 39 ++ Effects/IntersectionClipShader.xnb | Bin 0 -> 3064 bytes .../ParticleBackgrounds/StreamGougeLayer.png | Bin 0 -> 1986 bytes Items/Weapons/Melee/StreamGouge.cs | 20 +- Particles/StreamGougeParticleSet.cs | 62 ++ Projectiles/Melee/Spears/StreamGougeProj.cs | 185 +++++- Projectiles/Melee/StreamGougePortal.cs | 123 ++++ Projectiles/Melee/StreamGougePortal.png | Bin 0 -> 837 bytes Utilities/MiscUtils.cs | 589 +++++++++--------- 10 files changed, 698 insertions(+), 323 deletions(-) create mode 100644 Effects/IntersectionClipShader.fx create mode 100644 Effects/IntersectionClipShader.xnb create mode 100644 ExtraTextures/ParticleBackgrounds/StreamGougeLayer.png create mode 100644 Particles/StreamGougeParticleSet.cs create mode 100644 Projectiles/Melee/StreamGougePortal.cs create mode 100644 Projectiles/Melee/StreamGougePortal.png diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 242765f67a..2233420755 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -30,6 +30,7 @@ namespace CalamityMod.Effects public static Effect DoGDisintegrationShader; public static Effect ArtAttackTrailShader; public static Effect CircularAoETelegraph; + public static Effect IntersectionClipShader; public static Effect LocalLinearTransformationShader; public static Effect BaseFusableParticleEdgeShader; @@ -64,6 +65,7 @@ namespace CalamityMod.Effects DoGDisintegrationShader = CalamityMod.Instance.GetEffect("Effects/DoGDisintegration"); ArtAttackTrailShader = CalamityMod.Instance.GetEffect("Effects/ArtAttackTrail"); CircularAoETelegraph = CalamityMod.Instance.GetEffect("Effects/CircularAoETelegraph"); + IntersectionClipShader = CalamityMod.Instance.GetEffect("Effects/IntersectionClipShader"); LocalLinearTransformationShader = CalamityMod.Instance.GetEffect("Effects/LocalLinearTransformationShader"); BaseFusableParticleEdgeShader = CalamityMod.Instance.GetEffect("Effects/ParticleFusion/BaseFusableParticleEdgeShader"); @@ -96,6 +98,7 @@ namespace CalamityMod.Effects GameShaders.Misc["CalamityMod:DoGDisintegration"] = new MiscShaderData(new Ref(DoGDisintegrationShader), "DisintegrationPass"); GameShaders.Misc["CalamityMod:ArtAttack"] = new MiscShaderData(new Ref(ArtAttackTrailShader), "TrailPass"); GameShaders.Misc["CalamityMod:CircularAoETelegraph"] = new MiscShaderData(new Ref(CircularAoETelegraph), "TelegraphPass"); + GameShaders.Misc["CalamityMod:IntersectionClip"] = new MiscShaderData(new Ref(IntersectionClipShader), "ClipPass"); GameShaders.Misc["CalamityMod:LinearTransformation"] = new MiscShaderData(new Ref(LocalLinearTransformationShader), "TransformationPass"); GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"] = new MiscShaderData(new Ref(BaseFusableParticleEdgeShader), "ParticlePass"); diff --git a/Effects/IntersectionClipShader.fx b/Effects/IntersectionClipShader.fx new file mode 100644 index 0000000000..2a8e4fd1b4 --- /dev/null +++ b/Effects/IntersectionClipShader.fx @@ -0,0 +1,39 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity : register(C0); +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +float uIntersectionCutoffDirection; +float2 uIntersectionPosition; +float2 uIntersectionNormal; +float2 uSize; + +float2 RotatedBy(float2 xy, float theta) +{ + return float2(xy.x * cos(theta) + xy.y * sin(theta), xy.x * sin(theta) - xy.y * cos(theta)); +} +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0 +{ + float2 worldPos = uWorldPosition + RotatedBy(coords - 0.5, uRotation - 1.57) * uSize; + if (sign(dot(uIntersectionNormal, worldPos - uIntersectionPosition)) == uIntersectionCutoffDirection) + return 0; + + return tex2D(uImage0, coords) * sampleColor; +} + +technique Technique1 +{ + pass ClipPass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/IntersectionClipShader.xnb b/Effects/IntersectionClipShader.xnb new file mode 100644 index 0000000000000000000000000000000000000000..4bf75817013cf16a651e4fcfd46fc6b07987549c GIT binary patch literal 3064 zcmb7GO>7%Q6rSDu)1Xucp@IT62T+iL<%9&KB2hz}1|m#JV+SmR2(GiKSGB!iy{k5e zgDb?1Ll8ao;7C1G4Tl_x#Gz7q;Lu7)aLgfx9(+KehaN#lHs3enS&yxzg=fvqd*6KT z&6}CGv(BDfxYQ^9Iwpkmz4f7+_q~d@8N{>YTztvTm7GhSe=(l)%7If3;%7EDoqVwB zBRK(TY_S(AiLj=J-U5dn(AQMQ21jECBnDuFNw4VnBJ#Om5FY2l+{3h!_sSbNe_J`X z(iew@FXv~Y455V|ZRPTAur06-%^%hTjGO#n^3yr&a4x{M%iI8o*(3PelW^4w6kDx@ z{NfS(e)2PJ$w9Bzc-`Rg3=9*N5|x)1`gvy+^%MCX7-Sn%!xSU1!%sZFxUu3@T)CWR zJ;Nlogg)92Wg@~w*T)=Oel*Xb!Pj|ffA-JPFXdh+1ZkNhG0pqh@a@h~u1nTe+WiVO zrhWGRvyZAd&iBCZG1v4m#=>R1ettzQD;Wmf=BBaAcCKSgpe5b8z5u)T|H^ zOFyoS{RuQJV^C(bfj)&+FzhPyYleLr`hj6Tgg&SX3Hm7X8N*INFBtY^=vNK<7WCf@ z`yuo}<4i}P&lq+VdSKY!LBC!J-M#`avHwyV-0sKNrc&y9=W*7Z?y2&y+SK_71SCP#Dg_>F9m_5w?w!qRX#n zhiKeqTl7ne4`RpB+oG=ndtG7!9oV?UdO9$DzxRq^;QT4+sP*o5W^Zqg*_!;8Thw*< zw`$#zKKA41h~B4AR(jXnwN+W4Tu+GTlNlRZeIxdMDxHd@3;deKl3r=cEkZdJpL{!h zYI-t0IWsjS_8QHf#LDWKv}I?P8qL?Db67{F#JFC04wi_020eksvLQZ;mO^Xa@lRiO zaQXiy*=PFU{4{=W|XsNG+z?Q)N*E+gr~^KZ~r{^^DBSf`R3mJQeyp= z(~AD!^ochYGylB$;=JmI?j9AU(aejbY%0m`oh9aLIuG5`kNN34iQjjMB~~J?#uP44 ztxAZ~&y1@vG8mWd3Pr~NmnAPnV>Gm1_q;kU`e?rHyXTcb@gSG~Z7A)yJ00`txb0Zg zBgYvJtz%pU$AfXy9(0b=hr%)D@(3~l;SF<6ZsAA`@EtTrRi5ifRVGz@C3f0+&wfka z5rZSO1$otsfK%TWgLR%!58h2>3sJ+_!0xSDVy%j?8s_iCTMJvT)huzdsyMdf5K|o5 zLi)h>3Ur%s2Si+_e&T)kt zA#TPx#1ZP1_K>z@;j|==^1poj5MNmvsMH&+;9~U!RI-EUQk(odZ`p5qp6D%zkKMp*g z4QQFk|L+ZFm}dXcCzq?4RIvPQ%Ky5~((%!)*~&>XfSC;q|Bj9#7d06j{p0`u010qN zS#tmY4#NNd4#NS*Z>VGd00#z1L_t(&L*<#>cH1}-gk>vhMRFvK?aaLYqi$7oHP8S- zOPR~vFDE2W-HjsnPxApMQamzNWOhswF?C?T*y)c>jF1G0b%m_%nb>6`s>wg4MJZ?BA7tj2%}Xmb3L$@N5&IL9Kabtg@por`ig4e)gZ zpPw+{7(SDCOv+Rqp-g#jc{tMI^Lh-KL{{#scAl~X6|>9op5l>Ip@Od?=5q9wwlQLL z=55P9HaSfuOJtE)6EcBI7_<-^qMaM|jEe?Otcfn+{}j@~CS$1Z!)u^4GoPeDEq0_8 z5TglwtW4nf>egstDQFUx(?C>UA@)q_OuCEvd4e=m7lfn^waKK8xj;8`w>uOA4AgdH zz8S$KJ+`IK6T^caSXnD51ehkDHWT-k%vTX}ISLNocP2R(ALpC*0Nc-iR1E@;MUD3s za4=^QCbeRD6EHYb9wsMJYZc>S-hl8}Y}Oj2awLrtmBc~Xpx5{0{!G3Hx%OC@?D1q; zBl7>i#5q&e`WoqEm}?__jWd7+v3NaSzt}j791g!N7I+3ZPTGBdSR=Zq>jR@bsEL!v z;rHJQ7vOlqvUGhY0N*->nKT>ckeEr?fCRBP83~qoFG5eBJYu-hgJB%!0QPS8E~-WB z;mfB-*i4VDOJzKIcW!|Dw?0^SfQWd!=rlrHlP+v)j?u*nryM2N0z@$MzI`IZ9i|+2 zITLF(!M$!YDY?X2Fl)Mvtm{Gz6Wz7#BAL|5SP~ML?LKbq5ZYl=xMN8!Tudg_#fp%i zY^A)pnJC;zNd}~;rhfxkAj)dlS?A!!qnR`twUuhx*DO2n6n836z%7M@)It-L37VK_ zCgVloRI!-I+61aHK@p9VNpdn-Oyq${)soQ0xkPs0c&TE~!GCI~nvA+n7qB)z`u8rBt&8<2q5iuC9oXAo3hk3eO1t~^%`H)aHdQ=WGUk9vYNk<+!ES60 z1QG|!k-V2Rb*asxk4kytF_`3YB7wwF#-Y^WSb@5aOp1%26Qta|9ny+O(D*CoWYrV}%|r=(84))+NQLwQQC}}Zl z4kV2eow0~r%;lWt71&I~t&zNY^=$Uek<6wVh6jXN$AR|I{Hovn)GI`;uChVsO{vBv z&B=0rZvOOVC2_WjOP}rDYNtnx-lt=ku=C2F{peyXQ7(^S)Tle4B&7;U>xqEd?e+8H z;{zuBuOUoA>P@FgOhvVomS`*s9Y;140k^|dCSS*5!cp}?+e|`kGyw~@3J~(VVUXyT zKk(%~KoAL@30zWbsOLj4g<>LZHkbVI&s~#GQ<=nh990#$Y$BteQo3BP$1;!j{zKd* zxx-Y`*o|}{f2>~N?>{7HpuShMPAqTqcGPco_1RsK-(nJb-g;2c1ltB8eAH1A?U4Hc_l^i9d^M&JIFW07Y z+D&;jsY#6Kakz;TVn@BNOd8*q@RJcdauKkKoMl#?JMT^bj^s%JC}x0XU)`tekh7Gy zTY*~VQLq8{8E?Ab6sUH@kyQvWnUp_>+SCr9*C{~UFE}uVvdfz-P7>#UCrl`fPju^P zlEEghSv-J859%Rs99T%KZgd3PD763+@$h1(>nRqD^{q!l-0Cyo&hq#o>mbKc;qesP zzQuJM3j9MG>j#&%aj`)eLhjg0^L3F^|cl{A3ttBygDj z{=iti=Tuhv3OKqVx0r9)v&$O;_#c_cj>q6KcHP6RUM?Y&zgI+7Vb8*0F)P{imrp7K zp`}?`qzxLl_aM1wGO? U9)J-2VE_OC07*qoM6N<$g7XTr_5c6? literal 0 HcmV?d00001 diff --git a/Items/Weapons/Melee/StreamGouge.cs b/Items/Weapons/Melee/StreamGouge.cs index 8b96482352..e3c3193763 100644 --- a/Items/Weapons/Melee/StreamGouge.cs +++ b/Items/Weapons/Melee/StreamGouge.cs @@ -11,29 +11,37 @@ namespace CalamityMod.Items.Weapons.Melee { public class StreamGouge : ModItem { + public const int SpinTime = 45; + + public const int SpearFireTime = 24; + + public const int PortalLifetime = 30; + public override void SetStaticDefaults() { DisplayName.SetDefault("Stream Gouge"); - Tooltip.SetDefault("Fires an essence spear clone\n" + - "Ignores immunity frames"); + Tooltip.SetDefault("Summons a portal that the spear crosses through\n" + + "Shortly after going through the portal, portals appear near the mouse that release copies of the spear's cutting edge\n" + + "Enemies hit by the copies create lacerations in space, revealing a cosmic background"); } public override void SetDefaults() { item.width = 100; - item.damage = 112; + item.height = 100; + item.damage = 300; item.melee = true; item.noMelee = true; item.useTurn = true; item.noUseGraphic = true; + item.channel = true; item.useAnimation = 19; - item.useStyle = ItemUseStyleID.HoldingOut; item.useTime = 19; + item.useStyle = ItemUseStyleID.HoldingOut; item.knockBack = 9.75f; item.UseSound = SoundID.Item20; item.autoReuse = true; - item.height = 100; - item.value = Item.buyPrice(1, 80, 0, 0); + item.value = CalamityGlobalItem.RarityDarkBlueBuyPrice; item.rare = ItemRarityID.Red; item.shoot = ModContent.ProjectileType(); item.shootSpeed = 15f; diff --git a/Particles/StreamGougeParticleSet.cs b/Particles/StreamGougeParticleSet.cs new file mode 100644 index 0000000000..01b803e10d --- /dev/null +++ b/Particles/StreamGougeParticleSet.cs @@ -0,0 +1,62 @@ +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 +{ + 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 FusableParticleRenderLayer RenderLayer => FusableParticleRenderLayer.OverNPCsBeforeProjectiles; + + public override List BackgroundShaders => new List() + { + GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"].Shader, + }; + public override List BackgroundTextures => new List() + { + ModContent.GetTexture("CalamityMod/ExtraTextures/ParticleBackgrounds/StreamGougeLayer"), + }; + 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.GlobalTime * 0.045f; + effect.Parameters["generalBackgroundOffset"].SetValue(offset); + effect.Parameters["upscaleFactor"].SetValue(Vector2.One * -0.3f); + break; + } + } + + public override void DrawParticles() + { + Texture2D fusableParticleBase = ModContent.GetTexture("CalamityMod/ExtraTextures/FusableParticleBase"); + 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); + } + } + } +} diff --git a/Projectiles/Melee/Spears/StreamGougeProj.cs b/Projectiles/Melee/Spears/StreamGougeProj.cs index c4a0b6fd58..d2a355d718 100644 --- a/Projectiles/Melee/Spears/StreamGougeProj.cs +++ b/Projectiles/Melee/Spears/StreamGougeProj.cs @@ -1,58 +1,187 @@ using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Items.Weapons.Melee; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.IO; using Terraria; +using Terraria.Graphics.Shaders; using Terraria.ModLoader; -using CalamityMod.Projectiles.BaseProjectiles; + namespace CalamityMod.Projectiles.Melee.Spears { - public class StreamGougeProj : BaseSpearProjectile + public class StreamGougeProj : ModProjectile { + public int Time; + + public Player Owner => Main.player[projectile.owner]; + + public float SpinCompletion => Utils.InverseLerp(0f, StreamGouge.SpinTime, Time, true); + + public ref float InitialDirection => ref projectile.ai[0]; + + public ref float SpinDirection => ref projectile.ai[1]; + public override void SetStaticDefaults() { - DisplayName.SetDefault("Gouge"); + DisplayName.SetDefault("Stream Gouge"); } public override void SetDefaults() { projectile.width = 40; - projectile.aiStyle = 19; - projectile.melee = true; - projectile.timeLeft = 90; projectile.height = 40; + projectile.penetrate = -1; + projectile.melee = true; projectile.friendly = true; - projectile.hostile = false; projectile.tileCollide = false; projectile.ignoreWater = true; - projectile.penetrate = -1; - projectile.ownerHitCheck = true; projectile.hide = true; + projectile.timeLeft = 90000; + projectile.MaxUpdates = 2; projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 5; + projectile.localNPCHitCooldown = projectile.MaxUpdates * 13; } - public override float InitialSpeed => 3f; - public override float ForwardSpeed => 0.95f; - public override float ReelbackSpeed => 2.4f; - - public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + public override void SendExtraAI(BinaryWriter writer) { - spriteBatch.Draw(ModContent.GetTexture("CalamityMod/Projectiles/Melee/Spears/StreamGougeGlow"), - projectile.Center - Main.screenPosition, - null, - Color.White, - projectile.rotation, - Vector2.Zero, - 1f, - SpriteEffects.None, - 0f); + writer.Write(Time); } - public override Action EffectBeforeReelback => (proj) => + + public override void ReceiveExtraAI(BinaryReader reader) { - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X, projectile.velocity.Y, - ModContent.ProjectileType(), projectile.damage * 4, projectile.knockBack, projectile.owner, 0f, 0f); - }; + Time = reader.ReadInt32(); + } + + public override void AI() + { + // Play a strong slash sound on the first frame to accompany the spin. + if (Time == 0f) + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/MeatySlash"), projectile.Center); + + // Define the initial direction. + if (InitialDirection == 0f) + { + InitialDirection = projectile.velocity.ToRotation(); + SpinDirection = Main.rand.NextBool().ToDirectionInt(); + projectile.netUpdate = true; + } + else + { + float stabOffset = (float)Math.Sin(Time / 3f) * 15f; + float spearReach = MathHelper.Lerp(-10f, stabOffset + 90f, Utils.InverseLerp(0f, StreamGouge.SpearFireTime, Time - StreamGouge.SpinTime, true)); + projectile.velocity = InitialDirection.ToRotationVector2() * spearReach; + } + + // Define the current rotation. + projectile.rotation = (float)Math.Pow(SpinCompletion, 0.82) * MathHelper.Pi * SpinDirection * 4f + InitialDirection - MathHelper.PiOver4 + MathHelper.Pi; + + // Manipulate player variables. + DeterminePlayerVariables(); + + // Create portals near the mouse once charged. + if (Main.myPlayer == projectile.owner && Time >= StreamGouge.SpinTime + StreamGouge.SpearFireTime && Time % 9f == 8f) + { + Vector2 portalSpawnPosition = Main.MouseWorld + Main.rand.NextVector2Unit() * Main.rand.NextFloat(50f, 140f); + Vector2 spearVelocity = (Main.MouseWorld - portalSpawnPosition).SafeNormalize(Vector2.UnitY); + Projectile.NewProjectile(portalSpawnPosition, spearVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + + Time++; + } + + public void DeterminePlayerVariables() + { + bool spearStillInUse = Owner.channel && !Owner.noItems && !Owner.CCed; + Owner.direction = (Math.Cos(projectile.rotation - MathHelper.Pi + MathHelper.PiOver4) > 0f).ToDirectionInt(); + Owner.heldProj = projectile.whoAmI; + Owner.itemTime = Owner.itemAnimation = 2; + Owner.itemRotation = CalamityUtils.WrapAngle90Degrees(MathHelper.WrapAngle(projectile.rotation - MathHelper.Pi + MathHelper.PiOver4)); + projectile.Center = Owner.Center; + + // Die if the spear is no longer in use. + if (!spearStillInUse) + projectile.Kill(); + } + + public void DrawPortal(SpriteBatch spriteBatch, Vector2 drawPosition, float opacity) + { + Texture2D portalTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/StreamGougePortal"); + Vector2 origin = portalTexture.Size() * 0.5f; + Color baseColor = Color.White; + float rotation = Main.GlobalTime * 6f; + + // Black portal. + Color color = Color.Lerp(baseColor, Color.Black, 0.55f).MultiplyRGB(Color.DarkGray) * opacity; + spriteBatch.Draw(portalTexture, drawPosition, null, color, rotation, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + spriteBatch.Draw(portalTexture, drawPosition, null, color, -rotation, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + + spriteBatch.SetBlendState(BlendState.Additive); + + // Cyan portal. + color = Color.Lerp(baseColor, Color.Cyan, 0.55f) * opacity * 1.6f; + spriteBatch.Draw(portalTexture, drawPosition, null, color, rotation * 0.6f, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + + // Magenta portal. + color = Color.Lerp(baseColor, Color.Fuchsia, 0.55f) * opacity * 1.6f; + spriteBatch.Draw(portalTexture, drawPosition, null, color, rotation * -0.6f, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + + spriteBatch.SetBlendState(BlendState.AlphaBlend); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + // Draw the spin smear texture. + if (SpinCompletion >= 0f && SpinCompletion < 1f) + { + Texture2D smear = ModContent.GetTexture("CalamityMod/Particles/SemiCircularSmear"); + + spriteBatch.EnterShaderRegion(BlendState.Additive); + + float rotation = projectile.rotation - MathHelper.Pi / 5f; + if (SpinDirection == -1f) + rotation += MathHelper.Pi; + + Color smearColor = Color.Fuchsia * CalamityUtils.Convert01To010(SpinCompletion) * 0.9f; + Vector2 smearOrigin = smear.Size() * 0.5f; + + spriteBatch.Draw(smear, Owner.Center - Main.screenPosition, null, smearColor, rotation, smearOrigin, projectile.scale * 1.45f, 0, 0); + spriteBatch.ExitShaderRegion(); + } + + // Make the spear go through the portal. + float portalOpacity = Utils.InverseLerp(0.6f, 1f, SpinCompletion, true); + bool portalIsInteractable = portalOpacity >= 1f; + Vector2 portalDrawPosition = Owner.Center + InitialDirection.ToRotationVector2() * 130f - Main.screenPosition; + + Texture2D texture = Main.projectileTexture[projectile.type]; + if (portalIsInteractable) + { + spriteBatch.EnterShaderRegion(); + Vector2 intersectionNormal = portalDrawPosition + Main.screenPosition - projectile.Center; + Vector2 worldOffset = projectile.rotation.ToRotationVector2() * -45f; + Vector2 intersectionOffset = (portalDrawPosition + Main.screenPosition - projectile.Center) * -1.5f; + GameShaders.Misc["CalamityMod:IntersectionClip"].Shader.Parameters["uIntersectionPosition"].SetValue(portalDrawPosition + intersectionOffset); + GameShaders.Misc["CalamityMod:IntersectionClip"].Shader.Parameters["uIntersectionNormal"].SetValue(intersectionNormal); + GameShaders.Misc["CalamityMod:IntersectionClip"].Shader.Parameters["uIntersectionCutoffDirection"].SetValue(-1f); + GameShaders.Misc["CalamityMod:IntersectionClip"].Shader.Parameters["uWorldPosition"].SetValue(projectile.Center - Main.screenPosition + worldOffset); + GameShaders.Misc["CalamityMod:IntersectionClip"].Shader.Parameters["uSize"].SetValue(texture.Size()); + GameShaders.Misc["CalamityMod:IntersectionClip"].Shader.Parameters["uRotation"].SetValue(projectile.rotation); + GameShaders.Misc["CalamityMod:IntersectionClip"].Apply(); + } + + Vector2 drawPosition = projectile.Center - Main.screenPosition; + Vector2 origin = texture.Size() * 0.5f; + spriteBatch.Draw(texture, drawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, origin, 1f, 0, 0); + + if (portalIsInteractable) + spriteBatch.ExitShaderRegion(); + + // Draw the portal once ready. + DrawPortal(spriteBatch, portalDrawPosition, portalOpacity); + + return false; + } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { diff --git a/Projectiles/Melee/StreamGougePortal.cs b/Projectiles/Melee/StreamGougePortal.cs new file mode 100644 index 0000000000..57bbef8148 --- /dev/null +++ b/Projectiles/Melee/StreamGougePortal.cs @@ -0,0 +1,123 @@ +using CalamityMod.Items.Weapons.Melee; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class StreamGougePortal : ModProjectile + { + public Vector2 SpearCenter => Vector2.Lerp(projectile.Center + projectile.velocity + projectile.velocity.SafeNormalize(Vector2.Zero) * 42f, projectile.Center, 1f - projectile.scale); + public ref float Time => ref projectile.ai[0]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Portal"); + } + + public override void SetDefaults() + { + projectile.width = 14; + projectile.height = 14; + projectile.friendly = true; + projectile.melee = true; + projectile.tileCollide = false; + projectile.timeLeft = StreamGouge.PortalLifetime; + projectile.ignoreWater = true; + projectile.alpha = 255; + projectile.penetrate = -1; + projectile.MaxUpdates = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = -1; + } + + public override void AI() + { + // Play a slice sound when spawning. + if (projectile.localAI[0] == 0f) + { + Main.PlayTrackedSound(CalamityUtils.GetTrackableSound("Sounds/Custom/SwiftSlice"), projectile.Center); + projectile.localAI[0] = 1f; + } + + float spearOutwardness = MathHelper.Lerp(4f, 52f, Utils.InverseLerp(0f, 18f, Time, true)); + projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * spearOutwardness; + projectile.Opacity = Utils.InverseLerp(0f, 8f, Time, true) * Utils.InverseLerp(0f, 10f, projectile.timeLeft, true); + projectile.scale = projectile.Opacity; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; + Time++; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = ModContent.GetTexture("CalamityMod/Items/Weapons/Melee/StreamGouge"); + Vector2 spearDrawPosition = SpearCenter - Main.screenPosition; + Vector2 spearOrigin = texture.Size() * 0.5f; + Color spearColor = Main.hslToRgb(projectile.identity % 10f / 40f + 0.67f, 1f, 0.5f); + spearColor.A = 0; + + for (int i = 0; i < 2; i++) + spriteBatch.Draw(texture, spearDrawPosition, null, spearColor * projectile.Opacity, projectile.rotation, spearOrigin, projectile.scale, 0, 0); + + Texture2D portalTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/StreamGougePortal"); + Vector2 origin = portalTexture.Size() * 0.5f; + Color baseColor = Color.White; + Vector2 drawPosition = projectile.Center - Main.screenPosition; + float rotation = Main.GlobalTime * 6f + projectile.identity * 1.45f; + + // Black portal. + Color color = Color.Lerp(baseColor, Color.Black, 0.55f).MultiplyRGB(Color.DarkGray) * projectile.Opacity; + spriteBatch.Draw(portalTexture, drawPosition, null, color, rotation, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + spriteBatch.Draw(portalTexture, drawPosition, null, color, -rotation, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + + spriteBatch.SetBlendState(BlendState.Additive); + + // Cyan portal. + color = Color.Lerp(baseColor, Color.Cyan, 0.55f) * projectile.Opacity * 1.4f; + spriteBatch.Draw(portalTexture, drawPosition, null, color, rotation * 0.6f, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + + // Magenta portal. + color = Color.Lerp(baseColor, Color.Fuchsia, 0.55f) * projectile.Opacity * 1.4f; + spriteBatch.Draw(portalTexture, drawPosition, null, color, rotation * -0.7f, origin, projectile.scale * 1.2f, SpriteEffects.None, 0f); + spriteBatch.SetBlendState(BlendState.AlphaBlend); + return false; + } + + // Create impact and cosmic parallax particles when hitting enemies. + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + Main.PlaySound(SoundID.Item74, target.Center); + if (Main.netMode == NetmodeID.Server) + return; + + Color impactColor = Color.Lerp(Color.Cyan, Color.White, Main.rand.NextFloat(0.3f, 0.64f)); + Vector2 impactPoint = Vector2.Lerp(projectile.Center, target.Center, 0.65f); + ImpactParticle impactParticle = new ImpactParticle(impactPoint, 0.1f, 20, Main.rand.NextFloat(0.4f, 0.5f), impactColor); + GeneralParticleHandler.SpawnParticle(impactParticle); + + for (int i = 0; i < 20; i++) + { + Vector2 spawnPosition = target.Center + Main.rand.NextVector2Circular(30f, 30f); + FusableParticleManager.GetParticleSetByType()?.SpawnParticle(spawnPosition, 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()?.SpawnParticle(spawnPosition, scale); + } + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float _ = 0f; + Vector2 start = SpearCenter - projectile.velocity.SafeNormalize(Vector2.UnitY) * projectile.scale * 50f; + Vector2 end = SpearCenter + projectile.velocity.SafeNormalize(Vector2.UnitY) * projectile.scale * 50f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), start, end, 15f, ref _); + } + + public override bool ShouldUpdatePosition() => false; + } +} diff --git a/Projectiles/Melee/StreamGougePortal.png b/Projectiles/Melee/StreamGougePortal.png new file mode 100644 index 0000000000000000000000000000000000000000..ba38bd0adc678d626708305ec2421ab98cece06f GIT binary patch literal 837 zcmV-L1G@Z)P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!2kdb!2!6DYwZ940@_JLK~!i%?U_Am z6j2n0*DORtqoVkYh!7AzD#c1s?A1bSZ3TaVzrdd$*xHJP+KYmvR(>=A5z!#QK-frN zB`9Z@r|?aV=gytkY%%wN9%H}zlP5rx?0`wXtm;*1vRWD`5Sb* z8VAg`oskv8fN7=aIIBjl-M>_|hnElD{4-;U3`4HzVi-f3GZ2}Lj7E6Iz3Q!|!86`p z!{ny-M8ZRJ7BHP_I5MkfPxNxTe}?P0VSJ5DdpQeD%_?d-mDgXNRqcx5nhopW$aF+* z?kZZX!OLx}C7$VGSPg?W{wkW=ZL74>bktDO#V}wRQs>aqnrQ*o$Mw*TwLvlLp}DQ5 zHFqE~?iq#1tj?jqTm2Qo5uWMDFy_>_ZjTJBS#MRub?TFxVmKA)1KlXNGeY_s;IFj9ff?`P9K3 z2dZtx(%RCSH`17GdBLSUhUfq+h-rn|G#55qj!e4{2#X5wU3!4Z*#Do z&@_LIQl;BM71g(qpidDY$5sx-a4u?ANgZb=O)=aQo%uve%PjQF@L=#4u1&JuY~y$e P00000NkvXXu0mjf4&9lE literal 0 HcmV?d00001 diff --git a/Utilities/MiscUtils.cs b/Utilities/MiscUtils.cs index 4b0019a6aa..2afbe1ebb4 100644 --- a/Utilities/MiscUtils.cs +++ b/Utilities/MiscUtils.cs @@ -24,168 +24,179 @@ using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; +using TerrariaAudio = Terraria.Audio; + namespace CalamityMod { - public static partial class CalamityUtils - { - public static void DisplayLocalizedText(string key, Color? textColor = null) - { - // An attempt to bypass the need for a separate method and runtime/compile-time parameter - // constraints by using nulls for defaults. - if (!textColor.HasValue) - textColor = Color.White; - - if (Main.netMode == NetmodeID.SinglePlayer) - Main.NewText(Language.GetTextValue(key), textColor.Value); - else if (Main.netMode == NetmodeID.Server) - NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), textColor.Value); - } - - // Yes, this method has a use that Utils.Swap does not; You cannot use refs on array indices. - // The CLR will not allow that. As such, a custom method must be used to achieve this. - - /// - /// Swaps two array indices based on a temporary variable. - /// - /// The type of the array. - /// The array. - /// The first index to swap. - /// The second index to swap. - public static void SwapArrayIndices(ref T[] array, int index1, int index2) - { - T temp = array[index1]; - array[index1] = array[index2]; - array[index2] = temp; - } - - public static T[] ShuffleArray(T[] array, Random rand = null) - { - if (rand is null) - rand = new Random(); - - for (int i = array.Length; i > 0; --i) - { - int j = rand.Next(i); - T tempElement = array[j]; - array[j] = array[i - 1]; - array[i - 1] = tempElement; - } - return array; - } - - public static T[,] ShaveOffEdge(this T[,] array) - { - T[,] result = new T[array.GetLength(0) - 2, array.GetLength(1) - 2]; - for (int i = 0; i < result.GetLength(0); i++) - { - for (int j = 0; j < result.GetLength(1); j++) - { - result[i, j] = array[i + 1, j + 1]; - } - } - return result; + public static partial class CalamityUtils + { + /// + /// Gets an instance of a sound that is trackable when used in conjunction with . + /// + /// The path to the sound file. + public static TerrariaAudio.CustomSoundStyle GetTrackableSound(string path) + { + return new TerrariaAudio.CustomSoundStyle(CalamityMod.Instance.GetSound(path), TerrariaAudio.SoundType.Sound); } - /// - /// Retrieves all the colors from a and returns them as a 2D array. - /// - /// The texture to load. - /// - public static Color[,] GetColorsFromTexture(this Texture2D texture) - { - Color[] alignedColors = new Color[texture.Width * texture.Height]; - texture.GetData(alignedColors); // Fills the color array with all the colors in the texture + public static void DisplayLocalizedText(string key, Color? textColor = null) + { + // An attempt to bypass the need for a separate method and runtime/compile-time parameter + // constraints by using nulls for defaults. + if (!textColor.HasValue) + textColor = Color.White; - Color[,] colors2D = new Color[texture.Width, texture.Height]; - for (int x = 0; x < texture.Width; x++) - { - for (int y = 0; y < texture.Height; y++) - { - colors2D[x, y] = alignedColors[x + y * texture.Width]; - } - } - return colors2D; - } + if (Main.netMode == NetmodeID.SinglePlayer) + Main.NewText(Language.GetTextValue(key), textColor.Value); + else if (Main.netMode == NetmodeID.Server) + NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), textColor.Value); + } - public static string CombineStrings(params object[] args) - { - StringBuilder result = new StringBuilder(1024); - for (int i = 0; i < args.Length; ++i) - { - object o = args[i]; - result.Append(o.ToString()); - result.Append(' '); - } - return result.ToString(); - } + // Yes, this method has a use that Utils.Swap does not; You cannot use refs on array indices. + // The CLR will not allow that. As such, a custom method must be used to achieve this. - /// - /// Determines if a list contains an entry of a specific type. Specifically intended to account for derived types. - /// - /// The base type of the collection. - /// The collection. - /// The type to search for. - public static bool ContainsType(this IEnumerable collection, Type type) => collection.Any(entry => entry.GetType() == type.GetType()); + /// + /// Swaps two array indices based on a temporary variable. + /// + /// The type of the array. + /// The array. + /// The first index to swap. + /// The second index to swap. + public static void SwapArrayIndices(ref T[] array, int index1, int index2) + { + T temp = array[index1]; + array[index1] = array[index2]; + array[index2] = temp; + } - /// - /// Calculates the sound volume and panning for a sound which is played at the specified location in the game world.
- /// Note that sound does not play on dedicated servers or during world generation. - ///
- /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. - /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. - /// Volume and pan, in that order. Volume is always between 0 and 1. Pan is always between -1 and 1. - public static (float, float) CalculateSoundStats(Vector2 soundPos, bool ambient = false) - { - float volume = 0f; - float pan = 0f; + public static T[] ShuffleArray(T[] array, Random rand = null) + { + if (rand is null) + rand = new Random(); - if (soundPos.X == -1f || soundPos.Y == -1f) - volume = 1f; - else if (WorldGen.gen || Main.dedServ || Main.netMode == NetmodeID.Server) - volume = 0f; - else - { - float topLeftX = Main.screenPosition.X - Main.screenWidth * 2f; - float topLeftY = Main.screenPosition.Y - Main.screenHeight * 2f; + for (int i = array.Length; i > 0; --i) + { + int j = rand.Next(i); + T tempElement = array[j]; + array[j] = array[i - 1]; + array[i - 1] = tempElement; + } + return array; + } - // Sounds cannot be heard from more than ~2.5 screens away. - // This rectangle is 5x5 screens centered on the current screen center position. - Rectangle audibleArea = new Rectangle((int)topLeftX, (int)topLeftY, Main.screenWidth * 5, Main.screenHeight * 5); - Rectangle soundHitbox = new Rectangle((int)soundPos.X, (int)soundPos.Y, 1, 1); - Vector2 screenCenter = Main.screenPosition + new Vector2(Main.screenWidth * 0.5f, Main.screenHeight * 0.5f); - if (audibleArea.Intersects(soundHitbox)) - { - pan = (soundPos.X - screenCenter.X) / (Main.screenWidth * 0.5f); - float dist = Vector2.Distance(soundPos, screenCenter); - volume = 1f - (dist / (Main.screenWidth * 1.5f)); - } - } + public static T[,] ShaveOffEdge(this T[,] array) + { + T[,] result = new T[array.GetLength(0) - 2, array.GetLength(1) - 2]; + for (int i = 0; i < result.GetLength(0); i++) + { + for (int j = 0; j < result.GetLength(1); j++) + { + result[i, j] = array[i + 1, j + 1]; + } + } + return result; + } - pan = MathHelper.Clamp(pan, -1f, 1f); - volume = MathHelper.Clamp(volume, 0f, 1f); - if (ambient) - volume = Main.gameInactive ? 0f : volume * Main.ambientVolume; - else - volume *= Main.soundVolume; + /// + /// Retrieves all the colors from a and returns them as a 2D array. + /// + /// The texture to load. + /// + public static Color[,] GetColorsFromTexture(this Texture2D texture) + { + Color[] alignedColors = new Color[texture.Width * texture.Height]; + texture.GetData(alignedColors); // Fills the color array with all the colors in the texture - // This is actually done by vanilla. I guess if the sound volume gets corrupted during gameplay, you can't blast your eardrums out. - volume = MathHelper.Clamp(volume, 0f, 1f); - return (volume, pan); - } + Color[,] colors2D = new Color[texture.Width, texture.Height]; + for (int x = 0; x < texture.Width; x++) + { + for (int y = 0; y < texture.Height; y++) + { + colors2D[x, y] = alignedColors[x + y * texture.Width]; + } + } + return colors2D; + } - /// - /// Convenience function to utilize CalculateSoundStats immediately on an existing sound effect.
- /// This allows updating a looping sound every single frame to have the correct volume and pan, even if the player drags the audio sliders around. - ///
- /// The SoundEffectInstance which is having its values updated. - /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. - /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. - public static void ApplySoundStats(ref SoundEffectInstance sfx, Vector2 soundPos, bool ambient = false) - { - if (sfx is null || sfx.IsDisposed) - return; - (sfx.Volume, sfx.Pan) = CalculateSoundStats(soundPos, ambient); - } + public static string CombineStrings(params object[] args) + { + StringBuilder result = new StringBuilder(1024); + for (int i = 0; i < args.Length; ++i) + { + object o = args[i]; + result.Append(o.ToString()); + result.Append(' '); + } + return result.ToString(); + } + + /// + /// Determines if a list contains an entry of a specific type. Specifically intended to account for derived types. + /// + /// The base type of the collection. + /// The collection. + /// The type to search for. + public static bool ContainsType(this IEnumerable collection, Type type) => collection.Any(entry => entry.GetType() == type.GetType()); + + /// + /// Calculates the sound volume and panning for a sound which is played at the specified location in the game world.
+ /// Note that sound does not play on dedicated servers or during world generation. + ///
+ /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. + /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. + /// Volume and pan, in that order. Volume is always between 0 and 1. Pan is always between -1 and 1. + public static (float, float) CalculateSoundStats(Vector2 soundPos, bool ambient = false) + { + float volume = 0f; + float pan = 0f; + + if (soundPos.X == -1f || soundPos.Y == -1f) + volume = 1f; + else if (WorldGen.gen || Main.dedServ || Main.netMode == NetmodeID.Server) + volume = 0f; + else + { + float topLeftX = Main.screenPosition.X - Main.screenWidth * 2f; + float topLeftY = Main.screenPosition.Y - Main.screenHeight * 2f; + + // Sounds cannot be heard from more than ~2.5 screens away. + // This rectangle is 5x5 screens centered on the current screen center position. + Rectangle audibleArea = new Rectangle((int)topLeftX, (int)topLeftY, Main.screenWidth * 5, Main.screenHeight * 5); + Rectangle soundHitbox = new Rectangle((int)soundPos.X, (int)soundPos.Y, 1, 1); + Vector2 screenCenter = Main.screenPosition + new Vector2(Main.screenWidth * 0.5f, Main.screenHeight * 0.5f); + if (audibleArea.Intersects(soundHitbox)) + { + pan = (soundPos.X - screenCenter.X) / (Main.screenWidth * 0.5f); + float dist = Vector2.Distance(soundPos, screenCenter); + volume = 1f - (dist / (Main.screenWidth * 1.5f)); + } + } + + pan = MathHelper.Clamp(pan, -1f, 1f); + volume = MathHelper.Clamp(volume, 0f, 1f); + if (ambient) + volume = Main.gameInactive ? 0f : volume * Main.ambientVolume; + else + volume *= Main.soundVolume; + + // This is actually done by vanilla. I guess if the sound volume gets corrupted during gameplay, you can't blast your eardrums out. + volume = MathHelper.Clamp(volume, 0f, 1f); + return (volume, pan); + } + + /// + /// Convenience function to utilize CalculateSoundStats immediately on an existing sound effect.
+ /// This allows updating a looping sound every single frame to have the correct volume and pan, even if the player drags the audio sliders around. + ///
+ /// The SoundEffectInstance which is having its values updated. + /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. + /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. + public static void ApplySoundStats(ref SoundEffectInstance sfx, Vector2 soundPos, bool ambient = false) + { + if (sfx is null || sfx.IsDisposed) + return; + (sfx.Volume, sfx.Pan) = CalculateSoundStats(soundPos, ambient); + } /// /// Method to change the volume of a sound without having to manually do a nullcheck or having to clamp it down to between 0 and 1 @@ -200,148 +211,148 @@ namespace CalamityMod } public static void StartRain(bool torrentialTear = false, bool maxSeverity = false) - { - int num = 86400; - int num2 = num / 24; - Main.rainTime = Main.rand.Next(num2 * 8, num); - if (Main.rand.NextBool(3)) - { - Main.rainTime += Main.rand.Next(0, num2); - } - if (Main.rand.NextBool(4)) - { - Main.rainTime += Main.rand.Next(0, num2 * 2); - } - if (Main.rand.NextBool(5)) - { - Main.rainTime += Main.rand.Next(0, num2 * 2); - } - if (Main.rand.NextBool(6)) - { - Main.rainTime += Main.rand.Next(0, num2 * 3); - } - if (Main.rand.NextBool(7)) - { - Main.rainTime += Main.rand.Next(0, num2 * 4); - } - if (Main.rand.NextBool(8)) - { - Main.rainTime += Main.rand.Next(0, num2 * 5); - } - float num3 = 1f; - if (Main.rand.NextBool(2)) - { - num3 += 0.05f; - } - if (Main.rand.NextBool(3)) - { - num3 += 0.1f; - } - if (Main.rand.NextBool(4)) - { - num3 += 0.15f; - } - if (Main.rand.NextBool(5)) - { - num3 += 0.2f; - } - Main.rainTime = (int)(Main.rainTime * num3); - Main.raining = true; - if (torrentialTear) - TorrentialTear.AdjustRainSeverity(maxSeverity); - CalamityNetcode.SyncWorld(); - } + { + int num = 86400; + int num2 = num / 24; + Main.rainTime = Main.rand.Next(num2 * 8, num); + if (Main.rand.NextBool(3)) + { + Main.rainTime += Main.rand.Next(0, num2); + } + if (Main.rand.NextBool(4)) + { + Main.rainTime += Main.rand.Next(0, num2 * 2); + } + if (Main.rand.NextBool(5)) + { + Main.rainTime += Main.rand.Next(0, num2 * 2); + } + if (Main.rand.NextBool(6)) + { + Main.rainTime += Main.rand.Next(0, num2 * 3); + } + if (Main.rand.NextBool(7)) + { + Main.rainTime += Main.rand.Next(0, num2 * 4); + } + if (Main.rand.NextBool(8)) + { + Main.rainTime += Main.rand.Next(0, num2 * 5); + } + float num3 = 1f; + if (Main.rand.NextBool(2)) + { + num3 += 0.05f; + } + if (Main.rand.NextBool(3)) + { + num3 += 0.1f; + } + if (Main.rand.NextBool(4)) + { + num3 += 0.15f; + } + if (Main.rand.NextBool(5)) + { + num3 += 0.2f; + } + Main.rainTime = (int)(Main.rainTime * num3); + Main.raining = true; + if (torrentialTear) + TorrentialTear.AdjustRainSeverity(maxSeverity); + CalamityNetcode.SyncWorld(); + } - public static void StartSandstorm() - { - typeof(Terraria.GameContent.Events.Sandstorm).GetMethod("StartSandstorm", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null); - } + public static void StartSandstorm() + { + typeof(Terraria.GameContent.Events.Sandstorm).GetMethod("StartSandstorm", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null); + } - public static void StopSandstorm() - { - Terraria.GameContent.Events.Sandstorm.Happening = false; - } + public static void StopSandstorm() + { + Terraria.GameContent.Events.Sandstorm.Happening = false; + } - public static void AddWithCondition(this List list, T type, bool condition) - { - if (condition) - list.Add(type); - } + public static void AddWithCondition(this List list, T type, bool condition) + { + if (condition) + list.Add(type); + } - public static int SecondsToFrames(int seconds) => seconds * 60; - public static int SecondsToFrames(float seconds) => (int)(seconds * 60); + public static int SecondsToFrames(int seconds) => seconds * 60; + public static int SecondsToFrames(float seconds) => (int)(seconds * 60); - /// - /// Call this function to spawn explosion clouds at the specified location. Good for when NPCs or projectiles die and need to explode. - /// - /// The spot to spawn the explosion clouds - /// Number of times it loops to spawn gores - public static void ExplosionGores(Vector2 goreSource, int goreAmt) - { - Vector2 source = new Vector2(goreSource.X - 24f, goreSource.Y - 24f); - for (int goreIndex = 0; goreIndex < goreAmt; goreIndex++) - { - float velocityMult = 0.33f; - if (goreIndex < (goreAmt / 3)) - { - velocityMult = 0.66f; - } - if (goreIndex >= (2 * goreAmt / 3)) - { - velocityMult = 1f; - } - Mod mod = ModContent.GetInstance(); - int type = Main.rand.Next(61, 64); - int smoke = Gore.NewGore(source, default, type, 1f); - Gore gore = Main.gore[smoke]; - gore.velocity *= velocityMult; - gore.velocity.X += 1f; - gore.velocity.Y += 1f; - type = Main.rand.Next(61, 64); - smoke = Gore.NewGore(source, default, type, 1f); - gore = Main.gore[smoke]; - gore.velocity *= velocityMult; - gore.velocity.X -= 1f; - gore.velocity.Y += 1f; - type = Main.rand.Next(61, 64); - smoke = Gore.NewGore(source, default, type, 1f); - gore = Main.gore[smoke]; - gore.velocity *= velocityMult; - gore.velocity.X += 1f; - gore.velocity.Y -= 1f; - type = Main.rand.Next(61, 64); - smoke = Gore.NewGore(source, default, type, 1f); - gore = Main.gore[smoke]; - gore.velocity *= velocityMult; - gore.velocity.X -= 1f; - gore.velocity.Y -= 1f; - } - } + /// + /// Call this function to spawn explosion clouds at the specified location. Good for when NPCs or projectiles die and need to explode. + /// + /// The spot to spawn the explosion clouds + /// Number of times it loops to spawn gores + public static void ExplosionGores(Vector2 goreSource, int goreAmt) + { + Vector2 source = new Vector2(goreSource.X - 24f, goreSource.Y - 24f); + for (int goreIndex = 0; goreIndex < goreAmt; goreIndex++) + { + float velocityMult = 0.33f; + if (goreIndex < (goreAmt / 3)) + { + velocityMult = 0.66f; + } + if (goreIndex >= (2 * goreAmt / 3)) + { + velocityMult = 1f; + } + Mod mod = ModContent.GetInstance(); + int type = Main.rand.Next(61, 64); + int smoke = Gore.NewGore(source, default, type, 1f); + Gore gore = Main.gore[smoke]; + gore.velocity *= velocityMult; + gore.velocity.X += 1f; + gore.velocity.Y += 1f; + type = Main.rand.Next(61, 64); + smoke = Gore.NewGore(source, default, type, 1f); + gore = Main.gore[smoke]; + gore.velocity *= velocityMult; + gore.velocity.X -= 1f; + gore.velocity.Y += 1f; + type = Main.rand.Next(61, 64); + smoke = Gore.NewGore(source, default, type, 1f); + gore = Main.gore[smoke]; + gore.velocity *= velocityMult; + gore.velocity.X += 1f; + gore.velocity.Y -= 1f; + type = Main.rand.Next(61, 64); + smoke = Gore.NewGore(source, default, type, 1f); + gore = Main.gore[smoke]; + gore.velocity *= velocityMult; + gore.velocity.X -= 1f; + gore.velocity.Y -= 1f; + } + } - public static bool WithinBounds(this int index, int cap) => index >= 0 && index < cap; + public static bool WithinBounds(this int index, int cap) => index >= 0 && index < cap; - /// Clamps the distance between vectors via normalization. - /// - /// The starting point. - /// The ending point. - /// The maximum possible distance between the two vectors before they get clamped. - public static void DistanceClamp(ref Vector2 start, ref Vector2 end, float maxDistance) - { - if (Vector2.Distance(end, start) > maxDistance) - { - end = start + Vector2.Normalize(end - start) * maxDistance; - } - } + /// Clamps the distance between vectors via normalization. + /// + /// The starting point. + /// The ending point. + /// The maximum possible distance between the two vectors before they get clamped. + public static void DistanceClamp(ref Vector2 start, ref Vector2 end, float maxDistance) + { + if (Vector2.Distance(end, start) > maxDistance) + { + end = start + Vector2.Normalize(end - start) * maxDistance; + } + } - public static void ChangeTime(bool changeToDay) - { - Main.time = 0D; - Main.dayTime = changeToDay; - CalamityNetcode.SyncWorld(); - } + public static void ChangeTime(bool changeToDay) + { + Main.time = 0D; + Main.dayTime = changeToDay; + CalamityNetcode.SyncWorld(); + } - public static int GetBannerItem(int style) - { + public static int GetBannerItem(int style) + { int item = -1; switch (style) { @@ -729,11 +740,11 @@ namespace CalamityMod default: break; } - return item; - } + return item; + } - public static int GetBannerNPC(int style) - { + public static int GetBannerNPC(int style) + { int npc = -1; switch (style) { @@ -1118,7 +1129,7 @@ namespace CalamityMod default: break; } - return npc; - } - } + return npc; + } + } }