diff --git a/Buffs/CalamityGlobalBuff.cs b/Buffs/CalamityGlobalBuff.cs index 0fae2bfeae..179849f6eb 100644 --- a/Buffs/CalamityGlobalBuff.cs +++ b/Buffs/CalamityGlobalBuff.cs @@ -114,15 +114,15 @@ namespace CalamityMod.Buffs break; case BuffID.BeetleMight1: - tip = "Melee damage and speed increase by 5%"; + tip = "Melee damage increased by 10%"; break; case BuffID.BeetleMight2: - tip = "Melee damage and speed increase by 10%"; + tip = "Melee damage increased by 20%"; break; case BuffID.BeetleMight3: - tip = "Melee damage and speed increase by 15%"; + tip = "Melee damage increased by 30%"; break; case BuffID.BeetleEndurance1: diff --git a/Buffs/Summon/VoidConcentrationBuff.cs b/Buffs/Summon/VoidConcentrationBuff.cs new file mode 100644 index 0000000000..a83a737d5f --- /dev/null +++ b/Buffs/Summon/VoidConcentrationBuff.cs @@ -0,0 +1,36 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + class VoidConcentrationBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Concentrated Void"); + Description.SetDefault("The infinite void yearns for more..."); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + //Main.persistentBuff[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer mp = player.Calamity(); + int count = player.ownedProjectileCounts[ModContent.ProjectileType()]; + player.minionDamage += 0.05f; //5% + player.armorPenetration += 10; + if (!mp.voidAuraDamage && count == 0) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + { + player.buffTime[buffIndex] = 18000; + } + } + } +} diff --git a/Buffs/Summon/VoidConcentrationBuff.png b/Buffs/Summon/VoidConcentrationBuff.png new file mode 100644 index 0000000000..0aff2acf15 Binary files /dev/null and b/Buffs/Summon/VoidConcentrationBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 559cb4a85b..620d843d2f 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -42,6 +42,7 @@ using CalamityMod.NPCs.SulphurousSea; using CalamityMod.NPCs.SunkenSea; using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.NPCs.Yharon; +using CalamityMod.Particles; using CalamityMod.Projectiles.Boss; using CalamityMod.Projectiles.DraedonsArsenal; using CalamityMod.Projectiles.Enemy; @@ -52,6 +53,7 @@ using CalamityMod.Projectiles.Ranged; using CalamityMod.Projectiles.Rogue; using CalamityMod.Projectiles.Summon; using CalamityMod.Projectiles.Typeless; +using CalamityMod.Skies; using CalamityMod.Tiles; using CalamityMod.UI; using CalamityMod.World; @@ -71,6 +73,8 @@ using Terraria.Localization; using Terraria.ModLoader; using Terraria.ModLoader.IO; +using ProvidenceBoss = CalamityMod.NPCs.Providence.Providence; + namespace CalamityMod.CalPlayer { public partial class CalamityPlayer : ModPlayer @@ -589,6 +593,8 @@ namespace CalamityMod.CalPlayer public int roverDriveTimer = 0; public int roverFrameCounter = 0; public int roverFrame = 0; + public int voidFrameCounter = 0; + public int voidFrame = 0; public bool rottenDogTooth = false; public bool angelicAlliance = false; public int angelicActivate = -1; @@ -922,6 +928,8 @@ namespace CalamityMod.CalPlayer public bool plaguebringerMK2 = false; public bool igneousExaltation = false; public bool coldDivinity = false; + public bool voidAura = false; + public bool voidAuraDamage = false; public bool youngDuke = false; public bool virili = false; public bool frostBlossom = false; @@ -1050,6 +1058,10 @@ namespace CalamityMod.CalPlayer public bool lecherousOrbEnchant = false; #endregion Calamitas Enchant Effects + #region Draw Effects + public FireParticleSet ProvidenceBurnEffectDrawer = new FireParticleSet(-1, 1, Color.Yellow, Color.Red * 1.2f, 10f, 0.65f); + #endregion Draw Effects + #endregion #region SavingAndLoading @@ -1990,6 +2002,8 @@ namespace CalamityMod.CalPlayer plaguebringerMK2 = false; igneousExaltation = false; coldDivinity = false; + voidAura = false; + voidAuraDamage = false; radiantResolution = false; virili = false; frostBlossom = false; @@ -3664,10 +3678,6 @@ namespace CalamityMod.CalPlayer { meleeSpeedMult += 0.05f; } - if (graxDefense) - { - meleeSpeedMult += 0.1f; - } if (yPower) { meleeSpeedMult += 0.05f; @@ -3774,8 +3784,7 @@ namespace CalamityMod.CalPlayer } if (player.beetleOffense && player.beetleOrbs > 0) { - player.meleeDamage -= 0.05f * player.beetleOrbs; - meleeSpeedMult -= 0.05f * player.beetleOrbs; + meleeSpeedMult -= 0.1f * player.beetleOrbs; } if (CalamityConfig.Instance.Proficiency) { @@ -3860,6 +3869,14 @@ namespace CalamityMod.CalPlayer } roverFrameCounter++; + int frames = 4; + if (voidFrameCounter >= 6) + { + voidFrameCounter = 0; + voidFrame = voidFrame == frames - 1 ? 0 : voidFrame + 1; + } + voidFrameCounter++; + for (int i = 0; i < player.dye.Length; i++) { if (player.dye[i].type == ModContent.ItemType()) diff --git a/CalPlayer/CalamityPlayerDrawEffects.cs b/CalPlayer/CalamityPlayerDrawEffects.cs index e62115cd7d..21e8f60e60 100644 --- a/CalPlayer/CalamityPlayerDrawEffects.cs +++ b/CalPlayer/CalamityPlayerDrawEffects.cs @@ -4,8 +4,8 @@ using CalamityMod.Items.Weapons.Magic; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.NPCs; using CalamityMod.Projectiles.Summon; -using CalamityMod.Projectiles.Typeless; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -17,6 +17,8 @@ using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; +using ProvidenceBoss = CalamityMod.NPCs.Providence.Providence; + namespace CalamityMod.CalPlayer { public class CalamityPlayerDrawEffects : ModPlayer @@ -71,8 +73,14 @@ namespace CalamityMod.CalPlayer { if (drawInfo.shadow != 0f) return; + Player drawPlayer = drawInfo.drawPlayer; CalamityPlayer modPlayer = drawPlayer.Calamity(); + + modPlayer.ProvidenceBurnEffectDrawer.DrawSet(drawPlayer.Bottom - Vector2.UnitY * 10f); + modPlayer.ProvidenceBurnEffectDrawer.SpawnAreaCompactness = 18f; + modPlayer.ProvidenceBurnEffectDrawer.RelativePower = 0.4f; + if (modPlayer.sirenIce) { Texture2D texture = ModContent.GetTexture("CalamityMod/ExtraTextures/IceShield"); @@ -405,6 +413,25 @@ namespace CalamityMod.CalPlayer } }); + public static readonly PlayerLayer ConcentratedVoidAura = new PlayerLayer("CalamityMod", "VoidAura", PlayerLayer.Skin, drawInfo => + { + Player drawPlayer = drawInfo.drawPlayer; + CalamityPlayer modPlayer = drawPlayer.Calamity(); + if (modPlayer.voidAura || modPlayer.voidAuraDamage) + { + Texture2D tex = ModContent.GetTexture("CalamityMod/ExtraTextures/VoidConcentrationAura"); + Vector2 drawPos = drawPlayer.Center - Main.screenPosition + new Vector2(0f, drawPlayer.gfxOffY); + drawPos.Y -= 9; + SpriteEffects spriteEffects = drawPlayer.direction != -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; //intentionally inverse due to giving more space for the player model without faffing about with the specific positioning + Rectangle frame = tex.Frame(1, 4, 0, modPlayer.voidFrame); + Vector2 origin = new Vector2(tex.Width / 2f, tex.Height / 2f / 4f); + float scale = 1.75f; + + DrawData data = new DrawData(tex, drawPos, frame, Color.White * 0.4f, 0f, origin, scale, spriteEffects, 0); + Main.playerDrawData.Add(data); + } + }); + public static readonly PlayerLayer RoverDriveShield = new PlayerLayer("CalamityMod", "RoverDrive", PlayerLayer.Skin, drawInfo => { Player drawPlayer = drawInfo.drawPlayer; @@ -644,6 +671,7 @@ namespace CalamityMod.CalPlayer list.Insert(drawTheStupidSign, ForbiddenCircletSign); } list.Add(ColdDivinityOverlay); + list.Add(ConcentratedVoidAura); list.Add(RoverDriveShield); list.Add(StratusSphereDrawing); list.Add(ProfanedMoonlightDyeEffects); diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 65fca76761..5f655edca0 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -19,6 +19,7 @@ using CalamityMod.Items.Potions; using CalamityMod.Items.Potions.Alcohol; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.Items.Weapons.Summon; using CalamityMod.NPCs; using CalamityMod.NPCs.AcidRain; using CalamityMod.NPCs.Astral; @@ -47,6 +48,8 @@ using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; +using ProvidenceBoss = CalamityMod.NPCs.Providence.Providence; + namespace CalamityMod.CalPlayer { public class CalamityPlayerMiscEffects @@ -144,48 +147,6 @@ namespace CalamityMod.CalPlayer #region Revengeance Effects private static void RevengeanceModeMiscEffects(Player player, CalamityPlayer modPlayer, Mod mod) { - if (CalamityGlobalNPC.holyBoss != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBoss].active) - { - if (Main.myPlayer == Main.npc[CalamityGlobalNPC.holyBoss].target) - { - float x = Vector2.Distance(Main.player[Main.npc[CalamityGlobalNPC.holyBoss].target].Center, Main.npc[CalamityGlobalNPC.holyBoss].Center); - float aiState = Main.npc[CalamityGlobalNPC.holyBoss].ai[0]; - float aiTimer = Main.npc[CalamityGlobalNPC.holyBoss].ai[3]; - - float baseDistance = 2800f; - float shorterFlameCocoonDistance = (CalamityWorld.death || CalamityWorld.malice || !Main.dayTime) ? 600f : CalamityWorld.revenge ? 400f : Main.expertMode ? 200f : 0f; - float shorterSpearCocoonDistance = (CalamityWorld.death || CalamityWorld.malice || !Main.dayTime) ? 1000f : CalamityWorld.revenge ? 650f : Main.expertMode ? 300f : 0f; - float shorterDistance = aiState == 2f ? shorterFlameCocoonDistance : shorterSpearCocoonDistance; - - bool guardianAlive = false; - if (CalamityGlobalNPC.holyBossAttacker != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBossAttacker].active) - guardianAlive = true; - } - if (CalamityGlobalNPC.holyBossDefender != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBossDefender].active) - guardianAlive = true; - } - if (CalamityGlobalNPC.holyBossHealer != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBossHealer].active) - guardianAlive = true; - } - - float maxDistance = guardianAlive ? baseDistance : (aiState == 2f || aiState == 5f) ? baseDistance - MathHelper.Lerp(0f, shorterDistance, MathHelper.Clamp(aiTimer / 120f, 0f, 1f)) : baseDistance; - float drawDarknessDistance = maxDistance - 400f; - float intensityScalar = MathHelper.Lerp(0f, 0.9f, MathHelper.Clamp((x - drawDarknessDistance) / 400f, 0f, 1f)); - - if (!Main.player[Main.npc[CalamityGlobalNPC.holyBoss].target].Calamity().ZoneAbyss && !Main.player[Main.npc[CalamityGlobalNPC.holyBoss].target].headcovered) - ScreenObstruction.screenObstruction = MathHelper.Lerp(ScreenObstruction.screenObstruction, 1f, intensityScalar); - } - } - } - if (CalamityWorld.revenge || CalamityWorld.malice) { // This effect is way too annoying during the fight so I disabled it - Fab @@ -659,6 +620,35 @@ namespace CalamityMod.CalPlayer } } + // Update the Providence Burn effect drawer if applicable. + float providenceBurnIntensity = 0f; + if (Main.npc.IndexInRange(CalamityGlobalNPC.holyBoss) && Main.npc[CalamityGlobalNPC.holyBoss].active) + providenceBurnIntensity = (Main.npc[CalamityGlobalNPC.holyBoss].modNPC as ProvidenceBoss).CalculateBurnIntensity(); + modPlayer.ProvidenceBurnEffectDrawer.ParticleSpawnRate = int.MaxValue; + + // If the burn intensity is great enough, cause the player to ignite into flames. + if (providenceBurnIntensity > 0.45f) + modPlayer.ProvidenceBurnEffectDrawer.ParticleSpawnRate = 1; + + // Otherwise, if the intensity is too weak, but still presernt, cause the player to release holy cinders. + else if (providenceBurnIntensity > 0f) + { + int cinderCount = (int)MathHelper.Lerp(1f, 4f, Utils.InverseLerp(0f, 0.45f, providenceBurnIntensity, true)); + for (int i = 0; i < cinderCount; i++) + { + if (!Main.rand.NextBool(3)) + continue; + + Dust holyCinder = Dust.NewDustDirect(player.position, player.width, player.head, (int)CalamityDusts.ProfanedFire); + holyCinder.velocity = Main.rand.NextVector2Circular(3.5f, 3.5f); + holyCinder.velocity.Y -= Main.rand.NextFloat(1f, 3f); + holyCinder.scale = Main.rand.NextFloat(1.15f, 1.45f); + holyCinder.noGravity = true; + } + } + + modPlayer.ProvidenceBurnEffectDrawer.Update(); + // Immunity to most debuffs if (modPlayer.invincible) { @@ -3395,7 +3385,7 @@ namespace CalamityMod.CalPlayer player.AddBuff(ModContent.BuffType(), 3600, true); if (player.ownedProjectileCounts[ModContent.ProjectileType()] < 2) - Projectile.NewProjectile(player.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(232f * player.MinionDamage()), 2f, Main.myPlayer, 0f, 0f); + Projectile.NewProjectile(player.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(AngryChickenStaff.Damage * player.MinionDamage()), 2f, Main.myPlayer, 0f, 0f); } } diff --git a/CalamityLists.cs b/CalamityLists.cs index 5dc134aac7..cfe953fbe5 100644 --- a/CalamityLists.cs +++ b/CalamityLists.cs @@ -409,6 +409,7 @@ namespace CalamityMod ProjectileID.LaserMachinegun, ProjectileID.ChargedBlasterCannon, ProjectileID.MedusaHead, + ProjectileType(), ProjectileType(), ProjectileType(), @@ -418,6 +419,7 @@ namespace CalamityMod ProjectileType(), ProjectileType(), ProjectileType(), + ProjectileType(), ProjectileType(), ProjectileType(), @@ -428,14 +430,20 @@ namespace CalamityMod ProjectileType(), ProjectileType(), - ProjectileType(), ProjectileType(), + ProjectileType(), ProjectileType(), ProjectileType(), ProjectileType(), ProjectileType(), ProjectileType(), + ProjectileType(), + ProjectileType(), + ProjectileType(), + ProjectileType(), + ProjectileType(), + //Some hostile boss projectiles ProjectileType(), ProjectileType(), @@ -2541,7 +2549,7 @@ namespace CalamityMod NPCType(), NPCType(), NPCType(), - NPCType() + NPCType() }; bossMinionList = new List() diff --git a/CalamityMod.cs b/CalamityMod.cs index 9457518ad2..0e3a9c4cda 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -1409,49 +1409,6 @@ namespace CalamityMod { // Apply the calculated darkness value for the local player. CalamityPlayer modPlayer = Main.LocalPlayer.Calamity(); - if (CalamityGlobalNPC.holyBoss != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBoss].active) - { - if (Main.myPlayer == Main.npc[CalamityGlobalNPC.holyBoss].target) - { - float x = Vector2.Distance(Main.player[Main.npc[CalamityGlobalNPC.holyBoss].target].Center, Main.npc[CalamityGlobalNPC.holyBoss].Center); - float aiState = Main.npc[CalamityGlobalNPC.holyBoss].ai[0]; - float aiTimer = Main.npc[CalamityGlobalNPC.holyBoss].ai[3]; - - float baseDistance = 2800f; - float shorterFlameCocoonDistance = (CalamityWorld.death || CalamityWorld.malice || !Main.dayTime) ? 600f : CalamityWorld.revenge ? 400f : Main.expertMode ? 200f : 0f; - float shorterSpearCocoonDistance = (CalamityWorld.death || CalamityWorld.malice || !Main.dayTime) ? 1000f : CalamityWorld.revenge ? 650f : Main.expertMode ? 300f : 0f; - float shorterDistance = aiState == 2f ? shorterFlameCocoonDistance : shorterSpearCocoonDistance; - - bool guardianAlive = false; - if (CalamityGlobalNPC.holyBossAttacker != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBossAttacker].active) - guardianAlive = true; - } - if (CalamityGlobalNPC.holyBossDefender != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBossDefender].active) - guardianAlive = true; - } - if (CalamityGlobalNPC.holyBossHealer != -1) - { - if (Main.npc[CalamityGlobalNPC.holyBossHealer].active) - guardianAlive = true; - } - - float maxDistance = guardianAlive ? baseDistance : (aiState == 2f || aiState == 5f) ? baseDistance - MathHelper.Lerp(0f, shorterDistance, MathHelper.Clamp(aiTimer / 120f, 0f, 1f)) : baseDistance; - float drawDarknessDistance = maxDistance - 400f; - float intensityScalar = MathHelper.Lerp(0f, 0.9f, MathHelper.Clamp((x - drawDarknessDistance) / 400f, 0f, 1f)); - scale -= intensityScalar; - - // Return to prevent running other darkness code - return; - } - } - } - float darkRatio = MathHelper.Clamp(modPlayer.caveDarkness, 0f, 1f); if (modPlayer.ZoneAbyss) diff --git a/Effects/BordernadoFire.xnb b/Effects/BordernadoFire.xnb index 2d0ac3b0dc..7dff3c4fba 100644 Binary files a/Effects/BordernadoFire.xnb and b/Effects/BordernadoFire.xnb differ diff --git a/Effects/Dyes/AstralBlueDyeShader.fx b/Effects/Dyes/AstralBlueDyeShader.fx new file mode 100644 index 0000000000..3373d2db78 --- /dev/null +++ b/Effects/Dyes/AstralBlueDyeShader.fx @@ -0,0 +1,29 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + float interval = cos(uTime * 7 + coords.x * 4) / 2 + 0.5; + float4 returnColor = float4(lerp(uColor, uSecondaryColor, interval), 1); // Fade between two colors depending on the time and x position on the texture in a 0-1 cosine linear interpolation. The color can vary. + return returnColor * color; // And multiply by the original color to give it a blend effect. +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/AstralOrangeDyeShader.fx b/Effects/Dyes/AstralOrangeDyeShader.fx new file mode 100644 index 0000000000..d818ed01a9 --- /dev/null +++ b/Effects/Dyes/AstralOrangeDyeShader.fx @@ -0,0 +1,31 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float interval = (cos((uTime - 0.5) * 17 + frameY * 8) / 2 + 0.5); + float4 returnColor = float4(lerp(uColor, uSecondaryColor, interval), 1); // One again, use a cosine lerp based on position and time, but this time, with the Y position. + + return returnColor * color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/AstralSwirlDyeShader.fx b/Effects/Dyes/AstralSwirlDyeShader.fx new file mode 100644 index 0000000000..47674dfa44 --- /dev/null +++ b/Effects/Dyes/AstralSwirlDyeShader.fx @@ -0,0 +1,55 @@ +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; + +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 : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float interval = (cos(uTime * 2.2 + frameY * coords.x * 1.55) * 0.5 + 0.5) * 0.6 + 0.2; // A complex function that works based on the X and Y coords with a 0.2-0.8 range. + float brightness = 1.35; + float3 returnColor = uColor; + // Rotate the colors around and adjust the brightness. + for (int i = 0; i < 4; i++) + { + float2 positionAt = float2(interval, 1 - interval); + positionAt = (RotatedBy(float2(cos(uTime * 1.7 + i / 4 * 6.283), cos(uTime * 1.9 + i / 4 * 6.283)), uTime + i / 4 * 6.283) * 0.5 + 0.5) - positionAt; + float dist = distance(coords, positionAt); + if (dist < 0.35) + { + float inverseDistanceRatio = 1 - dist / 0.35; + returnColor = lerp(uColor, uSecondaryColor, inverseDistanceRatio); + brightness = lerp(1.35, 1.7, inverseDistanceRatio); + } + } + + if (frameY > 0.5) + { + returnColor = lerp(returnColor, uSecondaryColor, (frameY - 0.5) * 3); + } + + return float4(returnColor, 1) * color * brightness; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/BloodflareDyeShader.fx b/Effects/Dyes/BloodflareDyeShader.fx new file mode 100644 index 0000000000..8feb36ca88 --- /dev/null +++ b/Effects/Dyes/BloodflareDyeShader.fx @@ -0,0 +1,44 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float4 pixelBelow = tex2D(uImage0, coords); + float4 noiseColor = tex2D(uImage1, float2(coords.x, frac(frameY - uTime * 0.67)) * 0.5) * 1.5; + float verticalFlowMovement = (sin(coords.x * 14.71 + frameY * 13.5 - uTime * 5.6) * 0.5 + 0.5) * noiseColor.r; + if (pixelBelow.a == 0 && frameY < 0.96) + coords.y = saturate(coords.y + verticalFlowMovement / uSourceRect.w / 17); + float4 color = tex2D(uImage0, coords); + + // Prepare the dark outlines. + float outlineFade = pow(1 - (color.r + color.g + color.b) / 3, 2); + color = lerp(color, float4(uColor, 1), outlineFade) * color.a; + + // Prepare the bright in-lines. + color = lerp(color, float4(uSecondaryColor, 1), saturate(1 - outlineFade) * 0.8) * color.a; + + // Handle red fades based on noise. + color = lerp(color, float4(1, 0, 0, 1), pow(noiseColor.r, 3) * 0.3 + verticalFlowMovement * 0.3 + 0.16) * color.a; + + return color * (1 + (1 - outlineFade) * 0.25); +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/BloodflareDyeShader.xnb b/Effects/Dyes/BloodflareDyeShader.xnb new file mode 100644 index 0000000000..534222798e Binary files /dev/null and b/Effects/Dyes/BloodflareDyeShader.xnb differ diff --git a/Effects/Dyes/CalamitousDyeShader.fx b/Effects/Dyes/CalamitousDyeShader.fx new file mode 100644 index 0000000000..8b1c719929 --- /dev/null +++ b/Effects/Dyes/CalamitousDyeShader.fx @@ -0,0 +1,43 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float4 noiseColor = tex2D(uImage1, float2(coords.x, frameY)); + float4 color = tex2D(uImage0, coords); + float3 blendColor = lerp(uColor, uSecondaryColor, sqrt(frameY)); + float blendFactor = (cos(uTime * 9 + coords.x * 18) * 0.5 + 0.5) * 0.5; + + // Allow the fade to pulse upward based on how far up the pixel is. + blendFactor += (cos(uTime * -13 - frameY * 7.1)) * 0.5; + float brightness = blendFactor * 0.35 + noiseColor.r * 0.35; + + // Cause the effects to taper off at the bottom of the sprite. + if (frameY < 0.2) + { + brightness *= frameY / 0.2; + blendFactor *= frameY / 0.2; + } + float4 colorBlendMultiplier = lerp(float4(blendColor, 1), float4(1, 1, 1, 1), saturate(pow(blendFactor * 1.5, 2))); + return (lerp(color, float4(blendColor, 1), blendFactor * 0.5 + 0.2) * color.a) * colorBlendMultiplier * (1 + brightness); +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/CalamitousDyeShader.xnb b/Effects/Dyes/CalamitousDyeShader.xnb new file mode 100644 index 0000000000..4287b463b7 Binary files /dev/null and b/Effects/Dyes/CalamitousDyeShader.xnb differ diff --git a/Effects/Dyes/CeaselessDyeShader.fx b/Effects/Dyes/CeaselessDyeShader.fx new file mode 100644 index 0000000000..c0041ee41d --- /dev/null +++ b/Effects/Dyes/CeaselessDyeShader.fx @@ -0,0 +1,37 @@ +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 randomness(float2 uv) +{ + float noise = (frac(sin(dot(uv, float2(12.9898, 78.233) * 2.0)) * 43758.5453)); + return noise; +} + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + coords.x += randomness(uTime + frameY).x * 0.09 * (1 - frameY); // Add an X offset based on a noise function, giving a moon lord void-esque shader effect. + float4 color = tex2D(uImage0, coords); + float4 returnColor = color * 0.1; + returnColor.a = color.a; + return returnColor; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/CosmicFlameShader.fx b/Effects/Dyes/CosmicFlameShader.fx new file mode 100644 index 0000000000..c1dee78a4f --- /dev/null +++ b/Effects/Dyes/CosmicFlameShader.fx @@ -0,0 +1,49 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float2 swirlOffset = float2(sin(uTime * 0.96 + 1.754) * 0.31, sin(uTime * 0.96) * 0.16) * uSaturation; + float4 color = tex2D(uImage0, coords); + float4 noiseColor = tex2D(uImage1, frac(float2(coords.x, frameY + uTime * 0.36) + swirlOffset - uWorldPosition * 0.0006) * 0.26); + float4 flameColor = tex2D(uImage1, frac(float2(coords.x, frameY + uTime * 0.44)) * 0.1); + float brightnessFactor = noiseColor.r * 2; + + float normalizedDistanceFromCenter = distance(float2(coords.x, frameY), float2(0.5, 0.5)) * 2; + + // Cause "ring" fades based on distance. + float fadeToNormal = 1 - saturate((normalizedDistanceFromCenter - 0.67) / 0.3); + + // Cause noise-based stars to appear all across the sprite. + float3 starColor = lerp(uColor * 1.1, uSecondaryColor, sin(brightnessFactor * 6.283) * 0.5 + 0.5); + + // Prepare a dull, bluish-greyish background across the sprite for contrast. + color = lerp(color, float4(43 / 255.0, 58 / 255.0, 92 / 255.0, 1) * color.a, fadeToNormal * 0.45); + + // Fade to the secondary color based on the flame color map. This helps the overall result more vibrant. + color = lerp(color, float4(uSecondaryColor, 1) * color.a, flameColor.r * 0.5); + + // And create stars based on a noise texture that rise upward. + color = lerp(color, float4(starColor, 1) * color.a, fadeToNormal * pow(brightnessFactor, 6) * 0.15); + return color * (1 + brightnessFactor); +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/CosmicFlameShader.xnb b/Effects/Dyes/CosmicFlameShader.xnb new file mode 100644 index 0000000000..a526ff1430 Binary files /dev/null and b/Effects/Dyes/CosmicFlameShader.xnb differ diff --git a/Effects/Dyes/CryonicDyeShader.fx b/Effects/Dyes/CryonicDyeShader.fx new file mode 100644 index 0000000000..3a108d42f8 --- /dev/null +++ b/Effects/Dyes/CryonicDyeShader.fx @@ -0,0 +1,42 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float4 noiseColor = tex2D(uImage1, float2(frac(coords.x + uTime * 0.1), frameY)); + float4 color = tex2D(uImage0, coords); + + // Cause sharp brightness increases based on a perlin noise map. + // This causes icy, crystaline structures to appear. + float brightness = pow((noiseColor.r + noiseColor.g + noiseColor.b) / 3, 3) * 3; + float normalizedDistanceFromCenter = distance(float2(coords.x, frameY), float2(0.5, 0.5)) * 2; + + // Cause "ring" fades based on distance. + float fadeToSecondaryColor = pow(sin(uTime * -1.56 + normalizedDistanceFromCenter * 3.141), 6); + + // This fades out at the ends of the sprite. + if (normalizedDistanceFromCenter > 0.7) + fadeToSecondaryColor *= saturate(1 - (normalizedDistanceFromCenter - 0.7) / 0.2); + float4 endFadeColor = lerp(float4(uColor, 1), float4(uSecondaryColor, 1), 0.5); + return (lerp(color, endFadeColor, 0.3 + fadeToSecondaryColor * 0.6) * color.a) * (1 + brightness); +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/CryonicDyeShader.xnb b/Effects/Dyes/CryonicDyeShader.xnb new file mode 100644 index 0000000000..93b9009e6a Binary files /dev/null and b/Effects/Dyes/CryonicDyeShader.xnb differ diff --git a/Effects/Dyes/DefiledFlameDyeShader.fx b/Effects/Dyes/DefiledFlameDyeShader.fx new file mode 100644 index 0000000000..8d7f5639b6 --- /dev/null +++ b/Effects/Dyes/DefiledFlameDyeShader.fx @@ -0,0 +1,44 @@ +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; + +static float Variance = 0.4f; +static float MinBrightness = 1.5f; +static float MaxBrightness = 2.5f; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + + float4 noiseColor = tex2D(uImage1, coords); + + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float interval = cos(uTime * 7 + frameY * 6) * 0.5 + 0.5; + + float brightness = pow((interval + sin(uTime + coords.x * uTime * frameY * cos(uTime)) * 0.5 + 0.5) * 0.5, 2); // Force the brightness to rise to 1 more quickly + brightness = brightness * (MaxBrightness - MinBrightness) + MinBrightness; // And bring it to a specified range + + float4 colorMap = float4(lerp(uColor, uSecondaryColor, interval) + noiseColor.rgb * 0.4, 1); + colorMap.rgb *= brightness; + colorMap.rgb = colorMap.rgb - colorMap.rgb % Variance; // Slice the return color map to make pixels appear less varied and more extreme + + return colorMap * color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/DragonSoulDyeShader.fx b/Effects/Dyes/DragonSoulDyeShader.fx new file mode 100644 index 0000000000..80cb2729fd --- /dev/null +++ b/Effects/Dyes/DragonSoulDyeShader.fx @@ -0,0 +1,41 @@ +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; + +static float3 colors[4] = +{ + float3(195, 50, 37) / 255.0, + float3(252, 155, 0) / 255.0, + float3(255, 235, 195) / 255.0, + float3(252, 155, 0) / 255.0 +}; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float interval = (cos(coords.x * 6.283 + uTime * 3.141) * 2 + sin(uTime * 7 + frameY * 6)) * 0.125 + 0.5; + interval *= 2; // Exaggerate the interval. + float4 returnColor = float4(lerp(colors[floor(interval) % 4], colors[floor(interval + 1) % 4], interval % 1), 1); // But clamp it to a 0-1 range. + + return returnColor * color * 1.95; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/ElementalDyeShader.fx b/Effects/Dyes/ElementalDyeShader.fx new file mode 100644 index 0000000000..0303576ddb --- /dev/null +++ b/Effects/Dyes/ElementalDyeShader.fx @@ -0,0 +1,44 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; + + float time = (sin(uTime + coords.x * cos(uTime + 3.141 * coords.x) + 1.5707 * frameY) * 0.5 + 0.5) * 6; + float timeFloored = floor(time); + + float3 colors[6] = + { + float3(241, 149, 49), // Solar + float3(88, 201, 169), // Vortex + float3(102, 200, 249), // Stardust + float3(226, 76, 239) * 0.7, // Nebula + float3(102, 200, 249), // Stardust + float3(88, 201, 169) // Vortex + }; + + // Use a multi-lerp to fade between colors and then base them on a trig-based time step. + color.rgb *= lerp(colors[timeFloored] / 255.0, colors[(timeFloored + 1) % 6] / 255.0, time / 6) * 1.6; + return color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/EndothermicDyeShader.fx b/Effects/Dyes/EndothermicDyeShader.fx new file mode 100644 index 0000000000..75de6d38ef --- /dev/null +++ b/Effects/Dyes/EndothermicDyeShader.fx @@ -0,0 +1,33 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + + // Saturate basically clamps to a 0-1 range. Basically, the further away from the center the closer the color becomes to the secondary color. + float3 idealColor = lerp(uColor, uSecondaryColor, saturate(distance(float2(coords.x, frameY), (0.5, 0.5)))); + float4 color = tex2D(uImage0, coords); + float luminosity = (color.r + color.g + color.b) / 3; + color.rgb = luminosity * idealColor * 1.3; // Average out the colors. + return color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/NightmareDyeShader.fx b/Effects/Dyes/NightmareDyeShader.fx new file mode 100644 index 0000000000..8d14568a57 --- /dev/null +++ b/Effects/Dyes/NightmareDyeShader.fx @@ -0,0 +1,36 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float3 idealColor = uColor; + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float depth = sin(uTime * 3 + coords.x * 2) * 0.05; + if (frameY < 0.425 + depth) + { + idealColor = lerp(uColor, uSecondaryColor, 1 - frameY / (0.425 + depth)); + } + float4 color = tex2D(uImage0, coords); + float luminosity = (color.r + color.g + color.b) / 3; + color.rgb = luminosity * idealColor * 1.6; // Average out the colors. + return color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/PhantoplasmDyeShader.fx b/Effects/Dyes/PhantoplasmDyeShader.fx new file mode 100644 index 0000000000..02a09722ae --- /dev/null +++ b/Effects/Dyes/PhantoplasmDyeShader.fx @@ -0,0 +1,42 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float4 noiseColor = tex2D(uImage1, float2(coords.x, frac(frameY + uTime * 0.7))); + float4 color = tex2D(uImage0, coords); + float normalizedDistanceFromCenter = distance(float2(coords.x, frameY), float2(0.5, 0.5)) * 2; + + // Cause "ring" pulses based on distance. + float fadeToSecondaryColor = pow(sin(uTime * -2.56 + normalizedDistanceFromCenter * 2), 4); + + // This fades out at the ends of the sprite. + if (normalizedDistanceFromCenter > 0.7) + fadeToSecondaryColor *= saturate(1 - (normalizedDistanceFromCenter - 0.7) / 0.37 + sin(coords.x * coords.y * 12) * 0.1); + float4 endFadeColor = float4(lerp(uColor, uSecondaryColor, fadeToSecondaryColor * 0.74 + noiseColor.g * 0.13), 1); + + float4 blendedColor = (color + endFadeColor) * 0.5 - 0.05; + blendedColor *= 1.4; + blendedColor.a = 1; + return blendedColor * color.a * (1 + lerp(0.07, 0.3, fadeToSecondaryColor) + noiseColor.g * 0.1); +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/PhantoplasmDyeShader.xnb b/Effects/Dyes/PhantoplasmDyeShader.xnb new file mode 100644 index 0000000000..d1d075c350 Binary files /dev/null and b/Effects/Dyes/PhantoplasmDyeShader.xnb differ diff --git a/Effects/Dyes/ProfanedFlameDyeShader.fx b/Effects/Dyes/ProfanedFlameDyeShader.fx new file mode 100644 index 0000000000..f1964bc244 --- /dev/null +++ b/Effects/Dyes/ProfanedFlameDyeShader.fx @@ -0,0 +1,44 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float4 color = tex2D(uImage0, coords); + + // Read the fade map as a streak. + float4 fadeMapColor = tex2D(uImage1, float2(frac(coords.x * 0.18 + cos(uTime * 0.9) * 0.021), frac(frameY * 0.32 + uTime * 0.2))); + fadeMapColor.r *= pow(coords.x, 0.2); + + float opacity = lerp(1.05, 1.95, fadeMapColor.r); + opacity *= fadeMapColor.r + 1; + opacity *= lerp(0.4, 1.1, fadeMapColor.r); + + float3 transformColor = lerp(uColor, uSecondaryColor, fadeMapColor.r); + float orangeFade = 1 - saturate((frameY - 0.08) / 0.74); + opacity += (1 - orangeFade) * 0.6; + + transformColor = lerp(transformColor, float3(206 / 255, 116 / 255, 59 / 255), orangeFade); + color.rgb = lerp(color.rgb, transformColor, fadeMapColor.r); + opacity *= color.a; + return color * opacity; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/ProfanedFlameDyeShader.xnb b/Effects/Dyes/ProfanedFlameDyeShader.xnb new file mode 100644 index 0000000000..8121fa4bfa Binary files /dev/null and b/Effects/Dyes/ProfanedFlameDyeShader.xnb differ diff --git a/Effects/Dyes/ProfanedMoonlightDye.fx b/Effects/Dyes/ProfanedMoonlightDye.fx new file mode 100644 index 0000000000..70dc4c8cb9 --- /dev/null +++ b/Effects/Dyes/ProfanedMoonlightDye.fx @@ -0,0 +1,28 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 returnColor = tex2D(uImage0, coords); + returnColor.rgb *= uColor * ((cos(uTime) * 0.5 + 0.5) * 0.3 + 1.3); + return returnColor; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/ReaverDyeShader.fx b/Effects/Dyes/ReaverDyeShader.fx new file mode 100644 index 0000000000..283a3267b2 --- /dev/null +++ b/Effects/Dyes/ReaverDyeShader.fx @@ -0,0 +1,34 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + float luminosity = (color.r + color.g + color.b) / 3; + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + + float yMultiplier = sqrt(frameY) * (sin(frameY * 2 + uTime * 1.4) + 1) * 0.5; + + color.rgb *= ((coords.x * uColor * (1 - yMultiplier) * 1.4) + ((1 - coords.x) * uSecondaryColor * yMultiplier * 1.7)) * luminosity * 2.1; + color.rgb *= clamp(1.6 * saturate(distance((0.5, 0.5), coords)), 0.8, 1.6); // Intensify the colors based on how far they are from the center of the sprite. + return color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/ShadowspecDyeShader.fx b/Effects/Dyes/ShadowspecDyeShader.fx new file mode 100644 index 0000000000..dfa0d8c88b --- /dev/null +++ b/Effects/Dyes/ShadowspecDyeShader.fx @@ -0,0 +1,47 @@ +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; + +float2 RotatedBy(float theta, float x, float y) +{ + return float2(x * cos(theta) + y * sin(theta), x * sin(theta) - y * cos(theta)); +} +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float sineTime = sin(uTime); // Saved so that I don't have the compute this multiple times. Shaders have a limited number of mathematical instructions you can use - 64. + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + + float2 modifiedCoords = coords; + float4 color = tex2D(uImage0, coords); + + modifiedCoords = RotatedBy(uTime + 0.4 * sineTime, modifiedCoords.y, modifiedCoords.x); + float4 noiseColor = tex2D(uImage1, modifiedCoords); + + float xMultiplier = cos(coords.x * 2.3 + uTime) + 1; + float yMultiplier = sin(frameY * 2 + uTime * 1.4) + 1; + + float interpolationValue = saturate(xMultiplier * yMultiplier) * 0.7 + 0.3; // Range of 0-1. Depends on the current coordinates and the time. + + color.rgb *= 0.2 + pow(noiseColor.rgb, 3); // Squash the color to the upper and lower bounds and add a bit of lightness to it. + color.rgb *= lerp(uColor, uSecondaryColor, interpolationValue); // Blend with the secondary color. + color.rgb *= 1.7 + (sineTime * 0.5 + 1.5) * interpolationValue; // Range of 1.7 to 3.7, can cause certain spots to become very bright. + return color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/StratusDyeShader.fx b/Effects/Dyes/StratusDyeShader.fx new file mode 100644 index 0000000000..db0b8f5dfe --- /dev/null +++ b/Effects/Dyes/StratusDyeShader.fx @@ -0,0 +1,45 @@ +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; + +static float xAdditiveMax = 0.035; +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + float sineTime = sin(uTime); // Saved so that I don't have the compute this multiple times. Shaders have a limited number of mathematical instructions you can use - 64. + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + + float2 modifiedCoords = coords; + modifiedCoords.x += cos(uTime + frameY) * 0.5 + 0.5; // Cause the effect to sway around a bit with time. + + float4 noiseColor = tex2D(uImage1, frac(modifiedCoords)); + + float xMultiplier = cos(coords.x * 2.3 + uTime * 1.15) + 0.5; + float yMultiplier = (sin(frameY * 2 + uTime * 1.4) + 1) * 0.5; + + color.rgb *= lerp(uColor, uSecondaryColor, saturate(xMultiplier * yMultiplier * 1.6)); + if (noiseColor.r > 0.55 + sineTime * 0.025) + { + color.rgb *= 1.6; // Sometimes give light "patches" depending on the swaying noise image. + } + color.rgb *= 1.6 + (sineTime * 0.5 + 1.5) * ((frameY + coords.x) - 1) * 2; // Brighten the shader over time. + return color; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/FabstaffStreak.xnb b/Effects/FabstaffStreak.xnb index 45b95d5d3f..9bf2e57eaa 100644 Binary files a/Effects/FabstaffStreak.xnb and b/Effects/FabstaffStreak.xnb differ diff --git a/Effects/FadedUVMapStreak.xnb b/Effects/FadedUVMapStreak.xnb index fbc7a110ec..0ccc66632f 100644 Binary files a/Effects/FadedUVMapStreak.xnb and b/Effects/FadedUVMapStreak.xnb differ diff --git a/Effects/FadingSolidTrail.xnb b/Effects/FadingSolidTrail.xnb index 0d83a614e8..1f44e50a54 100644 Binary files a/Effects/FadingSolidTrail.xnb and b/Effects/FadingSolidTrail.xnb differ diff --git a/Effects/PhaseslayerRipShader.xnb b/Effects/PhaseslayerRipShader.xnb index 02b74566ba..e51ba52a94 100644 Binary files a/Effects/PhaseslayerRipShader.xnb and b/Effects/PhaseslayerRipShader.xnb differ diff --git a/Effects/PrismCrystalStreak.xnb b/Effects/PrismCrystalStreak.xnb index 43f330f1f6..b0aed6e0a2 100644 Binary files a/Effects/PrismCrystalStreak.xnb and b/Effects/PrismCrystalStreak.xnb differ diff --git a/Effects/SCalMouseShader.xnb b/Effects/SCalMouseShader.xnb index a6f0b32b7f..4c8990de6b 100644 Binary files a/Effects/SCalMouseShader.xnb and b/Effects/SCalMouseShader.xnb differ diff --git a/Effects/ScarletDevilStreak.xnb b/Effects/ScarletDevilStreak.xnb index b68ab8631d..20fda783a8 100644 Binary files a/Effects/ScarletDevilStreak.xnb and b/Effects/ScarletDevilStreak.xnb differ diff --git a/Effects/SupremeShieldShader.xnb b/Effects/SupremeShieldShader.xnb index 63dcfed3e6..5a46acbb23 100644 Binary files a/Effects/SupremeShieldShader.xnb and b/Effects/SupremeShieldShader.xnb differ diff --git a/Events/AcidRainEvent.cs b/Events/AcidRainEvent.cs index c5b5a8489a..89c80067e8 100644 --- a/Events/AcidRainEvent.cs +++ b/Events/AcidRainEvent.cs @@ -1,5 +1,6 @@ using CalamityMod.NPCs.AcidRain; using CalamityMod.NPCs.OldDuke; +using CalamityMod.Projectiles.Boss; using CalamityMod.World; using Microsoft.Xna.Framework; using System; @@ -176,6 +177,100 @@ namespace CalamityMod.Events BroadcastEventText("Mods.CalamityMod.AcidRainStart"); // A toxic downpour falls over the wasteland seas! } + /// + /// Handles updating the entire invasion, including more misc operations, such as summoning OD's tornado. + /// + public static void Update() + { + CalamityWorld.timeSinceAcidRainKill++; + CalamityWorld.timeSinceAcidStarted++; + + // If enough time has passed, and no enemy has been killed, end the invasion early. + // The player almost certainly does not want to deal with it. + if (CalamityWorld.timeSinceAcidRainKill >= AcidRainEvent.InvasionNoKillPersistTime) + { + CalamityWorld.acidRainPoints = 0; + CalamityWorld.triedToSummonOldDuke = false; + AcidRainEvent.UpdateInvasion(false); + } + if (!CalamityWorld.startAcidicDownpour) + { + int sulphSeaWidth = SulphurousSea.BiomeWidth; + for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + { + // A variable named "player" already exists above, which retrieves the player who is closest to the map center. + Player player2 = Main.player[playerIndex]; + if (player2.active) + { + // An artificial biome can be made, and therefore, the event could be started by an artificial biome. + // While fighting the event in an artificial biome is not bad, having it be started by a patch of Sulphurous Sand + // would definitely be strange. + // Because of this, this code is executed based on if the player is in the sea (based on tile count) AND position relative to the naturally generated sea. + bool inNaturalSeaPosition = (player2.Center.X <= (sulphSeaWidth + 60f) * 16f && CalamityWorld.abyssSide) || (player2.Center.X >= (Main.maxTilesX - (sulphSeaWidth + 60f)) * 16f && !CalamityWorld.abyssSide); + if (inNaturalSeaPosition && player2.Calamity().ZoneSulphur) + { + // Makes rain pour at its maximum intensity (but only after an idiot meanders into the Sulphurous Sea) + // You'll never catch me, Fabs, Not when I shift into MAXIMUM OVERDRIVE!! + CalamityWorld.startAcidicDownpour = true; + CalamityNetcode.SyncWorld(); + break; + } + } + } + } + + // Stop the rain if the Old Duke is present for visibility during the fight. + if (Main.raining && NPC.AnyNPCs(ModContent.NPCType())) + { + Main.raining = false; + CalamityNetcode.SyncWorld(); + } + + // If the rain stops for whatever reason, end the invasion. + // This is primarily done for compatibility, so that if another mod wants to manipulate the weather, + // they can without having to deal with endless rain. + if (!Main.raining && !NPC.AnyNPCs(ModContent.NPCType()) && CalamityWorld.timeSinceAcidStarted > 20) + { + CalamityWorld.acidRainPoints = 0; + CalamityWorld.triedToSummonOldDuke = false; + UpdateInvasion(false); + } + else if (CalamityWorld.timeSinceAcidStarted < 20) + { + Main.raining = true; + Main.cloudBGActive = 1f; + Main.numCloudsTemp = Main.cloudLimit; + Main.numClouds = Main.numCloudsTemp; + Main.windSpeedTemp = 0.72f; + Main.windSpeedSet = Main.windSpeedTemp; + Main.weatherCounter = 60 * 60 * 10; // 10 minutes of rain. Remember, once the rain goes away, so does the invasion. + Main.rainTime = Main.weatherCounter; + Main.maxRaining = 0.89f; + } + + // Summon Old Duke tornado post-Polter as needed + if (CalamityWorld.downedPolterghast && CalamityWorld.acidRainPoints == 1) + { + if (!NPC.AnyNPCs(ModContent.NPCType()) && + CalamityUtils.CountProjectiles(ModContent.ProjectileType()) <= 0) + { + if (CalamityWorld.triedToSummonOldDuke) + { + CalamityWorld.acidRainPoints = 0; + CalamityWorld.triedToSummonOldDuke = false; + UpdateInvasion(false); + } + else + { + int playerClosestToAbyss = Player.FindClosest(new Vector2(CalamityWorld.abyssSide ? 0 : Main.maxTilesX * 16, (int)Main.worldSurface), 0, 0); + Player closestToAbyss = Main.player[playerClosestToAbyss]; + if (Main.netMode != NetmodeID.MultiplayerClient && Math.Abs(closestToAbyss.Center.X - (CalamityWorld.abyssSide ? 0 : Main.maxTilesX * 16)) <= 12000f) + Projectile.NewProjectile(closestToAbyss.Center + Vector2.UnitY * 160f, Vector2.Zero, ModContent.ProjectileType(), 120, 8f, Main.myPlayer); + } + } + } + } + /// /// Updates the invasion, checking to see if it has ended. /// @@ -236,7 +331,56 @@ namespace CalamityMod.Events } } - internal static void OnEnemyKill(NPC npc) + public static void TryToStartEventNaturally() + { + // Attempt to start the acid rain at the 4:29AM. + // This does not happen if a player has the Broken Water Filter in use. + bool increasedEventChance = !CalamityWorld.downedEoCAcidRain || (!CalamityWorld.downedAquaticScourgeAcidRain && CalamityWorld.downedAquaticScourge) || (!CalamityWorld.downedBoomerDuke && CalamityWorld.downedPolterghast); + if (Main.time == 32399 && !Main.dayTime && Main.rand.NextBool(increasedEventChance ? 3 : 300)) + { + bool shouldNotStartEvent = false; + for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + { + if (!Main.player[playerIndex].active) + continue; + if (Main.player[playerIndex].Calamity().noStupidNaturalARSpawns) + { + shouldNotStartEvent = true; + break; + } + } + if (!shouldNotStartEvent) + { + TryStartEvent(); + CalamityNetcode.SyncWorld(); + } + } + + // Attempt to force an Acid Rain immediately after the EoC is dead when someone wanders to the sea. + if (NPC.downedBoss1 && !CalamityWorld.downedEoCAcidRain && !CalamityWorld.forcedRainAlready) + { + for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + { + if (Main.player[playerIndex].active && Main.player[playerIndex].Calamity().ZoneSulphur) + { + CalamityWorld.forcedRainAlready = true; + TryStartEvent(); + CalamityNetcode.SyncWorld(); + } + } + } + + if (CalamityWorld.forceRainTimer == 1) + { + TryStartEvent(); + CalamityNetcode.SyncWorld(); + } + + if (CalamityWorld.forceRainTimer > 0) + CalamityWorld.forceRainTimer--; + } + + public static void OnEnemyKill(NPC npc) { Dictionary possibleEnemies = PossibleEnemiesPreHM; diff --git a/Events/BossRushEvent.cs b/Events/BossRushEvent.cs index c0e7bba298..bc8afd12e8 100644 --- a/Events/BossRushEvent.cs +++ b/Events/BossRushEvent.cs @@ -295,10 +295,25 @@ namespace CalamityMod.Events { if (!BossRushActive) return; + // Prevent Moon Lord from spawning naturally if (NPC.MoonLordCountdown > 0) - { NPC.MoonLordCountdown = 0; + + // Handle projectile clearing. + if (CalamityWorld.bossRushHostileProjKillCounter > 0) + { + CalamityWorld.bossRushHostileProjKillCounter--; + if (CalamityWorld.bossRushHostileProjKillCounter == 1) + CalamityUtils.KillAllHostileProjectiles(); + + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.BRHostileProjKillSync); + netMessage.Write(CalamityWorld.bossRushHostileProjKillCounter); + netMessage.Send(); + } } } @@ -345,19 +360,18 @@ namespace CalamityMod.Events // Change time as necessary. if (Bosses[BossRushStage].ToChangeTimeTo != TimeChangeContext.None) - CalamityWorld.ChangeTime(Bosses[BossRushStage].ToChangeTimeTo == TimeChangeContext.Day); + CalamityUtils.ChangeTime(Bosses[BossRushStage].ToChangeTimeTo == TimeChangeContext.Day); // Play the typical boss roar sound. if (!Bosses[BossRushStage].UsesSpecialSound) - { Main.PlaySound(SoundID.Roar, Main.player[ClosestPlayerToWorldCenter].position, 0); - } // And spawn the boss. Bosses[BossRushStage].SpawnContext.Invoke(CurrentlyFoughtBoss); } } } + #endregion #region On Boss Kill diff --git a/ExtraTextures/CalamitasCinder.png b/ExtraTextures/CalamitasCinder.png new file mode 100644 index 0000000000..191dd23b73 Binary files /dev/null and b/ExtraTextures/CalamitasCinder.png differ diff --git a/ExtraTextures/VoidConcentrationAura.png b/ExtraTextures/VoidConcentrationAura.png new file mode 100644 index 0000000000..2b5d2fb66c Binary files /dev/null and b/ExtraTextures/VoidConcentrationAura.png differ diff --git a/Gores/Ares/AresArm_Gore1.png b/Gores/Ares/AresArm_Gore1.png new file mode 100644 index 0000000000..7aa6065a49 Binary files /dev/null and b/Gores/Ares/AresArm_Gore1.png differ diff --git a/Gores/Ares/AresArm_Gore2.png b/Gores/Ares/AresArm_Gore2.png new file mode 100644 index 0000000000..60a6c919de Binary files /dev/null and b/Gores/Ares/AresArm_Gore2.png differ diff --git a/Gores/Ares/AresArm_Gore3.png b/Gores/Ares/AresArm_Gore3.png new file mode 100644 index 0000000000..2fbe603cdc Binary files /dev/null and b/Gores/Ares/AresArm_Gore3.png differ diff --git a/Gores/Ares/AresBody_Gore1.png b/Gores/Ares/AresBody_Gore1.png new file mode 100644 index 0000000000..35c229b25e Binary files /dev/null and b/Gores/Ares/AresBody_Gore1.png differ diff --git a/Gores/Ares/AresBody_Gore2.png b/Gores/Ares/AresBody_Gore2.png new file mode 100644 index 0000000000..391c777385 Binary files /dev/null and b/Gores/Ares/AresBody_Gore2.png differ diff --git a/Gores/Ares/AresBody_Gore3.png b/Gores/Ares/AresBody_Gore3.png new file mode 100644 index 0000000000..03788a2d76 Binary files /dev/null and b/Gores/Ares/AresBody_Gore3.png differ diff --git a/Gores/Ares/AresBody_Gore4.png b/Gores/Ares/AresBody_Gore4.png new file mode 100644 index 0000000000..42f09bf434 Binary files /dev/null and b/Gores/Ares/AresBody_Gore4.png differ diff --git a/Gores/Ares/AresBody_Gore5.png b/Gores/Ares/AresBody_Gore5.png new file mode 100644 index 0000000000..e18eb5a29a Binary files /dev/null and b/Gores/Ares/AresBody_Gore5.png differ diff --git a/Gores/Ares/AresBody_Gore6.png b/Gores/Ares/AresBody_Gore6.png new file mode 100644 index 0000000000..f699679217 Binary files /dev/null and b/Gores/Ares/AresBody_Gore6.png differ diff --git a/Gores/Ares/AresBody_Gore7.png b/Gores/Ares/AresBody_Gore7.png new file mode 100644 index 0000000000..e9a8d20201 Binary files /dev/null and b/Gores/Ares/AresBody_Gore7.png differ diff --git a/Gores/Ares/AresGaussNuke_Gore1.png b/Gores/Ares/AresGaussNuke_Gore1.png new file mode 100644 index 0000000000..0a1bbb2327 Binary files /dev/null and b/Gores/Ares/AresGaussNuke_Gore1.png differ diff --git a/Gores/Ares/AresGaussNuke_Gore2.png b/Gores/Ares/AresGaussNuke_Gore2.png new file mode 100644 index 0000000000..9e45c93b48 Binary files /dev/null and b/Gores/Ares/AresGaussNuke_Gore2.png differ diff --git a/Gores/Ares/AresGaussNuke_Gore3.png b/Gores/Ares/AresGaussNuke_Gore3.png new file mode 100644 index 0000000000..7b2207d68e Binary files /dev/null and b/Gores/Ares/AresGaussNuke_Gore3.png differ diff --git a/Gores/Ares/AresHandBase_Gore1.png b/Gores/Ares/AresHandBase_Gore1.png new file mode 100644 index 0000000000..4000a1234c Binary files /dev/null and b/Gores/Ares/AresHandBase_Gore1.png differ diff --git a/Gores/Ares/AresHandBase_Gore2.png b/Gores/Ares/AresHandBase_Gore2.png new file mode 100644 index 0000000000..d1dcda125e Binary files /dev/null and b/Gores/Ares/AresHandBase_Gore2.png differ diff --git a/Gores/Ares/AresHandBase_Gore3.png b/Gores/Ares/AresHandBase_Gore3.png new file mode 100644 index 0000000000..4f111bc03e Binary files /dev/null and b/Gores/Ares/AresHandBase_Gore3.png differ diff --git a/Gores/Ares/AresLaserCannon_Gore1.png b/Gores/Ares/AresLaserCannon_Gore1.png new file mode 100644 index 0000000000..075c4fed61 Binary files /dev/null and b/Gores/Ares/AresLaserCannon_Gore1.png differ diff --git a/Gores/Ares/AresLaserCannon_Gore2.png b/Gores/Ares/AresLaserCannon_Gore2.png new file mode 100644 index 0000000000..e94d2e3bf0 Binary files /dev/null and b/Gores/Ares/AresLaserCannon_Gore2.png differ diff --git a/Gores/Ares/AresPlasmaFlamethrower_Gore1.png b/Gores/Ares/AresPlasmaFlamethrower_Gore1.png new file mode 100644 index 0000000000..ae954eedbb Binary files /dev/null and b/Gores/Ares/AresPlasmaFlamethrower_Gore1.png differ diff --git a/Gores/Ares/AresPlasmaFlamethrower_Gore2.png b/Gores/Ares/AresPlasmaFlamethrower_Gore2.png new file mode 100644 index 0000000000..1a4228a1d3 Binary files /dev/null and b/Gores/Ares/AresPlasmaFlamethrower_Gore2.png differ diff --git a/Gores/Ares/AresTeslaCannon_Gore1.png b/Gores/Ares/AresTeslaCannon_Gore1.png new file mode 100644 index 0000000000..e6b92d27da Binary files /dev/null and b/Gores/Ares/AresTeslaCannon_Gore1.png differ diff --git a/Gores/Ares/AresTeslaCannon_Gore2.png b/Gores/Ares/AresTeslaCannon_Gore2.png new file mode 100644 index 0000000000..9b54ff4391 Binary files /dev/null and b/Gores/Ares/AresTeslaCannon_Gore2.png differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker.png deleted file mode 100644 index 2754ddfc96..0000000000 Binary files a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker.png and /dev/null differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker2.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker2.png deleted file mode 100644 index 5c18ad17c9..0000000000 Binary files a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker2.png and /dev/null differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker3.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker3.png deleted file mode 100644 index d6fbc15b0e..0000000000 Binary files a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker3.png and /dev/null differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore1.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore1.png new file mode 100644 index 0000000000..4009972a78 Binary files /dev/null and b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore1.png differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore2.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore2.png new file mode 100644 index 0000000000..52719a2fe3 Binary files /dev/null and b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore2.png differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore3.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore3.png new file mode 100644 index 0000000000..60e920cd32 Binary files /dev/null and b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore3.png differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore4.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore4.png new file mode 100644 index 0000000000..3e9bf7b6b2 Binary files /dev/null and b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore4.png differ diff --git a/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore5.png b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore5.png new file mode 100644 index 0000000000..e7d3579972 Binary files /dev/null and b/Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore5.png differ diff --git a/Gores/SupremeCalamitas/BrimstoneHeart_Gore1.png b/Gores/SupremeCalamitas/BrimstoneHeart_Gore1.png new file mode 100644 index 0000000000..491063f204 Binary files /dev/null and b/Gores/SupremeCalamitas/BrimstoneHeart_Gore1.png differ diff --git a/Gores/SupremeCalamitas/BrimstoneHeart_Gore2.png b/Gores/SupremeCalamitas/BrimstoneHeart_Gore2.png new file mode 100644 index 0000000000..cb35235480 Binary files /dev/null and b/Gores/SupremeCalamitas/BrimstoneHeart_Gore2.png differ diff --git a/Gores/SupremeCalamitas/SepulcherArm_Gore.png b/Gores/SupremeCalamitas/SepulcherArm_Gore.png new file mode 100644 index 0000000000..fb7678cb5e Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherArm_Gore.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore1.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore1.png new file mode 100644 index 0000000000..cc91d0b99b Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore1.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore2.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore2.png new file mode 100644 index 0000000000..8d735724fc Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore2.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore3.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore3.png new file mode 100644 index 0000000000..3f01d98028 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore3.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore4.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore4.png new file mode 100644 index 0000000000..75e2bb2043 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore4.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore5.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore5.png new file mode 100644 index 0000000000..206ff5884f Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore5.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore6.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore6.png new file mode 100644 index 0000000000..1503860b0e Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore6.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore7.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore7.png new file mode 100644 index 0000000000..7f91f058e8 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore7.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore8.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore8.png new file mode 100644 index 0000000000..08f213b100 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore8.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody1_Gore9.png b/Gores/SupremeCalamitas/SepulcherBody1_Gore9.png new file mode 100644 index 0000000000..5909b57a8f Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody1_Gore9.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody2_Gore1.png b/Gores/SupremeCalamitas/SepulcherBody2_Gore1.png new file mode 100644 index 0000000000..66ad61c1c4 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody2_Gore1.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody2_Gore2.png b/Gores/SupremeCalamitas/SepulcherBody2_Gore2.png new file mode 100644 index 0000000000..a0afe9c2c6 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody2_Gore2.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody2_Gore3.png b/Gores/SupremeCalamitas/SepulcherBody2_Gore3.png new file mode 100644 index 0000000000..c51e0c6e39 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody2_Gore3.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody2_Gore4.png b/Gores/SupremeCalamitas/SepulcherBody2_Gore4.png new file mode 100644 index 0000000000..27c13b1f12 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody2_Gore4.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody2_Gore5.png b/Gores/SupremeCalamitas/SepulcherBody2_Gore5.png new file mode 100644 index 0000000000..56369887b4 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody2_Gore5.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody2_Gore6.png b/Gores/SupremeCalamitas/SepulcherBody2_Gore6.png new file mode 100644 index 0000000000..a558507804 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody2_Gore6.png differ diff --git a/Gores/SupremeCalamitas/SepulcherBody2_Gore7.png b/Gores/SupremeCalamitas/SepulcherBody2_Gore7.png new file mode 100644 index 0000000000..840e976c65 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherBody2_Gore7.png differ diff --git a/Gores/SupremeCalamitas/SepulcherForearm_Gore1.png b/Gores/SupremeCalamitas/SepulcherForearm_Gore1.png new file mode 100644 index 0000000000..8aebfc14ea Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherForearm_Gore1.png differ diff --git a/Gores/SupremeCalamitas/SepulcherForearm_Gore2.png b/Gores/SupremeCalamitas/SepulcherForearm_Gore2.png new file mode 100644 index 0000000000..6272a4257c Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherForearm_Gore2.png differ diff --git a/Gores/SupremeCalamitas/SepulcherHand_Gore1.png b/Gores/SupremeCalamitas/SepulcherHand_Gore1.png new file mode 100644 index 0000000000..1481801d09 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherHand_Gore1.png differ diff --git a/Gores/SupremeCalamitas/SepulcherHand_Gore2.png b/Gores/SupremeCalamitas/SepulcherHand_Gore2.png new file mode 100644 index 0000000000..e0534c6502 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherHand_Gore2.png differ diff --git a/Gores/SupremeCalamitas/SepulcherHead_Gore1.png b/Gores/SupremeCalamitas/SepulcherHead_Gore1.png new file mode 100644 index 0000000000..955bb07c3e Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherHead_Gore1.png differ diff --git a/Gores/SupremeCalamitas/SepulcherHead_Gore2.png b/Gores/SupremeCalamitas/SepulcherHead_Gore2.png new file mode 100644 index 0000000000..9615453c81 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherHead_Gore2.png differ diff --git a/Gores/SupremeCalamitas/SepulcherHead_Gore3.png b/Gores/SupremeCalamitas/SepulcherHead_Gore3.png new file mode 100644 index 0000000000..52ada3c123 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherHead_Gore3.png differ diff --git a/Gores/SupremeCalamitas/SepulcherHead_Gore4.png b/Gores/SupremeCalamitas/SepulcherHead_Gore4.png new file mode 100644 index 0000000000..7b37e0a607 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherHead_Gore4.png differ diff --git a/Gores/SupremeCalamitas/SepulcherHead_Gore5.png b/Gores/SupremeCalamitas/SepulcherHead_Gore5.png new file mode 100644 index 0000000000..d8f20446d2 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherHead_Gore5.png differ diff --git a/Gores/SupremeCalamitas/SepulcherTail_Gore1.png b/Gores/SupremeCalamitas/SepulcherTail_Gore1.png new file mode 100644 index 0000000000..40ca1472d8 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherTail_Gore1.png differ diff --git a/Gores/SupremeCalamitas/SepulcherTail_Gore2.png b/Gores/SupremeCalamitas/SepulcherTail_Gore2.png new file mode 100644 index 0000000000..81a900a180 Binary files /dev/null and b/Gores/SupremeCalamitas/SepulcherTail_Gore2.png differ diff --git a/ILEditing/ILChanges.cs b/ILEditing/ILChanges.cs index 3c4aea4405..b8c4f9aa46 100644 --- a/ILEditing/ILChanges.cs +++ b/ILEditing/ILChanges.cs @@ -106,218 +106,316 @@ namespace CalamityMod.ILEditing aLabDoorOpen = ModContent.TileType(); aLabDoorClosed = ModContent.TileType(); - ApplyLifeBytesChanges(); - AdjustChlorophyteBullets(); - RemoveAerialBaneDamageBoost(); - AdjustDamageVariance(); - RemoveExpertHardmodeScaling(); - IncreaseChlorophyteSpreadChance(); - ReduceTileBoostedRunSpeeds(); - ReduceWingHoverVelocities(); - RemoveRNGFromBlackBelt(); - ApplyBossZenDuringSlimeRain(); - PreventDungeonAbyssInteraction(); - BlockLivingTreesNearOcean(); - LabDoorFixes(); - AlterTownNPCSpawnRate(); - DisableDemonAltarGeneration(); - DisableTeleportersDuringBossFights(); - FixSplittingWormBannerDrops(); - IncorporateMinionExplodingCountdown(); - UseCoolFireCursorEffect(); - MakeMouseHoverItemsSupportAnimations(); - IncorporateEnchantmentInAffix(); + On.Terraria.Main.InitLifeBytes += BossRushLifeBytes; + IL.Terraria.Projectile.AI_001 += AdjustChlorophyteBullets; + IL.Terraria.Projectile.Damage += RemoveAerialBaneDamageBoost; + IL.Terraria.Main.DamageVar += AdjustDamageVariance; + IL.Terraria.NPC.scaleStats += RemoveExpertHardmodeScaling; + IL.Terraria.WorldGen.hardUpdateWorld += AdjustChlorophyteSpawnRate; + IL.Terraria.WorldGen.Chlorophyte += AdjustChlorophyteSpawnLimits; + IL.Terraria.Player.Update += ReduceTileBoostedRunSpeeds; + IL.Terraria.Player.Update += ReduceWingHoverVelocities; + IL.Terraria.Player.Hurt += RemoveRNGFromBlackBelt; + On.Terraria.NPC.SlimeRainSpawns += PreventBossSlimeRainSpawns; + IL.Terraria.WorldGen.MakeDungeon += PreventDungeonHorizontalCollisions; + IL.Terraria.WorldGen.DungeonHalls += PreventDungeonHallCollisions; + IL.Terraria.WorldGen.GrowLivingTree += BlockLivingTreesNearOcean; + IL.Terraria.NPC.NPCLoot += FixSplittingWormBannerDrops; + On.Terraria.WorldGen.OpenDoor += OpenDoor_LabDoorOverride; + On.Terraria.WorldGen.CloseDoor += CloseDoor_LabDoorOverride; + IL.Terraria.Main.UpdateTime += PermitNighttimeTownNPCSpawning; + On.Terraria.Main.UpdateTime_SpawnTownNPCs += AlterTownNPCSpawnRate; + On.Terraria.WorldGen.SmashAltar += PreventSmashAltarCode; + On.Terraria.Wiring.Teleport += DisableTeleporters; + On.Terraria.Projectile.NewProjectile_float_float_float_float_int_int_float_int_float_float += IncorporateMinionExplodingCountdown; + On.Terraria.Main.DrawCursor += UseCoolFireCursorEffect; + IL.Terraria.Main.DrawInterface_40_InteractItemIcon += MakeMouseHoverItemsSupportAnimations; + On.Terraria.Item.AffixName += IncorporateEnchantmentInAffix; } /// - /// Currently mostly useless, but clears static variables. + /// Unloads all IL Editing changes in the mod. /// internal static void Unload() { VanillaSpawnTownNPCs = null; labDoorOpen = labDoorClosed = aLabDoorOpen = aLabDoorClosed = -1; + + On.Terraria.Main.InitLifeBytes -= BossRushLifeBytes; + IL.Terraria.Projectile.AI_001 -= AdjustChlorophyteBullets; + IL.Terraria.Projectile.Damage -= RemoveAerialBaneDamageBoost; + IL.Terraria.Main.DamageVar -= AdjustDamageVariance; + IL.Terraria.NPC.scaleStats -= RemoveExpertHardmodeScaling; + IL.Terraria.WorldGen.hardUpdateWorld -= AdjustChlorophyteSpawnRate; + IL.Terraria.WorldGen.Chlorophyte -= AdjustChlorophyteSpawnLimits; + IL.Terraria.Player.Update -= ReduceTileBoostedRunSpeeds; + IL.Terraria.Player.Update -= ReduceWingHoverVelocities; + IL.Terraria.Player.Hurt -= RemoveRNGFromBlackBelt; + On.Terraria.NPC.SlimeRainSpawns -= PreventBossSlimeRainSpawns; + IL.Terraria.WorldGen.MakeDungeon -= PreventDungeonHorizontalCollisions; + IL.Terraria.WorldGen.DungeonHalls -= PreventDungeonHallCollisions; + IL.Terraria.WorldGen.GrowLivingTree -= BlockLivingTreesNearOcean; + IL.Terraria.NPC.NPCLoot -= FixSplittingWormBannerDrops; + On.Terraria.WorldGen.OpenDoor -= OpenDoor_LabDoorOverride; + On.Terraria.WorldGen.CloseDoor -= CloseDoor_LabDoorOverride; + IL.Terraria.Main.UpdateTime -= PermitNighttimeTownNPCSpawning; + On.Terraria.Main.UpdateTime_SpawnTownNPCs -= AlterTownNPCSpawnRate; + On.Terraria.WorldGen.SmashAltar -= PreventSmashAltarCode; + On.Terraria.Wiring.Teleport -= DisableTeleporters; + On.Terraria.Projectile.NewProjectile_float_float_float_float_int_int_float_int_float_float -= IncorporateMinionExplodingCountdown; + On.Terraria.Main.DrawCursor -= UseCoolFireCursorEffect; + IL.Terraria.Main.DrawInterface_40_InteractItemIcon -= MakeMouseHoverItemsSupportAnimations; + On.Terraria.Item.AffixName -= IncorporateEnchantmentInAffix; } #region IL Editing Routines - private static void ApplyLifeBytesChanges() => On.Terraria.Main.InitLifeBytes += BossRushLifeBytes; - private static void AdjustChlorophyteBullets() + private static void AdjustChlorophyteBullets(ILContext il) { - // Reduce dust from 10 to 5 and homing range. - IL.Terraria.Projectile.AI_001 += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(207)); // The ID of Chlorophyte Bullets. - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(10)); // The number of dust spawned by the bullet. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, 5); // Decrease dust to 5. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(300f)); // The 300 unit distance required to home in. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 150f); // Reduce homing range by 50%. - }; - } - - private static void RemoveAerialBaneDamageBoost() - { - IL.Terraria.Projectile.Damage += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(710)); // The ID of Aerial Bane projectiles. - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(1.5f)); // The damage multiplier. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 1f); // Multiplying by 1 means no damage bonus. - }; - } - - private static void AdjustDamageVariance() - { - // Change the damage variance from +-15% to +-5%. - IL.Terraria.Main.DamageVar += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(-15)); // The -15% lower bound of the variance. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, -5); // Increase to -5%. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(16)); // The +15% upper bound of the variance. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, 6); // Decrease to +5%. - }; - } - - private static void RemoveExpertHardmodeScaling() - { - // Completely disable the weak enemy scaling that occurs when Hardmode is active in Expert Mode. - IL.Terraria.NPC.scaleStats += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(1000)); // The less than 1000 HP check in order for the scaling to take place. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4_M1); // Replace the 1000 with -1, no NPC can have less than -1 HP on spawn, so it fails to run. - }; - } - - private static void IncreaseChlorophyteSpreadChance() - { - // Change the Chlorophyte spawn rate. - IL.Terraria.WorldGen.hardUpdateWorld += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(300)); // 1 in 300 genRand call used to generate Chlorophyte in mud tiles near jungle grass. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, 150); // Increase the chance to 1 in 150. - }; - - // Change the Chlorophyte spawn limits. - IL.Terraria.WorldGen.Chlorophyte += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(40)); // Find the 40 Chlorophyte tile limit. This limit is checked within a 71x71-tile square, with the reference tile as the center. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, 60); // Increase the limit to 60. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(130)); // Find the 130 Chlorophyte tile limit. This limit is checked within a 171x171-tile square, with the reference tile as the center. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, 200); // Increase the limit to 200. - }; - } - - private static void ReduceTileBoostedRunSpeeds() - { - // Reduce the run speed boost while running on Asphalt, Frozen Slime Blocks and Ice Blocks. - IL.Terraria.Player.Update += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR8(1.6)); // Movement speed cap (removed in 1.4). - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R8, 3D); // Increase it to some higher amount. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(1.6f)); // Movement speed cap (removed in 1.4). - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 3f); // Increase it to some higher amount. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(3.5f)); // The max run speed multiplier for Asphalt. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 1.75f); // Reduce by 1.75. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(1.25f)); // The max run speed multiplier for Frozen Slime Blocks. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 1f); // Reduce boost to 0. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(1.25f)); // The max run speed multiplier for Ice Blocks. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 1f); // Reduce boost to 0. - }; - } - - private static void ReduceWingHoverVelocities() - { - // Reduce wing hover horizontal velocities. Hoverboard is fine because both stats are at 10. - IL.Terraria.Player.Update += (il) => - { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(6.25f)); // The accRunSpeed variable is set to this specific value before hover adjustments occur. - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(12f)); // The accRunSpeed for Vortex Booster and Nebula Mantle. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(12f)); // The runAcceleration for Vortex Booster and Nebula Mantle. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(12f)); // The accRunSpeed for Betsy Wings. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. - - cursor.GotoNext(MoveType.Before, i => i.MatchLdcR4(12f)); // The runAcceleration for Betsy Wings. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. - }; - } - - private static void RemoveRNGFromBlackBelt() - { - // Change the random chance of the Black Belt to 100%, but don't let it work if Calamity's cooldown is active. - IL.Terraria.Player.Hurt += (il) => + // Reduce dust from 10 to 5 and homing range. + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(ProjectileID.ChlorophyteBullet))) { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(10)); // 1 in 10 Main.rand call for Black Belt activation. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4_1); // Replace with Main.rand.Next(1), aka 100% chance. + WriteFailToLog("chlorophyte bullet behavior", "Could not locate the bullet ID."); + return; + } + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(10))) // The number of dust spawned by the bullet. + { + WriteFailToLog("chlorophyte bullet behavior", "Could not locate the dust quantity."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, 5); // Decrease dust to 5. - // Move forwards past the Main.rand.Next call now that it has been edited. - cursor.GotoNext(MoveType.After, i => i.MatchCallvirt("Next")); - - // Load the player itself onto the stack so that it becomes an argument for the following delegate. - cursor.Emit(OpCodes.Ldarg_0); - - // Emit a delegate which places the player's Calamity dodge cooldown onto the stack. - cursor.EmitDelegate>((Player p) => p.Calamity().dodgeCooldownTimer); - - // Bitwise OR the "RNG result" (always zero) with the dodge cooldown. This will only return zero if both values were zero. - // The code path which calls NinjaDodge can ONLY occur if the result of this operation is zero, - // because it is now the value checked by the immediately following branch-if-true. - cursor.Emit(OpCodes.Or); - - // Move forwards past the NinjaDodge call. We need to set the dodge cooldown here. - cursor.GotoNext(MoveType.After, i => i.MatchCall("NinjaDodge")); - - // Load the player itself onto the stack so that it becomes an argument for the following delegate. - cursor.Emit(OpCodes.Ldarg_0); - - // Emit a delegate which sets the player's Calamity dodge cooldown and sends a sync packet appropriately. - cursor.EmitDelegate>((Player p) => - { - CalamityPlayer calPlayer = p.Calamity(); - calPlayer.dodgeCooldownTimer = CalamityPlayer.BeltDodgeCooldown; - if (Main.netMode == NetmodeID.MultiplayerClient) - calPlayer.SyncDodgeCooldown(false); - }); - }; + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(300f))) // The 300 unit distance required to home in. + { + WriteFailToLog("chlorophyte bullet behavior", "Could not locate the homing range."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 150f); // Reduce homing range by 50%. } - private static void ApplyBossZenDuringSlimeRain() => On.Terraria.NPC.SlimeRainSpawns += PreventBossSlimeRainSpawns; + private static void RemoveAerialBaneDamageBoost(ILContext il) + { + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(ProjectileID.DD2BetsyArrow))) // The ID of Aerial Bane projectiles. + { + WriteFailToLog("aerial bane damage boost reduction", "Could not locate the arrow ID."); + return; + } + if (cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(1.5f))) // The damage multiplier. + { + WriteFailToLog("aerial bane damage boost reduction", "Could not locate the damage multiplier."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 1f); // Multiplying by 1 means no damage bonus. + } + + private static void AdjustDamageVariance(ILContext il) + { + // Change the damage variance from +-15% to +-5%. + var cursor = new ILCursor(il); + if (cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(-15))) // The -15% lower bound of the variance. + { + WriteFailToLog("general damage variance reduction", "Could not locate the lower bound."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, -5); // Increase to -5%. + + if (cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(16))) // The 15% upper bound of the variance. + { + WriteFailToLog("general damage variance reduction", "Could not locate the upper bound."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, 6); // Decrease to +5%. + } + + private static void RemoveExpertHardmodeScaling(ILContext il) + { + // Completely disable the weak enemy scaling that occurs when Hardmode is active in Expert Mode. + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(1000))) // The less than 1000 HP check in order for the scaling to take place. + { + WriteFailToLog("expert hardmode scaling removal", "Could not locate the HP check."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4_M1); // Replace the 1000 with -1, no NPC can have less than -1 HP on spawn, so it fails to run. + } + + private static void AdjustChlorophyteSpawnRate(ILContext il) + { + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(300))) // 1 in 300 genRand call used to generate Chlorophyte in mud tiles near jungle grass. + { + WriteFailToLog("chlorophyte spread rate adjustment", "Could not locate the update chance."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, 150); // Increase the chance to 1 in 150. + } + + private static void AdjustChlorophyteSpawnLimits(ILContext il) + { + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(40))) // Find the 40 Chlorophyte tile limit. This limit is checked within a 71x71-tile square, with the reference tile as the center. + { + WriteFailToLog("chlorophyte spread limit adjustment", "Could not locate the lower limit."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, 60); // Increase the limit to 60. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(130))) // Find the 130 Chlorophyte tile limit. This limit is checked within a 171x171-tile square, with the reference tile as the center. + { + WriteFailToLog("chlorophyte spread limit adjustment", "Could not locate the upper limit."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, 200); // Increase the limit to 200. + } + + private static void ReduceTileBoostedRunSpeeds(ILContext il) + { + // Reduce the run speed boost while running on Asphalt, Frozen Slime Blocks and Ice Blocks. + + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR8(1.6))) // Movement speed cap (removed in 1.4). + { + WriteFailToLog("run speed adjustment", "Could not locate the movement speed limit."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R8, 3D); // Increase it to some higher amount. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR8(1.6f))) // Movement speed cap (removed in 1.4). + { + WriteFailToLog("run speed adjustment", "Could not locate the movement speed limit."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 3f); // Increase it to some higher amount. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(3.5f))) // The max run speed multiplier for Asphalt. + { + WriteFailToLog("run speed adjustment", "Could not locate the asphalt movement speed limit."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 1.75f); // Reduce by 1.75. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(1.25f))) // The max run speed multiplier for Frozen Slime Blocks. + { + WriteFailToLog("run speed adjustment", "Could not locate the frozen slime block movement speed limit."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 1f); // Reduce boost to 0. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(1.25f))) // The max run speed multiplier for Ice Blocks. + { + WriteFailToLog("run speed adjustment", "Could not locate the ice block movement speed limit."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 1f); // Reduce boost to 0. + } + + private static void ReduceWingHoverVelocities(ILContext il) + { + // Reduce wing hover horizontal velocities. Hoverboard is fine because both stats are at 10. + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(6.25f))) // The accRunSpeed variable is set to this specific value before hover adjustments occur. + { + WriteFailToLog("wing hover speed reduction", "Could not locate the base speed variable."); + return; + } + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(12f))) // The accRunSpeed for Vortex Booster and Nebula Mantle. + { + WriteFailToLog("wing hover speed reduction", "Could not locate the vortex booster/nebula mantle speed variable."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(12f))) // The runAcceleration for Vortex Booster and Nebula Mantle. + { + WriteFailToLog("wing hover speed reduction", "Could not locate the vortex booster/nebula mantle speed variable."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(12f))) // The accRunSpeed for Betsy Wings. + { + WriteFailToLog("wing hover speed reduction", "Could not locate the betsy's wings speed variable."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(12f))) // The runAcceleration for Betsy Wings. + { + WriteFailToLog("wing hover speed reduction", "Could not locate the betsy's wings speed variable."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_R4, 10.8f); // Reduce by 10%. + } + + private static void RemoveRNGFromBlackBelt(ILContext il) + { + // Change the random chance of the Black Belt to 100%, but don't let it work if Calamity's cooldown is active. + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(10))) // 1 in 10 Main.rand call for Black Belt activation. + { + WriteFailToLog("black belt dodge guarantee", "Could not locate the dodge chance."); + return; + } + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4_1); // Replace with Main.rand.Next(1), aka 100% chance. + + // Move forwards past the Main.rand.Next call now that it has been edited. + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCallvirt("Next"))) + { + WriteFailToLog("black belt dodge guarantee", "Could not locate the Random.Next call."); + return; + } + + // Load the player itself onto the stack so that it becomes an argument for the following delegate. + cursor.Emit(OpCodes.Ldarg_0); + + // Emit a delegate which places the player's Calamity dodge cooldown onto the stack. + cursor.EmitDelegate>((Player p) => p.Calamity().dodgeCooldownTimer); + + // Bitwise OR the "RNG result" (always zero) with the dodge cooldown. This will only return zero if both values were zero. + // The code path which calls NinjaDodge can ONLY occur if the result of this operation is zero, + // because it is now the value checked by the immediately following branch-if-true. + cursor.Emit(OpCodes.Or); + + // Move forwards past the NinjaDodge call. We need to set the dodge cooldown here. + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCall("NinjaDodge"))) + { + WriteFailToLog("black belt dodge guarantee", "Could not locate the Player.NinjaDodge call."); + return; + } + + // Load the player itself onto the stack so that it becomes an argument for the following delegate. + cursor.Emit(OpCodes.Ldarg_0); + + // Emit a delegate which sets the player's Calamity dodge cooldown and sends a sync packet appropriately. + cursor.EmitDelegate>((Player p) => + { + CalamityPlayer calPlayer = p.Calamity(); + calPlayer.dodgeCooldownTimer = CalamityPlayer.BeltDodgeCooldown; + if (Main.netMode == NetmodeID.MultiplayerClient) + calPlayer.SyncDodgeCooldown(false); + }); + } private static void ReplacePharaohSetInPyramids() { @@ -325,191 +423,177 @@ namespace CalamityMod.ILEditing IL.Terraria.NPC.scaleStats += (il) => { var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(848)); // The ID of the Pharaoh's Mask. + cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(848)); // The ID of the Pharaoh's Mask. cursor.Remove(); cursor.Emit(OpCodes.Ldc_I4, 1240); // Replace the Mask with a Ruby Hook, in 1.4 I will replace this with an Amber Hook so it makes more sense. // Note: There is no need to replace the other Pharaoh piece, due to how the vanilla code works. }; } - private static void PreventDungeonAbyssInteraction() + private static void PreventDungeonHallCollisions(ILContext il) + { + // Prevent the Dungeon's halls from getting anywhere near the Abyss. + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchStsfld("dungeonY"))) + { + WriteFailToLog("dungeon hall abyss collision fix", "Could not locate the dungeon's vertical position."); + return; + } + + cursor.EmitDelegate(() => + { + WorldGen.dungeonX = Utils.Clamp(WorldGen.dungeonX, SulphurousSea.BiomeWidth + 100, Main.maxTilesX - SulphurousSea.BiomeWidth - 100); + + // Adjust the Y position of the dungeon to accomodate for the X shift. + WorldUtils.Find(new Point(WorldGen.dungeonX, WorldGen.dungeonY), Searches.Chain(new Searches.Down(9001), new Conditions.IsSolid()), out Point result); + WorldGen.dungeonY = result.Y - 10; + }); + } + + private static void PreventDungeonHorizontalCollisions(ILContext il) { // Prevent the Dungeon from appearing near the Sulph sea. - IL.Terraria.WorldGen.MakeDungeon += il => + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchStsfld("dungeonY"))) { - var cursor = new ILCursor(il); - cursor.GotoNext(MoveType.After, i => i.MatchStsfld("dungeonY")); + WriteFailToLog("dungeon hall abyss collision fix", "Could not locate the dungeon's vertical position."); + return; + } - cursor.EmitDelegate(() => - { - WorldGen.dungeonX = Utils.Clamp(WorldGen.dungeonX, SulphurousSea.BiomeWidth + 100, Main.maxTilesX - SulphurousSea.BiomeWidth - 100); - - // Adjust the Y position of the dungeon to accomodate for the X shift. - WorldUtils.Find(new Point(WorldGen.dungeonX, WorldGen.dungeonY), Searches.Chain(new Searches.Down(9001), new Conditions.IsSolid()), out Point result); - WorldGen.dungeonY = result.Y - 10; - }); - }; - - // And prevent its halls from getting anywhere near the Abyss. - IL.Terraria.WorldGen.DungeonHalls += il => + cursor.EmitDelegate(() => { - var cursor = new ILCursor(il); + WorldGen.dungeonX = Utils.Clamp(WorldGen.dungeonX, SulphurousSea.BiomeWidth + 100, Main.maxTilesX - SulphurousSea.BiomeWidth - 100); - // Forcefully clamp the X position of the new hall end. - // This prevents a hall, and as a result, the dungeon, from ever impeding on the Abyss/Sulph Sea. - cursor.GotoNext(MoveType.After, i => i.MatchStloc(6)); - - cursor.Emit(OpCodes.Ldloc, 6); - cursor.EmitDelegate>(unclampedValue => - { - unclampedValue.X = MathHelper.Clamp(unclampedValue.X, SulphurousSea.BiomeWidth + 25, Main.maxTilesX - SulphurousSea.BiomeWidth - 25); - return unclampedValue; - }); - cursor.Emit(OpCodes.Stloc, 6); - }; + // Adjust the Y position of the dungeon to accomodate for the X shift. + WorldUtils.Find(new Point(WorldGen.dungeonX, WorldGen.dungeonY), Searches.Chain(new Searches.Down(9001), new Conditions.IsSolid()), out Point result); + WorldGen.dungeonY = result.Y - 10; + }); } - private static void BlockLivingTreesNearOcean() + private static void BlockLivingTreesNearOcean(ILContext il) { - IL.Terraria.WorldGen.GrowLivingTree += (il) => - { - var cursor = new ILCursor(il); - cursor.Emit(OpCodes.Ldarg_0); - cursor.EmitDelegate>(x => Utils.Clamp(x, 560, Main.maxTilesX - 560)); - cursor.Emit(OpCodes.Starg, 0); - }; + var cursor = new ILCursor(il); + cursor.Emit(OpCodes.Ldarg_0); + cursor.EmitDelegate>(x => Utils.Clamp(x, 560, Main.maxTilesX - 560)); + cursor.Emit(OpCodes.Starg, 0); } - private static void LabDoorFixes() + private static void PermitNighttimeTownNPCSpawning(ILContext il) { - On.Terraria.WorldGen.OpenDoor += OpenDoor_LabDoorOverride; - On.Terraria.WorldGen.CloseDoor += CloseDoor_LabDoorOverride; + // Don't do town NPC spawning at the end (which lies after a !Main.dayTime return). + // Do it at the beginning, without the arbitrary time restriction. + var cursor = new ILCursor(il); + cursor.EmitDelegate(() => + { + // A cached delegate is used here instead of direct reflection for performance reasons + // since UpdateTime is called every frame. + if (Main.dayTime || CalamityConfig.Instance.CanTownNPCsSpawnAtNight) + VanillaSpawnTownNPCs(); + }); + + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCallOrCallvirt
("UpdateTime_SpawnTownNPCs"))) + { + CalamityMod.Instance.Logger.Warn("Town NPC spawn editing code failed."); + return; + } + + cursor.Emit(OpCodes.Ret); } - private static void AlterTownNPCSpawnRate() + private static void AlterTownNPCSpawnRate(On.Terraria.Main.orig_UpdateTime_SpawnTownNPCs orig) { - IL.Terraria.Main.UpdateTime += (il) => - { - // Don't do town NPC spawning at the end (after a !Main.dayTime return). - // Do it at the beginning in spite of time. - - var cursor = new ILCursor(il); - cursor.EmitDelegate(() => - { - // A cached delegate is used here instead of direct reflection for performance reasons - // since UpdateTime is called every frame. - if (Main.dayTime || CalamityConfig.Instance.CanTownNPCsSpawnAtNight) - VanillaSpawnTownNPCs(); - }); - - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCallOrCallvirt
("UpdateTime_SpawnTownNPCs"))) - { - CalamityMod.Instance.Logger.Warn("Town NPC spawn editing code failed."); - return; - } - - cursor.Emit(OpCodes.Ret); - }; - - On.Terraria.Main.UpdateTime_SpawnTownNPCs += (orig) => - { - int oldWorldRate = Main.worldRate; - Main.worldRate *= CalamityConfig.Instance.TownNPCSpawnRateMultiplier; - orig(); - Main.worldRate = oldWorldRate; - }; + int oldWorldRate = Main.worldRate; + Main.worldRate *= CalamityConfig.Instance.TownNPCSpawnRateMultiplier; + orig(); + Main.worldRate = oldWorldRate; } - private static void DisableDemonAltarGeneration() => On.Terraria.WorldGen.SmashAltar += PreventSmashAltarCode; - - private static void DisableTeleportersDuringBossFights() => On.Terraria.Wiring.Teleport += DisableTeleporters; - - private static void FixSplittingWormBannerDrops() + private static void FixSplittingWormBannerDrops(ILContext il) { - IL.Terraria.NPC.NPCLoot += (il) => + var cursor = new ILCursor(il); + + // Locate the area after all the banner logic by using a nearby constant type. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(23))) { - var cursor = new ILCursor(il); + WriteFailToLog("splitting worm banner spam fix", "Could not locate the first hooking constant."); + return; + } + if (!cursor.TryGotoPrev(MoveType.Before, i => i.MatchLdarg(0))) + { + WriteFailToLog("splitting worm banner spam fix", "Could not locate the second hooking constant."); + return; + } - // Locate the area after all the banner logic by using a nearby constant type. - cursor.GotoNext(MoveType.Before, i => i.MatchLdcI4(23)); - cursor.GotoPrev(MoveType.Before, i => i.MatchLdarg(0)); + ILLabel afterBannerLogic = cursor.DefineLabel(); - ILLabel afterBannerLogic = cursor.DefineLabel(); + // Set this area after as a place to return to later. + cursor.MarkLabel(afterBannerLogic); - // Set this area after as a place to return to later. - cursor.MarkLabel(afterBannerLogic); + // Go to the beginning of the banner drop logic. + cursor.Goto(0); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdsfld("killCount"))) + { + WriteFailToLog("splitting worm banner spam fix", "Could not locate the NPC kill count."); + return; + } - // Go to the beginning of the banner drop logic. - cursor.Goto(0); - cursor.GotoNext(MoveType.Before, i => i.MatchLdsfld("killCount")); + // Load the NPC caller onto the stack. + cursor.Emit(OpCodes.Ldarg_0); + cursor.EmitDelegate>(npc => CalamityGlobalNPCLoot.SplittingWormLootBlockWrapper(npc, CalamityMod.Instance)); - // Load the NPC caller onto the stack. - cursor.Emit(OpCodes.Ldarg_0); - cursor.EmitDelegate>(npc => CalamityGlobalNPCLoot.SplittingWormLootBlockWrapper(npc, CalamityMod.Instance)); - - // Emit 0 (false) onto the stack. - cursor.Emit(OpCodes.Ldc_I4_0); - - // If the block is equal to false (indicating the drop logic should stop), skip all the ahead banner drop logic. - cursor.Emit(OpCodes.Beq, afterBannerLogic); - }; + // If the block is false (indicating the drop logic should stop), skip all the ahead banner drop logic. + cursor.Emit(OpCodes.Brfalse, afterBannerLogic); } - private static void IncorporateMinionExplodingCountdown() - { - On.Terraria.Projectile.NewProjectile_float_float_float_float_int_int_float_int_float_float += (orig, x, y, xSpeed, ySpeed, type, damage, knockback, owner, ai0, ai1) => - { - // This is unfortunately not something that can be done via SetDefaults since owner is set - // after that method is called. Doing it directly when the projectile is spawned appears to be the only reasonable way. - int proj = orig(x, y, xSpeed, ySpeed, type, damage, knockback, owner, ai0, ai1); - Projectile projectile = Main.projectile[proj]; - if (projectile.minion) - { - Player player = Main.player[projectile.owner]; - CalamityPlayerMiscEffects.EnchantHeldItemEffects(player, player.Calamity(), player.ActiveItem()); - if (player.Calamity().explosiveMinionsEnchant) - projectile.Calamity().ExplosiveEnchantCountdown = CalamityGlobalProjectile.ExplosiveEnchantTime; - } - return proj; - }; - } - - private static void MakeMouseHoverItemsSupportAnimations() + private static int IncorporateMinionExplodingCountdown(On.Terraria.Projectile.orig_NewProjectile_float_float_float_float_int_int_float_int_float_float orig, float x, float y, float xSpeed, float ySpeed, int type, int damage, float knockback, int owner, float ai0, float ai1) { - IL.Terraria.Main.DrawInterface_40_InteractItemIcon += (il) => + // This is unfortunately not something that can be done via SetDefaults since owner is set + // after that method is called. Doing it directly when the projectile is spawned appears to be the only reasonable way. + int proj = orig(x, y, xSpeed, ySpeed, type, damage, knockback, owner, ai0, ai1); + Projectile projectile = Main.projectile[proj]; + if (projectile.minion) { - var cursor = new ILCursor(il); - - // Locate the location where the frame rectangle is created. - if (!cursor.TryGotoNext(MoveType.After, i => i.MatchNewobj())) - return; - - int endIndex = cursor.Index; - - // And then go back to where it began, right after the draw position vector. - if (!cursor.TryGotoPrev(MoveType.After, i => i.MatchNewobj())) - return; - - // And delete the range that creates the rectangle with intent to replace it. - cursor.RemoveRange(Math.Abs(endIndex - cursor.Index)); - - cursor.Emit(OpCodes.Ldloc_0); - cursor.EmitDelegate>(itemType => - { - return Main.itemAnimations[itemType]?.GetFrame(Main.itemTexture[itemType]) ?? null; - }); - }; + Player player = Main.player[projectile.owner]; + CalamityPlayerMiscEffects.EnchantHeldItemEffects(player, player.Calamity(), player.ActiveItem()); + if (player.Calamity().explosiveMinionsEnchant) + projectile.Calamity().ExplosiveEnchantCountdown = CalamityGlobalProjectile.ExplosiveEnchantTime; + } + return proj; } - private static void IncorporateEnchantmentInAffix() + private static void MakeMouseHoverItemsSupportAnimations(ILContext il) { - On.Terraria.Item.AffixName += (orig, self) => + var cursor = new ILCursor(il); + + // Locate the location where the frame rectangle is created. + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchNewobj())) + return; + + int endIndex = cursor.Index; + + // And then go back to where it began, right after the draw position vector. + if (!cursor.TryGotoPrev(MoveType.After, i => i.MatchNewobj())) { - string result = orig(self); - if (!self.IsAir && self.Calamity().AppliedEnchantment.HasValue) - result = $"{self.Calamity().AppliedEnchantment.Value.Name} {result}"; - return result; - }; + WriteFailToLog("hover item animation support", "Could not locate the creation of the draw position vector."); + return; + } + + // And delete the range that creates the rectangle with intent to replace it. + cursor.RemoveRange(Math.Abs(endIndex - cursor.Index)); + + cursor.Emit(OpCodes.Ldloc_0); + cursor.EmitDelegate>(itemType => + { + return Main.itemAnimations[itemType]?.GetFrame(Main.itemTexture[itemType]) ?? null; + }); + } + + private static string IncorporateEnchantmentInAffix(On.Terraria.Item.orig_AffixName orig, Item self) + { + string result = orig(self); + if (!self.IsAir && self.Calamity().AppliedEnchantment.HasValue) + result = $"{self.Calamity().AppliedEnchantment.Value.Name} {result}"; + return result; } #endregion @@ -562,101 +646,98 @@ namespace CalamityMod.ILEditing return orig(i, j, forced); } - private static void UseCoolFireCursorEffect() + private static void UseCoolFireCursorEffect(On.Terraria.Main.orig_DrawCursor orig, Vector2 bonus, bool smart) { - On.Terraria.Main.DrawCursor += (orig, bonus, smart) => + // Do nothing special if the player has a regular mouse or is on the menu. + if (Main.gameMenu || !Main.LocalPlayer.Calamity().ableToDrawBlazingMouse) { - // Do nothing special if the player has a regular mouse or is on the menu. - if (Main.gameMenu || !Main.LocalPlayer.Calamity().ableToDrawBlazingMouse) + orig(bonus, smart); + return; + } + + if (Main.LocalPlayer.dead) + { + Main.SmartInteractShowingGenuine = false; + Main.SmartInteractShowingFake = false; + Main.SmartInteractNPC = -1; + Main.SmartInteractNPCsNearby.Clear(); + Main.SmartInteractTileCoords.Clear(); + Main.SmartInteractTileCoordsSelected.Clear(); + Main.TileInteractionLX = (Main.TileInteractionHX = (Main.TileInteractionLY = (Main.TileInteractionHY = -1))); + } + + Color flameColor = Color.Lerp(Color.DarkRed, Color.OrangeRed, (float)Math.Cos(Main.GlobalTime * 7.4f) * 0.5f + 0.5f); + Color cursorColor = flameColor * 1.9f; + Vector2 baseDrawPosition = Main.MouseScreen + bonus; + + // Draw the mouse as usual if the player isn't using the gamepad. + if (!PlayerInput.UsingGamepad) + { + int cursorIndex = smart.ToInt(); + + Color desaturatedCursorColor = cursorColor; + desaturatedCursorColor.R /= 5; + desaturatedCursorColor.G /= 5; + desaturatedCursorColor.B /= 5; + desaturatedCursorColor.A /= 2; + + Vector2 drawPosition = baseDrawPosition; + Vector2 desaturatedDrawPosition = drawPosition + Vector2.One; + + // If the blazing mouse is actually going to do damage, draw an indicator aura. + if (Main.LocalPlayer.Calamity().blazingMouseDamageEffects && !Main.mapFullscreen) { - orig(bonus, smart); - return; - } + Texture2D auraTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/CalamityAura"); + Rectangle auraFrame = auraTexture.Frame(1, 6, 0, (int)(Main.GlobalTime * 12.3f) % 6); + float auraScale = MathHelper.Lerp(0.95f, 1f, (float)Math.Sin(Main.GlobalTime * 1.1f) * 0.5f + 0.5f); - if (Main.LocalPlayer.dead) - { - Main.SmartInteractShowingGenuine = false; - Main.SmartInteractShowingFake = false; - Main.SmartInteractNPC = -1; - Main.SmartInteractNPCsNearby.Clear(); - Main.SmartInteractTileCoords.Clear(); - Main.SmartInteractTileCoordsSelected.Clear(); - Main.TileInteractionLX = (Main.TileInteractionHX = (Main.TileInteractionLY = (Main.TileInteractionHY = -1))); - } - - Color flameColor = Color.Lerp(Color.DarkRed, Color.OrangeRed, (float)Math.Cos(Main.GlobalTime * 7.4f) * 0.5f + 0.5f); - Color cursorColor = flameColor * 1.9f; - Vector2 baseDrawPosition = Main.MouseScreen + bonus; - - // Draw the mouse as usual if the player isn't using the gamepad. - if (!PlayerInput.UsingGamepad) - { - int cursorIndex = smart.ToInt(); - - Color desaturatedCursorColor = cursorColor; - desaturatedCursorColor.R /= 5; - desaturatedCursorColor.G /= 5; - desaturatedCursorColor.B /= 5; - desaturatedCursorColor.A /= 2; - - Vector2 drawPosition = baseDrawPosition; - Vector2 desaturatedDrawPosition = drawPosition + Vector2.One; - - // If the blazing mouse is actually going to do damage, draw an indicator aura. - if (Main.LocalPlayer.Calamity().blazingMouseDamageEffects && !Main.mapFullscreen) + for (int i = 0; i < 12; i++) { - Texture2D auraTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/CalamityAura"); - Rectangle auraFrame = auraTexture.Frame(1, 6, 0, (int)(Main.GlobalTime * 12.3f) % 6); - float auraScale = MathHelper.Lerp(0.95f, 1f, (float)Math.Sin(Main.GlobalTime * 1.1f) * 0.5f + 0.5f); + Color auraColor = Color.Orange * Main.LocalPlayer.Calamity().blazingMouseAuraFade * 0.125f; + auraColor.A = 0; + Vector2 offsetDrawPosition = baseDrawPosition + (MathHelper.TwoPi * i / 12f + Main.GlobalTime * 5f).ToRotationVector2() * 2.5f; + offsetDrawPosition.Y -= 18f; - for (int i = 0; i < 12; i++) - { - Color auraColor = Color.Orange * Main.LocalPlayer.Calamity().blazingMouseAuraFade * 0.125f; - auraColor.A = 0; - Vector2 offsetDrawPosition = baseDrawPosition + (MathHelper.TwoPi * i / 12f + Main.GlobalTime * 5f).ToRotationVector2() * 2.5f; - offsetDrawPosition.Y -= 18f; - - Main.spriteBatch.Draw(auraTexture, offsetDrawPosition, auraFrame, auraColor, 0f, auraFrame.Size() * 0.5f, Main.cursorScale * auraScale, SpriteEffects.None, 0f); - } + Main.spriteBatch.Draw(auraTexture, offsetDrawPosition, auraFrame, auraColor, 0f, auraFrame.Size() * 0.5f, Main.cursorScale * auraScale, SpriteEffects.None, 0f); } - - Main.spriteBatch.Draw(Main.cursorTextures[cursorIndex], drawPosition, null, desaturatedCursorColor, 0f, Vector2.Zero, Main.cursorScale, SpriteEffects.None, 0f); - - Main.spriteBatch.End(); - Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.UIScaleMatrix); - GameShaders.Misc["CalamityMod:FireMouse"].UseColor(Color.Red); - GameShaders.Misc["CalamityMod:FireMouse"].UseSecondaryColor(Color.Lerp(Color.Red, Color.Orange, 0.75f)); - GameShaders.Misc["CalamityMod:FireMouse"].Apply(); - - Main.spriteBatch.Draw(Main.cursorTextures[cursorIndex], desaturatedDrawPosition, null, cursorColor, 0f, Vector2.Zero, Main.cursorScale * 1.075f, SpriteEffects.None, 0f); - Main.spriteBatch.End(); - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.EffectMatrix); - return; } - // Don't bother doing any more drawing if the player is dead. - if (Main.LocalPlayer.dead && !Main.LocalPlayer.ghost && !Main.gameMenu) - return; + Main.spriteBatch.Draw(Main.cursorTextures[cursorIndex], drawPosition, null, desaturatedCursorColor, 0f, Vector2.Zero, Main.cursorScale, SpriteEffects.None, 0f); - if (PlayerInput.InvisibleGamepadInMenus) - return; + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.UIScaleMatrix); + GameShaders.Misc["CalamityMod:FireMouse"].UseColor(Color.Red); + GameShaders.Misc["CalamityMod:FireMouse"].UseSecondaryColor(Color.Lerp(Color.Red, Color.Orange, 0.75f)); + GameShaders.Misc["CalamityMod:FireMouse"].Apply(); - // Draw a white circle instead if using the smart cursor. - if (smart && !(UILinkPointNavigator.Available && !PlayerInput.InBuildingMode)) - { - cursorColor = Color.White * Main.GamepadCursorAlpha; - int frameX = 0; - Texture2D smartCursorTexture = Main.cursorTextures[13]; - Rectangle frame = smartCursorTexture.Frame(2, 1, frameX, 0); - Main.spriteBatch.Draw(smartCursorTexture, baseDrawPosition, frame, cursorColor, 0f, frame.Size() * 0.5f, Main.cursorScale, SpriteEffects.None, 0f); - return; - } + Main.spriteBatch.Draw(Main.cursorTextures[cursorIndex], desaturatedDrawPosition, null, cursorColor, 0f, Vector2.Zero, Main.cursorScale * 1.075f, SpriteEffects.None, 0f); + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.EffectMatrix); + return; + } - // Otherwise draw an ordinary crosshair at the mouse position. - cursorColor = Color.White; - Texture2D crosshairTexture = Main.cursorTextures[15]; - Main.spriteBatch.Draw(crosshairTexture, baseDrawPosition, null, cursorColor, 0f, crosshairTexture.Size() * 0.5f, Main.cursorScale, SpriteEffects.None, 0f); - }; + // Don't bother doing any more drawing if the player is dead. + if (Main.LocalPlayer.dead && !Main.LocalPlayer.ghost && !Main.gameMenu) + return; + + if (PlayerInput.InvisibleGamepadInMenus) + return; + + // Draw a white circle instead if using the smart cursor. + if (smart && !(UILinkPointNavigator.Available && !PlayerInput.InBuildingMode)) + { + cursorColor = Color.White * Main.GamepadCursorAlpha; + int frameX = 0; + Texture2D smartCursorTexture = Main.cursorTextures[13]; + Rectangle frame = smartCursorTexture.Frame(2, 1, frameX, 0); + Main.spriteBatch.Draw(smartCursorTexture, baseDrawPosition, frame, cursorColor, 0f, frame.Size() * 0.5f, Main.cursorScale, SpriteEffects.None, 0f); + return; + } + + // Otherwise draw an ordinary crosshair at the mouse position. + cursorColor = Color.White; + Texture2D crosshairTexture = Main.cursorTextures[15]; + Main.spriteBatch.Draw(crosshairTexture, baseDrawPosition, null, cursorColor, 0f, crosshairTexture.Size() * 0.5f, Main.cursorScale, SpriteEffects.None, 0f); } private static void PreventSmashAltarCode(On.Terraria.WorldGen.orig_SmashAltar orig, int i, int j) @@ -726,6 +807,8 @@ namespace CalamityMod.ILEditing Main.PlaySound(SoundID.DoorClosed, doorX * 16, doorY * 16); return true; } + + public static void WriteFailToLog(string editName, string reason) => CalamityMod.Instance.Logger.Warn($"The {editName} IL edit failed. {reason}"); #endregion } } diff --git a/Items/Accessories/ReaperToothNecklace.cs b/Items/Accessories/ReaperToothNecklace.cs index 2535043e59..df1cfcf6cc 100644 --- a/Items/Accessories/ReaperToothNecklace.cs +++ b/Items/Accessories/ReaperToothNecklace.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Items.Accessories public override void SetStaticDefaults() { DisplayName.SetDefault("Reaper Tooth Necklace"); - Tooltip.SetDefault("A grisly trophy from the ultimate predator\n" + "12% increased damage\n" + "Increases armor penetration by 30"); + Tooltip.SetDefault("A grisly trophy from the ultimate predator\n" + "10% increased damage\n" + "Increases armor penetration by 15"); } public override void SetDefaults() @@ -27,8 +27,8 @@ namespace CalamityMod.Items.Accessories public override void UpdateAccessory(Player player, bool hideVisual) { - player.allDamage += 0.12f; - player.armorPenetration += 30; + player.allDamage += 0.1f; + player.armorPenetration += 15; } public override void AddRecipes() diff --git a/Items/Accessories/SandSharkToothNecklace.cs b/Items/Accessories/SandSharkToothNecklace.cs index 63901be879..c75050eadb 100644 --- a/Items/Accessories/SandSharkToothNecklace.cs +++ b/Items/Accessories/SandSharkToothNecklace.cs @@ -10,7 +10,7 @@ namespace CalamityMod.Items.Accessories public override void SetStaticDefaults() { DisplayName.SetDefault("Sand Shark Tooth Necklace"); - Tooltip.SetDefault("Increases armor penetration by 15\n" + "6% increased damage"); + Tooltip.SetDefault("Increases armor penetration by 10\n" + "6% increased damage"); } public override void SetDefaults() @@ -25,7 +25,7 @@ namespace CalamityMod.Items.Accessories public override void UpdateAccessory(Player player, bool hideVisual) { player.allDamage += 0.06f; - player.armorPenetration += 15; + player.armorPenetration += 10; } public override void AddRecipes() diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index ff0ba8b14e..d70d214b02 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -1003,6 +1003,21 @@ namespace CalamityMod.Items } return false; } + if (player.ActiveItem().type == ModContent.ItemType() && player.ownedProjectileCounts[ModContent.ProjectileType()] == 0) + { + for (int i = 0; i < Main.projectile.Length; i++) + { + if (Main.projectile[i].modProjectile is VoidConcentrationAura) + { + if (Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + { + (Main.projectile[i].modProjectile as VoidConcentrationAura).HandleRightClick(); + break; + } + } + } + return false; + } if (player.ActiveItem().type == ModContent.ItemType()) { bool canContinue = true; diff --git a/Items/Dyes/BloodflareDye.cs b/Items/Dyes/BloodflareDye.cs new file mode 100644 index 0000000000..c48e0567da --- /dev/null +++ b/Items/Dyes/BloodflareDye.cs @@ -0,0 +1,37 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Graphics.Shaders; +using Microsoft.Xna.Framework; + +namespace CalamityMod.Items.Dyes +{ + public class BloodflareDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/BloodflareDyeShader")), "DyePass"). + UseColor(new Color(122, 10, 60)).UseSecondaryColor(new Color(219, 102, 106)).UseImage("Images/Misc/Perlin"); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Bloodflare Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Red; + item.Calamity().customRarity = CalamityRarity.PureGreen; + item.value = Item.sellPrice(0, 4, 0, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 2); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 2); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/BloodflareDye.png b/Items/Dyes/BloodflareDye.png new file mode 100644 index 0000000000..aa7383fe1d Binary files /dev/null and b/Items/Dyes/BloodflareDye.png differ diff --git a/Items/Dyes/BlueCosmicFlameDye.cs b/Items/Dyes/BlueCosmicFlameDye.cs new file mode 100644 index 0000000000..be095f9472 --- /dev/null +++ b/Items/Dyes/BlueCosmicFlameDye.cs @@ -0,0 +1,37 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Graphics.Shaders; +using Microsoft.Xna.Framework; + +namespace CalamityMod.Items.Dyes +{ + public class BlueCosmicFlameDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/CosmicFlameShader")), "DyePass"). + UseColor(new Color(52, 212, 229)).UseSecondaryColor(new Color(52, 212, 229)).UseImage("Images/Misc/Noise").UseSaturation(0f); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Blue Cosmic Flame Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.DarkBlue; + item.value = Item.sellPrice(0, 5, 0, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 2); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 2); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/BlueCosmicFlameDye.png b/Items/Dyes/BlueCosmicFlameDye.png new file mode 100644 index 0000000000..103049ae10 Binary files /dev/null and b/Items/Dyes/BlueCosmicFlameDye.png differ diff --git a/Items/Dyes/CalamitousDye.cs b/Items/Dyes/CalamitousDye.cs new file mode 100644 index 0000000000..ce329f8051 --- /dev/null +++ b/Items/Dyes/CalamitousDye.cs @@ -0,0 +1,37 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Dyes +{ + public class CalamitousDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/CalamitousDyeShader")), "DyePass"). + UseColor(new Color(227, 79, 79)).UseSecondaryColor(new Color(145, 27, 135)).UseImage("Images/Misc/Perlin"); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Calamitous Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.value = Item.sellPrice(0, 10, 0, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 3); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 3); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/CalamitousDye.png b/Items/Dyes/CalamitousDye.png new file mode 100644 index 0000000000..587ec7e601 Binary files /dev/null and b/Items/Dyes/CalamitousDye.png differ diff --git a/Items/Dyes/CryonicDye.cs b/Items/Dyes/CryonicDye.cs new file mode 100644 index 0000000000..86fd0e89bc --- /dev/null +++ b/Items/Dyes/CryonicDye.cs @@ -0,0 +1,36 @@ +using CalamityMod.Items.Placeables.Ores; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Dyes +{ + public class CryonicDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/CryonicDyeShader")), "DyePass"). + UseColor(new Color(138, 225, 255)).UseSecondaryColor(new Color(90, 90, 204)).UseImage("Images/Misc/Perlin"); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Cryonic Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Pink; + item.value = Item.sellPrice(0, 0, 75, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 2); + recipe.AddIngredient(ModContent.ItemType(), 4); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 2); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/CryonicDye.png b/Items/Dyes/CryonicDye.png new file mode 100644 index 0000000000..7aa240fd98 Binary files /dev/null and b/Items/Dyes/CryonicDye.png differ diff --git a/Items/Dyes/PhantoplasmDye.cs b/Items/Dyes/PhantoplasmDye.cs new file mode 100644 index 0000000000..993f77f826 --- /dev/null +++ b/Items/Dyes/PhantoplasmDye.cs @@ -0,0 +1,36 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Graphics.Shaders; +using Microsoft.Xna.Framework; + +namespace CalamityMod.Items.Dyes +{ + public class PhantoplasmDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/PhantoplasmDyeShader")), "DyePass"). + UseColor(new Color(245, 143, 182)).UseSecondaryColor(new Color(119, 238, 255)).UseImage("Images/Misc/Perlin"); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Phantoplasm Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.value = Item.sellPrice(0, 2, 50, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 2); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 2); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/PhantoplasmDye.png b/Items/Dyes/PhantoplasmDye.png new file mode 100644 index 0000000000..792d4bd633 Binary files /dev/null and b/Items/Dyes/PhantoplasmDye.png differ diff --git a/Items/Dyes/PinkCosmicFlameDye.cs b/Items/Dyes/PinkCosmicFlameDye.cs new file mode 100644 index 0000000000..9c953cf4bd --- /dev/null +++ b/Items/Dyes/PinkCosmicFlameDye.cs @@ -0,0 +1,37 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Graphics.Shaders; +using Microsoft.Xna.Framework; + +namespace CalamityMod.Items.Dyes +{ + public class PinkCosmicFlameDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/CosmicFlameShader")), "DyePass"). + UseColor(new Color(255, 115, 221)).UseSecondaryColor(new Color(255, 115, 221)).UseImage("Images/Misc/Noise").UseSaturation(0f); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Pink Cosmic Flame Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.DarkBlue; + item.value = Item.sellPrice(0, 5, 0, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 2); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 2); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/PinkCosmicFlameDye.png b/Items/Dyes/PinkCosmicFlameDye.png new file mode 100644 index 0000000000..65c1fd39ad Binary files /dev/null and b/Items/Dyes/PinkCosmicFlameDye.png differ diff --git a/Items/Dyes/ProfanedFlameDye.cs b/Items/Dyes/ProfanedFlameDye.cs new file mode 100644 index 0000000000..e777cce2b1 --- /dev/null +++ b/Items/Dyes/ProfanedFlameDye.cs @@ -0,0 +1,36 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Graphics.Shaders; +using Microsoft.Xna.Framework; + +namespace CalamityMod.Items.Dyes +{ + public class ProfanedFlameDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/ProfanedFlameDyeShader")), "DyePass"). + UseColor(new Color(255, 191, 73)).UseSecondaryColor(new Color(255, 255, 186)).UseImage("Images/Misc/Perlin"); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Profaned Flame Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.value = Item.sellPrice(0, 2, 50, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 2); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 2); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/ProfanedFlameDye.png b/Items/Dyes/ProfanedFlameDye.png new file mode 100644 index 0000000000..fefa274ca2 Binary files /dev/null and b/Items/Dyes/ProfanedFlameDye.png differ diff --git a/Items/Dyes/SwirlingCosmicFlameDye.cs b/Items/Dyes/SwirlingCosmicFlameDye.cs new file mode 100644 index 0000000000..f227541687 --- /dev/null +++ b/Items/Dyes/SwirlingCosmicFlameDye.cs @@ -0,0 +1,36 @@ +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Graphics.Shaders; +using Microsoft.Xna.Framework; + +namespace CalamityMod.Items.Dyes +{ + public class SwirlingCosmicFlameDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/CosmicFlameShader")), "DyePass"). + UseColor(new Color(52, 212, 229)).UseSecondaryColor(new Color(255, 115, 221)).UseImage("Images/Misc/Noise").UseSaturation(1f); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Swirling Cosmic Flame Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.DarkBlue; + item.value = Item.sellPrice(0, 7, 50, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/SwirlingCosmicFlameDye.png b/Items/Dyes/SwirlingCosmicFlameDye.png new file mode 100644 index 0000000000..bc524d1cc6 Binary files /dev/null and b/Items/Dyes/SwirlingCosmicFlameDye.png differ diff --git a/Items/Tools/Grax.cs b/Items/Tools/Grax.cs index e2de7f2ae4..231c660616 100644 --- a/Items/Tools/Grax.cs +++ b/Items/Tools/Grax.cs @@ -13,7 +13,7 @@ namespace CalamityMod.Items.Tools public override void SetStaticDefaults() { DisplayName.SetDefault("Grax"); - Tooltip.SetDefault("Hitting an enemy will greatly boost your defense and melee stats for a short time\n" + + Tooltip.SetDefault("Hitting an enemy will greatly boost your defense, melee damage and melee crit for a short time\n" + "Right click to use without hammering down walls or chopping down trees"); } diff --git a/Items/TreasureBags/YharonBag.cs b/Items/TreasureBags/YharonBag.cs index 69f01e7cd3..7970a74788 100644 --- a/Items/TreasureBags/YharonBag.cs +++ b/Items/TreasureBags/YharonBag.cs @@ -11,6 +11,8 @@ using CalamityMod.World; using Terraria; using Terraria.ModLoader; using Terraria.ID; +using CalamityMod.Items.Accessories.Wings; +using CalamityMod.Items.Materials; namespace CalamityMod.Items.TreasureBags { @@ -57,8 +59,13 @@ namespace CalamityMod.Items.TreasureBags ); // Equipment + DropHelper.DropItem(player, ModContent.ItemType()); DropHelper.DropItem(player, ModContent.ItemType()); + int soulFragMin = 22; + int soulFragMax = 28; + DropHelper.DropItem(player, ModContent.ItemType(), soulFragMin, soulFragMax); + // Vanity DropHelper.DropItemChance(player, ModContent.ItemType(), 7); DropHelper.DropItemChance(player, ModContent.ItemType(), 10); diff --git a/Items/Weapons/Melee/AegisBlade.cs b/Items/Weapons/Melee/AegisBlade.cs index b473d99535..7d3419fe2b 100644 --- a/Items/Weapons/Melee/AegisBlade.cs +++ b/Items/Weapons/Melee/AegisBlade.cs @@ -20,7 +20,7 @@ namespace CalamityMod.Items.Weapons.Melee item.width = 58; item.height = 58; item.scale = 1.5f; - item.damage = 68; + item.damage = 110; item.melee = true; item.useAnimation = item.useTime = 15; item.useTurn = true; @@ -66,7 +66,7 @@ namespace CalamityMod.Items.Weapons.Melee public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ModContent.ProjectileType(), (int)(damage * 0.6), knockBack, player.whoAmI); + Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ModContent.ProjectileType(), (int)(damage * 0.37), knockBack, player.whoAmI); return false; } diff --git a/Items/Weapons/Melee/AstralPike.cs b/Items/Weapons/Melee/AstralPike.cs index df0983db65..70de4755f0 100644 --- a/Items/Weapons/Melee/AstralPike.cs +++ b/Items/Weapons/Melee/AstralPike.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { item.width = 44; - item.damage = 128; + item.damage = 90; item.melee = true; item.noMelee = true; item.useTurn = true; diff --git a/Items/Weapons/Melee/Ataraxia.cs b/Items/Weapons/Melee/Ataraxia.cs index 23f4d63bee..1a40403a52 100644 --- a/Items/Weapons/Melee/Ataraxia.cs +++ b/Items/Weapons/Melee/Ataraxia.cs @@ -22,7 +22,7 @@ namespace CalamityMod.Items.Weapons.Melee item.width = 94; item.height = 92; item.melee = true; - item.damage = 1095; + item.damage = 710; item.knockBack = 2.5f; item.useAnimation = 19; item.useTime = 19; diff --git a/Items/Weapons/Melee/BladeofEnmity.cs b/Items/Weapons/Melee/BladeofEnmity.cs index 2ed5dcb022..c9ffe6ce17 100644 --- a/Items/Weapons/Melee/BladeofEnmity.cs +++ b/Items/Weapons/Melee/BladeofEnmity.cs @@ -18,7 +18,7 @@ namespace CalamityMod.Items.Weapons.Melee item.width = 60; item.height = 64; item.scale = 1.5f; - item.damage = 158; + item.damage = 190; item.melee = true; item.useAnimation = 10; item.useStyle = ItemUseStyleID.SwingThrow; diff --git a/Items/Weapons/Melee/BrinyBaron.cs b/Items/Weapons/Melee/BrinyBaron.cs index 0e7e4c6097..0fbb6efb04 100644 --- a/Items/Weapons/Melee/BrinyBaron.cs +++ b/Items/Weapons/Melee/BrinyBaron.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { - item.damage = 200; + item.damage = 127; item.knockBack = 4f; item.useAnimation = item.useTime = 15; item.melee = true; @@ -66,7 +66,7 @@ namespace CalamityMod.Items.Weapons.Melee public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ModContent.ProjectileType(), damage / 3, knockBack, player.whoAmI); + Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ModContent.ProjectileType(), (int)(damage * 0.52), knockBack, player.whoAmI); return false; } diff --git a/Items/Weapons/Melee/DiseasedPike.cs b/Items/Weapons/Melee/DiseasedPike.cs index 138d12accd..b7853c91c5 100644 --- a/Items/Weapons/Melee/DiseasedPike.cs +++ b/Items/Weapons/Melee/DiseasedPike.cs @@ -16,7 +16,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { item.width = 62; - item.damage = 75; + item.damage = 92; item.melee = true; item.noMelee = true; item.useTurn = true; diff --git a/Items/Weapons/Melee/ExsanguinationLance.cs b/Items/Weapons/Melee/ExsanguinationLance.cs index 733f11b7db..e142c93180 100644 --- a/Items/Weapons/Melee/ExsanguinationLance.cs +++ b/Items/Weapons/Melee/ExsanguinationLance.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { item.width = 44; - item.damage = 60; + item.damage = 90; item.melee = true; item.noMelee = true; item.useTurn = true; diff --git a/Items/Weapons/Melee/GrandGuardian.cs b/Items/Weapons/Melee/GrandGuardian.cs index eb922de395..fc9bf9cbe5 100644 --- a/Items/Weapons/Melee/GrandGuardian.cs +++ b/Items/Weapons/Melee/GrandGuardian.cs @@ -70,16 +70,16 @@ namespace CalamityMod.Items.Weapons.Melee Projectile.NewProjectile(targetPos, Vector2.Zero, ModContent.ProjectileType(), (int)(damage * 0.5f), 0f, player.whoAmI); if (targetLife <= (targetMaxLife * 0.5f) && player.ownedProjectileCounts[ModContent.ProjectileType()] < 3) { - float randomSpeedX = Main.rand.Next(9); - float randomSpeedY = Main.rand.Next(6, 15); - Projectile.NewProjectile(player.Center.X, player.Center.Y, -randomSpeedX, -randomSpeedY, ModContent.ProjectileType(), (int)(damage * 0.75f), knockback, player.whoAmI); - Projectile.NewProjectile(player.Center.X, player.Center.Y, randomSpeedX, -randomSpeedY, ModContent.ProjectileType(), (int)(damage * 0.75f), knockback, player.whoAmI); - Projectile.NewProjectile(player.Center.X, player.Center.Y, 0f, -randomSpeedY, ModContent.ProjectileType(), (int)(damage * 0.75f), knockback, player.whoAmI); + float randomSpeedX = Main.rand.Next(6, 13); + float randomSpeedY = Main.rand.Next(6, 13); + Projectile.NewProjectile(targetPos.X, targetPos.Y, -randomSpeedX, -randomSpeedY, ModContent.ProjectileType(), (int)(damage * 0.75f), knockback, player.whoAmI); + Projectile.NewProjectile(targetPos.X, targetPos.Y, randomSpeedX, -randomSpeedY, ModContent.ProjectileType(), (int)(damage * 0.75f), knockback, player.whoAmI); + Projectile.NewProjectile(targetPos.X, targetPos.Y, 0f, -randomSpeedY, ModContent.ProjectileType(), (int)(damage * 0.75f), knockback, player.whoAmI); } if (targetLife <= 0 && !player.moonLeech && player.ownedProjectileCounts[ModContent.ProjectileType()] < 3) { - float randomSpeedX = Main.rand.Next(9); - float randomSpeedY = Main.rand.Next(6, 15); + float randomSpeedX = Main.rand.Next(3, 7); + float randomSpeedY = Main.rand.Next(3, 7); Projectile.NewProjectile(targetPos.X, targetPos.Y, -randomSpeedX, -randomSpeedY, ModContent.ProjectileType(), 0, 0f, player.whoAmI); Projectile.NewProjectile(targetPos.X, targetPos.Y, randomSpeedX, -randomSpeedY, ModContent.ProjectileType(), 0, 0f, player.whoAmI); Projectile.NewProjectile(targetPos.X, targetPos.Y, 0f, -randomSpeedY, ModContent.ProjectileType(), 0, 0f, player.whoAmI); diff --git a/Items/Weapons/Melee/HolyCollider.cs b/Items/Weapons/Melee/HolyCollider.cs index 2f2bc11870..a1ee34def1 100644 --- a/Items/Weapons/Melee/HolyCollider.cs +++ b/Items/Weapons/Melee/HolyCollider.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Melee item.width = 94; item.height = 80; item.scale = 1.5f; - item.damage = 342; + item.damage = 270; item.melee = true; item.useAnimation = 22; item.useStyle = ItemUseStyleID.SwingThrow; diff --git a/Items/Weapons/Melee/Murasama.cs b/Items/Weapons/Melee/Murasama.cs index 30c4f8561a..49d498e579 100644 --- a/Items/Weapons/Melee/Murasama.cs +++ b/Items/Weapons/Melee/Murasama.cs @@ -26,7 +26,7 @@ namespace CalamityMod.Items.Weapons.Melee { item.height = 128; item.width = 56; - item.damage = 2001; + item.damage = 3001; item.melee = true; item.noMelee = true; item.noUseGraphic = true; diff --git a/Items/Weapons/Melee/Omniblade.cs b/Items/Weapons/Melee/Omniblade.cs index 0ccd879f86..6baf919099 100644 --- a/Items/Weapons/Melee/Omniblade.cs +++ b/Items/Weapons/Melee/Omniblade.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { item.width = 64; - item.damage = 95; + item.damage = 138; item.melee = true; item.useAnimation = 10; item.useStyle = ItemUseStyleID.SwingThrow; diff --git a/Items/Weapons/Melee/Oracle.cs b/Items/Weapons/Melee/Oracle.cs index fd80f86eb2..4dd5bd38ac 100644 --- a/Items/Weapons/Melee/Oracle.cs +++ b/Items/Weapons/Melee/Oracle.cs @@ -10,9 +10,9 @@ namespace CalamityMod.Items.Weapons.Melee { public class Oracle : ModItem { - public const int YoyoBaseDamage = 115; - public const int AuraBaseDamage = 40; - public const int AuraMaxDamage = 105; + public const int YoyoBaseDamage = 170; + public const int AuraBaseDamage = 100; + public const int AuraMaxDamage = 220; public override void SetStaticDefaults() { diff --git a/Items/Weapons/Melee/PhosphorescentGauntlet.cs b/Items/Weapons/Melee/PhosphorescentGauntlet.cs index 29d9a5ff8d..8c977ce9b8 100644 --- a/Items/Weapons/Melee/PhosphorescentGauntlet.cs +++ b/Items/Weapons/Melee/PhosphorescentGauntlet.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { item.width = item.height = 40; - item.damage = 930; + item.damage = 2705; item.melee = true; item.noMelee = true; item.noUseGraphic = true; diff --git a/Items/Weapons/Melee/PhotonRipper.cs b/Items/Weapons/Melee/PhotonRipper.cs index 24e2d87a0e..5b6bee5630 100644 --- a/Items/Weapons/Melee/PhotonRipper.cs +++ b/Items/Weapons/Melee/PhotonRipper.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Melee { item.height = 134; item.width = 54; - item.damage = 3660; + item.damage = 4050; // Displayed axe% is 1/5th of axePower here because trees have 500% hardness. This corrects for that. item.axe = 6000 / 5; diff --git a/Items/Weapons/Melee/SpineOfThanatos.cs b/Items/Weapons/Melee/SpineOfThanatos.cs index e702cd99ac..4f1b9a089e 100644 --- a/Items/Weapons/Melee/SpineOfThanatos.cs +++ b/Items/Weapons/Melee/SpineOfThanatos.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { item.width = item.height = 28; - item.damage = 369; + item.damage = 260; item.rare = ItemRarityID.Red; item.value = CalamityGlobalItem.RarityVioletBuyPrice; item.Calamity().customRarity = CalamityRarity.Violet; diff --git a/Items/Weapons/Melee/TheEnforcer.cs b/Items/Weapons/Melee/TheEnforcer.cs index cb2969333d..f73a27cef9 100644 --- a/Items/Weapons/Melee/TheEnforcer.cs +++ b/Items/Weapons/Melee/TheEnforcer.cs @@ -22,7 +22,7 @@ namespace CalamityMod.Items.Weapons.Melee item.width = 100; item.height = 100; item.scale = 1.5f; - item.damage = 760; + item.damage = 890; item.melee = true; item.useAnimation = 17; item.useStyle = ItemUseStyleID.SwingThrow; diff --git a/Items/Weapons/Melee/TheMutilator.cs b/Items/Weapons/Melee/TheMutilator.cs index 25a33f05c9..159e44f4af 100644 --- a/Items/Weapons/Melee/TheMutilator.cs +++ b/Items/Weapons/Melee/TheMutilator.cs @@ -21,7 +21,7 @@ namespace CalamityMod.Items.Weapons.Melee item.width = 90; item.height = 90; item.scale = 1.5f; - item.damage = 596; + item.damage = 483; item.melee = true; item.useAnimation = 18; item.useStyle = ItemUseStyleID.SwingThrow; diff --git a/Items/Weapons/Ranged/AcesHigh.cs b/Items/Weapons/Ranged/AcesHigh.cs index 8884fcf40e..49a26ce573 100644 --- a/Items/Weapons/Ranged/AcesHigh.cs +++ b/Items/Weapons/Ranged/AcesHigh.cs @@ -21,7 +21,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 230; + item.damage = 325; item.ranged = true; item.width = 48; item.height = 30; diff --git a/Items/Weapons/Ranged/ChickenCannon.cs b/Items/Weapons/Ranged/ChickenCannon.cs index 9263922eb7..656f87e4d5 100644 --- a/Items/Weapons/Ranged/ChickenCannon.cs +++ b/Items/Weapons/Ranged/ChickenCannon.cs @@ -11,39 +11,66 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetStaticDefaults() { DisplayName.SetDefault("Chicken Cannon"); - Tooltip.SetDefault("Fires chicken rockets"); + Tooltip.SetDefault("Fires chicken flares which create enormous incendiary explosions\n" + + "Right click to detonate all airborne rockets"); } public override void SetDefaults() { - item.damage = 90; + item.damage = 530; item.ranged = true; item.width = 76; item.height = 24; - item.useTime = 39; - item.useAnimation = 39; + item.useTime = item.useAnimation = 33; item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; - item.knockBack = 8.5f; - item.value = CalamityGlobalItem.Rarity15BuyPrice; - item.rare = ItemRarityID.Purple; - item.Calamity().customRarity = CalamityRarity.Violet; - item.UseSound = SoundID.Item11; + item.knockBack = 1.5f; + item.value = CalamityGlobalItem.Rarity15BuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + // No use sound is intentional item.autoReuse = true; - item.shootSpeed = 24f; - item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 17.5f; + item.shoot = ModContent.ProjectileType(); item.useAmmo = AmmoID.Rocket; } - public override Vector2? HoldoutOffset() - { - return new Vector2(-10, 0); - } + public override Vector2? HoldoutOffset() => new Vector2(-10, 0); + + public override bool AltFunctionUse(Player player) => true; public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ModContent.ProjectileType(), damage, knockBack, player.whoAmI); + // Play a sound and detonate all in-flight rockets, but don't shoot anything. + if (player.altFunctionUse == 2) + { + Main.PlaySound(SoundID.Item110, position); + DetonateRockets(player); + return false; + } + + // Otherwise just play a grenade launcher sound and fire a rocket. + Main.PlaySound(SoundID.Item61, position); + Projectile.NewProjectile(position, new Vector2(speedX, speedY), item.shoot, damage, knockBack, player.whoAmI); return false; } + + private void DetonateRockets(Player player) + { + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile p = Main.projectile[i]; + if (!p.active || p.owner != player.whoAmI || p.type != item.shoot) + continue; + + // All rockets will instantly explode on the next frame and send packets to indicate as such. + p.timeLeft = 1; + p.netUpdate = true; + p.netSpam = 0; + } + } + + // Right clicking to detonate all rockets is very fast. + public override float UseTimeMultiplier(Player player) => player.altFunctionUse == 2 ? 5f : 1f; } } diff --git a/Items/Weapons/Ranged/DragonsBreath.cs b/Items/Weapons/Ranged/DragonsBreath.cs index 4766897338..e46d503b62 100644 --- a/Items/Weapons/Ranged/DragonsBreath.cs +++ b/Items/Weapons/Ranged/DragonsBreath.cs @@ -11,7 +11,7 @@ namespace CalamityMod.Items.Weapons.Ranged public const int BetweenShotsPause = 15; public const int PelletsPerShot = 6; public const float FullAutoFireRateMult = 0.8f; - public const float FullAutoDamageMult = 0.85f; + public const float FullAutoDamageMult = 0.8f; // note this is extremely low because it's per pellet public const float Spread = 0.018f; @@ -21,14 +21,14 @@ namespace CalamityMod.Items.Weapons.Ranged Tooltip.SetDefault("Left click fires in two-shot bursts\n" + "The first shot is a spread of 6 normal bullets\n" + "The second shot is a tight spread of 6 Dragon's Breath rounds\n" + - "Right click fires full auto and mixes the bullets randomly, but does 15% less damage\n" + + "Right click fires full auto and mixes the bullets randomly, but does 20% less damage\n" + "This weapon has no randomness to its spread pattern\n" + "66% chance to not consume ammo"); } public override void SetDefaults() { - item.damage = 200; + item.damage = 272; item.ranged = true; item.width = 64; item.height = 28; diff --git a/Items/Weapons/Ranged/HeavenlyGale.cs b/Items/Weapons/Ranged/HeavenlyGale.cs index d4de9703bb..a72de55197 100644 --- a/Items/Weapons/Ranged/HeavenlyGale.cs +++ b/Items/Weapons/Ranged/HeavenlyGale.cs @@ -11,7 +11,7 @@ namespace CalamityMod.Items.Weapons.Ranged { public class HeavenlyGale : ModItem { - public const float NormalArrowDamageMult = 1.2f; + public const float NormalArrowDamageMult = 1.25f; private static int[] ExoArrows; public override void SetStaticDefaults() @@ -22,7 +22,7 @@ namespace CalamityMod.Items.Weapons.Ranged "Blue exo arrows burst into barrages of following arrows\n" + "Orange exo arrows explode into flames\n" + "Teal exo arrows pierce infinitely and ignore immunity frames\n" + - "Any non-wooden arrows used will deal 1.2x damage\n" + + $"Any non-wooden arrows used will deal {NormalArrowDamageMult}x damage\n" + "66% chance to not consume ammo"); ExoArrows = new int[] diff --git a/Items/Weapons/Ranged/Karasawa.cs b/Items/Weapons/Ranged/Karasawa.cs index fa8681b09f..d3457396b7 100644 --- a/Items/Weapons/Ranged/Karasawa.cs +++ b/Items/Weapons/Ranged/Karasawa.cs @@ -76,7 +76,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void AddRecipes() { ModRecipe r = new ModRecipe(mod); - r.AddIngredient(ModContent.ItemType()); + r.AddIngredient(ItemID.LargeRuby); r.AddIngredient(ModContent.ItemType(), 5); r.AddIngredient(ModContent.ItemType(), 10); r.AddIngredient(ModContent.ItemType(), 15); diff --git a/Items/Weapons/Ranged/Photoviscerator.cs b/Items/Weapons/Ranged/Photoviscerator.cs index a3ccae8ffb..0bfa278040 100644 --- a/Items/Weapons/Ranged/Photoviscerator.cs +++ b/Items/Weapons/Ranged/Photoviscerator.cs @@ -11,7 +11,7 @@ namespace CalamityMod.Items.Weapons.Ranged public class Photoviscerator : ModItem { public const int CooldownTime = 60 * 7; // 7 second cooldown. - public const double AltFireDamageMult = 1.5; + public const double AltFireDamageMult = 1D; public override void SetStaticDefaults() { diff --git a/Items/Weapons/Ranged/SurgeDriver.cs b/Items/Weapons/Ranged/SurgeDriver.cs index f3e8ed0a68..94b23d9a56 100644 --- a/Items/Weapons/Ranged/SurgeDriver.cs +++ b/Items/Weapons/Ranged/SurgeDriver.cs @@ -74,7 +74,7 @@ namespace CalamityMod.Items.Weapons.Ranged { Vector2 newShootVelocity = shootVelocity * Main.rand.NextFloat(1f, 1.45f); newShootVelocity = newShootVelocity.RotatedByRandom(0.15f); - Projectile.NewProjectile(gunTip, newShootVelocity, item.shoot, damage, knockBack, player.whoAmI); + Projectile.NewProjectile(gunTip, newShootVelocity, item.shoot, (int)(damage * 1.08), knockBack, player.whoAmI); } } diff --git a/Items/Weapons/Rogue/TheAtomSplitter.cs b/Items/Weapons/Rogue/TheAtomSplitter.cs index d37d9ee856..e640233cc8 100644 --- a/Items/Weapons/Rogue/TheAtomSplitter.cs +++ b/Items/Weapons/Rogue/TheAtomSplitter.cs @@ -18,7 +18,7 @@ namespace CalamityMod.Items.Weapons.Rogue public override void SafeSetDefaults() { item.width = item.height = 128; - item.damage = 456; + item.damage = 410; item.knockBack = 7f; item.useAnimation = item.useTime = 25; item.Calamity().rogue = true; diff --git a/Items/Weapons/Summon/AngryChickenStaff.cs b/Items/Weapons/Summon/AngryChickenStaff.cs index ca405e227c..66804946d5 100644 --- a/Items/Weapons/Summon/AngryChickenStaff.cs +++ b/Items/Weapons/Summon/AngryChickenStaff.cs @@ -8,6 +8,7 @@ namespace CalamityMod.Items.Weapons.Summon { public class AngryChickenStaff : ModItem { + public const int Damage = 107; public override void SetStaticDefaults() { DisplayName.SetDefault("Yharon's Kindle Staff"); @@ -18,17 +19,17 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetDefaults() { item.mana = 50; - item.damage = 83; + item.damage = Damage; item.useStyle = ItemUseStyleID.SwingThrow; item.width = 32; item.height = 32; item.useTime = item.useAnimation = 10; item.noMelee = true; item.knockBack = 7f; - item.value = CalamityGlobalItem.Rarity15BuyPrice; - item.rare = ItemRarityID.Purple; - item.Calamity().customRarity = CalamityRarity.Violet; - item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/FlareSound"); + item.value = CalamityGlobalItem.Rarity15BuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/FlareSound"); item.autoReuse = true; item.shoot = ModContent.ProjectileType(); item.shootSpeed = 10f; diff --git a/Items/Weapons/Summon/CosmicImmaterializer.cs b/Items/Weapons/Summon/CosmicImmaterializer.cs index bd29889670..ba6848556c 100644 --- a/Items/Weapons/Summon/CosmicImmaterializer.cs +++ b/Items/Weapons/Summon/CosmicImmaterializer.cs @@ -3,14 +3,13 @@ using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Summon; using CalamityMod.Tiles.Furniture.CraftingStations; using Microsoft.Xna.Framework; -using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Items.Weapons.Summon { - public class CosmicImmaterializer : ModItem + public class CosmicImmaterializer : ModItem { public override void SetStaticDefaults() { @@ -25,7 +24,7 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetDefaults() { item.mana = 100; - item.damage = 630; + item.damage = 560; item.useStyle = ItemUseStyleID.SwingThrow; item.width = 74; item.height = 72; @@ -45,7 +44,7 @@ namespace CalamityMod.Items.Weapons.Summon public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - CalamityUtils.KillShootProjectiles(true, type, player); + CalamityUtils.KillShootProjectiles(true, type, player); CalamityPlayer modPlayer = player.Calamity(); bool hasSummonerSet = modPlayer.tarraSummon || modPlayer.bloodflareSummon || modPlayer.silvaSummon || modPlayer.dsSetBonus || modPlayer.omegaBlueSet || modPlayer.fearmongerSet; //demonshade included so summoner isn't forced to use auric for BR Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, type, (int)(damage * (hasSummonerSet ? 1 : 0.66)), knockBack, player.whoAmI, 0f, 0f); @@ -59,8 +58,8 @@ namespace CalamityMod.Items.Weapons.Summon recipe.AddIngredient(ModContent.ItemType()); recipe.AddIngredient(ModContent.ItemType()); recipe.AddIngredient(ModContent.ItemType()); - recipe.AddIngredient(ModContent.ItemType(), 4); - recipe.AddTile(ModContent.TileType()); + recipe.AddIngredient(ModContent.ItemType(), 4); + recipe.AddTile(ModContent.TileType()); recipe.SetResult(this); recipe.AddRecipe(); } diff --git a/Items/Weapons/Summon/FlowersOfMortality.cs b/Items/Weapons/Summon/FlowersOfMortality.cs index 8020b91c54..02aa74bf4e 100644 --- a/Items/Weapons/Summon/FlowersOfMortality.cs +++ b/Items/Weapons/Summon/FlowersOfMortality.cs @@ -13,7 +13,7 @@ namespace CalamityMod.Items.Weapons.Summon { DisplayName.SetDefault("Flowers of Mortality"); Tooltip.SetDefault("Summons five rainbow flowers over your head\n" + - "The combined flowers consume three minion slots"); + "The combined flowers consume two and a half minion slots"); } public override void SetDefaults() diff --git a/Items/Weapons/Summon/MidnightSunBeacon.cs b/Items/Weapons/Summon/MidnightSunBeacon.cs index 447091eaa0..0b832294e5 100644 --- a/Items/Weapons/Summon/MidnightSunBeacon.cs +++ b/Items/Weapons/Summon/MidnightSunBeacon.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetDefaults() { - item.damage = 96; + item.damage = 91; item.mana = 12; item.width = item.height = 32; item.useTime = item.useAnimation = 10; diff --git a/Items/Weapons/Summon/VoidConcentrationStaff.cs b/Items/Weapons/Summon/VoidConcentrationStaff.cs new file mode 100644 index 0000000000..f7fc78b653 --- /dev/null +++ b/Items/Weapons/Summon/VoidConcentrationStaff.cs @@ -0,0 +1,66 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + class VoidConcentrationStaff : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Void Concentration Staff"); + Tooltip.SetDefault("Summons a foreboding aura\n" + //If you have flavour text ideas, feel free to implement, my brain is still like nonexistant as per usual yeah. + "Requires three minion slots to use\n" + + "Only one may exist\n" + + "Right click to launch a black hole that grows in size"); + } + + public override void SetDefaults() + { + item.width = 52; + item.height = 72; + item.useStyle = ItemUseStyleID.SwingThrow; + item.noMelee = true; + item.UseSound = SoundID.DD2_EtherianPortalOpen; + item.summon = true; + + item.mana = 100; + item.damage = 150; + item.knockBack = 4f; + item.useTime = item.useAnimation = 10; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 10f; + + item.value = CalamityGlobalItem.RarityPureGreenBuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.PureGreen; + } + + public override bool CanUseItem(Player player) + { + if (player.altFunctionUse != 2) + return player.ownedProjectileCounts[ModContent.ProjectileType()] == 0; + return base.CanUseItem(player); + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.altFunctionUse != 2) + { + Projectile.NewProjectile(player.Center, Vector2.Zero, type, damage, knockBack, player.whoAmI, 0f); + player.AddBuff(ModContent.BuffType(), 120); + } + return false; + } + + public override bool AltFunctionUse(Player player) + { + return base.AltFunctionUse(player); + } + } +} diff --git a/Items/Weapons/Summon/VoidConcentrationStaff.png b/Items/Weapons/Summon/VoidConcentrationStaff.png new file mode 100644 index 0000000000..d1cf945db4 Binary files /dev/null and b/Items/Weapons/Summon/VoidConcentrationStaff.png differ diff --git a/NPCs/AstrumAureus/AstrumAureus.cs b/NPCs/AstrumAureus/AstrumAureus.cs index 1782798cc0..c3b4448cbb 100644 --- a/NPCs/AstrumAureus/AstrumAureus.cs +++ b/NPCs/AstrumAureus/AstrumAureus.cs @@ -354,7 +354,7 @@ namespace CalamityMod.NPCs.AstrumAureus } // Drop an Astral Meteor if applicable - ThreadPool.QueueUserWorkItem(WorldGenerationMethods.AstralMeteorThreadWrapper); + ThreadPool.QueueUserWorkItem(_ => AstralBiome.PlaceAstralMeteor()); // If Astrum Aureus has not yet been killed, notify players of new Astral enemy drops if (!CalamityWorld.downedAstrageldon) diff --git a/NPCs/CalamityAI.cs b/NPCs/CalamityAI.cs index f65507dcf2..c7eecb2474 100644 --- a/NPCs/CalamityAI.cs +++ b/NPCs/CalamityAI.cs @@ -1540,7 +1540,7 @@ namespace CalamityMod.NPCs if (calamityGlobalNPC.newAI[2] == 2f) { int type = ModContent.ProjectileType(); - int damage = npc.GetProjectileDamage(type); + int damage = npc.GetProjectileDamage(type) + (provy ? 30 : 0); float gigaBlastFrequency = (expertMode ? 180f : 240f) - enrageScale * 15f; float projSpeed = malice ? 6.25f : 5f; if (calamityGlobalNPC.newAI[3] <= 300f) @@ -1566,7 +1566,7 @@ namespace CalamityMod.NPCs { npc.ai[0] = 0f; int type = ModContent.ProjectileType(); - int damage = npc.GetProjectileDamage(type); + int damage = npc.GetProjectileDamage(type) + (provy ? 30 : 0); float projSpeed = malice ? 5f : 4f; if (calamityGlobalNPC.newAI[3] % (hellblastGateValue * 6f) == 0f) { @@ -4071,6 +4071,9 @@ namespace CalamityMod.NPCs Player player = Main.player[npc.target]; + // Speed enrage + bool moveVeryFast = Vector2.Distance(npc.Center, player.Center) > 960f || (!player.ZoneDungeon && !BossRushEvent.BossRushActive && player.position.Y < Main.worldSurface * 16.0); + // Despawn if (!player.active || player.dead || Vector2.Distance(player.Center, vector) > 5600f) { @@ -4405,10 +4408,8 @@ namespace CalamityMod.NPCs // Basic movement towards a location void Movement(bool succ) { - float velocity = (!player.ZoneDungeon || BossRushEvent.BossRushActive) ? 25f : ((expertMode ? 7.5f : 6f) + (float)(death ? 2f * (1D - lifeRatio) : 0f)) * tileEnrageMult; - float acceleration = malice ? 0.3f : death ? 0.2f : expertMode ? 0.16f : 0.12f; - if (!player.ZoneDungeon || BossRushEvent.BossRushActive) - velocity = expertMode ? 25f : 20f; + float velocity = moveVeryFast ? 25f : BossRushEvent.BossRushActive ? 15f : ((expertMode ? 7.5f : 6f) + (float)(death ? 2f * (1D - lifeRatio) : 0f)) * tileEnrageMult; + float acceleration = moveVeryFast ? 0.75f : malice ? 0.3f : death ? 0.2f : expertMode ? 0.16f : 0.12f; // Increase speed dramatically in succ phase if (succ) diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index fe3ee4c34a..34d75aec1c 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -3204,7 +3204,7 @@ namespace CalamityMod.NPCs if (npc.type != NPCType() && npc.type != NPCType() && npc.type != NPCType() && npc.type != NPCType() && npc.type != NPCType() && npc.type != NPCType() && - npc.type != NPCType() && npc.type != NPCType() && + npc.type != NPCType() && npc.type != NPCType() && npc.type != NPCType()) { npc.active = false; @@ -3789,8 +3789,12 @@ namespace CalamityMod.NPCs else if (projectile.type == ProjectileType() || projectile.type == ProjectileType()) damage = (int)(damage * 0.75); } - else if (npc.type == NPCType()) + else if (npc.type == NPCType()) { + // 30% resist to Surge Driver's alt click comets. + if (projectile.type == ProjectileType()) + damage = (int)(damage * 0.7); + // 20% resist to Executioner's Blade stealth strikes. if (projectile.type == ProjectileType()) damage = (int)(damage * 0.8); @@ -3891,6 +3895,10 @@ namespace CalamityMod.NPCs // 10% resist to Executioner's Blade stealth strikes. else if (projectile.type == ProjectileType()) damage = (int)(damage * 0.9); + + // 10% resist to Surge Driver's alt click comets. + if (projectile.type == ProjectileType()) + damage = (int)(damage * 0.9); } else if (npc.type == NPCID.CultistBoss) { diff --git a/NPCs/CalamityGlobalNPCLoot.cs b/NPCs/CalamityGlobalNPCLoot.cs index adb1b20baa..c6e492d9b8 100644 --- a/NPCs/CalamityGlobalNPCLoot.cs +++ b/NPCs/CalamityGlobalNPCLoot.cs @@ -17,6 +17,7 @@ using CalamityMod.NPCs.SulphurousSea; using CalamityMod.NPCs.TownNPCs; using CalamityMod.Tiles.Ores; using CalamityMod.World; +using CalamityMod.World.Planets; using Microsoft.Xna.Framework; using System.Threading; using Terraria; @@ -211,8 +212,8 @@ namespace CalamityMod.NPCs { string key3 = "Mods.CalamityMod.HardmodeOreTier1Text"; Color messageColor3 = new Color(50, 255, 130); - WorldGenerationMethods.SpawnOre(TileID.Cobalt, 12E-05, .4f, .6f); - WorldGenerationMethods.SpawnOre(TileID.Palladium, 12E-05, .4f, .6f); + CalamityUtils.SpawnOre(TileID.Cobalt, 12E-05, 0.4f, 0.6f, 3, 8); + CalamityUtils.SpawnOre(TileID.Palladium, 12E-05, 0.4f, 0.6f, 3, 8); CalamityUtils.DisplayLocalizedText(key3, messageColor3); } } @@ -316,7 +317,7 @@ namespace CalamityMod.NPCs string key3 = "Mods.CalamityMod.SandSharkText3"; Color messageColor3 = Color.Goldenrod; - WorldGenerationMethods.SpawnOre(ModContent.TileType(), 12E-05, .5f, .7f); + CalamityUtils.SpawnOre(ModContent.TileType(), 12E-05, 0.5f, 0.7f, 3, 8, TileID.Dirt, TileID.Stone); CalamityUtils.DisplayLocalizedText(key2, messageColor2); CalamityUtils.DisplayLocalizedText(key3, messageColor3); @@ -499,7 +500,7 @@ namespace CalamityMod.NPCs // This operation is done on a separate thread to lighten the load on servers so that they // can focus on more critical operations asychronously and ideally avoid a time-out crash. // Very few operations in Terraria utilize the pool, so it is highly unlikely that no threads will remain in it. - ThreadPool.QueueUserWorkItem(_ => WorldGenerationMethods.GenerateLuminitePlanetoids()); + ThreadPool.QueueUserWorkItem(_ => LuminitePlanet.GenerateLuminitePlanetoids()); CalamityWorld.HasGeneratedLuminitePlanetoids = true; @@ -605,23 +606,23 @@ namespace CalamityMod.NPCs { string key = "Mods.CalamityMod.HardmodeOreTier2Text"; Color messageColor = new Color(50, 255, 130); - WorldGenerationMethods.SpawnOre(TileID.Mythril, 12E-05, .5f, .7f); - WorldGenerationMethods.SpawnOre(TileID.Orichalcum, 12E-05, .5f, .7f); + CalamityUtils.SpawnOre(TileID.Mythril, 12E-05, 0.5f, 0.7f, 3, 8); + CalamityUtils.SpawnOre(TileID.Orichalcum, 12E-05, 0.5f, 0.7f, 3, 8); CalamityUtils.DisplayLocalizedText(key, messageColor); } else if ((!NPC.downedMechBoss1 && !NPC.downedMechBoss2) || (!NPC.downedMechBoss2 && !NPC.downedMechBoss3) || (!NPC.downedMechBoss3 && !NPC.downedMechBoss1)) { string key = "Mods.CalamityMod.HardmodeOreTier3Text"; Color messageColor = new Color(50, 255, 130); - WorldGenerationMethods.SpawnOre(TileID.Adamantite, 12E-05, .6f, .8f); - WorldGenerationMethods.SpawnOre(TileID.Titanium, 12E-05, .6f, .8f); + CalamityUtils.SpawnOre(TileID.Adamantite, 12E-05, 0.6f, 0.8f, 3, 8); + CalamityUtils.SpawnOre(TileID.Titanium, 12E-05, 0.6f, 0.8f, 3, 8); CalamityUtils.DisplayLocalizedText(key, messageColor); } else { string key = "Mods.CalamityMod.HardmodeOreTier4Text"; Color messageColor = new Color(50, 255, 130); - WorldGenerationMethods.SpawnOre(ModContent.TileType(), 12E-05, .45f, .8f); + CalamityUtils.SpawnOre(ModContent.TileType(), 12E-05, 0.45f, 0.8f, 3, 8, TileID.Pearlstone, TileID.HallowHardenedSand, TileID.HallowSandstone, TileID.HallowedIce); CalamityUtils.DisplayLocalizedText(key, messageColor); } } diff --git a/NPCs/CeaselessVoid/CeaselessVoid.cs b/NPCs/CeaselessVoid/CeaselessVoid.cs index 6e040ed565..3ba094cea9 100644 --- a/NPCs/CeaselessVoid/CeaselessVoid.cs +++ b/NPCs/CeaselessVoid/CeaselessVoid.cs @@ -7,6 +7,7 @@ using CalamityMod.Items.Placeables.Furniture.Trophies; using CalamityMod.Items.Potions; using CalamityMod.Items.TreasureBags; using CalamityMod.Items.Weapons.Melee; +using CalamityMod.Items.Weapons.Summon; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -172,11 +173,13 @@ namespace CalamityMod.NPCs.CeaselessVoid // Materials DropHelper.DropItem(npc, ModContent.ItemType(), true, 2, 3); - // Weapons - DropHelper.DropItemChance(npc, ModContent.ItemType(), 4); + // Weapons + float dropChance = DropHelper.NormalWeaponDropRateFloat; + DropHelper.DropItemChance(npc, ModContent.ItemType(), dropChance); + DropHelper.DropItemChance(npc, ModContent.ItemType(), dropChance); - // Equipment - DropHelper.DropItemChance(npc, ModContent.ItemType(), 2); + // Equipment + DropHelper.DropItemChance(npc, ModContent.ItemType(), 2); // Vanity DropHelper.DropItemChance(npc, ModContent.ItemType(), 7); diff --git a/NPCs/Cryogen/Cryogen.cs b/NPCs/Cryogen/Cryogen.cs index e7f6f32399..e10ef43cdd 100644 --- a/NPCs/Cryogen/Cryogen.cs +++ b/NPCs/Cryogen/Cryogen.cs @@ -12,6 +12,7 @@ using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; using CalamityMod.NPCs.TownNPCs; using CalamityMod.Projectiles.Boss; +using CalamityMod.Tiles.AstralSnow; using CalamityMod.Tiles.Ores; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -1130,7 +1131,7 @@ namespace CalamityMod.NPCs.Cryogen { string key = "Mods.CalamityMod.IceOreText"; Color messageColor = Color.LightSkyBlue; - WorldGenerationMethods.SpawnOre(ModContent.TileType(), 15E-05, .45f, .65f); + CalamityUtils.SpawnOre(ModContent.TileType(), 15E-05, 0.45f, 0.65f, 3, 8, TileID.SnowBlock, TileID.IceBlock, TileID.CorruptIce, TileID.FleshIce, TileID.HallowedIce, ModContent.TileType(), ModContent.TileType()); CalamityUtils.DisplayLocalizedText(key, messageColor); } diff --git a/NPCs/ExoMechs/Ares/AresArmSegment.png b/NPCs/ExoMechs/Ares/AresArmSegment.png new file mode 100644 index 0000000000..120a62d7c5 Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresArmSegment.png differ diff --git a/NPCs/ExoMechs/Ares/AresArmSegment_Glow.png b/NPCs/ExoMechs/Ares/AresArmSegment_Glow.png new file mode 100644 index 0000000000..981953b1a8 Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresArmSegment_Glow.png differ diff --git a/NPCs/ExoMechs/Ares/AresBody.png b/NPCs/ExoMechs/Ares/AresBody.png new file mode 100644 index 0000000000..9afc594413 Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresBody.png differ diff --git a/NPCs/ExoMechs/Ares/AresBody_Glow.png b/NPCs/ExoMechs/Ares/AresBody_Glow.png new file mode 100644 index 0000000000..571a6d1d12 Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresBody_Glow.png differ diff --git a/NPCs/ExoMechs/Ares/AresGaussNuke.png b/NPCs/ExoMechs/Ares/AresGaussNuke.png new file mode 100644 index 0000000000..d254768bbc Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresGaussNuke.png differ diff --git a/NPCs/ExoMechs/Ares/AresGaussNuke_Glow.png b/NPCs/ExoMechs/Ares/AresGaussNuke_Glow.png new file mode 100644 index 0000000000..9d00e32599 Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresGaussNuke_Glow.png differ diff --git a/NPCs/ExoMechs/Ares/AresLaserCannon.png b/NPCs/ExoMechs/Ares/AresLaserCannon.png new file mode 100644 index 0000000000..ebf74ef98d Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresLaserCannon.png differ diff --git a/NPCs/ExoMechs/Ares/AresLaserCannon_Glow.png b/NPCs/ExoMechs/Ares/AresLaserCannon_Glow.png new file mode 100644 index 0000000000..18300268b4 Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresLaserCannon_Glow.png differ diff --git a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.png b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.png new file mode 100644 index 0000000000..ccd01b0530 Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.png differ diff --git a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower_Glow.png b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower_Glow.png new file mode 100644 index 0000000000..2cd39ab62b Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower_Glow.png differ diff --git a/NPCs/ExoMechs/Ares/AresTeslaCannon.png b/NPCs/ExoMechs/Ares/AresTeslaCannon.png new file mode 100644 index 0000000000..c06ebefe0d Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresTeslaCannon.png differ diff --git a/NPCs/ExoMechs/Ares/AresTeslaCannon_Glow.png b/NPCs/ExoMechs/Ares/AresTeslaCannon_Glow.png new file mode 100644 index 0000000000..421c3f914a Binary files /dev/null and b/NPCs/ExoMechs/Ares/AresTeslaCannon_Glow.png differ diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody1Glow.png b/NPCs/ExoMechs/Thanatos/ThanatosBody1Glow.png index cfa0941d35..74f921332d 100644 Binary files a/NPCs/ExoMechs/Thanatos/ThanatosBody1Glow.png and b/NPCs/ExoMechs/Thanatos/ThanatosBody1Glow.png differ diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody2Glow.png b/NPCs/ExoMechs/Thanatos/ThanatosBody2Glow.png index 8fea258abe..34dc02d5b3 100644 Binary files a/NPCs/ExoMechs/Thanatos/ThanatosBody2Glow.png and b/NPCs/ExoMechs/Thanatos/ThanatosBody2Glow.png differ diff --git a/NPCs/ExoMechs/Thanatos/ThanatosHeadGlow.png b/NPCs/ExoMechs/Thanatos/ThanatosHeadGlow.png index b4a0e95b3b..477da0aa63 100644 Binary files a/NPCs/ExoMechs/Thanatos/ThanatosHeadGlow.png and b/NPCs/ExoMechs/Thanatos/ThanatosHeadGlow.png differ diff --git a/NPCs/ExoMechs/Thanatos/ThanatosTailGlow.png b/NPCs/ExoMechs/Thanatos/ThanatosTailGlow.png index 54a5e2ecaf..8e758d699b 100644 Binary files a/NPCs/ExoMechs/Thanatos/ThanatosTailGlow.png and b/NPCs/ExoMechs/Thanatos/ThanatosTailGlow.png differ diff --git a/NPCs/HiveMind/HiveMindP2.cs b/NPCs/HiveMind/HiveMindP2.cs index fc85ac2df0..6252f0f07e 100644 --- a/NPCs/HiveMind/HiveMindP2.cs +++ b/NPCs/HiveMind/HiveMindP2.cs @@ -799,7 +799,7 @@ namespace CalamityMod.NPCs.HiveMind { string key = "Mods.CalamityMod.SkyOreText"; Color messageColor = Color.Cyan; - WorldGenerationMethods.SpawnOre(ModContent.TileType(), 12E-05, .4f, .6f); + CalamityUtils.SpawnOre(ModContent.TileType(), 12E-05, 0.4f, 0.6f, 3, 8); CalamityUtils.DisplayLocalizedText(key, messageColor); } diff --git a/NPCs/Perforator/PerforatorHive.cs b/NPCs/Perforator/PerforatorHive.cs index 52221159cb..1609be03fa 100644 --- a/NPCs/Perforator/PerforatorHive.cs +++ b/NPCs/Perforator/PerforatorHive.cs @@ -493,7 +493,7 @@ namespace CalamityMod.NPCs.Perforator { string key = "Mods.CalamityMod.SkyOreText"; Color messageColor = Color.Cyan; - WorldGenerationMethods.SpawnOre(ModContent.TileType(), 12E-05, .4f, .6f); + CalamityUtils.SpawnOre(ModContent.TileType(), 12E-05, 0.4f, 0.6f, 3, 8); CalamityUtils.DisplayLocalizedText(key, messageColor); } diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 996af43130..63637d44e3 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -277,10 +277,10 @@ namespace CalamityMod.NPCs.Providence { if (!player.dead && player.active) player.AddBuff(ModContent.BuffType(), 2); - } + } - // Count the remaining Guardians, healer especially because it allows the boss to heal - int guardianAmt = 0; + // Count the remaining Guardians, healer especially because it allows the boss to heal + int guardianAmt = 0; bool healerAlive = false; if (CalamityGlobalNPC.holyBossAttacker != -1) { @@ -1276,6 +1276,43 @@ namespace CalamityMod.NPCs.Providence } } + public float CalculateBurnIntensity() + { + float distanceToTarget = Vector2.Distance(Main.player[npc.target].Center, npc.Center); + float aiTimer = npc.ai[3]; + + float baseDistance = 2800f; + float shorterFlameCocoonDistance = (CalamityWorld.death || CalamityWorld.malice || !Main.dayTime) ? 600f : CalamityWorld.revenge ? 400f : Main.expertMode ? 200f : 0f; + float shorterSpearCocoonDistance = (CalamityWorld.death || CalamityWorld.malice || !Main.dayTime) ? 1000f : CalamityWorld.revenge ? 650f : Main.expertMode ? 300f : 0f; + float shorterDistance = AIState == (int)Phase.FlameCocoon ? shorterFlameCocoonDistance : shorterSpearCocoonDistance; + + bool guardianAlive = false; + if (CalamityGlobalNPC.holyBossAttacker != -1 && Main.npc[CalamityGlobalNPC.holyBossAttacker].active) + guardianAlive = true; + + if (CalamityGlobalNPC.holyBossDefender != -1 && Main.npc[CalamityGlobalNPC.holyBossDefender].active) + guardianAlive = true; + + if (CalamityGlobalNPC.holyBossHealer != -1 && Main.npc[CalamityGlobalNPC.holyBossHealer].active) + guardianAlive = true; + + float maxDistance = baseDistance; + + // A factor which measures how much of the distance shortening shave-off should be taken into account. + // It is determined based on how much time has elapsed during the attack thus far, specifically for the two cocoon attacks. + // This shave-off does not happen when guardians are present. + float shorterDistanceFade = Utils.InverseLerp(0f, 120f, aiTimer, true); + if (!guardianAlive) + { + maxDistance = baseDistance; + if (AIState == (int)Phase.FlameCocoon || AIState == (int)Phase.SpearCocoon) + maxDistance -= shorterDistance * shorterDistanceFade; + } + + float drawFireDistanceStart = maxDistance - 800f; + return Utils.InverseLerp(drawFireDistanceStart, maxDistance, distanceToTarget, true); + } + private void DespawnSpecificProjectiles() { for (int x = 0; x < Main.maxProjectiles; x++) @@ -1356,7 +1393,7 @@ namespace CalamityMod.NPCs.Providence string key3 = "Mods.CalamityMod.TreeOreText"; Color messageColor3 = Color.LightGreen; - WorldGenerationMethods.SpawnOre(ModContent.TileType(), 15E-05, .4f, .8f); + CalamityUtils.SpawnOre(ModContent.TileType(), 15E-05, 0.4f, 0.8f, 3, 8, TileID.Mud); CalamityUtils.DisplayLocalizedText(key2, messageColor2); CalamityUtils.DisplayLocalizedText(key3, messageColor3); diff --git a/NPCs/SupremeCalamitas/SCalWormHeart.cs b/NPCs/SupremeCalamitas/BrimstoneHeart.cs similarity index 82% rename from NPCs/SupremeCalamitas/SCalWormHeart.cs rename to NPCs/SupremeCalamitas/BrimstoneHeart.cs index 43ea6157ca..ed6df8c4bc 100644 --- a/NPCs/SupremeCalamitas/SCalWormHeart.cs +++ b/NPCs/SupremeCalamitas/BrimstoneHeart.cs @@ -10,7 +10,7 @@ using Terraria.ModLoader; namespace CalamityMod.NPCs.SupremeCalamitas { - public class SCalWormHeart : ModNPC + public class BrimstoneHeart : ModNPC { public PrimitiveTrail ChainDrawer = null; public int ChainHeartIndex => (int)npc.ai[0]; @@ -18,6 +18,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas public override void SetStaticDefaults() { DisplayName.SetDefault("Brimstone Heart"); + Main.npcFrameCount[npc.type] = 6; } public override void SetDefaults() @@ -49,7 +50,8 @@ namespace CalamityMod.NPCs.SupremeCalamitas public override void ReceiveExtraAI(BinaryReader reader) { ChainEndpoints.Clear(); - for (int i = 0; i < reader.ReadInt32(); i++) + int endpointCount = reader.ReadInt32(); + for (int i = 0; i < endpointCount; i++) ChainEndpoints.Add(reader.ReadVector2()); } @@ -72,7 +74,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas float widthInterpolant = Utils.InverseLerp(0f, 0.16f, completionRatio, true) * Utils.InverseLerp(1f, 0.84f, completionRatio, true); widthInterpolant = (float)Math.Pow(widthInterpolant, 8D); float baseWidth = MathHelper.Lerp(4f, 1f, widthInterpolant); - float pulseWidth = MathHelper.Lerp(0f, 3.2f, (float)Math.Pow(Math.Sin(Main.GlobalTime * 4.4f + npc.whoAmI * 1.3f + completionRatio), 16D)); + float pulseWidth = MathHelper.Lerp(0f, 3.2f, (float)Math.Pow(Math.Sin(Main.GlobalTime * 2.6f + npc.whoAmI * 1.3f + completionRatio), 16D)); return baseWidth + pulseWidth; } @@ -82,6 +84,14 @@ namespace CalamityMod.NPCs.SupremeCalamitas return Color.Lerp(Color.DarkRed * 0.7f, Color.Red, colorInterpolant) * 0.425f; } + public override void FindFrame(int frameHeight) + { + int frame = (int)Math.Round((float)Math.Pow(Math.Sin(Main.GlobalTime * 2.6f + npc.whoAmI * 1.3f), 6D) * Main.npcFrameCount[npc.type]); + if (frame >= Main.npcFrameCount[npc.type]) + frame = Main.npcFrameCount[npc.type] - 1; + npc.frame.Y = frame * frameHeight; + } + public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor) { if (ChainDrawer is null) @@ -114,6 +124,11 @@ namespace CalamityMod.NPCs.SupremeCalamitas { if (npc.life <= 0) { + for (int i = 1; i <= 2; i++) + { + Vector2 heartGoreVelocity = new Vector2((i == 1).ToDirectionInt() * 3f, Main.rand.NextFloat(-2f, 0f)); + Gore.NewGorePerfect(npc.Center, heartGoreVelocity, mod.GetGoreSlot($"Gores/SupremeCalamitas/BrimstoneHeart_Gore{i}"), npc.scale); + } for (int i = 0; i < ChainEndpoints.Count; i++) TendrilDestructionEffects(i); } diff --git a/NPCs/SupremeCalamitas/BrimstoneHeart.png b/NPCs/SupremeCalamitas/BrimstoneHeart.png new file mode 100644 index 0000000000..c597cfe505 Binary files /dev/null and b/NPCs/SupremeCalamitas/BrimstoneHeart.png differ diff --git a/NPCs/SupremeCalamitas/SCalSky.cs b/NPCs/SupremeCalamitas/SCalSky.cs deleted file mode 100644 index bf4233d713..0000000000 --- a/NPCs/SupremeCalamitas/SCalSky.cs +++ /dev/null @@ -1,107 +0,0 @@ -using CalamityMod.Projectiles.Boss; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Graphics.Effects; -using Terraria.ModLoader; - -namespace CalamityMod.NPCs.SupremeCalamitas -{ - public class SCalSky : CustomSky - { - private bool isActive = false; - private float intensity = 0f; - private int SCalIndex = -1; - public static float OverridingIntensity = 0f; - - public override void Update(GameTime gameTime) - { - if (isActive && intensity < 1f) - { - intensity += 0.01f; - } - else if (!isActive && intensity > 0f) - { - intensity -= 0.01f; - } - } - - private float GetIntensity() - { - if (CalamityUtils.CountProjectiles(ModContent.ProjectileType()) > 0) - return OverridingIntensity; - - OverridingIntensity = 0f; - if (this.UpdateSCalIndex()) - { - float x = 0f; - if (this.SCalIndex != -1) - { - x = Vector2.Distance(Main.player[Main.myPlayer].Center, Main.npc[this.SCalIndex].Center); - } - return 1f - Utils.SmoothStep(3000f, 6000f, x); - } - return 0f; - } - - public override Color OnTileColor(Color inColor) - { - float intensity = this.GetIntensity(); - return new Color(Vector4.Lerp(new Vector4(0.5f, 0.8f, 1f, 1f), inColor.ToVector4(), 1f - intensity)); - } - - private bool UpdateSCalIndex() - { - int SCalType = ModContent.NPCType(); - if (SCalIndex >= 0 && Main.npc[SCalIndex].active && Main.npc[SCalIndex].type == SCalType) - { - return true; - } - SCalIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == SCalType) - { - SCalIndex = i; - break; - } - } - //this.DoGIndex = DoGIndex; - return SCalIndex != -1; - } - - public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) - { - if (maxDepth >= 0 && minDepth < 0) - { - float intensity = this.GetIntensity(); - spriteBatch.Draw(Main.blackTileTexture, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.Black * intensity); - } - } - - public override float GetCloudAlpha() - { - return 0f; - } - - public override void Activate(Vector2 position, params object[] args) - { - isActive = true; - } - - public override void Deactivate(params object[] args) - { - isActive = false; - } - - public override void Reset() - { - isActive = false; - } - - public override bool IsActive() - { - return isActive || intensity > 0f; - } - } -} diff --git a/NPCs/SupremeCalamitas/SCalWormArm.cs b/NPCs/SupremeCalamitas/SCalWormArm.cs new file mode 100644 index 0000000000..126860646d --- /dev/null +++ b/NPCs/SupremeCalamitas/SCalWormArm.cs @@ -0,0 +1,217 @@ +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.SupremeCalamitas +{ + public class SCalWormArm : ModNPC + { + public class SepulcherArmLimb + { + public Vector2 Center; + public float Rotation; + + public SepulcherArmLimb(Vector2 center, float rotation) + { + Center = center; + Rotation = rotation; + } + + public void SendData(BinaryWriter writer) + { + writer.WritePackedVector2(Center); + writer.Write(Rotation); + } + + public void ReceiveData(BinaryReader reader) + { + Center = reader.ReadPackedVector2(); + Rotation = reader.ReadSingle(); + } + } + + public NPC SegmentToAttachTo => Main.npc[(int)npc.ai[0]]; + public bool CurrentlyMoving + { + get => npc.ai[1] == 1f; + set => npc.ai[1] = value.ToInt(); + } + public Vector2 MoveDestination + { + get => new Vector2(npc.ai[2], npc.ai[3]); + set + { + npc.ai[2] = value.X; + npc.ai[3] = value.Y; + } + } + public ref float Time => ref npc.localAI[0]; + public bool ReelingBack + { + get => npc.localAI[1] == 0f; + set => npc.localAI[1] = 1f - value.ToInt(); + } + public Player Target => Main.player[npc.target]; + public SepulcherArmLimb[] Limbs = new SepulcherArmLimb[4]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sepulcher"); + } + + public override void SetDefaults() + { + npc.damage = 0; + npc.npcSlots = 5f; + npc.width = 34; + npc.height = 48; + npc.defense = 0; + CalamityGlobalNPC global = npc.Calamity(); + global.DR = 0.999999f; + global.unbreakableDR = true; + npc.lifeMax = CalamityWorld.revenge ? 345000 : 300000; + npc.aiStyle = aiType = -1; + npc.knockBackResist = 0f; + npc.scale = Main.expertMode ? 1.35f : 1.2f; + npc.dontTakeDamage = true; + npc.alpha = 255; + npc.chaseable = false; + npc.behindTiles = true; + npc.noGravity = true; + npc.noTileCollide = true; + npc.canGhostHeal = false; + npc.netAlways = true; + npc.dontCountMe = true; + + for (int i = 0; i < Limbs.Length; i++) + Limbs[i] = new SepulcherArmLimb(npc.Center, 0f); + } + + public override void SendExtraAI(BinaryWriter writer) + { + for (int i = 0; i < Limbs.Length; i++) + Limbs[i].SendData(writer); + writer.Write(npc.rotation); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + for (int i = 0; i < Limbs.Length; i++) + Limbs[i].ReceiveData(reader); + npc.rotation = reader.ReadSingle(); + } + + public override void AI() + { + // Die if the segment is not present. + if (!Main.npc.IndexInRange((int)npc.ai[0]) || !Main.npc[(int)npc.ai[0]].active) + { + npc.life = 0; + npc.HitEffect(0, 10.0); + npc.checkDead(); + return; + } + + npc.Opacity = SegmentToAttachTo.Opacity; + npc.TargetClosest(false); + + Vector2 idealMovePosition = SegmentToAttachTo.Center; + float sideFactor = MathHelper.Lerp(200f, 18f, Utils.InverseLerp(-0.51f, -0.06f, npc.rotation, true)); + float aheadFactor = MathHelper.Lerp(284f, 680f, Utils.InverseLerp(-0.51f, -0.06f, npc.rotation, true)); + idealMovePosition += (SegmentToAttachTo.rotation + npc.rotation * npc.direction - MathHelper.PiOver2).ToRotationVector2() * npc.scale * aheadFactor; + idealMovePosition += (SegmentToAttachTo.rotation + npc.rotation * npc.direction - MathHelper.PiOver2 + MathHelper.PiOver2 * npc.direction).ToRotationVector2() * npc.scale * sideFactor; + npc.Center = idealMovePosition; + UpdateLimbs(); + + if (ReelingBack) + { + npc.rotation -= 0.066f; + if (npc.rotation < -0.55f) + ReelingBack = false; + } + else + { + npc.rotation += 0.029f; + if (npc.rotation > 0.77f) + ReelingBack = true; + } + + Time++; + } + + public void MoveToDestination() + { + npc.Center = Vector2.Lerp(npc.Center, MoveDestination, 0.05f); + npc.Center = npc.Center.MoveTowards(MoveDestination, 10f); + + // Stop moving if sufficiently close to the desired destination. + if (npc.WithinRange(MoveDestination, 15f)) + { + npc.Center = MoveDestination; + MoveDestination = Vector2.Zero; + CurrentlyMoving = false; + npc.netUpdate = true; + } + } + + public void UpdateLimbs() + { + Vector2 offsetFromSegment = Vector2.Zero; + + offsetFromSegment += new Vector2(npc.direction * 60f, 55f).RotatedBy(SegmentToAttachTo.rotation - (MathHelper.PiOver2 - npc.rotation * 1.7f - 0.77f) * npc.direction).SafeNormalize(Vector2.UnitY) * 92f; + Limbs[0].Center = SegmentToAttachTo.Center + offsetFromSegment; + Limbs[0].Rotation = offsetFromSegment.ToRotation(); + + Limbs[1].Rotation = npc.AngleFrom(Limbs[0].Center); + Limbs[1].Center = Limbs[0].Center + offsetFromSegment * 0.5f + (npc.Center - Limbs[0].Center).SafeNormalize(Vector2.UnitY) * 84f; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D armTexture = Main.npcTexture[npc.type]; + Texture2D foreArmTexture = ModContent.GetTexture("CalamityMod/NPCs/SupremeCalamitas/SCalWormForeArm"); + Texture2D handTexture = ModContent.GetTexture("CalamityMod/NPCs/SupremeCalamitas/SCalWormHand"); + + Vector2 forearmDrawPosition = Limbs[0].Center - Main.screenPosition; + Color drawColor = Lighting.GetColor((int)(Limbs[0].Center.X / 16), (int)(Limbs[0].Center.Y / 16)); + spriteBatch.Draw(foreArmTexture, forearmDrawPosition, null, drawColor, Limbs[0].Rotation + MathHelper.PiOver2, foreArmTexture.Size() * 0.5f, npc.scale, SpriteEffects.None, 0f); + + Vector2 armDrawPosition = Limbs[1].Center - Main.screenPosition; + drawColor = Lighting.GetColor((int)(Limbs[1].Center.X / 16), (int)(Limbs[1].Center.Y / 16)); + spriteBatch.Draw(armTexture, armDrawPosition, null, drawColor, Limbs[1].Rotation + MathHelper.PiOver2, armTexture.Size() * new Vector2(0.5f, 0f), npc.scale, SpriteEffects.FlipVertically, 0f); + + Vector2 handDrawPosition = armDrawPosition; + SpriteEffects handDirection = npc.direction == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(handTexture, handDrawPosition, null, drawColor, Limbs[1].Rotation - MathHelper.PiOver2, handTexture.Size() * new Vector2(0.5f, 0f), npc.scale, handDirection, 0f); + + return false; + } + + public override void HitEffect(int hitDirection, double damage) + { + if (npc.life <= 0) + { + Vector2 forearmGoreSpawnPosition = Limbs[0].Center + Main.rand.NextVector2Circular(6f, 6f); + Vector2 armGoreSpawnPosition = Limbs[1].Center + Main.rand.NextVector2Circular(6f, 6f); + Vector2 handGoreSpawnPosition = armGoreSpawnPosition + Main.rand.NextVector2Circular(6f, 6f); + + Gore.NewGorePerfect(armGoreSpawnPosition, Main.rand.NextVector2Circular(3f, 3f), mod.GetGoreSlot($"Gores/SupremeCalamitas/SepulcherArm_Gore"), npc.scale); + for (int i = 1; i <= 2; i++) + Gore.NewGorePerfect(forearmGoreSpawnPosition, Main.rand.NextVector2Circular(3f, 3f), mod.GetGoreSlot($"Gores/SupremeCalamitas/SepulcherForearm_Gore{i}"), npc.scale); + for (int i = 1; i <= 2; i++) + Gore.NewGorePerfect(handGoreSpawnPosition, Main.rand.NextVector2Circular(3f, 3f), mod.GetGoreSlot($"Gores/SupremeCalamitas/SepulcherHand_Gore{i}"), npc.scale); + } + } + + public override bool CheckActive() => false; + + public override bool PreNPCLoot() => false; + + public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) => false; + } +} diff --git a/NPCs/SupremeCalamitas/SCalWormArm.png b/NPCs/SupremeCalamitas/SCalWormArm.png new file mode 100644 index 0000000000..b45111f206 Binary files /dev/null and b/NPCs/SupremeCalamitas/SCalWormArm.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormBody.cs b/NPCs/SupremeCalamitas/SCalWormBody.cs index a6265bf8d7..59835db0ec 100644 --- a/NPCs/SupremeCalamitas/SCalWormBody.cs +++ b/NPCs/SupremeCalamitas/SCalWormBody.cs @@ -12,8 +12,10 @@ namespace CalamityMod.NPCs.SupremeCalamitas public class SCalWormBody : ModNPC { private bool setAlpha = false; + public NPC AheadSegment => Main.npc[(int)npc.ai[1]]; + public NPC HeadSegment => Main.npc[(int)npc.ai[2]]; - public override void SetStaticDefaults() + public override void SetStaticDefaults() { DisplayName.SetDefault("Sepulcher"); } @@ -22,8 +24,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas { npc.damage = 0; //70 npc.npcSlots = 5f; - npc.width = 20; //28 - npc.height = 20; //28 + npc.width = npc.height = 48; npc.defense = 0; CalamityGlobalNPC global = npc.Calamity(); global.DR = 0.999999f; @@ -43,8 +44,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas npc.noGravity = true; npc.noTileCollide = true; npc.canGhostHeal = false; - npc.HitSound = SoundID.NPCHit4; - npc.DeathSound = SoundID.NPCDeath14; npc.netAlways = true; npc.dontCountMe = true; } @@ -73,85 +72,49 @@ namespace CalamityMod.NPCs.SupremeCalamitas npc.realLife = (int)npc.ai[2]; } - bool flag = false; - if (npc.ai[1] <= 0f) - { - flag = true; - } - else if (Main.npc[(int)npc.ai[1]].life <= 0 || npc.life <= 0) - { - flag = true; - } - if (flag) - { - npc.life = 0; - npc.HitEffect(0, 10.0); - npc.checkDead(); - } + bool shouldDie = false; + if (npc.ai[1] <= 0f) + shouldDie = true; + else if (AheadSegment.life <= 0 || !AheadSegment.active || npc.life <= 0) + shouldDie = true; - if (Main.npc[(int)npc.ai[1]].alpha < 128 && !setAlpha) - { - if (npc.alpha != 0) - { - for (int num934 = 0; num934 < 2; num934++) - { - int num935 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 182, 0f, 0f, 100, default, 2f); - Main.dust[num935].noGravity = true; - Main.dust[num935].noLight = true; - } - } - npc.alpha -= 42; - if (npc.alpha <= 0) - { - setAlpha = true; - npc.alpha = 0; - } - } - else - { - npc.alpha = Main.npc[(int)npc.ai[2]].alpha; - } + if (shouldDie) + { + npc.life = 0; + npc.HitEffect(0, 10.0); + npc.checkDead(); + } - Vector2 vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num191 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2); - float num192 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2); - num191 = (int)(num191 / 16f) * 16; - num192 = (int)(num192 / 16f) * 16; - vector18.X = (int)(vector18.X / 16f) * 16; - vector18.Y = (int)(vector18.Y / 16f) * 16; - num191 -= vector18.X; - num192 -= vector18.Y; - float num193 = (float)System.Math.Sqrt(num191 * num191 + num192 * num192); - if (npc.ai[1] > 0f && npc.ai[1] < Main.npc.Length) - { - try - { - vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num191 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - vector18.X; - num192 = Main.npc[(int)npc.ai[1]].position.Y + (Main.npc[(int)npc.ai[1]].height / 2) - vector18.Y; - } - catch - { - } - npc.rotation = (float)System.Math.Atan2(num192, num191) + 1.57f; - num193 = (float)System.Math.Sqrt(num191 * num191 + num192 * num192); - int num194 = npc.width; - num193 = (num193 - num194) / num193; - num191 *= num193; - num192 *= num193; - npc.velocity = Vector2.Zero; - npc.position.X = npc.position.X + num191; - npc.position.Y = npc.position.Y + num192; - if (num191 < 0f) - { - npc.spriteDirection = -1; - } - else if (num191 > 0f) - { - npc.spriteDirection = 1; - } - } - } + if (AheadSegment.alpha < 128 && !setAlpha) + { + if (npc.alpha != 0) + { + for (int i = 0; i < 2; i++) + { + Dust fire = Dust.NewDustDirect(npc.position, npc.width, npc.height, 182, 0f, 0f, 100, default, 2f); + fire.noGravity = true; + fire.noLight = true; + } + } + npc.alpha -= 42; + if (npc.alpha <= 0) + { + setAlpha = true; + npc.alpha = 0; + } + } + else + npc.alpha = HeadSegment.alpha; + + if (Main.npc.IndexInRange((int)npc.ai[1])) + { + Vector2 offsetToAheadSegment = AheadSegment.Center - npc.Center; + npc.rotation = offsetToAheadSegment.ToRotation() + MathHelper.PiOver2; + npc.velocity = Vector2.Zero; + npc.Center = AheadSegment.Center - offsetToAheadSegment.SafeNormalize(Vector2.UnitY) * 52f; + npc.spriteDirection = (offsetToAheadSegment.X > 0f).ToDirectionInt(); + } + } public override void ModifyHitByProjectile(Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) { @@ -174,7 +137,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (npc.spriteDirection == 1) spriteEffects = SpriteEffects.FlipHorizontally; - Texture2D texture2D15 = npc.localAI[3] == 1f ? ModContent.GetTexture("CalamityMod/NPCs/SupremeCalamitas/SCalWormBodyAlt") : Main.npcTexture[npc.type]; + Texture2D texture2D15 = npc.localAI[3] / 2f % 2f == 0f ? ModContent.GetTexture("CalamityMod/NPCs/SupremeCalamitas/SCalWormBodyAlt") : Main.npcTexture[npc.type]; Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / 2)); Vector2 vector43 = npc.Center - Main.screenPosition; @@ -182,14 +145,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas vector43 += vector11 * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, spriteEffects, 0f); - if (npc.localAI[3] == 1f) - { - texture2D15 = ModContent.GetTexture("CalamityMod/NPCs/SupremeCalamitas/SCalWormBodyAltGlow"); - Color color37 = Color.Lerp(Color.White, Color.Red, 0.5f); - - spriteBatch.Draw(texture2D15, vector43, npc.frame, color37, npc.rotation, vector11, npc.scale, spriteEffects, 0f); - } - return false; } @@ -207,29 +162,28 @@ namespace CalamityMod.NPCs.SupremeCalamitas { if (npc.life <= 0) { - npc.position.X = npc.position.X + (float)(npc.width / 2); - npc.position.Y = npc.position.Y + (float)(npc.height / 2); - npc.width = 50; - npc.height = 50; - npc.position.X = npc.position.X - (float)(npc.width / 2); - npc.position.Y = npc.position.Y - (float)(npc.height / 2); - for (int num621 = 0; num621 < 5; num621++) + int variant = (int)(npc.localAI[3] / 2f % 2f); + if (variant == 0) { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.NextBool(2)) + for (int i = 1; i <= 9; i++) { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + if (!Main.rand.NextBool(3)) + continue; + + Vector2 goreSpawnPosition = npc.Center; + Gore.NewGorePerfect(goreSpawnPosition, Main.rand.NextVector2Circular(2f, 2f), mod.GetGoreSlot($"Gores/SupremeCalamitas/SepulcherBody1_Gore{i}"), npc.scale); } } - for (int num623 = 0; num623 < 10; num623++) + else { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); - Main.dust[num624].velocity *= 2f; + for (int i = 1; i <= 7; i++) + { + if (!Main.rand.NextBool(3)) + continue; + + Vector2 goreSpawnPosition = npc.Center; + Gore.NewGorePerfect(goreSpawnPosition, Main.rand.NextVector2Circular(2f, 2f), mod.GetGoreSlot($"Gores/SupremeCalamitas/SepulcherBody2_Gore{i}"), npc.scale); + } } } } diff --git a/NPCs/SupremeCalamitas/SCalWormBody.png b/NPCs/SupremeCalamitas/SCalWormBody.png index 5a37855ad8..5e8b75333e 100644 Binary files a/NPCs/SupremeCalamitas/SCalWormBody.png and b/NPCs/SupremeCalamitas/SCalWormBody.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormBodyAlt.png b/NPCs/SupremeCalamitas/SCalWormBodyAlt.png index 35971e8491..7bddb6f35e 100644 Binary files a/NPCs/SupremeCalamitas/SCalWormBodyAlt.png and b/NPCs/SupremeCalamitas/SCalWormBodyAlt.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormBodyAltGlow.png b/NPCs/SupremeCalamitas/SCalWormBodyAltGlow.png deleted file mode 100644 index 5e4e89bd98..0000000000 Binary files a/NPCs/SupremeCalamitas/SCalWormBodyAltGlow.png and /dev/null differ diff --git a/NPCs/SupremeCalamitas/SCalWormBodyWeak.cs b/NPCs/SupremeCalamitas/SCalWormBodyWeak.cs index 33fa11dda4..913ddad300 100644 --- a/NPCs/SupremeCalamitas/SCalWormBodyWeak.cs +++ b/NPCs/SupremeCalamitas/SCalWormBodyWeak.cs @@ -1,4 +1,5 @@ using CalamityMod.Projectiles.Boss; +using CalamityMod.Projectiles.Typeless; using CalamityMod.World; using Microsoft.Xna.Framework; using System.IO; @@ -11,10 +12,14 @@ namespace CalamityMod.NPCs.SupremeCalamitas public class SCalWormBodyWeak : ModNPC { private bool setAlpha = false; + public NPC AheadSegment => Main.npc[(int)npc.ai[1]]; + public NPC HeadSegment => Main.npc[(int)npc.ai[2]]; + public ref float AttackTimer => ref npc.localAI[0]; public override void SetStaticDefaults() { DisplayName.SetDefault("Brimstone Heart"); + Main.npcFrameCount[npc.type] = 5; } public override void SetDefaults() @@ -27,70 +32,60 @@ namespace CalamityMod.NPCs.SupremeCalamitas npc.aiStyle = -1; aiType = -1; npc.knockBackResist = 0f; - CalamityGlobalNPC global = npc.Calamity(); - global.DR = 0.999999f; - global.unbreakableDR = true; - npc.scale = 1.2f; - if (Main.expertMode) - { - npc.scale = 1.35f; - } + npc.scale = Main.expertMode ? 1.35f : 1.2f; npc.alpha = 255; npc.chaseable = false; npc.behindTiles = true; npc.noGravity = true; npc.noTileCollide = true; npc.canGhostHeal = false; - npc.HitSound = SoundID.NPCHit13; - npc.DeathSound = SoundID.NPCDeath13; npc.netAlways = true; npc.dontCountMe = true; - } + + CalamityGlobalNPC global = npc.Calamity(); + global.DR = 0.999999f; + global.unbreakableDR = true; + } public override void SendExtraAI(BinaryWriter writer) { - writer.Write(npc.localAI[0]); + writer.Write(AttackTimer); writer.Write(setAlpha); } public override void ReceiveExtraAI(BinaryReader reader) { - npc.localAI[0] = reader.ReadSingle(); + AttackTimer = reader.ReadSingle(); setAlpha = reader.ReadBoolean(); } public override void AI() { if (npc.ai[2] > 0f) - { npc.realLife = (int)npc.ai[2]; - } - bool flag = false; + bool shouldDie = false; if (npc.ai[1] <= 0f) - { - flag = true; - } - else if (Main.npc[(int)npc.ai[1]].life <= 0 || npc.life <= 0) - { - flag = true; - } - if (flag) + shouldDie = true; + else if (AheadSegment.life <= 0 || !AheadSegment.active || npc.life <= 0) + shouldDie = true; + + if (shouldDie) { npc.life = 0; npc.HitEffect(0, 10.0); npc.checkDead(); } - if (Main.npc[(int)npc.ai[1]].alpha < 128 && !setAlpha) + if (AheadSegment.alpha < 128 && !setAlpha) { if (npc.alpha != 0) { - for (int num934 = 0; num934 < 2; num934++) + for (int i = 0; i < 2; i++) { - int num935 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 182, 0f, 0f, 100, default, 2f); - Main.dust[num935].noGravity = true; - Main.dust[num935].noLight = true; + Dust fire = Dust.NewDustDirect(npc.position, npc.width, npc.height, 182, 0f, 0f, 100, default, 2f); + fire.noGravity = true; + fire.noLight = true; } } npc.alpha -= 42; @@ -101,16 +96,14 @@ namespace CalamityMod.NPCs.SupremeCalamitas } } else - { - npc.alpha = Main.npc[(int)npc.ai[2]].alpha; - } + npc.alpha = HeadSegment.alpha; - if (Main.netMode != NetmodeID.MultiplayerClient) + AttackTimer += CalamityWorld.malice ? 1.5f : 1f; + if (AttackTimer >= 900f) { - npc.localAI[0] += CalamityWorld.malice ? 1.5f : 1f; - if (npc.localAI[0] >= 900f) + AttackTimer = 0f; + if (Main.netMode != NetmodeID.MultiplayerClient) { - npc.localAI[0] = 0f; int type = ModContent.ProjectileType(); int damage = npc.GetProjectileDamage(type); int totalProjectiles = 4; @@ -121,48 +114,18 @@ namespace CalamityMod.NPCs.SupremeCalamitas Vector2 velocity = spinningPoint.RotatedBy(radians * k); Projectile.NewProjectile(npc.Center, velocity, type, damage, 0f, Main.myPlayer); } - Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SCalSounds/BrimstoneShoot"), npc.Center); + npc.netUpdate = true; } + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SCalSounds/BrimstoneShoot"), npc.Center); } - Vector2 vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num191 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2); - float num192 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2); - num191 = (int)(num191 / 16f) * 16; - num192 = (int)(num192 / 16f) * 16; - vector18.X = (int)(vector18.X / 16f) * 16; - vector18.Y = (int)(vector18.Y / 16f) * 16; - num191 -= vector18.X; - num192 -= vector18.Y; - float num193 = (float)System.Math.Sqrt(num191 * num191 + num192 * num192); - if (npc.ai[1] > 0f && npc.ai[1] < Main.npc.Length) + if (Main.npc.IndexInRange((int)npc.ai[1])) { - try - { - vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num191 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - vector18.X; - num192 = Main.npc[(int)npc.ai[1]].position.Y + (Main.npc[(int)npc.ai[1]].height / 2) - vector18.Y; - } - catch - { - } - npc.rotation = (float)System.Math.Atan2(num192, num191) + 1.57f; - num193 = (float)System.Math.Sqrt(num191 * num191 + num192 * num192); - int num194 = npc.width; - num193 = (num193 - num194) / num193; - num191 *= num193; - num192 *= num193; + Vector2 offsetToAheadSegment = AheadSegment.Center - npc.Center; + npc.rotation = offsetToAheadSegment.ToRotation() + MathHelper.PiOver2; npc.velocity = Vector2.Zero; - npc.position.X = npc.position.X + num191; - npc.position.Y = npc.position.Y + num192; - if (num191 < 0f) - { - npc.spriteDirection = -1; - } - else if (num191 > 0f) - { - npc.spriteDirection = 1; - } + npc.Center = AheadSegment.Center - offsetToAheadSegment.SafeNormalize(Vector2.UnitY) * 34f; + npc.spriteDirection = (offsetToAheadSegment.X > 0f).ToDirectionInt(); } } @@ -181,6 +144,27 @@ namespace CalamityMod.NPCs.SupremeCalamitas } } + public override void FindFrame(int frameHeight) + { + npc.frameCounter++; + npc.frame.Y = ((int)(npc.frameCounter / 5) + npc.whoAmI) % Main.npcFrameCount[npc.type] * frameHeight; + } + + public override void HitEffect(int hitDirection, double damage) + { + if (Main.netMode != NetmodeID.MultiplayerClient && npc.life <= 0) + { + for (int i = 0; i < Main.rand.Next(1, 3 + 1); i++) + { + if (!Main.rand.NextBool(3)) + continue; + + Vector2 soulVelocity = -Vector2.UnitY.RotatedByRandom(0.53f) * Main.rand.NextFloat(2.5f, 4f); + Projectile.NewProjectile(npc.Center, soulVelocity, ModContent.ProjectileType(), 0, 0f); + } + } + } + public override bool CheckActive() { return false; diff --git a/NPCs/SupremeCalamitas/SCalWormBodyWeak.png b/NPCs/SupremeCalamitas/SCalWormBodyWeak.png index 8bc8635d1b..3ab290bdf1 100644 Binary files a/NPCs/SupremeCalamitas/SCalWormBodyWeak.png and b/NPCs/SupremeCalamitas/SCalWormBodyWeak.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormForeArm.png b/NPCs/SupremeCalamitas/SCalWormForeArm.png new file mode 100644 index 0000000000..da24ee8a4f Binary files /dev/null and b/NPCs/SupremeCalamitas/SCalWormForeArm.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormHand.png b/NPCs/SupremeCalamitas/SCalWormHand.png new file mode 100644 index 0000000000..c28935e9f2 Binary files /dev/null and b/NPCs/SupremeCalamitas/SCalWormHand.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormHead.cs b/NPCs/SupremeCalamitas/SCalWormHead.cs index bf98c7ff11..97fa659099 100644 --- a/NPCs/SupremeCalamitas/SCalWormHead.cs +++ b/NPCs/SupremeCalamitas/SCalWormHead.cs @@ -27,7 +27,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas npc.damage = 0; //150 npc.npcSlots = 5f; npc.width = 62; //324 - npc.height = 78; //216 + npc.height = 64; //216 npc.defense = 0; CalamityGlobalNPC global = npc.Calamity(); global.DR = 0.999999f; @@ -36,20 +36,16 @@ namespace CalamityMod.NPCs.SupremeCalamitas npc.aiStyle = -1; //new aiType = -1; //new npc.knockBackResist = 0f; - npc.scale = 1.2f; - if (Main.expertMode) - { - npc.scale = 1.35f; - } - npc.alpha = 255; + npc.scale = Main.expertMode ? 1.35f : 1.2f; + npc.scale *= 1.25f; + + npc.alpha = 255; npc.chaseable = false; npc.behindTiles = true; npc.noGravity = true; npc.noTileCollide = true; npc.canGhostHeal = false; - npc.HitSound = SoundID.NPCHit4; - npc.DeathSound = SoundID.NPCDeath14; - npc.netAlways = true; + npc.netAlways = true; } public override void SendExtraAI(BinaryWriter writer) @@ -81,44 +77,58 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (Vector2.Distance(Main.player[npc.target].Center, npc.Center) > CalamityGlobalNPC.CatchUpDistance200Tiles) npc.TargetClosest(); - Player player = Main.player[npc.target]; - if (npc.ai[2] > 0f) - { npc.realLife = (int)npc.ai[2]; - } if (Main.netMode != NetmodeID.MultiplayerClient) { if (!TailSpawned && npc.ai[0] == 0f) { + float rotationalOffset = 0f; int Previous = npc.whoAmI; - for (int num36 = 0; num36 < maxLength; num36++) + for (int i = 0; i < maxLength; i++) { int lol; - if (num36 >= 0 && num36 < minLength && num36 % 2 == 0) + if (i >= 0 && i < minLength && i % 2 == 1) { lol = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType(), npc.whoAmI); Main.npc[lol].localAI[0] += passedVar; passedVar += 36f; } - else if (num36 >= 0 && num36 < minLength) + else if (i >= 0 && i < minLength) { lol = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType(), npc.whoAmI); - if (npc.localAI[0] % 2 == 0) - { - Main.npc[lol].localAI[3] = 1f; - npc.localAI[0] = 1f; - } - else - { - npc.localAI[0] = 2f; - } - } + Main.npc[lol].localAI[3] = i; + } else - { lol = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType(), npc.whoAmI); - } + + // Create arms. + if (i >= 3 && i % 4 == 0) + { + NPC segment = Main.npc[lol]; + int arm = NPC.NewNPC((int)segment.Center.X, (int)segment.Center.Y, ModContent.NPCType(), lol); + if (Main.npc.IndexInRange(arm)) + { + Main.npc[arm].ai[0] = lol; + Main.npc[arm].direction = 1; + Main.npc[arm].rotation = rotationalOffset; + } + + rotationalOffset += MathHelper.Pi / 6f; + + arm = NPC.NewNPC((int)segment.Center.X, (int)segment.Center.Y, ModContent.NPCType(), lol); + if (Main.npc.IndexInRange(arm)) + { + Main.npc[arm].ai[0] = lol; + Main.npc[arm].direction = -1; + Main.npc[arm].rotation = rotationalOffset + MathHelper.Pi; + } + + rotationalOffset += MathHelper.Pi / 6f; + rotationalOffset = MathHelper.WrapAngle(rotationalOffset); + } + Main.npc[lol].realLife = npc.whoAmI; Main.npc[lol].ai[2] = npc.whoAmI; Main.npc[lol].ai[1] = Previous; @@ -133,30 +143,17 @@ namespace CalamityMod.NPCs.SupremeCalamitas } } - if (Main.player[npc.target].dead || !NPC.AnyNPCs(ModContent.NPCType()) || CalamityGlobalNPC.SCal < 0 || !Main.npc[CalamityGlobalNPC.SCal].active) - { - npc.TargetClosest(false); - npc.alpha += 5; - if (npc.alpha >= 255) - { - npc.alpha = 255; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].type == npc.type || Main.npc[i].type == ModContent.NPCType() || Main.npc[i].type == ModContent.NPCType() || Main.npc[i].type == ModContent.NPCType()) - { - Main.npc[i].active = false; - } - } - } - } - else - { - npc.alpha -= 42; - if (npc.alpha < 0) - { - npc.alpha = 0; - } - } + if (Main.player[npc.target].dead || !NPC.AnyNPCs(ModContent.NPCType()) || CalamityGlobalNPC.SCal < 0 || !Main.npc[CalamityGlobalNPC.SCal].active) + { + npc.TargetClosest(false); + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.NPCKilled, "Sounds/NPCKilled/SepulcherDeath"), Main.player[npc.target].Center); + npc.life = 0; + npc.HitEffect(); + npc.active = false; + npc.netUpdate = true; + } + else + npc.Opacity = MathHelper.Clamp(npc.Opacity + 0.165f, 0f, 1f); Vector2 vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num191 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2); @@ -304,11 +301,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas vector43 += vector11 * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, spriteEffects, 0f); - texture2D15 = ModContent.GetTexture("CalamityMod/NPCs/SupremeCalamitas/SCalWormHeadGlow"); - Color color37 = Color.Lerp(Color.White, Color.Red, 0.5f); - - spriteBatch.Draw(texture2D15, vector43, npc.frame, color37, npc.rotation, vector11, npc.scale, spriteEffects, 0f); - return false; } @@ -334,33 +326,20 @@ namespace CalamityMod.NPCs.SupremeCalamitas public override void HitEffect(int hitDirection, double damage) { - if (npc.life <= 0) - { - npc.position.X = npc.position.X + (float)(npc.width / 2); - npc.position.Y = npc.position.Y + (float)(npc.height / 2); - npc.width = 50; - npc.height = 50; - npc.position.X = npc.position.X - (float)(npc.width / 2); - npc.position.Y = npc.position.Y - (float)(npc.height / 2); - for (int num621 = 0; num621 < 5; num621++) + if (npc.life <= 0) + { + for (int i = 1; i <= 3; i++) { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.NextBool(2)) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } + Vector2 goreSpawnPosition = npc.Center; + + // Spawn at a slight offset when spawning mandibles. + if (i == 2) + goreSpawnPosition += npc.velocity.SafeNormalize(Vector2.Zero).RotatedBy(MathHelper.PiOver4) * 16f; + if (i == 3) + goreSpawnPosition += npc.velocity.SafeNormalize(Vector2.Zero).RotatedBy(-MathHelper.PiOver4) * 16f; + Gore.NewGorePerfect(goreSpawnPosition, npc.velocity, mod.GetGoreSlot($"Gores/SupremeCalamitas/SepulcherHead_Gore{i}"), npc.scale); } - for (int num623 = 0; num623 < 10; num623++) - { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); - Main.dust[num624].velocity *= 2f; - } - } + } } } } diff --git a/NPCs/SupremeCalamitas/SCalWormHead.png b/NPCs/SupremeCalamitas/SCalWormHead.png index 8bd5ba6d26..ce918150f1 100644 Binary files a/NPCs/SupremeCalamitas/SCalWormHead.png and b/NPCs/SupremeCalamitas/SCalWormHead.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormHeadGlow.png b/NPCs/SupremeCalamitas/SCalWormHeadGlow.png deleted file mode 100644 index 6b5306839a..0000000000 Binary files a/NPCs/SupremeCalamitas/SCalWormHeadGlow.png and /dev/null differ diff --git a/NPCs/SupremeCalamitas/SCalWormHeart.png b/NPCs/SupremeCalamitas/SCalWormHeart.png deleted file mode 100644 index 8bc8635d1b..0000000000 Binary files a/NPCs/SupremeCalamitas/SCalWormHeart.png and /dev/null differ diff --git a/NPCs/SupremeCalamitas/SCalWormTail.cs b/NPCs/SupremeCalamitas/SCalWormTail.cs index 3fb861c106..d0200712e0 100644 --- a/NPCs/SupremeCalamitas/SCalWormTail.cs +++ b/NPCs/SupremeCalamitas/SCalWormTail.cs @@ -42,8 +42,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas npc.noGravity = true; npc.noTileCollide = true; npc.canGhostHeal = false; - npc.HitSound = SoundID.NPCHit4; - npc.DeathSound = SoundID.NPCDeath14; npc.netAlways = true; npc.dontCountMe = true; } @@ -164,11 +162,6 @@ namespace CalamityMod.NPCs.SupremeCalamitas vector43 += vector11 * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, spriteEffects, 0f); - texture2D15 = ModContent.GetTexture("CalamityMod/NPCs/SupremeCalamitas/SCalWormTailGlow"); - Color color37 = Color.Lerp(Color.White, Color.Red, 0.5f); - - spriteBatch.Draw(texture2D15, vector43, npc.frame, color37, npc.rotation, vector11, npc.scale, spriteEffects, 0f); - return false; } @@ -190,32 +183,15 @@ namespace CalamityMod.NPCs.SupremeCalamitas public override void HitEffect(int hitDirection, double damage) { if (npc.life <= 0) - { - npc.position.X = npc.position.X + (float)(npc.width / 2); - npc.position.Y = npc.position.Y + (float)(npc.height / 2); - npc.width = 50; - npc.height = 50; - npc.position.X = npc.position.X - (float)(npc.width / 2); - npc.position.Y = npc.position.Y - (float)(npc.height / 2); - for (int num621 = 0; num621 < 5; num621++) - { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default, 2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.NextBool(2)) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int num623 = 0; num623 < 10; num623++) - { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default, 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default, 2f); - Main.dust[num624].velocity *= 2f; - } - } + { + for (int i = 1; i <= 2; i++) + { + Vector2 goreSpawnPosition = npc.Center; + if (i == 2) + goreSpawnPosition -= (npc.rotation - MathHelper.PiOver2).ToRotationVector2() * 20f; + Gore.NewGorePerfect(goreSpawnPosition, Main.rand.NextVector2Circular(3f, 3f), mod.GetGoreSlot($"Gores/SupremeCalamitas/SepulcherTail_Gore{i}"), npc.scale); + } + } } public override bool CheckActive() diff --git a/NPCs/SupremeCalamitas/SCalWormTail.png b/NPCs/SupremeCalamitas/SCalWormTail.png index a8e1ab41e1..283e094283 100644 Binary files a/NPCs/SupremeCalamitas/SCalWormTail.png and b/NPCs/SupremeCalamitas/SCalWormTail.png differ diff --git a/NPCs/SupremeCalamitas/SCalWormTailGlow.png b/NPCs/SupremeCalamitas/SCalWormTailGlow.png deleted file mode 100644 index 2d4265fd16..0000000000 Binary files a/NPCs/SupremeCalamitas/SCalWormTailGlow.png and /dev/null differ diff --git a/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs b/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs index 894bb0b395..9d706a6e3e 100644 --- a/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs +++ b/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs @@ -16,11 +16,15 @@ namespace CalamityMod.NPCs.SupremeCalamitas { private int timer = 0; private bool start = true; + public NPC SCal => Main.npc[CalamityGlobalNPC.SCal]; + public Player Target => Main.player[npc.target]; + public Vector2 EyePosition => npc.Center + new Vector2(npc.spriteDirection == -1 ? 40f : -36f, 16f); + public ref float RotationalDegreeOffset => ref npc.ai[1]; public override void SetStaticDefaults() { DisplayName.SetDefault("Soul Seeker"); - Main.npcFrameCount[npc.type] = 8; + Main.npcFrameCount[npc.type] = 6; NPCID.Sets.TrailingMode[npc.type] = 1; } @@ -37,8 +41,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas npc.defense = 60; npc.DR_NERD(0.25f); npc.LifeMaxNERB(Main.expertMode ? 24000 : 15000, 28000); - npc.HitSound = SoundID.NPCHit4; - npc.DeathSound = SoundID.NPCDeath14; + npc.DeathSound = SoundID.DD2_SkeletonDeath; } public override void SendExtraAI(BinaryWriter writer) @@ -62,33 +65,35 @@ namespace CalamityMod.NPCs.SupremeCalamitas public override bool PreAI() { - NPC parent = Main.npc[CalamityGlobalNPC.SCal]; - bool expertMode = Main.expertMode; + // Die if SCal is no longer present. + if (CalamityGlobalNPC.SCal < 0 || !SCal.active) + { + npc.active = false; + npc.netUpdate = true; + return false; + } + if (start) { - for (int num621 = 0; num621 < 10; num621++) - { - int num622 = Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); - } - npc.ai[1] = npc.ai[0]; + for (int i = 0; i < 10; i++) + Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); + RotationalDegreeOffset = npc.ai[0]; start = false; } // Get a target - if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) + if (npc.target < 0 || npc.target == Main.maxPlayers || Target.dead || !Target.active) npc.TargetClosest(); - // Despawn safety, make sure to target another player if the current player target is too far away - if (Vector2.Distance(Main.player[npc.target].Center, npc.Center) > CalamityGlobalNPC.CatchUpDistance200Tiles) + // Target another player if the current player target is too far away + if (!npc.WithinRange(Target.Center, CalamityGlobalNPC.CatchUpDistance200Tiles)) npc.TargetClosest(); - Vector2 direction = Main.player[npc.target].Center - npc.Center; - direction.Normalize(); - direction *= 9f; - npc.rotation = direction.ToRotation(); + npc.spriteDirection = (Target.Center.X < npc.Center.X).ToDirectionInt(); + timer++; - int timerLimit = CalamityWorld.malice ? 120 : 180; - if (timer > timerLimit) + int shootRate = CalamityWorld.malice ? 120 : 180; + if (timer > shootRate) { for (int i = 0; i < Main.maxNPCs; i++) { @@ -96,7 +101,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (seeker.type == npc.type) { if (seeker == npc) - Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SCalSounds/BrimstoneShoot"), parent.Center); + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SCalSounds/BrimstoneShoot"), SCal.Center); break; } } @@ -104,24 +109,15 @@ namespace CalamityMod.NPCs.SupremeCalamitas { int type = ModContent.ProjectileType(); int damage = npc.GetProjectileDamage(type); - Projectile.NewProjectile(npc.Center, direction, type, damage, 1f, Main.myPlayer); + Vector2 shootVelocity = (Target.Center - EyePosition).SafeNormalize(Vector2.UnitY) * 9f; + Projectile.NewProjectile(EyePosition, shootVelocity, type, damage, 1f, Main.myPlayer); } timer = 0; npc.netUpdate = true; } - if (CalamityGlobalNPC.SCal < 0 || !parent.active) - { - npc.active = false; - npc.netUpdate = true; - return false; - } - Player player = Main.player[npc.target]; - double deg = npc.ai[1]; - double rad = deg * (Math.PI / 180); - double dist = 300; - npc.position.X = parent.Center.X - (int)(Math.Cos(rad) * dist) - npc.width / 2; - npc.position.Y = parent.Center.Y - (int)(Math.Sin(rad) * dist) - npc.height / 2; - npc.ai[1] += 0.5f; //2 + + npc.position = SCal.Center - MathHelper.ToRadians(RotationalDegreeOffset).ToRotationVector2() * 300f - npc.Size * 0.5f; + RotationalDegreeOffset += 0.5f; return false; } @@ -159,16 +155,13 @@ namespace CalamityMod.NPCs.SupremeCalamitas num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); Main.dust[num624].velocity *= 2f; } - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/SoulSeekerSupremeGores/SupremeSoulSeeker"), npc.scale); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/SoulSeekerSupremeGores/SupremeSoulSeeker2"), npc.scale); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/SoulSeekerSupremeGores/SupremeSoulSeeker3"), npc.scale); + + for (int i = 1; i <= 5; i++) + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot($"Gores/SoulSeekerSupremeGores/SupremeSoulSeeker_Gore{i}"), npc.scale); } } - public override bool CheckActive() - { - return false; - } + public override bool CheckActive() => false; public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { @@ -180,7 +173,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2)); Color color36 = Color.White; float amount9 = 0.5f; - int num153 = 5; + int num153 = 2; if (CalamityConfig.Instance.Afterimages) { diff --git a/NPCs/SupremeCalamitas/SoulSeekerSupreme.png b/NPCs/SupremeCalamitas/SoulSeekerSupreme.png index d0ae0b4980..cea992e2a7 100644 Binary files a/NPCs/SupremeCalamitas/SoulSeekerSupreme.png and b/NPCs/SupremeCalamitas/SoulSeekerSupreme.png differ diff --git a/NPCs/SupremeCalamitas/SoulSeekerSupremeGlow.png b/NPCs/SupremeCalamitas/SoulSeekerSupremeGlow.png index 27c809cbac..5c481d1bf2 100644 Binary files a/NPCs/SupremeCalamitas/SoulSeekerSupremeGlow.png and b/NPCs/SupremeCalamitas/SoulSeekerSupremeGlow.png differ diff --git a/NPCs/SupremeCalamitas/SupremeCalamitas.cs b/NPCs/SupremeCalamitas/SupremeCalamitas.cs index d438591214..d2f24dcac9 100644 --- a/NPCs/SupremeCalamitas/SupremeCalamitas.cs +++ b/NPCs/SupremeCalamitas/SupremeCalamitas.cs @@ -86,8 +86,8 @@ namespace CalamityMod.NPCs.SupremeCalamitas private int spawnY = 0; private int spawnYReset = 0; private int spawnYAdd = 0; - private int bulletHellCounter = 0; - private int bulletHellCounter2 = 0; + public int bulletHellCounter = 0; + public int bulletHellCounter2 = 0; private int attackCastDelay = 0; private int hitTimer = 0; @@ -415,7 +415,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas } // Summon a shield if the next attack will be a charge. - else if (!npc.dontTakeDamage && ((willCharge && AttackCloseToBeingOver) || npc.ai[1] == 2f)) + else if (((willCharge && AttackCloseToBeingOver) || npc.ai[1] == 2f) && bulletHellCounter2 % 900 == 0) { if (npc.ai[1] != 2f) { @@ -1869,7 +1869,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas for (int num388 = 0; num388 < 50; num388++) Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.Brimstone, Main.rand.Next(-30, 31) * 0.2f, Main.rand.Next(-30, 31) * 0.2f, 0, default, 1f); - Main.PlaySound(SoundID.Roar, (int)npc.position.X, (int)npc.position.Y, 0); + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SupremeCalamitasSpawn"), npc.Center); } } @@ -2543,20 +2543,18 @@ namespace CalamityMod.NPCs.SupremeCalamitas } // And play a fire-like sound effect. - Main.PlaySound(SoundID.DD2_BetsyWindAttack, target.Center); hasSummonedSepulcher1 = true; hasSummonedSepulcher2 = npc.life <= npc.lifeMax * 0.08; - // TODO: Resprite brimstone hearts a bit. if (Main.netMode != NetmodeID.MultiplayerClient) { List hearts = new List(); for (int x = 0; x < 5; x++) { - hearts.Add(NPC.NewNPC(spawnX + 50, tempSpawnY, ModContent.NPCType(), 0, 0f, 0f, 0f, 0f, 255)); + hearts.Add(NPC.NewNPC(spawnX + 50, tempSpawnY, ModContent.NPCType(), 0, 0f, 0f, 0f, 0f, 255)); spawnX += spawnXAdd; - hearts.Add(NPC.NewNPC(spawnX2 - 50, tempSpawnY, ModContent.NPCType(), 0, 0f, 0f, 0f, 0f, 255)); + hearts.Add(NPC.NewNPC(spawnX2 - 50, tempSpawnY, ModContent.NPCType(), 0, 0f, 0f, 0f, 0f, 255)); spawnX2 -= spawnXAdd; tempSpawnY += spawnYAdd; } @@ -2569,6 +2567,8 @@ namespace CalamityMod.NPCs.SupremeCalamitas NPC.SpawnOnPlayer(npc.FindClosestPlayer(), ModContent.NPCType()); npc.netUpdate = true; } + + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SCalSounds/SepulcherSpawn"), target.Center); } } @@ -2662,7 +2662,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas public void ConnectAllBrimstoneHearts(List heartIndices) { - int heartType = ModContent.NPCType(); + int heartType = ModContent.NPCType(); // Ensure that the hearts go in order based on the arena. IEnumerable hearts = heartIndices.Select(i => Main.npc[i]); @@ -2695,14 +2695,14 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (tries >= 100) endpoint.X = MathHelper.Clamp(endpoint.X, safeBox.Left, safeBox.Right); - heart.ModNPC().ChainEndpoints.Add(endpoint); + heart.ModNPC().ChainEndpoints.Add(endpoint); } if (Main.rand.NextBool(2)) { endpoint.X = heart.Center.X + Main.rand.NextBool(2).ToDirectionInt() * Main.rand.NextFloat(45f, 360f); endpoint.X = MathHelper.Clamp(endpoint.X, safeBox.Left, safeBox.Right); - heart.ModNPC().ChainEndpoints.Add(endpoint); + heart.ModNPC().ChainEndpoints.Add(endpoint); } heart.netUpdate = true; @@ -2945,7 +2945,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas if (lifeRatio < 0.05f) flickerPower += 0.1f; float opacity = forcefieldOpacity; - opacity *= MathHelper.Lerp(1f, 1f - flickerPower, (float)Math.Pow(Math.Cos(Main.GlobalTime * MathHelper.Lerp(3f, 9f, flickerPower)), 24D)); + opacity *= MathHelper.Lerp(1f, MathHelper.Max(1f - flickerPower, 0.56f), (float)Math.Pow(Math.Cos(Main.GlobalTime * MathHelper.Lerp(3f, 5f, flickerPower)), 24D)); // During/prior to a charge the forcefield is always darker than usual and thus its intensity is also higher. if (!npc.dontTakeDamage && (willCharge || npc.ai[1] == 2f)) diff --git a/NPCs/SupremeCalamitas/unknown.png b/NPCs/SupremeCalamitas/unknown.png deleted file mode 100644 index 8aec7550d7..0000000000 Binary files a/NPCs/SupremeCalamitas/unknown.png and /dev/null differ diff --git a/NPCs/TownNPCs/FAP_Head.png b/NPCs/TownNPCs/FAP_Head.png index cce3f796b8..05a348609d 100644 Binary files a/NPCs/TownNPCs/FAP_Head.png and b/NPCs/TownNPCs/FAP_Head.png differ diff --git a/NPCs/Yharon/Yharon.cs b/NPCs/Yharon/Yharon.cs index fe8964ca63..be93674baa 100644 --- a/NPCs/Yharon/Yharon.cs +++ b/NPCs/Yharon/Yharon.cs @@ -2879,37 +2879,37 @@ namespace CalamityMod.NPCs.Yharon DropHelper.DropItemCondition(npc, ModContent.ItemType(), true, CalamityWorld.malice); DropHelper.DropItemCondition(npc, ModContent.ItemType(), true, CalamityWorld.malice); - // Phase 1 drops: Contained in the bag, so they only drop directly on Normal - if (!Main.expertMode) - { - // Weapons - float w = DropHelper.NormalWeaponDropRateFloat; - DropHelper.DropEntireWeightedSet(npc, - DropHelper.WeightStack(w), - DropHelper.WeightStack(w), - DropHelper.WeightStack(w), - DropHelper.WeightStack(w), - DropHelper.WeightStack(w), - DropHelper.WeightStack(w), // Yharon Kindle Staff - DropHelper.WeightStack(w), // Infernal Spear - DropHelper.WeightStack(w) - ); + // Normal drops: Everything that would otherwise be in the bag + if (!Main.expertMode) + { + // Weapons + float w = DropHelper.NormalWeaponDropRateFloat; + DropHelper.DropEntireWeightedSet(npc, + DropHelper.WeightStack(w), + DropHelper.WeightStack(w), + DropHelper.WeightStack(w), + DropHelper.WeightStack(w), + DropHelper.WeightStack(w), + DropHelper.WeightStack(w), // Yharon Kindle Staff + DropHelper.WeightStack(w), // Infernal Spear + DropHelper.WeightStack(w) + ); - // Vanity - DropHelper.DropItemChance(npc, ModContent.ItemType(), 7); - DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); - } + // Vanity + DropHelper.DropItemChance(npc, ModContent.ItemType(), 7); + DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); - // Materials - int soulFragMin = Main.expertMode ? 22 : 15; - int soulFragMax = Main.expertMode ? 28 : 22; - DropHelper.DropItem(npc, ModContent.ItemType(), true, soulFragMin, soulFragMax); + // Materials + int soulFragMin = 15; + int soulFragMax = 22; + DropHelper.DropItem(npc, ModContent.ItemType(), true, soulFragMin, soulFragMax); - // Equipment - DropHelper.DropItem(npc, ModContent.ItemType(), Main.expertMode); + // Equipment + DropHelper.DropItem(npc, ModContent.ItemType(), Main.expertMode); + } - // Vanity - DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); + // Vanity + DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); // Other // DropHelper.DropItem(npc, ModContent.ItemType()); @@ -2918,7 +2918,7 @@ namespace CalamityMod.NPCs.Yharon // If Yharon has not been killed yet, notify players of Auric Ore if (!CalamityWorld.downedYharon) { - WorldGenerationMethods.SpawnOre(ModContent.TileType(), 2E-05, .6f, .8f); + CalamityUtils.SpawnOre(ModContent.TileType(), 2E-05, 0.6f, 0.8f, 6, 12); string key = "Mods.CalamityMod.AuricOreText"; Color messageColor = Color.Gold; diff --git a/Projectiles/Boss/SCalRitualDrama.cs b/Projectiles/Boss/SCalRitualDrama.cs index 215ae94a4f..eb6ca69f86 100644 --- a/Projectiles/Boss/SCalRitualDrama.cs +++ b/Projectiles/Boss/SCalRitualDrama.cs @@ -1,5 +1,6 @@ using CalamityMod.Dusts; using CalamityMod.NPCs.SupremeCalamitas; +using CalamityMod.Skies; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -53,7 +54,6 @@ namespace CalamityMod.Projectiles.Boss // Make a laugh sound and create a burst of brimstone dust. Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SupremeCalamitasSpawn"), projectile.Center); - Main.PlaySound(SoundID.DD2_EtherianPortalDryadTouch, projectile.Center); Main.LocalPlayer.Calamity().GeneralScreenShakePower = Utils.InverseLerp(3400f, 1560f, Main.LocalPlayer.Distance(projectile.Center), true) * 16f; diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index acaf027920..a6b5708cd6 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -230,6 +230,11 @@ namespace CalamityMod.Projectiles projectile.idStaticNPCHitCooldown = 18; break; + case ProjectileID.MonkStaffT3: + case ProjectileID.MonkStaffT3_Alt: + projectile.scale = 2f; + break; + case ProjectileID.Retanimini: case ProjectileID.MiniRetinaLaser: case ProjectileID.FlowerPetal: @@ -2130,20 +2135,20 @@ namespace CalamityMod.Projectiles { if (projectile.type == ProjectileID.PureSpray || projectile.type == ProjectileID.PurificationPowder) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Pure, !isPowder); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Pure, !isPowder); } //commented out for Terraria 1.4 when vile/vicious powder spread corruption/crimson if (projectile.type == ProjectileID.CorruptSpray)// || projectile.type == ProjectileID.VilePowder) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Corrupt, !isPowder); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Corrupt, !isPowder); } if (projectile.type == ProjectileID.CrimsonSpray)// || projectile.type == ProjectileID.ViciousPowder) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Crimson, !isPowder); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Crimson, !isPowder); } if (projectile.type == ProjectileID.HallowSpray) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Hallow); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Hallow); } NetMessage.SendTileRange(-1, i, j, 1, 1); } diff --git a/Projectiles/Healing/RainHeal.cs b/Projectiles/Healing/RainHeal.cs index 7ec71fe52d..3a4669b204 100644 --- a/Projectiles/Healing/RainHeal.cs +++ b/Projectiles/Healing/RainHeal.cs @@ -25,9 +25,13 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - projectile.velocity *= 0.99f; - - projectile.HealingProjectile(8, projectile.owner, 12f, 15f, false); + if (projectile.timeLeft < 165) + { + if (projectile.timeLeft > 150) + projectile.velocity *= 0.9f; + else + projectile.HealingProjectile(8, projectile.owner, 12f, 15f, false); + } float num498 = projectile.velocity.X * 0.2f; float num499 = -(projectile.velocity.Y * 0.2f); diff --git a/Projectiles/Melee/RainBolt.cs b/Projectiles/Melee/RainBolt.cs index a1817ae411..f430295a54 100644 --- a/Projectiles/Melee/RainBolt.cs +++ b/Projectiles/Melee/RainBolt.cs @@ -27,8 +27,6 @@ namespace CalamityMod.Projectiles.Melee public override void AI() { - projectile.velocity *= 0.95f; - if (projectile.localAI[0] == 0f) { Main.PlaySound(SoundID.Item9, projectile.Center); @@ -41,9 +39,11 @@ namespace CalamityMod.Projectiles.Melee if (projectile.timeLeft < 150) CalamityGlobalProjectile.HomeInOnNPC(projectile, !projectile.tileCollide, 600f, 12f, 20f); - } + else + projectile.velocity *= 0.95f; + } - public override void Kill(int timeLeft) + public override void Kill(int timeLeft) { Main.PlaySound(SoundID.Item60, projectile.Center); for (int k = 0; k < 5; k++) diff --git a/Projectiles/Melee/Yoyos/OracleYoyo.cs b/Projectiles/Melee/Yoyos/OracleYoyo.cs index e23ff9c76e..a04fd4c99f 100644 --- a/Projectiles/Melee/Yoyos/OracleYoyo.cs +++ b/Projectiles/Melee/Yoyos/OracleYoyo.cs @@ -27,9 +27,12 @@ namespace CalamityMod.Projectiles.Melee.Yoyos private const float MinDischargeRate = 0.05f; private const float MaxDischargeRate = 0.53f; private const float DischargeRateScaleFactor = 0.003f; - private const float ChargePerHit = 3f; + private const float ChargePerHit = 4.5f; private const int HitsPerOrbVolley = 3; + // The aura hits once per this many frames. + private const int AuraLocalIFrames = 10; + // Ensures that the main AI only runs once per frame, despite the projectile's multiple updates private const int UpdatesPerFrame = 3; @@ -67,13 +70,13 @@ namespace CalamityMod.Projectiles.Melee.Yoyos projectile.penetrate = -1; projectile.MaxUpdates = UpdatesPerFrame; projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 3 * UpdatesPerFrame; + projectile.localNPCHitCooldown = 4 * UpdatesPerFrame; } public override void AI() { - if ((projectile.position - Main.player[projectile.owner].position).Length() > 3200f) //200 blocks - projectile.Kill(); + if ((projectile.position - Main.player[projectile.owner].position).Length() > 3200f) //200 blocks + projectile.Kill(); // Only do stuff once per frame, despite the yoyo's extra updates. if (!projectile.FinalExtraUpdate()) @@ -117,7 +120,7 @@ namespace CalamityMod.Projectiles.Melee.Yoyos Main.PlaySound(SoundID.Item93, (int)projectile.Center.X, (int)projectile.Center.Y); } - if (AuraFrame % 5 == 4) + if (AuraFrame % AuraLocalIFrames == 0) { // The aura's direct damage scales with its charge and with melee stats. float chargeRatio = AuraCharge / MaxCharge; @@ -127,7 +130,8 @@ namespace CalamityMod.Projectiles.Melee.Yoyos } else projectile.soundDelay = 2; - AuraFrame++; + + AuraFrame = (AuraFrame + 1) % AuraLocalIFrames; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) @@ -235,11 +239,11 @@ namespace CalamityMod.Projectiles.Melee.Yoyos if (projectile.owner == Main.myPlayer) { Projectile p = Projectile.NewProjectileDirect(target.Center, Vector2.Zero, ModContent.ProjectileType(), finalDamage, 0f, projectile.owner, i); - if (p.whoAmI.WithinBounds(Main.maxProjectiles)) - { - p.melee = true; - p.Calamity().forceMelee = true; - } + if (p.whoAmI.WithinBounds(Main.maxProjectiles)) + { + p.melee = true; + p.Calamity().forceMelee = true; + } } } } diff --git a/Projectiles/Ranged/Chicken.cs b/Projectiles/Ranged/Chicken.cs deleted file mode 100644 index 6c2ece7e7f..0000000000 --- a/Projectiles/Ranged/Chicken.cs +++ /dev/null @@ -1,121 +0,0 @@ -using Microsoft.Xna.Framework; -using System; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Ranged -{ - public class Chicken : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Chicken"); - Main.projFrames[projectile.type] = 4; - } - - public override void SetDefaults() - { - projectile.width = 10; - projectile.height = 10; - projectile.friendly = true; - projectile.ignoreWater = true; - projectile.penetrate = 1; - projectile.aiStyle = 1; - projectile.ranged = true; - } - - public override void AI() - { - projectile.frameCounter++; - if (projectile.frameCounter > 4) - { - projectile.frame++; - projectile.frameCounter = 0; - } - if (projectile.frame > 3) - { - projectile.frame = 0; - } - if (Math.Abs(projectile.velocity.X) >= 8f || Math.Abs(projectile.velocity.Y) >= 8f) - { - for (int num246 = 0; num246 < 2; num246++) - { - float num247 = 0f; - float num248 = 0f; - if (num246 == 1) - { - num247 = projectile.velocity.X * 0.5f; - num248 = projectile.velocity.Y * 0.5f; - } - int num249 = Dust.NewDust(new Vector2(projectile.position.X + 3f + num247, projectile.position.Y + 3f + num248) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 6, 0f, 0f, 100, default, 1f); - Main.dust[num249].scale *= 2f + (float)Main.rand.Next(10) * 0.1f; - Main.dust[num249].velocity *= 0.2f; - Main.dust[num249].noGravity = true; - num249 = Dust.NewDust(new Vector2(projectile.position.X + 3f + num247, projectile.position.Y + 3f + num248) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 244, 0f, 0f, 100, default, 0.5f); - Main.dust[num249].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f; - Main.dust[num249].velocity *= 0.05f; - } - if (Math.Abs(projectile.velocity.X) < 15f && Math.Abs(projectile.velocity.Y) < 15f) - { - projectile.velocity *= 1.1f; - } - else if (Main.rand.NextBool(2)) - { - int num252 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 244, 0f, 0f, 100, default, 1f); - Main.dust[num252].scale = 0.1f + (float)Main.rand.Next(5) * 0.1f; - Main.dust[num252].fadeIn = 1.5f + (float)Main.rand.Next(5) * 0.1f; - Main.dust[num252].noGravity = true; - Main.dust[num252].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2)).RotatedBy((double)projectile.rotation, default) * 1.1f; - Main.rand.Next(2); - num252 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 1f); - Main.dust[num252].scale = 1f + (float)Main.rand.Next(5) * 0.1f; - Main.dust[num252].noGravity = true; - Main.dust[num252].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2 - 6)).RotatedBy((double)projectile.rotation, default) * 1.1f; - } - } - projectile.ai[0] += 1f; - projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; - } - - public override bool OnTileCollide(Vector2 oldVelocity) - { - projectile.velocity.X = 0f; - projectile.velocity.Y = -15f; - projectile.timeLeft = 20; - return false; - } - - public override void Kill(int timeLeft) - { - projectile.position = projectile.Center; - projectile.width = projectile.height = 1040; - projectile.position.X = projectile.position.X - (float)(projectile.width / 2); - projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); - } - Main.PlaySound(SoundID.Item14, (int)projectile.Center.X, (int)projectile.Center.Y); - for (int num621 = 0; num621 < 40; num621++) - { - int num622 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default, 2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.NextBool(2)) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int num623 = 0; num623 < 70; num623++) - { - int num624 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 2f); - Main.dust[num624].velocity *= 2f; - } - } - - - } -} diff --git a/Projectiles/Ranged/ChickenExplosion.cs b/Projectiles/Ranged/ChickenExplosion.cs index d7dc9c24a0..a1ea46359f 100644 --- a/Projectiles/Ranged/ChickenExplosion.cs +++ b/Projectiles/Ranged/ChickenExplosion.cs @@ -3,6 +3,7 @@ using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Ranged { public class ChickenExplosion : ModProjectile @@ -11,7 +12,7 @@ namespace CalamityMod.Projectiles.Ranged public override void SetStaticDefaults() { - DisplayName.SetDefault("Explosion"); + DisplayName.SetDefault("Kentucky Fried Explosion"); } public override void SetDefaults() @@ -25,7 +26,7 @@ namespace CalamityMod.Projectiles.Ranged projectile.timeLeft = 150; projectile.ranged = true; projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; + projectile.localNPCHitCooldown = 15; } public override void AI() @@ -36,62 +37,42 @@ namespace CalamityMod.Projectiles.Ranged Main.PlaySound(SoundID.Item20, (int)projectile.position.X, (int)projectile.position.Y); projectile.localAI[0] += 1f; } - bool flag15 = false; - bool flag16 = false; - if (projectile.velocity.X < 0f && projectile.position.X < projectile.ai[0]) + + EmitDust(); + } + + public void EmitDust() + { + if (Main.dedServ) + return; + + for (int i = 0; i < 70; i++) { - flag15 = true; - } - if (projectile.velocity.X > 0f && projectile.position.X > projectile.ai[0]) - { - flag15 = true; - } - if (projectile.velocity.Y < 0f && projectile.position.Y < projectile.ai[1]) - { - flag16 = true; - } - if (projectile.velocity.Y > 0f && projectile.position.Y > projectile.ai[1]) - { - flag16 = true; - } - if (flag15 && flag16) - { - projectile.Kill(); - } - float num461 = 25f; - if (projectile.ai[0] > 180f) - { - num461 -= (projectile.ai[0] - 180f) / 2f; - } - if (num461 <= 0f) - { - num461 = 0f; - projectile.Kill(); - } - num461 *= 0.7f; - projectile.ai[0] += 4f; - int num462 = 0; - while ((float)num462 < num461) - { - float num463 = (float)Main.rand.Next(-120, 121); - float num464 = (float)Main.rand.Next(-120, 121); - float num465 = (float)Main.rand.Next(36, 108); - float num466 = (float)Math.Sqrt((double)(num463 * num463 + num464 * num464)); - num466 = num465 / num466; - num463 *= num466; - num464 *= num466; - int num467 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 244, 0f, 0f, 100, default, 2.5f); - Main.dust[num467].noGravity = true; - Main.dust[num467].position.X = projectile.Center.X; - Main.dust[num467].position.Y = projectile.Center.Y; - Dust expr_149DF_cp_0 = Main.dust[num467]; - expr_149DF_cp_0.position.X += (float)Main.rand.Next(-10, 11); - Dust expr_14A09_cp_0 = Main.dust[num467]; - expr_14A09_cp_0.position.Y += (float)Main.rand.Next(-10, 11); - Main.dust[num467].velocity.X = num463; - Main.dust[num467].velocity.Y = num464; - num462++; + // The exponent being greater than 1 gives the randomness a bias towards 0. This means that more dust will spawn + // closer to the center than the edge. + Vector2 dustSpawnOffset = Main.rand.NextVector2Unit() * (float)Math.Pow(Main.rand.NextFloat(), 2.4D) * projectile.Size * 0.5f; + + // Dust should fly off more quickly the farther away it is from the center. + // At 5% out, a speed of 5 pixels/second is achieved. At 85%, a speed of 15 pixels/second is. + // Direction is determined based on the outward direction rotated by anywhere from -90 to 90 degrees. + Vector2 dustVelocity = dustSpawnOffset.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.PiOver2 * Main.rand.NextFloatDirection()); + dustVelocity *= MathHelper.Lerp(5f, 15f, Utils.InverseLerp(0.05f, 0.85f, (dustSpawnOffset / projectile.Size / 0.5f).Length())); + + // Fire variants. + int dustType = 6; + if (Main.rand.NextBool(4)) + dustType = 244; + + // Smoke. + if (Main.rand.NextBool(7)) + dustType = 31; + + Dust flame = Dust.NewDustPerfect(projectile.Center + dustSpawnOffset, dustType, dustVelocity); + flame.scale = Main.rand.NextFloat(0.85f, 1.3f); + flame.noGravity = true; } } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(projectile.Center, projectile.Size.Length() * 0.5f, targetHitbox); } } diff --git a/Projectiles/Ranged/ChickenRocket.cs b/Projectiles/Ranged/ChickenRocket.cs new file mode 100644 index 0000000000..2eed90fcc0 --- /dev/null +++ b/Projectiles/Ranged/ChickenRocket.cs @@ -0,0 +1,133 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class ChickenRocket : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Chicken Rocket"); + Main.projFrames[projectile.type] = 4; + } + + public override void SetDefaults() + { + projectile.width = 10; + projectile.height = 10; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.penetrate = 1; + projectile.MaxUpdates = 2; + projectile.timeLeft = 300; + projectile.ranged = true; + } + + public override void AI() + { + // Animation frames. + projectile.frameCounter++; + if (projectile.frameCounter > 4) + { + projectile.frame++; + projectile.frameCounter = 0; + } + if (projectile.frame > 3) + projectile.frame = 0; + + float speed = projectile.velocity.Length(); + if (speed >= 12f) + { + // If the rocket is going fast enough, emit some dust. + for (int i = 0; i < 2; i++) + { + float dx = i == 1 ? projectile.velocity.X * 0.5f : 0f; + float dy = i == 1 ? projectile.velocity.Y * 0.5f : 0f; + int d = Dust.NewDust(new Vector2(projectile.position.X + 3f + dx, projectile.position.Y + 3f + dy) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 6, 0f, 0f, 100, default, 1f); + Main.dust[d].scale *= 2f + Main.rand.NextFloat(); + Main.dust[d].velocity *= 0.2f; + Main.dust[d].noGravity = true; + d = Dust.NewDust(new Vector2(projectile.position.X + 3f + dx, projectile.position.Y + 3f + dy) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 244, 0f, 0f, 100, default, 0.5f); + Main.dust[d].fadeIn = 1f + Main.rand.NextFloat(0.5f); + Main.dust[d].velocity *= 0.05f; + } + + // Exponentially accelerate if not going fast enough yet. + if (speed < 21f) + projectile.velocity *= 1.006f; + + // When going at very high speed, emit even more dust. + else if (Main.rand.NextBool()) + { + int d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 244, 0f, 0f, 100, default, 1f); + Main.dust[d].scale = 0.1f + Main.rand.NextFloat(0.5f); + Main.dust[d].fadeIn = 1.5f + Main.rand.NextFloat(0.5f); + Main.dust[d].noGravity = true; + Main.dust[d].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2)).RotatedBy(projectile.rotation) * 1.1f; + Main.rand.Next(2); + d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 1f); + Main.dust[d].scale = 1f + Main.rand.NextFloat(0.5f); + Main.dust[d].noGravity = true; + Main.dust[d].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2 - 6)).RotatedBy(projectile.rotation) * 1.1f; + } + } + + projectile.ai[0] += 1f; + projectile.rotation = (float)Math.Atan2(projectile.velocity.Y, projectile.velocity.X) + MathHelper.PiOver2; + + // Slight gravity, equivalent to Plasma Grenade. + projectile.velocity.Y += 0.09f; + } + + // Instead of dying instantly on collision, fly straight up for a moment. + public override bool OnTileCollide(Vector2 oldVelocity) + { + projectile.velocity.X = 0f; + projectile.velocity.Y = -15f; + + // If there isn't much time left anyway, just explode immediately on collision. + if (projectile.timeLeft > 20) + projectile.timeLeft = 20; + else + return true; + + return false; + } + + public override void Kill(int timeLeft) + { + projectile.position = projectile.Center; + projectile.width = projectile.height = 1040; + projectile.position.X = projectile.position.X - (float)(projectile.width / 2); + projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); + if (projectile.owner == Main.myPlayer) + { + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + Main.PlaySound(SoundID.Item14, (int)projectile.Center.X, (int)projectile.Center.Y); + for (int i = 0; i < 40; i++) + { + int d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default, 2f); + Main.dust[d].velocity *= 3f; + if (Main.rand.NextBool(2)) + { + Main.dust[d].scale = 0.5f; + Main.dust[d].fadeIn = 1f + Main.rand.NextFloat(); + } + } + for (int i = 0; i < 70; i++) + { + int d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 3f); + Main.dust[d].noGravity = true; + Main.dust[d].velocity *= 5f; + d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 2f); + Main.dust[d].velocity *= 2f; + } + } + + + } +} diff --git a/Projectiles/Ranged/Chicken.png b/Projectiles/Ranged/ChickenRocket.png similarity index 100% rename from Projectiles/Ranged/Chicken.png rename to Projectiles/Ranged/ChickenRocket.png diff --git a/Projectiles/Ranged/PrismMine.cs b/Projectiles/Ranged/PrismMine.cs index 5be27c2cb6..6dd01e07dc 100644 --- a/Projectiles/Ranged/PrismMine.cs +++ b/Projectiles/Ranged/PrismMine.cs @@ -7,12 +7,13 @@ using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { - public class PrismMine : ModProjectile + public class PrismMine : ModProjectile { public List MinesToConnectTo = new List(); public ref float Time => ref projectile.ai[0]; + public const float DamageFactorLowerBound = 0.425f; public const float MineConnectDistanceMax = 1200f; - public override void SetStaticDefaults() => DisplayName.SetDefault("Mine"); + public override void SetStaticDefaults() => DisplayName.SetDefault("Mine"); public override void SetDefaults() { @@ -20,16 +21,16 @@ namespace CalamityMod.Projectiles.Ranged projectile.friendly = true; projectile.ignoreWater = true; projectile.tileCollide = false; - projectile.ranged = true; - projectile.penetrate = -1; + projectile.ranged = true; + projectile.penetrate = -1; projectile.usesLocalNPCImmunity = true; projectile.localNPCHitCooldown = 7; projectile.timeLeft = 280; } - public override void AI() - { - projectile.velocity *= 0.96f; + public override void AI() + { + projectile.velocity *= 0.96f; Lighting.AddLight(projectile.Center, Color.Cyan.ToVector3()); float idealScale = MathHelper.Lerp(0.93f, 1.07f, (float)Math.Sin(MathHelper.TwoPi * projectile.timeLeft / 14f) * 0.5f + 0.5f); @@ -37,7 +38,7 @@ namespace CalamityMod.Projectiles.Ranged Time++; } - public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) { foreach (Projectile mine in LocateOtherMines()) { @@ -51,11 +52,24 @@ namespace CalamityMod.Projectiles.Ranged return base.Colliding(projHitbox, targetHitbox); } - public List LocateOtherMines() - { + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + // Have the damage be reduced based on hit count. This effect becomes stronger the more hits, before hitting a lower bound. + float damageFactor = 1f - 3f * (float)Math.Pow(projectile.numHits / 14f, 2D) + 2f * (float)Math.Pow(projectile.numHits / 14f, 3D); + + // The above equation is a polynomial that will eventually shoot off to infinity if the hit count somehow gets high enough. + // To amend this, the limit is reached by default after enough hits have been made. + if (projectile.numHits > 12 || damageFactor < DamageFactorLowerBound) + damageFactor = DamageFactorLowerBound; + + damage = (int)(damage * damageFactor); + } + + public List LocateOtherMines() + { List mines = new List(); for (int i = 0; i < Main.maxProjectiles; i++) - { + { Projectile proj = Main.projectile[i]; if (proj.type != projectile.type || !proj.active || proj.timeLeft <= 12 || i == projectile.whoAmI) continue; @@ -63,31 +77,31 @@ namespace CalamityMod.Projectiles.Ranged continue; mines.Add(proj); - } + } return mines; - } + } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D baseTexture = Main.projectileTexture[projectile.type]; Texture2D glowTexture = ModContent.GetTexture($"{Texture}Glowmask"); Texture2D laserTexture = ModContent.GetTexture($"CalamityMod/Projectiles/Ranged/PrismMineArc"); void drawLineTo(Vector2 destination, Color laserColor) - { + { float rotation = projectile.AngleTo(destination); float remainingDistance = projectile.Distance(destination) - 30f; float laserScale = 0.5f; Rectangle frame = laserTexture.Frame(1, 7, 0, (int)(Main.GlobalTime * 10f + projectile.identity * 3f) % 7); Vector2 laserOrigin = frame.Size() * 0.5f; while (remainingDistance > frame.Height * laserScale) - { + { Vector2 laserDrawPosition = projectile.Center + projectile.SafeDirectionTo(destination, -Vector2.UnitY) * remainingDistance - Main.screenPosition; spriteBatch.Draw(laserTexture, laserDrawPosition, frame, laserColor, rotation, laserOrigin, laserScale, SpriteEffects.None, 0f); remainingDistance -= frame.Height * laserScale; } - } + } Vector2 origin = baseTexture.Size() * 0.5f; Vector2 drawPosition = projectile.Center - Main.screenPosition; @@ -105,6 +119,6 @@ namespace CalamityMod.Projectiles.Ranged glowColor.A = 0; spriteBatch.Draw(glowTexture, drawPosition, glowFrame, glowColor, projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); return false; - } - } -} \ No newline at end of file + } + } +} diff --git a/Projectiles/Ranged/PrismaticEnergyBlast.cs b/Projectiles/Ranged/PrismaticEnergyBlast.cs index 073240ffd1..ee55885a43 100644 --- a/Projectiles/Ranged/PrismaticEnergyBlast.cs +++ b/Projectiles/Ranged/PrismaticEnergyBlast.cs @@ -58,7 +58,7 @@ namespace CalamityMod.Projectiles.Ranged if (Main.myPlayer != projectile.owner || ExplodedYet || LaserLength <= 60f) return; - Projectile.NewProjectile(laserEnd, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, 0f, projectile.owner); + Projectile.NewProjectile(laserEnd, Vector2.Zero, ModContent.ProjectileType(), projectile.damage / 2, 0f, projectile.owner); if (!ExplodedYet) { diff --git a/Projectiles/Rogue/FinalDawnFlame.cs b/Projectiles/Rogue/FinalDawnFlame.cs index c5ba6d565f..294f0b6a24 100644 --- a/Projectiles/Rogue/FinalDawnFlame.cs +++ b/Projectiles/Rogue/FinalDawnFlame.cs @@ -47,7 +47,7 @@ namespace CalamityMod.Projectiles.Rogue Flames = new Flame[TotalFlames]; for (int i = 0; i < Flames.Length; i++) { - Vector2 flamePosition = Main.rand.NextVector2Circular(projectile.width / 2, projectile.height / 2); + Vector2 flamePosition = Main.rand.NextVector2Circular(projectile.width * 0.36f, projectile.height / 2); Flames[i].Position = flamePosition; Flames[i].Frame = Main.rand.Next(8); @@ -57,16 +57,16 @@ namespace CalamityMod.Projectiles.Rogue Flames[i].Direction = Main.rand.Next(2); } } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D texture = Main.projectileTexture[projectile.type]; int frameHeight = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; - + if (Flames.Length > 0) { - for(int i = 0; i < Flames.Length; i++) - { + for (int i = 0; i < Flames.Length; i++) + { int frameHeight2 = frameHeight * Flames[i].Frame; spriteBatch.Draw(texture, projectile.Center + Flames[i].Position - Main.screenPosition, @@ -77,9 +77,9 @@ namespace CalamityMod.Projectiles.Rogue Flames[i].Scale, Flames[i].Direction == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f); - } + } } - return false; + return false; } public override void AI() @@ -106,7 +106,7 @@ namespace CalamityMod.Projectiles.Rogue { if (projectile.ai[0] < 570) { - Vector2 pos = new Vector2(Main.rand.NextFloat(projectile.width / 2)).RotatedByRandom(MathHelper.TwoPi); + Vector2 pos = new Vector2(Main.rand.NextFloat(projectile.width * 0.36f)).RotatedByRandom(MathHelper.TwoPi); float widthHeightRatio = (float)projectile.height / projectile.width; pos.Y *= widthHeightRatio; diff --git a/Projectiles/Rogue/FinalDawnProjectile.cs b/Projectiles/Rogue/FinalDawnProjectile.cs index cfc94e209e..ce177acb2a 100644 --- a/Projectiles/Rogue/FinalDawnProjectile.cs +++ b/Projectiles/Rogue/FinalDawnProjectile.cs @@ -102,7 +102,7 @@ namespace CalamityMod.Projectiles.Rogue int stealth = Projectile.NewProjectile(player.Center, player.SafeDirectionTo(Main.MouseWorld) * 38f, ModContent.ProjectileType(), - (int)(projectile.damage * 1.5f), + (int)(projectile.damage * 1.05f), projectile.knockBack, projectile.owner); Main.projectile[stealth].Calamity().stealthStrike = true; diff --git a/Projectiles/Summon/FlowersOfMortalityPetal.cs b/Projectiles/Summon/FlowersOfMortalityPetal.cs index b743c1018e..b4478dfbeb 100644 --- a/Projectiles/Summon/FlowersOfMortalityPetal.cs +++ b/Projectiles/Summon/FlowersOfMortalityPetal.cs @@ -56,7 +56,7 @@ namespace CalamityMod.Projectiles.Summon Time++; NPC potentialTarget = projectile.Center.MinionHoming(1050f, Owner, false); - if (Time % 25 == 24 && Main.myPlayer == projectile.owner && potentialTarget != null) + if (Time % 50f == 49f && Main.myPlayer == projectile.owner && potentialTarget != null) { Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 10f; Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage / 3, projectile.knockBack, projectile.owner); diff --git a/Projectiles/Summon/SonOfYharon.cs b/Projectiles/Summon/SonOfYharon.cs index 647c7500cc..f24f76fb13 100644 --- a/Projectiles/Summon/SonOfYharon.cs +++ b/Projectiles/Summon/SonOfYharon.cs @@ -92,22 +92,22 @@ namespace CalamityMod.Projectiles.Summon { projectile.frame = 0; } - } - else - { - projectile.frameCounter++; - if (projectile.frameCounter > 12) - { - projectile.frame++; - projectile.frameCounter = 0; - } - if (projectile.frame > 3) - { - projectile.frame = 0; - } - } + } + else + { + projectile.frameCounter++; + if (projectile.frameCounter > 12) + { + projectile.frame++; + projectile.frameCounter = 0; + } + if (projectile.frame > 3) + { + projectile.frame = 0; + } + } - projectile.ChargingMinionAI(1000f, 2000f, 3000f, 500f, 1, 30f, 8f, 4f, new Vector2(0f, -60f), 40f, 8f, true, true); + projectile.ChargingMinionAI(1000f, 2000f, 3000f, 500f, 1, 30f, 8f, 4f, new Vector2(0f, -60f), 40f, 8f, true, true); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Summon/VoidConcentrationAura.cs b/Projectiles/Summon/VoidConcentrationAura.cs new file mode 100644 index 0000000000..41076dda92 --- /dev/null +++ b/Projectiles/Summon/VoidConcentrationAura.cs @@ -0,0 +1,94 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Steamworks; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + class VoidConcentrationAura : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public int timer = 0; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Concentrated Void Aura"); + } + + public override void SetDefaults() + { + projectile.width = 46; + projectile.height = 80; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 3f; + projectile.timeLeft = 18000; + projectile.penetrate = -1; + + projectile.tileCollide = false; + projectile.timeLeft *= 5; + projectile.minion = true; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(timer); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + timer = reader.ReadInt32(); + } + + public override bool? CanCutTiles() + { + return true; + } + + public void HandleRightClick() + { + Vector2 velocity = Main.MouseWorld - Main.player[projectile.owner].Center; + velocity.Normalize(); + velocity *= 2f; + Projectile.NewProjectile(Main.player[projectile.owner].Center, velocity, ModContent.ProjectileType(), (int)(projectile.damage * 5f), 0f, projectile.owner); + projectile.Kill(); + } + + public override void AI() + { + Player owner = Main.player[projectile.owner]; + CalamityPlayer mp = owner.Calamity(); + projectile.Center = owner.Center; + mp.voidAuraDamage = true; + if (owner.dead) + mp.voidAuraDamage = false; + if (!mp.voidAuraDamage) + { + mp.voidAura = false; + projectile.Kill(); + } + if (owner.whoAmI == Main.myPlayer && owner.ownedProjectileCounts[projectile.type] <= 25 && timer > 0 && timer % 4 == 0) + { + NPC target = CalamityUtils.MinionHoming(projectile.Center, 1800f, owner); + if (target != null) + { + Vector2 correctedVelocity = target.Center - owner.Center; + correctedVelocity.Normalize(); + correctedVelocity *= 3f; + int perturbificator9000 = Main.rand.Next(-1, 2); + Vector2 perturbedspeed = new Vector2(correctedVelocity.X + perturbificator9000, correctedVelocity.Y + perturbificator9000).RotatedBy(MathHelper.ToRadians(Main.rand.Next(1, 3))); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, perturbedspeed.X, perturbedspeed.Y, ModContent.ProjectileType(), (int)(projectile.damage * 0.75f), 0f, owner.whoAmI); + } + timer = -1; + } + if (timer > 50 && timer % 4 == 0) + return; + timer++; + } + } +} diff --git a/Projectiles/Summon/VoidConcentrationBlackhole.cs b/Projectiles/Summon/VoidConcentrationBlackhole.cs new file mode 100644 index 0000000000..e05dd64f54 --- /dev/null +++ b/Projectiles/Summon/VoidConcentrationBlackhole.cs @@ -0,0 +1,190 @@ +using CalamityMod.NPCs; +using CalamityMod.Projectiles.Melee; +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + class VoidConcentrationBlackhole : ModProjectile + { + private int damage = 0; + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(damage); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + damage = reader.ReadInt32(); + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Black Hole"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 80; //32 base, 2.5x the normal (for hitbox purposes) + projectile.height = 85; //34 base, 2.5x the normal (for hitbox purposes) + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 0f; + projectile.timeLeft = 1800; + projectile.penetrate = -1; + + projectile.tileCollide = false; + projectile.minion = true; + projectile.scale = 0.01f; + } + + private void ApplySucc(NPC npc) + { + float succStrength = 4f / projectile.scale; + succStrength *= projectile.scale; + Vector2 velocity = projectile.Center - npc.Center; + velocity *= 2f; + velocity.SafeNormalize(Vector2.Zero); + float num550 = 5f * projectile.scale; + Vector2 vector43 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); + float num551 = projectile.Center.X - vector43.X; + float num552 = projectile.Center.Y - vector43.Y; + float num553 = (float)Math.Sqrt((double)(num551 * num551 + num552 * num552)); + if (num553 < 100f) + { + num550 = 28f; //14 + } + num553 = num550 / num553; + num551 *= num553; + num552 *= num553; + npc.velocity.X = (velocity.X * 15f + num551) / 16f; + npc.velocity.Y = (velocity.Y * 15f + num552) / 16f; + npc.velocity = (velocity / succStrength); + } + + private void Death() + { + if (projectile.scale >= 2.5f) //it's boom o' clock + { + projectile.height *= 2; + projectile.width *= 2; + projectile.maxPenetrate = -1; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + projectile.damage = damage; + projectile.Damage(); + projectile.friendly = false; + projectile.Damage(); + Main.PlaySound(SoundID.Item, (int)projectile.Center.X, (int)projectile.Center.Y, 14); + projectile.Kill(); + } + } + + public override void Kill(int timeLeft) + { + for (int d = 0; d < 6; d++) + { + int shadow = Dust.NewDust(projectile.position, projectile.width, projectile.height, 27, 0f, 0f, 100, new Color(0, 0, 0), 4f); + Main.dust[shadow].velocity *= 3f; + if (Main.rand.NextBool(2)) + { + Main.dust[shadow].scale = 0.5f; + Main.dust[shadow].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + for (int d = 0; d < 18; d++) + { + int shadow = Dust.NewDust(projectile.position, projectile.width, projectile.height, 27, 0f, 0f, 100, new Color(0, 0, 0), 4f); + Main.dust[shadow].noGravity = true; + Main.dust[shadow].velocity *= 5f; + shadow = Dust.NewDust(projectile.position, projectile.width, projectile.height, 27, 0f, 0f, 100, new Color(0, 0, 0), 3f); + Main.dust[shadow].velocity *= 2f; + } + } + + public override bool PreAI() + { + if (damage == 0) + { + damage = projectile.damage; + projectile.damage = 0; + projectile.position = Main.player[projectile.owner].position; + } + return true; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = Main.projectileTexture[projectile.type]; + Vector2 drawPos = projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY); + int height = texture.Height / Main.projFrames[projectile.type]; + int frameHeight = height * projectile.frame; + Rectangle rectangle = new Rectangle(0, frameHeight, texture.Width, height); + Vector2 origin = new Vector2(texture.Width / 2f, height / 2f); + SpriteEffects spriteEffects = SpriteEffects.None; + if (projectile.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; + spriteBatch.Draw(texture, drawPos, new Microsoft.Xna.Framework.Rectangle?(rectangle), lightColor, projectile.rotation, origin, projectile.scale, spriteEffects, 0f); + return false; + } + + public override void AI() + { + + projectile.scale += 0.01f; + if (projectile.scale % 0.02f == 0) + { + projectile.scale += 0.01f; //speeds up the projectile's growth to prevent it being too long + } + int radius = (int)(projectile.scale * 100f); //0.01f; to a max of 2.5f; so radius of 1 to 250 by default + if (projectile.scale >= 2f) + radius *= 2; + + int baseWidth = 32; + int baseHeight = 34; + int newWidth = (int)(baseWidth * projectile.scale); + int newHeight = (int)(baseHeight * projectile.scale); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, newWidth, newHeight); + + + + if (projectile.frameCounter > 6) + { + projectile.frame++; + projectile.frameCounter = 0; + } + if (projectile.frame >= Main.projFrames[projectile.type] - 1) + { + projectile.frame = 0; + } + projectile.frameCounter++; + + for (int i = 0; i < Main.npc.Length; i++) + { + if (Main.npc[i].active && !Main.npc[i].friendly /*&& CalamityGlobalNPC.ShouldAffectNPC(Main.npc[i])*/) //TODO - REMOVE COMMENT BEFORE MERGE + { + if (Vector2.Distance(projectile.Center, Main.npc[i].Center) <= radius) + ApplySucc(Main.npc[i]); + } + } + + + if (projectile.scale >= 2.5f) //it's boom o' clock + { + Death(); + } + } + } +} diff --git a/Projectiles/Summon/VoidConcentrationBlackhole.png b/Projectiles/Summon/VoidConcentrationBlackhole.png new file mode 100644 index 0000000000..ab6fe62770 Binary files /dev/null and b/Projectiles/Summon/VoidConcentrationBlackhole.png differ diff --git a/Projectiles/Summon/VoidConcentrationOrb.cs b/Projectiles/Summon/VoidConcentrationOrb.cs new file mode 100644 index 0000000000..51bd4f81ad --- /dev/null +++ b/Projectiles/Summon/VoidConcentrationOrb.cs @@ -0,0 +1,115 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + class VoidConcentrationOrb : ModProjectile + { + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Void Orb"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 54; + projectile.height = 50; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 0f; + projectile.timeLeft = 300; + projectile.penetrate = 1; + + projectile.tileCollide = false; + projectile.minion = true; + projectile.scale = 0.01f; + } + + public override bool? CanHitNPC(NPC target) + { + if (projectile.scale < 1f) + return false; + return null; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + for (int d = 0; d < 6; d++) + { + int shadow = Dust.NewDust(projectile.position, projectile.width, projectile.height, 27, 0f, 0f, 100, new Color(0, 0, 0), 2f); + Main.dust[shadow].velocity *= 3f; + if (Main.rand.NextBool(2)) + { + Main.dust[shadow].scale = 0.5f; + Main.dust[shadow].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + for (int d = 0; d < 10; d++) + { + int shadow = Dust.NewDust(projectile.position, projectile.width, projectile.height, 27, 0f, 0f, 100, new Color(0, 0, 0), 3f); + Main.dust[shadow].noGravity = true; + Main.dust[shadow].velocity *= 5f; + shadow = Dust.NewDust(projectile.position, projectile.width, projectile.height, 27, 0f, 0f, 100, new Color(0, 0, 0), 2f); + Main.dust[shadow].velocity *= 2f; + } + } + + public override void AI() + { + Player owner = Main.player[projectile.owner]; + NPC target = CalamityUtils.MinionHoming(projectile.Center, 1800f, owner); + + if (projectile.scale >= 1f) + { + if (target != null) + { + float num550 = 40f; + Vector2 vector43 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); + float num551 = target.Center.X - vector43.X; + float num552 = target.Center.Y - vector43.Y; + float num553 = (float)Math.Sqrt((double)(num551 * num551 + num552 * num552)); + if (num553 < 100f) + { + num550 = 28f; //14 + } + num553 = num550 / num553; + num551 *= num553; + num552 *= num553; + projectile.velocity.X = (projectile.velocity.X * 25f + num551) / 26f; + projectile.velocity.Y = (projectile.velocity.Y * 25f + num552) / 26f; + if (Main.rand.NextBool(5)) + projectile.velocity *= 1.1f; + } + + } + else + { + projectile.scale += 0.025f; + projectile.velocity *= 1.03f; + } + + if (projectile.frameCounter > 6) + { + projectile.frame++; + projectile.frameCounter = 0; + } + if (projectile.frame >= Main.projFrames[projectile.type] - 1) + { + projectile.frame = 0; + } + projectile.frameCounter++; + + if (projectile.timeLeft <= 60) + { + projectile.alpha += 4; + } + } + } +} diff --git a/Projectiles/Summon/VoidConcentrationOrb.png b/Projectiles/Summon/VoidConcentrationOrb.png new file mode 100644 index 0000000000..036c9b9603 Binary files /dev/null and b/Projectiles/Summon/VoidConcentrationOrb.png differ diff --git a/Projectiles/Typeless/AstralSpray.cs b/Projectiles/Typeless/AstralSpray.cs index 5e9971ceca..01e3656923 100644 --- a/Projectiles/Typeless/AstralSpray.cs +++ b/Projectiles/Typeless/AstralSpray.cs @@ -31,7 +31,7 @@ namespace CalamityMod.Projectiles.Typeless int x = (int)(projectile.Center.X / 16f); int y = (int)(projectile.Center.Y / 16f); - WorldGenerationMethods.ConvertToAstral(x - 1, x + 1, y - 1, y + 1); + AstralBiome.ConvertToAstral(x - 1, x + 1, y - 1, y + 1); } if (projectile.timeLeft > 133) { diff --git a/Projectiles/Typeless/SepulcherSoul.cs b/Projectiles/Typeless/SepulcherSoul.cs new file mode 100644 index 0000000000..38e6ccace4 --- /dev/null +++ b/Projectiles/Typeless/SepulcherSoul.cs @@ -0,0 +1,42 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class SepulcherSoul : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Tormented Soul"); + Main.projFrames[projectile.type] = 3; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 16; + projectile.Opacity = 0f; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.timeLeft = 120; + } + + public override void AI() + { + if (projectile.localAI[0] == 0f) + { + projectile.frame = Main.rand.Next(Main.projFrames[projectile.type]); + projectile.localAI[0] = 1f; + } + Vector2 idealVelocity = Vector2.Zero; + idealVelocity.X = (float)(Math.Sin(Time / 27f + projectile.identity * 1.1f) + (float)Math.Cos(Math.E * (Time / 27f + projectile.identity * 1.1f))) * 4f; + idealVelocity.Y = MathHelper.SmoothStep(-3f, -9f, (float)Math.Sin(Time / 23f + projectile.identity * 1.1f) * 0.5f + 0.5f); + projectile.velocity = Vector2.Lerp(projectile.velocity, idealVelocity, 0.075f); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + projectile.Opacity = Utils.InverseLerp(0f, 15f, Time, true) * Utils.InverseLerp(0f, 25f, projectile.timeLeft, true); + Time++; + } + } +} diff --git a/Projectiles/Typeless/SepulcherSoul.png b/Projectiles/Typeless/SepulcherSoul.png new file mode 100644 index 0000000000..a59212a6b7 Binary files /dev/null and b/Projectiles/Typeless/SepulcherSoul.png differ diff --git a/Projectiles/Typeless/WaterConvertor.cs b/Projectiles/Typeless/WaterConvertor.cs index e5afdf2afe..0072558c70 100644 --- a/Projectiles/Typeless/WaterConvertor.cs +++ b/Projectiles/Typeless/WaterConvertor.cs @@ -41,23 +41,23 @@ namespace CalamityMod.Projectiles.Typeless { if (projectile.ai[0] == 0f) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Pure); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Pure); } if (projectile.ai[0] == 1f) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Corrupt); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Corrupt); } if (projectile.ai[0] == 2f) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Crimson); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Crimson); } if (projectile.ai[0] == 3f) { - WorldGenerationMethods.ConvertFromAstral(i, j, ConvertType.Hallow); + AstralBiome.ConvertFromAstral(i, j, ConvertType.Hallow); } if (projectile.ai[0] == 4f) { - WorldGenerationMethods.ConvertToAstral(i, j); + AstralBiome.ConvertToAstral(i, j); NetMessage.SendTileRange(-1, i, j, 1, 1); } } diff --git a/Schematics/LargeScrapPile1.csch b/Schematics/LargeScrapPile1.csch new file mode 100644 index 0000000000..71acadddb1 Binary files /dev/null and b/Schematics/LargeScrapPile1.csch differ diff --git a/Schematics/LargeScrapPile2.csch b/Schematics/LargeScrapPile2.csch new file mode 100644 index 0000000000..415cbbcfc6 Binary files /dev/null and b/Schematics/LargeScrapPile2.csch differ diff --git a/Schematics/LargeScrapPile3.csch b/Schematics/LargeScrapPile3.csch new file mode 100644 index 0000000000..3faf1e1d48 Binary files /dev/null and b/Schematics/LargeScrapPile3.csch differ diff --git a/Schematics/LargeScrapPile4.csch b/Schematics/LargeScrapPile4.csch new file mode 100644 index 0000000000..d444a71416 Binary files /dev/null and b/Schematics/LargeScrapPile4.csch differ diff --git a/Schematics/SchematicManager.cs b/Schematics/SchematicManager.cs index 0dda76c2b1..031a94261e 100644 --- a/Schematics/SchematicManager.cs +++ b/Schematics/SchematicManager.cs @@ -33,6 +33,16 @@ namespace CalamityMod.Schematics // Astral world gen structures ["Astral Beacon"] = CalamitySchematicIO.LoadSchematic("Schematics/AstralBeacon.csch"), + + // Sulphurous Sea scrap world gen structures + ["Sulphurous Scrap 1"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile1.csch").ShaveOffEdge(), + ["Sulphurous Scrap 2"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile2.csch").ShaveOffEdge(), + ["Sulphurous Scrap 3"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile3.csch").ShaveOffEdge(), + ["Sulphurous Scrap 4"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile4.csch").ShaveOffEdge(), + ["Large Sulphurous Scrap 1"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile1.csch").ShaveOffEdge(), + ["Large Sulphurous Scrap 2"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile2.csch").ShaveOffEdge(), + ["Large Sulphurous Scrap 3"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile3.csch").ShaveOffEdge(), + ["Large Sulphurous Scrap 4"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile4.csch").ShaveOffEdge(), }; } internal static void Unload() @@ -41,7 +51,18 @@ namespace CalamityMod.Schematics PilePlacementMaps = null; } #endregion + + #region Get Schematic Area + public static Vector2? GetSchematicArea(string name) + { + // If no schematic exists with this name, simply return null. + if (!TileMaps.TryGetValue(name, out SchematicMetaTile[,] schematic)) + return null; + return new Vector2(schematic.GetLength(0), schematic.GetLength(1)); + } + #endregion Get Schematic Area + #region Place Schematic public static void PlaceSchematic(string name, Point pos, SchematicAnchor anchorType, ref bool specialCondition, T chestDelegate = null) where T : Delegate { diff --git a/Schematics/SmallScrapPile1.csch b/Schematics/SmallScrapPile1.csch new file mode 100644 index 0000000000..71adf27c17 Binary files /dev/null and b/Schematics/SmallScrapPile1.csch differ diff --git a/Schematics/SmallScrapPile2.csch b/Schematics/SmallScrapPile2.csch new file mode 100644 index 0000000000..51fc4a598e Binary files /dev/null and b/Schematics/SmallScrapPile2.csch differ diff --git a/Schematics/SmallScrapPile3.csch b/Schematics/SmallScrapPile3.csch new file mode 100644 index 0000000000..6d291fcf13 Binary files /dev/null and b/Schematics/SmallScrapPile3.csch differ diff --git a/Schematics/SmallScrapPile4.csch b/Schematics/SmallScrapPile4.csch new file mode 100644 index 0000000000..0161115799 Binary files /dev/null and b/Schematics/SmallScrapPile4.csch differ diff --git a/NPCs/SupremeCalamitas/SCalScreenShaderData.cs b/Skies/SCalScreenShaderData.cs similarity index 94% rename from NPCs/SupremeCalamitas/SCalScreenShaderData.cs rename to Skies/SCalScreenShaderData.cs index 7f0b3dca34..af7e823da1 100644 --- a/NPCs/SupremeCalamitas/SCalScreenShaderData.cs +++ b/Skies/SCalScreenShaderData.cs @@ -1,8 +1,9 @@ +using CalamityMod.NPCs.SupremeCalamitas; using Terraria; using Terraria.Graphics.Shaders; using Terraria.ModLoader; -namespace CalamityMod.NPCs.SupremeCalamitas +namespace CalamityMod.Skies { public class SCalScreenShaderData : ScreenShaderData { diff --git a/Skies/SCalSky.cs b/Skies/SCalSky.cs new file mode 100644 index 0000000000..d0e2978fe8 --- /dev/null +++ b/Skies/SCalSky.cs @@ -0,0 +1,246 @@ +using CalamityMod.NPCs; +using CalamityMod.NPCs.SupremeCalamitas; +using CalamityMod.Projectiles.Boss; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.Graphics.Effects; +using Terraria.ModLoader; + +namespace CalamityMod.Skies +{ + public class SCalSky : CustomSky + { + public class Cinder + { + public int Time; + public int Lifetime; + public int IdentityIndex; + public float Scale; + public float Depth; + public Color DrawColor; + public Vector2 Velocity; + public Vector2 Center; + public Cinder(int lifetime, int identity, float depth, Color color, Vector2 startingPosition, Vector2 startingVelocity) + { + Lifetime = lifetime; + IdentityIndex = identity; + Depth = depth; + DrawColor = color; + Center = startingPosition; + Velocity = startingVelocity; + } + } + + private bool isActive = false; + private float intensity = 0f; + private int SCalIndex = -1; + public List Cinders = new List(); + public static int CinderReleaseChance + { + get + { + if (!Main.npc.IndexInRange(CalamityGlobalNPC.SCal) || Main.npc[CalamityGlobalNPC.SCal].type != ModContent.NPCType()) + return int.MaxValue; + + NPC scal = Main.npc[CalamityGlobalNPC.SCal]; + float lifeRatio = scal.life / (float)scal.lifeMax; + + // Release a good amount of cinders during bullet hells. If this is too distracting this can be + // inverted so that less appear than usual instead. + if (scal.ModNPC().bulletHellCounter2 % 900 != 0) + return lifeRatio <= 0.1f ? 8 : 11; + + // Release more and more cinders at the end of the battle until the acceptance phase, where it all slows down dramatically, with just a few ashes. + if (lifeRatio < 0.1f) + { + if (lifeRatio <= 0.01f) + return 32; + + return (int)Math.Round(MathHelper.Lerp(2f, 11f, Utils.InverseLerp(0.03f, 0.1f, lifeRatio, true))); + } + + // Release a good amount of cinders while brothers or Sepulcher-1 are alive. Sepulcher-2 falls into an above case and does not execute this return. + if (NPC.AnyNPCs(ModContent.NPCType()) || NPC.AnyNPCs(ModContent.NPCType()) || NPC.AnyNPCs(ModContent.NPCType())) + return 10; + + // Release a moderate amount of cinders normally. + return 18; + } + } + public static float CinderSpeed + { + get + { + if (!Main.npc.IndexInRange(CalamityGlobalNPC.SCal) || Main.npc[CalamityGlobalNPC.SCal].type != ModContent.NPCType()) + return 0f; + + NPC scal = Main.npc[CalamityGlobalNPC.SCal]; + float lifeRatio = scal.life / (float)scal.lifeMax; + + // Move more and more quickly at the end of the battle until the acceptance phase, where it all slows down dramatically. + if (lifeRatio < 0.1f) + { + if (lifeRatio <= 0.01f) + return 4.5f; + + return MathHelper.Lerp(10.75f, 6.7f, Utils.InverseLerp(0.03f, 0.1f, lifeRatio, true)); + } + + // Move a little quickly while brothers or Sepulcher-1 are alive. Sepulcher-2 falls into an above case and does not execute this return. + if (NPC.AnyNPCs(ModContent.NPCType()) || NPC.AnyNPCs(ModContent.NPCType()) || NPC.AnyNPCs(ModContent.NPCType())) + return 7.4f; + + // Move moderately quickly usually. + return 5.6f; + } + } + public static float OverridingIntensity = 0f; + + public override void Update(GameTime gameTime) + { + if (isActive && intensity < 1f) + { + intensity += 0.01f; + } + else if (!isActive && intensity > 0f) + { + intensity -= 0.01f; + } + + Color selectCinderColor() + { + if (!Main.npc.IndexInRange(CalamityGlobalNPC.SCal) || Main.npc[CalamityGlobalNPC.SCal].type != ModContent.NPCType()) + return Color.Transparent; + + NPC scal = Main.npc[CalamityGlobalNPC.SCal]; + float lifeRatio = scal.life / (float)scal.lifeMax; + if (lifeRatio > 0.5f) + return Color.Lerp(Color.Red, Color.Orange, Main.rand.NextFloat(0.8f)); + else if (lifeRatio > 0.3f) + return Color.Lerp(Color.DarkRed, Color.Lerp(Color.Blue, Color.DarkBlue, Main.rand.NextFloat() * 0.65f), 0.45f); + else if (lifeRatio > 0.01f) + return Color.Lerp(Color.Red, Color.Yellow, Main.rand.NextFloat(0.2f, 0.9f)); + else + return Color.Gray; + } + + // Randomly add cinders. + if (intensity >= 1f && Main.rand.NextBool(CinderReleaseChance)) + { + int lifetime = Main.rand.Next(285, 445); + float depth = Main.rand.NextFloat(1.8f, 5f); + Vector2 startingPosition = Main.screenPosition + new Vector2(Main.screenWidth * Main.rand.NextFloat(-0.1f, 1.1f), Main.screenHeight * 1.05f); + Vector2 startingVelocity = -Vector2.UnitY.RotatedByRandom(0.91f); + Cinders.Add(new Cinder(lifetime, Cinders.Count, depth, selectCinderColor(), startingPosition, startingVelocity)); + } + + // Update all cinders. + for (int i = 0; i < Cinders.Count; i++) + { + Cinders[i].Scale = Utils.InverseLerp(Cinders[i].Lifetime, Cinders[i].Lifetime / 3, Cinders[i].Time, true); + Cinders[i].Scale *= MathHelper.Lerp(0.6f, 0.9f, Cinders[i].IdentityIndex % 6f / 6f); + + Vector2 idealVelocity = -Vector2.UnitY.RotatedBy(MathHelper.Lerp(-0.94f, 0.94f, (float)Math.Sin(Cinders[i].Time / 36f + Cinders[i].IdentityIndex) * 0.5f + 0.5f)) * CinderSpeed; + float movementInterpolant = MathHelper.Lerp(0.01f, 0.08f, Utils.InverseLerp(45f, 145f, Cinders[i].Time, true)); + Cinders[i].Velocity = Vector2.Lerp(Cinders[i].Velocity, idealVelocity, movementInterpolant); + Cinders[i].Velocity = Cinders[i].Velocity.SafeNormalize(-Vector2.UnitY) * CinderSpeed; + Cinders[i].Time++; + + Cinders[i].Center += Cinders[i].Velocity; + } + + // Clear away all dead cinders. + Cinders.RemoveAll(c => c.Time >= c.Lifetime); + } + + private float GetIntensity() + { + if (CalamityUtils.CountProjectiles(ModContent.ProjectileType()) > 0) + return OverridingIntensity; + + OverridingIntensity = 0f; + if (UpdateSCalIndex()) + { + float x = 0f; + if (SCalIndex != -1) + x = Vector2.Distance(Main.player[Main.myPlayer].Center, Main.npc[this.SCalIndex].Center); + + return 1f - Utils.SmoothStep(3000f, 6000f, x); + } + return 0f; + } + + public override Color OnTileColor(Color inColor) => new Color(Vector4.Lerp(new Vector4(0.5f, 0.8f, 1f, 1f), inColor.ToVector4(), 1f - GetIntensity())); + + private bool UpdateSCalIndex() + { + int SCalType = ModContent.NPCType(); + if (SCalIndex >= 0 && Main.npc[SCalIndex].active && Main.npc[SCalIndex].type == SCalType) + { + return true; + } + SCalIndex = -1; + for (int i = 0; i < Main.npc.Length; i++) + { + if (Main.npc[i].active && Main.npc[i].type == SCalType) + { + SCalIndex = i; + break; + } + } + return SCalIndex != -1; + } + + public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) + { + if (maxDepth >= 0 && minDepth < 0) + { + float intensity = GetIntensity(); + spriteBatch.Draw(Main.blackTileTexture, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.Black * intensity); + } + + // Draw cinders. + Texture2D cinderTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/CalamitasCinder"); + for (int i = 0; i < Cinders.Count; i++) + { + Vector2 drawPosition = Cinders[i].Center - Main.screenPosition; + for (int j = 0; j < 3; j++) + { + Vector2 offsetDrawPosition = drawPosition + (MathHelper.TwoPi * j / 3f).ToRotationVector2() * 1.4f; + Color offsetDrawColor = Color.Red * 0.56f; + offsetDrawColor.A = 0; + spriteBatch.Draw(cinderTexture, offsetDrawPosition, null, offsetDrawColor, 0f, cinderTexture.Size() * 0.5f, Cinders[i].Scale * 1.5f, SpriteEffects.None, 0f); + } + spriteBatch.Draw(cinderTexture, drawPosition, null, Cinders[i].DrawColor, 0f, cinderTexture.Size() * 0.5f, Cinders[i].Scale, SpriteEffects.None, 0f); + } + } + + public override float GetCloudAlpha() + { + return 0f; + } + + public override void Activate(Vector2 position, params object[] args) + { + isActive = true; + } + + public override void Deactivate(params object[] args) + { + isActive = false; + } + + public override void Reset() + { + isActive = false; + } + + public override bool IsActive() + { + return isActive || intensity > 0f; + } + } +} diff --git a/Sounds/Custom/SCalSounds/SepulcherSpawn.cs b/Sounds/Custom/SCalSounds/SepulcherSpawn.cs new file mode 100644 index 0000000000..45ffb992dd --- /dev/null +++ b/Sounds/Custom/SCalSounds/SepulcherSpawn.cs @@ -0,0 +1,18 @@ +using Microsoft.Xna.Framework.Audio; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Sounds.Custom.SCalSounds +{ + public class SepulcherSpawn : ModSound + { + public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type) + { + soundInstance = sound.CreateInstance(); + soundInstance.Volume = volume; + soundInstance.Pan = pan; + Main.PlaySoundInstance(soundInstance); + return soundInstance; + } + } +} diff --git a/Sounds/Custom/SCalSounds/SepulcherSpawn.ogg b/Sounds/Custom/SCalSounds/SepulcherSpawn.ogg new file mode 100644 index 0000000000..b0b6e2ccf8 Binary files /dev/null and b/Sounds/Custom/SCalSounds/SepulcherSpawn.ogg differ diff --git a/Sounds/Custom/THanosLaser.ogg b/Sounds/Custom/THanosLaser.ogg new file mode 100644 index 0000000000..46efb4dc75 Binary files /dev/null and b/Sounds/Custom/THanosLaser.ogg differ diff --git a/Sounds/NPCKilled/SepulcherDeath.cs b/Sounds/NPCKilled/SepulcherDeath.cs new file mode 100644 index 0000000000..d4e74ea577 --- /dev/null +++ b/Sounds/NPCKilled/SepulcherDeath.cs @@ -0,0 +1,18 @@ +using Microsoft.Xna.Framework.Audio; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Sounds.NPCKilled +{ + public class SepulcherDeath : ModSound + { + public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type) + { + soundInstance = sound.CreateInstance(); + soundInstance.Volume = volume; + soundInstance.Pan = pan; + Main.PlaySoundInstance(soundInstance); + return soundInstance; + } + } +} diff --git a/Sounds/NPCKilled/SepulcherDeath.ogg b/Sounds/NPCKilled/SepulcherDeath.ogg new file mode 100644 index 0000000000..8da5bc6466 Binary files /dev/null and b/Sounds/NPCKilled/SepulcherDeath.ogg differ diff --git a/Utilities/CollisionUtils.cs b/Utilities/CollisionUtils.cs index 2ba78d6163..13537d71e1 100644 --- a/Utilities/CollisionUtils.cs +++ b/Utilities/CollisionUtils.cs @@ -24,5 +24,29 @@ namespace CalamityMod float _ = 0f; return Collision.CheckAABBvLineCollision(targetTopLeft, targetHitboxDimensions, start, end, entity.width, ref _); } + + /// + /// Determines if a typical hitbox rectangle is intersecting a circular hitbox. + /// + /// The center of the circular hitbox. + /// The radius of the circular hitbox. + /// The hitbox of the target to check. + public static bool CircularHitboxCollision(Vector2 centerCheckPosition, float radius, Rectangle targetHitbox) + { + float topLeftDistance = Vector2.Distance(centerCheckPosition, targetHitbox.TopLeft()); + float topRightDistance = Vector2.Distance(centerCheckPosition, targetHitbox.TopRight()); + float bottomLeftDistance = Vector2.Distance(centerCheckPosition, targetHitbox.BottomLeft()); + float bottomRightDistance = Vector2.Distance(centerCheckPosition, targetHitbox.BottomRight()); + + float distanceToClosestPoint = topLeftDistance; + if (topRightDistance < distanceToClosestPoint) + distanceToClosestPoint = topRightDistance; + if (bottomLeftDistance < distanceToClosestPoint) + distanceToClosestPoint = bottomLeftDistance; + if (bottomRightDistance < distanceToClosestPoint) + distanceToClosestPoint = bottomRightDistance; + + return distanceToClosestPoint <= radius; + } } } diff --git a/Utilities/MiscUtils.cs b/Utilities/MiscUtils.cs index 12b400734c..31d3f21c91 100644 --- a/Utilities/MiscUtils.cs +++ b/Utilities/MiscUtils.cs @@ -44,6 +44,19 @@ namespace CalamityMod 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; + } + /// /// Retrieves all the colors from a and returns them as a 2D array. /// @@ -294,5 +307,12 @@ namespace CalamityMod end = start + Vector2.Normalize(end - start) * maxDistance; } } + + public static void ChangeTime(bool changeToDay) + { + Main.time = 0D; + Main.dayTime = changeToDay; + CalamityNetcode.SyncWorld(); + } } } diff --git a/Utilities/NPCDebuffs.cs b/Utilities/NPCDebuffs.cs index 794f7ce459..8c214aa6bc 100644 --- a/Utilities/NPCDebuffs.cs +++ b/Utilities/NPCDebuffs.cs @@ -190,7 +190,7 @@ namespace CalamityMod { ModContent.NPCType(), new Tuple(false, CalamityMod.cragEnemyImmunities) }, { ModContent.NPCType(), new Tuple(false, CalamityMod.cragEnemyImmunities) }, { ModContent.NPCType(), new Tuple(false, CalamityMod.cragEnemyImmunities) }, - { ModContent.NPCType(), new Tuple(false, CalamityMod.cragEnemyImmunities) }, + { ModContent.NPCType(), new Tuple(false, CalamityMod.cragEnemyImmunities) }, { ModContent.NPCType(), new Tuple(true, new int[] { }) }, { ModContent.NPCType(), new Tuple(true, new int[] { }) }, { ModContent.NPCType(), new Tuple(true, new int[] { }) }, diff --git a/Utilities/WorldgenUtils.cs b/Utilities/WorldgenUtils.cs new file mode 100644 index 0000000000..7552177cc3 --- /dev/null +++ b/Utilities/WorldgenUtils.cs @@ -0,0 +1,35 @@ +using System.Linq; +using Terraria; +using Terraria.ID; + +namespace CalamityMod +{ + public static partial class CalamityUtils + { + /// + /// Generates clusters of ore across the world based on various requirements and with various strengths/frequencies. + /// + /// + /// + /// + /// + /// + /// + /// + public static void SpawnOre(int type, double frequency, float verticalStartFactor, float verticalEndFactor, int strengthMin, int strengthMax, params int[] convertibleTiles) + { + int x = Main.maxTilesX; + int y = Main.maxTilesY; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + for (int k = 0; k < (int)(x * y * frequency); k++) + { + int tilesX = WorldGen.genRand.Next(0, x); + int tilesY = WorldGen.genRand.Next((int)(y * verticalStartFactor), (int)(y * verticalEndFactor)); + if (convertibleTiles.Length <= 0 || convertibleTiles.Contains(ParanoidTileRetrieval(tilesX, tilesY).type)) + WorldGen.OreRunner(tilesX, tilesY, WorldGen.genRand.Next(strengthMin, strengthMax), WorldGen.genRand.Next(3, 8), (ushort)type); + } + } + } + } +} diff --git a/World/Abyss.cs b/World/Abyss.cs index e8ced8b34c..3bb51503c8 100644 --- a/World/Abyss.cs +++ b/World/Abyss.cs @@ -1,13 +1,24 @@ +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Pets; +using CalamityMod.Items.Tools.ClimateChange; +using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Items.Weapons.Melee; +using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.Items.Weapons.Rogue; +using CalamityMod.Items.Weapons.Summon; using CalamityMod.Tiles.Abyss; using CalamityMod.Tiles.FurnitureVoid; +using CalamityMod.Tiles.Ores; using CalamityMod.Walls; +using Microsoft.Xna.Framework; +using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.World { - public class Abyss : ModWorld + public class Abyss { public static void PlaceAbyss() { @@ -219,7 +230,7 @@ namespace CalamityMod.World } } - WorldGenerationMethods.ChasmGenerator(abyssChasmX, (int)WorldGen.worldSurfaceLow, CalamityWorld.abyssChasmBottom, true); + MiscWorldgenRoutines.ChasmGenerator(abyssChasmX, (int)WorldGen.worldSurfaceLow, CalamityWorld.abyssChasmBottom, true); int maxAbyssIslands = 11; //Small World if (y > 2100) @@ -227,8 +238,9 @@ namespace CalamityMod.World else if (y > 1500) maxAbyssIslands = 16; //Medium World - WorldGenerationMethods.SpecialHut((ushort)ModContent.TileType(), (ushort)ModContent.TileType(), - (ushort)ModContent.WallType(), 8, abyssChasmX, CalamityWorld.abyssChasmBottom); + // Place the Terminus shrine. + UndergroundShrines.SpecialHut((ushort)ModContent.TileType(), (ushort)ModContent.TileType(), + (ushort)ModContent.WallType(), UndergroundShrines.UndergroundShrineType.Abyss, abyssChasmX, CalamityWorld.abyssChasmBottom); int islandLocationOffset = 30; int islandLocationY = rockLayer; @@ -241,32 +253,32 @@ namespace CalamityMod.World switch (randomIsland) { case 0: - WorldGenerationMethods.AbyssIsland(islandLocationX, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX + 40, islandLocationY + 15, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX - 40, islandLocationY + 15, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); + AbyssIsland(islandLocationX + 40, islandLocationY + 15, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX - 40, islandLocationY + 15, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); break; case 1: - WorldGenerationMethods.AbyssIsland(islandLocationX + 30, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX, islandLocationY + 15, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX - 40, islandLocationY + 10, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX + 30, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); + AbyssIsland(islandLocationX, islandLocationY + 15, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX - 40, islandLocationY + 10, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); islandLocationX += 30; break; case 2: - WorldGenerationMethods.AbyssIsland(islandLocationX - 30, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX + 30, islandLocationY + 10, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX, islandLocationY + 15, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX - 30, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); + AbyssIsland(islandLocationX + 30, islandLocationY + 10, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX, islandLocationY + 15, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); islandLocationX -= 30; break; case 3: - WorldGenerationMethods.AbyssIsland(islandLocationX + 25, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX - 5, islandLocationY + 5, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX - 35, islandLocationY + 15, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX + 25, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); + AbyssIsland(islandLocationX - 5, islandLocationY + 5, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX - 35, islandLocationY + 15, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); islandLocationX += 25; break; case 4: - WorldGenerationMethods.AbyssIsland(islandLocationX - 25, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX + 5, islandLocationY + 15, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); - WorldGenerationMethods.AbyssIsland(islandLocationX + 35, islandLocationY + 5, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX - 25, islandLocationY, 60, 66, 30, 36, true, false, hasVoidstone); + AbyssIsland(islandLocationX + 5, islandLocationY + 15, 60, 66, 30, 36, false, tenebrisSide, hasVoidstone); + AbyssIsland(islandLocationX + 35, islandLocationY + 5, 60, 66, 30, 36, false, !tenebrisSide, hasVoidstone); islandLocationX -= 25; break; } @@ -283,7 +295,7 @@ namespace CalamityMod.World for (int abyssHouse = 0; abyssHouse < CalamityWorld.numAbyssIslands; abyssHouse++) //11 15 19 { if (abyssHouse != 20) - WorldGenerationMethods.AbyssIslandHouse(CalamityWorld.AbyssIslandX[abyssHouse], + AbyssIslandHouse(CalamityWorld.AbyssIslandX[abyssHouse], CalamityWorld.AbyssIslandY[abyssHouse], CalamityWorld.AbyssItemArray[abyssHouse > 9 ? (abyssHouse - 10) : abyssHouse], //10 choices 0 to 9 CalamityWorld.AbyssIslandY[abyssHouse] > (rockLayer + y * 0.143)); @@ -350,5 +362,460 @@ namespace CalamityMod.World } } } - } + + #region Houses + public static void AbyssIsland(int i, int j, int sizeMin, int sizeMax, int sizeMin2, int sizeMax2, bool hasChest, bool hasTenebris, bool isVoid) + { + int sizeMinSmall = sizeMin / 5; + int sizeMaxSmall = sizeMax / 5; + double num = (double)WorldGen.genRand.Next(sizeMin, sizeMax); //100 150 + float num2 = (float)WorldGen.genRand.Next(sizeMinSmall, sizeMaxSmall); //20 30 + int num3 = i; + int num4 = i; + int num5 = i; + int num6 = j; + Vector2 vector; + vector.X = (float)i; + vector.Y = (float)j; + Vector2 vector2; + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + while (vector2.X > -2f && vector2.X < 2f) + { + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + } + vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; + while (num > 0.0 && num2 > 0f) + { + num -= (double)WorldGen.genRand.Next(4); + num2 -= 1f; + int num7 = (int)((double)vector.X - num * 0.5); + int num8 = (int)((double)vector.X + num * 0.5); + int num9 = (int)((double)vector.Y - num * 0.5); + int num10 = (int)((double)vector.Y + num * 0.5); + if (num7 < 0) + { + num7 = 0; + } + if (num8 > Main.maxTilesX) + { + num8 = Main.maxTilesX; + } + if (num9 < 0) + { + num9 = 0; + } + if (num10 > Main.maxTilesY) + { + num10 = Main.maxTilesY; + } + double num11 = num * (double)WorldGen.genRand.Next(sizeMin, sizeMax) * 0.01; //80 120 + float num12 = vector.Y + 1f; + for (int k = num7; k < num8; k++) + { + if (WorldGen.genRand.Next(2) == 0) + { + num12 += (float)WorldGen.genRand.Next(-1, 2); + } + if (num12 < vector.Y) + { + num12 = vector.Y; + } + if (num12 > vector.Y + 2f) + { + num12 = vector.Y + 2f; + } + for (int l = num9; l < num10; l++) + { + if ((float)l > num12) + { + float arg_218_0 = Math.Abs((float)k - vector.X); + float num13 = Math.Abs((float)l - vector.Y) * 3f; + if (Math.Sqrt((double)(arg_218_0 * arg_218_0 + num13 * num13)) < num11 * 0.4) + { + if (k < num3) + { + num3 = k; + } + if (k > num4) + { + num4 = k; + } + if (l < num5) + { + num5 = l; + } + if (l > num6) + { + num6 = l; + } + Main.tile[k, l].active(true); + Main.tile[k, l].type = (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType()); + CalamityUtils.SafeSquareTileFrame(k, l, true); + } + } + } + } + vector += vector2; + vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; + if (vector2.X > 1f) + { + vector2.X = 1f; + } + if (vector2.X < -1f) + { + vector2.X = -1f; + } + if ((double)vector2.Y > 0.2) + { + vector2.Y = -0.2f; + } + if ((double)vector2.Y < -0.2) + { + vector2.Y = -0.2f; + } + } + int m = num3; + int num15; + for (m += WorldGen.genRand.Next(5); m < num4; m += WorldGen.genRand.Next(num15, (int)((double)num15 * 1.5))) + { + int num14 = num6; + while (!Main.tile[m, num14].active()) + { + num14--; + } + num14 += WorldGen.genRand.Next(-3, 4); + num15 = WorldGen.genRand.Next(4, 8); + int num16 = isVoid ? ModContent.TileType() : ModContent.TileType(); + if (WorldGen.genRand.Next(4) == 0) + { + num16 = hasChest ? ModContent.TileType() : ModContent.TileType(); + } + for (int n = m - num15; n <= m + num15; n++) + { + for (int num17 = num14 - num15; num17 <= num14 + num15; num17++) + { + if (num17 > num5) + { + float arg_409_0 = (float)Math.Abs(n - m); + float num18 = (float)(Math.Abs(num17 - num14) * 2); + if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num15 + WorldGen.genRand.Next(2))) + { + Main.tile[n, num17].active(true); + Main.tile[n, num17].type = (ushort)num16; + CalamityUtils.SafeSquareTileFrame(n, num17, true); + } + } + } + } + } + if (hasTenebris) + { + int p = num3; + int num150; + for (p += WorldGen.genRand.Next(5); p < num4; p += WorldGen.genRand.Next(num150, (int)((double)num150 * 1.5))) + { + int num14 = num6; + while (!Main.tile[p, num14].active()) + { + num14--; + } + num14 += WorldGen.genRand.Next(-3, 4); //-3 4 + num150 = 1; //4 8 + int num16 = ModContent.TileType(); + for (int n = p - num150; n <= p + num150; n++) + { + for (int num17 = num14 - num150; num17 <= num14 + num150; num17++) + { + if (num17 > num5) + { + float arg_409_0 = (float)Math.Abs(n - p); + float num18 = (float)(Math.Abs(num17 - num14) * 2); + if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num150 + WorldGen.genRand.Next(2))) + { + Main.tile[n, num17].active(true); + Main.tile[n, num17].type = (ushort)num16; + CalamityUtils.SafeSquareTileFrame(n, num17, true); + } + } + } + } + } + } + int sizeMinSmall2 = sizeMin2 / 8; + int sizeMaxSmall2 = sizeMax2 / 8; + num = (double)WorldGen.genRand.Next(sizeMin2, sizeMax2); + num2 = (float)WorldGen.genRand.Next(sizeMinSmall2, sizeMaxSmall2); + vector.X = (float)i; + vector.Y = (float)num5; + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + while (vector2.X > -2f && vector2.X < 2f) + { + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + } + vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; + while (num > 0.0 && num2 > 0f) + { + num -= (double)WorldGen.genRand.Next(4); + num2 -= 1f; + vector += vector2; + vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; + if (vector2.X > 1f) + { + vector2.X = 1f; + } + if (vector2.X < -1f) + { + vector2.X = -1f; + } + if ((double)vector2.Y > 0.2) + { + vector2.Y = -0.2f; + } + if ((double)vector2.Y < -0.2) + { + vector2.Y = -0.2f; + } + } + int num23 = num3; + num23 += WorldGen.genRand.Next(5); + while (num23 < num4) + { + int num24 = num6; + while ((!Main.tile[num23, num24].active() || Main.tile[num23, num24].type != 0) && num23 < num4) + { + num24--; + if (num24 < num5) + { + num24 = num6; + num23 += WorldGen.genRand.Next(1, 4); + } + } + if (num23 < num4) + { + num24 += WorldGen.genRand.Next(0, 4); + int num25 = WorldGen.genRand.Next(2, 5); + int num26 = isVoid ? ModContent.TileType() : ModContent.TileType(); + for (int num27 = num23 - num25; num27 <= num23 + num25; num27++) + { + for (int num28 = num24 - num25; num28 <= num24 + num25; num28++) + { + if (num28 > num5) + { + float arg_890_0 = (float)Math.Abs(num27 - num23); + float num29 = (float)(Math.Abs(num28 - num24) * 2); + if (Math.Sqrt((double)(arg_890_0 * arg_890_0 + num29 * num29)) < (double)num25) + { + Main.tile[num27, num28].type = (ushort)num26; + CalamityUtils.SafeSquareTileFrame(num27, num28, true); + } + } + } + } + num23 += WorldGen.genRand.Next(num25, (int)((double)num25 * 1.5)); + } + } + for (int num30 = num3 - 20; num30 <= num4 + 20; num30++) + { + for (int num31 = num5 - 20; num31 <= num6 + 20; num31++) + { + bool flag = true; + for (int num32 = num30 - 1; num32 <= num30 + 1; num32++) + { + for (int num33 = num31 - 1; num33 <= num31 + 1; num33++) + { + if (!Main.tile[num32, num33].active()) + { + flag = false; + } + } + } + if (flag) + { + Main.tile[num30, num31].wall = (ushort)(isVoid ? ModContent.WallType() : ModContent.WallType()); + WorldGen.SquareWallFrame(num30, num31, true); + } + } + } + for (int num34 = num3; num34 <= num4; num34++) + { + int num35 = num5 - 10; + while (!Main.tile[num34, num35 + 1].active()) + { + num35++; + } + if (num35 < num6 && Main.tile[num34, num35 + 1].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) + { + if (WorldGen.genRand.Next(10) == 0) + { + int num36 = WorldGen.genRand.Next(1, 3); + for (int num37 = num34 - num36; num37 <= num34 + num36; num37++) + { + if (Main.tile[num37, num35].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) + { + Main.tile[num37, num35].active(false); + Main.tile[num37, num35].liquid = 255; + Main.tile[num37, num35].lava(false); + CalamityUtils.SafeSquareTileFrame(num34, num35, true); + } + if (Main.tile[num37, num35 + 1].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) + { + Main.tile[num37, num35 + 1].active(false); + Main.tile[num37, num35 + 1].liquid = 255; + Main.tile[num37, num35 + 1].lava(false); + CalamityUtils.SafeSquareTileFrame(num34, num35 + 1, true); + } + if (num37 > num34 - num36 && num37 < num34 + 2 && Main.tile[num37, num35 + 2].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) + { + Main.tile[num37, num35 + 2].active(false); + Main.tile[num37, num35 + 2].liquid = 255; + Main.tile[num37, num35 + 2].lava(false); + CalamityUtils.SafeSquareTileFrame(num34, num35 + 2, true); + } + } + } + if (WorldGen.genRand.Next(5) == 0) + { + Main.tile[num34, num35].liquid = 255; + } + Main.tile[num34, num35].lava(false); + CalamityUtils.SafeSquareTileFrame(num34, num35, true); + } + } + } + + public static void AbyssIslandHouse(int i, int j, int itemChoice, bool isVoid) + { + ushort type = (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType()); //tile + ushort wall = (ushort)(isVoid ? ModContent.WallType() : ModContent.WallType()); //wall + Vector2 vector = new Vector2((float)i, (float)j); + int num = 1; + if (WorldGen.genRand.Next(2) == 0) + { + num = -1; + } + int num2 = WorldGen.genRand.Next(5, 9); + int num3 = 3; + vector.X = (float)(i + (num2 + 2) * num); + for (int k = j - 15; k < j + 30; k++) + { + if (Main.tile[(int)vector.X, k].active()) + { + vector.Y = (float)(k - 1); + break; + } + } + vector.X = (float)i; + int num4 = (int)(vector.X - (float)num2 - 1f); + int num5 = (int)(vector.X + (float)num2 + 1f); + int num6 = (int)(vector.Y - (float)num3 - 1f); + int num7 = (int)(vector.Y + 2f); + if (num4 < 0) + { + num4 = 0; + } + if (num5 > Main.maxTilesX) + { + num5 = Main.maxTilesX; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int l = num4; l <= num5; l++) + { + for (int m = num6 - 1; m < num7 + 1; m++) + { + if (m != num6 - 1 || (l != num4 && l != num5)) + { + Main.tile[l, m].active(true); + Main.tile[l, m].type = type; + Main.tile[l, m].wall = wall; + Main.tile[l, m].halfBrick(false); + Main.tile[l, m].slope(0); + } + } + } + num4 = (int)(vector.X - (float)num2); + num5 = (int)(vector.X + (float)num2); + num6 = (int)(vector.Y - (float)num3); + num7 = (int)(vector.Y + 1f); + if (num4 < 0) + { + num4 = 0; + } + if (num5 > Main.maxTilesX) + { + num5 = Main.maxTilesX; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int n = num4; n <= num5; n++) + { + for (int num8 = num6; num8 < num7; num8++) + { + if ((num8 != num6 || (n != num4 && n != num5)) && Main.tile[n, num8].wall == wall) + { + Main.tile[n, num8].active(false); + } + } + } + int num9 = i + (num2 + 1) * num; + int num10 = (int)vector.Y; + for (int num11 = num9 - 2; num11 <= num9 + 2; num11++) + { + Main.tile[num11, num10].active(false); + Main.tile[num11, num10 - 1].active(false); + Main.tile[num11, num10 - 2].active(false); + } + switch (itemChoice) + { + case 0: + itemChoice = ModContent.ItemType(); + break; //rain item + case 1: + itemChoice = ModContent.ItemType(); + break; //movement acc + case 2: + itemChoice = ModContent.ItemType(); + break; //regen acc + case 3: + itemChoice = ModContent.ItemType(); + break; //ranged + case 4: + itemChoice = ModContent.ItemType(); + break; //defense acc + case 5: + itemChoice = ModContent.ItemType(); + break; //melee + case 6: + itemChoice = ModContent.ItemType(); + break; //light pet + case 7: + itemChoice = ModContent.ItemType(); + break; //summon + case 8: + itemChoice = ModContent.ItemType(); + break; //magic + case 9: + itemChoice = ModContent.ItemType(); + break; //throwing + default: + itemChoice = 497; + break; + } + WorldGen.AddBuriedChest(i, num10 - 3, itemChoice, false, 4); //chest + } + #endregion + + } } diff --git a/World/AstralBiome.cs b/World/AstralBiome.cs new file mode 100644 index 0000000000..8d44f12849 --- /dev/null +++ b/World/AstralBiome.cs @@ -0,0 +1,1175 @@ +using CalamityMod.Schematics; +using CalamityMod.Tiles.Abyss; +using CalamityMod.Tiles.Astral; +using CalamityMod.Tiles.AstralDesert; +using CalamityMod.Tiles.AstralSnow; +using CalamityMod.Tiles.FurnitureVoid; +using CalamityMod.Tiles.Ores; +using CalamityMod.Walls; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Utilities; +using Terraria.World.Generation; + +namespace CalamityMod.World +{ + public class AstralBiome + { + public static bool CanAstralMeteorSpawn() + { + int astralOreCount = 0; + float worldSizeFactor = Main.maxTilesX / 4200f; // Small = 4200, Medium = 6400, Large = 8400 + int astralOreAllowed = (int)(200f * worldSizeFactor); // Small = 201 Medium = 305 Large = 401 + for (int x = 5; x < Main.maxTilesX - 5; x++) + { + int y = 5; + while (y < Main.worldSurface) + { + if (Main.tile[x, y].active() && Main.tile[x, y].type == ModContent.TileType()) + { + astralOreCount++; + if (astralOreCount > astralOreAllowed) + return false; + } + y++; + } + } + return true; + } + + public static bool CanAstralBiomeSpawn() + { + int astralTileCount = 0; + float worldSizeFactor = Main.maxTilesX / 4200f; // Small = 4200, Medium = 6400, Large = 8400 + int astralTilesAllowed = (int)(400f * worldSizeFactor); // Small = 401 Medium = 605 Large = 801 + for (int x = 5; x < Main.maxTilesX - 5; x++) + { + int y = 5; + while (y < Main.worldSurface) + { + if (Main.tile[x, y].active() && + (Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || + Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || + Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || + Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || + Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || + Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType())) + { + astralTileCount++; + if (astralTileCount > astralTilesAllowed) + return false; + } + y++; + } + } + return true; + } + + public static void PlaceAstralMeteor() + { + Mod ancientsAwakened = CalamityMod.Instance.ancientsAwakened; + + // This flag is also used to determine whether players are nearby. + bool meteorDropped = true; + + // Clients in multiplayer don't drop meteors. + if (Main.netMode == NetmodeID.MultiplayerClient) + return; + for (int i = 0; i < 255; i++) + { + if (Main.player[i].active) + { + meteorDropped = false; + break; + } + } + + // Check whether there is already too much ore. + if (!CanAstralMeteorSpawn()) + return; + + UnifiedRandom rand = WorldGen.genRand; + float solidTileRequirement = 600f; + bool localAbyssSide = WorldGen.dungeonX < Main.maxTilesX / 2; + while (!meteorDropped) + { + float worldEdgeMargin = (float)Main.maxTilesX * 0.08f; + int xLimit = Main.maxTilesX / 2; + int x = CalamityWorld.abyssSide ? rand.Next(400, xLimit) : rand.Next(xLimit, Main.maxTilesX - 400); + while ((float)x > (float)Main.spawnTileX - worldEdgeMargin && (float)x < (float)Main.spawnTileX + worldEdgeMargin) + { + x = CalamityWorld.abyssSide ? rand.Next(400, xLimit) : rand.Next(xLimit, Main.maxTilesX - 400); + } + //world surface = 920 large 740 medium 560 small + int y = (int)(Main.worldSurface * 0.5); //Large = 522, Medium = 444, Small = 336 + while (y < Main.maxTilesY) + { + if (Main.tile[x, y].active() && Main.tileSolid[(int)Main.tile[x, y].type]) + { + int suitableTiles = 0; + int checkRadius = 15; + for (int l = x - checkRadius; l < x + checkRadius; l++) + { + for (int m = y - checkRadius; m < y + checkRadius; m++) + { + if (WorldGen.SolidTile(l, m)) + { + suitableTiles++; + + // Avoid floating islands: Clouds and Sunplate both harshly punish attempted meteor spawns + if (Main.tile[l, m].type == TileID.Cloud || Main.tile[l, m].type == TileID.Sunplate) + { + suitableTiles -= 100; + } + // Avoid Sulphurous Sea beach: Cannot be converted by astral + else if (Main.tile[l, m].type == ModContent.TileType() || Main.tile[l, m].type == ModContent.TileType()) + { + suitableTiles -= 100; + } + + // Prevent the Astral biome from overriding or interfering with an AA biome + else if (ancientsAwakened != null) + { + if (Main.tile[l, m].type == ancientsAwakened.TileType("InfernoGrass") || Main.tile[l, m].type == ancientsAwakened.TileType("Torchstone") || + Main.tile[l, m].type == ancientsAwakened.TileType("Torchsand") || Main.tile[l, m].type == ancientsAwakened.TileType("Torchsandstone") || + Main.tile[l, m].type == ancientsAwakened.TileType("Torchsandhardened") || Main.tile[l, m].type == ancientsAwakened.TileType("Torchice") || + Main.tile[l, m].type == ancientsAwakened.TileType("Depthstone") || Main.tile[l, m].type == ancientsAwakened.TileType("Depthsand") || + Main.tile[l, m].type == ancientsAwakened.TileType("Depthsandstone") || Main.tile[l, m].type == ancientsAwakened.TileType("Depthsandhardened") || + Main.tile[l, m].type == ancientsAwakened.TileType("Depthice")) + { + suitableTiles -= 100; + } + } + } + + // Liquid aversion makes meteors less likely to fall in lakes + else if (Main.tile[l, m].liquid > 0) + { + suitableTiles--; + } + } + } + + if ((float)suitableTiles < solidTileRequirement) + { + solidTileRequirement -= 0.5f; + break; + } + meteorDropped = GenerateAstralMeteor(x, y); + + // If the meteor actually dropped, post the message stating as such. + if (meteorDropped) + { + string key = "Mods.CalamityMod.AstralText"; + Color messageColor = Color.Gold; + + CalamityUtils.DisplayLocalizedText(key, messageColor); + break; + } + break; + } + else + { + y++; + } + } + if (solidTileRequirement < 100f) + { + return; + } + } + } + + public static bool GenerateAstralMeteor(int i, int j) + { + UnifiedRandom rand = WorldGen.genRand; + if (i < 50 || i > Main.maxTilesX - 50) + { + return false; + } + // Avoid the dungeon so that the beacon doesn't eat it. + if (Math.Abs(i - WorldGen.dungeonX) < 65) + { + return false; + } + if (j < 50 || j > Main.maxTilesY - 50) + { + return false; + } + int num = 35; + Rectangle rectangle = new Rectangle((i - num) * 16, (j - num) * 16, num * 2 * 16, num * 2 * 16); + for (int k = 0; k < 255; k++) + { + if (Main.player[k].active) + { + Rectangle value = new Rectangle((int)(Main.player[k].position.X + (float)(Main.player[k].width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.player[k].position.Y + (float)(Main.player[k].height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); + if (rectangle.Intersects(value)) + { + return false; + } + } + } + for (int l = 0; l < 200; l++) + { + if (Main.npc[l].active) + { + Rectangle value2 = new Rectangle((int)Main.npc[l].position.X, (int)Main.npc[l].position.Y, Main.npc[l].width, Main.npc[l].height); + if (rectangle.Intersects(value2)) + { + return false; + } + } + } + for (int m = i - num; m < i + num; m++) + { + for (int n = j - num; n < j + num; n++) + { + if (Main.tile[m, n].active() && Main.tile[m, n].type == 21) + { + return false; + } + } + } + num = rand.Next(17, 23); + for (int num2 = i - num; num2 < i + num; num2++) + { + for (int num3 = j - num; num3 < j + num; num3++) + { + if (num3 > j + rand.Next(-2, 3) - 5) + { + float num4 = (float)Math.Abs(i - num2); + float num5 = (float)Math.Abs(j - num3); + float num6 = (float)Math.Sqrt((double)(num4 * num4 + num5 * num5)); + if ((double)num6 < (double)num * 0.9 + (double)rand.Next(-4, 5)) + { + if (Main.tile[num2, num3] != null) + { + if (!Main.tileSolid[(int)Main.tile[num2, num3].type]) + { + Main.tile[num2, num3].active(false); + } + Main.tile[num2, num3].type = (ushort)ModContent.TileType(); + } + } + } + } + } + num = WorldGen.genRand.Next(8, 14); + for (int num7 = i - num; num7 < i + num; num7++) + { + for (int num8 = j - num; num8 < j + num; num8++) + { + if (num8 > j + rand.Next(-2, 3) - 4) + { + float num9 = (float)Math.Abs(i - num7); + float num10 = (float)Math.Abs(j - num8); + float num11 = (float)Math.Sqrt((double)(num9 * num9 + num10 * num10)); + if ((double)num11 < (double)num * 0.8 + (double)rand.Next(-3, 4)) + { + if (Main.tile[num7, num8] != null) + Main.tile[num7, num8].active(false); + } + } + } + } + num = WorldGen.genRand.Next(25, 35); + for (int num12 = i - num; num12 < i + num; num12++) + { + for (int num13 = j - num; num13 < j + num; num13++) + { + float num14 = (float)Math.Abs(i - num12); + float num15 = (float)Math.Abs(j - num13); + float num16 = (float)Math.Sqrt((double)(num14 * num14 + num15 * num15)); + if (Main.tile[num12, num13] != null) + { + if ((double)num16 < (double)num * 0.7) + { + if (Main.tile[num12, num13].type == 5 || Main.tile[num12, num13].type == 32 || Main.tile[num12, num13].type == 352) + { + try + { WorldGen.KillTile(num12, num13, false, false, true); } + catch (NullReferenceException) + { } + } + Main.tile[num12, num13].liquid = 0; + } + if (Main.tile[num12, num13].type == (ushort)ModContent.TileType()) + { + if (!WorldGen.SolidTile(num12 - 1, num13) && !WorldGen.SolidTile(num12 + 1, num13) && !WorldGen.SolidTile(num12, num13 - 1) && !WorldGen.SolidTile(num12, num13 + 1)) + { + Main.tile[num12, num13].active(false); + } + else if ((Main.tile[num12, num13].halfBrick() || Main.tile[num12 - 1, num13].topSlope()) && !WorldGen.SolidTile(num12, num13 + 1)) + { + Main.tile[num12, num13].active(false); + } + } + WorldGen.SquareTileFrame(num12, num13, true); + WorldGen.SquareWallFrame(num12, num13, true); + } + } + } + num = WorldGen.genRand.Next(23, 32); + for (int num17 = i - num; num17 < i + num; num17++) + { + for (int num18 = j - num; num18 < j + num; num18++) + { + if (num18 > j + WorldGen.genRand.Next(-3, 4) - 3 && Main.tile[num17, num18].active() && rand.NextBool(10)) + { + float num19 = (float)Math.Abs(i - num17); + float num20 = (float)Math.Abs(j - num18); + float num21 = (float)Math.Sqrt((double)(num19 * num19 + num20 * num20)); + if ((double)num21 < (double)num * 0.8) + { + if (Main.tile[num17, num18] != null) + { + if (Main.tile[num17, num18].type == 5 || Main.tile[num17, num18].type == 32 || Main.tile[num17, num18].type == 352) + { + WorldGen.KillTile(num17, num18, false, false, false); + } + Main.tile[num17, num18].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(num17, num18, true); + } + } + } + } + } + num = WorldGen.genRand.Next(30, 38); + for (int num22 = i - num; num22 < i + num; num22++) + { + for (int num23 = j - num; num23 < j + num; num23++) + { + if (num23 > j + WorldGen.genRand.Next(-2, 3) && Main.tile[num22, num23].active() && rand.NextBool(20)) + { + float num24 = (float)Math.Abs(i - num22); + float num25 = (float)Math.Abs(j - num23); + float num26 = (float)Math.Sqrt((double)(num24 * num24 + num25 * num25)); + if ((double)num26 < (double)num * 0.85) + { + if (Main.tile[num22, num23] != null) + { + if (Main.tile[num22, num23].type == 5 || Main.tile[num22, num23].type == 32 || Main.tile[num22, num23].type == 352) + { + WorldGen.KillTile(num22, num23, false, false, false); + } + Main.tile[num22, num23].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(num22, num23, true); + } + } + } + } + } + + if (Main.netMode != NetmodeID.MultiplayerClient) + { + NetMessage.SendTileSquare(-1, i, j, 40, TileChangeType.None); + if (CanAstralBiomeSpawn()) + { + DoAstralConversion(new Point(i, j)); + + // Upward checks go up 180 tiles. If for whatever reason the placement Y position + // would cause this upward movement to go outside of the world, clamp it to prevent index problems. + if (j < 181) + j = 181; + + int checkWidth = 180; + float averageHeight = 0f; + float lowestHeight = 0f; + + int xAreaToSpawn = i; + + Dictionary xAreaHeightMap = new Dictionary(); + + // Gauge the bumpiness of various potential locations. + // The least bumpy one will be selected as the place to spawn the monolith. + for (int tries = 0; tries < 30; tries++) + { + int x = i + Main.rand.Next(-60, 61); + + // Don't attempt to add duplicate keys. + if (xAreaHeightMap.ContainsKey(x)) + continue; + + float averageRelativeHeight = 0f; + for (int dx = -30; dx <= 30; dx++) + { + WorldUtils.Find(new Point(x + dx, j - 180), Searches.Chain(new Searches.Down(360), new Conditions.IsSolid()), out Point result); + averageRelativeHeight += Math.Abs(result.Y - j); + } + averageRelativeHeight /= 60f; + xAreaHeightMap.Add(x, averageRelativeHeight); + } + + i = xAreaHeightMap.OrderBy(x => x.Value).First().Key; + + for (int x = i - checkWidth / 2; x < i + checkWidth / 2; x++) + { + int y = j - 200; + Tile tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y); + while (!Main.tileSolid[tileAtPosition.type] || + !tileAtPosition.active() || + TileID.Sets.Platforms[tileAtPosition.type]) + { + y++; + if (y > j - 10) + break; + tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y); + } + lowestHeight = (int)MathHelper.Max(lowestHeight, y); + averageHeight += y; + } + lowestHeight -= 35f; + averageHeight /= checkWidth; + float height = lowestHeight; + + // If there's a sudden change between the average and lowest height (which is indicative of holes/chasms), go with the average. + if (Math.Abs(lowestHeight - averageHeight) > 50f) + height = averageHeight; + + // WorldGen.gen prevents NewItem from working, and thus prevents a bunch of dumb items from being spawned immediately and deleting the WoF/Aureus loot in the process. + WorldGen.gen = true; + // Add the average height of a tree to the Y position to offset trees usually messing with the calculation. + // Then also add 10 blocks because these things seem to always like to appear standing on the floor. + int finalVerticalOffset = 18; + bool _ = true; + SchematicManager.PlaceSchematic>("Astral Beacon", new Point(i, (int)height + finalVerticalOffset), SchematicAnchor.Center, ref _); + WorldGen.gen = false; + } + } + return true; + } + + public static void DoAstralConversion(object obj) + { + //Pre-calculate all variables necessary for elliptical area checking + Point origin = (Point)obj; + Vector2 center = origin.ToVector2() * 16f + new Vector2(8f); + + float angle = MathHelper.Pi * 0.15f; + float otherAngle = MathHelper.PiOver2 - angle; + + int distanceInTiles = 150 + (Main.maxTilesX - 4200) / 4200 * 200; + float distance = distanceInTiles * 16f; + float constant = distance * 2f / (float)Math.Sin(angle); + + float fociSpacing = distance * (float)Math.Sin(otherAngle) / (float)Math.Sin(angle); + int verticalRadius = (int)(constant / 16f); + + Vector2 fociOffset = Vector2.UnitY * fociSpacing; + Vector2 topFoci = center - fociOffset; + Vector2 bottomFoci = center + fociOffset; + + UnifiedRandom rand = WorldGen.genRand; + for (int x = origin.X - distanceInTiles - 2; x <= origin.X + distanceInTiles + 2; x++) + { + for (int y = (int)(origin.Y - verticalRadius * 0.4f) - 3; y <= origin.Y + verticalRadius + 3; y++) + { + if (CheckInEllipse(new Point(x, y), topFoci, bottomFoci, constant, center, out float dist, y < origin.Y)) + { + //If we're in the outer blurPercent% of the ellipse + float percent = dist / constant; + float blurPercent = 0.98f; + if (percent > blurPercent) + { + float outerEdgePercent = (percent - blurPercent) / (1f - blurPercent); + if (rand.NextFloat(1f) > outerEdgePercent) + { + ConvertToAstral(x, y); + } + } + else + { + ConvertToAstral(x, y); + } + } + } + } + } + + public static void ConvertToAstral(int startX, int endX, int startY, int endY) + { + for (int x = startX; x <= endX; x++) + { + for (int y = startY; y <= endY; y++) + { + ConvertToAstral(x, y); + } + } + } + + public static void ConvertToAstral(int x, int y) + { + if (WorldGen.InWorld(x, y, 1)) + { + int type = Main.tile[x, y].type; + int wallType = Main.tile[x, y].wall; + + if (Main.tile[x, y] != null) + { + if (WallID.Sets.Conversion.Grass[wallType]) + { + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (WallID.Sets.Conversion.HardenedSand[wallType]) + { + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (WallID.Sets.Conversion.Sandstone[wallType]) + { + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (WallID.Sets.Conversion.Stone[wallType]) + { + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else + { + switch (wallType) + { + case WallID.DirtUnsafe: + case WallID.DirtUnsafe1: + case WallID.DirtUnsafe2: + case WallID.DirtUnsafe3: + case WallID.DirtUnsafe4: + case WallID.Cave6Unsafe: + case WallID.Dirt: + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.SnowWallUnsafe: + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.DesertFossil: + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.IceUnsafe: + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.LivingWood: + Main.tile[x, y].wall = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + } + } + if (TileID.Sets.Conversion.Grass[type] && !TileID.Sets.GrassSpecial[type]) + { + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Stone[type] || Main.tileMoss[type]) + { + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Sand[type]) + { + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.HardenedSand[type]) + { + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Sandstone[type]) + { + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Ice[type]) + { + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else + { + Tile tile = Main.tile[x, y]; + switch (type) + { + case TileID.Dirt: + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.SnowBlock: + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.Silt: + case TileID.Slush: + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.DesertFossil: + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.ClayBlock: + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.Vines: + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.LivingWood: + Main.tile[x, y].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.LeafBlock: + case TileID.Sunflower: + WorldGen.KillTile(x, y); + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y); + } + break; + case TileID.LargePiles: + if (tile.frameX <= 1170) + { + RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 0, 1170, 0, 18); + } + if (tile.frameX >= 1728) + { + RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1728, 1872, 0, 18); + } + if (tile.frameX >= 1404 && tile.frameX <= 1710) + { + RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1404, 1710, 0, 18); + } + break; + case TileID.LargePiles2: + if (tile.frameX >= 1566 && tile.frameY < 36) + { + RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 1566, 1872, 0, 18); + } + if (tile.frameX >= 756 && tile.frameX <= 900) + { + RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 756, 900, 0, 18); + } + break; + case TileID.SmallPiles: + if (tile.frameY == 18) + { + ushort newType; + if (tile.frameX >= 1476 && tile.frameX <= 1674) + { + newType = (ushort)ModContent.TileType(); + } + else if (tile.frameX <= 558 || (tile.frameX >= 1368 && tile.frameX <= 1458)) + { + newType = (ushort)ModContent.TileType(); + } + else if (tile.frameX >= 900 && tile.frameX <= 1098) + { + newType = (ushort)ModContent.TileType(); + } + else + { + break; + } + int leftMost = x; + if (tile.frameX % 36 != 0) //this means it's the right tile of the two + { + leftMost--; + } + if (Main.tile[leftMost, y] != null) + { + Main.tile[leftMost, y].type = newType; + WorldGen.SquareTileFrame(leftMost, y, true); + NetMessage.SendTileSquare(-1, leftMost, y, 1); + } + if (Main.tile[leftMost + 1, y] != null) + { + Main.tile[leftMost + 1, y].type = newType; + WorldGen.SquareTileFrame(leftMost + 1, y, true); + NetMessage.SendTileSquare(-1, leftMost + 1, y, 1); + } + while (Main.tile[leftMost, y].frameX >= 216) + { + if (Main.tile[leftMost, y] != null) + Main.tile[leftMost, y].frameX -= 216; + if (Main.tile[leftMost + 1, y] != null) + Main.tile[leftMost + 1, y].frameX -= 216; + } + } + else if (tile.frameY == 0) + { + ushort newType3; + if (tile.frameX >= 972 && tile.frameX <= 1062) + { + newType3 = (ushort)ModContent.TileType(); + } + else if (tile.frameX <= 486) + { + newType3 = (ushort)ModContent.TileType(); + } + else if (tile.frameX >= 648 && tile.frameX <= 846) + { + newType3 = (ushort)ModContent.TileType(); + } + else + { + break; + } + Main.tile[x, y].type = newType3; + while (Main.tile[x, y].frameX >= 108) //REFRAME IT + { + Main.tile[x, y].frameX -= 108; + } + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + break; + case TileID.Stalactite: + int topMost = tile.frameY <= 54 ? (tile.frameY % 36 == 0 ? y : y - 1) : y; + bool twoTall = tile.frameY <= 54; + bool hanging = tile.frameY <= 18 || tile.frameY == 72; + ushort newType2; + if (tile.frameX >= 378 && tile.frameX <= 414) //DESERT + { + newType2 = (ushort)ModContent.TileType(); + } + else if ((tile.frameX >= 54 && tile.frameX <= 90) || (tile.frameX >= 216 && tile.frameX <= 360)) + { + newType2 = (ushort)ModContent.TileType(); + } + else if (tile.frameX <= 36) + { + newType2 = (ushort)ModContent.TileType(); + } + else + { + break; + } + + //Set types + if (Main.tile[x, topMost] != null) + { + Main.tile[x, topMost].type = newType2; + } + if (twoTall) + { + if (Main.tile[x, topMost + 1] != null) + Main.tile[x, topMost + 1].type = newType2; + } + + //Fix frames + while (Main.tile[x, topMost].frameX >= 54) + { + if (Main.tile[x, topMost] != null) + Main.tile[x, topMost].frameX -= 54; + if (twoTall) + { + if (Main.tile[x, topMost + 1] != null) + Main.tile[x, topMost + 1].frameX -= 54; + } + } + + if (Main.tile[x, topMost] != null) + { + WorldGen.SquareTileFrame(x, topMost, true); + NetMessage.SendTileSquare(-1, x, topMost, 1); + } + + if (Main.tile[x, topMost + 1] != null) + { + WorldGen.SquareTileFrame(x, topMost + 1, true); + NetMessage.SendTileSquare(-1, x, topMost + 1, 1); + } + + if (hanging) + { + ConvertToAstral(x, topMost - 1); + break; + } + else + { + if (twoTall) + { + ConvertToAstral(x, topMost + 2); + break; + } + ConvertToAstral(x, topMost + 1); + break; + } + } + } + } + } + } + + public static void ConvertFromAstral(int x, int y, ConvertType convert, bool tileframe = true) + { + Tile tile = Main.tile[x, y]; + int type = tile.type; + int wallType = tile.wall; + + if (WorldGen.InWorld(x, y, 1)) + { + #region WALL + if (Main.tile[x, y] != null) + { + if (wallType == ModContent.WallType()) + { + Main.tile[x, y].wall = WallID.DirtUnsafe; + } + else if (wallType == ModContent.WallType() || wallType == ModContent.WallType()) + { + Main.tile[x, y].wall = WallID.SnowWallUnsafe; + } + else if (wallType == ModContent.WallType()) + { + Main.tile[x, y].wall = WallID.DesertFossil; + } + else if (wallType == ModContent.WallType()) + { + switch (convert) + { + case ConvertType.Corrupt: + Main.tile[x, y].wall = WallID.CorruptGrassUnsafe; + break; + case ConvertType.Crimson: + Main.tile[x, y].wall = WallID.CrimsonGrassUnsafe; + break; + case ConvertType.Hallow: + Main.tile[x, y].wall = WallID.HallowedGrassUnsafe; + break; + case ConvertType.Pure: + Main.tile[x, y].wall = WallID.GrassUnsafe; + break; + } + } + else if (wallType == ModContent.WallType()) + { + Main.tile[x, y].wall = WallID.IceUnsafe; + } + else if (wallType == ModContent.WallType()) + { + Main.tile[x, y].wall = WallID.LivingWood; + } + else if (wallType == ModContent.WallType()) + { + switch (convert) + { + case ConvertType.Corrupt: + Main.tile[x, y].wall = WallID.EbonstoneUnsafe; + break; + case ConvertType.Crimson: + Main.tile[x, y].wall = WallID.CrimstoneUnsafe; + break; + case ConvertType.Hallow: + Main.tile[x, y].wall = WallID.PearlstoneBrickUnsafe; + break; + case ConvertType.Pure: + Main.tile[x, y].wall = WallID.Stone; + break; + } + } + } + #endregion + + #region TILE + if (Main.tile[x, y] != null) + { + if (type == ModContent.TileType()) + { + tile.type = TileID.Dirt; + } + else if (type == ModContent.TileType()) + { + tile.type = TileID.SnowBlock; + } + else if (type == ModContent.TileType()) + { + tile.type = TileID.Silt; + } + else if (type == ModContent.TileType()) + { + tile.type = TileID.DesertFossil; + } + else if (type == ModContent.TileType()) + { + tile.type = TileID.ClayBlock; + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, TileID.CorruptGrass, TileID.FleshGrass, TileID.HallowedGrass, TileID.Grass); + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, TileID.Ebonstone, TileID.Crimstone, TileID.Pearlstone, TileID.Stone); + } + else if (type == ModContent.TileType()) + { + tile.type = TileID.LivingWood; + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, TileID.Ebonsand, TileID.Crimsand, TileID.Pearlsand, TileID.Sand); + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, TileID.CorruptSandstone, TileID.CrimsonSandstone, TileID.HallowSandstone, TileID.Sandstone); + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, TileID.CorruptHardenedSand, TileID.CrimsonHardenedSand, TileID.HallowHardenedSand, TileID.HardenedSand); + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, TileID.CorruptIce, TileID.FleshIce, TileID.HallowedIce, TileID.IceBlock); + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, ushort.MaxValue, TileID.CrimsonVines, TileID.HallowedVines, TileID.Vines); + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, TileID.CorruptPlants, ushort.MaxValue, TileID.HallowedPlants, TileID.Plants); + } + else if (type == ModContent.TileType()) + { + SetTileFromConvert(x, y, convert, ushort.MaxValue, ushort.MaxValue, TileID.HallowedPlants2, TileID.Plants2); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.LargePiles, x, y, 378, 0); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 0, 18); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 0, 0); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.LargePiles2, x, y, 1566, 0); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 1476, 18); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 972, 0); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.LargePiles, x, y, 1404, 0); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 900, 18); + } + else if (type == ModContent.TileType()) + { + RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 648, 0); + } + else if (type == ModContent.TileType()) + { + ushort originType = TileID.Stone; + switch (convert) + { + case ConvertType.Corrupt: + originType = TileID.Ebonstone; + break; + case ConvertType.Crimson: + originType = TileID.Crimstone; + break; + case ConvertType.Hallow: + originType = TileID.Pearlstone; + break; + } + ReplaceAstralStalactite(TileID.Stalactite, originType, x, y); + } + else if (type == ModContent.TileType()) + { + ushort originType = TileID.Sandstone; + switch (convert) + { + case ConvertType.Corrupt: + originType = TileID.CorruptSandstone; + break; + case ConvertType.Crimson: + originType = TileID.CrimsonSandstone; + break; + case ConvertType.Hallow: + originType = TileID.HallowSandstone; + break; + } + ReplaceAstralStalactite(TileID.Stalactite, originType, x, y); + } + else if (type == ModContent.TileType()) + { + ReplaceAstralStalactite(TileID.Stalactite, TileID.IceBlock, x, y); + } + if (TileID.Sets.Conversion.Grass[type] || type == TileID.Dirt) + { + WorldGen.SquareTileFrame(x, y); + } + } + #endregion + + if (tileframe) + { + if (Main.netMode == NetmodeID.SinglePlayer) + { + WorldGen.SquareTileFrame(x, y, true); + } + else if (Main.netMode == NetmodeID.Server) + { + NetMessage.SendTileSquare(-1, x, y, 1); + } + } + } + } + + public static void SetTileFromConvert(int x, int y, ConvertType convert, ushort corrupt, ushort crimson, ushort hallow, ushort pure) + { + switch (convert) + { + case ConvertType.Corrupt: + if (corrupt != ushort.MaxValue) + { + Main.tile[x, y].type = corrupt; + WorldGen.SquareTileFrame(x, y); + } + break; + case ConvertType.Crimson: + if (crimson != ushort.MaxValue) + { + Main.tile[x, y].type = crimson; + WorldGen.SquareTileFrame(x, y); + } + break; + case ConvertType.Hallow: + if (hallow != ushort.MaxValue) + { + Main.tile[x, y].type = hallow; + WorldGen.SquareTileFrame(x, y); + } + break; + case ConvertType.Pure: + if (pure != ushort.MaxValue) + { + Main.tile[x, y].type = pure; + WorldGen.SquareTileFrame(x, y); + } + break; + } + } + + public static void RecursiveReplaceToAstral(ushort checkType, ushort replaceType, int x, int y, int replaceTextureWidth, int minFrameX = 0, int maxFrameX = int.MaxValue, int minFrameY = 0, int maxFrameY = int.MaxValue) + { + Tile tile = Main.tile[x, y]; + if (tile == null || !tile.active() || tile.type != checkType || tile.frameX < minFrameX || tile.frameX > maxFrameX || tile.frameY < minFrameY || tile.frameY > maxFrameY) + return; + + Main.tile[x, y].type = replaceType; + while (Main.tile[x, y].frameX >= replaceTextureWidth) + { + Main.tile[x, y].frameX -= (short)replaceTextureWidth; + } + + if (Main.tile[x - 1, y] != null) + RecursiveReplaceToAstral(checkType, replaceType, x - 1, y, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); + if (Main.tile[x + 1, y] != null) + RecursiveReplaceToAstral(checkType, replaceType, x + 1, y, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); + if (Main.tile[x, y - 1] != null) + RecursiveReplaceToAstral(checkType, replaceType, x, y - 1, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); + if (Main.tile[x, y + 1] != null) + RecursiveReplaceToAstral(checkType, replaceType, x, y + 1, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); + } + + public static void RecursiveReplaceFromAstral(ushort checkType, ushort replaceType, int x, int y, int addFrameX, int addFrameY) + { + Tile tile = Main.tile[x, y]; + if (tile == null || !tile.active() || tile.type != checkType) + return; + + Main.tile[x, y].type = replaceType; + Main.tile[x, y].frameX += (short)addFrameX; + Main.tile[x, y].frameY += (short)addFrameY; + + if (Main.tile[x - 1, y] != null) + RecursiveReplaceFromAstral(checkType, replaceType, x - 1, y, addFrameX, addFrameY); + if (Main.tile[x + 1, y] != null) + RecursiveReplaceFromAstral(checkType, replaceType, x + 1, y, addFrameX, addFrameY); + if (Main.tile[x, y - 1] != null) + RecursiveReplaceFromAstral(checkType, replaceType, x, y - 1, addFrameX, addFrameY); + if (Main.tile[x, y + 1] != null) + RecursiveReplaceFromAstral(checkType, replaceType, x, y + 1, addFrameX, addFrameY); + } + + public static void ReplaceAstralStalactite(ushort replaceType, ushort replaceOriginTile, int x, int y) + { + Tile tile = Main.tile[x, y]; + + int topMost = tile.frameY <= 54 ? (tile.frameY % 36 == 0 ? y : y - 1) : y; + bool twoTall = tile.frameY <= 54; + bool hanging = tile.frameY <= 18 || tile.frameY == 72; + + int yOriginTile = hanging ? topMost - 1 : (twoTall ? topMost + 2 : y + 1); + + if (Main.tile[x, topMost++] != null) + Main.tile[x, topMost++].type = replaceType; + if (twoTall) + { + if (Main.tile[x, topMost] != null) + Main.tile[x, topMost].type = replaceType; + } + if (Main.tile[x, yOriginTile] != null) + Main.tile[x, yOriginTile].type = replaceOriginTile; + } + + public static bool CheckInEllipse(Point tile, Vector2 focus1, Vector2 focus2, float distanceConstant, Vector2 center, out float distance, bool collapse = false) + { + Vector2 point = tile.ToWorldCoordinates(); + if (collapse) //Collapse ensures the ellipse is shrunk down a lot in terms of distance. + { + float distY = center.Y - point.Y; + point.Y -= distY * 8f; + } + float distance1 = Vector2.Distance(point, focus1); + float distance2 = Vector2.Distance(point, focus2); + distance = distance1 + distance2; + return distance <= distanceConstant; + } + } +} diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index 0aa759ce12..c172d3e141 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -31,6 +31,7 @@ using CalamityMod.Tiles.AstralSnow; using CalamityMod.Tiles.Crags; using CalamityMod.Tiles.Ores; using CalamityMod.Tiles.SunkenSea; +using CalamityMod.World.Planets; using Microsoft.Xna.Framework; using System; using System.Collections.Generic; @@ -1033,14 +1034,14 @@ namespace CalamityMod.World tasks.Insert(ShiniesIndex + 2, new PassLegacy("EvilIsland", delegate (GenerationProgress progress) { progress.Message = "Evil Island"; - SmallBiomes.PlaceEvilIsland(); + WorldEvilIsland.PlaceEvilIsland(); })); } int DungeonChestIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Dungeon")); if (DungeonChestIndex != -1) { - tasks.Insert(DungeonChestIndex + 1, new PassLegacy("Calamity Mod: Biome Chests", WorldGenerationMethods.GenerateBiomeChests)); + tasks.Insert(DungeonChestIndex + 1, new PassLegacy("Calamity Mod: Biome Chests", MiscWorldgenRoutines.GenerateBiomeChests)); } int WaterFromSandIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Remove Water From Sand")); @@ -1094,27 +1095,27 @@ namespace CalamityMod.World fuhX = xUnderworldGen; fuhY = yUnderworldGen; - WorldGenerationMethods.UnderworldIsland(xUnderworldGen, yUnderworldGen, 180, 201, 120, 136); - WorldGenerationMethods.UnderworldIsland(xUnderworldGen - 50, yUnderworldGen - 30, 100, 111, 60, 71); - WorldGenerationMethods.UnderworldIsland(xUnderworldGen + 50, yUnderworldGen - 30, 100, 111, 60, 71); + MiscWorldgenRoutines.UnderworldIsland(xUnderworldGen, yUnderworldGen, 180, 201, 120, 136); + MiscWorldgenRoutines.UnderworldIsland(xUnderworldGen - 50, yUnderworldGen - 30, 100, 111, 60, 71); + MiscWorldgenRoutines.UnderworldIsland(xUnderworldGen + 50, yUnderworldGen - 30, 100, 111, 60, 71); - WorldGenerationMethods.ChasmGenerator(fuhX - 110, fuhY - 10, WorldGen.genRand.Next(150) + 150); - WorldGenerationMethods.ChasmGenerator(fuhX + 110, fuhY - 10, WorldGen.genRand.Next(150) + 150); + MiscWorldgenRoutines.ChasmGenerator(fuhX - 110, fuhY - 10, WorldGen.genRand.Next(150) + 150); + MiscWorldgenRoutines.ChasmGenerator(fuhX + 110, fuhY - 10, WorldGen.genRand.Next(150) + 150); - WorldGenerationMethods.UnderworldIsland(xUnderworldGen - 150, yUnderworldGen - 30, 60, 66, 35, 41); - WorldGenerationMethods.UnderworldIsland(xUnderworldGen + 150, yUnderworldGen - 30, 60, 66, 35, 41); - WorldGenerationMethods.UnderworldIsland(xUnderworldGen - 180, yUnderworldGen - 20, 60, 66, 35, 41); - WorldGenerationMethods.UnderworldIsland(xUnderworldGen + 180, yUnderworldGen - 20, 60, 66, 35, 41); + MiscWorldgenRoutines.UnderworldIsland(xUnderworldGen - 150, yUnderworldGen - 30, 60, 66, 35, 41); + MiscWorldgenRoutines.UnderworldIsland(xUnderworldGen + 150, yUnderworldGen - 30, 60, 66, 35, 41); + MiscWorldgenRoutines.UnderworldIsland(xUnderworldGen - 180, yUnderworldGen - 20, 60, 66, 35, 41); + MiscWorldgenRoutines.UnderworldIsland(xUnderworldGen + 180, yUnderworldGen - 20, 60, 66, 35, 41); - WorldGenerationMethods.UnderworldIslandHouse(fuhX, fuhY + 30, 1323); - WorldGenerationMethods.UnderworldIslandHouse(fuhX - 22, fuhY + 15, 1322); - WorldGenerationMethods.UnderworldIslandHouse(fuhX + 22, fuhY + 15, 535); - WorldGenerationMethods.UnderworldIslandHouse(fuhX - 50, fuhY - 30, 112); - WorldGenerationMethods.UnderworldIslandHouse(fuhX + 50, fuhY - 30, 906); - WorldGenerationMethods.UnderworldIslandHouse(fuhX - 150, fuhY - 30, 218); - WorldGenerationMethods.UnderworldIslandHouse(fuhX + 150, fuhY - 30, 3019); - WorldGenerationMethods.UnderworldIslandHouse(fuhX - 180, fuhY - 20, 274); - WorldGenerationMethods.UnderworldIslandHouse(fuhX + 180, fuhY - 20, 220); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX, fuhY + 30, 1323); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX - 22, fuhY + 15, 1322); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX + 22, fuhY + 15, 535); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX - 50, fuhY - 30, 112); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX + 50, fuhY - 30, 906); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX - 150, fuhY - 30, 218); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX + 150, fuhY - 30, 3019); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX - 180, fuhY - 20, 274); + MiscWorldgenRoutines.UnderworldIslandHouse(fuhX + 180, fuhY - 20, 220); })); #endregion @@ -1131,7 +1132,7 @@ namespace CalamityMod.World tasks.Insert(FinalIndex + 2, new PassLegacy("SpecialShrines", delegate (GenerationProgress progress) { progress.Message = "Special Shrines"; - SmallBiomes.PlaceShrines(); + UndergroundShrines.PlaceShrines(); })); @@ -1180,11 +1181,11 @@ namespace CalamityMod.World tasks.Insert(FinalIndex + 6, new PassLegacy("IWannaRock", delegate (GenerationProgress progress) { progress.Message = "I Wanna Rock"; - WorldGenerationMethods.PlaceRoxShrine(); + MiscWorldgenRoutines.PlaceRoxShrine(); })); } - tasks.Add(new PassLegacy("Planetoid Test", WorldGenerationMethods.Planetoids)); + tasks.Add(new PassLegacy("Planetoid Test", Planetoid.GenerateAllBasePlanetoids)); } // An Astral Meteor always falls at the beginning of Hardmode. @@ -1196,939 +1197,13 @@ namespace CalamityMod.World // Insert the Astral biome generation right before the final hardmode announcement. tasks.Insert(announceIndex, new PassLegacy("AstralMeteor", delegate (GenerationProgress progress) { - WorldGenerationMethods.PlaceAstralMeteor(); + AstralBiome.PlaceAstralMeteor(); })); } #endregion #region PostUpdate - public override void PostUpdate() - { - if (DraedonSummonCountdown > 0) - { - DraedonSummonCountdown--; - HandleDraedonSummoning(); - } - - // Sunken Sea Location...duh - SunkenSeaLocation = new Rectangle(WorldGen.UndergroundDesertLocation.Left, WorldGen.UndergroundDesertLocation.Bottom, - WorldGen.UndergroundDesertLocation.Width, WorldGen.UndergroundDesertLocation.Height / 2); - - // Player variable, always finds the closest player relative to the center of the map - int closestPlayer = Player.FindClosest(new Vector2(Main.maxTilesX / 2, (float)Main.worldSurface / 2f) * 16f, 0, 0); - Player player = Main.player[closestPlayer]; - CalamityPlayer modPlayer = player.Calamity(); - - // Force boss rush to off - if (!BossRushEvent.DeactivateStupidFuckingBullshit) - { - BossRushEvent.DeactivateStupidFuckingBullshit = true; - BossRushEvent.BossRushActive = false; - CalamityNetcode.SyncWorld(); - } - - // Attempt to start the acid rain at the 4:29AM - bool moreRain = !downedEoCAcidRain || (!downedAquaticScourgeAcidRain && downedAquaticScourge) || (!downedBoomerDuke && downedPolterghast); - if (Main.time == 32399 && !Main.dayTime && Main.rand.NextBool(moreRain ? 3 : 300)) - { - bool noRain = false; - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) - { - if (!Main.player[playerIndex].active) - continue; - if (Main.player[playerIndex].Calamity().noStupidNaturalARSpawns) - { - noRain = true; - break; - } - } - if (!noRain) - { - AcidRainEvent.TryStartEvent(); - CalamityNetcode.SyncWorld(); - } - } - if (NPC.downedBoss1 && !downedEoCAcidRain && !forcedRainAlready) - { - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) - { - if (Main.player[playerIndex].active) - { - if (Main.player[playerIndex].Calamity().ZoneSulphur) - { - forcedRainAlready = true; - AcidRainEvent.TryStartEvent(); - CalamityNetcode.SyncWorld(); - } - } - } - } - if (forceRainTimer == 1) - { - AcidRainEvent.TryStartEvent(); - CalamityNetcode.SyncWorld(); - } - if (forceRainTimer > 0) - forceRainTimer--; - - if (rainingAcid) - { - timeSinceAcidRainKill++; - timeSinceAcidStarted++; - - // If enough time has passed, and no enemy has been killed, end the invasion early. - // The player almost certainly does not want to deal with it. - if (timeSinceAcidRainKill >= AcidRainEvent.InvasionNoKillPersistTime) - { - acidRainPoints = 0; - triedToSummonOldDuke = false; - AcidRainEvent.UpdateInvasion(false); - } - if (!startAcidicDownpour) - { - int sulphSeaWidth = SulphurousSea.BiomeWidth; - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) - { - // A variable named "player" already exists above, which retrieves the player who is closest to the map center. - Player player2 = Main.player[playerIndex]; - if (player2.active) - { - // An artificial biome can be made, and therefore, the event could be started by an artificial biome. - // While fighting the event in an artificial biome is not bad, having it be started by a patch of Sulphurous Sand - // would definitely be strange. - // Because of this, this code is executed based on if the player is in the sea (based on tile count) AND position relative to the naturally generated sea. - if (((player2.Center.X <= (sulphSeaWidth + 60f) * 16f && abyssSide) || - (player2.Center.X >= (Main.maxTilesX - (sulphSeaWidth + 60f)) * 16f && !abyssSide)) && - player2.Calamity().ZoneSulphur) - { - // Makes rain pour at its maximum intensity (but only after an idiot meanders into the Sulphurous Sea) - // You'll never catch me, Fabs, Not when I shift into MAXIMUM OVERDRIVE!! - startAcidicDownpour = true; - CalamityNetcode.SyncWorld(); - break; - } - } - } - } - - // Stop the rain if the Old Duke is present for visibility during the fight. - if (Main.raining && NPC.AnyNPCs(ModContent.NPCType())) - { - Main.raining = false; - CalamityNetcode.SyncWorld(); - } - - // If the rain stops for whatever reason, end the invasion. - // This is primarily done for compatibility, so that if another mod wants to manipulate the weather, - // they can without having to deal with endless rain. - if (!Main.raining && !NPC.AnyNPCs(ModContent.NPCType()) && timeSinceAcidStarted > 20) - { - acidRainPoints = 0; - triedToSummonOldDuke = false; - AcidRainEvent.UpdateInvasion(false); - } - else if (timeSinceAcidStarted < 20) - { - Main.raining = true; - Main.cloudBGActive = 1f; - Main.numCloudsTemp = Main.cloudLimit; - Main.numClouds = Main.numCloudsTemp; - Main.windSpeedTemp = 0.72f; - Main.windSpeedSet = Main.windSpeedTemp; - Main.weatherCounter = 60 * 60 * 10; // 10 minutes of rain. Remember, once the rain goes away, so does the invasion. - Main.rainTime = Main.weatherCounter; - Main.maxRaining = 0.89f; - } - - // Summon Old Duke tornado post-Polter as needed - if (downedPolterghast && acidRainPoints == 1) - { - if (!NPC.AnyNPCs(ModContent.NPCType()) && - CalamityUtils.CountProjectiles(ModContent.ProjectileType()) <= 0) - { - if (triedToSummonOldDuke) - { - acidRainPoints = 0; - triedToSummonOldDuke = false; - AcidRainEvent.UpdateInvasion(false); - } - else - { - int playerClosestToAbyss = Player.FindClosest(new Vector2(abyssSide ? 0 : Main.maxTilesX * 16, (int)Main.worldSurface), 0, 0); - Player closestToAbyss = Main.player[playerClosestToAbyss]; - if (Main.netMode != NetmodeID.MultiplayerClient && Math.Abs(closestToAbyss.Center.X - (abyssSide ? 0 : Main.maxTilesX * 16)) <= 12000f) - { - Projectile.NewProjectile(closestToAbyss.Center + Vector2.UnitY * 160f, Vector2.Zero, - ModContent.ProjectileType(), 120, 8f, Main.myPlayer); - } - } - } - } - } - else - { - if (timeSinceAcidStarted != 0) - timeSinceAcidStarted = 0; - startAcidicDownpour = false; - } - - // Lumenyl crystal, tenebris spread and sea prism crystal spawn rates - int l = 0; - float mult2 = 1.5E-05f * Main.worldRate; - while (l < Main.maxTilesX * Main.maxTilesY * mult2) - { - int x = WorldGen.genRand.Next(10, Main.maxTilesX - 10); - int y = WorldGen.genRand.Next((int)Main.worldSurface - 1, Main.maxTilesY - 20); - - int y2 = y - 1; - if (y2 < 10) - y2 = 10; - - if (Main.tile[x, y] != null) - { - if (Main.tile[x, y].nactive()) - { - if (Main.tile[x, y].liquid <= 32) - { - if (Main.tile[x, y].type == TileID.JungleGrass) - { - if (Main.tile[x, y2].liquid == 0) - { - // Plantera Bulbs pre-mech - if (WorldGen.genRand.Next(1500) == 0) - { - if (Main.hardMode && (!NPC.downedMechBoss1 || !NPC.downedMechBoss2 || !NPC.downedMechBoss3)) - { - bool placeBulb = true; - int minDistanceFromOtherBulbs = 150; - for (int i = x - minDistanceFromOtherBulbs; i < x + minDistanceFromOtherBulbs; i += 2) - { - for (int j = y - minDistanceFromOtherBulbs; j < y + minDistanceFromOtherBulbs; j += 2) - { - if (i > 1 && i < Main.maxTilesX - 2 && j > 1 && j < Main.maxTilesY - 2 && Main.tile[i, j].active() && Main.tile[i, j].type == TileID.PlanteraBulb) - { - placeBulb = false; - break; - } - } - } - - if (placeBulb) - { - WorldGen.PlaceJunglePlant(x, y2, TileID.PlanteraBulb, 0, 0); - WorldGen.SquareTileFrame(x, y2); - WorldGen.SquareTileFrame(x + 2, y2); - WorldGen.SquareTileFrame(x - 1, y2); - if (Main.tile[x, y2].type == TileID.PlanteraBulb && Main.netMode == NetmodeID.Server) - { - NetMessage.SendTileSquare(-1, x, y2, 5); - } - } - } - } - - // Life Fruit pre-mech - int random = Main.expertMode ? 90 : 120; - if (WorldGen.genRand.Next(random) == 0) - { - if (Main.hardMode && !NPC.downedMechBossAny) - { - bool placeFruit = true; - int minDistanceFromOtherFruit = Main.expertMode ? 50 : 60; - for (int i = x - minDistanceFromOtherFruit; i < x + minDistanceFromOtherFruit; i += 2) - { - for (int j = y - minDistanceFromOtherFruit; j < y + minDistanceFromOtherFruit; j += 2) - { - if (i > 1 && i < Main.maxTilesX - 2 && j > 1 && j < Main.maxTilesY - 2 && Main.tile[i, j].active() && Main.tile[i, j].type == TileID.LifeFruit) - { - placeFruit = false; - break; - } - } - } - - if (placeFruit) - { - WorldGen.PlaceJunglePlant(x, y2, TileID.LifeFruit, WorldGen.genRand.Next(3), 0); - WorldGen.SquareTileFrame(x, y2); - WorldGen.SquareTileFrame(x + 1, y2 + 1); - if (Main.tile[x, y2].type == TileID.LifeFruit && Main.netMode == NetmodeID.Server) - { - NetMessage.SendTileSquare(-1, x, y2, 4); - } - } - } - } - } - } - } - - int tileType = Main.tile[x, y].type; - bool tenebris = tileType == ModContent.TileType() && downedCalamitas; - - if (CalamityGlobalTile.GrowthTiles.Contains(tileType) || tenebris) - { - int growthChance = tenebris ? 4 : 2; - if (tileType == ModContent.TileType()) - growthChance *= 5; - - if (Main.rand.NextBool(growthChance)) - { - switch (WorldGen.genRand.Next(4)) - { - case 0: - x++; - break; - case 1: - x--; - break; - case 2: - y++; - break; - case 3: - y--; - break; - default: - break; - } - - if (Main.tile[x, y] != null) - { - Tile tile = Main.tile[x, y]; - bool growTile = tenebris ? (tile.active() && tile.type == ModContent.TileType()) : (!tile.active() && tile.liquid >= 128); - bool isSunkenSeaTile = tileType == ModContent.TileType() || tileType == ModContent.TileType() || tileType == ModContent.TileType(); - bool meetsAdditionalGrowConditions = tile.slope() == 0 && !tile.halfBrick() && !tile.lava(); - - if (growTile && meetsAdditionalGrowConditions) - { - int tileType2 = ModContent.TileType(); - - if (tileType == ModContent.TileType()) - tileType2 = ModContent.TileType(); - - bool canPlaceBasedOnAttached = true; - if (tileType2 == ModContent.TileType() && !isSunkenSeaTile) - canPlaceBasedOnAttached = false; - - if (canPlaceBasedOnAttached && (CanPlaceBasedOnProximity(x, y, tileType2) || tenebris)) - { - tile.type = tenebris ? (ushort)tileType : (ushort)tileType2; - - if (!tenebris) - { - tile.active(true); - if (Main.tile[x, y + 1].active() && Main.tileSolid[Main.tile[x, y + 1].type] && Main.tile[x, y + 1].slope() == 0 && !Main.tile[x, y + 1].halfBrick()) - { - tile.frameY = 0; - } - else if (Main.tile[x, y - 1].active() && Main.tileSolid[Main.tile[x, y - 1].type] && Main.tile[x, y - 1].slope() == 0 && !Main.tile[x, y - 1].halfBrick()) - { - tile.frameY = 18; - } - else if (Main.tile[x + 1, y].active() && Main.tileSolid[Main.tile[x + 1, y].type] && Main.tile[x + 1, y].slope() == 0 && !Main.tile[x + 1, y].halfBrick()) - { - tile.frameY = 36; - } - else if (Main.tile[x - 1, y].active() && Main.tileSolid[Main.tile[x - 1, y].type] && Main.tile[x - 1, y].slope() == 0 && !Main.tile[x - 1, y].halfBrick()) - { - tile.frameY = 54; - } - tile.frameX = (short)(WorldGen.genRand.Next(18) * 18); - } - - WorldGen.SquareTileFrame(x, y); - - if (Main.netMode == NetmodeID.Server) - NetMessage.SendTileSquare(-1, x, y, 1, TileChangeType.None); - } - } - } - } - } - } - } - l++; - } - - BossRushEvent.Update(); - - if (bossRushHostileProjKillCounter > 0) - { - bossRushHostileProjKillCounter--; - if (bossRushHostileProjKillCounter == 1) - CalamityUtils.KillAllHostileProjectiles(); - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.BRHostileProjKillSync); - netMessage.Write(bossRushHostileProjKillCounter); - netMessage.Send(); - } - } - - if (DoGSecondStageCountdown > 0) - { - DoGSecondStageCountdown--; - if (Main.netMode != NetmodeID.MultiplayerClient) - { - if (DoGSecondStageCountdown == 21540) - CalamityUtils.SpawnBossBetter(player.Center, ModContent.NPCType(), new OffscreenBossSpawnContext()); - if (DoGSecondStageCountdown == 14340) - CalamityUtils.SpawnBossBetter(player.Center, ModContent.NPCType(), new OffscreenBossSpawnContext()); - if (DoGSecondStageCountdown == 7140) - CalamityUtils.SpawnBossBetter(player.Center, ModContent.NPCType(), new OffscreenBossSpawnContext()); - - if (DoGSecondStageCountdown <= 60) - { - int freeNPCSlots = Main.maxNPCs - Main.npc.Take(Main.maxNPCs).Where(npc => npc.active).Count(); - - // If there are too many slots occupied, make a note in the logs, - // and don't attempt to spawn the Devourer of Gods. - if (freeNPCSlots < 102) - { - CalamityMod.Instance.Logger.Warn("You have too many occupied NPC slots for DoG to spawn. Remove dummies or kill excessive town NPCs."); - DoGSecondStageCountdown = 0; - } - else if (!NPC.AnyNPCs(ModContent.NPCType())) - { - NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); - string key = "Mods.CalamityMod.EdgyBossText10"; - Color messageColor = Color.Cyan; - CalamityUtils.DisplayLocalizedText(key, messageColor); - } - } - } - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.DoGCountdownSync); - netMessage.Write(DoGSecondStageCountdown); - netMessage.Send(); - } - } - - if (player.ZoneDungeon && !NPC.downedBoss3 && !player.dead) - { - if (!NPC.AnyNPCs(NPCID.DungeonGuardian) && Main.netMode != NetmodeID.MultiplayerClient) - NPC.SpawnOnPlayer(closestPlayer, NPCID.DungeonGuardian); //your hell is as vast as my bonergrin, pray your life ends quickly - } - - if (player.ZoneRockLayerHeight && - !player.ZoneUnderworldHeight && - !player.ZoneDungeon && - !player.ZoneJungle && - !modPlayer.ZoneSunkenSea && - !CalamityPlayer.areThereAnyDamnBosses) - { - if (NPC.downedPlantBoss && - !modPlayer.ZoneAbyss && - player.townNPCs < 3f) - { - double spawnRate = 100000D; - - if (revenge) - spawnRate *= 0.85D; - - if (demonMode) - spawnRate *= 0.75D; - - if (death && Main.bloodMoon) - spawnRate *= 0.2D; - if (modPlayer.zerg) - spawnRate *= 0.5D; - if (modPlayer.chaosCandle) - spawnRate *= 0.6D; - if (player.enemySpawns) - spawnRate *= 0.7D; - if (Main.waterCandles > 0) - spawnRate *= 0.8D; - - if (modPlayer.bossZen || DoGSecondStageCountdown > 0) - spawnRate *= 50D; - if (modPlayer.zen || (CalamityConfig.Instance.DisableExpertTownSpawns && player.townNPCs > 1f && Main.expertMode)) - spawnRate *= 2D; - if (modPlayer.tranquilityCandle) - spawnRate *= 1.67D; - if (player.calmed) - spawnRate *= 1.43D; - if (Main.peaceCandles > 0) - spawnRate *= 1.25D; - - int chance = (int)spawnRate; - if (Main.rand.Next(chance) == 0) - { - if (!NPC.AnyNPCs(ModContent.NPCType()) && Main.netMode != NetmodeID.MultiplayerClient && - ArmoredDiggerSpawnCooldown <= 0) - { - NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); - ArmoredDiggerSpawnCooldown = 3600; - } - } - } - } - if (ArmoredDiggerSpawnCooldown > 0) - { - ArmoredDiggerSpawnCooldown--; - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.ArmoredDiggerCountdownSync); - netMessage.Write(ArmoredDiggerSpawnCooldown); - netMessage.Send(); - } - } - - if (modPlayer.ZoneAbyss) - { - if (player.chaosState && !player.dead) - { - bool adultWyrmAlive = false; - if (CalamityGlobalNPC.adultEidolonWyrmHead != -1) - { - if (Main.npc[CalamityGlobalNPC.adultEidolonWyrmHead].active) - adultWyrmAlive = true; - } - - if (!adultWyrmAlive && Main.netMode != NetmodeID.MultiplayerClient) - NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); - } - } - - // DO NOT REMOVE -- this code is being kept for April Fools 2020 - if (Main.rand.NextBool(100000000) && DateTime.Now.Month == 4 && DateTime.Now.Day == 1) - { - string key = "Mods.CalamityMod.AprilFools"; - Color messageColor = Color.Crimson; - CalamityUtils.DisplayLocalizedText(key, messageColor); - } - - if (death && !CalamityPlayer.areThereAnyDamnBosses && !Main.snowMoon && !Main.pumpkinMoon && !DD2Event.Ongoing && player.statLifeMax2 >= 300 && !WorldGen.spawnEye && WorldGen.spawnHardBoss <= 0) //does not occur while a boss is alive or during certain events - { - if (bossSpawnCountdown <= 0 && deathBossSpawnCooldown <= 0) // Check for countdown and cooldown being 0 - { - if (Main.rand.NextBool(50000)) - { - // Only set countdown and boss type if conditions are met - // Night time bosses set message only before 11pm. Day time bosses only before 2pm. - if (!NPC.downedBoss1 && bossType == 0) - if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) - { - BossText(); - bossType = NPCID.EyeofCthulhu; - bossSpawnCountdown = 3600; // 1 minute - } - - if (!NPC.downedBoss2 && bossType == 0) - if (player.ZoneCorrupt) - { - BossText(); - bossType = NPCID.EaterofWorldsHead; - bossSpawnCountdown = 3600; - } - - if (!NPC.downedBoss2 && bossType == 0) - if (player.ZoneCrimson) - { - BossText(); - bossType = NPCID.BrainofCthulhu; - bossSpawnCountdown = 3600; - } - - /*if (!NPC.downedQueenBee && bossType == 0) - if (player.ZoneJungle && !player.ZoneOverworldHeight && !player.ZoneSkyHeight) - { - BossText(); - bossType = NPCID.QueenBee; - bossSpawnCountdown = 3600; - }*/ - - if (!downedDesertScourge && bossType == 0) - if (player.ZoneDesert) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - if (!downedPerforator && bossType == 0) - if (player.ZoneCrimson) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - if (!downedHiveMind && bossType == 0) - if (player.ZoneCorrupt) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - if (!downedCrabulon && bossType == 0) - if (player.ZoneGlowshroom) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - if (Main.hardMode) - { - if (!NPC.downedMechBoss1 && bossType == 0) - if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) - { - BossText(); - bossType = NPCID.TheDestroyer; - bossSpawnCountdown = 3600; - } - - if (!NPC.downedMechBoss2 && bossType == 0) - if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) - { - BossText(); - bossType = NPCID.Spazmatism; - bossSpawnCountdown = 3600; - } - - if (!NPC.downedMechBoss3 && bossType == 0) - if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) - { - BossText(); - bossType = NPCID.SkeletronPrime; - bossSpawnCountdown = 3600; - } - - if (!NPC.downedPlantBoss && bossType == 0) - if (player.ZoneJungle && !player.ZoneOverworldHeight && !player.ZoneSkyHeight) - { - BossText(); - bossType = NPCID.Plantera; - bossSpawnCountdown = 3600; - } - - if (!NPC.downedFishron && bossType == 0) - if (player.ZoneBeach && !modPlayer.ZoneSulphur) - { - BossText(); - bossType = NPCID.DukeFishron; - bossSpawnCountdown = 3600; - } - - if (!downedCryogen && bossType == 0) - if (player.ZoneSnow && player.ZoneOverworldHeight) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - if (!downedCalamitas && bossType == 0) - if (!Main.dayTime && player.ZoneOverworldHeight && Main.time < 12600) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - if (!downedAstrageldon && bossType == 0) - if (modPlayer.ZoneAstral && - !Main.dayTime && player.ZoneOverworldHeight) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - /*if (!downedPlaguebringer && bossType == 0) - if (player.ZoneJungle && NPC.downedGolemBoss && !player.ZoneOverworldHeight && !player.ZoneSkyHeight) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - }*/ - - if (NPC.downedMoonlord) - { - if (!downedGuardians && bossType == 0) - if (Main.dayTime && (player.ZoneUnderworldHeight || - (player.ZoneHoly && player.ZoneOverworldHeight)) && Main.time < 34200) //only before 2pm - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - - if (!downedBumble && bossType == 0) - if (player.ZoneJungle && player.ZoneOverworldHeight) - { - BossText(); - bossType = ModContent.NPCType(); - bossSpawnCountdown = 3600; - } - } - } - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.BossSpawnCountdownSync); - netMessage.Write(bossSpawnCountdown); - netMessage.Send(); - var netMessage2 = mod.GetPacket(); - netMessage2.Write((byte)CalamityModMessageType.BossTypeSync); - netMessage2.Write(bossType); - netMessage2.Send(); - } - } - } - else - { - if (bossSpawnCountdown > 0) - { - bossSpawnCountdown--; - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.BossSpawnCountdownSync); - netMessage.Write(bossSpawnCountdown); - netMessage.Send(); - } - } - - if (bossSpawnCountdown <= 0 && deathBossSpawnCooldown <= 0) // Check both cooldowns again here to avoid infinite message possibilities - { - bool canSpawn = true; - switch (bossType) - { - case NPCID.EyeofCthulhu: - if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) - canSpawn = false; - break; - case NPCID.EaterofWorldsHead: - if (!player.ZoneCorrupt) - canSpawn = false; - break; - case NPCID.BrainofCthulhu: - if (!player.ZoneCrimson) - canSpawn = false; - break; - /*case NPCID.QueenBee: - if (!player.ZoneJungle || player.ZoneOverworldHeight || player.ZoneSkyHeight) - canSpawn = false; - break;*/ - case NPCID.TheDestroyer: - if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) - canSpawn = false; - break; - case NPCID.Spazmatism: - if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) - canSpawn = false; - break; - case NPCID.SkeletronPrime: - if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) - canSpawn = false; - break; - case NPCID.Plantera: - if (!player.ZoneJungle || player.ZoneOverworldHeight || player.ZoneSkyHeight) - canSpawn = false; - break; - case NPCID.DukeFishron: - if (!player.ZoneBeach) - canSpawn = false; - break; - } - - if (bossType == ModContent.NPCType()) - { - if (!player.ZoneDesert) - canSpawn = false; - } - else if (bossType == ModContent.NPCType()) - { - if (!player.ZoneCrimson) - canSpawn = false; - } - else if (bossType == ModContent.NPCType()) - { - if (!player.ZoneCorrupt) - canSpawn = false; - } - else if (bossType == ModContent.NPCType()) - { - if (!player.ZoneGlowshroom) - canSpawn = false; - } - else if (bossType == ModContent.NPCType()) - { - if (!player.ZoneSnow || !player.ZoneOverworldHeight) - canSpawn = false; - } - else if (bossType == ModContent.NPCType()) - { - if (Main.dayTime || !player.ZoneOverworldHeight || Main.time > 16200) - canSpawn = false; - } - else if (bossType == ModContent.NPCType()) - { - if (!modPlayer.ZoneAstral || - Main.dayTime || !player.ZoneOverworldHeight) - canSpawn = false; - } - /*else if (bossType == ModContent.NPCType()) - { - if (!player.ZoneJungle || player.ZoneOverworldHeight || player.ZoneSkyHeight) - canSpawn = false; - }*/ - else if (bossType == ModContent.NPCType()) - { - if (!Main.dayTime || (!player.ZoneUnderworldHeight && - (!player.ZoneHoly || !player.ZoneOverworldHeight)) || Main.time > 37800) - canSpawn = false; - } - else if (bossType == ModContent.NPCType()) - { - if (!player.ZoneJungle || !player.ZoneOverworldHeight) - canSpawn = false; - } - - if (canSpawn) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - if (bossType == NPCID.Spazmatism) - NPC.SpawnOnPlayer(closestPlayer, NPCID.Retinazer); - else if (bossType == ModContent.NPCType()) - { - NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); - NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); - } - else if (bossType == ModContent.NPCType()) - { - NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); - NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); - } - if (bossType == NPCID.DukeFishron) - { - NPC.NewNPC((int)player.Center.X - 300, (int)player.Center.Y - 300, bossType); - } - else - { - NPC.SpawnOnPlayer(closestPlayer, bossType); - } - } - - deathBossSpawnCooldown = 86400; // 24 minutes (1 full Terraria day) - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.DeathBossSpawnCountdownSync); - netMessage.Write(deathBossSpawnCooldown); - netMessage.Send(); - } - } - - bossType = 0; - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.BossTypeSync); - netMessage.Write(bossType); - netMessage.Send(); - } - } - - // IMPORTANT! Decrement this cooldown AFTER everything else to avoid infinite possibilities - if (deathBossSpawnCooldown > 0) - { - deathBossSpawnCooldown--; - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.DeathBossSpawnCountdownSync); - netMessage.Write(deathBossSpawnCooldown); - netMessage.Send(); - } - } - } - } - - if (!downedDesertScourge && Main.netMode != NetmodeID.MultiplayerClient && !Main.hardMode) - CalamityUtils.StopSandstorm(); - - if (Main.netMode != NetmodeID.MultiplayerClient) - { - CultistRitual.delay -= Main.dayRate * 10; - if (CultistRitual.delay < 0) - { - CultistRitual.delay = 0; - } - CultistRitual.recheck -= Main.dayRate * 10; - if (CultistRitual.recheck < 0) - { - CultistRitual.recheck = 0; - } - } - } - - public static void HandleDraedonSummoning() - { - // Fire a giant laser into the sky. - if (Main.netMode != NetmodeID.MultiplayerClient && DraedonSummonCountdown == DraedonSummonCountdownMax - 45) - Projectile.NewProjectile(DraedonSummonPosition + Vector2.UnitY * 80f, Vector2.Zero, ModContent.ProjectileType(), 70, 0f); - - if (DraedonSummonCountdown < 150) - { - float fadeToWhite = Utils.InverseLerp(150f, 90f, DraedonSummonCountdown, true) * Utils.InverseLerp(30f, 50f, DraedonSummonCountdown, true); - MoonlordDeathDrama.RequestLight(fadeToWhite, Main.LocalPlayer.Center); - } - - if (DraedonSummonCountdown == 0) - NPC.NewNPC((int)DraedonSummonPosition.X, (int)DraedonSummonPosition.Y, ModContent.NPCType()); - } - #endregion - - #region Check Placement Proximity - private bool CanPlaceBasedOnProximity(int x, int y, int tileType) - { - if (tileType == ModContent.TileType() && !downedCalamitas) - return false; - - int minDistanceFromOtherTiles = 6; - int sameTilesNearby = 0; - for (int i = x - minDistanceFromOtherTiles; i < x + minDistanceFromOtherTiles; i++) - { - for (int j = y - minDistanceFromOtherTiles; j < y + minDistanceFromOtherTiles; j++) - { - if (Main.tile[i, j].active() && Main.tile[i, j].type == tileType) - { - sameTilesNearby++; - if (sameTilesNearby > 1) - return false; - } - } - } - - return true; - } - #endregion - - #region ChangeTime - public static void ChangeTime(bool day) - { - Main.time = 0.0; - Main.dayTime = day; - CalamityNetcode.SyncWorld(); - } - #endregion - - #region BossText - public void BossText() - { - string key = "Mods.CalamityMod.BossSpawnText"; - Color messageColor = Color.Crimson; - CalamityUtils.DisplayLocalizedText(key, messageColor); - } + public override void PostUpdate() => WorldUpdateMiscEffects.PerformWorldUpdates(); #endregion } } diff --git a/World/MiscWorldgenRoutines.cs b/World/MiscWorldgenRoutines.cs new file mode 100644 index 0000000000..14f9a10476 --- /dev/null +++ b/World/MiscWorldgenRoutines.cs @@ -0,0 +1,832 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Items.Potions; +using CalamityMod.Items.Weapons.Rogue; +using CalamityMod.Tiles; +using CalamityMod.Tiles.Abyss; +using CalamityMod.Tiles.Astral; +using CalamityMod.Tiles.Crags; +using CalamityMod.Tiles.FurnitureAncient; +using CalamityMod.Tiles.Ores; +using CalamityMod.Walls; +using Microsoft.Xna.Framework; +using System; +using System.Reflection; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.World.Generation; + +namespace CalamityMod.World +{ + public class MiscWorldgenRoutines + { + #region Dungeon Biome Chests + public static void GenerateBiomeChests(GenerationProgress progress) + { + progress.Message = "Calamity Mod: Biome Chests"; + + // Get dungeon size field infos. These fields are private for some reason + int MinX = (int)typeof(WorldGen).GetField("dMinX", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) + 25; + int MaxX = (int)typeof(WorldGen).GetField("dMaxX", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) - 25; + int MaxY = (int)typeof(WorldGen).GetField("dMaxY", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) - 25; + + int[] ChestTypes = { ModContent.TileType() }; + int[] ItemTypes = { ModContent.ItemType() }; + int[] ChestStyles = { 1 }; // Astral Chest generates in style 1, which is locked + + for (int i = 0; i < ChestTypes.Length; ++i) + { + Chest chest = null; + int attempts = 0; + + // Try 1000 times to place the chest somewhere in the dungeon. + // The placement algorithm ensures that if it tries to appear in midair, it is moved down to the floor. + while (chest == null && attempts < 1000) + { + attempts++; + int x = WorldGen.genRand.Next(MinX, MaxX); + int y = WorldGen.genRand.Next((int)Main.worldSurface, MaxY); + if (Main.wallDungeon[Main.tile[x, y].wall] && !Main.tile[x, y].active()) + chest = AddChestWithLoot(x, y, (ushort)ChestTypes[i], tileStyle: ChestStyles[i]); + } + + // If a chest was placed, force its first item to be the unique Biome Chest weapon. + if (chest != null) + { + chest.item[0].SetDefaults(ItemTypes[i]); + chest.item[0].Prefix(-1); + } + } + } + + internal static Chest AddChestWithLoot(int i, int j, ushort type = TileID.Containers, uint startingSlot = 1, int tileStyle = 0) + { + int chestIndex = -1; + + // Slide downwards on the Y axis trying to find the floor beneath the empty position initially picked + while (j < Main.maxTilesY - 210) + { + if (!WorldGen.SolidTile(i, j)) + { + j++; + continue; + } + + // If there are already 1,000 chests in the world and this one fails to place, just give up. + chestIndex = WorldGen.PlaceChest(i - 1, j - 1, type, false, tileStyle); + break; + } + + if (chestIndex < 0) + return null; + Chest chest = Main.chest[chestIndex]; + PlaceLootInChest(ref chest, type, startingSlot); + return chest; + } + + internal static void PlaceLootInChest(ref Chest chest, ushort type, uint startingSlot) + { + uint itemIndex = startingSlot; + + void PutItemInChest(ref Chest c, int id, int minQuantity = 0, int maxQuantity = 0, bool condition = true) + { + if (!condition) + return; + c.item[itemIndex].SetDefaults(id, false); + + // Don't set quantity unless quantity is specified + if(minQuantity > 0) + { + // Max quantity cannot be less than min quantity. It's zero if not specified, meaning you get exactly minQuantity. + if (maxQuantity < minQuantity) + maxQuantity = minQuantity; + c.item[itemIndex].stack = WorldGen.genRand.Next(minQuantity, maxQuantity + 1); + } + itemIndex++; + } + + // Astral Chest has completely different loot in it + if (type == ModContent.TileType()) + { + PutItemInChest(ref chest, ModContent.ItemType(), 30, 80); + PutItemInChest(ref chest, ModContent.ItemType(), 10, 14); + PutItemInChest(ref chest, ModContent.ItemType(), 8); + PutItemInChest(ref chest, ModContent.ItemType(), 3, 5); + PutItemInChest(ref chest, ItemID.FallenStar, 12, 30); + + // Gold Coins don't stack above 100, so this efficiently lets you stuff over a platinum into a chest + int goldCoins = WorldGen.genRand.Next(30, 120); + if (goldCoins > 100) + { + PutItemInChest(ref chest, ItemID.PlatinumCoin); + goldCoins -= 100; + } + PutItemInChest(ref chest, ItemID.GoldCoin, goldCoins); + } + else if (type == ModContent.TileType()) + { + // 15-29 torches (in accordence with vanilla) + PutItemInChest(ref chest, ItemID.Torch, 15, 29); + + // 50% chance of 1 or 2 of the following potions + int[] potions = new int[] + { + ModContent.ItemType(), ItemID.WaterWalkingPotion, ItemID.ShinePotion, ItemID.GillsPotion, ItemID.FlipperPotion + }; + PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); + PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); + + // 33% chance of flippers + PutItemInChest(ref chest, ItemID.Flipper, condition: WorldGen.genRand.NextBool(3)); + + // Typical coins + PutItemInChest(ref chest, ItemID.GoldCoin, 2, 4); + } + // Default loot + else + { + // Silver, Tungsten, Gold or Platinum bars (following worldgen choice) + int barID = WorldGen.genRand.NextBool() ? WorldGen.goldBar : WorldGen.silverBar; + PutItemInChest(ref chest, barID, 3, 10); + + // 50% chance of 25-50 Holy Arrows + PutItemInChest(ref chest, ItemID.HolyArrow, 25, 50, WorldGen.genRand.NextBool()); + + // 50% chance of 1 or 2 of the following potions + int[] potions = new int[] { + ItemID.SpelunkerPotion, ItemID.FeatherfallPotion, ItemID.NightOwlPotion, + ItemID.WaterWalkingPotion, ItemID.ArcheryPotion, ItemID.GravitationPotion + }; + PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); + + // 50% chance of 1 or 2 of the following potions + // Yes, in vanilla, Dangersense Potions have double the chance to appear. + potions = new int[] { + ItemID.ThornsPotion, ItemID.WaterWalkingPotion, ItemID.InvisibilityPotion, + ItemID.ManaRegenerationPotion, ItemID.TeleportationPotion, ItemID.TrapsightPotion, ItemID.TrapsightPotion + }; + + PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); + PutItemInChest(ref chest, ItemID.RecallPotion, 1, 2, WorldGen.genRand.NextBool()); + PutItemInChest(ref chest, ItemID.GoldCoin, 1, 2); + } + } + #endregion + + #region Place Rox Shrine + public static void PlaceRoxShrine() + { + while (!CalamityWorld.roxShrinePlaced) + { + CalamityWorld.roxShrinePlaced = true; + for (int x = 0; x < Main.maxTilesX; x++) + { + for (int y = 0; y < Main.maxTilesY; y++) + { + if (Main.tile[x, y] != null && Main.tile[x, y].type == TileID.LargePiles) + { + if ((Main.tile[x, y].frameX == 18 && Main.tile[x, y].frameY == 0) || (Main.tile[x, y].frameX == 45 && Main.tile[x, y].frameY == 0)) + { + if (WorldGen.genRand.Next(3) == 0) + { + for (int dx = -1; dx < 2; dx++) + { + for (int dy = -1; dy < 2; dy++) + Main.tile[x + dx, y + dy].active(false); + } + + WorldGen.PlaceTile(x, y + 1, ModContent.TileType()); + return; + } + else + CalamityWorld.roxShrinePlaced = false; + } + } + } + } + } + } + #endregion + + // NOTE - The crag gen is scheduled for a rework soon. As such, its code will not be moved. + + #region UnderworldIsland + public static void UnderworldIsland(int i, int j, int sizeMin, int sizeMax, int sizeMin2, int sizeMax2) + { + double num = (double)WorldGen.genRand.Next(sizeMin, sizeMax); //100 150 + float num2 = (float)WorldGen.genRand.Next(sizeMin / 5, sizeMax / 5); //20 30 + int num3 = i; + int num4 = i; + int num5 = i; + int num6 = j; + Vector2 vector; + vector.X = (float)i; + vector.Y = (float)j; + Vector2 vector2; + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + while (vector2.X > -2f && vector2.X < 2f) + { + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + } + vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; + while (num > 0.0 && num2 > 0f) + { + num -= (double)WorldGen.genRand.Next(4); + num2 -= 1f; + int num7 = (int)((double)vector.X - num * 0.5); + int num8 = (int)((double)vector.X + num * 0.5); + int num9 = (int)((double)vector.Y - num * 0.5); + int num10 = (int)((double)vector.Y + num * 0.5); + if (num7 < 0) + { + num7 = 0; + } + if (num8 > Main.maxTilesX) + { + num8 = Main.maxTilesX; + } + if (num9 < Main.maxTilesY - 270) + { + num9 = Main.maxTilesY - 270; + } + if (num10 > Main.maxTilesY) + { + num10 = Main.maxTilesY; + } + double num11 = num * (double)WorldGen.genRand.Next(sizeMin, sizeMax) * 0.01; //80 120 + float num12 = vector.Y + 1f; + for (int k = num7; k < num8; k++) + { + if (WorldGen.genRand.Next(2) == 0) + { + num12 += (float)WorldGen.genRand.Next(-1, 2); + } + if (num12 < vector.Y) + { + num12 = vector.Y; + } + if (num12 > vector.Y + 2f) + { + num12 = vector.Y + 2f; + } + for (int l = num9; l < num10; l++) + { + if ((float)l > num12) + { + float arg_218_0 = Math.Abs((float)k - vector.X); + float num13 = Math.Abs((float)l - vector.Y) * 3f; + if (Math.Sqrt((double)(arg_218_0 * arg_218_0 + num13 * num13)) < num11 * 0.4) + { + if (k < num3) + { + num3 = k; + } + if (k > num4) + { + num4 = k; + } + if (l < num5) + { + num5 = l; + } + if (l > num6) + { + num6 = l; + } + Main.tile[k, l].active(true); + Main.tile[k, l].type = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(k, l, true); + } + } + } + } + vector += vector2; + vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; + if (vector2.X > 1f) + { + vector2.X = 1f; + } + if (vector2.X < -1f) + { + vector2.X = -1f; + } + if ((double)vector2.Y > 0.2) + { + vector2.Y = -0.2f; + } + if ((double)vector2.Y < -0.2) + { + vector2.Y = -0.2f; + } + } + int m = num3; + int num15; + for (m += WorldGen.genRand.Next(5); m < num4; m += WorldGen.genRand.Next(num15, (int)((double)num15 * 1.5))) + { + int num14 = num6; + while (!Main.tile[m, num14].active()) + { + num14--; + if (num14 < Main.maxTilesX - WorldGen.genRand.Next(265, 275 + 1)) + break; + } + num14 += WorldGen.genRand.Next(-3, 4); + num15 = WorldGen.genRand.Next(4, 8); + int num16 = ModContent.TileType(); + if (WorldGen.genRand.Next(4) == 0) + { + num16 = ModContent.TileType(); + } + for (int n = m - num15; n <= m + num15; n++) + { + for (int num17 = num14 - num15; num17 <= num14 + num15; num17++) + { + if (num17 > num5) + { + float arg_409_0 = (float)Math.Abs(n - m); + float num18 = (float)(Math.Abs(num17 - num14) * 2); + if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num15 + WorldGen.genRand.Next(2))) + { + Main.tile[n, num17].active(true); + Main.tile[n, num17].type = (ushort)num16; + WorldGen.SquareTileFrame(n, num17, true); + } + } + } + } + } + num = (double)WorldGen.genRand.Next(sizeMin2, sizeMax2); + num2 = (float)WorldGen.genRand.Next(sizeMin2 / 8, sizeMax2 / 8); + vector.X = (float)i; + vector.Y = (float)num5; + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + while (vector2.X > -2f && vector2.X < 2f) + { + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + } + vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; + while (num > 0.0 && num2 > 0f) + { + num -= (double)WorldGen.genRand.Next(4); + num2 -= 1f; + vector += vector2; + vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; + if (vector2.X > 1f) + { + vector2.X = 1f; + } + if (vector2.X < -1f) + { + vector2.X = -1f; + } + if ((double)vector2.Y > 0.2) + { + vector2.Y = -0.2f; + } + if ((double)vector2.Y < -0.2) + { + vector2.Y = -0.2f; + } + } + int num23 = num3; + num23 += WorldGen.genRand.Next(5); + while (num23 < num4) + { + int num24 = num6; + while ((!Main.tile[num23, num24].active() || Main.tile[num23, num24].type != 0) && num23 < num4) + { + num24--; + if (num24 < num5) + { + num24 = num6; + num23 += WorldGen.genRand.Next(1, 4); + } + } + if (num23 < num4) + { + num24 += WorldGen.genRand.Next(0, 4); + int num25 = WorldGen.genRand.Next(2, 5); + int num26 = ModContent.TileType(); + for (int num27 = num23 - num25; num27 <= num23 + num25; num27++) + { + for (int num28 = num24 - num25; num28 <= num24 + num25; num28++) + { + if (num28 > num5) + { + float arg_890_0 = (float)Math.Abs(num27 - num23); + float num29 = (float)(Math.Abs(num28 - num24) * 2); + if (Math.Sqrt((double)(arg_890_0 * arg_890_0 + num29 * num29)) < (double)num25) + { + Main.tile[num27, num28].type = (ushort)num26; + WorldGen.SquareTileFrame(num27, num28, true); + } + } + } + } + num23 += WorldGen.genRand.Next(num25, (int)((double)num25 * 1.5)); + } + } + for (int num34 = num3; num34 <= num4; num34++) + { + int num35 = num5 - 10; + while (!Main.tile[num34, num35 + 1].active()) + { + num35++; + } + if (num35 < num6 && Main.tile[num34, num35 + 1].type == (ushort)ModContent.TileType()) + { + if (WorldGen.genRand.Next(10) == 0) + { + int num36 = WorldGen.genRand.Next(1, 3); + for (int num37 = num34 - num36; num37 <= num34 + num36; num37++) + { + if (Main.tile[num37, num35].type == (ushort)ModContent.TileType()) + { + Main.tile[num37, num35].active(false); + Main.tile[num37, num35].liquid = 255; + Main.tile[num37, num35].lava(false); + WorldGen.SquareTileFrame(num34, num35, true); + } + if (Main.tile[num37, num35 + 1].type == (ushort)ModContent.TileType()) + { + Main.tile[num37, num35 + 1].active(false); + Main.tile[num37, num35 + 1].liquid = 255; + Main.tile[num37, num35 + 1].lava(false); + WorldGen.SquareTileFrame(num34, num35 + 1, true); + } + if (num37 > num34 - num36 && num37 < num34 + 2 && Main.tile[num37, num35 + 2].type == (ushort)ModContent.TileType()) + { + Main.tile[num37, num35 + 2].active(false); + Main.tile[num37, num35 + 2].liquid = 255; + Main.tile[num37, num35 + 2].lava(false); + WorldGen.SquareTileFrame(num34, num35 + 2, true); + } + } + } + if (WorldGen.genRand.Next(5) == 0) + { + Main.tile[num34, num35].liquid = 255; + } + Main.tile[num34, num35].lava(false); + WorldGen.SquareTileFrame(num34, num35, true); + } + } + } + #endregion + + #region UnderworldIslandHouse + public static void UnderworldIslandHouse(int i, int j, int item) + { + ushort type = (ushort)ModContent.TileType(); //tile + byte wall = (byte)ModContent.WallType(); //wall + Vector2 vector = new Vector2((float)i, (float)j); + int num = 1; + if (WorldGen.genRand.Next(2) == 0) + { + num = -1; + } + int num2 = WorldGen.genRand.Next(7, 12); + int num3 = WorldGen.genRand.Next(5, 7); + vector.X = (float)(i + (num2 + 2) * num); + for (int k = j - 15; k < j + 30; k++) + { + if (Main.tile[(int)vector.X, k].active()) + { + vector.Y = (float)(k - 1); + break; + } + } + vector.X = (float)i; + int num4 = (int)(vector.X - (float)num2 - 1f); + int num5 = (int)(vector.X + (float)num2 + 1f); + int num6 = (int)(vector.Y - (float)num3 - 1f); + int num7 = (int)(vector.Y + 2f); + if (num4 < 0) + { + num4 = 0; + } + if (num5 > Main.maxTilesX) + { + num5 = Main.maxTilesX; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int l = num4; l <= num5; l++) + { + for (int m = num6 - 1; m < num7 + 1; m++) + { + if (m != num6 - 1 || (l != num4 && l != num5)) + { + Main.tile[l, m].active(true); + Main.tile[l, m].liquid = 0; + Main.tile[l, m].type = type; + Main.tile[l, m].wall = 0; + Main.tile[l, m].halfBrick(false); + Main.tile[l, m].slope(0); + } + } + } + num4 = (int)(vector.X - (float)num2); + num5 = (int)(vector.X + (float)num2); + num6 = (int)(vector.Y - (float)num3); + num7 = (int)(vector.Y + 1f); + if (num4 < 0) + { + num4 = 0; + } + if (num5 > Main.maxTilesX) + { + num5 = Main.maxTilesX; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int n = num4; n <= num5; n++) + { + for (int num8 = num6; num8 < num7; num8++) + { + if ((num8 != num6 || (n != num4 && n != num5)) && Main.tile[n, num8].wall == 0) + { + Main.tile[n, num8].active(false); + Main.tile[n, num8].wall = wall; + } + } + } + int num9 = i + (num2 + 1) * num; + int num10 = (int)vector.Y; + for (int num11 = num9 - 2; num11 <= num9 + 2; num11++) + { + Main.tile[num11, num10].active(false); + Main.tile[num11, num10 - 1].active(false); + Main.tile[num11, num10 - 2].active(false); + } + WorldGen.PlaceTile(num9, num10, ModContent.TileType(), true, false, -1); //door + num9 = i + (num2 + 1) * -num - num; + for (int num12 = num6; num12 <= num7 + 1; num12++) + { + Main.tile[num9, num12].active(true); + Main.tile[num9, num12].liquid = 0; + Main.tile[num9, num12].type = type; + Main.tile[num9, num12].wall = 0; + Main.tile[num9, num12].halfBrick(false); + Main.tile[num9, num12].slope(0); + } + WorldGen.AddBuriedChest(i, num10 - 3, item, false, 4); //chest + int num22 = i + (num2 / 2 + 1) * -num; + WorldGen.PlaceTile(num22, num7 - 1, ModContent.TileType(), true, false, -1); //table + WorldGen.PlaceTile(num22 - 2, num7 - 1, ModContent.TileType(), true, false, 0); //chair + Tile tile = Main.tile[num22 - 2, num7 - 1]; + tile.frameX += 18; + Tile tile2 = Main.tile[num22 - 2, num7 - 2]; + tile2.frameX += 18; + WorldGen.PlaceTile(num22 + 2, num7 - 1, ModContent.TileType(), true, false, 0); //chair + } + #endregion + + #region ChasmGenerator + public static void ChasmGenerator(int i, int j, int steps, bool ocean = false) + { + float num = steps; //850 small 1450 medium 2050 large + if (ocean) + { + int tileYLookup = j; + if (CalamityWorld.abyssSide) + { + while (!Main.tile[i + 125, tileYLookup].active()) + { + tileYLookup++; + } + } + else + { + while (!Main.tile[i - 125, tileYLookup].active()) + { + tileYLookup++; + } + } + j = tileYLookup; + } + Vector2 vector; + vector.X = i; + vector.Y = j; + Vector2 vector2; + vector2.X = WorldGen.genRand.Next(-1, 2) * 0.1f; + vector2.Y = WorldGen.genRand.Next(3, 8) * 0.2f + 0.5f; + int num2 = 5; + double num3 = WorldGen.genRand.Next(5, 7) + 20; //start width + while (num3 > 0.0) + { + if (num > 0f) + { + num3 += WorldGen.genRand.Next(2); + num3 -= WorldGen.genRand.Next(2); + float smallHoleLimit = 790f; //small + if (Main.maxTilesY > 1500) + { smallHoleLimit = 1360f; if (Main.maxTilesY > 2100) { smallHoleLimit = 1950f; } } + if (ocean && num > smallHoleLimit) + { + if (num3 < 7.0) //min width + { + num3 = 7.0; //min width + } + if (num3 > 11.0) //max width + { + num3 = 11.0; //max width + } + } + else //dig large hole + { + if (num3 < (ocean ? 45.0 : 8.0)) //min width + { + num3 = ocean ? 45.0 : 8.0; //min width + } + if (num3 > (ocean ? 50.0 : 20.0)) //max width + { + num3 = ocean ? 50.0 : 20.0; //max width + } + if (num == 1f && num3 < (ocean ? 50.0 : 15.0)) + { + num3 = ocean ? 50.0 : 15.0; + } + } + } + else + { + if ((double)vector.Y > CalamityWorld.abyssChasmBottom) + { + num3 -= WorldGen.genRand.Next(5) + 8; + } + } + if (Main.maxTilesY > 2100) + { + if (((double)vector.Y > CalamityWorld.abyssChasmBottom && num > 0f && ocean) || + (vector.Y >= Main.maxTilesY && num > 0f && !ocean)) + { + num = 0f; + } + } + else if (Main.maxTilesY > 1500) + { + if (((double)vector.Y > CalamityWorld.abyssChasmBottom && num > 0f && ocean) || + (vector.Y > Main.maxTilesY && num > 0f && !ocean)) + { + num = 0f; + } + } + else + { + if (((double)vector.Y > CalamityWorld.abyssChasmBottom && num > 0f && ocean) || + (vector.Y > Main.maxTilesY && num > 0f && !ocean)) + { + num = 0f; + } + } + num -= 1f; + int num4; + int num5; + int num6; + int num7; + if (num > num2) + { + num4 = (int)(vector.X - num3 * 0.5); + num5 = (int)(vector.X + num3 * 0.5); + num6 = (int)(vector.Y - num3 * 0.5); + num7 = (int)(vector.Y + num3 * 0.5); + if (num4 < 0) + { + num4 = 0; + } + if (num5 > Main.maxTilesX - 1) + { + num5 = Main.maxTilesX - 1; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int k = num4; k < num5; k++) + { + for (int l = num6; l < num7; l++) + { + if ((Math.Abs(k - vector.X) + Math.Abs(l - vector.Y)) < num3 * 0.5 * (1.0 + WorldGen.genRand.Next(-5, 6) * 0.015)) + { + if (ocean) + { + Main.tile[k, l].active(false); + Main.tile[k, l].liquid = 255; + Main.tile[k, l].lava(false); + } + else + { + Main.tile[k, l].active(false); + Main.tile[k, l].liquid = 255; + Main.tile[k, l].lava(true); + } + } + } + } + } + /*if (num <= 2f && vector.Y < (Main.rockLayer + Main.maxTilesY * 0.3)) + { + num = 2f; + }*/ + vector += vector2; + vector2.X += WorldGen.genRand.Next(-1, 2) * 0.01f; + if (vector2.X > 0.02) + { + vector2.X = 0.02f; + } + if (vector2.X < -0.02) + { + vector2.X = -0.02f; + } + num4 = (int)(vector.X - num3 * 1.1); + num5 = (int)(vector.X + num3 * 1.1); + num6 = (int)(vector.Y - num3 * 1.1); + num7 = (int)(vector.Y + num3 * 1.1); + if (num4 < 1) + { + num4 = 1; + } + if (num5 > Main.maxTilesX - 1) + { + num5 = Main.maxTilesX - 1; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int m = num4; m < num5; m++) + { + for (int n = num6; n < num7; n++) + { + if ((Math.Abs(m - vector.X) + Math.Abs(n - vector.Y)) < num3 * 1.1 * (1.0 + WorldGen.genRand.Next(-5, 6) * 0.015)) + { + if (n > j + WorldGen.genRand.Next(7, 16)) + { + Main.tile[m, n].active(false); + } + if (steps <= num2) + { + Main.tile[m, n].active(false); + } + if (ocean) + { + Main.tile[m, n].liquid = 255; + Main.tile[m, n].lava(false); + } + else + { + Main.tile[m, n].liquid = 255; + Main.tile[m, n].lava(true); + } + } + } + } + for (int num11 = num4; num11 < num5; num11++) + { + for (int num12 = num6; num12 < num7; num12++) + { + if ((Math.Abs(num11 - vector.X) + Math.Abs(num12 - vector.Y)) < num3 * 1.1 * (1.0 + WorldGen.genRand.Next(-5, 6) * 0.015)) + { + if (ocean) + { + Main.tile[num11, num12].liquid = 255; + Main.tile[num11, num12].lava(false); + } + else + { + Main.tile[num11, num12].liquid = 255; + Main.tile[num11, num12].lava(true); + } + if (steps <= num2) + { + Main.tile[num11, num12].active(false); + } + } + } + } + } + } + #endregion + } +} diff --git a/World/Planets/LuminitePlanet.cs b/World/Planets/LuminitePlanet.cs index 288136fa9b..7886b6dc64 100644 --- a/World/Planets/LuminitePlanet.cs +++ b/World/Planets/LuminitePlanet.cs @@ -9,6 +9,38 @@ namespace CalamityMod.World.Planets { public class LuminitePlanet : Planetoid { + public static void GenerateLuminitePlanetoids() + { + // Don't attempt to generate these things client-side. + if (Main.netMode == NetmodeID.MultiplayerClient) + return; + + // The worldgen structure map only gets created/regenerated when you generate a world, for some reason. + // This means if you simply enter a world and generate this planetoid, the map will not exist yet, and errors will arise. + // As a result, a new one is generated as necessary. + if (WorldGen.structures is null) + WorldGen.structures = new StructureMap(); + + int totalPlanetoidsToGenerate = Main.maxTilesX / 4200 + 1; + for (int i = 0; i < totalPlanetoidsToGenerate; i++) + { + for (int tries = 0; tries < 3000; tries++) + { + Point planetoidOrigin = new Point(WorldGen.genRand.Next(Main.maxTilesX / 2 - 700, Main.maxTilesX / 2 + 700), WorldGen.genRand.Next(85, 110)); + if (WorldGen.genRand.NextBool(2)) + { + if (Biomes.Place(planetoidOrigin, WorldGen.structures)) + break; + } + else + { + if (Biomes.Place(planetoidOrigin, WorldGen.structures)) + break; + } + } + } + } + public override bool Place(Point origin, StructureMap structures) { int radius = _random.Next(18, 21); diff --git a/World/Planets/LuminitePlanet2.cs b/World/Planets/LuminitePlanet2.cs index 0b5c20e235..d54e4e765a 100644 --- a/World/Planets/LuminitePlanet2.cs +++ b/World/Planets/LuminitePlanet2.cs @@ -1,6 +1,5 @@ using CalamityMod.Tiles.Ores; using Microsoft.Xna.Framework; -using System.Linq; using Terraria; using Terraria.ID; using Terraria.ModLoader; diff --git a/World/Planets/Planetoid.cs b/World/Planets/Planetoid.cs index 8a50a06157..d3e882d2c7 100644 --- a/World/Planets/Planetoid.cs +++ b/World/Planets/Planetoid.cs @@ -11,6 +11,69 @@ namespace CalamityMod.World.Planets { private Rectangle _area; + public static void GenerateAllBasePlanetoids(GenerationProgress progress) + { + progress.Message = "Generating Planetoids..."; + + int GrassPlanetoidCount = Main.maxTilesX / 1100; + int LCPlanetoidCount = Main.maxTilesX / 800; + int MudPlanetoidCount = Main.maxTilesX / 1100; + + const int MainPlanetoidAttempts = 3000; + int i = 0; + while (i < MainPlanetoidAttempts) + { + if (Biomes.Place(new Point(WorldGen.genRand.Next(Main.maxTilesX / 2 - 300, Main.maxTilesX / 2 + 300), WorldGen.genRand.Next(128, 134)), WorldGen.structures)) + { + break; + } + i++; + } + + const int CrystalHeartPlanetoidAttempts = 15000; + i = 0; + while (LCPlanetoidCount > 0 && i < CrystalHeartPlanetoidAttempts) + { + int x = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.2), (int)(Main.maxTilesX * 0.8)); + int y = WorldGen.genRand.Next(70, 101); + + bool placed = Biomes.Place(x, y, WorldGen.structures); + + if (placed) + LCPlanetoidCount--; + i++; + } + + const int GrassPlanetoidAttempts = 12000; + i = 0; + while (GrassPlanetoidCount > 0 && i < GrassPlanetoidAttempts) + { + int x = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.333), (int)(Main.maxTilesX * 0.666)); + int y = WorldGen.genRand.Next(100, 131); + + + bool placed = Biomes.Place(x, y, WorldGen.structures); + + if (placed) + GrassPlanetoidCount--; + i++; + } + + const int MudPlanetoidAttempts = 12000; + i = 0; + while (MudPlanetoidCount > 0 && i < MudPlanetoidAttempts) + { + int x = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.3f), (int)(Main.maxTilesX * 0.7f)); + int y = WorldGen.genRand.Next(100, 131); + + bool placed = Biomes.Place(x, y, WorldGen.structures); + + if (placed) + MudPlanetoidCount--; + i++; + } + } + public static bool InvalidSkyPlacementArea(Rectangle area) { Mod varia = CalamityMod.Instance.varia; diff --git a/World/SmallBiomes.cs b/World/SmallBiomes.cs deleted file mode 100644 index 7e50ac1da2..0000000000 --- a/World/SmallBiomes.cs +++ /dev/null @@ -1,172 +0,0 @@ -using CalamityMod.World.Planets; -using Microsoft.Xna.Framework; -using System; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.World -{ - public class SmallBiomes : ModWorld - { - public static void PlaceEvilIsland() - { - int x = Main.maxTilesX; - int xIslandGen; - int yIslandGen; - Rectangle potentialArea; - - do - { - xIslandGen = WorldGen.crimson ? - WorldGen.genRand.Next((int)(x * 0.1), (int)(x * 0.15)) : - WorldGen.genRand.Next((int)(x * 0.85), (int)(x * 0.9)); - yIslandGen = WorldGen.genRand.Next(90, 151); - yIslandGen = Math.Min(yIslandGen, (int)WorldGen.worldSurfaceLow - 50); - - int checkAreaX = 200; - int checkAreaY = 200; - potentialArea = new Rectangle(xIslandGen + checkAreaX / 2, yIslandGen + checkAreaY / 2, checkAreaX, checkAreaY); - } - while (!Planetoid.InvalidSkyPlacementArea(potentialArea)); - - int tileXLookup = xIslandGen; - if (WorldGen.crimson) - { - while (Main.tile[tileXLookup, yIslandGen].active()) - tileXLookup++; - } - else - { - while (Main.tile[tileXLookup, yIslandGen].active()) - tileXLookup--; - } - - xIslandGen = tileXLookup; - CalamityWorld.fehX = xIslandGen; - CalamityWorld.fehY = yIslandGen; - WorldGenerationMethods.EvilIsland(xIslandGen, yIslandGen); - WorldGenerationMethods.EvilIslandHouse(CalamityWorld.fehX, CalamityWorld.fehY); - } - - public static void PlaceShrines() - { - int x = Main.maxTilesX; - int y = Main.maxTilesY; - int genLimit = x / 2; - int generateBack = genLimit - 80; //Small = 2020 - int generateForward = genLimit + 80; //Small = 2180 - double shrineChance = 100E-05; - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Surface Shrine - { - int tilesX = WorldGen.genRand.Next((int)(x * 0.35), generateBack); - int tilesX2 = WorldGen.genRand.Next(generateForward, (int)(x * 0.65)); - int tilesY = WorldGen.genRand.Next((int)(y * 0.3f), (int)(y * 0.35f)); - - if (Main.tile[tilesX, tilesY].type == TileID.Dirt || Main.tile[tilesX, tilesY].type == TileID.Stone) - { - WorldGenerationMethods.SpecialHut(TileID.RedBrick, TileID.Dirt, WallID.RedBrick, 0, tilesX, tilesY); - break; - } - if (Main.tile[tilesX2, tilesY].type == TileID.Dirt || Main.tile[tilesX2, tilesY].type == TileID.Stone) - { - WorldGenerationMethods.SpecialHut(TileID.RedBrick, TileID.Dirt, WallID.RedBrick, 0, tilesX2, tilesY); - break; - } - } - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Evil Shrine - { - int tilesX = WorldGen.genRand.Next(0, x); - int tilesY = WorldGen.genRand.Next((int)(y * 0.3f), (int)(y * 0.35f)); - - if (Main.tile[tilesX, tilesY].type == (WorldGen.crimson ? TileID.Crimstone : TileID.Ebonstone)) - { - WorldGenerationMethods.SpecialHut(WorldGen.crimson ? TileID.CrimtaneBrick : TileID.DemoniteBrick, - WorldGen.crimson ? TileID.Crimstone : TileID.Ebonstone, - WorldGen.crimson ? WallID.CrimtaneBrick : WallID.DemoniteBrick, 1, tilesX, tilesY); - break; - } - } - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Cavern Shrine - { - int tilesX = WorldGen.genRand.Next((int)(x * 0.3), generateBack); - int tilesX2 = WorldGen.genRand.Next(generateForward, (int)(x * 0.7)); - int tilesY = WorldGen.genRand.Next((int)(y * 0.55f), (int)(y * 0.8f)); - - if (Main.tile[tilesX, tilesY].type == TileID.Stone) - { - WorldGenerationMethods.SpecialHut(TileID.ObsidianBrick, TileID.Obsidian, WallID.ObsidianBrick, 2, tilesX, tilesY); - break; - } - if (Main.tile[tilesX2, tilesY].type == TileID.Stone) - { - WorldGenerationMethods.SpecialHut(TileID.ObsidianBrick, TileID.Obsidian, WallID.ObsidianBrick, 2, tilesX2, tilesY); - break; - } - } - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Ice Shrine - { - int tilesX = WorldGen.genRand.Next(0, x); - int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); - - if (Main.tile[tilesX, tilesY].type == TileID.IceBlock) - { - WorldGenerationMethods.SpecialHut(TileID.IceBrick, TileID.IceBlock, WallID.IceBrick, 3, tilesX, tilesY); - break; - } - } - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Desert Shrine - { - int tilesX = WorldGen.genRand.Next(0, x); - int tilesY = WorldGen.genRand.Next((int)(y * 0.3f), (int)(y * 0.5f)); - - if (Main.tile[tilesX, tilesY].type == TileID.DesertFossil) - { - WorldGenerationMethods.SpecialHut(TileID.DesertFossil, TileID.Sandstone, WallID.DesertFossil, 4, tilesX, tilesY); - break; - } - } - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Mushroom Shrine - { - int tilesX = WorldGen.genRand.Next(0, x); - int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); - - if (Main.tile[tilesX, tilesY].type == TileID.MushroomGrass) - { - WorldGenerationMethods.SpecialHut(TileID.MushroomBlock, TileID.Mud, WallID.MushroomUnsafe, 5, tilesX, tilesY); - break; - } - } - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Granite Shrine - { - int tilesX = WorldGen.genRand.Next(0, x); - int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); - - if (Main.tile[tilesX, tilesY].type == TileID.Granite) - { - WorldGenerationMethods.SpecialHut(TileID.GraniteBlock, TileID.Granite, WallID.GraniteUnsafe, 6, tilesX, tilesY); - break; - } - } - - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Marble Shrine - { - int tilesX = WorldGen.genRand.Next(0, x); - int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); - - if (Main.tile[tilesX, tilesY].type == TileID.Marble) - { - WorldGenerationMethods.SpecialHut(TileID.MarbleBlock, TileID.Marble, WallID.MarbleUnsafe, 7, tilesX, tilesY); - break; - } - } - } - } -} diff --git a/World/SulphurousSea.cs b/World/SulphurousSea.cs index d1cc3969d1..893443a221 100644 --- a/World/SulphurousSea.cs +++ b/World/SulphurousSea.cs @@ -1,11 +1,13 @@ using CalamityMod.Items; using CalamityMod.Items.Accessories; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.Schematics; using CalamityMod.Tiles.Abyss; using CalamityMod.Walls; using Microsoft.Xna.Framework; using System; using System.Collections.Generic; +using System.Linq; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -13,7 +15,7 @@ using Terraria.World.Generation; namespace CalamityMod.World { - public class SulphurousSea : ModWorld + public class SulphurousSea { #region Fields and Properties public static int BiomeWidth @@ -91,6 +93,7 @@ namespace CalamityMod.World PlaceColumns(); PlaceRustyChests(); CreateBeachNearSea(); + PlaceScrapPiles(); } #endregion @@ -691,7 +694,7 @@ namespace CalamityMod.World SulphSeaTiles.Contains(CalamityUtils.ParanoidTileRetrieval(x, y + 1).type) && CalamityUtils.ParanoidTileRetrieval(x, y + 1).active()) { - chest = WorldGenerationMethods.AddChestWithLoot(x, y, (ushort)ModContent.TileType()); + chest = MiscWorldgenRoutines.AddChestWithLoot(x, y, (ushort)ModContent.TileType()); } } } @@ -837,6 +840,80 @@ namespace CalamityMod.World } #endregion + #region Scrap Piles + public static void PlaceScrapPiles() + { + List pastPlacementPostiion = new List(); + for (int i = 0; i < 3; i++) + { + int x = WorldGen.genRand.Next(75, BiomeWidth - 85); + if (!CalamityWorld.abyssSide) + x = Main.maxTilesX - x; + int y = WorldGen.genRand.Next(YStart + (int)(BlockDepth * 0.3f), YStart + (int)(BlockDepth * 0.8f)); + + Point pilePlacementPosition = new Point(x, y); + + // If the selected position is sitting inside of a tile, try again. + if (WorldGen.SolidTile(pilePlacementPosition.X, pilePlacementPosition.Y)) + { + i--; + continue; + } + + // If the selected position is close to other piles, try again. + if (pastPlacementPostiion.Any(p => Vector2.Distance(p, pilePlacementPosition.ToVector2()) < 85f)) + { + i--; + continue; + } + + // Otherwise, decide which pile should be created. + bool createLargePile = WorldGen.genRand.NextBool(3); + int pileVariant = WorldGen.genRand.Next(4); + string schematicName = $"{(createLargePile ? "Large " : string.Empty)}Sulphurous Scrap {pileVariant + 1}"; + Vector2? wrappedSchematicArea = SchematicManager.GetSchematicArea(schematicName); + + // Create a log message if for some reason the schematic in question doesn't exist. + if (!wrappedSchematicArea.HasValue) + { + CalamityMod.Instance.Logger.Warn($"Tried to place a schematic with name \"{schematicName}\". No matching schematic file found."); + continue; + } + + Vector2 schematicArea = wrappedSchematicArea.Value; + + // Decide the placement position by searching downward and looking for the lowest point. + // If the position is quite steep, try again. + Vector2 left = pilePlacementPosition.ToVector2() - Vector2.UnitX * schematicArea.X * 0.5f; + Vector2 right = pilePlacementPosition.ToVector2() + Vector2.UnitX * schematicArea.X * 0.5f; + while (!WorldGen.SolidTile(CalamityUtils.ParanoidTileRetrieval((int)left.X, (int)left.Y))) + left.Y++; + while (!WorldGen.SolidTile(CalamityUtils.ParanoidTileRetrieval((int)right.X, (int)right.Y))) + right.Y++; + + if (Math.Abs(left.Y - right.Y) >= 20f) + { + i--; + continue; + } + + // If the placement position ended up in the abyss, try again. + if (left.Y >= YStart + BlockDepth + 5 || right.Y >= YStart + BlockDepth + 5) + { + i--; + continue; + } + + // Pick the lowest point vertically. + Point bottomCenter = new Point(pilePlacementPosition.X, (int)Math.Max(left.Y, right.Y) + 6); + bool _ = false; + SchematicManager.PlaceSchematic>(schematicName, bottomCenter, SchematicAnchor.BottomCenter, ref _); + + pastPlacementPostiion.Add(bottomCenter.ToVector2()); + } + } + #endregion Scrap Piles + #region Misc Functions public static List YStartWhitelist = new List() { diff --git a/World/SunkenSea.cs b/World/SunkenSea.cs index 72f0cbac25..271e4536ee 100644 --- a/World/SunkenSea.cs +++ b/World/SunkenSea.cs @@ -9,7 +9,7 @@ using Terraria.World.Generation; namespace CalamityMod.World { - public class SunkenSea : ModWorld + public class SunkenSea { private struct Hub { @@ -537,7 +537,7 @@ namespace CalamityMod.World { if (WorldGen.genRand.Next(5) == 0) { - WorldGenerationMethods.PlaceTit(num5, num6, (ushort)ModContent.TileType()); + PlaceTit(num5, num6, (ushort)ModContent.TileType()); } if (WorldGen.genRand.Next(8) == 0) { @@ -602,5 +602,76 @@ namespace CalamityMod.World } return true; } + + public static void PlaceTit(int x, int y, ushort type = 165) + { + if (Main.tile[x, y - 1] == null) + { + Main.tile[x, y - 1] = new Tile(); + } + if (Main.tile[x, y] == null) + { + Main.tile[x, y] = new Tile(); + } + if (Main.tile[x, y + 1] == null) + { + Main.tile[x, y + 1] = new Tile(); + } + if (WorldGen.SolidTile(x, y - 1) && !Main.tile[x, y].active() && !Main.tile[x, y + 1].active()) + { + if (Main.tile[x, y - 1].type == (ushort)ModContent.TileType()) + { + if (WorldGen.genRand.Next(2) == 0 || Main.tile[x, y + 2].active()) + { + int num2 = WorldGen.genRand.Next(3) * 18; + Main.tile[x, y].type = type; + Main.tile[x, y].active(true); + Main.tile[x, y].frameX = (short)num2; + Main.tile[x, y].frameY = 72; + } + else + { + int num3 = WorldGen.genRand.Next(3) * 18; + Main.tile[x, y].type = type; + Main.tile[x, y].active(true); + Main.tile[x, y].frameX = (short)num3; + Main.tile[x, y].frameY = 0; + Main.tile[x, y + 1].type = type; + Main.tile[x, y + 1].active(true); + Main.tile[x, y + 1].frameX = (short)num3; + Main.tile[x, y + 1].frameY = 18; + } + } + } + else + { + if (WorldGen.SolidTile(x, y + 1) && !Main.tile[x, y].active() && !Main.tile[x, y - 1].active()) + { + if (Main.tile[x, y + 1].type == (ushort)ModContent.TileType()) + { + if (WorldGen.genRand.Next(2) == 0 || Main.tile[x, y - 2].active()) + { + int num13 = WorldGen.genRand.Next(3) * 18; + Main.tile[x, y].type = type; + Main.tile[x, y].active(true); + Main.tile[x, y].frameX = (short)num13; + Main.tile[x, y].frameY = 90; + } + else + { + int num14 = WorldGen.genRand.Next(3) * 18; + Main.tile[x, y - 1].type = type; + Main.tile[x, y - 1].active(true); + Main.tile[x, y - 1].frameX = (short)num14; + Main.tile[x, y - 1].frameY = 36; + Main.tile[x, y].type = type; + Main.tile[x, y].active(true); + Main.tile[x, y].frameX = (short)num14; + Main.tile[x, y].frameY = 54; + } + } + } + } + } } } diff --git a/World/UndergroundShrines.cs b/World/UndergroundShrines.cs new file mode 100644 index 0000000000..933ae2dbaa --- /dev/null +++ b/World/UndergroundShrines.cs @@ -0,0 +1,301 @@ +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Mounts; +using CalamityMod.Items.Placeables.Furniture; +using CalamityMod.Items.SummonItems; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.World +{ + public class UndergroundShrines + { + #region Enumeration + public enum UndergroundShrineType + { + Surface, + Cavern, + WorldEvil, + Ice, + Desert, + Mushroom, + Granite, + Marble, + Abyss + } + #endregion + + #region Hut Outline Creation + + // Special Hut: Takes arguments of tile type 1, tile type 2, wall type, hut type (useful if you use this method to generate different huts), and location of the shrine (x and y) + public static void SpecialHut(ushort tile, ushort tile2, ushort wall, UndergroundShrineType hutType, int shrineLocationX, int shrineLocationY) + { + // Random variables for shrine size + int randomX = WorldGen.genRand.Next(2, 4); + int randomY = WorldGen.genRand.Next(2, 4); + + // Replace tiles in shrine area with shrine tile type 1 + for (int x = shrineLocationX - randomX - 1; x <= shrineLocationX + randomX + 1; x++) + { + for (int y = shrineLocationY - randomY - 1; y <= shrineLocationY + randomY + 1; y++) + { + Main.tile[x, y].active(true); + Main.tile[x, y].type = tile; + Main.tile[x, y].slope(0); + Main.tile[x, y].liquid = 0; + Main.tile[x, y].lava(false); + } + } + + // Replace walls in shrine area with shrine wall type + for (int x = shrineLocationX - randomX; x <= shrineLocationX + randomX; x++) + { + for (int y = shrineLocationY - randomY; y <= shrineLocationY + randomY; y++) + { + Main.tile[x, y].active(false); + Main.tile[x, y].wall = wall; + } + } + + // Remove tiles from the inner part of the shrine area + for (int x = shrineLocationX - randomX - 1; x <= shrineLocationX + randomX + 1; x++) + { + for (int y = shrineLocationY + randomY - 2; y <= shrineLocationY + randomY; y++) + Main.tile[x, y].active(false); + } + for (int x = shrineLocationX - randomX - 1; x <= shrineLocationX + randomX + 1; x++) + { + for (int y = shrineLocationY + randomY - 2; y <= shrineLocationY + randomY - 1; y++) + Main.tile[x, y].active(false); + } + + // Replace tiles from bottom of shrine area with shrine tile type 2 + for (int x = shrineLocationX - randomX - 1; x <= shrineLocationX + randomX + 1; x++) + { + int verticalOffset = 4; + int y = shrineLocationY + randomY + 2; + while (!Main.tile[x, y].active() && y < Main.maxTilesY && verticalOffset > 0) + { + Main.tile[x, y].active(true); + Main.tile[x, y].type = tile2; + Main.tile[x, y].slope(0); + y++; + verticalOffset--; + } + } + + // Replace tiles from top of shrine with shrine tile type 1 + randomX -= WorldGen.genRand.Next(1, 3); + int num21 = shrineLocationY - randomY - 2; + while (randomX > -1) + { + for (int x = shrineLocationX - randomX - 1; x <= shrineLocationX + randomX + 1; x++) + { + Main.tile[x, num21].active(true); + Main.tile[x, num21].type = tile; + } + randomX -= WorldGen.genRand.Next(1, 3); + num21--; + } + + // Place shrine chest + CalamityWorld.SChestX[(int)hutType] = shrineLocationX; + CalamityWorld.SChestY[(int)hutType] = shrineLocationY; + SpecialChest(hutType); + } + #endregion + + #region Chest Creation + // Special Chest: Used for placing shrine chests, takes argument of the shrine type which dictates what item will spawn in the first slot of this chest + public static void SpecialChest(UndergroundShrineType shrineType) + { + int item = 0; + int chestType = 0; + + switch (shrineType) + { + case UndergroundShrineType.Surface: + item = ModContent.ItemType(); + break; + case UndergroundShrineType.Cavern: + item = ModContent.ItemType(); + chestType = 44; + break; + case UndergroundShrineType.WorldEvil: + item = WorldGen.crimson ? ModContent.ItemType() : ModContent.ItemType(); + chestType = WorldGen.crimson ? 43 : 3; + break; + case UndergroundShrineType.Ice: + item = ModContent.ItemType(); + chestType = 47; + break; + case UndergroundShrineType.Desert: + item = ModContent.ItemType(); + chestType = 30; + break; + case UndergroundShrineType.Mushroom: + item = ModContent.ItemType(); + chestType = 32; + break; + case UndergroundShrineType.Granite: + item = ModContent.ItemType(); + chestType = 50; + break; + case UndergroundShrineType.Marble: + item = ModContent.ItemType(); + chestType = 51; + break; + case UndergroundShrineType.Abyss: + item = ModContent.ItemType(); + chestType = 4; + break; + } + + // Destroy tiles in chest spawn location + for (int j = CalamityWorld.SChestX[(int)shrineType] - 1; j <= CalamityWorld.SChestX[(int)shrineType] + 1; j++) + { + for (int k = CalamityWorld.SChestY[(int)shrineType]; k <= CalamityWorld.SChestY[(int)shrineType] + 2; k++) + WorldGen.KillTile(j, k, false, false, false); + } + + // Attempt to fix sloped tiles under the chest to prevent the chest from killing itself (literally) + for (int l = CalamityWorld.SChestX[(int)shrineType] - 1; l <= CalamityWorld.SChestX[(int)shrineType] + 1; l++) + { + for (int m = CalamityWorld.SChestY[(int)shrineType]; m <= CalamityWorld.SChestY[(int)shrineType] + 3; m++) + { + if (m < Main.maxTilesY) + { + Main.tile[l, m].slope(0); + Main.tile[l, m].halfBrick(false); + } + } + } + + // Place the chest, finally + WorldGen.AddBuriedChest(CalamityWorld.SChestX[(int)shrineType], CalamityWorld.SChestY[(int)shrineType], item, false, chestType); + } + #endregion + + #region Direct Gen + public static void PlaceShrines() + { + int x = Main.maxTilesX; + int y = Main.maxTilesY; + int genLimit = x / 2; + int generateBack = genLimit - 80; //Small = 2020 + int generateForward = genLimit + 80; //Small = 2180 + double shrineChance = 100E-05; + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Surface Shrine + { + int tilesX = WorldGen.genRand.Next((int)(x * 0.35), generateBack); + int tilesX2 = WorldGen.genRand.Next(generateForward, (int)(x * 0.65)); + int tilesY = WorldGen.genRand.Next((int)(y * 0.3f), (int)(y * 0.35f)); + + if (Main.tile[tilesX, tilesY].type == TileID.Dirt || Main.tile[tilesX, tilesY].type == TileID.Stone) + { + SpecialHut(TileID.RedBrick, TileID.Dirt, WallID.RedBrick, 0, tilesX, tilesY); + break; + } + if (Main.tile[tilesX2, tilesY].type == TileID.Dirt || Main.tile[tilesX2, tilesY].type == TileID.Stone) + { + SpecialHut(TileID.RedBrick, TileID.Dirt, WallID.RedBrick, 0, tilesX2, tilesY); + break; + } + } + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Evil Shrine + { + int tilesX = WorldGen.genRand.Next(0, x); + int tilesY = WorldGen.genRand.Next((int)(y * 0.3f), (int)(y * 0.35f)); + + if (Main.tile[tilesX, tilesY].type == (WorldGen.crimson ? TileID.Crimstone : TileID.Ebonstone)) + { + SpecialHut(WorldGen.crimson ? TileID.CrimtaneBrick : TileID.DemoniteBrick, + WorldGen.crimson ? TileID.Crimstone : TileID.Ebonstone, + WorldGen.crimson ? WallID.CrimtaneBrick : WallID.DemoniteBrick, UndergroundShrineType.WorldEvil, tilesX, tilesY); + break; + } + } + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Cavern Shrine + { + int tilesX = WorldGen.genRand.Next((int)(x * 0.3), generateBack); + int tilesX2 = WorldGen.genRand.Next(generateForward, (int)(x * 0.7)); + int tilesY = WorldGen.genRand.Next((int)(y * 0.55f), (int)(y * 0.8f)); + + if (Main.tile[tilesX, tilesY].type == TileID.Stone) + { + SpecialHut(TileID.ObsidianBrick, TileID.Obsidian, WallID.ObsidianBrick, UndergroundShrineType.Cavern, tilesX, tilesY); + break; + } + if (Main.tile[tilesX2, tilesY].type == TileID.Stone) + { + SpecialHut(TileID.ObsidianBrick, TileID.Obsidian, WallID.ObsidianBrick, UndergroundShrineType.Cavern, tilesX2, tilesY); + break; + } + } + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Ice Shrine + { + int tilesX = WorldGen.genRand.Next(0, x); + int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); + + if (Main.tile[tilesX, tilesY].type == TileID.IceBlock) + { + SpecialHut(TileID.IceBrick, TileID.IceBlock, WallID.IceBrick, UndergroundShrineType.Ice, tilesX, tilesY); + break; + } + } + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Desert Shrine + { + int tilesX = WorldGen.genRand.Next(0, x); + int tilesY = WorldGen.genRand.Next((int)(y * 0.3f), (int)(y * 0.5f)); + + if (Main.tile[tilesX, tilesY].type == TileID.DesertFossil) + { + SpecialHut(TileID.DesertFossil, TileID.Sandstone, WallID.DesertFossil, UndergroundShrineType.Desert, tilesX, tilesY); + break; + } + } + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Mushroom Shrine + { + int tilesX = WorldGen.genRand.Next(0, x); + int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); + + if (Main.tile[tilesX, tilesY].type == TileID.MushroomGrass) + { + SpecialHut(TileID.MushroomBlock, TileID.Mud, WallID.MushroomUnsafe, UndergroundShrineType.Mushroom, tilesX, tilesY); + break; + } + } + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Granite Shrine + { + int tilesX = WorldGen.genRand.Next(0, x); + int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); + + if (Main.tile[tilesX, tilesY].type == TileID.Granite) + { + SpecialHut(TileID.GraniteBlock, TileID.Granite, WallID.GraniteUnsafe, UndergroundShrineType.Granite, tilesX, tilesY); + break; + } + } + + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Marble Shrine + { + int tilesX = WorldGen.genRand.Next(0, x); + int tilesY = WorldGen.genRand.Next((int)(y * 0.35f), (int)(y * 0.5f)); + + if (Main.tile[tilesX, tilesY].type == TileID.Marble) + { + SpecialHut(TileID.MarbleBlock, TileID.Marble, WallID.MarbleUnsafe, UndergroundShrineType.Marble, tilesX, tilesY); + break; + } + } + } + #endregion + } +} diff --git a/World/WorldEvilIsland.cs b/World/WorldEvilIsland.cs new file mode 100644 index 0000000000..8769c4e4b5 --- /dev/null +++ b/World/WorldEvilIsland.cs @@ -0,0 +1,570 @@ +using CalamityMod.World.Planets; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.World +{ + public class WorldEvilIsland + { + public static void PlaceEvilIsland() + { + int x = Main.maxTilesX; + int xIslandGen; + int yIslandGen; + Rectangle potentialArea; + + do + { + xIslandGen = WorldGen.crimson ? + WorldGen.genRand.Next((int)(x * 0.1), (int)(x * 0.15)) : + WorldGen.genRand.Next((int)(x * 0.85), (int)(x * 0.9)); + yIslandGen = WorldGen.genRand.Next(90, 151); + yIslandGen = Math.Min(yIslandGen, (int)WorldGen.worldSurfaceLow - 50); + + int checkAreaX = 200; + int checkAreaY = 200; + potentialArea = new Rectangle(xIslandGen + checkAreaX / 2, yIslandGen + checkAreaY / 2, checkAreaX, checkAreaY); + } + while (!Planetoid.InvalidSkyPlacementArea(potentialArea)); + + int tileXLookup = xIslandGen; + if (WorldGen.crimson) + { + while (Main.tile[tileXLookup, yIslandGen].active()) + tileXLookup++; + } + else + { + while (Main.tile[tileXLookup, yIslandGen].active()) + tileXLookup--; + } + + xIslandGen = tileXLookup; + CalamityWorld.fehX = xIslandGen; + CalamityWorld.fehY = yIslandGen; + EvilIsland(xIslandGen, yIslandGen); + EvilIslandHouse(CalamityWorld.fehX, CalamityWorld.fehY); + } + + public static void EvilIsland(int i, int j) + { + double num = (double)WorldGen.genRand.Next(100, 150); + float num2 = (float)WorldGen.genRand.Next(20, 30); + int num3 = i; + int num4 = i; + int num5 = i; + int num6 = j; + Vector2 vector; + vector.X = (float)i; + vector.Y = (float)j; + Vector2 vector2; + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + while (vector2.X > -2f && vector2.X < 2f) + { + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + } + vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; + while (num > 0.0 && num2 > 0f) + { + num -= (double)WorldGen.genRand.Next(4); + num2 -= 1f; + int num7 = (int)((double)vector.X - num * 0.5); + int num8 = (int)((double)vector.X + num * 0.5); + int num9 = (int)((double)vector.Y - num * 0.5); + int num10 = (int)((double)vector.Y + num * 0.5); + if (num7 < 0) + { + num7 = 0; + } + if (num8 > Main.maxTilesX) + { + num8 = Main.maxTilesX; + } + if (num9 < 0) + { + num9 = 0; + } + if (num10 > Main.maxTilesY) + { + num10 = Main.maxTilesY; + } + double num11 = num * (double)WorldGen.genRand.Next(80, 120) * 0.01; //80 120 + float num12 = vector.Y + 1f; + for (int k = num7; k < num8; k++) + { + if (WorldGen.genRand.Next(2) == 0) + { + num12 += (float)WorldGen.genRand.Next(-1, 2); + } + if (num12 < vector.Y) + { + num12 = vector.Y; + } + if (num12 > vector.Y + 2f) + { + num12 = vector.Y + 2f; + } + for (int l = num9; l < num10; l++) + { + if ((float)l > num12) + { + float arg_218_0 = Math.Abs((float)k - vector.X); + float num13 = Math.Abs((float)l - vector.Y) * 3f; + if (Math.Sqrt((double)(arg_218_0 * arg_218_0 + num13 * num13)) < num11 * 0.4) + { + if (k < num3) + { + num3 = k; + } + if (k > num4) + { + num4 = k; + } + if (l < num5) + { + num5 = l; + } + if (l > num6) + { + num6 = l; + } + Main.tile[k, l].active(true); + Main.tile[k, l].type = (ushort)(WorldGen.crimson ? 400 : 401); //ebonstone or crimstone + WorldGen.SquareTileFrame(k, l, true); + } + } + } + } + vector += vector2; + vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; + if (vector2.X > 1f) + { + vector2.X = 1f; + } + if (vector2.X < -1f) + { + vector2.X = -1f; + } + if ((double)vector2.Y > 0.2) + { + vector2.Y = -0.2f; + } + if ((double)vector2.Y < -0.2) + { + vector2.Y = -0.2f; + } + } + int m = num3; + int num15; + for (m += WorldGen.genRand.Next(5); m < num4; m += WorldGen.genRand.Next(num15, (int)((double)num15 * 1.5))) + { + int num14 = num6; + while (!Main.tile[m, num14].active()) + { + num14--; + } + num14 += WorldGen.genRand.Next(-3, 4); + num15 = WorldGen.genRand.Next(4, 8); + int num16 = WorldGen.crimson ? 400 : 401; + if (WorldGen.genRand.Next(4) == 0) + { + num16 = WorldGen.crimson ? 398 : 399; + } + for (int n = m - num15; n <= m + num15; n++) + { + for (int num17 = num14 - num15; num17 <= num14 + num15; num17++) + { + if (num17 > num5) + { + float arg_409_0 = (float)Math.Abs(n - m); + float num18 = (float)(Math.Abs(num17 - num14) * 2); + if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num15 + WorldGen.genRand.Next(2))) + { + Main.tile[n, num17].active(true); + Main.tile[n, num17].type = (ushort)num16; + WorldGen.SquareTileFrame(n, num17, true); + } + } + } + } + } + num = (double)WorldGen.genRand.Next(80, 95); + num2 = (float)WorldGen.genRand.Next(10, 15); + vector.X = (float)i; + vector.Y = (float)num5; + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + while (vector2.X > -2f && vector2.X < 2f) + { + vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; + } + vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; + while (num > 0.0 && num2 > 0f) + { + num -= (double)WorldGen.genRand.Next(4); + num2 -= 1f; + int num7 = (int)((double)vector.X - num * 0.5); + int num8 = (int)((double)vector.X + num * 0.5); + int num9 = num5 - 1; + int num10 = (int)((double)vector.Y + num * 0.5); + if (num7 < 0) + { + num7 = 0; + } + if (num8 > Main.maxTilesX) + { + num8 = Main.maxTilesX; + } + if (num9 < 0) + { + num9 = 0; + } + if (num10 > Main.maxTilesY) + { + num10 = Main.maxTilesY; + } + double num11 = num * (double)WorldGen.genRand.Next(80, 120) * 0.01; + float num19 = vector.Y + 1f; + for (int num20 = num7; num20 < num8; num20++) + { + if (WorldGen.genRand.Next(2) == 0) + { + num19 += (float)WorldGen.genRand.Next(-1, 2); + } + if (num19 < vector.Y) + { + num19 = vector.Y; + } + if (num19 > vector.Y + 2f) + { + num19 = vector.Y + 2f; + } + for (int num21 = num9; num21 < num10; num21++) + { + if ((float)num21 > num19) + { + float arg_69E_0 = Math.Abs((float)num20 - vector.X); + float num22 = Math.Abs((float)num21 - vector.Y) * 3f; + if (Math.Sqrt((double)(arg_69E_0 * arg_69E_0 + num22 * num22)) < num11 * 0.4 && + Main.tile[num20, num21].type == (WorldGen.crimson ? 400 : 401)) + { + Main.tile[num20, num21].type = (ushort)(WorldGen.crimson ? 22 : 204); //ore + WorldGen.SquareTileFrame(num20, num21, true); + } + } + } + } + vector += vector2; + vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; + if (vector2.X > 1f) + { + vector2.X = 1f; + } + if (vector2.X < -1f) + { + vector2.X = -1f; + } + if ((double)vector2.Y > 0.2) + { + vector2.Y = -0.2f; + } + if ((double)vector2.Y < -0.2) + { + vector2.Y = -0.2f; + } + } + int num23 = num3; + num23 += WorldGen.genRand.Next(5); + while (num23 < num4) + { + int num24 = num6; + while ((!Main.tile[num23, num24].active() || Main.tile[num23, num24].type != 0) && num23 < num4) + { + num24--; + if (num24 < num5) + { + num24 = num6; + num23 += WorldGen.genRand.Next(1, 4); + } + } + if (num23 < num4) + { + num24 += WorldGen.genRand.Next(0, 4); + int num25 = WorldGen.genRand.Next(2, 5); + int num26 = WorldGen.crimson ? 400 : 401; + for (int num27 = num23 - num25; num27 <= num23 + num25; num27++) + { + for (int num28 = num24 - num25; num28 <= num24 + num25; num28++) + { + if (num28 > num5) + { + float arg_890_0 = (float)Math.Abs(num27 - num23); + float num29 = (float)(Math.Abs(num28 - num24) * 2); + if (Math.Sqrt((double)(arg_890_0 * arg_890_0 + num29 * num29)) < (double)num25) + { + Main.tile[num27, num28].type = (ushort)num26; + WorldGen.SquareTileFrame(num27, num28, true); + } + } + } + } + num23 += WorldGen.genRand.Next(num25, (int)((double)num25 * 1.5)); + } + } + for (int num30 = num3 - 20; num30 <= num4 + 20; num30++) + { + for (int num31 = num5 - 20; num31 <= num6 + 20; num31++) + { + bool flag = true; + for (int num32 = num30 - 1; num32 <= num30 + 1; num32++) + { + for (int num33 = num31 - 1; num33 <= num31 + 1; num33++) + { + if (!Main.tile[num32, num33].active()) + { + flag = false; + } + } + } + if (flag) + { + Main.tile[num30, num31].wall = (ushort)(WorldGen.crimson ? 220 : 221); + WorldGen.SquareWallFrame(num30, num31, true); + } + } + } + for (int num34 = num3; num34 <= num4; num34++) + { + int num35 = num5 - 10; + while (!Main.tile[num34, num35 + 1].active()) + { + num35++; + } + if (num35 < num6 && Main.tile[num34, num35 + 1].type == (WorldGen.crimson ? 400 : 401)) + { + if (WorldGen.genRand.Next(10) == 0) + { + int num36 = WorldGen.genRand.Next(1, 3); + for (int num37 = num34 - num36; num37 <= num34 + num36; num37++) + { + if (Main.tile[num37, num35].type == (WorldGen.crimson ? 400 : 401)) + { + Main.tile[num37, num35].active(false); + Main.tile[num37, num35].liquid = 255; + Main.tile[num37, num35].lava(false); + WorldGen.SquareTileFrame(num34, num35, true); + } + if (Main.tile[num37, num35 + 1].type == (WorldGen.crimson ? 400 : 401)) + { + Main.tile[num37, num35 + 1].active(false); + Main.tile[num37, num35 + 1].liquid = 255; + Main.tile[num37, num35 + 1].lava(false); + WorldGen.SquareTileFrame(num34, num35 + 1, true); + } + if (num37 > num34 - num36 && num37 < num34 + 2 && Main.tile[num37, num35 + 2].type == (WorldGen.crimson ? 400 : 401)) + { + Main.tile[num37, num35 + 2].active(false); + Main.tile[num37, num35 + 2].liquid = 255; + Main.tile[num37, num35 + 2].lava(false); + WorldGen.SquareTileFrame(num34, num35 + 2, true); + } + } + } + if (WorldGen.genRand.Next(5) == 0) + { + Main.tile[num34, num35].liquid = 255; + } + Main.tile[num34, num35].lava(false); + WorldGen.SquareTileFrame(num34, num35, true); + } + } + int num38 = WorldGen.genRand.Next(4); + for (int num39 = 0; num39 <= num38; num39++) + { + int num40 = WorldGen.genRand.Next(num3 - 5, num4 + 5); + int num41 = num5 - WorldGen.genRand.Next(20, 40); + int num42 = WorldGen.genRand.Next(4, 8); + int num43 = WorldGen.crimson ? 400 : 401; + if (WorldGen.genRand.Next(2) == 0) + { + num43 = WorldGen.crimson ? 398 : 399; + } + for (int num44 = num40 - num42; num44 <= num40 + num42; num44++) + { + for (int num45 = num41 - num42; num45 <= num41 + num42; num45++) + { + float arg_C74_0 = (float)Math.Abs(num44 - num40); + float num46 = (float)(Math.Abs(num45 - num41) * 2); + if (Math.Sqrt((double)(arg_C74_0 * arg_C74_0 + num46 * num46)) < (double)(num42 + WorldGen.genRand.Next(-1, 2))) + { + Main.tile[num44, num45].active(true); + Main.tile[num44, num45].type = (ushort)num43; + WorldGen.SquareTileFrame(num44, num45, true); + } + } + } + for (int num47 = num40 - num42 + 2; num47 <= num40 + num42 - 2; num47++) + { + int num48 = num41 - num42; + while (!Main.tile[num47, num48].active()) + { + num48++; + } + Main.tile[num47, num48].active(false); + Main.tile[num47, num48].liquid = 255; + WorldGen.SquareTileFrame(num47, num48, true); + } + } + } + + public static void EvilIslandHouse(int i, int j) + { + ushort type = (ushort)(WorldGen.crimson ? 152 : 347); //tile + byte wall = (byte)(WorldGen.crimson ? 35 : 174); //wall + Vector2 vector = new Vector2((float)i, (float)j); + int num = 1; + if (WorldGen.genRand.Next(2) == 0) + { + num = -1; + } + int num2 = WorldGen.genRand.Next(7, 12); + int num3 = WorldGen.genRand.Next(5, 7); + vector.X = (float)(i + (num2 + 2) * num); + for (int k = j - 15; k < j + 30; k++) + { + if (Main.tile[(int)vector.X, k].active()) + { + vector.Y = (float)(k - 1); + break; + } + } + vector.X = (float)i; + int num4 = (int)(vector.X - (float)num2 - 1f); + int num5 = (int)(vector.X + (float)num2 + 1f); + int num6 = (int)(vector.Y - (float)num3 - 1f); + int num7 = (int)(vector.Y + 2f); + if (num4 < 0) + { + num4 = 0; + } + if (num5 > Main.maxTilesX) + { + num5 = Main.maxTilesX; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int l = num4; l <= num5; l++) + { + for (int m = num6 - 1; m < num7 + 1; m++) + { + if (m != num6 - 1 || (l != num4 && l != num5)) + { + Main.tile[l, m].active(true); + Main.tile[l, m].liquid = 0; + Main.tile[l, m].type = type; + Main.tile[l, m].wall = 0; + Main.tile[l, m].halfBrick(false); + Main.tile[l, m].slope(0); + } + } + } + num4 = (int)(vector.X - (float)num2); + num5 = (int)(vector.X + (float)num2); + num6 = (int)(vector.Y - (float)num3); + num7 = (int)(vector.Y + 1f); + if (num4 < 0) + { + num4 = 0; + } + if (num5 > Main.maxTilesX) + { + num5 = Main.maxTilesX; + } + if (num6 < 0) + { + num6 = 0; + } + if (num7 > Main.maxTilesY) + { + num7 = Main.maxTilesY; + } + for (int n = num4; n <= num5; n++) + { + for (int num8 = num6; num8 < num7; num8++) + { + if ((num8 != num6 || (n != num4 && n != num5)) && Main.tile[n, num8].wall == 0) + { + Main.tile[n, num8].active(false); + Main.tile[n, num8].wall = wall; + } + } + } + int num9 = i + (num2 + 1) * num; + int num10 = (int)vector.Y; + for (int num11 = num9 - 2; num11 <= num9 + 2; num11++) + { + Main.tile[num11, num10].active(false); + Main.tile[num11, num10 - 1].active(false); + Main.tile[num11, num10 - 2].active(false); + } + WorldGen.PlaceTile(num9, num10, 10, true, false, -1, WorldGen.crimson ? 1 : 10); //door + num9 = i + (num2 + 1) * -num - num; + for (int num12 = num6; num12 <= num7 + 1; num12++) + { + Main.tile[num9, num12].active(true); + Main.tile[num9, num12].liquid = 0; + Main.tile[num9, num12].type = type; + Main.tile[num9, num12].wall = 0; + Main.tile[num9, num12].halfBrick(false); + Main.tile[num9, num12].slope(0); + } + int contain; + if (WorldGen.crimson) + { + contain = 1571; //scourge + } + else + { + contain = 1569; //vampire + } + WorldGen.AddBuriedChest(i, num10 - 3, contain, false, WorldGen.crimson ? 19 : 20); //chest + int num14 = i - num2 / 2 + 1; + int num15 = i + num2 / 2 - 1; + int num16 = 1; + if (num2 > 10) + { + num16 = 2; + } + int num17 = (num6 + num7) / 2 - 1; + for (int num18 = num14 - num16; num18 <= num14 + num16; num18++) + { + for (int num19 = num17 - 1; num19 <= num17 + 1; num19++) + { + Main.tile[num18, num19].wall = 21; //glass + } + } + for (int num20 = num15 - num16; num20 <= num15 + num16; num20++) + { + for (int num21 = num17 - 1; num21 <= num17 + 1; num21++) + { + Main.tile[num20, num21].wall = 21; //glass + } + } + int num22 = i + (num2 / 2 + 1) * -num; + WorldGen.PlaceTile(num22, num7 - 1, 14, true, false, -1, WorldGen.crimson ? 1 : 8); //table + WorldGen.PlaceTile(num22 - 2, num7 - 1, 15, true, false, 0, WorldGen.crimson ? 2 : 11); //chair + Tile tile = Main.tile[num22 - 2, num7 - 1]; + tile.frameX += 18; + Tile tile2 = Main.tile[num22 - 2, num7 - 2]; + tile2.frameX += 18; + WorldGen.PlaceTile(num22 + 2, num7 - 1, 15, true, false, 0, WorldGen.crimson ? 2 : 11); //chair + } + } +} diff --git a/World/WorldGenerationMethods.cs b/World/WorldGenerationMethods.cs deleted file mode 100644 index 48f76bfa7e..0000000000 --- a/World/WorldGenerationMethods.cs +++ /dev/null @@ -1,3368 +0,0 @@ -using CalamityMod.Items.Accessories; -using CalamityMod.Items.Materials; -using CalamityMod.Items.Mounts; -using CalamityMod.Items.Pets; -using CalamityMod.Items.Placeables.Furniture; -using CalamityMod.Items.Potions; -using CalamityMod.Items.SummonItems; -using CalamityMod.Items.Tools.ClimateChange; -using CalamityMod.Items.Weapons.Magic; -using CalamityMod.Items.Weapons.Melee; -using CalamityMod.Items.Weapons.Ranged; -using CalamityMod.Items.Weapons.Rogue; -using CalamityMod.Items.Weapons.Summon; -using CalamityMod.Schematics; -using CalamityMod.Tiles; -using CalamityMod.Tiles.Abyss; -using CalamityMod.Tiles.Astral; -using CalamityMod.Tiles.AstralDesert; -using CalamityMod.Tiles.AstralSnow; -using CalamityMod.Tiles.Crags; -using CalamityMod.Tiles.FurnitureAncient; -using CalamityMod.Tiles.Ores; -using CalamityMod.Tiles.SunkenSea; -using CalamityMod.Walls; -using CalamityMod.World.Planets; -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Terraria; -using Terraria.ID; -using Terraria.Localization; -using Terraria.ModLoader; -using Terraria.Utilities; -using Terraria.World.Generation; - -namespace CalamityMod.World -{ - public class WorldGenerationMethods : ModWorld - { - #region Dungeon Biome Chests - public static void GenerateBiomeChests(GenerationProgress progress) - { - progress.Message = "Calamity Mod: Biome Chests"; - - // Get dungeon size field infos. These fields are private for some reason - int MinX = (int)typeof(WorldGen).GetField("dMinX", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) + 25; - int MaxX = (int)typeof(WorldGen).GetField("dMaxX", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) - 25; - int MaxY = (int)typeof(WorldGen).GetField("dMaxY", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) - 25; - - int[] ChestTypes = { ModContent.TileType() }; - int[] ItemTypes = { ModContent.ItemType() }; - int[] ChestStyles = { 1 }; // Astral Chest generates in style 1, which is locked - - for (int i = 0; i < ChestTypes.Length; ++i) - { - Chest chest = null; - int attempts = 0; - - // Try 1000 times to place the chest somewhere in the dungeon. - // The placement algorithm ensures that if it tries to appear in midair, it is moved down to the floor. - while (chest == null && attempts < 1000) - { - attempts++; - int x = WorldGen.genRand.Next(MinX, MaxX); - int y = WorldGen.genRand.Next((int)Main.worldSurface, MaxY); - if (Main.wallDungeon[Main.tile[x, y].wall] && !Main.tile[x, y].active()) - chest = AddChestWithLoot(x, y, (ushort)ChestTypes[i], tileStyle: ChestStyles[i]); - } - - // If a chest was placed, force its first item to be the unique Biome Chest weapon. - if (chest != null) - { - chest.item[0].SetDefaults(ItemTypes[i]); - chest.item[0].Prefix(-1); - } - } - } - - internal static Chest AddChestWithLoot(int i, int j, ushort type = TileID.Containers, uint startingSlot = 1, int tileStyle = 0) - { - int chestIndex = -1; - - // Slide downwards on the Y axis trying to find the floor beneath the empty position initially picked - while (j < Main.maxTilesY - 210) - { - if (!WorldGen.SolidTile(i, j)) - { - j++; - continue; - } - - // If there are already 1,000 chests in the world and this one fails to place, just give up. - chestIndex = WorldGen.PlaceChest(i - 1, j - 1, type, false, tileStyle); - break; - } - - if (chestIndex < 0) - return null; - Chest chest = Main.chest[chestIndex]; - PlaceLootInChest(ref chest, type, startingSlot); - return chest; - } - - internal static void PlaceLootInChest(ref Chest chest, ushort type, uint startingSlot) - { - uint itemIndex = startingSlot; - - void PutItemInChest(ref Chest c, int id, int minQuantity = 0, int maxQuantity = 0, bool condition = true) - { - if (!condition) - return; - c.item[itemIndex].SetDefaults(id, false); - - // Don't set quantity unless quantity is specified - if(minQuantity > 0) - { - // Max quantity cannot be less than min quantity. It's zero if not specified, meaning you get exactly minQuantity. - if (maxQuantity < minQuantity) - maxQuantity = minQuantity; - c.item[itemIndex].stack = WorldGen.genRand.Next(minQuantity, maxQuantity + 1); - } - itemIndex++; - } - - // Astral Chest has completely different loot in it - if (type == ModContent.TileType()) - { - PutItemInChest(ref chest, ModContent.ItemType(), 30, 80); - PutItemInChest(ref chest, ModContent.ItemType(), 10, 14); - PutItemInChest(ref chest, ModContent.ItemType(), 8); - PutItemInChest(ref chest, ModContent.ItemType(), 3, 5); - PutItemInChest(ref chest, ItemID.FallenStar, 12, 30); - - // Gold Coins don't stack above 100, so this efficiently lets you stuff over a platinum into a chest - int goldCoins = WorldGen.genRand.Next(30, 120); - if (goldCoins > 100) - { - PutItemInChest(ref chest, ItemID.PlatinumCoin); - goldCoins -= 100; - } - PutItemInChest(ref chest, ItemID.GoldCoin, goldCoins); - } - else if (type == ModContent.TileType()) - { - // 15-29 torches (in accordence with vanilla) - PutItemInChest(ref chest, ItemID.Torch, 15, 29); - - // 50% chance of 1 or 2 of the following potions - int[] potions = new int[] - { - ModContent.ItemType(), ItemID.WaterWalkingPotion, ItemID.ShinePotion, ItemID.GillsPotion, ItemID.FlipperPotion - }; - PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); - PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); - - // 33% chance of flippers - PutItemInChest(ref chest, ItemID.Flipper, condition: WorldGen.genRand.NextBool(3)); - - // Typical coins - PutItemInChest(ref chest, ItemID.GoldCoin, 2, 4); - } - // Default loot - else - { - // Silver, Tungsten, Gold or Platinum bars (following worldgen choice) - int barID = WorldGen.genRand.NextBool() ? WorldGen.goldBar : WorldGen.silverBar; - PutItemInChest(ref chest, barID, 3, 10); - - // 50% chance of 25-50 Holy Arrows - PutItemInChest(ref chest, ItemID.HolyArrow, 25, 50, WorldGen.genRand.NextBool()); - - // 50% chance of 1 or 2 of the following potions - int[] potions = new int[] { - ItemID.SpelunkerPotion, ItemID.FeatherfallPotion, ItemID.NightOwlPotion, - ItemID.WaterWalkingPotion, ItemID.ArcheryPotion, ItemID.GravitationPotion - }; - PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); - - // 50% chance of 1 or 2 of the following potions - // Yes, in vanilla, Dangersense Potions have double the chance to appear. - potions = new int[] { - ItemID.ThornsPotion, ItemID.WaterWalkingPotion, ItemID.InvisibilityPotion, - ItemID.ManaRegenerationPotion, ItemID.TeleportationPotion, ItemID.TrapsightPotion, ItemID.TrapsightPotion - }; - - PutItemInChest(ref chest, WorldGen.genRand.Next(potions), 1, 2, WorldGen.genRand.NextBool()); - PutItemInChest(ref chest, ItemID.RecallPotion, 1, 2, WorldGen.genRand.NextBool()); - PutItemInChest(ref chest, ItemID.GoldCoin, 1, 2); - } - } - #endregion - - #region Place Rox Shrine - public static void PlaceRoxShrine() - { - while (!CalamityWorld.roxShrinePlaced) - { - CalamityWorld.roxShrinePlaced = true; - for (int x = 0; x < Main.maxTilesX; x++) - { - for (int y = 0; y < Main.maxTilesY; y++) - { - if (Main.tile[x, y] != null && Main.tile[x, y].type == TileID.LargePiles) - { - if ((Main.tile[x, y].frameX == 18 && Main.tile[x, y].frameY == 0) || (Main.tile[x, y].frameX == 45 && Main.tile[x, y].frameY == 0)) - { - if (WorldGen.genRand.Next(3) == 0) - { - for (int dx = -1; dx < 2; dx++) - { - for (int dy = -1; dy < 2; dy++) - Main.tile[x + dx, y + dy].active(false); - } - - WorldGen.PlaceTile(x, y + 1, ModContent.TileType()); - return; - } - else - CalamityWorld.roxShrinePlaced = false; - } - } - } - } - } - } - #endregion - - #region OreSpawn - public static void SpawnOre(int type, double frequency, float depth, float depthLimit) - { - int x = Main.maxTilesX; - int y = Main.maxTilesY; - if (Main.netMode != NetmodeID.MultiplayerClient) - { - for (int k = 0; k < (int)(x * y * frequency); k++) - { - int tilesX = WorldGen.genRand.Next(0, x); - int tilesY = WorldGen.genRand.Next((int)(y * depth), (int)(y * depthLimit)); - if (type == ModContent.TileType()) - { - WorldGen.OreRunner(tilesX, tilesY, WorldGen.genRand.Next(6, 12), WorldGen.genRand.Next(6, 12), (ushort)type); - } - else if (type == ModContent.TileType()) - { - if (Main.tile[tilesX, tilesY].type == TileID.Mud) - { - WorldGen.OreRunner(tilesX, tilesY, WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(3, 8), (ushort)type); - } - } - else if (type == ModContent.TileType() || type == TileID.LunarOre) - { - if (Main.tile[tilesX, tilesY].type == TileID.Dirt || Main.tile[tilesX, tilesY].type == TileID.Stone) - { - WorldGen.OreRunner(tilesX, tilesY, WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(3, 8), (ushort)type); - } - } - else if (type == ModContent.TileType()) - { - if (Main.tile[tilesX, tilesY].type == TileID.SnowBlock || Main.tile[tilesX, tilesY].type == TileID.IceBlock || Main.tile[tilesX, tilesY].type == TileID.CorruptIce || Main.tile[tilesX, tilesY].type == TileID.HallowedIce || Main.tile[tilesX, tilesY].type == TileID.FleshIce || Main.tile[tilesX, tilesY].type == ModContent.TileType() || Main.tile[tilesX, tilesY].type == ModContent.TileType()) - { - WorldGen.OreRunner(tilesX, tilesY, WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(3, 8), (ushort)type); - } - } - else if (type == ModContent.TileType()) - { - if (Main.tile[tilesX, tilesY].type == TileID.Pearlstone || Main.tile[tilesX, tilesY].type == TileID.HallowHardenedSand || Main.tile[tilesX, tilesY].type == TileID.HallowSandstone || Main.tile[tilesX, tilesY].type == TileID.HallowedIce) - { - WorldGen.OreRunner(tilesX, tilesY, WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(3, 8), (ushort)type); - } - } - else - { - WorldGen.OreRunner(tilesX, tilesY, WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(3, 8), (ushort)type); - } - } - } - } - #endregion - - #region AstralMeteor - public static bool CanAstralMeteorSpawn() - { - int astralOreCount = 0; - float worldSizeFactor = Main.maxTilesX / 4200f; // Small = 4200, Medium = 6400, Large = 8400 - int astralOreAllowed = (int)(200f * worldSizeFactor); // Small = 201 Medium = 305 Large = 401 - for (int x = 5; x < Main.maxTilesX - 5; x++) - { - int y = 5; - while (y < Main.worldSurface) - { - if (Main.tile[x, y].active() && Main.tile[x, y].type == ModContent.TileType()) - { - astralOreCount++; - if (astralOreCount > astralOreAllowed) - return false; - } - y++; - } - } - return true; - } - - public static bool CanAstralBiomeSpawn() - { - int astralTileCount = 0; - float worldSizeFactor = Main.maxTilesX / 4200f; // Small = 4200, Medium = 6400, Large = 8400 - int astralTilesAllowed = (int)(400f * worldSizeFactor); // Small = 401 Medium = 605 Large = 801 - for (int x = 5; x < Main.maxTilesX - 5; x++) - { - int y = 5; - while (y < Main.worldSurface) - { - if (Main.tile[x, y].active() && - (Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || - Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || - Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || - Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || - Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || - Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType())) - { - astralTileCount++; - if (astralTileCount > astralTilesAllowed) - return false; - } - y++; - } - } - return true; - } - - public static void AstralMeteorThreadWrapper(object context) - { - PlaceAstralMeteor(); - } - - public static void PlaceAstralMeteor() - { - Mod ancientsAwakened = CalamityMod.Instance.ancientsAwakened; - - // This flag is also used to determine whether players are nearby. - bool meteorDropped = true; - - // Clients in multiplayer don't drop meteors. - if (Main.netMode == NetmodeID.MultiplayerClient) - return; - for (int i = 0; i < 255; i++) - { - if (Main.player[i].active) - { - meteorDropped = false; - break; - } - } - - // Check whether there is already too much ore. - if (!CanAstralMeteorSpawn()) - return; - - UnifiedRandom rand = WorldGen.genRand; - float solidTileRequirement = 600f; - bool localAbyssSide = WorldGen.dungeonX < Main.maxTilesX / 2; - while (!meteorDropped) - { - float worldEdgeMargin = (float)Main.maxTilesX * 0.08f; - int xLimit = Main.maxTilesX / 2; - int x = CalamityWorld.abyssSide ? rand.Next(400, xLimit) : rand.Next(xLimit, Main.maxTilesX - 400); - while ((float)x > (float)Main.spawnTileX - worldEdgeMargin && (float)x < (float)Main.spawnTileX + worldEdgeMargin) - { - x = CalamityWorld.abyssSide ? rand.Next(400, xLimit) : rand.Next(xLimit, Main.maxTilesX - 400); - } - //world surface = 920 large 740 medium 560 small - int y = (int)(Main.worldSurface * 0.5); //Large = 522, Medium = 444, Small = 336 - while (y < Main.maxTilesY) - { - if (Main.tile[x, y].active() && Main.tileSolid[(int)Main.tile[x, y].type]) - { - int suitableTiles = 0; - int checkRadius = 15; - for (int l = x - checkRadius; l < x + checkRadius; l++) - { - for (int m = y - checkRadius; m < y + checkRadius; m++) - { - if (WorldGen.SolidTile(l, m)) - { - suitableTiles++; - - // Avoid floating islands: Clouds and Sunplate both harshly punish attempted meteor spawns - if (Main.tile[l, m].type == TileID.Cloud || Main.tile[l, m].type == TileID.Sunplate) - { - suitableTiles -= 100; - } - // Avoid Sulphurous Sea beach: Cannot be converted by astral - else if (Main.tile[l, m].type == ModContent.TileType() || Main.tile[l, m].type == ModContent.TileType()) - { - suitableTiles -= 100; - } - - // Prevent the Astral biome from overriding or interfering with an AA biome - else if (ancientsAwakened != null) - { - if (Main.tile[l, m].type == ancientsAwakened.TileType("InfernoGrass") || Main.tile[l, m].type == ancientsAwakened.TileType("Torchstone") || - Main.tile[l, m].type == ancientsAwakened.TileType("Torchsand") || Main.tile[l, m].type == ancientsAwakened.TileType("Torchsandstone") || - Main.tile[l, m].type == ancientsAwakened.TileType("Torchsandhardened") || Main.tile[l, m].type == ancientsAwakened.TileType("Torchice") || - Main.tile[l, m].type == ancientsAwakened.TileType("Depthstone") || Main.tile[l, m].type == ancientsAwakened.TileType("Depthsand") || - Main.tile[l, m].type == ancientsAwakened.TileType("Depthsandstone") || Main.tile[l, m].type == ancientsAwakened.TileType("Depthsandhardened") || - Main.tile[l, m].type == ancientsAwakened.TileType("Depthice")) - { - suitableTiles -= 100; - } - } - } - - // Liquid aversion makes meteors less likely to fall in lakes - else if (Main.tile[l, m].liquid > 0) - { - suitableTiles--; - } - } - } - - if ((float)suitableTiles < solidTileRequirement) - { - solidTileRequirement -= 0.5f; - break; - } - meteorDropped = GenerateAstralMeteor(x, y); - - // If the meteor actually dropped, post the message stating as such. - if (meteorDropped) - { - string key = "Mods.CalamityMod.AstralText"; - Color messageColor = Color.Gold; - - CalamityUtils.DisplayLocalizedText(key, messageColor); - break; - } - break; - } - else - { - y++; - } - } - if (solidTileRequirement < 100f) - { - return; - } - } - } - - public static bool GenerateAstralMeteor(int i, int j) - { - UnifiedRandom rand = WorldGen.genRand; - if (i < 50 || i > Main.maxTilesX - 50) - { - return false; - } - // Avoid the dungeon so that the beacon doesn't eat it. - if (Math.Abs(i - WorldGen.dungeonX) < 65) - { - return false; - } - if (j < 50 || j > Main.maxTilesY - 50) - { - return false; - } - int num = 35; - Rectangle rectangle = new Rectangle((i - num) * 16, (j - num) * 16, num * 2 * 16, num * 2 * 16); - for (int k = 0; k < 255; k++) - { - if (Main.player[k].active) - { - Rectangle value = new Rectangle((int)(Main.player[k].position.X + (float)(Main.player[k].width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.player[k].position.Y + (float)(Main.player[k].height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); - if (rectangle.Intersects(value)) - { - return false; - } - } - } - for (int l = 0; l < 200; l++) - { - if (Main.npc[l].active) - { - Rectangle value2 = new Rectangle((int)Main.npc[l].position.X, (int)Main.npc[l].position.Y, Main.npc[l].width, Main.npc[l].height); - if (rectangle.Intersects(value2)) - { - return false; - } - } - } - for (int m = i - num; m < i + num; m++) - { - for (int n = j - num; n < j + num; n++) - { - if (Main.tile[m, n].active() && Main.tile[m, n].type == 21) - { - return false; - } - } - } - num = rand.Next(17, 23); - for (int num2 = i - num; num2 < i + num; num2++) - { - for (int num3 = j - num; num3 < j + num; num3++) - { - if (num3 > j + rand.Next(-2, 3) - 5) - { - float num4 = (float)Math.Abs(i - num2); - float num5 = (float)Math.Abs(j - num3); - float num6 = (float)Math.Sqrt((double)(num4 * num4 + num5 * num5)); - if ((double)num6 < (double)num * 0.9 + (double)rand.Next(-4, 5)) - { - if (Main.tile[num2, num3] != null) - { - if (!Main.tileSolid[(int)Main.tile[num2, num3].type]) - { - Main.tile[num2, num3].active(false); - } - Main.tile[num2, num3].type = (ushort)ModContent.TileType(); - } - } - } - } - } - num = WorldGen.genRand.Next(8, 14); - for (int num7 = i - num; num7 < i + num; num7++) - { - for (int num8 = j - num; num8 < j + num; num8++) - { - if (num8 > j + rand.Next(-2, 3) - 4) - { - float num9 = (float)Math.Abs(i - num7); - float num10 = (float)Math.Abs(j - num8); - float num11 = (float)Math.Sqrt((double)(num9 * num9 + num10 * num10)); - if ((double)num11 < (double)num * 0.8 + (double)rand.Next(-3, 4)) - { - if (Main.tile[num7, num8] != null) - Main.tile[num7, num8].active(false); - } - } - } - } - num = WorldGen.genRand.Next(25, 35); - for (int num12 = i - num; num12 < i + num; num12++) - { - for (int num13 = j - num; num13 < j + num; num13++) - { - float num14 = (float)Math.Abs(i - num12); - float num15 = (float)Math.Abs(j - num13); - float num16 = (float)Math.Sqrt((double)(num14 * num14 + num15 * num15)); - if (Main.tile[num12, num13] != null) - { - if ((double)num16 < (double)num * 0.7) - { - if (Main.tile[num12, num13].type == 5 || Main.tile[num12, num13].type == 32 || Main.tile[num12, num13].type == 352) - { - try - { WorldGen.KillTile(num12, num13, false, false, true); } - catch (NullReferenceException) - { } - } - Main.tile[num12, num13].liquid = 0; - } - if (Main.tile[num12, num13].type == (ushort)ModContent.TileType()) - { - if (!WorldGen.SolidTile(num12 - 1, num13) && !WorldGen.SolidTile(num12 + 1, num13) && !WorldGen.SolidTile(num12, num13 - 1) && !WorldGen.SolidTile(num12, num13 + 1)) - { - Main.tile[num12, num13].active(false); - } - else if ((Main.tile[num12, num13].halfBrick() || Main.tile[num12 - 1, num13].topSlope()) && !WorldGen.SolidTile(num12, num13 + 1)) - { - Main.tile[num12, num13].active(false); - } - } - WorldGen.SquareTileFrame(num12, num13, true); - WorldGen.SquareWallFrame(num12, num13, true); - } - } - } - num = WorldGen.genRand.Next(23, 32); - for (int num17 = i - num; num17 < i + num; num17++) - { - for (int num18 = j - num; num18 < j + num; num18++) - { - if (num18 > j + WorldGen.genRand.Next(-3, 4) - 3 && Main.tile[num17, num18].active() && rand.NextBool(10)) - { - float num19 = (float)Math.Abs(i - num17); - float num20 = (float)Math.Abs(j - num18); - float num21 = (float)Math.Sqrt((double)(num19 * num19 + num20 * num20)); - if ((double)num21 < (double)num * 0.8) - { - if (Main.tile[num17, num18] != null) - { - if (Main.tile[num17, num18].type == 5 || Main.tile[num17, num18].type == 32 || Main.tile[num17, num18].type == 352) - { - WorldGen.KillTile(num17, num18, false, false, false); - } - Main.tile[num17, num18].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(num17, num18, true); - } - } - } - } - } - num = WorldGen.genRand.Next(30, 38); - for (int num22 = i - num; num22 < i + num; num22++) - { - for (int num23 = j - num; num23 < j + num; num23++) - { - if (num23 > j + WorldGen.genRand.Next(-2, 3) && Main.tile[num22, num23].active() && rand.NextBool(20)) - { - float num24 = (float)Math.Abs(i - num22); - float num25 = (float)Math.Abs(j - num23); - float num26 = (float)Math.Sqrt((double)(num24 * num24 + num25 * num25)); - if ((double)num26 < (double)num * 0.85) - { - if (Main.tile[num22, num23] != null) - { - if (Main.tile[num22, num23].type == 5 || Main.tile[num22, num23].type == 32 || Main.tile[num22, num23].type == 352) - { - WorldGen.KillTile(num22, num23, false, false, false); - } - Main.tile[num22, num23].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(num22, num23, true); - } - } - } - } - } - - if (Main.netMode != NetmodeID.MultiplayerClient) - { - NetMessage.SendTileSquare(-1, i, j, 40, TileChangeType.None); - if (CanAstralBiomeSpawn()) - { - DoAstralConversion(new Point(i, j)); - - // Upward checks go up 180 tiles. If for whatever reason the placement Y position - // would cause this upward movement to go outside of the world, clamp it to prevent index problems. - if (j < 181) - j = 181; - - int checkWidth = 180; - float averageHeight = 0f; - float lowestHeight = 0f; - - int xAreaToSpawn = i; - - Dictionary xAreaHeightMap = new Dictionary(); - - // Gauge the bumpiness of various potential locations. - // The least bumpy one will be selected as the place to spawn the monolith. - for (int tries = 0; tries < 30; tries++) - { - int x = i + Main.rand.Next(-60, 61); - - // Don't attempt to add duplicate keys. - if (xAreaHeightMap.ContainsKey(x)) - continue; - - float averageRelativeHeight = 0f; - for (int dx = -30; dx <= 30; dx++) - { - WorldUtils.Find(new Point(x + dx, j - 180), Searches.Chain(new Searches.Down(360), new Conditions.IsSolid()), out Point result); - averageRelativeHeight += Math.Abs(result.Y - j); - } - averageRelativeHeight /= 60f; - xAreaHeightMap.Add(x, averageRelativeHeight); - } - - i = xAreaHeightMap.OrderBy(x => x.Value).First().Key; - - for (int x = i - checkWidth / 2; x < i + checkWidth / 2; x++) - { - int y = j - 200; - Tile tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y); - while (!Main.tileSolid[tileAtPosition.type] || - !tileAtPosition.active() || - TileID.Sets.Platforms[tileAtPosition.type]) - { - y++; - if (y > j - 10) - break; - tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y); - } - lowestHeight = (int)MathHelper.Max(lowestHeight, y); - averageHeight += y; - } - lowestHeight -= 35f; - averageHeight /= checkWidth; - float height = lowestHeight; - - // If there's a sudden change between the average and lowest height (which is indicative of holes/chasms), go with the average. - if (Math.Abs(lowestHeight - averageHeight) > 50f) - height = averageHeight; - - // WorldGen.gen prevents NewItem from working, and thus prevents a bunch of dumb items from being spawned immediately and deleting the WoF/Aureus loot in the process. - WorldGen.gen = true; - // Add the average height of a tree to the Y position to offset trees usually messing with the calculation. - // Then also add 10 blocks because these things seem to always like to appear standing on the floor. - int finalVerticalOffset = 18; - bool _ = true; - SchematicManager.PlaceSchematic>("Astral Beacon", new Point(i, (int)height + finalVerticalOffset), SchematicAnchor.Center, ref _); - WorldGen.gen = false; - } - } - return true; - } - - public static void DoAstralConversion(object obj) - { - //Pre-calculate all variables necessary for elliptical area checking - Point origin = (Point)obj; - Vector2 center = origin.ToVector2() * 16f + new Vector2(8f); - - float angle = MathHelper.Pi * 0.15f; - float otherAngle = MathHelper.PiOver2 - angle; - - int distanceInTiles = 150 + (Main.maxTilesX - 4200) / 4200 * 200; - float distance = distanceInTiles * 16f; - float constant = distance * 2f / (float)Math.Sin(angle); - - float fociSpacing = distance * (float)Math.Sin(otherAngle) / (float)Math.Sin(angle); - int verticalRadius = (int)(constant / 16f); - - Vector2 fociOffset = Vector2.UnitY * fociSpacing; - Vector2 topFoci = center - fociOffset; - Vector2 bottomFoci = center + fociOffset; - - UnifiedRandom rand = WorldGen.genRand; - for (int x = origin.X - distanceInTiles - 2; x <= origin.X + distanceInTiles + 2; x++) - { - for (int y = (int)(origin.Y - verticalRadius * 0.4f) - 3; y <= origin.Y + verticalRadius + 3; y++) - { - if (CheckInEllipse(new Point(x, y), topFoci, bottomFoci, constant, center, out float dist, y < origin.Y)) - { - //If we're in the outer blurPercent% of the ellipse - float percent = dist / constant; - float blurPercent = 0.98f; - if (percent > blurPercent) - { - float outerEdgePercent = (percent - blurPercent) / (1f - blurPercent); - if (rand.NextFloat(1f) > outerEdgePercent) - { - ConvertToAstral(x, y); - } - } - else - { - ConvertToAstral(x, y); - } - } - } - } - } - - public static void ConvertToAstral(int startX, int endX, int startY, int endY) - { - for (int x = startX; x <= endX; x++) - { - for (int y = startY; y <= endY; y++) - { - ConvertToAstral(x, y); - } - } - } - - public static void ConvertToAstral(int x, int y) - { - if (WorldGen.InWorld(x, y, 1)) - { - int type = Main.tile[x, y].type; - int wallType = Main.tile[x, y].wall; - - if (Main.tile[x, y] != null) - { - if (WallID.Sets.Conversion.Grass[wallType]) - { - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (WallID.Sets.Conversion.HardenedSand[wallType]) - { - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (WallID.Sets.Conversion.Sandstone[wallType]) - { - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (WallID.Sets.Conversion.Stone[wallType]) - { - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else - { - switch (wallType) - { - case WallID.DirtUnsafe: - case WallID.DirtUnsafe1: - case WallID.DirtUnsafe2: - case WallID.DirtUnsafe3: - case WallID.DirtUnsafe4: - case WallID.Cave6Unsafe: - case WallID.Dirt: - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.SnowWallUnsafe: - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.DesertFossil: - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.IceUnsafe: - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.LivingWood: - Main.tile[x, y].wall = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - } - } - if (TileID.Sets.Conversion.Grass[type] && !TileID.Sets.GrassSpecial[type]) - { - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Stone[type] || Main.tileMoss[type]) - { - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Sand[type]) - { - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.HardenedSand[type]) - { - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Sandstone[type]) - { - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Ice[type]) - { - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else - { - Tile tile = Main.tile[x, y]; - switch (type) - { - case TileID.Dirt: - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.SnowBlock: - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.Silt: - case TileID.Slush: - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.DesertFossil: - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.ClayBlock: - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.Vines: - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.LivingWood: - Main.tile[x, y].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.LeafBlock: - case TileID.Sunflower: - WorldGen.KillTile(x, y); - if (Main.netMode == NetmodeID.MultiplayerClient) - { - NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y); - } - break; - case TileID.LargePiles: - if (tile.frameX <= 1170) - { - RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 0, 1170, 0, 18); - } - if (tile.frameX >= 1728) - { - RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1728, 1872, 0, 18); - } - if (tile.frameX >= 1404 && tile.frameX <= 1710) - { - RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1404, 1710, 0, 18); - } - break; - case TileID.LargePiles2: - if (tile.frameX >= 1566 && tile.frameY < 36) - { - RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 1566, 1872, 0, 18); - } - if (tile.frameX >= 756 && tile.frameX <= 900) - { - RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 756, 900, 0, 18); - } - break; - case TileID.SmallPiles: - if (tile.frameY == 18) - { - ushort newType; - if (tile.frameX >= 1476 && tile.frameX <= 1674) - { - newType = (ushort)ModContent.TileType(); - } - else if (tile.frameX <= 558 || (tile.frameX >= 1368 && tile.frameX <= 1458)) - { - newType = (ushort)ModContent.TileType(); - } - else if (tile.frameX >= 900 && tile.frameX <= 1098) - { - newType = (ushort)ModContent.TileType(); - } - else - { - break; - } - int leftMost = x; - if (tile.frameX % 36 != 0) //this means it's the right tile of the two - { - leftMost--; - } - if (Main.tile[leftMost, y] != null) - { - Main.tile[leftMost, y].type = newType; - WorldGen.SquareTileFrame(leftMost, y, true); - NetMessage.SendTileSquare(-1, leftMost, y, 1); - } - if (Main.tile[leftMost + 1, y] != null) - { - Main.tile[leftMost + 1, y].type = newType; - WorldGen.SquareTileFrame(leftMost + 1, y, true); - NetMessage.SendTileSquare(-1, leftMost + 1, y, 1); - } - while (Main.tile[leftMost, y].frameX >= 216) - { - if (Main.tile[leftMost, y] != null) - Main.tile[leftMost, y].frameX -= 216; - if (Main.tile[leftMost + 1, y] != null) - Main.tile[leftMost + 1, y].frameX -= 216; - } - } - else if (tile.frameY == 0) - { - ushort newType3; - if (tile.frameX >= 972 && tile.frameX <= 1062) - { - newType3 = (ushort)ModContent.TileType(); - } - else if (tile.frameX <= 486) - { - newType3 = (ushort)ModContent.TileType(); - } - else if (tile.frameX >= 648 && tile.frameX <= 846) - { - newType3 = (ushort)ModContent.TileType(); - } - else - { - break; - } - Main.tile[x, y].type = newType3; - while (Main.tile[x, y].frameX >= 108) //REFRAME IT - { - Main.tile[x, y].frameX -= 108; - } - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - break; - case TileID.Stalactite: - int topMost = tile.frameY <= 54 ? (tile.frameY % 36 == 0 ? y : y - 1) : y; - bool twoTall = tile.frameY <= 54; - bool hanging = tile.frameY <= 18 || tile.frameY == 72; - ushort newType2; - if (tile.frameX >= 378 && tile.frameX <= 414) //DESERT - { - newType2 = (ushort)ModContent.TileType(); - } - else if ((tile.frameX >= 54 && tile.frameX <= 90) || (tile.frameX >= 216 && tile.frameX <= 360)) - { - newType2 = (ushort)ModContent.TileType(); - } - else if (tile.frameX <= 36) - { - newType2 = (ushort)ModContent.TileType(); - } - else - { - break; - } - - //Set types - if (Main.tile[x, topMost] != null) - { - Main.tile[x, topMost].type = newType2; - } - if (twoTall) - { - if (Main.tile[x, topMost + 1] != null) - Main.tile[x, topMost + 1].type = newType2; - } - - //Fix frames - while (Main.tile[x, topMost].frameX >= 54) - { - if (Main.tile[x, topMost] != null) - Main.tile[x, topMost].frameX -= 54; - if (twoTall) - { - if (Main.tile[x, topMost + 1] != null) - Main.tile[x, topMost + 1].frameX -= 54; - } - } - - if (Main.tile[x, topMost] != null) - { - WorldGen.SquareTileFrame(x, topMost, true); - NetMessage.SendTileSquare(-1, x, topMost, 1); - } - - if (Main.tile[x, topMost + 1] != null) - { - WorldGen.SquareTileFrame(x, topMost + 1, true); - NetMessage.SendTileSquare(-1, x, topMost + 1, 1); - } - - if (hanging) - { - ConvertToAstral(x, topMost - 1); - break; - } - else - { - if (twoTall) - { - ConvertToAstral(x, topMost + 2); - break; - } - ConvertToAstral(x, topMost + 1); - break; - } - } - } - } - } - } - - public static void ConvertFromAstral(int x, int y, ConvertType convert, bool tileframe = true) - { - Tile tile = Main.tile[x, y]; - int type = tile.type; - int wallType = tile.wall; - - if (WorldGen.InWorld(x, y, 1)) - { - #region WALL - if (Main.tile[x, y] != null) - { - if (wallType == ModContent.WallType()) - { - Main.tile[x, y].wall = WallID.DirtUnsafe; - } - else if (wallType == ModContent.WallType() || wallType == ModContent.WallType()) - { - Main.tile[x, y].wall = WallID.SnowWallUnsafe; - } - else if (wallType == ModContent.WallType()) - { - Main.tile[x, y].wall = WallID.DesertFossil; - } - else if (wallType == ModContent.WallType()) - { - switch (convert) - { - case ConvertType.Corrupt: - Main.tile[x, y].wall = WallID.CorruptGrassUnsafe; - break; - case ConvertType.Crimson: - Main.tile[x, y].wall = WallID.CrimsonGrassUnsafe; - break; - case ConvertType.Hallow: - Main.tile[x, y].wall = WallID.HallowedGrassUnsafe; - break; - case ConvertType.Pure: - Main.tile[x, y].wall = WallID.GrassUnsafe; - break; - } - } - else if (wallType == ModContent.WallType()) - { - Main.tile[x, y].wall = WallID.IceUnsafe; - } - else if (wallType == ModContent.WallType()) - { - Main.tile[x, y].wall = WallID.LivingWood; - } - else if (wallType == ModContent.WallType()) - { - switch (convert) - { - case ConvertType.Corrupt: - Main.tile[x, y].wall = WallID.EbonstoneUnsafe; - break; - case ConvertType.Crimson: - Main.tile[x, y].wall = WallID.CrimstoneUnsafe; - break; - case ConvertType.Hallow: - Main.tile[x, y].wall = WallID.PearlstoneBrickUnsafe; - break; - case ConvertType.Pure: - Main.tile[x, y].wall = WallID.Stone; - break; - } - } - } - #endregion - - #region TILE - if (Main.tile[x, y] != null) - { - if (type == ModContent.TileType()) - { - tile.type = TileID.Dirt; - } - else if (type == ModContent.TileType()) - { - tile.type = TileID.SnowBlock; - } - else if (type == ModContent.TileType()) - { - tile.type = TileID.Silt; - } - else if (type == ModContent.TileType()) - { - tile.type = TileID.DesertFossil; - } - else if (type == ModContent.TileType()) - { - tile.type = TileID.ClayBlock; - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, TileID.CorruptGrass, TileID.FleshGrass, TileID.HallowedGrass, TileID.Grass); - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, TileID.Ebonstone, TileID.Crimstone, TileID.Pearlstone, TileID.Stone); - } - else if (type == ModContent.TileType()) - { - tile.type = TileID.LivingWood; - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, TileID.Ebonsand, TileID.Crimsand, TileID.Pearlsand, TileID.Sand); - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, TileID.CorruptSandstone, TileID.CrimsonSandstone, TileID.HallowSandstone, TileID.Sandstone); - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, TileID.CorruptHardenedSand, TileID.CrimsonHardenedSand, TileID.HallowHardenedSand, TileID.HardenedSand); - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, TileID.CorruptIce, TileID.FleshIce, TileID.HallowedIce, TileID.IceBlock); - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, ushort.MaxValue, TileID.CrimsonVines, TileID.HallowedVines, TileID.Vines); - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, TileID.CorruptPlants, ushort.MaxValue, TileID.HallowedPlants, TileID.Plants); - } - else if (type == ModContent.TileType()) - { - SetTileFromConvert(x, y, convert, ushort.MaxValue, ushort.MaxValue, TileID.HallowedPlants2, TileID.Plants2); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.LargePiles, x, y, 378, 0); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 0, 18); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 0, 0); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.LargePiles2, x, y, 1566, 0); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 1476, 18); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 972, 0); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.LargePiles, x, y, 1404, 0); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 900, 18); - } - else if (type == ModContent.TileType()) - { - RecursiveReplaceFromAstral((ushort)type, TileID.SmallPiles, x, y, 648, 0); - } - else if (type == ModContent.TileType()) - { - ushort originType = TileID.Stone; - int frameXAdd = 54; - switch (convert) - { - case ConvertType.Corrupt: - originType = TileID.Ebonstone; - frameXAdd = 324; - break; - case ConvertType.Crimson: - originType = TileID.Crimstone; - frameXAdd = 270; - break; - case ConvertType.Hallow: - originType = TileID.Pearlstone; - frameXAdd = 216; - break; - } - ReplaceAstralStalactite((ushort)type, TileID.Stalactite, originType, x, y, frameXAdd, 0); - } - else if (type == ModContent.TileType()) - { - ushort originType = TileID.Sandstone; - int frameXAdd = 378; - switch (convert) - { - case ConvertType.Corrupt: - originType = TileID.CorruptSandstone; - frameXAdd = 324; - break; - case ConvertType.Crimson: - originType = TileID.CrimsonSandstone; - frameXAdd = 270; - break; - case ConvertType.Hallow: - originType = TileID.HallowSandstone; - frameXAdd = 216; - break; - } - ReplaceAstralStalactite((ushort)type, TileID.Stalactite, originType, x, y, frameXAdd, 0); - } - else if (type == ModContent.TileType()) - { - ReplaceAstralStalactite((ushort)type, TileID.Stalactite, TileID.IceBlock, x, y, 0, 0); - } - if (TileID.Sets.Conversion.Grass[type] || type == TileID.Dirt) - { - WorldGen.SquareTileFrame(x, y); - } - } - #endregion - - if (tileframe) - { - if (Main.netMode == NetmodeID.SinglePlayer) - { - WorldGen.SquareTileFrame(x, y, true); - } - else if (Main.netMode == NetmodeID.Server) - { - NetMessage.SendTileSquare(-1, x, y, 1); - } - } - } - } - - public static void SetTileFromConvert(int x, int y, ConvertType convert, ushort corrupt, ushort crimson, ushort hallow, ushort pure) - { - switch (convert) - { - case ConvertType.Corrupt: - if (corrupt != ushort.MaxValue) - { - Main.tile[x, y].type = corrupt; - WorldGen.SquareTileFrame(x, y); - } - break; - case ConvertType.Crimson: - if (crimson != ushort.MaxValue) - { - Main.tile[x, y].type = crimson; - WorldGen.SquareTileFrame(x, y); - } - break; - case ConvertType.Hallow: - if (hallow != ushort.MaxValue) - { - Main.tile[x, y].type = hallow; - WorldGen.SquareTileFrame(x, y); - } - break; - case ConvertType.Pure: - if (pure != ushort.MaxValue) - { - Main.tile[x, y].type = pure; - WorldGen.SquareTileFrame(x, y); - } - break; - } - } - - public static void RecursiveReplaceToAstral(ushort checkType, ushort replaceType, int x, int y, int replaceTextureWidth, int minFrameX = 0, int maxFrameX = int.MaxValue, int minFrameY = 0, int maxFrameY = int.MaxValue) - { - Tile tile = Main.tile[x, y]; - if (tile == null || !tile.active() || tile.type != checkType || tile.frameX < minFrameX || tile.frameX > maxFrameX || tile.frameY < minFrameY || tile.frameY > maxFrameY) - return; - - Main.tile[x, y].type = replaceType; - while (Main.tile[x, y].frameX >= replaceTextureWidth) - { - Main.tile[x, y].frameX -= (short)replaceTextureWidth; - } - - if (Main.tile[x - 1, y] != null) - RecursiveReplaceToAstral(checkType, replaceType, x - 1, y, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); - if (Main.tile[x + 1, y] != null) - RecursiveReplaceToAstral(checkType, replaceType, x + 1, y, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); - if (Main.tile[x, y - 1] != null) - RecursiveReplaceToAstral(checkType, replaceType, x, y - 1, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); - if (Main.tile[x, y + 1] != null) - RecursiveReplaceToAstral(checkType, replaceType, x, y + 1, replaceTextureWidth, minFrameX, maxFrameX, minFrameY, maxFrameY); - } - - public static void RecursiveReplaceFromAstral(ushort checkType, ushort replaceType, int x, int y, int addFrameX, int addFrameY) - { - Tile tile = Main.tile[x, y]; - if (tile == null || !tile.active() || tile.type != checkType) - return; - - Main.tile[x, y].type = replaceType; - Main.tile[x, y].frameX += (short)addFrameX; - Main.tile[x, y].frameY += (short)addFrameY; - - if (Main.tile[x - 1, y] != null) - RecursiveReplaceFromAstral(checkType, replaceType, x - 1, y, addFrameX, addFrameY); - if (Main.tile[x + 1, y] != null) - RecursiveReplaceFromAstral(checkType, replaceType, x + 1, y, addFrameX, addFrameY); - if (Main.tile[x, y - 1] != null) - RecursiveReplaceFromAstral(checkType, replaceType, x, y - 1, addFrameX, addFrameY); - if (Main.tile[x, y + 1] != null) - RecursiveReplaceFromAstral(checkType, replaceType, x, y + 1, addFrameX, addFrameY); - } - - public static void ReplaceAstralStalactite(ushort checkType, ushort replaceType, ushort replaceOriginTile, int x, int y, int addFrameX, int addFrameY) - { - Tile tile = Main.tile[x, y]; - - int topMost = tile.frameY <= 54 ? (tile.frameY % 36 == 0 ? y : y - 1) : y; - bool twoTall = tile.frameY <= 54; - bool hanging = tile.frameY <= 18 || tile.frameY == 72; - - int yOriginTile = hanging ? topMost - 1 : (twoTall ? topMost + 2 : y + 1); - - if (Main.tile[x, topMost++] != null) - Main.tile[x, topMost++].type = replaceType; - if (twoTall) - { - if (Main.tile[x, topMost] != null) - Main.tile[x, topMost].type = replaceType; - } - if (Main.tile[x, yOriginTile] != null) - Main.tile[x, yOriginTile].type = replaceOriginTile; - } - - public static bool CheckInEllipse(Point tile, Vector2 focus1, Vector2 focus2, float distanceConstant, Vector2 center, out float distance, bool collapse = false) - { - Vector2 point = tile.ToVector2() * 16f + new Vector2(8f); - if (collapse) //Collapse ensures the ellipse is shrunk down a lot in terms of distance. - { - float distY = center.Y - point.Y; - point.Y -= distY * 8f; - } - float distance1 = Vector2.Distance(point, focus1); - float distance2 = Vector2.Distance(point, focus2); - distance = distance1 + distance2; - return distance <= distanceConstant; - } - #endregion - - #region EvilIsland - public static void EvilIsland(int i, int j) - { - double num = (double)WorldGen.genRand.Next(100, 150); - float num2 = (float)WorldGen.genRand.Next(20, 30); - int num3 = i; - int num4 = i; - int num5 = i; - int num6 = j; - Vector2 vector; - vector.X = (float)i; - vector.Y = (float)j; - Vector2 vector2; - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - while (vector2.X > -2f && vector2.X < 2f) - { - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - } - vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; - while (num > 0.0 && num2 > 0f) - { - num -= (double)WorldGen.genRand.Next(4); - num2 -= 1f; - int num7 = (int)((double)vector.X - num * 0.5); - int num8 = (int)((double)vector.X + num * 0.5); - int num9 = (int)((double)vector.Y - num * 0.5); - int num10 = (int)((double)vector.Y + num * 0.5); - if (num7 < 0) - { - num7 = 0; - } - if (num8 > Main.maxTilesX) - { - num8 = Main.maxTilesX; - } - if (num9 < 0) - { - num9 = 0; - } - if (num10 > Main.maxTilesY) - { - num10 = Main.maxTilesY; - } - double num11 = num * (double)WorldGen.genRand.Next(80, 120) * 0.01; //80 120 - float num12 = vector.Y + 1f; - for (int k = num7; k < num8; k++) - { - if (WorldGen.genRand.Next(2) == 0) - { - num12 += (float)WorldGen.genRand.Next(-1, 2); - } - if (num12 < vector.Y) - { - num12 = vector.Y; - } - if (num12 > vector.Y + 2f) - { - num12 = vector.Y + 2f; - } - for (int l = num9; l < num10; l++) - { - if ((float)l > num12) - { - float arg_218_0 = Math.Abs((float)k - vector.X); - float num13 = Math.Abs((float)l - vector.Y) * 3f; - if (Math.Sqrt((double)(arg_218_0 * arg_218_0 + num13 * num13)) < num11 * 0.4) - { - if (k < num3) - { - num3 = k; - } - if (k > num4) - { - num4 = k; - } - if (l < num5) - { - num5 = l; - } - if (l > num6) - { - num6 = l; - } - Main.tile[k, l].active(true); - Main.tile[k, l].type = (ushort)(WorldGen.crimson ? 400 : 401); //ebonstone or crimstone - WorldGen.SquareTileFrame(k, l, true); - } - } - } - } - vector += vector2; - vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; - if (vector2.X > 1f) - { - vector2.X = 1f; - } - if (vector2.X < -1f) - { - vector2.X = -1f; - } - if ((double)vector2.Y > 0.2) - { - vector2.Y = -0.2f; - } - if ((double)vector2.Y < -0.2) - { - vector2.Y = -0.2f; - } - } - int m = num3; - int num15; - for (m += WorldGen.genRand.Next(5); m < num4; m += WorldGen.genRand.Next(num15, (int)((double)num15 * 1.5))) - { - int num14 = num6; - while (!Main.tile[m, num14].active()) - { - num14--; - } - num14 += WorldGen.genRand.Next(-3, 4); - num15 = WorldGen.genRand.Next(4, 8); - int num16 = WorldGen.crimson ? 400 : 401; - if (WorldGen.genRand.Next(4) == 0) - { - num16 = WorldGen.crimson ? 398 : 399; - } - for (int n = m - num15; n <= m + num15; n++) - { - for (int num17 = num14 - num15; num17 <= num14 + num15; num17++) - { - if (num17 > num5) - { - float arg_409_0 = (float)Math.Abs(n - m); - float num18 = (float)(Math.Abs(num17 - num14) * 2); - if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num15 + WorldGen.genRand.Next(2))) - { - Main.tile[n, num17].active(true); - Main.tile[n, num17].type = (ushort)num16; - WorldGen.SquareTileFrame(n, num17, true); - } - } - } - } - } - num = (double)WorldGen.genRand.Next(80, 95); - num2 = (float)WorldGen.genRand.Next(10, 15); - vector.X = (float)i; - vector.Y = (float)num5; - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - while (vector2.X > -2f && vector2.X < 2f) - { - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - } - vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; - while (num > 0.0 && num2 > 0f) - { - num -= (double)WorldGen.genRand.Next(4); - num2 -= 1f; - int num7 = (int)((double)vector.X - num * 0.5); - int num8 = (int)((double)vector.X + num * 0.5); - int num9 = num5 - 1; - int num10 = (int)((double)vector.Y + num * 0.5); - if (num7 < 0) - { - num7 = 0; - } - if (num8 > Main.maxTilesX) - { - num8 = Main.maxTilesX; - } - if (num9 < 0) - { - num9 = 0; - } - if (num10 > Main.maxTilesY) - { - num10 = Main.maxTilesY; - } - double num11 = num * (double)WorldGen.genRand.Next(80, 120) * 0.01; - float num19 = vector.Y + 1f; - for (int num20 = num7; num20 < num8; num20++) - { - if (WorldGen.genRand.Next(2) == 0) - { - num19 += (float)WorldGen.genRand.Next(-1, 2); - } - if (num19 < vector.Y) - { - num19 = vector.Y; - } - if (num19 > vector.Y + 2f) - { - num19 = vector.Y + 2f; - } - for (int num21 = num9; num21 < num10; num21++) - { - if ((float)num21 > num19) - { - float arg_69E_0 = Math.Abs((float)num20 - vector.X); - float num22 = Math.Abs((float)num21 - vector.Y) * 3f; - if (Math.Sqrt((double)(arg_69E_0 * arg_69E_0 + num22 * num22)) < num11 * 0.4 && - Main.tile[num20, num21].type == (WorldGen.crimson ? 400 : 401)) - { - Main.tile[num20, num21].type = (ushort)(WorldGen.crimson ? 22 : 204); //ore - WorldGen.SquareTileFrame(num20, num21, true); - } - } - } - } - vector += vector2; - vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; - if (vector2.X > 1f) - { - vector2.X = 1f; - } - if (vector2.X < -1f) - { - vector2.X = -1f; - } - if ((double)vector2.Y > 0.2) - { - vector2.Y = -0.2f; - } - if ((double)vector2.Y < -0.2) - { - vector2.Y = -0.2f; - } - } - int num23 = num3; - num23 += WorldGen.genRand.Next(5); - while (num23 < num4) - { - int num24 = num6; - while ((!Main.tile[num23, num24].active() || Main.tile[num23, num24].type != 0) && num23 < num4) - { - num24--; - if (num24 < num5) - { - num24 = num6; - num23 += WorldGen.genRand.Next(1, 4); - } - } - if (num23 < num4) - { - num24 += WorldGen.genRand.Next(0, 4); - int num25 = WorldGen.genRand.Next(2, 5); - int num26 = WorldGen.crimson ? 400 : 401; - for (int num27 = num23 - num25; num27 <= num23 + num25; num27++) - { - for (int num28 = num24 - num25; num28 <= num24 + num25; num28++) - { - if (num28 > num5) - { - float arg_890_0 = (float)Math.Abs(num27 - num23); - float num29 = (float)(Math.Abs(num28 - num24) * 2); - if (Math.Sqrt((double)(arg_890_0 * arg_890_0 + num29 * num29)) < (double)num25) - { - Main.tile[num27, num28].type = (ushort)num26; - WorldGen.SquareTileFrame(num27, num28, true); - } - } - } - } - num23 += WorldGen.genRand.Next(num25, (int)((double)num25 * 1.5)); - } - } - for (int num30 = num3 - 20; num30 <= num4 + 20; num30++) - { - for (int num31 = num5 - 20; num31 <= num6 + 20; num31++) - { - bool flag = true; - for (int num32 = num30 - 1; num32 <= num30 + 1; num32++) - { - for (int num33 = num31 - 1; num33 <= num31 + 1; num33++) - { - if (!Main.tile[num32, num33].active()) - { - flag = false; - } - } - } - if (flag) - { - Main.tile[num30, num31].wall = (ushort)(WorldGen.crimson ? 220 : 221); - WorldGen.SquareWallFrame(num30, num31, true); - } - } - } - for (int num34 = num3; num34 <= num4; num34++) - { - int num35 = num5 - 10; - while (!Main.tile[num34, num35 + 1].active()) - { - num35++; - } - if (num35 < num6 && Main.tile[num34, num35 + 1].type == (WorldGen.crimson ? 400 : 401)) - { - if (WorldGen.genRand.Next(10) == 0) - { - int num36 = WorldGen.genRand.Next(1, 3); - for (int num37 = num34 - num36; num37 <= num34 + num36; num37++) - { - if (Main.tile[num37, num35].type == (WorldGen.crimson ? 400 : 401)) - { - Main.tile[num37, num35].active(false); - Main.tile[num37, num35].liquid = 255; - Main.tile[num37, num35].lava(false); - WorldGen.SquareTileFrame(num34, num35, true); - } - if (Main.tile[num37, num35 + 1].type == (WorldGen.crimson ? 400 : 401)) - { - Main.tile[num37, num35 + 1].active(false); - Main.tile[num37, num35 + 1].liquid = 255; - Main.tile[num37, num35 + 1].lava(false); - WorldGen.SquareTileFrame(num34, num35 + 1, true); - } - if (num37 > num34 - num36 && num37 < num34 + 2 && Main.tile[num37, num35 + 2].type == (WorldGen.crimson ? 400 : 401)) - { - Main.tile[num37, num35 + 2].active(false); - Main.tile[num37, num35 + 2].liquid = 255; - Main.tile[num37, num35 + 2].lava(false); - WorldGen.SquareTileFrame(num34, num35 + 2, true); - } - } - } - if (WorldGen.genRand.Next(5) == 0) - { - Main.tile[num34, num35].liquid = 255; - } - Main.tile[num34, num35].lava(false); - WorldGen.SquareTileFrame(num34, num35, true); - } - } - int num38 = WorldGen.genRand.Next(4); - for (int num39 = 0; num39 <= num38; num39++) - { - int num40 = WorldGen.genRand.Next(num3 - 5, num4 + 5); - int num41 = num5 - WorldGen.genRand.Next(20, 40); - int num42 = WorldGen.genRand.Next(4, 8); - int num43 = WorldGen.crimson ? 400 : 401; - if (WorldGen.genRand.Next(2) == 0) - { - num43 = WorldGen.crimson ? 398 : 399; - } - for (int num44 = num40 - num42; num44 <= num40 + num42; num44++) - { - for (int num45 = num41 - num42; num45 <= num41 + num42; num45++) - { - float arg_C74_0 = (float)Math.Abs(num44 - num40); - float num46 = (float)(Math.Abs(num45 - num41) * 2); - if (Math.Sqrt((double)(arg_C74_0 * arg_C74_0 + num46 * num46)) < (double)(num42 + WorldGen.genRand.Next(-1, 2))) - { - Main.tile[num44, num45].active(true); - Main.tile[num44, num45].type = (ushort)num43; - WorldGen.SquareTileFrame(num44, num45, true); - } - } - } - for (int num47 = num40 - num42 + 2; num47 <= num40 + num42 - 2; num47++) - { - int num48 = num41 - num42; - while (!Main.tile[num47, num48].active()) - { - num48++; - } - Main.tile[num47, num48].active(false); - Main.tile[num47, num48].liquid = 255; - WorldGen.SquareTileFrame(num47, num48, true); - } - } - } - #endregion - - #region EvilIslandHouse - public static void EvilIslandHouse(int i, int j) - { - ushort type = (ushort)(WorldGen.crimson ? 152 : 347); //tile - byte wall = (byte)(WorldGen.crimson ? 35 : 174); //wall - Vector2 vector = new Vector2((float)i, (float)j); - int num = 1; - if (WorldGen.genRand.Next(2) == 0) - { - num = -1; - } - int num2 = WorldGen.genRand.Next(7, 12); - int num3 = WorldGen.genRand.Next(5, 7); - vector.X = (float)(i + (num2 + 2) * num); - for (int k = j - 15; k < j + 30; k++) - { - if (Main.tile[(int)vector.X, k].active()) - { - vector.Y = (float)(k - 1); - break; - } - } - vector.X = (float)i; - int num4 = (int)(vector.X - (float)num2 - 1f); - int num5 = (int)(vector.X + (float)num2 + 1f); - int num6 = (int)(vector.Y - (float)num3 - 1f); - int num7 = (int)(vector.Y + 2f); - if (num4 < 0) - { - num4 = 0; - } - if (num5 > Main.maxTilesX) - { - num5 = Main.maxTilesX; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int l = num4; l <= num5; l++) - { - for (int m = num6 - 1; m < num7 + 1; m++) - { - if (m != num6 - 1 || (l != num4 && l != num5)) - { - Main.tile[l, m].active(true); - Main.tile[l, m].liquid = 0; - Main.tile[l, m].type = type; - Main.tile[l, m].wall = 0; - Main.tile[l, m].halfBrick(false); - Main.tile[l, m].slope(0); - } - } - } - num4 = (int)(vector.X - (float)num2); - num5 = (int)(vector.X + (float)num2); - num6 = (int)(vector.Y - (float)num3); - num7 = (int)(vector.Y + 1f); - if (num4 < 0) - { - num4 = 0; - } - if (num5 > Main.maxTilesX) - { - num5 = Main.maxTilesX; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int n = num4; n <= num5; n++) - { - for (int num8 = num6; num8 < num7; num8++) - { - if ((num8 != num6 || (n != num4 && n != num5)) && Main.tile[n, num8].wall == 0) - { - Main.tile[n, num8].active(false); - Main.tile[n, num8].wall = wall; - } - } - } - int num9 = i + (num2 + 1) * num; - int num10 = (int)vector.Y; - for (int num11 = num9 - 2; num11 <= num9 + 2; num11++) - { - Main.tile[num11, num10].active(false); - Main.tile[num11, num10 - 1].active(false); - Main.tile[num11, num10 - 2].active(false); - } - WorldGen.PlaceTile(num9, num10, 10, true, false, -1, WorldGen.crimson ? 1 : 10); //door - num9 = i + (num2 + 1) * -num - num; - for (int num12 = num6; num12 <= num7 + 1; num12++) - { - Main.tile[num9, num12].active(true); - Main.tile[num9, num12].liquid = 0; - Main.tile[num9, num12].type = type; - Main.tile[num9, num12].wall = 0; - Main.tile[num9, num12].halfBrick(false); - Main.tile[num9, num12].slope(0); - } - int contain; - if (WorldGen.crimson) - { - contain = 1571; //scourge - } - else - { - contain = 1569; //vampire - } - WorldGen.AddBuriedChest(i, num10 - 3, contain, false, WorldGen.crimson ? 19 : 20); //chest - int num14 = i - num2 / 2 + 1; - int num15 = i + num2 / 2 - 1; - int num16 = 1; - if (num2 > 10) - { - num16 = 2; - } - int num17 = (num6 + num7) / 2 - 1; - for (int num18 = num14 - num16; num18 <= num14 + num16; num18++) - { - for (int num19 = num17 - 1; num19 <= num17 + 1; num19++) - { - Main.tile[num18, num19].wall = 21; //glass - } - } - for (int num20 = num15 - num16; num20 <= num15 + num16; num20++) - { - for (int num21 = num17 - 1; num21 <= num17 + 1; num21++) - { - Main.tile[num20, num21].wall = 21; //glass - } - } - int num22 = i + (num2 / 2 + 1) * -num; - WorldGen.PlaceTile(num22, num7 - 1, 14, true, false, -1, WorldGen.crimson ? 1 : 8); //table - WorldGen.PlaceTile(num22 - 2, num7 - 1, 15, true, false, 0, WorldGen.crimson ? 2 : 11); //chair - Tile tile = Main.tile[num22 - 2, num7 - 1]; - tile.frameX += 18; - Tile tile2 = Main.tile[num22 - 2, num7 - 2]; - tile2.frameX += 18; - WorldGen.PlaceTile(num22 + 2, num7 - 1, 15, true, false, 0, WorldGen.crimson ? 2 : 11); //chair - } - #endregion - - #region UnderworldIsland - public static void UnderworldIsland(int i, int j, int sizeMin, int sizeMax, int sizeMin2, int sizeMax2) - { - double num = (double)WorldGen.genRand.Next(sizeMin, sizeMax); //100 150 - float num2 = (float)WorldGen.genRand.Next(sizeMin / 5, sizeMax / 5); //20 30 - int num3 = i; - int num4 = i; - int num5 = i; - int num6 = j; - Vector2 vector; - vector.X = (float)i; - vector.Y = (float)j; - Vector2 vector2; - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - while (vector2.X > -2f && vector2.X < 2f) - { - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - } - vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; - while (num > 0.0 && num2 > 0f) - { - num -= (double)WorldGen.genRand.Next(4); - num2 -= 1f; - int num7 = (int)((double)vector.X - num * 0.5); - int num8 = (int)((double)vector.X + num * 0.5); - int num9 = (int)((double)vector.Y - num * 0.5); - int num10 = (int)((double)vector.Y + num * 0.5); - if (num7 < 0) - { - num7 = 0; - } - if (num8 > Main.maxTilesX) - { - num8 = Main.maxTilesX; - } - if (num9 < Main.maxTilesY - 270) - { - num9 = Main.maxTilesY - 270; - } - if (num10 > Main.maxTilesY) - { - num10 = Main.maxTilesY; - } - double num11 = num * (double)WorldGen.genRand.Next(sizeMin, sizeMax) * 0.01; //80 120 - float num12 = vector.Y + 1f; - for (int k = num7; k < num8; k++) - { - if (WorldGen.genRand.Next(2) == 0) - { - num12 += (float)WorldGen.genRand.Next(-1, 2); - } - if (num12 < vector.Y) - { - num12 = vector.Y; - } - if (num12 > vector.Y + 2f) - { - num12 = vector.Y + 2f; - } - for (int l = num9; l < num10; l++) - { - if ((float)l > num12) - { - float arg_218_0 = Math.Abs((float)k - vector.X); - float num13 = Math.Abs((float)l - vector.Y) * 3f; - if (Math.Sqrt((double)(arg_218_0 * arg_218_0 + num13 * num13)) < num11 * 0.4) - { - if (k < num3) - { - num3 = k; - } - if (k > num4) - { - num4 = k; - } - if (l < num5) - { - num5 = l; - } - if (l > num6) - { - num6 = l; - } - Main.tile[k, l].active(true); - Main.tile[k, l].type = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(k, l, true); - } - } - } - } - vector += vector2; - vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; - if (vector2.X > 1f) - { - vector2.X = 1f; - } - if (vector2.X < -1f) - { - vector2.X = -1f; - } - if ((double)vector2.Y > 0.2) - { - vector2.Y = -0.2f; - } - if ((double)vector2.Y < -0.2) - { - vector2.Y = -0.2f; - } - } - int m = num3; - int num15; - for (m += WorldGen.genRand.Next(5); m < num4; m += WorldGen.genRand.Next(num15, (int)((double)num15 * 1.5))) - { - int num14 = num6; - while (!Main.tile[m, num14].active()) - { - num14--; - if (num14 < Main.maxTilesX - WorldGen.genRand.Next(265, 275 + 1)) - break; - } - num14 += WorldGen.genRand.Next(-3, 4); - num15 = WorldGen.genRand.Next(4, 8); - int num16 = ModContent.TileType(); - if (WorldGen.genRand.Next(4) == 0) - { - num16 = ModContent.TileType(); - } - for (int n = m - num15; n <= m + num15; n++) - { - for (int num17 = num14 - num15; num17 <= num14 + num15; num17++) - { - if (num17 > num5) - { - float arg_409_0 = (float)Math.Abs(n - m); - float num18 = (float)(Math.Abs(num17 - num14) * 2); - if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num15 + WorldGen.genRand.Next(2))) - { - Main.tile[n, num17].active(true); - Main.tile[n, num17].type = (ushort)num16; - WorldGen.SquareTileFrame(n, num17, true); - } - } - } - } - } - num = (double)WorldGen.genRand.Next(sizeMin2, sizeMax2); - num2 = (float)WorldGen.genRand.Next(sizeMin2 / 8, sizeMax2 / 8); - vector.X = (float)i; - vector.Y = (float)num5; - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - while (vector2.X > -2f && vector2.X < 2f) - { - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - } - vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; - while (num > 0.0 && num2 > 0f) - { - num -= (double)WorldGen.genRand.Next(4); - num2 -= 1f; - vector += vector2; - vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; - if (vector2.X > 1f) - { - vector2.X = 1f; - } - if (vector2.X < -1f) - { - vector2.X = -1f; - } - if ((double)vector2.Y > 0.2) - { - vector2.Y = -0.2f; - } - if ((double)vector2.Y < -0.2) - { - vector2.Y = -0.2f; - } - } - int num23 = num3; - num23 += WorldGen.genRand.Next(5); - while (num23 < num4) - { - int num24 = num6; - while ((!Main.tile[num23, num24].active() || Main.tile[num23, num24].type != 0) && num23 < num4) - { - num24--; - if (num24 < num5) - { - num24 = num6; - num23 += WorldGen.genRand.Next(1, 4); - } - } - if (num23 < num4) - { - num24 += WorldGen.genRand.Next(0, 4); - int num25 = WorldGen.genRand.Next(2, 5); - int num26 = ModContent.TileType(); - for (int num27 = num23 - num25; num27 <= num23 + num25; num27++) - { - for (int num28 = num24 - num25; num28 <= num24 + num25; num28++) - { - if (num28 > num5) - { - float arg_890_0 = (float)Math.Abs(num27 - num23); - float num29 = (float)(Math.Abs(num28 - num24) * 2); - if (Math.Sqrt((double)(arg_890_0 * arg_890_0 + num29 * num29)) < (double)num25) - { - Main.tile[num27, num28].type = (ushort)num26; - WorldGen.SquareTileFrame(num27, num28, true); - } - } - } - } - num23 += WorldGen.genRand.Next(num25, (int)((double)num25 * 1.5)); - } - } - for (int num34 = num3; num34 <= num4; num34++) - { - int num35 = num5 - 10; - while (!Main.tile[num34, num35 + 1].active()) - { - num35++; - } - if (num35 < num6 && Main.tile[num34, num35 + 1].type == (ushort)ModContent.TileType()) - { - if (WorldGen.genRand.Next(10) == 0) - { - int num36 = WorldGen.genRand.Next(1, 3); - for (int num37 = num34 - num36; num37 <= num34 + num36; num37++) - { - if (Main.tile[num37, num35].type == (ushort)ModContent.TileType()) - { - Main.tile[num37, num35].active(false); - Main.tile[num37, num35].liquid = 255; - Main.tile[num37, num35].lava(false); - WorldGen.SquareTileFrame(num34, num35, true); - } - if (Main.tile[num37, num35 + 1].type == (ushort)ModContent.TileType()) - { - Main.tile[num37, num35 + 1].active(false); - Main.tile[num37, num35 + 1].liquid = 255; - Main.tile[num37, num35 + 1].lava(false); - WorldGen.SquareTileFrame(num34, num35 + 1, true); - } - if (num37 > num34 - num36 && num37 < num34 + 2 && Main.tile[num37, num35 + 2].type == (ushort)ModContent.TileType()) - { - Main.tile[num37, num35 + 2].active(false); - Main.tile[num37, num35 + 2].liquid = 255; - Main.tile[num37, num35 + 2].lava(false); - WorldGen.SquareTileFrame(num34, num35 + 2, true); - } - } - } - if (WorldGen.genRand.Next(5) == 0) - { - Main.tile[num34, num35].liquid = 255; - } - Main.tile[num34, num35].lava(false); - WorldGen.SquareTileFrame(num34, num35, true); - } - } - } - #endregion - - #region UnderworldIslandHouse - public static void UnderworldIslandHouse(int i, int j, int item) - { - ushort type = (ushort)ModContent.TileType(); //tile - byte wall = (byte)ModContent.WallType(); //wall - Vector2 vector = new Vector2((float)i, (float)j); - int num = 1; - if (WorldGen.genRand.Next(2) == 0) - { - num = -1; - } - int num2 = WorldGen.genRand.Next(7, 12); - int num3 = WorldGen.genRand.Next(5, 7); - vector.X = (float)(i + (num2 + 2) * num); - for (int k = j - 15; k < j + 30; k++) - { - if (Main.tile[(int)vector.X, k].active()) - { - vector.Y = (float)(k - 1); - break; - } - } - vector.X = (float)i; - int num4 = (int)(vector.X - (float)num2 - 1f); - int num5 = (int)(vector.X + (float)num2 + 1f); - int num6 = (int)(vector.Y - (float)num3 - 1f); - int num7 = (int)(vector.Y + 2f); - if (num4 < 0) - { - num4 = 0; - } - if (num5 > Main.maxTilesX) - { - num5 = Main.maxTilesX; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int l = num4; l <= num5; l++) - { - for (int m = num6 - 1; m < num7 + 1; m++) - { - if (m != num6 - 1 || (l != num4 && l != num5)) - { - Main.tile[l, m].active(true); - Main.tile[l, m].liquid = 0; - Main.tile[l, m].type = type; - Main.tile[l, m].wall = 0; - Main.tile[l, m].halfBrick(false); - Main.tile[l, m].slope(0); - } - } - } - num4 = (int)(vector.X - (float)num2); - num5 = (int)(vector.X + (float)num2); - num6 = (int)(vector.Y - (float)num3); - num7 = (int)(vector.Y + 1f); - if (num4 < 0) - { - num4 = 0; - } - if (num5 > Main.maxTilesX) - { - num5 = Main.maxTilesX; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int n = num4; n <= num5; n++) - { - for (int num8 = num6; num8 < num7; num8++) - { - if ((num8 != num6 || (n != num4 && n != num5)) && Main.tile[n, num8].wall == 0) - { - Main.tile[n, num8].active(false); - Main.tile[n, num8].wall = wall; - } - } - } - int num9 = i + (num2 + 1) * num; - int num10 = (int)vector.Y; - for (int num11 = num9 - 2; num11 <= num9 + 2; num11++) - { - Main.tile[num11, num10].active(false); - Main.tile[num11, num10 - 1].active(false); - Main.tile[num11, num10 - 2].active(false); - } - WorldGen.PlaceTile(num9, num10, ModContent.TileType(), true, false, -1); //door - num9 = i + (num2 + 1) * -num - num; - for (int num12 = num6; num12 <= num7 + 1; num12++) - { - Main.tile[num9, num12].active(true); - Main.tile[num9, num12].liquid = 0; - Main.tile[num9, num12].type = type; - Main.tile[num9, num12].wall = 0; - Main.tile[num9, num12].halfBrick(false); - Main.tile[num9, num12].slope(0); - } - WorldGen.AddBuriedChest(i, num10 - 3, item, false, 4); //chest - int num22 = i + (num2 / 2 + 1) * -num; - WorldGen.PlaceTile(num22, num7 - 1, ModContent.TileType(), true, false, -1); //table - WorldGen.PlaceTile(num22 - 2, num7 - 1, ModContent.TileType(), true, false, 0); //chair - Tile tile = Main.tile[num22 - 2, num7 - 1]; - tile.frameX += 18; - Tile tile2 = Main.tile[num22 - 2, num7 - 2]; - tile2.frameX += 18; - WorldGen.PlaceTile(num22 + 2, num7 - 1, ModContent.TileType(), true, false, 0); //chair - } - #endregion - - #region AbyssIsland - public static void AbyssIsland(int i, int j, int sizeMin, int sizeMax, int sizeMin2, int sizeMax2, bool hasChest, bool hasTenebris, bool isVoid) - { - int sizeMinSmall = sizeMin / 5; - int sizeMaxSmall = sizeMax / 5; - double num = (double)WorldGen.genRand.Next(sizeMin, sizeMax); //100 150 - float num2 = (float)WorldGen.genRand.Next(sizeMinSmall, sizeMaxSmall); //20 30 - int num3 = i; - int num4 = i; - int num5 = i; - int num6 = j; - Vector2 vector; - vector.X = (float)i; - vector.Y = (float)j; - Vector2 vector2; - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - while (vector2.X > -2f && vector2.X < 2f) - { - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - } - vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; - while (num > 0.0 && num2 > 0f) - { - num -= (double)WorldGen.genRand.Next(4); - num2 -= 1f; - int num7 = (int)((double)vector.X - num * 0.5); - int num8 = (int)((double)vector.X + num * 0.5); - int num9 = (int)((double)vector.Y - num * 0.5); - int num10 = (int)((double)vector.Y + num * 0.5); - if (num7 < 0) - { - num7 = 0; - } - if (num8 > Main.maxTilesX) - { - num8 = Main.maxTilesX; - } - if (num9 < 0) - { - num9 = 0; - } - if (num10 > Main.maxTilesY) - { - num10 = Main.maxTilesY; - } - double num11 = num * (double)WorldGen.genRand.Next(sizeMin, sizeMax) * 0.01; //80 120 - float num12 = vector.Y + 1f; - for (int k = num7; k < num8; k++) - { - if (WorldGen.genRand.Next(2) == 0) - { - num12 += (float)WorldGen.genRand.Next(-1, 2); - } - if (num12 < vector.Y) - { - num12 = vector.Y; - } - if (num12 > vector.Y + 2f) - { - num12 = vector.Y + 2f; - } - for (int l = num9; l < num10; l++) - { - if ((float)l > num12) - { - float arg_218_0 = Math.Abs((float)k - vector.X); - float num13 = Math.Abs((float)l - vector.Y) * 3f; - if (Math.Sqrt((double)(arg_218_0 * arg_218_0 + num13 * num13)) < num11 * 0.4) - { - if (k < num3) - { - num3 = k; - } - if (k > num4) - { - num4 = k; - } - if (l < num5) - { - num5 = l; - } - if (l > num6) - { - num6 = l; - } - Main.tile[k, l].active(true); - Main.tile[k, l].type = (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType()); - CalamityUtils.SafeSquareTileFrame(k, l, true); - } - } - } - } - vector += vector2; - vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; - if (vector2.X > 1f) - { - vector2.X = 1f; - } - if (vector2.X < -1f) - { - vector2.X = -1f; - } - if ((double)vector2.Y > 0.2) - { - vector2.Y = -0.2f; - } - if ((double)vector2.Y < -0.2) - { - vector2.Y = -0.2f; - } - } - int m = num3; - int num15; - for (m += WorldGen.genRand.Next(5); m < num4; m += WorldGen.genRand.Next(num15, (int)((double)num15 * 1.5))) - { - int num14 = num6; - while (!Main.tile[m, num14].active()) - { - num14--; - } - num14 += WorldGen.genRand.Next(-3, 4); - num15 = WorldGen.genRand.Next(4, 8); - int num16 = isVoid ? ModContent.TileType() : ModContent.TileType(); - if (WorldGen.genRand.Next(4) == 0) - { - num16 = hasChest ? ModContent.TileType() : ModContent.TileType(); - } - for (int n = m - num15; n <= m + num15; n++) - { - for (int num17 = num14 - num15; num17 <= num14 + num15; num17++) - { - if (num17 > num5) - { - float arg_409_0 = (float)Math.Abs(n - m); - float num18 = (float)(Math.Abs(num17 - num14) * 2); - if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num15 + WorldGen.genRand.Next(2))) - { - Main.tile[n, num17].active(true); - Main.tile[n, num17].type = (ushort)num16; - CalamityUtils.SafeSquareTileFrame(n, num17, true); - } - } - } - } - } - if (hasTenebris) - { - int p = num3; - int num150; - for (p += WorldGen.genRand.Next(5); p < num4; p += WorldGen.genRand.Next(num150, (int)((double)num150 * 1.5))) - { - int num14 = num6; - while (!Main.tile[p, num14].active()) - { - num14--; - } - num14 += WorldGen.genRand.Next(-3, 4); //-3 4 - num150 = 1; //4 8 - int num16 = ModContent.TileType(); - for (int n = p - num150; n <= p + num150; n++) - { - for (int num17 = num14 - num150; num17 <= num14 + num150; num17++) - { - if (num17 > num5) - { - float arg_409_0 = (float)Math.Abs(n - p); - float num18 = (float)(Math.Abs(num17 - num14) * 2); - if (Math.Sqrt((double)(arg_409_0 * arg_409_0 + num18 * num18)) < (double)(num150 + WorldGen.genRand.Next(2))) - { - Main.tile[n, num17].active(true); - Main.tile[n, num17].type = (ushort)num16; - CalamityUtils.SafeSquareTileFrame(n, num17, true); - } - } - } - } - } - } - int sizeMinSmall2 = sizeMin2 / 8; - int sizeMaxSmall2 = sizeMax2 / 8; - num = (double)WorldGen.genRand.Next(sizeMin2, sizeMax2); - num2 = (float)WorldGen.genRand.Next(sizeMinSmall2, sizeMaxSmall2); - vector.X = (float)i; - vector.Y = (float)num5; - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - while (vector2.X > -2f && vector2.X < 2f) - { - vector2.X = (float)WorldGen.genRand.Next(-20, 21) * 0.2f; - } - vector2.Y = (float)WorldGen.genRand.Next(-20, -10) * 0.02f; - while (num > 0.0 && num2 > 0f) - { - num -= (double)WorldGen.genRand.Next(4); - num2 -= 1f; - vector += vector2; - vector2.X += (float)WorldGen.genRand.Next(-20, 21) * 0.05f; - if (vector2.X > 1f) - { - vector2.X = 1f; - } - if (vector2.X < -1f) - { - vector2.X = -1f; - } - if ((double)vector2.Y > 0.2) - { - vector2.Y = -0.2f; - } - if ((double)vector2.Y < -0.2) - { - vector2.Y = -0.2f; - } - } - int num23 = num3; - num23 += WorldGen.genRand.Next(5); - while (num23 < num4) - { - int num24 = num6; - while ((!Main.tile[num23, num24].active() || Main.tile[num23, num24].type != 0) && num23 < num4) - { - num24--; - if (num24 < num5) - { - num24 = num6; - num23 += WorldGen.genRand.Next(1, 4); - } - } - if (num23 < num4) - { - num24 += WorldGen.genRand.Next(0, 4); - int num25 = WorldGen.genRand.Next(2, 5); - int num26 = isVoid ? ModContent.TileType() : ModContent.TileType(); - for (int num27 = num23 - num25; num27 <= num23 + num25; num27++) - { - for (int num28 = num24 - num25; num28 <= num24 + num25; num28++) - { - if (num28 > num5) - { - float arg_890_0 = (float)Math.Abs(num27 - num23); - float num29 = (float)(Math.Abs(num28 - num24) * 2); - if (Math.Sqrt((double)(arg_890_0 * arg_890_0 + num29 * num29)) < (double)num25) - { - Main.tile[num27, num28].type = (ushort)num26; - CalamityUtils.SafeSquareTileFrame(num27, num28, true); - } - } - } - } - num23 += WorldGen.genRand.Next(num25, (int)((double)num25 * 1.5)); - } - } - for (int num30 = num3 - 20; num30 <= num4 + 20; num30++) - { - for (int num31 = num5 - 20; num31 <= num6 + 20; num31++) - { - bool flag = true; - for (int num32 = num30 - 1; num32 <= num30 + 1; num32++) - { - for (int num33 = num31 - 1; num33 <= num31 + 1; num33++) - { - if (!Main.tile[num32, num33].active()) - { - flag = false; - } - } - } - if (flag) - { - Main.tile[num30, num31].wall = (ushort)(isVoid ? ModContent.WallType() : ModContent.WallType()); - WorldGen.SquareWallFrame(num30, num31, true); - } - } - } - for (int num34 = num3; num34 <= num4; num34++) - { - int num35 = num5 - 10; - while (!Main.tile[num34, num35 + 1].active()) - { - num35++; - } - if (num35 < num6 && Main.tile[num34, num35 + 1].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) - { - if (WorldGen.genRand.Next(10) == 0) - { - int num36 = WorldGen.genRand.Next(1, 3); - for (int num37 = num34 - num36; num37 <= num34 + num36; num37++) - { - if (Main.tile[num37, num35].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) - { - Main.tile[num37, num35].active(false); - Main.tile[num37, num35].liquid = 255; - Main.tile[num37, num35].lava(false); - CalamityUtils.SafeSquareTileFrame(num34, num35, true); - } - if (Main.tile[num37, num35 + 1].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) - { - Main.tile[num37, num35 + 1].active(false); - Main.tile[num37, num35 + 1].liquid = 255; - Main.tile[num37, num35 + 1].lava(false); - CalamityUtils.SafeSquareTileFrame(num34, num35 + 1, true); - } - if (num37 > num34 - num36 && num37 < num34 + 2 && Main.tile[num37, num35 + 2].type == (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType())) - { - Main.tile[num37, num35 + 2].active(false); - Main.tile[num37, num35 + 2].liquid = 255; - Main.tile[num37, num35 + 2].lava(false); - CalamityUtils.SafeSquareTileFrame(num34, num35 + 2, true); - } - } - } - if (WorldGen.genRand.Next(5) == 0) - { - Main.tile[num34, num35].liquid = 255; - } - Main.tile[num34, num35].lava(false); - CalamityUtils.SafeSquareTileFrame(num34, num35, true); - } - } - } - #endregion - - #region AbyssIslandHouse - public static void AbyssIslandHouse(int i, int j, int itemChoice, bool isVoid) - { - ushort type = (ushort)(isVoid ? ModContent.TileType() : ModContent.TileType()); //tile - ushort wall = (ushort)(isVoid ? ModContent.WallType() : ModContent.WallType()); //wall - Vector2 vector = new Vector2((float)i, (float)j); - int num = 1; - if (WorldGen.genRand.Next(2) == 0) - { - num = -1; - } - int num2 = WorldGen.genRand.Next(5, 9); - int num3 = 3; - vector.X = (float)(i + (num2 + 2) * num); - for (int k = j - 15; k < j + 30; k++) - { - if (Main.tile[(int)vector.X, k].active()) - { - vector.Y = (float)(k - 1); - break; - } - } - vector.X = (float)i; - int num4 = (int)(vector.X - (float)num2 - 1f); - int num5 = (int)(vector.X + (float)num2 + 1f); - int num6 = (int)(vector.Y - (float)num3 - 1f); - int num7 = (int)(vector.Y + 2f); - if (num4 < 0) - { - num4 = 0; - } - if (num5 > Main.maxTilesX) - { - num5 = Main.maxTilesX; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int l = num4; l <= num5; l++) - { - for (int m = num6 - 1; m < num7 + 1; m++) - { - if (m != num6 - 1 || (l != num4 && l != num5)) - { - Main.tile[l, m].active(true); - Main.tile[l, m].type = type; - Main.tile[l, m].wall = wall; - Main.tile[l, m].halfBrick(false); - Main.tile[l, m].slope(0); - } - } - } - num4 = (int)(vector.X - (float)num2); - num5 = (int)(vector.X + (float)num2); - num6 = (int)(vector.Y - (float)num3); - num7 = (int)(vector.Y + 1f); - if (num4 < 0) - { - num4 = 0; - } - if (num5 > Main.maxTilesX) - { - num5 = Main.maxTilesX; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int n = num4; n <= num5; n++) - { - for (int num8 = num6; num8 < num7; num8++) - { - if ((num8 != num6 || (n != num4 && n != num5)) && Main.tile[n, num8].wall == wall) - { - Main.tile[n, num8].active(false); - } - } - } - int num9 = i + (num2 + 1) * num; - int num10 = (int)vector.Y; - for (int num11 = num9 - 2; num11 <= num9 + 2; num11++) - { - Main.tile[num11, num10].active(false); - Main.tile[num11, num10 - 1].active(false); - Main.tile[num11, num10 - 2].active(false); - } - switch (itemChoice) - { - case 0: - itemChoice = ModContent.ItemType(); - break; //rain item - case 1: - itemChoice = ModContent.ItemType(); - break; //movement acc - case 2: - itemChoice = ModContent.ItemType(); - break; //regen acc - case 3: - itemChoice = ModContent.ItemType(); - break; //ranged - case 4: - itemChoice = ModContent.ItemType(); - break; //defense acc - case 5: - itemChoice = ModContent.ItemType(); - break; //melee - case 6: - itemChoice = ModContent.ItemType(); - break; //light pet - case 7: - itemChoice = ModContent.ItemType(); - break; //summon - case 8: - itemChoice = ModContent.ItemType(); - break; //magic - case 9: - itemChoice = ModContent.ItemType(); - break; //throwing - default: - itemChoice = 497; - break; - } - WorldGen.AddBuriedChest(i, num10 - 3, itemChoice, false, 4); //chest - } - #endregion - - #region SpecialHut - // Special Hut: Takes arguments of tile type 1, tile type 2, wall type, hut type (useful if you use this method to generate different huts), and location of the shrine (x and y) - public static void SpecialHut(ushort tile, ushort tile2, ushort wall, int hutType, int shrineLocationX, int shrineLocationY) - { - // Random variables for shrine size - int randomX = WorldGen.genRand.Next(2, 4); - int randomY = WorldGen.genRand.Next(2, 4); - - // Replace tiles in shrine area with shrine tile type 1 - for (int n = shrineLocationX - randomX - 1; n <= shrineLocationX + randomX + 1; n++) - { - for (int num8 = shrineLocationY - randomY - 1; num8 <= shrineLocationY + randomY + 1; num8++) - { - Main.tile[n, num8].active(true); - Main.tile[n, num8].type = tile; - Main.tile[n, num8].slope(0); - Main.tile[n, num8].liquid = 0; - Main.tile[n, num8].lava(false); - } - } - - // Replace walls in shrine area with shrine wall type - for (int num9 = shrineLocationX - randomX; num9 <= shrineLocationX + randomX; num9++) - { - for (int num10 = shrineLocationY - randomY; num10 <= shrineLocationY + randomY; num10++) - { - Main.tile[num9, num10].active(false); - Main.tile[num9, num10].wall = wall; - } - } - - // Remove tiles from the inner part of the shrine area - for (int num14 = shrineLocationX - randomX - 1; num14 <= shrineLocationX + randomX + 1; num14++) - { - for (int num15 = shrineLocationY + randomY - 2; num15 <= shrineLocationY + randomY; num15++) - Main.tile[num14, num15].active(false); - } - for (int num16 = shrineLocationX - randomX - 1; num16 <= shrineLocationX + randomX + 1; num16++) - { - for (int num17 = shrineLocationY + randomY - 2; num17 <= shrineLocationY + randomY - 1; num17++) - Main.tile[num16, num17].active(false); - } - - // Replace tiles from bottom of shrine area with shrine tile type 2 - for (int num18 = shrineLocationX - randomX - 1; num18 <= shrineLocationX + randomX + 1; num18++) - { - int num19 = 4; - int num20 = shrineLocationY + randomY + 2; - while (!Main.tile[num18, num20].active() && num20 < Main.maxTilesY && num19 > 0) - { - Main.tile[num18, num20].active(true); - Main.tile[num18, num20].type = tile2; - Main.tile[num18, num20].slope(0); - num20++; - num19--; - } - } - - // Replace tiles from top of shrine with shrine tile type 1 - randomX -= WorldGen.genRand.Next(1, 3); - int num21 = shrineLocationY - randomY - 2; - while (randomX > -1) - { - for (int num22 = shrineLocationX - randomX - 1; num22 <= shrineLocationX + randomX + 1; num22++) - { - Main.tile[num22, num21].active(true); - Main.tile[num22, num21].type = tile; - } - randomX -= WorldGen.genRand.Next(1, 3); - num21--; - } - - // Place shrine chest - CalamityWorld.SChestX[hutType] = shrineLocationX; - CalamityWorld.SChestY[hutType] = shrineLocationY; - SpecialChest(hutType); - } - #endregion - - #region SpecialChest - // Special Chest: Used for placing shrine chests, takes argument of item choice which dictates what item will spawn in the first slot of this chest - public static void SpecialChest(int itemChoice) - { - int item = 0; - int chestType = 0; - - switch (itemChoice) //0 to 9 - { - case 0: - item = ModContent.ItemType(); - break; - case 1: - item = WorldGen.crimson ? ModContent.ItemType() : ModContent.ItemType(); - chestType = WorldGen.crimson ? 43 : 3; - break; - case 2: - item = ModContent.ItemType(); - chestType = 44; - break; - case 3: - item = ModContent.ItemType(); - chestType = 47; - break; - case 4: - item = ModContent.ItemType(); - chestType = 30; - break; - case 5: - item = ModContent.ItemType(); - chestType = 32; - break; - case 6: - item = ModContent.ItemType(); - chestType = 50; - break; - case 7: - item = ModContent.ItemType(); - chestType = 51; - break; - case 8: - item = ModContent.ItemType(); - chestType = 4; - break; - } - - // Destroy tiles in chest spawn location - for (int j = CalamityWorld.SChestX[itemChoice] - 1; j <= CalamityWorld.SChestX[itemChoice] + 1; j++) - { - for (int k = CalamityWorld.SChestY[itemChoice]; k <= CalamityWorld.SChestY[itemChoice] + 2; k++) - WorldGen.KillTile(j, k, false, false, false); - } - - // Attempt to fix sloped tiles under the chest to prevent the chest from killing itself (literally) - for (int l = CalamityWorld.SChestX[itemChoice] - 1; l <= CalamityWorld.SChestX[itemChoice] + 1; l++) - { - for (int m = CalamityWorld.SChestY[itemChoice]; m <= CalamityWorld.SChestY[itemChoice] + 3; m++) - { - if (m < Main.maxTilesY) - { - Main.tile[l, m].slope(0); - Main.tile[l, m].halfBrick(false); - } - } - } - - // Place the chest, finally - WorldGen.AddBuriedChest(CalamityWorld.SChestX[itemChoice], CalamityWorld.SChestY[itemChoice], item, false, chestType); - } - #endregion - - #region ChasmGenerator - public static void ChasmGenerator(int i, int j, int steps, bool ocean = false) - { - float num = steps; //850 small 1450 medium 2050 large - if (ocean) - { - int tileYLookup = j; - if (CalamityWorld.abyssSide) - { - while (!Main.tile[i + 125, tileYLookup].active()) - { - tileYLookup++; - } - } - else - { - while (!Main.tile[i - 125, tileYLookup].active()) - { - tileYLookup++; - } - } - j = tileYLookup; - } - Vector2 vector; - vector.X = i; - vector.Y = j; - Vector2 vector2; - vector2.X = WorldGen.genRand.Next(-1, 2) * 0.1f; - vector2.Y = WorldGen.genRand.Next(3, 8) * 0.2f + 0.5f; - int num2 = 5; - double num3 = WorldGen.genRand.Next(5, 7) + 20; //start width - while (num3 > 0.0) - { - if (num > 0f) - { - num3 += WorldGen.genRand.Next(2); - num3 -= WorldGen.genRand.Next(2); - float smallHoleLimit = 790f; //small - if (Main.maxTilesY > 1500) - { smallHoleLimit = 1360f; if (Main.maxTilesY > 2100) { smallHoleLimit = 1950f; } } - if (ocean && num > smallHoleLimit) - { - if (num3 < 7.0) //min width - { - num3 = 7.0; //min width - } - if (num3 > 11.0) //max width - { - num3 = 11.0; //max width - } - } - else //dig large hole - { - if (num3 < (ocean ? 45.0 : 8.0)) //min width - { - num3 = ocean ? 45.0 : 8.0; //min width - } - if (num3 > (ocean ? 50.0 : 20.0)) //max width - { - num3 = ocean ? 50.0 : 20.0; //max width - } - if (num == 1f && num3 < (ocean ? 50.0 : 15.0)) - { - num3 = ocean ? 50.0 : 15.0; - } - } - } - else - { - if ((double)vector.Y > CalamityWorld.abyssChasmBottom) - { - num3 -= WorldGen.genRand.Next(5) + 8; - } - } - if (Main.maxTilesY > 2100) - { - if (((double)vector.Y > CalamityWorld.abyssChasmBottom && num > 0f && ocean) || - (vector.Y >= Main.maxTilesY && num > 0f && !ocean)) - { - num = 0f; - } - } - else if (Main.maxTilesY > 1500) - { - if (((double)vector.Y > CalamityWorld.abyssChasmBottom && num > 0f && ocean) || - (vector.Y > Main.maxTilesY && num > 0f && !ocean)) - { - num = 0f; - } - } - else - { - if (((double)vector.Y > CalamityWorld.abyssChasmBottom && num > 0f && ocean) || - (vector.Y > Main.maxTilesY && num > 0f && !ocean)) - { - num = 0f; - } - } - num -= 1f; - int num4; - int num5; - int num6; - int num7; - if (num > num2) - { - num4 = (int)(vector.X - num3 * 0.5); - num5 = (int)(vector.X + num3 * 0.5); - num6 = (int)(vector.Y - num3 * 0.5); - num7 = (int)(vector.Y + num3 * 0.5); - if (num4 < 0) - { - num4 = 0; - } - if (num5 > Main.maxTilesX - 1) - { - num5 = Main.maxTilesX - 1; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int k = num4; k < num5; k++) - { - for (int l = num6; l < num7; l++) - { - if ((Math.Abs(k - vector.X) + Math.Abs(l - vector.Y)) < num3 * 0.5 * (1.0 + WorldGen.genRand.Next(-5, 6) * 0.015)) - { - if (ocean) - { - Main.tile[k, l].active(false); - Main.tile[k, l].liquid = 255; - Main.tile[k, l].lava(false); - } - else - { - Main.tile[k, l].active(false); - Main.tile[k, l].liquid = 255; - Main.tile[k, l].lava(true); - } - } - } - } - } - /*if (num <= 2f && vector.Y < (Main.rockLayer + Main.maxTilesY * 0.3)) - { - num = 2f; - }*/ - vector += vector2; - vector2.X += WorldGen.genRand.Next(-1, 2) * 0.01f; - if (vector2.X > 0.02) - { - vector2.X = 0.02f; - } - if (vector2.X < -0.02) - { - vector2.X = -0.02f; - } - num4 = (int)(vector.X - num3 * 1.1); - num5 = (int)(vector.X + num3 * 1.1); - num6 = (int)(vector.Y - num3 * 1.1); - num7 = (int)(vector.Y + num3 * 1.1); - if (num4 < 1) - { - num4 = 1; - } - if (num5 > Main.maxTilesX - 1) - { - num5 = Main.maxTilesX - 1; - } - if (num6 < 0) - { - num6 = 0; - } - if (num7 > Main.maxTilesY) - { - num7 = Main.maxTilesY; - } - for (int m = num4; m < num5; m++) - { - for (int n = num6; n < num7; n++) - { - if ((Math.Abs(m - vector.X) + Math.Abs(n - vector.Y)) < num3 * 1.1 * (1.0 + WorldGen.genRand.Next(-5, 6) * 0.015)) - { - if (n > j + WorldGen.genRand.Next(7, 16)) - { - Main.tile[m, n].active(false); - } - if (steps <= num2) - { - Main.tile[m, n].active(false); - } - if (ocean) - { - Main.tile[m, n].liquid = 255; - Main.tile[m, n].lava(false); - } - else - { - Main.tile[m, n].liquid = 255; - Main.tile[m, n].lava(true); - } - } - } - } - for (int num11 = num4; num11 < num5; num11++) - { - for (int num12 = num6; num12 < num7; num12++) - { - if ((Math.Abs(num11 - vector.X) + Math.Abs(num12 - vector.Y)) < num3 * 1.1 * (1.0 + WorldGen.genRand.Next(-5, 6) * 0.015)) - { - if (ocean) - { - Main.tile[num11, num12].liquid = 255; - Main.tile[num11, num12].lava(false); - } - else - { - Main.tile[num11, num12].liquid = 255; - Main.tile[num11, num12].lava(true); - } - if (steps <= num2) - { - Main.tile[num11, num12].active(false); - } - } - } - } - } - } - #endregion - - #region PlaceTits - public static void PlaceTit(int x, int y, ushort type = 165) - { - if (Main.tile[x, y - 1] == null) - { - Main.tile[x, y - 1] = new Tile(); - } - if (Main.tile[x, y] == null) - { - Main.tile[x, y] = new Tile(); - } - if (Main.tile[x, y + 1] == null) - { - Main.tile[x, y + 1] = new Tile(); - } - if (WorldGen.SolidTile(x, y - 1) && !Main.tile[x, y].active() && !Main.tile[x, y + 1].active()) - { - if (Main.tile[x, y - 1].type == (ushort)ModContent.TileType()) - { - if (WorldGen.genRand.Next(2) == 0 || Main.tile[x, y + 2].active()) - { - int num2 = WorldGen.genRand.Next(3) * 18; - Main.tile[x, y].type = type; - Main.tile[x, y].active(true); - Main.tile[x, y].frameX = (short)num2; - Main.tile[x, y].frameY = 72; - } - else - { - int num3 = WorldGen.genRand.Next(3) * 18; - Main.tile[x, y].type = type; - Main.tile[x, y].active(true); - Main.tile[x, y].frameX = (short)num3; - Main.tile[x, y].frameY = 0; - Main.tile[x, y + 1].type = type; - Main.tile[x, y + 1].active(true); - Main.tile[x, y + 1].frameX = (short)num3; - Main.tile[x, y + 1].frameY = 18; - } - } - } - else - { - if (WorldGen.SolidTile(x, y + 1) && !Main.tile[x, y].active() && !Main.tile[x, y - 1].active()) - { - if (Main.tile[x, y + 1].type == (ushort)ModContent.TileType()) - { - if (WorldGen.genRand.Next(2) == 0 || Main.tile[x, y - 2].active()) - { - int num13 = WorldGen.genRand.Next(3) * 18; - Main.tile[x, y].type = type; - Main.tile[x, y].active(true); - Main.tile[x, y].frameX = (short)num13; - Main.tile[x, y].frameY = 90; - } - else - { - int num14 = WorldGen.genRand.Next(3) * 18; - Main.tile[x, y - 1].type = type; - Main.tile[x, y - 1].active(true); - Main.tile[x, y - 1].frameX = (short)num14; - Main.tile[x, y - 1].frameY = 36; - Main.tile[x, y].type = type; - Main.tile[x, y].active(true); - Main.tile[x, y].frameX = (short)num14; - Main.tile[x, y].frameY = 54; - } - } - } - } - } - #endregion - - #region Planetoids - - public static void GenerateLuminitePlanetoids() - { - // Don't attempt to generate these things client-side. - if (Main.netMode == NetmodeID.MultiplayerClient) - return; - - // The worldgen structure map only gets created/regenerated when you generate a world, for some reason. - // This means if you simply enter a world and generate this planetoid, the map will not exist yet, and errors will arise. - // As a result, a new one is generated as necessary. - if (WorldGen.structures is null) - WorldGen.structures = new StructureMap(); - - int totalPlanetoidsToGenerate = Main.maxTilesX / 4200 + 1; - for (int i = 0; i < totalPlanetoidsToGenerate; i++) - { - for (int tries = 0; tries < 3000; tries++) - { - Point planetoidOrigin = new Point(WorldGen.genRand.Next(Main.maxTilesX / 2 - 700, Main.maxTilesX / 2 + 700), WorldGen.genRand.Next(85, 110)); - if (WorldGen.genRand.NextBool(2)) - { - if (Biomes.Place(planetoidOrigin, WorldGen.structures)) - break; - } - else - { - if (Biomes.Place(planetoidOrigin, WorldGen.structures)) - break; - } - } - } - } - - public static void Planetoids(GenerationProgress progress) - { - progress.Message = "Generating Planetoids..."; - - int GrassPlanetoidCount = Main.maxTilesX / 1100; - int LCPlanetoidCount = Main.maxTilesX / 800; - int MudPlanetoidCount = Main.maxTilesX / 1100; - - const int MainPlanetoidAttempts = 3000; - int i = 0; - while (i < MainPlanetoidAttempts) - { - if (Biomes.Place(new Point(WorldGen.genRand.Next(Main.maxTilesX / 2 - 300, Main.maxTilesX / 2 + 300), WorldGen.genRand.Next(128, 134)), WorldGen.structures)) - { - break; - } - i++; - } - - const int CrystalHeartPlanetoidAttempts = 15000; - i = 0; - while (LCPlanetoidCount > 0 && i < CrystalHeartPlanetoidAttempts) - { - int x = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.2), (int)(Main.maxTilesX * 0.8)); - int y = WorldGen.genRand.Next(70, 101); - - bool placed = Biomes.Place(x, y, WorldGen.structures); - - if (placed) - LCPlanetoidCount--; - i++; - } - - const int GrassPlanetoidAttempts = 12000; - i = 0; - while (GrassPlanetoidCount > 0 && i < GrassPlanetoidAttempts) - { - int x = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.333), (int)(Main.maxTilesX * 0.666)); - int y = WorldGen.genRand.Next(100, 131); - - - bool placed = Biomes.Place(x, y, WorldGen.structures); - - if (placed) - GrassPlanetoidCount--; - i++; - } - - const int MudPlanetoidAttempts = 12000; - i = 0; - while (MudPlanetoidCount > 0 && i < MudPlanetoidAttempts) - { - int x = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.3f), (int)(Main.maxTilesX * 0.7f)); - int y = WorldGen.genRand.Next(100, 131); - - bool placed = Biomes.Place(x, y, WorldGen.structures); - - if (placed) - MudPlanetoidCount--; - i++; - } - } - #endregion - } -} diff --git a/World/WorldUpdateMiscEffects.cs b/World/WorldUpdateMiscEffects.cs new file mode 100644 index 0000000000..e1713d1aee --- /dev/null +++ b/World/WorldUpdateMiscEffects.cs @@ -0,0 +1,807 @@ +using CalamityMod.CalPlayer; +using CalamityMod.DataStructures; +using CalamityMod.Events; +using CalamityMod.NPCs; +using CalamityMod.NPCs.Abyss; +using CalamityMod.NPCs.AstrumAureus; +using CalamityMod.NPCs.Bumblebirb; +using CalamityMod.NPCs.Calamitas; +using CalamityMod.NPCs.CeaselessVoid; +using CalamityMod.NPCs.Crabulon; +using CalamityMod.NPCs.Cryogen; +using CalamityMod.NPCs.DesertScourge; +using CalamityMod.NPCs.DevourerofGods; +using CalamityMod.NPCs.HiveMind; +using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.Perforator; +using CalamityMod.NPCs.ProfanedGuardians; +using CalamityMod.NPCs.Signus; +using CalamityMod.NPCs.StormWeaver; +using CalamityMod.Tiles; +using CalamityMod.Tiles.Abyss; +using CalamityMod.Tiles.SunkenSea; +using Microsoft.Xna.Framework; +using System; +using System.Linq; +using Terraria; +using Terraria.GameContent.Events; +using Terraria.ID; +using Terraria.ModLoader; + +using static CalamityMod.World.CalamityWorld; + +namespace CalamityMod.World +{ + public class WorldUpdateMiscEffects + { + public static void PerformWorldUpdates() + { + // Sunken Sea Location...duh + SunkenSeaLocation = new Rectangle(WorldGen.UndergroundDesertLocation.Left, WorldGen.UndergroundDesertLocation.Bottom, WorldGen.UndergroundDesertLocation.Width, WorldGen.UndergroundDesertLocation.Height / 2); + + // Player variable, always finds the closest player relative to the center of the map + int closestPlayer = Player.FindClosest(new Vector2(Main.maxTilesX / 2, (float)Main.worldSurface / 2f) * 16f, 0, 0); + Player player = Main.player[closestPlayer]; + CalamityPlayer modPlayer = player.Calamity(); + + // Force boss rush to off if necessary. + if (!BossRushEvent.DeactivateStupidFuckingBullshit) + { + BossRushEvent.DeactivateStupidFuckingBullshit = true; + BossRushEvent.BossRushActive = false; + CalamityNetcode.SyncWorld(); + } + + // Handle Acid Rain update logic. + if (rainingAcid) + AcidRainEvent.Update(); + else + { + if (timeSinceAcidStarted != 0) + timeSinceAcidStarted = 0; + startAcidicDownpour = false; + } + + // Lumenyl crystal, tenebris spread and sea prism crystal spawn rates + HandleTileGrowth(); + + // Update Boss Rush. + BossRushEvent.Update(); + + // Handle Phase 2 DoG's summon-code, for both DoG directly and his sentinels. + HandleDoGP2Countdown(player); + + // Handle conditional summons. + TrySpawnArmoredDigger(player, modPlayer); + TrySpawnDungeonGuardian(player); + TrySpawnAEoW(player, modPlayer); + TrySpawnRandomDeathmodeBosses(player, modPlayer); + + // Very, very, very rarely display a Lorde joke text if the system clock is set to April Fools Day. + if (Main.rand.NextBool(100000000) && DateTime.Now.Month == 4 && DateTime.Now.Day == 1) + { + string key = "Mods.CalamityMod.AprilFools"; + Color messageColor = Color.Crimson; + CalamityUtils.DisplayLocalizedText(key, messageColor); + } + + // Disable sandstorms if the Desert Scourge is still alive and Hardmode hasn't begun. + if (!downedDesertScourge && Main.netMode != NetmodeID.MultiplayerClient && !Main.hardMode) + CalamityUtils.StopSandstorm(); + + // Make the cultist countdown happen much more quickly. + if (Main.netMode != NetmodeID.MultiplayerClient) + { + CultistRitual.delay -= Main.dayRate * 10; + CultistRitual.recheck -= Main.dayRate * 10; + if (CultistRitual.recheck < 0) + CultistRitual.recheck = 0; + if (CultistRitual.delay < 0) + CultistRitual.delay = 0; + } + } + + #region Handle Tile Growing + + public static void HandleTileGrowth() + { + int l = 0; + float mult2 = 1.5E-05f * Main.worldRate; + while (l < Main.maxTilesX * Main.maxTilesY * mult2) + { + int x = WorldGen.genRand.Next(10, Main.maxTilesX - 10); + int y = WorldGen.genRand.Next((int)Main.worldSurface - 1, Main.maxTilesY - 20); + + int y2 = y - 1; + if (y2 < 10) + y2 = 10; + + if (Main.tile[x, y] != null) + { + if (Main.tile[x, y].nactive()) + { + if (Main.tile[x, y].liquid <= 32) + { + if (Main.tile[x, y].type == TileID.JungleGrass) + { + if (Main.tile[x, y2].liquid == 0) + { + // Plantera Bulbs pre-mech + if (WorldGen.genRand.Next(1500) == 0) + { + if (Main.hardMode && (!NPC.downedMechBoss1 || !NPC.downedMechBoss2 || !NPC.downedMechBoss3)) + { + bool placeBulb = true; + int minDistanceFromOtherBulbs = 150; + for (int i = x - minDistanceFromOtherBulbs; i < x + minDistanceFromOtherBulbs; i += 2) + { + for (int j = y - minDistanceFromOtherBulbs; j < y + minDistanceFromOtherBulbs; j += 2) + { + if (i > 1 && i < Main.maxTilesX - 2 && j > 1 && j < Main.maxTilesY - 2 && Main.tile[i, j].active() && Main.tile[i, j].type == TileID.PlanteraBulb) + { + placeBulb = false; + break; + } + } + } + + if (placeBulb) + { + WorldGen.PlaceJunglePlant(x, y2, TileID.PlanteraBulb, 0, 0); + WorldGen.SquareTileFrame(x, y2); + WorldGen.SquareTileFrame(x + 2, y2); + WorldGen.SquareTileFrame(x - 1, y2); + if (Main.tile[x, y2].type == TileID.PlanteraBulb && Main.netMode == NetmodeID.Server) + { + NetMessage.SendTileSquare(-1, x, y2, 5); + } + } + } + } + + // Life Fruit pre-mech + int random = Main.expertMode ? 90 : 120; + if (WorldGen.genRand.Next(random) == 0) + { + if (Main.hardMode && !NPC.downedMechBossAny) + { + bool placeFruit = true; + int minDistanceFromOtherFruit = Main.expertMode ? 50 : 60; + for (int i = x - minDistanceFromOtherFruit; i < x + minDistanceFromOtherFruit; i += 2) + { + for (int j = y - minDistanceFromOtherFruit; j < y + minDistanceFromOtherFruit; j += 2) + { + if (i > 1 && i < Main.maxTilesX - 2 && j > 1 && j < Main.maxTilesY - 2 && Main.tile[i, j].active() && Main.tile[i, j].type == TileID.LifeFruit) + { + placeFruit = false; + break; + } + } + } + + if (placeFruit) + { + WorldGen.PlaceJunglePlant(x, y2, TileID.LifeFruit, WorldGen.genRand.Next(3), 0); + WorldGen.SquareTileFrame(x, y2); + WorldGen.SquareTileFrame(x + 1, y2 + 1); + if (Main.tile[x, y2].type == TileID.LifeFruit && Main.netMode == NetmodeID.Server) + { + NetMessage.SendTileSquare(-1, x, y2, 4); + } + } + } + } + } + } + } + + int tileType = Main.tile[x, y].type; + bool tenebris = tileType == ModContent.TileType() && downedCalamitas; + + if (CalamityGlobalTile.GrowthTiles.Contains(tileType) || tenebris) + { + int growthChance = tenebris ? 4 : 2; + if (tileType == ModContent.TileType()) + growthChance *= 5; + + if (Main.rand.NextBool(growthChance)) + { + switch (WorldGen.genRand.Next(4)) + { + case 0: + x++; + break; + case 1: + x--; + break; + case 2: + y++; + break; + case 3: + y--; + break; + default: + break; + } + + if (Main.tile[x, y] != null) + { + Tile tile = Main.tile[x, y]; + bool growTile = tenebris ? (tile.active() && tile.type == ModContent.TileType()) : (!tile.active() && tile.liquid >= 128); + bool isSunkenSeaTile = tileType == ModContent.TileType() || tileType == ModContent.TileType() || tileType == ModContent.TileType(); + bool meetsAdditionalGrowConditions = tile.slope() == 0 && !tile.halfBrick() && !tile.lava(); + + if (growTile && meetsAdditionalGrowConditions) + { + int tileType2 = ModContent.TileType(); + + if (tileType == ModContent.TileType()) + tileType2 = ModContent.TileType(); + + bool canPlaceBasedOnAttached = true; + if (tileType2 == ModContent.TileType() && !isSunkenSeaTile) + canPlaceBasedOnAttached = false; + + if (canPlaceBasedOnAttached && (CanPlaceBasedOnProximity(x, y, tileType2) || tenebris)) + { + tile.type = tenebris ? (ushort)tileType : (ushort)tileType2; + + if (!tenebris) + { + tile.active(true); + if (Main.tile[x, y + 1].active() && Main.tileSolid[Main.tile[x, y + 1].type] && Main.tile[x, y + 1].slope() == 0 && !Main.tile[x, y + 1].halfBrick()) + { + tile.frameY = 0; + } + else if (Main.tile[x, y - 1].active() && Main.tileSolid[Main.tile[x, y - 1].type] && Main.tile[x, y - 1].slope() == 0 && !Main.tile[x, y - 1].halfBrick()) + { + tile.frameY = 18; + } + else if (Main.tile[x + 1, y].active() && Main.tileSolid[Main.tile[x + 1, y].type] && Main.tile[x + 1, y].slope() == 0 && !Main.tile[x + 1, y].halfBrick()) + { + tile.frameY = 36; + } + else if (Main.tile[x - 1, y].active() && Main.tileSolid[Main.tile[x - 1, y].type] && Main.tile[x - 1, y].slope() == 0 && !Main.tile[x - 1, y].halfBrick()) + { + tile.frameY = 54; + } + tile.frameX = (short)(WorldGen.genRand.Next(18) * 18); + } + + WorldGen.SquareTileFrame(x, y); + + if (Main.netMode == NetmodeID.Server) + NetMessage.SendTileSquare(-1, x, y, 1, TileChangeType.None); + } + } + } + } + } + } + } + l++; + } + + } + + public static bool CanPlaceBasedOnProximity(int x, int y, int tileType) + { + if (tileType == ModContent.TileType() && !downedCalamitas) + return false; + + int minDistanceFromOtherTiles = 6; + int sameTilesNearby = 0; + for (int i = x - minDistanceFromOtherTiles; i < x + minDistanceFromOtherTiles; i++) + { + for (int j = y - minDistanceFromOtherTiles; j < y + minDistanceFromOtherTiles; j++) + { + if (Main.tile[i, j].active() && Main.tile[i, j].type == tileType) + { + sameTilesNearby++; + if (sameTilesNearby > 1) + return false; + } + } + } + + return true; + } + #endregion + + #region Handle Phase 2 DoG's Summoning + public static void HandleDoGP2Countdown(Player player) + { + if (DoGSecondStageCountdown <= 0) + return; + + DoGSecondStageCountdown--; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + if (DoGSecondStageCountdown == 21540) + CalamityUtils.SpawnBossBetter(player.Center, ModContent.NPCType(), new OffscreenBossSpawnContext()); + if (DoGSecondStageCountdown == 14340) + CalamityUtils.SpawnBossBetter(player.Center, ModContent.NPCType(), new OffscreenBossSpawnContext()); + if (DoGSecondStageCountdown == 7140) + CalamityUtils.SpawnBossBetter(player.Center, ModContent.NPCType(), new OffscreenBossSpawnContext()); + + if (DoGSecondStageCountdown <= 60) + { + int freeNPCSlots = Main.maxNPCs - Main.npc.Take(Main.maxNPCs).Where(npc => npc.active).Count(); + + // If there are too many slots occupied, make a note in the logs, + // and don't attempt to spawn the Devourer of Gods. + if (freeNPCSlots < 102) + { + CalamityMod.Instance.Logger.Warn("You have too many occupied NPC slots for DoG to spawn. Remove dummies or kill excessive town NPCs."); + DoGSecondStageCountdown = 0; + } + else if (!NPC.AnyNPCs(ModContent.NPCType())) + { + NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + string key = "Mods.CalamityMod.EdgyBossText10"; + Color messageColor = Color.Cyan; + CalamityUtils.DisplayLocalizedText(key, messageColor); + } + } + } + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.DoGCountdownSync); + netMessage.Write(DoGSecondStageCountdown); + netMessage.Send(); + } + } + #endregion + + #region Handle Armored Digger Random Spawns + public static void TrySpawnArmoredDigger(Player player, CalamityPlayer modPlayer) + { + if (player.ZoneRockLayerHeight && !player.ZoneUnderworldHeight && !player.ZoneDungeon && !player.ZoneJungle && !modPlayer.ZoneSunkenSea && !modPlayer.ZoneAbyss && !CalamityPlayer.areThereAnyDamnBosses) + { + if (NPC.downedPlantBoss && player.townNPCs < 3f) + { + double spawnRate = 100000D; + + if (revenge) + spawnRate *= 0.85D; + + if (demonMode) + spawnRate *= 0.75D; + + if (death && Main.bloodMoon) + spawnRate *= 0.2D; + if (modPlayer.zerg) + spawnRate *= 0.5D; + if (modPlayer.chaosCandle) + spawnRate *= 0.6D; + if (player.enemySpawns) + spawnRate *= 0.7D; + if (Main.waterCandles > 0) + spawnRate *= 0.8D; + + if (modPlayer.bossZen || DoGSecondStageCountdown > 0) + spawnRate *= 50D; + if (modPlayer.zen || (CalamityConfig.Instance.DisableExpertTownSpawns && player.townNPCs > 1f && Main.expertMode)) + spawnRate *= 2D; + if (modPlayer.tranquilityCandle) + spawnRate *= 1.67D; + if (player.calmed) + spawnRate *= 1.43D; + if (Main.peaceCandles > 0) + spawnRate *= 1.25D; + + int chance = (int)spawnRate; + if (Main.rand.NextBool(chance)) + { + if (!NPC.AnyNPCs(ModContent.NPCType()) && Main.netMode != NetmodeID.MultiplayerClient && + ArmoredDiggerSpawnCooldown <= 0) + { + NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + ArmoredDiggerSpawnCooldown = 3600; + } + } + } + } + if (ArmoredDiggerSpawnCooldown > 0) + { + ArmoredDiggerSpawnCooldown--; + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.ArmoredDiggerCountdownSync); + netMessage.Write(ArmoredDiggerSpawnCooldown); + netMessage.Send(); + } + } + } + #endregion + + #region Handle Dungeon Guardian Spawns + public static void TrySpawnDungeonGuardian(Player player) + { + if (Main.netMode == NetmodeID.MultiplayerClient || !player.ZoneDungeon || NPC.downedBoss3 || player.dead) + return; + + if (!NPC.AnyNPCs(NPCID.DungeonGuardian)) + NPC.SpawnOnPlayer(player.whoAmI, NPCID.DungeonGuardian); //your hell is as vast as my bonergrin, pray your life ends quickly + } + #endregion + + #region Handle Adult Eidolon Wyrm Spawns + public static void TrySpawnAEoW(Player player, CalamityPlayer modPlayer) + { + if (Main.netMode == NetmodeID.MultiplayerClient || !modPlayer.ZoneAbyss || !player.chaosState || player.dead) + return; + + bool adultWyrmAlive = CalamityGlobalNPC.adultEidolonWyrmHead != -1 && Main.npc[CalamityGlobalNPC.adultEidolonWyrmHead].active; + if (!adultWyrmAlive) + NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + } + #endregion + + #region Handle Deathmode Random Boss Spawns + + public static void TrySpawnRandomDeathmodeBosses(Player player, CalamityPlayer modPlayer) + { + void BossText() + { + string key = "Mods.CalamityMod.BossSpawnText"; + Color messageColor = Color.Crimson; + CalamityUtils.DisplayLocalizedText(key, messageColor); + } + + //does not occur while a boss is alive or during certain events) + if (death && !CalamityPlayer.areThereAnyDamnBosses && !Main.snowMoon && !Main.pumpkinMoon && !DD2Event.Ongoing && player.statLifeMax2 >= 300 && !WorldGen.spawnEye && WorldGen.spawnHardBoss <= 0) + return; + if (bossSpawnCountdown <= 0 && deathBossSpawnCooldown <= 0) // Check for countdown and cooldown being 0 + { + if (Main.rand.NextBool(50000)) + { + // Only set countdown and boss type if conditions are met + // Night time bosses set message only before 11pm. Day time bosses only before 2pm. + if (!NPC.downedBoss1 && bossType == 0) + if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) + { + BossText(); + bossType = NPCID.EyeofCthulhu; + bossSpawnCountdown = 3600; // 1 minute + } + + if (!NPC.downedBoss2 && bossType == 0) + if (player.ZoneCorrupt) + { + BossText(); + bossType = NPCID.EaterofWorldsHead; + bossSpawnCountdown = 3600; + } + + if (!NPC.downedBoss2 && bossType == 0) + if (player.ZoneCrimson) + { + BossText(); + bossType = NPCID.BrainofCthulhu; + bossSpawnCountdown = 3600; + } + + /*if (!NPC.downedQueenBee && bossType == 0) + if (player.ZoneJungle && !player.ZoneOverworldHeight && !player.ZoneSkyHeight) + { + BossText(); + bossType = NPCID.QueenBee; + bossSpawnCountdown = 3600; + }*/ + + if (!downedDesertScourge && bossType == 0) + if (player.ZoneDesert) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + if (!downedPerforator && bossType == 0) + if (player.ZoneCrimson) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + if (!downedHiveMind && bossType == 0) + if (player.ZoneCorrupt) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + if (!downedCrabulon && bossType == 0) + if (player.ZoneGlowshroom) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + if (Main.hardMode) + { + if (!NPC.downedMechBoss1 && bossType == 0) + if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) + { + BossText(); + bossType = NPCID.TheDestroyer; + bossSpawnCountdown = 3600; + } + + if (!NPC.downedMechBoss2 && bossType == 0) + if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) + { + BossText(); + bossType = NPCID.Spazmatism; + bossSpawnCountdown = 3600; + } + + if (!NPC.downedMechBoss3 && bossType == 0) + if (!Main.dayTime && (player.ZoneOverworldHeight || player.ZoneSkyHeight) && Main.time < 12600) + { + BossText(); + bossType = NPCID.SkeletronPrime; + bossSpawnCountdown = 3600; + } + + if (!NPC.downedPlantBoss && bossType == 0) + if (player.ZoneJungle && !player.ZoneOverworldHeight && !player.ZoneSkyHeight) + { + BossText(); + bossType = NPCID.Plantera; + bossSpawnCountdown = 3600; + } + + if (!NPC.downedFishron && bossType == 0) + if (player.ZoneBeach && !modPlayer.ZoneSulphur) + { + BossText(); + bossType = NPCID.DukeFishron; + bossSpawnCountdown = 3600; + } + + if (!downedCryogen && bossType == 0) + if (player.ZoneSnow && player.ZoneOverworldHeight) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + if (!downedCalamitas && bossType == 0) + if (!Main.dayTime && player.ZoneOverworldHeight && Main.time < 12600) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + if (!downedAstrageldon && bossType == 0) + if (modPlayer.ZoneAstral && + !Main.dayTime && player.ZoneOverworldHeight) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + /*if (!downedPlaguebringer && bossType == 0) + if (player.ZoneJungle && NPC.downedGolemBoss && !player.ZoneOverworldHeight && !player.ZoneSkyHeight) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + }*/ + + if (NPC.downedMoonlord) + { + if (!downedGuardians && bossType == 0) + if (Main.dayTime && (player.ZoneUnderworldHeight || + (player.ZoneHoly && player.ZoneOverworldHeight)) && Main.time < 34200) //only before 2pm + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + + if (!downedBumble && bossType == 0) + if (player.ZoneJungle && player.ZoneOverworldHeight) + { + BossText(); + bossType = ModContent.NPCType(); + bossSpawnCountdown = 3600; + } + } + } + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.BossSpawnCountdownSync); + netMessage.Write(bossSpawnCountdown); + netMessage.Send(); + var netMessage2 = CalamityMod.Instance.GetPacket(); + netMessage2.Write((byte)CalamityModMessageType.BossTypeSync); + netMessage2.Write(bossType); + netMessage2.Send(); + } + } + } + else + { + if (bossSpawnCountdown > 0) + { + bossSpawnCountdown--; + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.BossSpawnCountdownSync); + netMessage.Write(bossSpawnCountdown); + netMessage.Send(); + } + } + + if (bossSpawnCountdown <= 0 && deathBossSpawnCooldown <= 0) // Check both cooldowns again here to avoid infinite message possibilities + { + bool canSpawn = true; + switch (bossType) + { + case NPCID.EyeofCthulhu: + if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) + canSpawn = false; + break; + case NPCID.EaterofWorldsHead: + if (!player.ZoneCorrupt) + canSpawn = false; + break; + case NPCID.BrainofCthulhu: + if (!player.ZoneCrimson) + canSpawn = false; + break; + /*case NPCID.QueenBee: + if (!player.ZoneJungle || player.ZoneOverworldHeight || player.ZoneSkyHeight) + canSpawn = false; + break;*/ + case NPCID.TheDestroyer: + if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) + canSpawn = false; + break; + case NPCID.Spazmatism: + if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) + canSpawn = false; + break; + case NPCID.SkeletronPrime: + if (Main.dayTime || (!player.ZoneOverworldHeight && !player.ZoneSkyHeight) || Main.time > 16200) + canSpawn = false; + break; + case NPCID.Plantera: + if (!player.ZoneJungle || player.ZoneOverworldHeight || player.ZoneSkyHeight) + canSpawn = false; + break; + case NPCID.DukeFishron: + if (!player.ZoneBeach) + canSpawn = false; + break; + } + + if (bossType == ModContent.NPCType()) + { + if (!player.ZoneDesert) + canSpawn = false; + } + else if (bossType == ModContent.NPCType()) + { + if (!player.ZoneCrimson) + canSpawn = false; + } + else if (bossType == ModContent.NPCType()) + { + if (!player.ZoneCorrupt) + canSpawn = false; + } + else if (bossType == ModContent.NPCType()) + { + if (!player.ZoneGlowshroom) + canSpawn = false; + } + else if (bossType == ModContent.NPCType()) + { + if (!player.ZoneSnow || !player.ZoneOverworldHeight) + canSpawn = false; + } + else if (bossType == ModContent.NPCType()) + { + if (Main.dayTime || !player.ZoneOverworldHeight || Main.time > 16200) + canSpawn = false; + } + else if (bossType == ModContent.NPCType()) + { + if (!modPlayer.ZoneAstral || + Main.dayTime || !player.ZoneOverworldHeight) + canSpawn = false; + } + /*else if (bossType == ModContent.NPCType()) + { + if (!player.ZoneJungle || player.ZoneOverworldHeight || player.ZoneSkyHeight) + canSpawn = false; + }*/ + else if (bossType == ModContent.NPCType()) + { + if (!Main.dayTime || (!player.ZoneUnderworldHeight && + (!player.ZoneHoly || !player.ZoneOverworldHeight)) || Main.time > 37800) + canSpawn = false; + } + else if (bossType == ModContent.NPCType()) + { + if (!player.ZoneJungle || !player.ZoneOverworldHeight) + canSpawn = false; + } + + if (canSpawn) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + if (bossType == NPCID.Spazmatism) + NPC.SpawnOnPlayer(player.whoAmI, NPCID.Retinazer); + else if (bossType == ModContent.NPCType()) + { + NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + } + else if (bossType == ModContent.NPCType()) + { + NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + } + if (bossType == NPCID.DukeFishron) + { + NPC.NewNPC((int)player.Center.X - 300, (int)player.Center.Y - 300, bossType); + } + else + { + NPC.SpawnOnPlayer(player.whoAmI, bossType); + } + } + + deathBossSpawnCooldown = 86400; // 24 minutes (1 full Terraria day) + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.DeathBossSpawnCountdownSync); + netMessage.Write(deathBossSpawnCooldown); + netMessage.Send(); + } + } + + bossType = 0; + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.BossTypeSync); + netMessage.Write(bossType); + netMessage.Send(); + } + } + + // IMPORTANT! Decrement this cooldown AFTER everything else to avoid infinite possibilities + if (deathBossSpawnCooldown > 0) + { + deathBossSpawnCooldown--; + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.DeathBossSpawnCountdownSync); + netMessage.Write(deathBossSpawnCooldown); + netMessage.Send(); + } + } + } + } + #endregion + } +}