diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index bacecd2c19..b10a025e4b 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -906,7 +906,6 @@ namespace CalamityMod.CalPlayer public bool brimseeker = false; public bool necrosteocytesDudes = false; public bool gammaHead = false; - public List GammaCanisters = new List(); public bool rustyDrone = false; public bool tundraFlameBlossom = false; public bool starSwallowerPetFroge = false; @@ -7232,8 +7231,15 @@ namespace CalamityMod.CalPlayer if (CalamityWorld.revenge && CalamityConfig.Instance.Rippers && shatteredCommunity && rageGainCooldown == 0) { float HPRatio = (float)damage / player.statLifeMax2; + float rageConversionRatio = 0.8f; + // Damage to rage conversion is half as effective while Rage Mode is active. - float rageConversionRatio = rageModeActive ? 0.4f : 0.8f; + if (rageModeActive) + rageConversionRatio *= 0.5f; + // If Rage is over 100%, damage to rage conversion scales down asymptotically based on how full Rage is. + if (rage >= rageMax) + rageConversionRatio *= 3f / (3f + rage / rageMax); + rage += rageMax * HPRatio * rageConversionRatio; rageGainCooldown = DefaultRageGainCooldown; // Rage capping is handled in MiscEffects diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 931eef0274..4e8c11ab33 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -2536,9 +2536,6 @@ namespace CalamityMod.CalPlayer player.lavaMax += 240; } - if (modPlayer.eQuiver) - player.magicQuiver = true; - if (modPlayer.bloodPactBoost) { player.allDamage += 0.05f; diff --git a/CalPlayer/CalamityPlayerNetcode.cs b/CalPlayer/CalamityPlayerNetcode.cs index 99942f33bc..add54032ae 100644 --- a/CalPlayer/CalamityPlayerNetcode.cs +++ b/CalPlayer/CalamityPlayerNetcode.cs @@ -250,14 +250,14 @@ namespace CalamityMod.CalPlayer internal void HandleRage(BinaryReader reader) { - rage = reader.ReadInt32(); + rage = reader.ReadSingle(); if (Main.netMode == NetmodeID.Server) SyncRage(true); } internal void HandleAdrenaline(BinaryReader reader) { - adrenaline = reader.ReadInt32(); + adrenaline = reader.ReadSingle(); if (Main.netMode == NetmodeID.Server) SyncAdrenaline(true); } diff --git a/CalPlayer/CalamityPlayerOnHit.cs b/CalPlayer/CalamityPlayerOnHit.cs index f4400b693b..dc7f1ac2b2 100644 --- a/CalPlayer/CalamityPlayerOnHit.cs +++ b/CalPlayer/CalamityPlayerOnHit.cs @@ -110,24 +110,6 @@ namespace CalamityMod.CalPlayer modPlayer.bloodflareMeleeHits++; } } - if (CalamityWorld.revenge && CalamityConfig.Instance.Rippers) - { - int stressGain = (int)(damage * 0.1); - int stressMaxGain = 10; - if (stressGain < 1) - { - stressGain = 1; - } - if (stressGain > stressMaxGain) - { - stressGain = stressMaxGain; - } - modPlayer.rage += stressGain; - if (modPlayer.rage >= modPlayer.rageMax) - { - modPlayer.rage = modPlayer.rageMax; - } - } } } } @@ -237,27 +219,6 @@ namespace CalamityMod.CalPlayer modPlayer.bloodflareMeleeHits++; } } - if (CalamityWorld.revenge && CalamityConfig.Instance.Rippers) - { - if (modProj.trueMelee) - { - int stressGain = (int)(proj.damage * 0.1); - int stressMaxGain = 10; - if (stressGain < 1) - { - stressGain = 1; - } - if (stressGain > stressMaxGain) - { - stressGain = stressMaxGain; - } - modPlayer.rage += stressGain; - if (modPlayer.rage >= modPlayer.rageMax) - { - modPlayer.rage = modPlayer.rageMax; - } - } - } } } #endregion diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 30f41c4725..407dc6b42c 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -12,7 +12,8 @@ namespace CalamityMod.Effects public static Effect LightShader; public static Effect TentacleShader; public static Effect LightDistortionShader; - + public static Effect FadedUVMapStreakShader; + public static void LoadShaders() { if (Main.dedServ) @@ -21,6 +22,7 @@ namespace CalamityMod.Effects LightShader = CalamityMod.Instance.GetEffect("Effects/LightBurstShader"); TentacleShader = CalamityMod.Instance.GetEffect("Effects/TentacleShader"); LightDistortionShader = CalamityMod.Instance.GetEffect("Effects/DistortionShader"); + FadedUVMapStreakShader = CalamityMod.Instance.GetEffect("Effects/FadedUVMapStreak"); Filters.Scene["CalamityMod:Astral"] = new Filter(new AstralScreenShaderData(new Ref(AstralFogShader), "AstralPass").UseColor(0.18f, 0.08f, 0.24f), EffectPriority.VeryHigh); @@ -29,6 +31,7 @@ namespace CalamityMod.Effects GameShaders.Misc["CalamityMod:SubsumingTentacle"] = new MiscShaderData(new Ref(TentacleShader), "BurstPass"); GameShaders.Misc["CalamityMod:LightDistortion"] = new MiscShaderData(new Ref(LightDistortionShader), "DistortionPass"); + GameShaders.Misc["CalamityMod:TrailStreak"] = new MiscShaderData(new Ref(FadedUVMapStreakShader), "TrailPass"); } } } diff --git a/Effects/FadedUVMapStreak.fx b/Effects/FadedUVMapStreak.fx new file mode 100644 index 0000000000..497063c9da --- /dev/null +++ b/Effects/FadedUVMapStreak.fx @@ -0,0 +1,72 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput)0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + // Read the fade map as a streak. + float4 fadeMapColor = tex2D(uImage1, float2(frac(coords.x - uTime * 2.5), coords.y)); + float opacity = fadeMapColor.r; + + // Fade out at the edges of the trail to give a blur effect. + // This is very important. + float power = lerp(3, 10, coords.x); + opacity = lerp(pow(sin(coords.y * 3.141), power), opacity, coords.x); + + // Fade out at the end of the streak. + if (coords.x > 0.7) + opacity *= pow(1 - (coords.x - 0.7) / 0.3, 6); + return color * opacity * 1.5; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/FadedUVMapStreak.xnb b/Effects/FadedUVMapStreak.xnb new file mode 100644 index 0000000000..45b95d5d3f Binary files /dev/null and b/Effects/FadedUVMapStreak.xnb differ diff --git a/ExtraTextures/TelluricGlareStreak.png b/ExtraTextures/TelluricGlareStreak.png new file mode 100644 index 0000000000..7793d1e456 Binary files /dev/null and b/ExtraTextures/TelluricGlareStreak.png differ diff --git a/Items/Accessories/ElementalQuiver.cs b/Items/Accessories/ElementalQuiver.cs index 51e18ed2b2..9d28759915 100644 --- a/Items/Accessories/ElementalQuiver.cs +++ b/Items/Accessories/ElementalQuiver.cs @@ -12,10 +12,9 @@ namespace CalamityMod.Items.Accessories public override void SetStaticDefaults() { DisplayName.SetDefault("Elemental Quiver"); - Tooltip.SetDefault("Ranged projectiles have a chance to split\n" + - "15% increased ranged damage, 5% increased ranged critical strike chance, and 20% reduced ammo usage\n" + + Tooltip.SetDefault("15% increased ranged damage, 5% increased ranged critical strike chance, and 20% reduced ammo usage\n" + "5 increased defense, 2 increased life regen, and 15% increased pick speed\n" + - "Greatly increases arrow speed and grants a 20% chance to not consume arrows"); + "Greatly increases arrow speed and grants a 20% chance to not consume arrows"); } public override void SetDefaults() @@ -29,14 +28,15 @@ namespace CalamityMod.Items.Accessories public override void UpdateAccessory(Player player, bool hideVisual) { - CalamityPlayer modPlayer = player.Calamity(); - modPlayer.eQuiver = true; - modPlayer.rangedAmmoCost *= 0.8f; player.rangedDamage += 0.15f; player.rangedCrit += 5; player.lifeRegen += 2; player.statDefense += 5; player.pickSpeed -= 0.15f; + player.magicQuiver = true; + CalamityPlayer modPlayer = player.Calamity(); + modPlayer.eQuiver = true; // Since splitting was removed, this has no effect. + modPlayer.rangedAmmoCost *= 0.8f; } public override void AddRecipes() diff --git a/Items/Accessories/ShatteredCommunity.cs b/Items/Accessories/ShatteredCommunity.cs index 5878f6285b..f26df095ed 100644 --- a/Items/Accessories/ShatteredCommunity.cs +++ b/Items/Accessories/ShatteredCommunity.cs @@ -31,7 +31,7 @@ namespace CalamityMod.Items.Accessories private static long CumulativeLevelCost(int level) => (BaseLevelCost / 2L) * level * (level + 1); private const int MaxLevel = 60; - internal int rageLevel = 0; + internal int level = 0; internal long totalRageDamage = 0L; public override void SetStaticDefaults() @@ -62,7 +62,7 @@ namespace CalamityMod.Items.Accessories { var clone = (ShatteredCommunity)base.Clone(); clone.everInInventory = everInInventory; - clone.rageLevel = rageLevel; + clone.level = level; clone.totalRageDamage = totalRageDamage; return clone; } @@ -70,7 +70,7 @@ namespace CalamityMod.Items.Accessories { var clone = (ShatteredCommunity)base.Clone(); clone.everInInventory = everInInventory; - clone.rageLevel = rageLevel; + clone.level = level; clone.totalRageDamage = totalRageDamage; return clone; } @@ -92,17 +92,14 @@ namespace CalamityMod.Items.Accessories player.moveSpeed += 0.2f; // Shattered Community provides a stacking +1% Rage Mode damage per level. - modPlayer.RageDamageBoost += rageLevel * 0.01; + modPlayer.RageDamageBoost += level * 0.01; } // Community and Shattered Community are mutually exclusive public override bool CanEquipAccessory(Player player, int slot) => !player.Calamity().community; public override bool CanUseItem(Player player) => false; - public override void UpdateInventory(Player player) - { - everInInventory = true; - } + public override void UpdateInventory(Player player) => everInInventory = true; // Produces purple light while in the world. public override void PostUpdate() @@ -136,16 +133,33 @@ namespace CalamityMod.Items.Accessories sc.totalRageDamage += damage; // Level up if applicable. - if (sc.totalRageDamage > CumulativeLevelCost(sc.rageLevel + 1)) + if (sc.level < MaxLevel && sc.totalRageDamage > CumulativeLevelCost(sc.level + 1)) { - ++sc.rageLevel; + ++sc.level; sc.LevelUpEffects(player); } } private void LevelUpEffects(Player player) { - // TODO -- it should probably do something fancy involving dust or whatever + // Spawn the purple laser beam from failing the Dungeon Defenders event. + int projID = ProjectileID.DD2ElderWins; + Vector2 offset = new Vector2(0f, 800f); // The effect is extremely tall, so start it very low down + Projectile fx = Projectile.NewProjectileDirect(player.Center + offset, Vector2.Zero, projID, 0, 0f, player.whoAmI); + fx.friendly = false; + fx.hostile = false; + // On the 108th update, crystal debris is spawned, so we avoid that. + fx.timeLeft = 107; + fx.MaxUpdates = 2; // Make the animation play at double speed. + + // Play a weird dimensional lightning sound simultaneously. + var extraSound = SoundID.DD2_EtherianPortalDryadTouch.WithVolume(1.4f); + Main.PlaySound(extraSound, player.Center); + + // Display a level up text notification. + Rectangle textArea = new Rectangle((int)player.Center.X, (int)player.Center.Y, 1, 1); + Color textColor = new Color(236, 209, 236); + CombatText.NewText(textArea, textColor, "The Community cracks...", false, false); } public override void ModifyTooltips(List tooltips) @@ -165,17 +179,17 @@ namespace CalamityMod.Items.Accessories // Line 6: Current level sb.Append("Current level: "); - sb.Append(rageLevel); + sb.Append(level); sb.Append(" (+"); - sb.Append(rageLevel); + sb.Append(level); sb.Append("% Rage Mode damage)"); tooltips.Add(new TooltipLine(mod, "Tooltip6", sb.ToString())); sb.Clear(); - if (rageLevel < MaxLevel) + if (level < MaxLevel) { - long progressToNextLevel = totalRageDamage - CumulativeLevelCost(rageLevel); - long totalToNextLevel = LevelCost(rageLevel + 1); + long progressToNextLevel = totalRageDamage - CumulativeLevelCost(level); + long totalToNextLevel = LevelCost(level + 1); double ratio = (double)progressToNextLevel / totalToNextLevel; string percent = (100D * ratio).ToString("0.00"); @@ -198,7 +212,7 @@ namespace CalamityMod.Items.Accessories TagCompound tag = new TagCompound { { "real", everInInventory }, - { "level", rageLevel }, + { "level", level }, { "totalDamage", totalRageDamage } }; return tag; @@ -207,21 +221,21 @@ namespace CalamityMod.Items.Accessories public override void Load(TagCompound tag) { everInInventory = tag.GetBool("real"); - rageLevel = tag.GetInt("level"); + level = tag.GetInt("level"); totalRageDamage = tag.GetLong("totalDamage"); } public override void NetSend(BinaryWriter writer) { writer.Write(everInInventory); - writer.Write(rageLevel); + writer.Write(level); writer.Write(totalRageDamage); } public override void NetRecieve(BinaryReader reader) { everInInventory = reader.ReadBoolean(); - rageLevel = reader.ReadInt32(); + level = reader.ReadInt32(); totalRageDamage = reader.ReadInt64(); } diff --git a/Items/Weapons/Magic/DivineRetribution.cs b/Items/Weapons/Magic/DivineRetribution.cs index c78077d2d3..752aa7861d 100644 --- a/Items/Weapons/Magic/DivineRetribution.cs +++ b/Items/Weapons/Magic/DivineRetribution.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetDefaults() { - item.damage = 49; + item.damage = 42; item.magic = true; item.mana = 15; item.width = 66; diff --git a/Items/Weapons/Magic/FatesReveal.cs b/Items/Weapons/Magic/FatesReveal.cs index 511e6af166..1e74e5475a 100644 --- a/Items/Weapons/Magic/FatesReveal.cs +++ b/Items/Weapons/Magic/FatesReveal.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Magic public override void SetDefaults() { - item.damage = 50; + item.damage = 120; item.magic = true; item.mana = 20; item.width = 80; diff --git a/Items/Weapons/Magic/MadAlchemistsCocktailGlove.cs b/Items/Weapons/Magic/MadAlchemistsCocktailGlove.cs index 28426def58..159170ac99 100644 --- a/Items/Weapons/Magic/MadAlchemistsCocktailGlove.cs +++ b/Items/Weapons/Magic/MadAlchemistsCocktailGlove.cs @@ -51,7 +51,7 @@ namespace CalamityMod.Items.Weapons.Magic item.UseSound = SoundID.Item106; item.autoReuse = true; item.shoot = ModContent.ProjectileType(); - item.shootSpeed = 12f; + item.shootSpeed = 19f; item.value = CalamityGlobalItem.Rarity11BuyPrice; item.rare = ItemRarityID.Purple; diff --git a/Items/Weapons/Ranged/AstrealDefeat.cs b/Items/Weapons/Ranged/AstrealDefeat.cs index 7198257293..c3b41892f2 100644 --- a/Items/Weapons/Ranged/AstrealDefeat.cs +++ b/Items/Weapons/Ranged/AstrealDefeat.cs @@ -7,15 +7,15 @@ using Terraria.ModLoader; namespace CalamityMod.Items.Weapons.Ranged { - public class AstrealDefeat : ModItem + public class AstrealDefeat : ModItem { public override void SetStaticDefaults() { DisplayName.SetDefault("Astreal Defeat"); Tooltip.SetDefault("Ethereal bow of the tyrant king's mother\n" + - "The mother strongly discouraged acts of violence throughout her life\n" + - "Though she kept this bow close, to protect her family in times of great disaster\n" + - "Converts wooden arrows into astreal arrows that emit flames as they travel"); + "The mother strongly discouraged acts of violence throughout her life\n" + + "Though she kept this bow close, to protect her family in times of great disaster\n" + + "All arrows are converted to Astreal Arrows that emit flames as they travel"); } public override void SetDefaults() @@ -40,22 +40,18 @@ namespace CalamityMod.Items.Weapons.Ranged public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - Vector2 velocity = new Vector2(speedX, speedY); - if (velocity.Length() > 8f) - { - velocity.Normalize(); - velocity *= 8f; - } + Vector2 velocity = new Vector2(speedX, speedY); + float speed = velocity.Length(); + if (speed > 8f) + velocity *= 8f / speed; - if (type == ProjectileID.WoodenArrowFriendly) - { - float ai0 = Main.rand.Next(4); - Projectile.NewProjectile(position.X, position.Y, velocity.X, velocity.Y, ModContent.ProjectileType(), damage, knockBack, player.whoAmI, ai0, 0f); - } - else - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI); + // Always fires Astreal Arrows, regardless of ammo chosen. + // Normally we like to allow bows to fire normal arrows but this weapon is incredibly overpowered when that is allowed. + type = ModContent.ProjectileType(); + float aiVar = Main.rand.Next(4); - return false; + Projectile.NewProjectile(position, velocity, type, damage, knockBack, player.whoAmI, aiVar); + return false; } public override void AddRecipes() diff --git a/Items/Weapons/Ranged/BloodBoiler.cs b/Items/Weapons/Ranged/BloodBoiler.cs index 8564d5354e..5bd7b17508 100644 --- a/Items/Weapons/Ranged/BloodBoiler.cs +++ b/Items/Weapons/Ranged/BloodBoiler.cs @@ -14,8 +14,7 @@ namespace CalamityMod.Items.Weapons.Ranged { DisplayName.SetDefault("Blood Boiler"); Tooltip.SetDefault("Fires a stream of lifestealing bloodfire\n" + - "Must be used in 10 second bursts\n" + - "Uses your life as ammo"); + "Uses your health as ammo\n" + "25% chance to not consume ammo"); } public override void SetDefaults() @@ -25,33 +24,31 @@ namespace CalamityMod.Items.Weapons.Ranged item.width = 60; item.height = 30; item.useTime = 5; - item.useAnimation = 600; + item.useAnimation = 15; + item.autoReuse = true; item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.knockBack = 4f; - item.value = CalamityGlobalItem.Rarity12BuyPrice; - item.rare = ItemRarityID.Purple; - item.Calamity().customRarity = CalamityRarity.Turquoise; - item.autoReuse = true; + item.value = CalamityGlobalItem.Rarity12BuyPrice; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Turquoise; item.shootSpeed = 12f; item.shoot = ModContent.ProjectileType(); } - public override Vector2? HoldoutOffset() - { - return new Vector2(-5, 0); - } + public override Vector2? HoldoutOffset() => new Vector2(-5, 0); public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - //using this weapon once will subtract 120 health in total - player.statLife -= 1; + if (Main.rand.NextFloat() > 0.75f) + --player.statLife; if (player.statLife <= 0) { - player.KillMe(PlayerDeathReason.ByCustomReason(Main.rand.NextBool(2) ? player.name + " suffered from severe anemia." : player.name + " was unable to obtain a blood transfusion."), 1000.0, 0, false); + PlayerDeathReason pdr = PlayerDeathReason.ByCustomReason(Main.rand.NextBool(2) ? player.name + " suffered from severe anemia." : player.name + " was unable to obtain a blood transfusion."); + player.KillMe(pdr, 1000.0, 0, false); + return false; } - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0.0f, 0.0f); - return false; + return true; } public override void AddRecipes() diff --git a/Items/Weapons/Ranged/FetidEmesis.cs b/Items/Weapons/Ranged/FetidEmesis.cs index 0bc196ded9..462de59b1e 100644 --- a/Items/Weapons/Ranged/FetidEmesis.cs +++ b/Items/Weapons/Ranged/FetidEmesis.cs @@ -16,7 +16,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 120; + item.damage = 129; item.ranged = true; item.width = 76; item.height = 46; diff --git a/Items/Weapons/Ranged/Monsoon.cs b/Items/Weapons/Ranged/Monsoon.cs index 76e43db0e3..86061bf902 100644 --- a/Items/Weapons/Ranged/Monsoon.cs +++ b/Items/Weapons/Ranged/Monsoon.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - item.damage = 85; + item.damage = 90; item.ranged = true; item.width = 46; item.height = 78; @@ -28,8 +28,8 @@ namespace CalamityMod.Items.Weapons.Ranged item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.knockBack = 2.5f; - item.value = Item.buyPrice(1, 40, 0, 0); - item.Calamity().customRarity = (CalamityRarity)13; + item.value = CalamityGlobalItem.Rarity13BuyPrice; + item.Calamity().customRarity = CalamityRarity.PureGreen; item.UseSound = SoundID.Item5; item.autoReuse = true; item.shoot = ProjectileID.WoodenArrowFriendly; diff --git a/Items/Weapons/Ranged/SepticSkewer.cs b/Items/Weapons/Ranged/SepticSkewer.cs index 7ea6a5e2a1..eafb4117c4 100644 --- a/Items/Weapons/Ranged/SepticSkewer.cs +++ b/Items/Weapons/Ranged/SepticSkewer.cs @@ -1,23 +1,22 @@ using CalamityMod.Projectiles.Ranged; using Microsoft.Xna.Framework; -using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Items.Weapons.Ranged { - public class SepticSkewer : ModItem + public class SepticSkewer : ModItem { public override void SetStaticDefaults() { DisplayName.SetDefault("Septic Skewer"); Tooltip.SetDefault("Launches a spiky harpoon infested with toxins\n" + - "Releases bacteria when returning to the player"); + "Releases bacteria when returning to the player"); } public override void SetDefaults() { - item.damage = 300; + item.damage = 272; item.ranged = true; item.width = 46; item.height = 24; @@ -35,9 +34,6 @@ namespace CalamityMod.Items.Weapons.Ranged item.Calamity().customRarity = CalamityRarity.PureGreen; } - public override Vector2? HoldoutOffset() - { - return new Vector2(-10, 0); - } + public override Vector2? HoldoutOffset() => new Vector2(-10, 0); } } diff --git a/Items/Weapons/Ranged/TelluricGlare.cs b/Items/Weapons/Ranged/TelluricGlare.cs index 47758d0b45..507984278a 100644 --- a/Items/Weapons/Ranged/TelluricGlare.cs +++ b/Items/Weapons/Ranged/TelluricGlare.cs @@ -8,20 +8,20 @@ namespace CalamityMod.Items.Weapons.Ranged { public class TelluricGlare : ModItem { + public const int RayCount = 4; public override void SetStaticDefaults() { DisplayName.SetDefault("Telluric Glare"); - Tooltip.SetDefault("Converts wooden arrows into extremely fast energy arrows"); + Tooltip.SetDefault($"Fires a burst of {RayCount} solar rays outward"); } public override void SetDefaults() { - item.damage = 60; + item.damage = 150; item.ranged = true; item.width = 54; item.height = 92; - item.useTime = 15; - item.useAnimation = 15; + item.useTime = item.useAnimation = 16; item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.knockBack = 4f; @@ -31,18 +31,27 @@ namespace CalamityMod.Items.Weapons.Ranged item.UseSound = SoundID.Item5; item.autoReuse = true; item.shoot = ModContent.ProjectileType(); - item.shootSpeed = 12f; + item.shootSpeed = 18f; item.useAmmo = AmmoID.Arrow; } 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 (type == ProjectileID.WoodenArrowFriendly) - Projectile.NewProjectile(position, new Vector2(speedX, speedY), ModContent.ProjectileType(), damage, knockBack, player.whoAmI); - else - Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + Vector2 velocity = new Vector2(speedX, speedY).SafeNormalize(Vector2.UnitX * player.direction) * 30f; + bool willHitTiles = Collision.CanHit(position, 0, 0, position + velocity, 0, 0); + for (int i = 0; i < RayCount; i++) + { + Vector2 offset = velocity.RotatedBy(MathHelper.Pi * (i - (RayCount - 1f) / 2f) * 0.18f, default); + + // Go back if the spawn position and offset spawn position have an obstacle to prevent arrows from appearing + // behind walls the player cannot access. + if (!willHitTiles) + offset -= velocity; - return false; + Projectile.NewProjectile(position + offset, new Vector2(speedX, speedY), item.shoot, damage, knockBack, player.whoAmI); + } + + return false; } } } diff --git a/Items/Weapons/Rogue/JawsOfOblivion.cs b/Items/Weapons/Rogue/JawsOfOblivion.cs index 3a5da1cbfe..daa85d4e50 100644 --- a/Items/Weapons/Rogue/JawsOfOblivion.cs +++ b/Items/Weapons/Rogue/JawsOfOblivion.cs @@ -51,7 +51,7 @@ namespace CalamityMod.Items.Weapons.Rogue if (player.Calamity().StealthStrikeAvailable()) { - int p = Projectile.NewProjectile(position, currentDirection, type, (int)(damage * 0.67), knockBack * 2f, player.whoAmI); + int p = Projectile.NewProjectile(position, currentDirection, type, damage, knockBack + 6f, player.whoAmI); if (p.WithinBounds(Main.maxProjectiles)) Main.projectile[p].Calamity().stealthStrike = true; } diff --git a/Items/Weapons/Summon/GammaHeart.cs b/Items/Weapons/Summon/GammaHeart.cs index 3572886146..8be7c471b9 100644 --- a/Items/Weapons/Summon/GammaHeart.cs +++ b/Items/Weapons/Summon/GammaHeart.cs @@ -11,8 +11,7 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Gamma Heart"); - Tooltip.SetDefault("Summons radioactive heads that are bound by your body\n" + - "If the entity already exists, using this item again will cause it to gain more heads"); + Tooltip.SetDefault("Summons radioactive heads that are bound by your body"); } public override void SetDefaults() @@ -38,9 +37,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) { if (player.altFunctionUse != 2) - { Projectile.NewProjectileDirect(player.Center, Vector2.Zero, type, damage, knockBack, player.whoAmI); - } return false; } } diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index 89f2caf4fa..94bd205be1 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -3394,9 +3394,9 @@ namespace CalamityMod.NPCs // Other projectile resists if (npc.type == NPCType()) { - // 5% resist to Time Bolt + // 10% resist to Time Bolt if (projectile.type == ProjectileType()) - damage = (int)(damage * 0.95); + damage = (int)(damage * 0.9); } else if (npc.type == NPCType()) { diff --git a/NPCs/Yharon/DetonatingFlare.cs b/NPCs/Yharon/DetonatingFlare.cs index b2a149dd4e..4eb8b8b234 100644 --- a/NPCs/Yharon/DetonatingFlare.cs +++ b/NPCs/Yharon/DetonatingFlare.cs @@ -23,14 +23,14 @@ namespace CalamityMod.NPCs.Yharon public override void SetDefaults() { - npc.Calamity().canBreakPlayerDefense = true; - npc.aiStyle = -1; + npc.Calamity().canBreakPlayerDefense = true; + npc.aiStyle = -1; aiType = -1; - npc.GetNPCDamage(); - npc.width = 50; + npc.GetNPCDamage(); + npc.width = 50; npc.height = 50; - npc.defense = 50; - npc.lifeMax = 10000; + npc.lifeMax = 3000; + npc.defense = 20; npc.knockBackResist = 0f; npc.noGravity = true; npc.noTileCollide = true; @@ -166,9 +166,9 @@ namespace CalamityMod.NPCs.Yharon npc.localAI[0] = 0f; if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { - int type = ProjectileID.CultistBossFireBall; - int damage = npc.GetProjectileDamage(type); - Projectile.NewProjectile(vector.X, vector.Y, num4, num5, type, damage, 0f, Main.myPlayer, 0f, 0f); + int type = ProjectileID.CultistBossFireBall; + int damage = npc.GetProjectileDamage(type); + Projectile.NewProjectile(vector.X, vector.Y, num4, num5, type, damage, 0f, Main.myPlayer, 0f, 0f); } } int num10 = (int)npc.position.X + npc.width / 2; @@ -241,53 +241,53 @@ namespace CalamityMod.NPCs.Yharon return new Color(255, Main.DiscoG, 53, 0); } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - SpriteEffects spriteEffects = SpriteEffects.None; - if (npc.spriteDirection == 1) - spriteEffects = SpriteEffects.FlipHorizontally; + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects spriteEffects = SpriteEffects.None; + if (npc.spriteDirection == 1) + spriteEffects = SpriteEffects.FlipHorizontally; - Texture2D texture2D15 = Main.npcTexture[npc.type]; - Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2)); - Color color36 = new Color(255, Main.DiscoG, 53, 0); - float amount9 = 0.5f; - int num153 = 10; + Texture2D texture2D15 = Main.npcTexture[npc.type]; + Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2)); + Color color36 = new Color(255, Main.DiscoG, 53, 0); + float amount9 = 0.5f; + int num153 = 10; - if (CalamityConfig.Instance.Afterimages) - { - for (int num155 = 1; num155 < num153; num155 += 2) - { - Color color38 = lightColor; - color38 = Color.Lerp(color38, color36, amount9); - color38 = npc.GetAlpha(color38); - color38 *= (float)(num153 - num155) / 15f; - Vector2 vector41 = npc.oldPos[num155] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition; - vector41 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; - vector41 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); - spriteBatch.Draw(texture2D15, vector41, npc.frame, color38, npc.rotation, vector11, npc.scale, spriteEffects, 0f); - } - } + if (CalamityConfig.Instance.Afterimages) + { + for (int num155 = 1; num155 < num153; num155 += 2) + { + Color color38 = lightColor; + color38 = Color.Lerp(color38, color36, amount9); + color38 = npc.GetAlpha(color38); + color38 *= (float)(num153 - num155) / 15f; + Vector2 vector41 = npc.oldPos[num155] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition; + vector41 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; + vector41 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + spriteBatch.Draw(texture2D15, vector41, npc.frame, color38, npc.rotation, vector11, npc.scale, spriteEffects, 0f); + } + } - Vector2 vector43 = npc.Center - Main.screenPosition; - vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; - vector43 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); - spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, spriteEffects, 0f); + Vector2 vector43 = npc.Center - Main.screenPosition; + vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; + vector43 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, spriteEffects, 0f); - return false; - } + return false; + } - public override bool CanHitPlayer(Player target, ref int cooldownSlot) + public override bool CanHitPlayer(Player target, ref int cooldownSlot) { cooldownSlot = 1; return true; } - public override void OnHitPlayer(Player player, int damage, bool crit) - { - player.AddBuff(ModContent.BuffType(), 240, true); - } + public override void OnHitPlayer(Player player, int damage, bool crit) + { + player.AddBuff(ModContent.BuffType(), 240, true); + } - public override void FindFrame(int frameHeight) + public override void FindFrame(int frameHeight) { npc.frameCounter += 0.15f; npc.frameCounter %= Main.npcFrameCount[npc.type]; diff --git a/NPCs/Yharon/DetonatingFlare2.cs b/NPCs/Yharon/DetonatingFlare2.cs index 6485929fab..06bc9ba4f0 100644 --- a/NPCs/Yharon/DetonatingFlare2.cs +++ b/NPCs/Yharon/DetonatingFlare2.cs @@ -6,9 +6,10 @@ using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.NPCs.Yharon { - public class DetonatingFlare2 : ModNPC + public class DetonatingFlare2 : ModNPC { float randomSpeed = 0f; @@ -16,24 +17,24 @@ namespace CalamityMod.NPCs.Yharon { DisplayName.SetDefault("Detonating Flame"); Main.npcFrameCount[npc.type] = 5; - NPCID.Sets.TrailingMode[npc.type] = 1; - } + NPCID.Sets.TrailingMode[npc.type] = 1; + } public override void SetDefaults() { - npc.Calamity().canBreakPlayerDefense = true; - npc.aiStyle = -1; + npc.Calamity().canBreakPlayerDefense = true; + npc.aiStyle = -1; aiType = -1; - npc.GetNPCDamage(); - npc.width = 50; + npc.GetNPCDamage(); + npc.width = 50; npc.height = 50; - npc.defense = 75; - npc.lifeMax = 13000; + npc.lifeMax = 3900; + npc.defense = 26; npc.knockBackResist = 0f; npc.noGravity = true; npc.noTileCollide = true; npc.canGhostHeal = false; - npc.HitSound = SoundID.NPCHit52; + npc.HitSound = SoundID.NPCHit52; npc.DeathSound = SoundID.NPCDeath55; npc.alpha = 255; } @@ -76,36 +77,36 @@ namespace CalamityMod.NPCs.Yharon return new Color(255, Main.DiscoG, 53, 0); } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - Texture2D texture2D15 = Main.npcTexture[npc.type]; - Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2)); - Color color36 = new Color(255, Main.DiscoG, 53, 0); - float amount9 = 0.5f; - int num153 = 10; + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture2D15 = Main.npcTexture[npc.type]; + Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2)); + Color color36 = new Color(255, Main.DiscoG, 53, 0); + float amount9 = 0.5f; + int num153 = 10; - if (CalamityConfig.Instance.Afterimages) - { - for (int num155 = 1; num155 < num153; num155 += 2) - { - Color color38 = lightColor; - color38 = Color.Lerp(color38, color36, amount9); - color38 = npc.GetAlpha(color38); - color38 *= (float)(num153 - num155) / 15f; - Vector2 vector41 = npc.oldPos[num155] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition; - vector41 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; - vector41 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); - spriteBatch.Draw(texture2D15, vector41, npc.frame, color38, npc.rotation, vector11, npc.scale, SpriteEffects.None, 0f); - } - } + if (CalamityConfig.Instance.Afterimages) + { + for (int num155 = 1; num155 < num153; num155 += 2) + { + Color color38 = lightColor; + color38 = Color.Lerp(color38, color36, amount9); + color38 = npc.GetAlpha(color38); + color38 *= (float)(num153 - num155) / 15f; + Vector2 vector41 = npc.oldPos[num155] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition; + vector41 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; + vector41 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + spriteBatch.Draw(texture2D15, vector41, npc.frame, color38, npc.rotation, vector11, npc.scale, SpriteEffects.None, 0f); + } + } - Vector2 vector43 = npc.Center - Main.screenPosition; - vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; - vector43 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); - spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, SpriteEffects.None, 0f); + Vector2 vector43 = npc.Center - Main.screenPosition; + vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; + vector43 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, SpriteEffects.None, 0f); - return false; - } + return false; + } public override bool CanHitPlayer(Player target, ref int cooldownSlot) { @@ -113,12 +114,12 @@ namespace CalamityMod.NPCs.Yharon return true; } - public override void OnHitPlayer(Player player, int damage, bool crit) - { - player.AddBuff(ModContent.BuffType(), 240, true); - } + public override void OnHitPlayer(Player player, int damage, bool crit) + { + player.AddBuff(ModContent.BuffType(), 240, true); + } - public override void FindFrame(int frameHeight) + public override void FindFrame(int frameHeight) { npc.frameCounter += 0.15f; npc.frameCounter %= Main.npcFrameCount[npc.type]; diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index c60abf07a0..6311b65d9c 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -1160,26 +1160,6 @@ namespace CalamityMod.Projectiles if (!projectile.npcProj && !projectile.trap && projectile.friendly && projectile.damage > 0) { - if (modPlayer.eQuiver && projectile.ranged && CalamityLists.rangedProjectileExceptionList.TrueForAll(x => projectile.type != x)) - { - if (Main.player[projectile.owner].miscCounter % 60 == 0 && projectile.FinalExtraUpdate()) - { - float spread = 180f * 0.0174f; - double startAngle = Math.Atan2(projectile.velocity.X, projectile.velocity.Y) - spread / 2; - if (projectile.owner == Main.myPlayer && player.ownedProjectileCounts[projectile.type] < 50) - { - int projectile1 = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(Math.Sin(startAngle) * 8f), (float)(Math.Cos(startAngle) * 8f), projectile.type, (int)(projectile.damage * 0.15), projectile.knockBack, projectile.owner, 0f, 0f); - int projectile2 = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(-Math.Sin(startAngle) * 8f), (float)(-Math.Cos(startAngle) * 8f), projectile.type, (int)(projectile.damage * 0.15), projectile.knockBack, projectile.owner, 0f, 0f); - Main.projectile[projectile1].ranged = false; - Main.projectile[projectile2].ranged = false; - Main.projectile[projectile1].timeLeft = 60; - Main.projectile[projectile2].timeLeft = 60; - Main.projectile[projectile1].noDropItem = true; - Main.projectile[projectile2].noDropItem = true; - } - } - } - if (modPlayer.fungalSymbiote && trueMelee) { if (Main.player[projectile.owner].miscCounter % 6 == 0 && projectile.FinalExtraUpdate()) diff --git a/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs b/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs index 73b122ed85..01eaccc70e 100644 --- a/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs +++ b/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs @@ -245,19 +245,11 @@ namespace CalamityMod.Projectiles.DraedonsArsenal Main.myPlayer == projectile.owner) { Vector2 spawnPosition = projectile.Center + Vector2.UnitX * 8f * projectile.spriteDirection; - - float shootSpeed = 14f; - float gravity = -StarSwallowerAcid.Gravity; - float distance = Vector2.Distance(spawnPosition, potentialTarget.Center); - float angle = 0.5f * (float)Math.Asin(MathHelper.Clamp(gravity * distance / (float)Math.Pow(shootSpeed, 2), -1f, 1f)); - - Vector2 velocity = new Vector2(0f, -shootSpeed).RotatedBy(angle).RotatedByRandom(0.015f); - velocity.X *= (potentialTarget.Center.X - projectile.Center.X < 0).ToDirectionInt(); - projectile.spriteDirection = (potentialTarget.Center.X - projectile.Center.X > 0).ToDirectionInt(); + Vector2 fireVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(spawnPosition, potentialTarget.Center, StarSwallowerAcid.Gravity, 14f); Projectile.NewProjectile(spawnPosition, - velocity, + fireVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, diff --git a/Projectiles/Magic/GhastlyBlast.cs b/Projectiles/Magic/GhastlyBlast.cs index 7d81ae12e0..cc72fbc243 100644 --- a/Projectiles/Magic/GhastlyBlast.cs +++ b/Projectiles/Magic/GhastlyBlast.cs @@ -9,6 +9,10 @@ namespace CalamityMod.Projectiles.Magic { public class GhastlyBlast : ModProjectile { + private const float DriftVelocity = 10f; + private const float FramesBeforeSlowing = 8f; + private const float MaximumWaitFrames = 360f; + public override void SetStaticDefaults() { DisplayName.SetDefault("Ghast Blast"); @@ -23,30 +27,35 @@ namespace CalamityMod.Projectiles.Magic projectile.friendly = true; projectile.alpha = 255; projectile.penetrate = 6; - projectile.extraUpdates = 1; + projectile.extraUpdates = 2; projectile.tileCollide = false; projectile.ignoreWater = true; projectile.magic = true; projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 8; + projectile.localNPCHitCooldown = 12; } public override void AI() { projectile.ai[0] += 1f; - int num1013 = 0; - if (projectile.velocity.Length() <= 8f) //4 - { - num1013 = 1; - } + bool goingSlow = projectile.velocity.Length() <= DriftVelocity; + bool currentlyHoming = projectile.ai[1] > 0f; + + // Rapidly fade in when the projectile starts existing projectile.alpha -= 15; if (projectile.alpha < 0) { projectile.alpha = 0; } - if (num1013 == 0) + + // Moving faster than drift velocity, but not homing. + // This way, when the projectile speeds back up upon homing, it doesn't suddenly lose its homing again. + if (!goingSlow && !currentlyHoming) { + // Spin at a certain rate projectile.rotation -= 0.104719758f; + + // Dust, randomly if (Main.rand.NextBool(3)) { if (Main.rand.NextBool(2)) @@ -72,9 +81,11 @@ namespace CalamityMod.Projectiles.Magic dust29.customData = projectile; } } - if (projectile.ai[0] >= 30f) + + // Grow and slow down + if (projectile.ai[0] >= FramesBeforeSlowing * projectile.MaxUpdates) { - projectile.velocity *= 0.98f; + projectile.velocity *= 0.977f; projectile.scale += 0.00744680827f; if (projectile.scale > 1.2f) { @@ -82,16 +93,23 @@ namespace CalamityMod.Projectiles.Magic } projectile.rotation -= 0.0174532924f; } - if (projectile.velocity.Length() < 8.2f) //4.1 + + // Set velocity to the drift velocity exactly after slowing down enough and reset the time counter. + float speed = projectile.velocity.Length(); + if (speed < 1.02f * DriftVelocity) { - projectile.velocity.Normalize(); - projectile.velocity *= 4f; + projectile.velocity *= DriftVelocity / speed; projectile.ai[0] = 0f; } } - else if (num1013 == 1) + + // Either moving at or below drift velocity, or currently homing. Either case runs this AI path. + else { + // Spin at the exact same rate anyway projectile.rotation -= 0.104719758f; + + // Excessively complicated dust int num3; for (int num1014 = 0; num1014 < 1; num1014 = num3 + 1) { @@ -127,11 +145,16 @@ namespace CalamityMod.Projectiles.Magic } num3 = num1014; } + + // Every so many frames, spawn a sub blast. if (projectile.ai[0] % 30f == 0f && projectile.ai[0] < 241f && Main.myPlayer == projectile.owner) { Vector2 vector144 = Vector2.UnitY.RotatedByRandom(6.2831854820251465) * 12f; Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, vector144.X, vector144.Y, ModContent.ProjectileType(), projectile.damage, 0f, projectile.owner, 0f, (float)projectile.whoAmI); } + + // Undocumented, unrefactored homing. Will not home through walls. + // Apparently has two different homing distances. Vector2 vector145 = projectile.Center; float num1015 = 800f; bool flag59 = false; @@ -195,11 +218,14 @@ namespace CalamityMod.Projectiles.Magic projectile.velocity.Y = (projectile.velocity.Y * (float)(HomingN - 1) + dy) / (float)HomingN; } } + + // If the projectile is solid enough, add light. if (projectile.alpha < 150) { Lighting.AddLight(projectile.Center, 0.9f, 0f, 0.1f); } - if (projectile.ai[0] >= 600f) + + if (projectile.ai[0] >= MaximumWaitFrames * projectile.MaxUpdates) { projectile.Kill(); } diff --git a/Projectiles/Magic/GhastlyVisageProj.cs b/Projectiles/Magic/GhastlyVisageProj.cs index fa46444dae..fa8f758516 100644 --- a/Projectiles/Magic/GhastlyVisageProj.cs +++ b/Projectiles/Magic/GhastlyVisageProj.cs @@ -145,7 +145,7 @@ namespace CalamityMod.Projectiles.Magic if (flag15 && Main.myPlayer == projectile.owner) { int num42 = ModContent.ProjectileType(); - float scaleFactor11 = 6f; + float coreVelocity = 13f; int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); float weaponKnockback2 = player.ActiveItem().knockBack; if (flag16) @@ -169,7 +169,7 @@ namespace CalamityMod.Projectiles.Magic projectile.netUpdate = true; } projectile.velocity = value19 * 0.55f; - Vector2 vector20 = Vector2.Normalize(projectile.velocity) * scaleFactor11 * (0.6f + Main.rand.NextFloat() * 0.8f); + Vector2 vector20 = Vector2.Normalize(projectile.velocity) * coreVelocity; if (float.IsNaN(vector20.X) || float.IsNaN(vector20.Y)) { vector20 = -Vector2.UnitY; diff --git a/Projectiles/Ranged/TelluricGlareProj.cs b/Projectiles/Ranged/TelluricGlareProj.cs index ed68a7a951..69f025f783 100644 --- a/Projectiles/Ranged/TelluricGlareProj.cs +++ b/Projectiles/Ranged/TelluricGlareProj.cs @@ -1,77 +1,98 @@ using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Dusts; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; using Terraria; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Ranged { public class TelluricGlareProj : ModProjectile { + public PrimitiveTrail TrailDrawer = null; public override void SetStaticDefaults() { DisplayName.SetDefault("Glare"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 11; } public override void SetDefaults() { - projectile.width = 10; - projectile.height = 10; - projectile.extraUpdates = 30; + projectile.width = projectile.height = 14; + projectile.arrow = true; projectile.friendly = true; projectile.ranged = true; - projectile.penetrate = -1; projectile.aiStyle = 1; - projectile.timeLeft = 300; - projectile.arrow = true; - aiType = ProjectileID.WoodenArrowFriendly; + projectile.timeLeft = 180; projectile.usesLocalNPCImmunity = true; projectile.localNPCHitCooldown = 10; } - public override void AI() - { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 4f) + public float PrimitiveWidthFunction(float completionRatio) + { + float width; + if (completionRatio <= 0.23f) + width = MathHelper.SmoothStep(1f, projectile.width * 1.4f, Utils.InverseLerp(0f, 0.23f, completionRatio, true)); + else { - for (int num468 = 0; num468 < 2; num468++) - { - int num469 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 244, 0f, 0f, 100, default, 1.7f); - Main.dust[num469].noGravity = true; - Main.dust[num469].velocity *= 0f; - } + width = MathHelper.SmoothStep(projectile.width * 2f, projectile.width, Utils.InverseLerp(0.18f, 0.29f, completionRatio, true)); + width *= Utils.InverseLerp(1f, 0.51f, completionRatio, true); } + + return width; + } + + public Color PrimitiveColorFunction(float completionRatio) + { + float whiteFadeRequirement = 0.41f; + float startingInterpolant = (float)Math.Cos(completionRatio * 2.7f - Main.GlobalTime * 5.3f + Utils.InverseLerp(0f, whiteFadeRequirement * 0.5f, completionRatio, true) * 3.2f); + startingInterpolant = startingInterpolant * 0.5f + 0.5f; + Color startingColor = Color.Lerp(Color.Yellow, Color.OrangeRed, startingInterpolant * 0.6f); + return Color.Lerp(startingColor, Color.Wheat, MathHelper.SmoothStep(0f, 1f, Utils.InverseLerp(0f, whiteFadeRequirement, completionRatio, true))); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/TelluricGlareStreak")); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 58); + return false; } public override void Kill(int timeLeft) { - projectile.position = projectile.Center; - projectile.width = projectile.height = 32; - projectile.position.X = projectile.position.X - (float)(projectile.width / 2); - projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 36); Main.PlaySound(SoundID.Item14, projectile.position); - for (int num621 = 0; num621 < 10; num621++) + + // Explode into a bunch of holy fire on death. + for (int i = 0; i < 10; i++) { - int num622 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 244, 0f, 0f, 100, default, 2f); - Main.dust[num622].velocity *= 3f; + Dust holyFire = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, (int)CalamityDusts.ProfanedFire, 0f, 0f, 100, default, 2f); + holyFire.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; + holyFire.scale = 0.5f; + holyFire.fadeIn = Main.rand.NextFloat(1f, 2f); } } - for (int num623 = 0; num623 < 20; num623++) + for (int i = 0; i < 20; i++) { - int num624 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 246, 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, 246, 0f, 0f, 100, default, 2f); - Main.dust[num624].velocity *= 2f; + Dust holyFire = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 246, 0f, 0f, 100, default, 3f); + holyFire.noGravity = true; + holyFire.velocity *= 5f; + + holyFire = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 246, 0f, 0f, 100, default, 2f); + holyFire.velocity *= 2f; } } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(ModContent.BuffType(), 120); - } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => target.AddBuff(ModContent.BuffType(), 120); } } diff --git a/Projectiles/Rogue/NightsGazeProjectile.cs b/Projectiles/Rogue/NightsGazeProjectile.cs index 98570e8fe8..947e7fb52a 100644 --- a/Projectiles/Rogue/NightsGazeProjectile.cs +++ b/Projectiles/Rogue/NightsGazeProjectile.cs @@ -29,6 +29,8 @@ namespace CalamityMod.Projectiles.Rogue projectile.Calamity().rogue = true; } + private int SplitProjDamage => (int)(projectile.damage * (projectile.Calamity().stealthStrike ? 1f : 0.75f)); + public override void AI() { if (projectile.ai[0] == 0f) @@ -40,11 +42,12 @@ namespace CalamityMod.Projectiles.Rogue { if (Main.rand.NextBool(8)) { - int projectileDamage = (int)(projectile.damage * 0.75f); - int projectileType = ModContent.ProjectileType(); + int projID = ModContent.ProjectileType(); + int starDamage = SplitProjDamage; + float starKB = 5f; Vector2 velocity = projectile.velocity; - int p = Projectile.NewProjectile(projectile.Center, velocity, projectileType, projectileDamage, 5f, projectile.owner, 1f, 0f); + int p = Projectile.NewProjectile(projectile.Center, velocity, projID, starDamage, starKB, projectile.owner, 1f, 0f); Main.projectile[p].penetrate = 1; } } @@ -53,33 +56,31 @@ namespace CalamityMod.Projectiles.Rogue public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { target.AddBuff(ModContent.BuffType(), projectile.timeLeft); - OnHitEffects(); + OnHitEffects(); } public override void OnHitPvp(Player target, int damage, bool crit) { target.AddBuff(ModContent.BuffType(), projectile.timeLeft); - OnHitEffects(); - } + OnHitEffects(); + } - private void OnHitEffects() - { - int starCount = 6; - int starFrequency = 3; + private void OnHitEffects() + { + int onHitCount = 6; + int chanceOfStar = 2; float spread = 20f; - for (int i = 0; i < starCount; i++) + int projectileDamage = SplitProjDamage; + float kb = 5f; + int sparkID = ModContent.ProjectileType(); + int starID = ModContent.ProjectileType(); + for (int i = 0; i < onHitCount; i++) { - int projectileDamage = (int)(projectile.damage * 0.75f); - int projectileType = ModContent.ProjectileType(); - if (Main.rand.Next(starCount) < starFrequency) - { - projectileType = ModContent.ProjectileType(); - } + int projID = Main.rand.NextBool(chanceOfStar) ? starID : sparkID; Vector2 velocity = projectile.oldVelocity.RotateRandom(MathHelper.ToRadians(spread)); float speed = Main.rand.NextFloat(1.5f, 2f); float moveDuration = Main.rand.Next(5, 15); - - Projectile.NewProjectile(projectile.Center, velocity * speed, projectileType, projectileDamage, 5f, projectile.owner, 0f, moveDuration); + Projectile.NewProjectile(projectile.Center, velocity * speed, projID, projectileDamage, kb, projectile.owner, 0f, moveDuration); } Main.PlaySound(SoundID.Item, (int)projectile.position.X, (int)projectile.position.Y, 62, 0.6f); @@ -103,8 +104,8 @@ namespace CalamityMod.Projectiles.Rogue public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) { - Texture2D texture = ModContent.GetTexture("CalamityMod/Items/Weapons/Rogue/NightsGazeGlow"); - Vector2 origin = new Vector2(texture.Width / 2f, texture.Height / 2f); + Texture2D texture = ModContent.GetTexture("CalamityMod/Items/Weapons/Rogue/NightsGazeGlow"); + Vector2 origin = new Vector2(texture.Width / 2f, texture.Height / 2f); spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, null, Color.White, projectile.rotation, origin, 1f, SpriteEffects.None, 0f); } @@ -112,12 +113,12 @@ namespace CalamityMod.Projectiles.Rogue { for (int i = 0; i < 5; i++) { - int dustType = Utils.SelectRandom(Main.rand, new int[] - { - 109, - 111, - 132 - }); + int dustType = Utils.SelectRandom(Main.rand, new int[] + { + 109, + 111, + 132 + }); int dust = Dust.NewDust(projectile.Center, 1, 1, dustType, projectile.velocity.X / 3f, projectile.velocity.Y / 3f, 0, default, 1.5f); Main.dust[dust].noGravity = true; diff --git a/Projectiles/Rogue/ReaperProjectile.cs b/Projectiles/Rogue/ReaperProjectile.cs index b0c1f71a8b..947291b71d 100644 --- a/Projectiles/Rogue/ReaperProjectile.cs +++ b/Projectiles/Rogue/ReaperProjectile.cs @@ -24,11 +24,11 @@ namespace CalamityMod.Projectiles.Rogue projectile.height = 70; projectile.friendly = true; projectile.tileCollide = false; - projectile.penetrate = 12; + projectile.penetrate = 30; projectile.timeLeft = 1080; projectile.extraUpdates = 3; projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 40; // can't hit too fast, but can hit many many times + projectile.localNPCHitCooldown = 32; // can't hit too fast, but can hit many many times projectile.Calamity().rogue = true; } diff --git a/Projectiles/Rogue/ValedictionBoomerang.cs b/Projectiles/Rogue/ValedictionBoomerang.cs index 3419450543..b835b7262a 100644 --- a/Projectiles/Rogue/ValedictionBoomerang.cs +++ b/Projectiles/Rogue/ValedictionBoomerang.cs @@ -2,7 +2,6 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Projectiles.Magic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -11,7 +10,7 @@ namespace CalamityMod.Projectiles.Rogue { public class ValedictionBoomerang : ModProjectile { - public override string Texture => "CalamityMod/Items/Weapons/Rogue/Valediction"; + public override string Texture => "CalamityMod/Items/Weapons/Rogue/Valediction"; public override void SetStaticDefaults() { @@ -133,7 +132,8 @@ namespace CalamityMod.Projectiles.Rogue private void OnHitEffects() { int typhoonAmt = 3; - if (projectile.owner == Main.myPlayer && projectile.Calamity().stealthStrike) + int typhoonDamage = (int)(projectile.damage * 1.6f); + if (projectile.owner == Main.myPlayer && projectile.numHits < 1 && projectile.Calamity().stealthStrike) { Main.PlaySound(SoundID.Item84, projectile.position); for (int typhoonCount = 0; typhoonCount < typhoonAmt; typhoonCount++) @@ -145,7 +145,7 @@ namespace CalamityMod.Projectiles.Rogue } velocity.Normalize(); velocity *= (float)Main.rand.Next(70, 101) * 0.1f; - Projectile typhoon = Projectile.NewProjectileDirect(projectile.Center, velocity, ModContent.ProjectileType(), projectile.damage / 2, 0f, projectile.owner); + Projectile typhoon = Projectile.NewProjectileDirect(projectile.Center, velocity, ModContent.ProjectileType(), typhoonDamage, 0f, projectile.owner); if (typhoon.whoAmI.WithinBounds(Main.maxProjectiles)) { typhoon.Calamity().forceRogue = true; diff --git a/Projectiles/Summon/DazzlingStabber.cs b/Projectiles/Summon/DazzlingStabber.cs index 5eb8d4bce0..1a5af418d3 100644 --- a/Projectiles/Summon/DazzlingStabber.cs +++ b/Projectiles/Summon/DazzlingStabber.cs @@ -1,33 +1,24 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.Summon; -using CalamityMod.CalPlayer; -using CalamityMod.Dusts; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Summon { - public class DazzlingStabber : ModProjectile + public class DazzlingStabber : ModProjectile { - public float NPCTargetTimer - { - get => projectile.ai[0]; - set => projectile.ai[0] = value; - } - public float IdleOffsetAngle - { - get => projectile.ai[1]; - set => projectile.ai[1] = value; - } - public const float DistanceToCheck = 1500f; - public const float TeleportSlice = 40f; - public static readonly float TeleportSliceAngleMax = MathHelper.ToRadians(23f); + public Player Owner => Main.player[projectile.owner]; + public ref float AttackDelay => ref projectile.ai[0]; + public ref float RestOffsetAngle => ref projectile.ai[1]; public override void SetStaticDefaults() { DisplayName.SetDefault("Dazzling Stabber"); Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 25; ProjectileID.Sets.MinionSacrificable[projectile.type] = true; ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; } @@ -40,128 +31,146 @@ namespace CalamityMod.Projectiles.Summon projectile.friendly = true; projectile.ignoreWater = true; projectile.minionSlots = 1f; - projectile.timeLeft = 18000; + projectile.timeLeft = 90000; projectile.penetrate = -1; projectile.tileCollide = false; - projectile.timeLeft *= 5; projectile.minion = true; + projectile.light = 1f; projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 12; + projectile.localNPCHitCooldown = 10; } public override void AI() { Lighting.AddLight(projectile.Center, Color.White.ToVector3()); - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); + + ApplyPlayerBuffs(); + AdjustDamageDynamically(); + UpdateFrames(); + + NPC potentialTarget = projectile.Center.MinionHoming(1100f, Owner); + + if (potentialTarget != null) + SliceTarget(potentialTarget); + else + ReturnToRestingPosition(); + } + + public void ApplyPlayerBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + if (projectile.type == ModContent.ProjectileType()) + { + if (Owner.dead) + Owner.Calamity().providenceStabber = false; + if (Owner.Calamity().providenceStabber) + projectile.timeLeft = 2; + } + } + + public void AdjustDamageDynamically() + { if (projectile.localAI[0] == 0f) { - projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; projectile.localAI[0] = 1f; } - if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) { - int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / - projectile.Calamity().spawnedPlayerMinionDamageValue * - player.MinionDamage()); + int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / projectile.Calamity().spawnedPlayerMinionDamageValue * Owner.MinionDamage()); projectile.damage = trueDamage; } - bool isProperProjectile = projectile.type == ModContent.ProjectileType(); - player.AddBuff(ModContent.BuffType(), 3600); - if (isProperProjectile) - { - if (player.dead) - { - modPlayer.providenceStabber = false; - } - if (modPlayer.providenceStabber) - { - projectile.timeLeft = 2; - } - } + } - NPC potentialTarget = projectile.Center.MinionHoming(DistanceToCheck, player); - - if (projectile.frameCounter++ > 6) - { + public void UpdateFrames() + { + projectile.frameCounter++; + if (projectile.frameCounter % 6 == 0) projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; - projectile.frameCounter = 0; - } - - if (potentialTarget is null) - { - projectile.rotation = projectile.rotation.AngleTowards(IdleOffsetAngle, 0.05f); - Vector2 destination = player.Center + new Vector2(0f, -120f).RotatedBy(IdleOffsetAngle); - projectile.velocity = (destination - projectile.Center) / 15f; - } - else - { - NPCTargetTimer++; - // Alternate between normal charge and slower charge/knife summon - if (NPCTargetTimer % 160f < 100f) - { - ChargeAttack(potentialTarget); - } - // Teleport onto the target and just the rotation for a slice. - else if (NPCTargetTimer % 160f == 160f - TeleportSlice) - { - TeleportOntoTarget(potentialTarget); - } - // Slice the target and don't move. - else if (NPCTargetTimer % 160f > 160f - TeleportSlice) - { - projectile.rotation -= TeleportSliceAngleMax * 2f / TeleportSlice; - } - } - projectile.direction = projectile.spriteDirection = (projectile.velocity.X > 0).ToDirectionInt(); } - public void ChargeAttack(NPC target) + public void SliceTarget(NPC target) { - if (NPCTargetTimer % 160f < 30f) + // Don't do anything if the attack delay is still passing. + if (AttackDelay > -60f) { - projectile.velocity *= 0.99f; - projectile.rotation = projectile.rotation.AngleLerp(projectile.AngleTo(target.Center) + MathHelper.PiOver2, 0.25f); + AttackDelay--; + if (AttackDelay > 0f) + return; } - else if (NPCTargetTimer % 160f == 30f) + + // Don't do anything if very close to the target. + if (projectile.WithinRange(target.Center, 60f)) + return; + + // Reset the velocity to fly upward if there is very little motion to ensure + // that the summon does not get stuck. + if (projectile.velocity.Length() < 1.6f) + projectile.velocity = Vector2.UnitY * 5f; + + // If close to the target, slow down dramatically. + if (projectile.velocity.Length() > 5f && projectile.WithinRange(target.Center, 90f)) + projectile.velocity *= 0.8f; + + // Otherwise, if not close, speed up dramatically. + else if (projectile.velocity.Length() < 40f) + projectile.velocity *= 1.03f; + + float angularTurnSpeed = 0.35f; + float angleToTargetCoords = projectile.AngleTo(target.Center); + + projectile.velocity = projectile.velocity.ToRotation().AngleTowards(angleToTargetCoords, angularTurnSpeed).ToRotationVector2() * projectile.velocity.Length(); + + // If not super close to the target but the target is very much in the line of sight of the summon, charge. + if (!projectile.WithinRange(target.Center, 75f) && Vector2.Dot(projectile.DirectionTo(target.Center), projectile.velocity.SafeNormalize(Vector2.Zero)) > 0.85f) { - projectile.velocity = projectile.DirectionTo(target.Center) * 20f; + projectile.velocity = projectile.DirectionTo(target.Center) * 36f; + AttackDelay = 15f; + projectile.netUpdate = true; } - else if (NPCTargetTimer % 160f < 60f) - { - projectile.velocity *= 0.99f; - projectile.rotation = projectile.rotation.AngleLerp(projectile.AngleTo(target.Center) + MathHelper.PiOver2, 0.25f); - } - else if (NPCTargetTimer % 160f == 60f) - { - projectile.velocity = projectile.DirectionTo(target.Center) * 16f; - for (int i = 0; i < 3; i++) - { - float angle = MathHelper.Lerp(-0.3f, 0.3f, i / 3f); - Projectile.NewProjectile(projectile.Center, projectile.velocity.RotatedBy(angle), ModContent.ProjectileType(), (int)(projectile.damage * 0.25), 1f, projectile.owner); - } - } - else projectile.velocity *= 0.99f; + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; } - public void TeleportOntoTarget(NPC target) + public void ReturnToRestingPosition() { - // Spawn a spiral of holy flame dust. - float angleStart = Main.rand.NextFloat(MathHelper.TwoPi); - for (int i = 0; i < 30; i++) + projectile.rotation = projectile.rotation.AngleTowards(RestOffsetAngle, 0.25f); + + // Rapidly approach the resting position. + Vector2 destination = Owner.Center + Vector2.UnitY.RotatedBy(RestOffsetAngle) * -120f; + projectile.velocity = (destination - projectile.Center) / 10f; + } + + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + for (int i = 1; i < projectile.oldPos.Length; i++) + CalamityUtils.DistanceClamp(ref projectile.oldPos[i - 1], ref projectile.oldPos[i], 6f); + + Texture2D trailSegmentTexture = ModContent.GetTexture("CalamityMod/Projectiles/StarProj"); + for (int i = 2; i < projectile.oldPos.Length; i++) { - float angle = MathHelper.TwoPi / 30f * i + angleStart; - Dust dust = Dust.NewDustPerfect(projectile.Center + angle.ToRotationVector2() * 10f, (int)CalamityDusts.ProfanedFire); - dust.velocity = angle.ToRotationVector2() * 5f * MathHelper.Lerp(1f, 0f, i % 6f / 6f); + float completionRatio = i / (float)projectile.oldPos.Length; + float rotation = (projectile.oldPos[i - 1] - projectile.oldPos[i]).ToRotation() + MathHelper.PiOver2; + float scale = MathHelper.Lerp(0.7f, 0.1f, completionRatio) * projectile.scale; + Color color = Color.Lerp(Color.LightPink, Color.Goldenrod, completionRatio * 3f % 1f) * 1.5f; + + // Become dimmer the slower the projectile is moving. + color *= Utils.InverseLerp(1f, 8f, projectile.velocity.Length(), true); + + // As well as how close the projectile is to pointing away from its rotation. + color *= Utils.InverseLerp(0.65f, 0.45f, projectile.velocity.AngleBetween(-(projectile.rotation + MathHelper.PiOver2).ToRotationVector2()) / MathHelper.Pi, true); + + spriteBatch.Draw(trailSegmentTexture, + projectile.oldPos[i] + projectile.Size * 0.5f + new Vector2(0f, 8f).RotatedBy(projectile.rotation) - Main.screenPosition, + null, + color, + rotation, + trailSegmentTexture.Size() * 0.5f, + scale, + SpriteEffects.None, + 0f); } - - Vector2 teleportOffset = Utils.RandomVector2(Main.rand, -12f, 12f); - - projectile.Center = target.Center + teleportOffset; - projectile.rotation = projectile.AngleTo(target.Center) + MathHelper.PiOver2 + TeleportSliceAngleMax; - projectile.velocity = Vector2.Zero; - projectile.netUpdate = true; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) diff --git a/Projectiles/Summon/DazzlingStabberKnife.cs b/Projectiles/Summon/DazzlingStabberKnife.cs deleted file mode 100644 index b3cfa88bfd..0000000000 --- a/Projectiles/Summon/DazzlingStabberKnife.cs +++ /dev/null @@ -1,59 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Summon -{ - public class DazzlingStabberKnife : ModProjectile - { - public const float HomingSpeed = 17f; - public const float HomingInertia = 20f; - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Knife"); - ProjectileID.Sets.MinionShot[projectile.type] = true; - } - - public override void SetDefaults() - { - projectile.width = 14; - projectile.height = 24; - projectile.friendly = true; - projectile.minion = true; - projectile.minionSlots = 0f; - projectile.ignoreWater = true; - projectile.penetrate = 1; - projectile.timeLeft = 600; - } - public override void AI() - { - Lighting.AddLight(projectile.Center, Color.White.ToVector3()); - projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; - NPC potentialTarget = projectile.Center.MinionHoming(750f, Main.player[projectile.owner]); - if (potentialTarget != null) - { - if (projectile.Distance(potentialTarget.Center) > 70f) - { - projectile.velocity = (projectile.velocity * (HomingInertia - 1f) + projectile.DirectionTo(potentialTarget.Center) * HomingSpeed) / HomingInertia; - } - } - } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - CalamityGlobalProjectile.DrawCenteredAndAfterimage(projectile, lightColor, ProjectileID.Sets.TrailingMode[projectile.type], 2); - return false; - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(ModContent.BuffType(), 60); - } - - public override void OnHitPvp(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 60); - } - } -} diff --git a/Projectiles/Summon/DazzlingStabberKnife.png b/Projectiles/Summon/DazzlingStabberKnife.png deleted file mode 100644 index 35d51ec4d1..0000000000 Binary files a/Projectiles/Summon/DazzlingStabberKnife.png and /dev/null differ diff --git a/Projectiles/Summon/EndoHydraHead.cs b/Projectiles/Summon/EndoHydraHead.cs index 1e3eef0a40..664a2756cc 100644 --- a/Projectiles/Summon/EndoHydraHead.cs +++ b/Projectiles/Summon/EndoHydraHead.cs @@ -169,6 +169,7 @@ namespace CalamityMod.Projectiles.Summon projectile.MinionAntiClump(0.15f); AdjustOldVelocityArray(); } + public void AdjustOldVelocityArray() { for (int i = OldVelocities.Length - 1; i > 0; i--) @@ -177,6 +178,7 @@ namespace CalamityMod.Projectiles.Summon } OldVelocities[0] = projectile.velocity; } + public override void Kill(int timeLeft) { for (int i = 0; i < 10; i++) diff --git a/Projectiles/Summon/GammaBullet.cs b/Projectiles/Summon/GammaBullet.cs deleted file mode 100644 index 5da5edb652..0000000000 --- a/Projectiles/Summon/GammaBullet.cs +++ /dev/null @@ -1,70 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Dusts; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Summon -{ - public class GammaBullet : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/Enemy/NuclearBulletMedium"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Gamma Bullet"); - ProjectileID.Sets.MinionShot[projectile.type] = true; - } - - public override void SetDefaults() - { - projectile.width = 24; - projectile.height = 12; - projectile.friendly = true; - projectile.minion = true; - projectile.minionSlots = 0f; - projectile.alpha = 255; - projectile.timeLeft = 180; - projectile.tileCollide = true; - projectile.ignoreWater = true; - } - public override void AI() - { - Lighting.AddLight(projectile.Center, Color.White.ToVector3() * 1.25f); - projectile.ai[1]++; - if (projectile.ai[1] <= 20f) - { - projectile.alpha = (int)MathHelper.Lerp(255, 0, projectile.ai[1] / 20f); - } - if (projectile.ai[1] % 10f == 9f) - { - for (int i = 0; i < 24; i++) - { - float angle = MathHelper.TwoPi / 24f * i; - Dust dust = Dust.NewDustPerfect(projectile.Center + angle.ToRotationVector2().RotatedBy(projectile.rotation) * new Vector2(7f, 4f), (int)CalamityDusts.SulfurousSeaAcid); - dust.scale = 0.9f; - dust.alpha = projectile.alpha; - dust.noGravity = true; - } - } - projectile.velocity *= 1.03f; - projectile.rotation = projectile.velocity.ToRotation(); - } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(ModContent.BuffType(), 240); - } - public override void Kill(int timeLeft) - { - for (int i = 0; i <= 2; i++) - { - int idx = Dust.NewDust(projectile.position, 8, 8, (int)CalamityDusts.SulfurousSeaAcid, 0, 0, 0, default, 0.75f); - Main.dust[idx].noGravity = true; - Main.dust[idx].velocity *= 3f; - idx = Dust.NewDust(projectile.position, 8, 8, (int)CalamityDusts.SulfurousSeaAcid, 0, 0, 0, default, 0.75f); - Main.dust[idx].noGravity = true; - Main.dust[idx].velocity *= 3f; - } - } - } -} diff --git a/Projectiles/Summon/GammaCanister.cs b/Projectiles/Summon/GammaCanister.cs index c997d37fc3..d84d09c414 100644 --- a/Projectiles/Summon/GammaCanister.cs +++ b/Projectiles/Summon/GammaCanister.cs @@ -1,14 +1,13 @@ -using CalamityMod.Dusts; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Summon { public class GammaCanister : ModProjectile { + public const float Gravity = 0.2f; public override void SetStaticDefaults() { DisplayName.SetDefault("Gamma Canister"); @@ -19,75 +18,38 @@ namespace CalamityMod.Projectiles.Summon { projectile.width = 20; projectile.height = 28; - projectile.friendly = projectile.hostile = false; + projectile.friendly = true; projectile.minion = true; projectile.minionSlots = 0f; + projectile.alpha = 255; projectile.timeLeft = 300; projectile.tileCollide = true; projectile.ignoreWater = true; } public override void AI() { - if (!Main.player[projectile.owner].Calamity().GammaCanisters.Contains(projectile.whoAmI)) + NPC potentialTarget = projectile.Center.MinionHoming(1450f, Main.player[projectile.owner]); + if (projectile.timeLeft >= 180) + projectile.velocity.Y += Gravity; + + else if (potentialTarget != null) { - Main.player[projectile.owner].Calamity().GammaCanisters.Add(projectile.whoAmI); + // This looks quite stupid but the weapon is going to be useless otherwise and I'm not reworking this thing a 3rd time. + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.DirectionTo(potentialTarget.Center) * 18f, 0.18f); } - projectile.ai[1]++; - if (projectile.ai[1] == 80f) - { - for (int i = 0; i < 36; i++) - { - Vector2 velocity = Vector2.One.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(3f, 8f); - Dust dust = Dust.NewDustPerfect(projectile.Center, (int)CalamityDusts.SulfurousSeaAcid); - dust.velocity = velocity; - dust.noGravity = true; - dust.scale = Main.rand.NextFloat(1.3f, 1.7f); - } - } - projectile.velocity = Vector2.UnitY * (float)Math.Sin(projectile.ai[1] / 40f * MathHelper.TwoPi) * 0.5f; - } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - const float totalRotations = 3f; - const float outwardPositionDeltaStart = 8f; - float angle = MathHelper.TwoPi * projectile.ai[1] / totalRotations / 80f; - float outwardPositionDelta = outwardPositionDeltaStart; - if (projectile.ai[1] < 80f && projectile.ai[1] > 55f) - { - outwardPositionDelta = MathHelper.Lerp(outwardPositionDeltaStart, 0f, (projectile.ai[1] - 55f) / 35f); - } - if (projectile.ai[1] >= 80f) - { - outwardPositionDelta = 0f; - } - for (int i = 0; i < 3; i++) - { - angle += MathHelper.TwoPi / 3f * i; - spriteBatch.Draw(ModContent.GetTexture(Texture), - projectile.Center + angle.ToRotationVector2() * outwardPositionDelta + Vector2.UnitY * (float)Math.Cos(angle) * 3f - Main.screenPosition, - null, - Color.White, - projectile.rotation, - projectile.Size * 0.5f, - projectile.scale, - SpriteEffects.None, - 0f); - } - return false; + projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; + projectile.alpha = Utils.Clamp(projectile.alpha - 22, 0, 255); } + public override void Kill(int timeLeft) { - Main.player[projectile.owner].Calamity().GammaCanisters.Clear(); + if (Main.myPlayer != projectile.owner) + return; + for (int i = 0; i < 12; i++) { - int idx = Dust.NewDust(projectile.position, 8, 8, (int)CalamityDusts.SulfurousSeaAcid, 0, 0, 0, default, 0.75f); - Main.dust[idx].noGravity = true; - Main.dust[idx].velocity *= 3f; - Main.dust[idx].scale = 1.8f; - idx = Dust.NewDust(projectile.position, 8, 8, (int)CalamityDusts.SulfurousSeaAcid, 0, 0, 0, default, 0.75f); - Main.dust[idx].noGravity = true; - Main.dust[idx].velocity *= 3f; - Main.dust[idx].scale = 1.8f; + Vector2 shootVelocity = (MathHelper.TwoPi * i / 12f).ToRotationVector2() * Main.rand.NextFloat(6f, 17f); + Projectile.NewProjectile(projectile.Center + shootVelocity * 2f, shootVelocity, ModContent.ProjectileType(), projectile.damage / 2, projectile.knockBack * 0.4f, projectile.owner); } } } diff --git a/Projectiles/Summon/GammaDeathray.cs b/Projectiles/Summon/GammaDeathray.cs deleted file mode 100644 index ef056ed865..0000000000 --- a/Projectiles/Summon/GammaDeathray.cs +++ /dev/null @@ -1,192 +0,0 @@ -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.Dusts; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; -using System.IO; -using Terraria; -using Terraria.ID; -using Terraria.Enums; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Summon -{ - public class GammaDeathray : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/Enemy/CragmawBeam"; - - public float MaximumLength => projectile.Distance(Main.MouseWorld); - // How fat the laser is - public const float LaserSize = 1.35f; - // Pretty self explanatory - public const int TotalFadeoutTime = 45; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Gamma Ray"); - ProjectileID.Sets.MinionShot[projectile.type] = true; - } - - public override void SetDefaults() - { - projectile.width = 22; - projectile.height = 22; - projectile.friendly = true; - projectile.minion = true; - projectile.penetrate = -1; - projectile.tileCollide = false; - projectile.timeLeft = 10000; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 7; - } - - // Netcode for sending and receiving shit - // localAI[0] is the timer, localAI[1] is the laser length - - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(projectile.localAI[0]); - writer.Write(projectile.localAI[1]); - } - - public override void ReceiveExtraAI(BinaryReader reader) - { - projectile.localAI[0] = reader.ReadSingle(); - projectile.localAI[1] = reader.ReadSingle(); - } - - public override void AI() - { - Projectile owner = Main.projectile[(int)projectile.ai[0]]; - if (!owner.active || owner.type != ModContent.ProjectileType()) - projectile.Kill(); - - projectile.velocity = projectile.AngleTo(Main.MouseWorld).ToRotationVector2(); - projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; - - if (owner.active) - { - projectile.Center = owner.Center + projectile.AngleTo(Main.MouseWorld).ToRotationVector2() * 12f; - } - projectile.localAI[0] += 1f; - - // Fadein/out. The timeleft varies, so this must be done manually. - if (projectile.localAI[0] < TotalFadeoutTime) - { - projectile.scale = MathHelper.Lerp(0.01f, LaserSize, projectile.localAI[0] / TotalFadeoutTime); - } - - if (projectile.timeLeft < TotalFadeoutTime) - { - projectile.scale = MathHelper.Lerp(LaserSize, 0f, 1f - (projectile.timeLeft / (float)TotalFadeoutTime)); - } - - for (int i = 0; i < 6; i++) - { - Dust dust = Dust.NewDustPerfect(projectile.Center, (int)CalamityDusts.SulfurousSeaAcid); - dust.velocity = projectile.velocity.RotatedBy(MathHelper.Pi * 0.75f) * (i >= 3).ToDirectionInt(); - dust.velocity = dust.velocity.RotatedByRandom(0.3f); - dust.noGravity = true; - dust.scale = 1f / (float)Math.Cos(i / 6f * MathHelper.PiOver2) / (float)Math.Sqrt(i + 1); - } - - Vector2 samplingPoint = projectile.Center; - - float[] samples = new float[3]; - - float determinedLength = 0f; - Collision.LaserScan(samplingPoint, projectile.velocity, projectile.width * projectile.scale, MaximumLength, samples); - for (int i = 0; i < samples.Length; i++) - { - determinedLength += samples[i]; - } - determinedLength /= samples.Length; - - determinedLength = MathHelper.Clamp(determinedLength, MaximumLength * 0.5f, MaximumLength); - - float lerpDelta = 0.5f; - projectile.localAI[1] = MathHelper.Lerp(projectile.localAI[1], determinedLength, lerpDelta); - Vector2 beamEndPosiiton = projectile.Center + projectile.velocity * (projectile.localAI[1] - 6f); - - // Draw acid green light across the laser - DelegateMethods.v3_1 = new Vector3(0.62f, 0.94f, 0.38f); - Utils.PlotTileLine(projectile.Center, projectile.Center + projectile.velocity * projectile.localAI[1], projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CastLight)); - } - public override void Kill(int timeLeft) - { - Main.projectile[(int)projectile.ai[0]].ai[0] = 0f; // Detach this laser from its owner. - Main.projectile[(int)projectile.ai[0]].netUpdate = true; - } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - if (projectile.velocity == Vector2.Zero) - { - return false; - } - Texture2D laserTailTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/GammaBeamBegin"); - Texture2D laserBodyTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/GammaBeamMid"); - Texture2D laserHeadTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/GammaBeamEnd"); - float laserLength = projectile.localAI[1]; - Color drawColor = new Color(1f, 1f, 1f) * 0.9f; - - // Laser tail logic - - Main.spriteBatch.Draw(laserTailTexture, projectile.Center - Main.screenPosition, null, drawColor, projectile.rotation, laserTailTexture.Size() / 2f, projectile.scale, SpriteEffects.None, 0f); - - // Laser body logic - - laserLength -= (laserTailTexture.Height / 2 + laserHeadTexture.Height) * projectile.scale; - Vector2 centerDelta = projectile.Center; - centerDelta += projectile.velocity * projectile.scale * (float)laserTailTexture.Height / 2f; - if (laserLength > 0f) - { - float laserLengthDelta = 0f; - Rectangle sourceRectangle = new Rectangle(0, 16 * (projectile.timeLeft / 3 % 5), laserBodyTexture.Width, 16); - while (laserLengthDelta + 1f < laserLength) - { - if (laserLength - laserLengthDelta < sourceRectangle.Height) - { - sourceRectangle.Height = (int)(laserLength - laserLengthDelta); - } - Main.spriteBatch.Draw(laserBodyTexture, centerDelta - Main.screenPosition, new Rectangle?(sourceRectangle), drawColor, projectile.rotation, new Vector2(sourceRectangle.Width / 2f, 0f), projectile.scale, SpriteEffects.None, 0f); - laserLengthDelta += sourceRectangle.Height * projectile.scale; - centerDelta += projectile.velocity * sourceRectangle.Height * projectile.scale; - sourceRectangle.Y += 16; - if (sourceRectangle.Y + sourceRectangle.Height > laserBodyTexture.Height) - { - sourceRectangle.Y = 0; - } - } - } - - // Laser head logic - - Main.spriteBatch.Draw(laserHeadTexture, centerDelta - Main.screenPosition, null, drawColor, projectile.rotation, laserHeadTexture.Frame(1, 1, 0, 0).Top(), projectile.scale, SpriteEffects.None, 0f); - return false; - } - - public override void CutTiles() - { - DelegateMethods.tilecut_0 = TileCuttingContext.AttackProjectile; - Vector2 unit = projectile.velocity; - Utils.PlotTileLine(projectile.Center, projectile.Center + unit * projectile.localAI[1], (float)projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CutTiles)); - } - - public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) - { - if (projHitbox.Intersects(targetHitbox)) - { - return true; - } - float value = 0f; - if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + projectile.velocity * projectile.localAI[1], 22f * projectile.scale, ref value)) - { - return true; - } - return false; - } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(ModContent.BuffType(), 300); - } - } -} diff --git a/Projectiles/Summon/GammaHead.cs b/Projectiles/Summon/GammaHead.cs index 9677b86323..39baa1a432 100644 --- a/Projectiles/Summon/GammaHead.cs +++ b/Projectiles/Summon/GammaHead.cs @@ -1,10 +1,11 @@ using CalamityMod.Buffs.Summon; +using CalamityMod.DataStructures; using CalamityMod.Dusts; -using CalamityMod.CalPlayer; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -13,14 +14,20 @@ namespace CalamityMod.Projectiles.Summon { public class GammaHead : ModProjectile { - public Vector2 DeltaPosition; - public int BulletShootCounter; - public float AngularMultiplier1; - public float AngularMultiplier2; - public const int MaximumLaserCount = 6; // Otherwise intense lag ensues. - public const float AttackStartWait = 30f; - public const float SuperchargeTimeMax = 540f; - public const float DistanceToCheck = 1000f; + public Vector2 CurrentPositionOffset; + public Vector2 IdealPositionOffset; + public Vector2[] OldVelocities = new Vector2[20]; + public Player Owner => Main.player[projectile.owner]; + public ref float Time => ref projectile.ai[0]; + public Vector2 DrawStartPosition + { + get + { + if (projectile.owner < 0 || projectile.owner >= Main.player.Length) + return Vector2.Zero; + return Main.player[projectile.owner].Top + Vector2.UnitY * 8f; + } + } public override void SetStaticDefaults() { DisplayName.SetDefault("Gamma Head"); @@ -42,278 +49,216 @@ namespace CalamityMod.Projectiles.Summon projectile.tileCollide = false; projectile.timeLeft *= 5; projectile.minion = true; - projectile.coldDamage = true; - } - public Vector2 DrawStartPosition - { - get - { - if (projectile.owner < 0 || projectile.owner >= Main.player.Length) - return Vector2.Zero; - return Main.player[projectile.owner].Top + Vector2.UnitY * 8f; - } - } - public override void ReceiveExtraAI(BinaryReader reader) - { - BulletShootCounter = reader.ReadInt32(); - AngularMultiplier1 = reader.ReadSingle(); - AngularMultiplier2 = reader.ReadSingle(); - DeltaPosition = reader.ReadVector2(); } + public override void SendExtraAI(BinaryWriter writer) { - writer.Write(BulletShootCounter); - writer.Write(AngularMultiplier1); - writer.Write(AngularMultiplier2); - writer.WriteVector2(DeltaPosition); + writer.WritePackedVector2(CurrentPositionOffset); + writer.WritePackedVector2(IdealPositionOffset); } + + public override void ReceiveExtraAI(BinaryReader reader) + { + CurrentPositionOffset = reader.ReadPackedVector2(); + IdealPositionOffset = reader.ReadPackedVector2(); + } + public override void AI() { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); + Vector2 returnPosition = DrawStartPosition + CurrentPositionOffset; - if (DeltaPosition == Vector2.Zero) + if (projectile.localAI[0] == 0f) { - int totalHeads = CalamityUtils.CountProjectiles(projectile.type); - DeltaPosition = new Vector2(Main.rand.NextFloat(-42f - 6f * totalHeads, 42f + 6f * totalHeads), -Main.rand.NextFloat(8f, 64f + 7f * totalHeads)); - - projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); - projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; - - AngularMultiplier1 = Main.rand.NextFloat(3f); - AngularMultiplier2 = Main.rand.NextFloat(3f); - projectile.netUpdate = true; + PerformInitializationEffects(); projectile.localAI[0] = 1f; - } - - bool isProperProjectile = projectile.type == ModContent.ProjectileType(); - player.AddBuff(ModContent.BuffType(), 3600); - if (isProperProjectile) - { - if (player.dead) - { - modPlayer.gammaHead = false; - } - if (modPlayer.gammaHead) - { - projectile.timeLeft = 2; - } } - if (modPlayer.GammaCanisters.Count > 0) - { - for (int i = 0; i < modPlayer.GammaCanisters.Count; i++) - { - if (projectile.Hitbox.Intersects(Main.projectile[modPlayer.GammaCanisters[i]].Hitbox) && - Main.projectile[modPlayer.GammaCanisters[i]].active) - { - int laserCount = 0; - for (int j = 0; j < Main.projectile.Length; j++) - { - if (laserCount < MaximumLaserCount) - { - if (Main.projectile[j].type == projectile.type && Main.projectile[j].owner == projectile.owner && - Main.projectile[j].ai[0] == 0f && Main.projectile[j].active && Main.projectile[j].ai[1] <= 0) - { - Main.projectile[j].ai[0] = Projectile.NewProjectile(projectile.Center, Vector2.UnitY, ModContent.ProjectileType(), - (int)(projectile.damage * 1.2f), projectile.knockBack, projectile.owner, Main.projectile[j].whoAmI); + ApplyMinionBuffs(); - Main.projectile[j].ai[1] = SuperchargeTimeMax; - Main.projectile[j].netUpdate = true; - laserCount++; - } - } - else - { - Main.projectile[j].ai[1] = SuperchargeTimeMax; - Main.projectile[j].netUpdate = true; - } - } + projectile.direction = projectile.spriteDirection = Owner.direction; - // Kill removes the respective canister from the list. No need to do this manually. - for (int j = 0; j < modPlayer.GammaCanisters.Count; j++) - { - Main.projectile[modPlayer.GammaCanisters[i]].Kill(); - } - break; - } - } - } - - // Spawn gamma canisters - else if (player.ownedProjectileCounts[projectile.type] >= 7) - { - int ownedGammaHeads = player.ownedProjectileCounts[projectile.type]; - int canisterSpawnChance = 520 - (int)(200 * (1 - 1f / (ownedGammaHeads + 6f))); - if (Main.rand.NextBool(canisterSpawnChance * ownedGammaHeads)) - { - Vector2 spawnPosition = player.Center + new Vector2(Main.screenWidth / 2, Main.screenHeight / 2) * Main.rand.NextFloat(-1f, 1f); - Projectile.NewProjectileDirect(spawnPosition, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, projectile.owner); - } - } - - // Omega-complex dust. - projectile.localAI[1]++; - if (projectile.localAI[1] < 60f) - { - for (int i = 0; i < 5; i++) - { - float angle = projectile.localAI[1] / 60f * MathHelper.TwoPi; - float x = (float)Math.Sin(angle * AngularMultiplier1) * (float)Math.Cos(angle); - float y = (float)Math.Cos(angle * (float)Math.Cos(MathHelper.PiOver2 * AngularMultiplier2 + angle * 2f)) * (float)Math.Sin(angle); - Vector2 velocity = new Vector2(x * 4f, y * 4f) + player.velocity; - velocity = velocity.RotatedBy(MathHelper.TwoPi / 5f * i); - - Dust dust = Dust.NewDustPerfect(projectile.Center + angle.ToRotationVector2() * 8f, (int)CalamityDusts.SulfurousSeaAcid); - dust.velocity = velocity; - dust.scale = (float)Math.Cos(angle) + 1.3f; - dust.noGravity = true; - } - } - // Explosion - if (projectile.localAI[1] == 60f) - { - for (int i = 0; i < 60; i++) - { - float angle = MathHelper.TwoPi / 60f * i; - angle += projectile.AngleFrom(player.Center) / 60f; - angle += (float)Math.Sin(angle) * MathHelper.PiOver2; - Dust dust = Dust.NewDustPerfect(projectile.Center + angle.ToRotationVector2() * 8f, (int)CalamityDusts.SulfurousSeaAcid); - dust.velocity = angle.ToRotationVector2() * new Vector2(4f, 3f * (float)Math.Cos(angle)) * 3f; - dust.scale = 1.3f; - dust.noGravity = true; - } - } - if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) - { - int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / - projectile.Calamity().spawnedPlayerMinionDamageValue * - player.MinionDamage()); - projectile.damage = trueDamage; - } - - Vector2 returnPosition = DrawStartPosition + (player.direction > 0).ToDirectionInt() * 6f * Vector2.UnitX + DeltaPosition; - - NPC potentialTarget = projectile.Center.MinionHoming(DistanceToCheck, player); - - // Kill laser when done - if (projectile.ai[1] == GammaDeathray.TotalFadeoutTime && projectile.ai[0] != 0f) - { - for (int i = 0; i < Main.projectile.Length; i++) - { - if (Main.projectile[i].active && Main.projectile[i].ai[1] >= 0f && Main.projectile[i].type == projectile.type && Main.projectile[i].owner == projectile.owner) - { - Main.projectile[i].spriteDirection = 1; - Main.projectile[i].ai[1] = 0f; - Main.projectile[i].netUpdate = true; - Main.projectile[(int)Main.projectile[i].ai[0]].timeLeft = GammaDeathray.TotalFadeoutTime; - } - } - } - // Bullet/deathray - if (projectile.ai[1] > 0) - { - projectile.direction = projectile.spriteDirection = 1; - projectile.rotation = projectile.AngleTo(Main.MouseWorld); - projectile.ai[1]--; - } - else if (potentialTarget != null) - { - if (projectile.Distance(player.Center) < DistanceToCheck && - Collision.CanHit(projectile.Center, 1, 1, player.Center, 1, 1) && - Main.myPlayer == projectile.owner) - { - BulletShootCounter++; - if (BulletShootCounter % 20f == 14f) - { - Projectile bullet = Projectile.NewProjectileDirect(projectile.Center, - projectile.DirectionTo(potentialTarget.Center) * 8f, - ModContent.ProjectileType(), projectile.damage, 2f, projectile.owner); - bullet.ai[0] = potentialTarget.whoAmI; - } - - if (BulletShootCounter % 20f >= 17f) - projectile.frame = Main.projFrames[projectile.type] - 1; - else if (BulletShootCounter % 20f >= 11f) - projectile.frame = Main.projFrames[projectile.type] - 2; - else if (BulletShootCounter % 20f >= 6f) - projectile.frame = Main.projFrames[projectile.type] - 3; - - projectile.direction = projectile.spriteDirection = (potentialTarget.Center.X - projectile.Center.X > 0).ToDirectionInt(); - returnPosition.X -= 48f * (player.Center.X - projectile.Center.X > 0).ToDirectionInt(); - } - else - { - projectile.direction = projectile.spriteDirection = (player.Center.X - projectile.Center.X > 0).ToDirectionInt(); - projectile.frame = 0; - } - projectile.rotation = projectile.rotation.AngleTowards(0f, 0.05f); - } + float idealRotation = 0f; + NPC potentialTarget = projectile.Center.MinionHoming(950f, Owner); + if (potentialTarget != null) + NoticeTarget(potentialTarget, ref returnPosition, ref idealRotation); else - { - projectile.direction = projectile.spriteDirection = (player.Center.X - projectile.Center.X > 0).ToDirectionInt(); - projectile.rotation = projectile.rotation.AngleTowards(0f, 0.05f); projectile.frame = 0; + + projectile.rotation = projectile.rotation.AngleLerp(idealRotation, 0.15f); + projectile.rotation = projectile.rotation.AngleTowards(idealRotation, 0.15f); + + projectile.Center = new Vector2(projectile.Center.X, MathHelper.Clamp(projectile.Center.Y, 1f, returnPosition.Y - 8f)); + MoveTowardsDestination(returnPosition); + AdjustOldVelocityArray(); + + Time++; + } + + public void PerformInitializationEffects() + { + int totalHeads = CalamityUtils.CountProjectiles(projectile.type); + CurrentPositionOffset = IdealPositionOffset = new Vector2(Main.rand.NextFloat(-72f - 8f * totalHeads, 72f + 8f * totalHeads), -Main.rand.NextFloat(8f, 84f + 4f * totalHeads)); + projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + + projectile.netUpdate = true; + + if (Main.dedServ) + return; + + // Release a circle of sulphuric dust. + for (int i = 0; i < 18; i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center, (int)CalamityDusts.SulfurousSeaAcid); + dust.velocity = new Vector2(0f, -5f).RotatedBy(i / 18f * MathHelper.TwoPi); + dust.noGravity = true; + dust.scale = 1.35f; + } + } + + public void ApplyMinionBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + if (projectile.type == ModContent.ProjectileType()) + { + if (Owner.dead) + Owner.Calamity().gammaHead = false; + if (Owner.Calamity().gammaHead) + projectile.timeLeft = 2; + } + } + + public void NoticeTarget(NPC target, ref Vector2 returnPosition, ref float idealRotation) + { + // Reel back a bit if a valid target has been located. + returnPosition -= (target.Center - projectile.Center).SafeNormalize(Vector2.Zero) * 16f; + + // And release canisters from time to time. + int canisterShootRate = 100; + + // Open the mouth prior to firing. + if (Time % canisterShootRate > canisterShootRate - 20) + projectile.frame = (int)(Main.projFrames[projectile.type] * Utils.InverseLerp(canisterShootRate - 20, canisterShootRate - 4, Time % canisterShootRate, true)); + projectile.frame %= Main.projFrames[projectile.type]; + + Vector2 spawnPosition = projectile.Center; + float shootSpeed = MathHelper.Lerp(8f, 20f, Utils.InverseLerp(90f, 850f, target.Distance(spawnPosition), true)); + Vector2 shootVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(spawnPosition, target.Center, GammaCanister.Gravity, shootSpeed, projectile.DirectionTo(target.Center)); + float fireAngle = shootVelocity.ToRotation(); + + // Direction affecting. + if (target.Center.X - spawnPosition.X < 0) + fireAngle += MathHelper.Pi; + idealRotation = fireAngle; + + // Shoot the actual canister. + if (Main.myPlayer == projectile.owner && Time % canisterShootRate == canisterShootRate - 1) + Projectile.NewProjectile(spawnPosition, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + } + + public void MoveTowardsDestination(Vector2 returnPosition) + { + float distanceFromTarget = projectile.Distance(returnPosition); + if (distanceFromTarget > 7f) + { + float flySpeed = MathHelper.Lerp(2f, 17f, Utils.InverseLerp(10f, 70f, distanceFromTarget, true)); + projectile.velocity = (projectile.velocity * 9f + projectile.DirectionTo(returnPosition) * flySpeed) / 10f; } - if (projectile.Distance(returnPosition) > 28f) - { - projectile.velocity += new Vector2(Math.Sign(returnPosition.X - projectile.Center.X), Math.Sign(returnPosition.Y - projectile.Center.Y)) * new Vector2(0.015f, 0.025f) * Main.rand.NextFloat(0.98f, 1.02f); - if (Math.Abs(projectile.velocity.X) > 2.5f) - { - projectile.velocity.X = 2.1f * Math.Sign(projectile.velocity.X); - } - if (Math.Abs(projectile.velocity.Y) > 1.6f) - { - projectile.velocity.Y = 1.4f * Math.Sign(projectile.velocity.Y); - } - projectile.velocity += (returnPosition - projectile.Center) / 10f; - } - else projectile.velocity *= 0.98f; - projectile.Center = new Vector2(projectile.Center.X, MathHelper.Clamp(projectile.Center.Y, 1f, returnPosition.Y - 8f)); + int totalHeads = CalamityUtils.CountProjectiles(projectile.type); + int moveRate = 40 + totalHeads * 4; + + // Reset the ideal offset from time to time. + if (Time % moveRate == moveRate - 1f) + IdealPositionOffset = new Vector2(Main.rand.NextFloat(-72f - 8f * totalHeads, 72f + 8f * totalHeads), -Main.rand.NextFloat(8f, 84f + 4f * totalHeads)); + + if (Vector2.Distance(IdealPositionOffset, CurrentPositionOffset) > 0.2f) + CurrentPositionOffset = Vector2.Lerp(CurrentPositionOffset, IdealPositionOffset, 0.125f); + + // Clamp the Y position. + if (projectile.Center.Y > Owner.Top.Y - 46f) + projectile.Center = new Vector2(projectile.Center.X, Owner.Top.Y - 46f); + + // Clamp the center so that it does not go too far from the return position. + if (projectile.Distance(returnPosition) > 120f) + projectile.Center = returnPosition + projectile.DirectionFrom(returnPosition) * 120f; + + // Disallow heads from getting too close to each other. + projectile.MinionAntiClump(0.15f); } + + public void AdjustOldVelocityArray() + { + for (int i = OldVelocities.Length - 1; i > 0; i--) + OldVelocities[i] = OldVelocities[i - 1]; + + OldVelocities[0] = projectile.velocity; + } + public override void Kill(int timeLeft) { + if (Main.dedServ) + return; + for (int i = 0; i < 10; i++) - { - Dust.NewDustPerfect(projectile.Center, (int)CalamityDusts.SulfurousSeaAcid, Vector2.One.RotatedByRandom(MathHelper.TwoPi) * 4f).noGravity = true; - } + Dust.NewDustPerfect(projectile.Center, (int)CalamityDusts.SulfurousSeaAcid, Main.rand.NextVector2CircularEdge(4f, 4f)).noGravity = true; } - public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { - Player player = Main.player[projectile.owner]; - Texture2D chain = ModContent.GetTexture("CalamityMod/Projectiles/Summon/GammaHeadChain"); - Vector2 start = projectile.Center + (projectile.spriteDirection == -1).ToInt() * 10f * Vector2.UnitX; - Vector2 end = DrawStartPosition - projectile.DirectionTo(DrawStartPosition) * 11f; - Vector2 bodyTop = DrawStartPosition + new Vector2(player.direction == 1 ? 6f : -6f, 0f); + Vector2 end = projectile.Center + (projectile.spriteDirection == 1).ToInt() * 10 * Vector2.UnitX; - for (int i = 0; i <= (int)projectile.Distance(end) / 10 + 1; i++) + List controlPoints = new List { - float ratio = i / (projectile.Distance(end) / 10 + 1); - Vector2 positionAtPoint = start + (bodyTop - start) * ratio; - if (projectile.Distance(positionAtPoint) > 9) - { - float angleAtPoint = (start - positionAtPoint).ToRotation(); - if (i < (int)projectile.Distance(end) / 10 + 1) - { - float nextRatio = (i + 1f) / (projectile.Distance(end) / 10 + 1); - Vector2 nextPositionAtPoint = start + (bodyTop - start) * nextRatio; - - angleAtPoint = (nextPositionAtPoint - positionAtPoint).ToRotation(); - } - angleAtPoint += MathHelper.PiOver2; - spriteBatch.Draw(chain, - positionAtPoint - Main.screenPosition, - null, - Color.Lerp(Color.White, Color.Transparent, 0.5f), - angleAtPoint, - chain.Size() / 2f, - 1f, - SpriteEffects.None, - 0f); - } + DrawStartPosition + }; + for (int i = 0; i < OldVelocities.Length; i++) + { + // Incorporate the past movement into neck turns, giving it rubber band-like movment. + // Become less responsive at the neck ends. Having the ends have typical movement can look strange sometimes. + float swayResponsiveness = Utils.InverseLerp(0f, 6f, i, true) * Utils.InverseLerp(OldVelocities.Length, OldVelocities.Length - 6f, i, true); + Vector2 swayTotalOffset = OldVelocities[i] * swayResponsiveness; + controlPoints.Add(Vector2.Lerp(DrawStartPosition, end, i / (float)OldVelocities.Length) + swayTotalOffset); } + controlPoints.Add(end); + + int chainPointCount = (int)(Vector2.Distance(controlPoints.First(), controlPoints.Last()) / 5f); + if (chainPointCount < 12) + chainPointCount = 12; + BezierCurve bezierCurve = new BezierCurve(controlPoints.ToArray()); + List chainPoints = bezierCurve.GetPoints(chainPointCount); + + for (int i = 0; i < chainPoints.Count; i++) + { + Vector2 positionAtPoint = chainPoints[i]; + if (Vector2.Distance(positionAtPoint, projectile.Center) < 10f) + continue; + float angleAtPoint = i == chainPoints.Count - 1 ? (end - chainPoints[i]).ToRotation() : (chainPoints[i + 1] - chainPoints[i]).ToRotation(); + angleAtPoint += MathHelper.PiOver2; + spriteBatch.Draw(chain, + positionAtPoint - Main.screenPosition, + null, + Color.Lerp(Color.White, Color.Transparent, 0.6f), + angleAtPoint, + chain.Size() / 2f, + 1f, + SpriteEffects.None, + 0f); + } + + Texture2D headTexture = ModContent.GetTexture(Texture); + spriteBatch.Draw(headTexture, + projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY, + headTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame), + lightColor, + projectile.rotation, + projectile.Size * 0.5f, + projectile.scale, + projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, + 0f); + + return false; } public override bool CanDamage() => false; } diff --git a/Projectiles/Summon/HomingGammaBullet.cs b/Projectiles/Summon/HomingGammaBullet.cs new file mode 100644 index 0000000000..54ccff874f --- /dev/null +++ b/Projectiles/Summon/HomingGammaBullet.cs @@ -0,0 +1,60 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Dusts; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class HomingGammaBullet : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Enemy/NuclearBulletMedium"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gamma Bullet"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.width = 24; + projectile.height = 12; + projectile.friendly = true; + projectile.minion = true; + projectile.minionSlots = 0f; + projectile.alpha = 255; + projectile.timeLeft = 360; + projectile.tileCollide = true; + projectile.ignoreWater = true; + } + + public override void AI() + { + projectile.alpha = Utils.Clamp(projectile.alpha - 35, 0, 255); + projectile.rotation = projectile.velocity.ToRotation(); + + NPC potentialTarget = projectile.Center.MinionHoming(700f, Main.player[projectile.owner]); + if (potentialTarget != null && !projectile.WithinRange(potentialTarget.Center, 100f) && projectile.timeLeft < 290) + projectile.velocity = (projectile.velocity * 6f + projectile.DirectionTo(potentialTarget.Center) * 15f) / 7f; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => target.AddBuff(ModContent.BuffType(), 240); + + public override void Kill(int timeLeft) + { + if (Main.dedServ) + return; + + for (int i = 0; i < 3; i++) + { + Dust sulphuricAcid = Dust.NewDustDirect(projectile.position, 8, 8, (int)CalamityDusts.SulfurousSeaAcid, 0, 0, 0, default, 0.75f); + sulphuricAcid.noGravity = true; + sulphuricAcid.velocity *= 1.8f; + + sulphuricAcid = Dust.CloneDust(sulphuricAcid); + sulphuricAcid.velocity *= -1f; + } + } + } +} diff --git a/TrailGeneration/PrimitiveTrail.cs b/TrailGeneration/PrimitiveTrail.cs index 6582821d20..f58f0a90f8 100644 --- a/TrailGeneration/PrimitiveTrail.cs +++ b/TrailGeneration/PrimitiveTrail.cs @@ -3,10 +3,9 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; -using System.Diagnostics.Contracts; using System.Linq; -using System.Runtime.CompilerServices; using Terraria; +using Terraria.Graphics.Shaders; namespace CalamityMod { @@ -16,17 +15,20 @@ namespace CalamityMod { public Vector2 Position; public Color Color; + public Vector2 TextureCoordinates; public VertexDeclaration VertexDeclaration => _vertexDeclaration; private static readonly VertexDeclaration _vertexDeclaration = new VertexDeclaration(new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0), - new VertexElement(8, VertexElementFormat.Color, VertexElementUsage.Color, 0) + new VertexElement(8, VertexElementFormat.Color, VertexElementUsage.Color, 0), + new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), }); - public VertexPosition2DColor(Vector2 position, Color color) + public VertexPosition2DColor(Vector2 position, Color color, Vector2 textureCoordinates) { Position = position; Color = color; + TextureCoordinates = textureCoordinates; } } @@ -36,25 +38,37 @@ namespace CalamityMod public VertexWidthFunction WidthFunction; public VertexColorFunction ColorFunction; - public Effect EffectToUse; + public BasicEffect BaseEffect; + public MiscShaderData SpecialShader; + public TrailPointRetrievalFunction TrailPointFunction; - public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, Effect specialShader = null) + public delegate List TrailPointRetrievalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null); + + public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, TrailPointRetrievalFunction pointFunction = null, MiscShaderData specialShader = null) { if (widthFunction is null || colorFunction is null) throw new NullReferenceException($"In order to create a primitive trail, a non-null {(widthFunction is null ? "width" : "color")} function must be specified."); WidthFunction = widthFunction; ColorFunction = colorFunction; - EffectToUse = specialShader ?? new BasicEffect(Main.instance.GraphicsDevice); - if (EffectToUse is BasicEffect) + // Default to bezier smoothening if nothing else is inputted. + if (pointFunction is null) + pointFunction = SmoothBezierPointRetreivalFunction; + + TrailPointFunction = pointFunction; + + if (specialShader != null) + SpecialShader = specialShader; + + BaseEffect = new BasicEffect(Main.instance.GraphicsDevice) { - (EffectToUse as BasicEffect).VertexColorEnabled = true; - (EffectToUse as BasicEffect).TextureEnabled = false; - UpdateBasicEffect(EffectToUse as BasicEffect); - } + VertexColorEnabled = true, + TextureEnabled = false + }; + UpdateBaseEffect(out _, out _); } - public void UpdateBasicEffect(BasicEffect effect) + public void UpdateBaseEffect(out Matrix effectProjection, out Matrix effectView) { // The screen width and height. int width = Main.instance.GraphicsDevice.Viewport.Width; @@ -63,7 +77,7 @@ namespace CalamityMod Vector2 zoom = Main.GameViewMatrix.Zoom; // Get a matrix that aims towards the Z axis (these calculations are relative to a 2D world). - Matrix effectView = Matrix.CreateLookAt(Vector3.Zero, Vector3.UnitZ, Vector3.Up); + effectView = Matrix.CreateLookAt(Vector3.Zero, Vector3.UnitZ, Vector3.Up); // Offset the matrix to the appropriate position. effectView *= Matrix.CreateTranslation(width / 2, height / -2, 0f); @@ -74,30 +88,72 @@ namespace CalamityMod // And account for the current zoom. effectView *= Matrix.CreateScale(zoom.X, zoom.Y, 1f); - Matrix effectProjection = Matrix.CreateOrthographic(width, height, 0f, 1000f); - effect.View = effectView; - effect.Projection = effectProjection; + effectProjection = Matrix.CreateOrthographic(width, height, 0f, 1000f); + BaseEffect.View = effectView; + BaseEffect.Projection = effectProjection; } - [Pure] - public List GetTrailPoints(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints) + public static List RigidPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) { - if (EffectToUse is BasicEffect) - UpdateBasicEffect((BasicEffect)EffectToUse); - List originalControlPoints = new List(); + List basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList(); + List endPoints = new List(); + + if (basePoints.Count < 3) + return endPoints; + + // Remap the original positions across a certain length. + for (int i = 0; i < totalTrailPoints; i++) + { + float completionRatio = i / (float)totalTrailPoints; + int currentColorIndex = (int)(completionRatio * (basePoints.Count - 1)); + Vector2 currentColor = basePoints[currentColorIndex]; + Vector2 nextColor = basePoints[(currentColorIndex + 1) % basePoints.Count]; + endPoints.Add(Vector2.Lerp(currentColor, nextColor, completionRatio * (basePoints.Count - 1) % 0.999f) + generalOffset); + } + return endPoints; + } + + // NOTE: Beziers can be laggy when a lot of control points are used, since our implementation + // uses a recursive Lerp that gets more computationally expensive the more original indices. + // n(n + 1)/2 linear interpolations to be precise, where n is the amount of original indices. + public static List SmoothBezierPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) + { + List controlPoints = new List(); for (int i = 0; i < originalPositions.Count(); i++) { // Don't incorporate points that are zeroed out. // They are almost certainly a result of incomplete oldPos arrays. if (originalPositions.ElementAt(i) == Vector2.Zero) continue; - originalControlPoints.Add(originalPositions.ElementAt(i) + generalOffset); + controlPoints.Add(originalPositions.ElementAt(i) + generalOffset); } - BezierCurve bezierCurve = new BezierCurve(originalControlPoints.ToArray()); - return originalControlPoints.Count <= 1 ? originalControlPoints : bezierCurve.GetPoints(totalTrailPoints); + BezierCurve bezierCurve = new BezierCurve(controlPoints.ToArray()); + return controlPoints.Count <= 1 ? controlPoints : bezierCurve.GetPoints(totalTrailPoints); } - public List GetVerticesFromTrailPoints(List trailPoints) + public static List SmoothCatmullRomPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations) + { + List smoothenedPoints = new List(); + for (int i = 0; i < originalPositions.Count() - 1; i++) + { + if (originalPositions.ElementAt(i) == Vector2.Zero || originalPositions.ElementAt(i + 1) == Vector2.Zero) + continue; + + float currentRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i)); + float aheadRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i + 1)); + int pointsToAdd = (int)(Math.Abs(aheadRotation - currentRotation) * 50f / MathHelper.Pi) + 4; + + float segmentLength = Vector2.Distance(originalPositions.ElementAt(i), originalPositions.ElementAt(i + 1)); + float increment = 1f / (pointsToAdd + 2); + Vector2 end = originalPositions.ElementAt(i) + currentRotation.ToRotationVector2() * segmentLength; + Vector2 front = originalPositions.ElementAt(i + 1) + aheadRotation.ToRotationVector2() * -segmentLength; + for (float j = increment; j < 1f; j += increment) + smoothenedPoints.Add(Vector2.CatmullRom(end, originalPositions.ElementAt(i), originalPositions.ElementAt(i + 1), front, j) + generalOffset); + } + return smoothenedPoints; + } + + public VertexPosition2DColor[] GetVerticesFromTrailPoints(List trailPoints) { List vertices = new List(); for (int i = 0; i < trailPoints.Count - 1; i++) @@ -110,52 +166,82 @@ namespace CalamityMod Vector2 positionAhead = trailPoints[i + 1]; Vector2 directionToAhead = (positionAhead - trailPoints[i]).SafeNormalize(Vector2.Zero); + Vector2 leftCurrentTextureCoord = new Vector2(completionRatio, 0f); + Vector2 rightCurrentTextureCoord = new Vector2(completionRatio, 1f); + // Point 90 degrees away from the direction towards the next point, and use it to mark the edges of the rectangle. // This doesn't use RotatedBy for the sake of performance (there can potentially be a lot of trail points). Vector2 sideDirection = new Vector2(-directionToAhead.Y, directionToAhead.X); - // The bounds of the rectangle. - Vector2 firstUp = currentPosition - sideDirection * widthAtVertex; - Vector2 firstDown = currentPosition + sideDirection * widthAtVertex; - - Vector2 secondUp = positionAhead - sideDirection * widthAtVertex; - Vector2 secondDown = positionAhead + sideDirection * widthAtVertex; - // What this is doing, at its core, is defining a rectangle based on two triangles. // These triangles are defined based on the width of the strip at that point. - // These rectangles combined are what make the trail itself. - vertices.Add(new VertexPosition2DColor(firstUp, vertexColor)); - vertices.Add(new VertexPosition2DColor(secondUp, vertexColor)); - vertices.Add(new VertexPosition2DColor(firstDown, vertexColor)); - - vertices.Add(new VertexPosition2DColor(secondUp, vertexColor)); - vertices.Add(new VertexPosition2DColor(secondDown, vertexColor)); - vertices.Add(new VertexPosition2DColor(firstDown, vertexColor)); + // The resulting rectangles combined are what make the trail itself. + vertices.Add(new VertexPosition2DColor(currentPosition - sideDirection * widthAtVertex, vertexColor, leftCurrentTextureCoord)); + vertices.Add(new VertexPosition2DColor(currentPosition + sideDirection * widthAtVertex, vertexColor, rightCurrentTextureCoord)); } - return vertices; + + return vertices.ToArray(); } - public void Draw(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints) + public short[] GetIndicesFromTrailPoints(int pointCount) + { + // What this is doing is basically representing each point on the vertices list as + // indices. These indices should come together to create a tiny rectangle that acts + // as a segment on the trail. This is achieved here by splitting the indices (or rather, points) + // into 2 triangles, which requires 6 points. + // The logic here basically determines which indices are connected together. + int totalIndices = (pointCount - 1) * 6; + short[] indices = new short[totalIndices]; + + for (int i = 0; i < pointCount - 2; i++) + { + int startingTriangleIndex = i * 6; + int connectToIndex = i * 2; + indices[startingTriangleIndex] = (short)connectToIndex; + indices[startingTriangleIndex + 1] = (short)(connectToIndex + 1); + indices[startingTriangleIndex + 2] = (short)(connectToIndex + 2); + indices[startingTriangleIndex + 3] = (short)(connectToIndex + 2); + indices[startingTriangleIndex + 4] = (short)(connectToIndex + 1); + indices[startingTriangleIndex + 5] = (short)(connectToIndex + 3); + } + + return indices; + } + + public void Draw(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) { Main.instance.GraphicsDevice.RasterizerState = RasterizerState.CullNone; - - List trailPoints = GetTrailPoints(originalPositions, generalOffset, totalTrailPoints); + List trailPoints = TrailPointFunction(originalPositions, generalOffset, totalTrailPoints, originalRotations); // A trail with only one point or less has nothing to connect to, and therefore, can't make a trail. - if (trailPoints.Count <= 1) + if (originalPositions.Count() <= 2 || trailPoints.Count <= 2) return; - List vertices = GetVerticesFromTrailPoints(trailPoints); + // If the trail point has any NaN positions, don't draw anything. + if (trailPoints.Any(point => point.HasNaNs())) + return; - foreach (var pass in EffectToUse.CurrentTechnique.Passes) + UpdateBaseEffect(out Matrix projection, out Matrix view); + VertexPosition2DColor[] vertices = GetVerticesFromTrailPoints(trailPoints); + + short[] triangleIndices = GetIndicesFromTrailPoints(trailPoints.Count); + + // Don't draw anything if the indicies/vertices are in any way invalid. + // If they are, the graphics engine, along with the entire game, will crash. + if (triangleIndices.Length % 6 != 0 || vertices.Length % 2 != 0) + return; + + if (SpecialShader != null) { - pass.Apply(); - - // The division by 3 here is because, vertices is a list of vertices. - // That parameter, however, wants the amount of primitives (in this case triangles), it should draw. - // Getting the amount of triangles in this case is simply a matter of dividing the total vertices by 3. - Main.instance.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count / 3); + SpecialShader.Shader.Parameters["uWorldViewProjection"].SetValue(view * projection); + SpecialShader.Apply(); } + else + BaseEffect.CurrentTechnique.Passes[0].Apply(); + + Main.instance.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, triangleIndices, 0, triangleIndices.Length / 3); + + Main.pixelShader.CurrentTechnique.Passes[0].Apply(); } } } \ No newline at end of file diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index b3545e886a..b1c56729ec 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -1,8 +1,10 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.Reflection; using System.Text; using Terraria; +using Terraria.Graphics.Shaders; namespace CalamityMod { @@ -259,6 +261,16 @@ namespace CalamityMod return Color.Lerp(currentColor, nextColor, increment * colors.Length % 1f); } + // Cached for efficiency purposes. + internal static readonly FieldInfo UImageField = typeof(MiscShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); + + /// + /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. + /// + /// The shader to bind the texture to. + /// The texture to bind. + public static void SetShaderTexture(this MiscShaderData shader, Texture2D texture) => UImageField.SetValue(shader, new Ref(texture)); + public static void EnterShaderRegion(this SpriteBatch spriteBatch) { spriteBatch.End(); diff --git a/Utilities/MathematicalUtils.cs b/Utilities/MathematicalUtils.cs index 884bbe3266..05680c8b33 100644 --- a/Utilities/MathematicalUtils.cs +++ b/Utilities/MathematicalUtils.cs @@ -20,6 +20,37 @@ namespace CalamityMod /// The second vector. public static float AngleBetween(this Vector2 v1, Vector2 v2) => (float)Math.Acos(Vector2.Dot(v1.SafeNormalize(Vector2.Zero), v2.SafeNormalize(Vector2.Zero))); + /// + /// Uses a rewritten horizontal range formula to determine the direction to fire a projectile in order for it to hit a destination. Falls back on a certain value if no such direction can exist. If no fallback is provided, a clamp is used. + /// + /// The starting position of the projectile. + /// The destination for the projectile to land at. + /// The gravity of the projectile. + /// The magnitude + /// The direction to fall back to if the calculations result in any NaNs. If nothing is specified, a clamp is performed to prevent any chance of NaNs at all. + public static Vector2 GetProjectilePhysicsFiringVelocity(Vector2 shootingPosition, Vector2 destination, float gravity, float shootSpeed, Vector2? nanFallback = null) + { + // Ensure that the gravity has the right sign for Terraria's coordinate system. + gravity = -Math.Abs(gravity); + + float horizontalRange = MathHelper.Distance(shootingPosition.X, destination.X); + float fireAngleSine = gravity * horizontalRange / (float)Math.Pow(shootSpeed, 2); + + // Clamp the sine if no fallback is provided. + if (nanFallback is null) + fireAngleSine = MathHelper.Clamp(fireAngleSine, -1f, 1f); + + float fireAngle = (float)Math.Asin(fireAngleSine) * 0.5f; + + // Get out of here if no valid firing angle exists. This can only happen if a fallback does indeed exist. + if (float.IsNaN(fireAngle)) + return nanFallback.Value * shootSpeed; + + Vector2 fireVelocity = new Vector2(0f, -shootSpeed).RotatedBy(fireAngle); + fireVelocity.X *= (destination.X - shootingPosition.X < 0).ToDirectionInt(); + return fireVelocity; + } + // REMOVE THIS IN CALAMITY 1.4, it's a 1.4 World.cs function. // Due to its temporary state, this method will not receive an XML documentation comment. public static Rectangle ClampToWorld(Rectangle tileRectangle)