diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 34d6cfbf95..b21c97043d 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -50,6 +50,7 @@ namespace CalamityMod.ILEditing IL.Terraria.Player.QuickHeal += ConditionallyReplaceManaSickness; IL.Terraria.Player.QuickMana += ConditionallyReplaceManaSickness; IL.Terraria.Player.ItemCheck_Inner += ConditionallyReplaceManaSickness; + IL.Terraria.Main.DoDraw += UseCustomDrawLayers; On.Terraria.Main.SortDrawCacheWorms += DrawFusableParticles; On.Terraria.Main.DrawInfernoRings += DrawForegroundParticles; On.Terraria.Main.SetDisplayMode += ResetRenderTargetSizes; @@ -163,6 +164,7 @@ namespace CalamityMod.ILEditing IL.Terraria.Player.QuickHeal -= ConditionallyReplaceManaSickness; IL.Terraria.Player.QuickMana -= ConditionallyReplaceManaSickness; IL.Terraria.Player.ItemCheck_Inner -= ConditionallyReplaceManaSickness; + IL.Terraria.Main.DoDraw -= UseCustomDrawLayers; On.Terraria.Main.SortDrawCacheWorms -= DrawFusableParticles; On.Terraria.Main.DrawInfernoRings -= DrawForegroundParticles; On.Terraria.Main.SetDisplayMode -= ResetRenderTargetSizes; diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index afd5c63d00..c79990adca 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -38,7 +38,8 @@ using Terraria.ModLoader; using Terraria.UI.Gamepad; using Terraria.Utilities; using Terraria.Graphics.Light; - +using System.Collections.Generic; +using Terraria.GameContent.Events; namespace CalamityMod.ILEditing { @@ -57,6 +58,16 @@ namespace CalamityMod.ILEditing private static readonly MethodInfo textureGetValueMethod = typeof(Asset).GetMethod("get_Value", BindingFlags.Public | BindingFlags.Instance); + // Restarting the sprite batch for each different projectile is analogously equivalent to creating an entire new factory just to build a single car. + // It is inefficient and leads to performance problems as many projectiles do it. + // To mitigate this problem, a special draw cache exists for the purpose of deferring drawing of projectiles to a time in which all projectiles may be + // subject to the same additive draw state before all of the spritebatch's contents are flushed. + public static List ProjectileDrawCacheAdditiveBlending + { + get; + internal set; + } = new(Main.maxProjectiles); + #region Dash Fixes and Improvements private static void MakeShieldSlamIFramesConsistent(ILContext il) { @@ -647,10 +658,37 @@ namespace CalamityMod.ILEditing } #endregion Fire Cursor Effect for the Calamity Accessory + #region Custom Draw Layers + private static void UseCustomDrawLayers(ILContext il) + { + ILCursor cursor = new(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCall("DrawWhite"))) + return; + + cursor.EmitDelegate(() => + { + Main.spriteBatch.SetBlendState(BlendState.Additive); + for (int i = 0; i < ProjectileDrawCacheAdditiveBlending.Count; i++) + { + try + { + Main.instance.DrawProj(ProjectileDrawCacheAdditiveBlending[i]); + } + catch (Exception e) + { + TimeLogger.DrawException(e); + Main.projectile[ProjectileDrawCacheAdditiveBlending[i]].active = false; + } + } + Main.spriteBatch.SetBlendState(BlendState.AlphaBlend); + ProjectileDrawCacheAdditiveBlending.Clear(); + }); + } + #endregion Custom Draw Layers + #region General Particle Rendering private static void DrawFusableParticles(On.Terraria.Main.orig_SortDrawCacheWorms orig, Main self) { - DeathAshParticle.DrawAll(); FusableParticleManager.RenderAllFusableParticles(); diff --git a/InverseKinematics/CyclicCoordinateDescentUpdateRule.cs b/InverseKinematics/CyclicCoordinateDescentUpdateRule.cs new file mode 100644 index 0000000000..4ba0b13b44 --- /dev/null +++ b/InverseKinematics/CyclicCoordinateDescentUpdateRule.cs @@ -0,0 +1,55 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; + +namespace CalamityMod.InverseKinematics +{ + public class CyclicCoordinateDescentUpdateRule : IInverseKinematicsUpdateRule + { + public float AngularOffsetAcceleration; + public float AngularDeviationLenience; + public CyclicCoordinateDescentUpdateRule(float angularOffsetAcceleration, float angularDeviationLenience) + { + AngularOffsetAcceleration = angularOffsetAcceleration; + AngularDeviationLenience = angularDeviationLenience; + } + + public void Update(LimbCollection limbs, Vector2 destination) + { + float distanceFromStart = Vector2.Distance(destination, limbs.ConnectPoint); + float distanceFromEnd = Vector2.Distance(destination, limbs.EndPoint); + float slowdownInterpolant = Utils.GetLerpValue(8f, 40f, distanceFromEnd, true); + slowdownInterpolant *= Utils.GetLerpValue(8f, 40f, distanceFromStart, true); + + Vector2 originalEndPoint = limbs.EndPoint; + for (int i = limbs.Limbs.Length - 1; i >= 0; i--) + { + // Move based on angular offsets. Movement is dampened the closer a limb is to being the first limb. + Vector2 currentToEndOffset = originalEndPoint - limbs.Limbs[i].ConnectPoint; + Vector2 currentToDestinationOffset = destination - limbs.Limbs[i].ConnectPoint; + Vector2 perpendicularDirection = currentToDestinationOffset.RotatedBy(MathHelper.PiOver2); + float angularOffset = currentToEndOffset.AngleBetween(currentToDestinationOffset) * (float)Math.Sqrt((i + 1f) / limbs.Limbs.Length); + + // Determine direction by choosing the angle which approaches the destination faster. + float leftAngularOffset = currentToEndOffset.AngleBetween(currentToDestinationOffset - perpendicularDirection); + float rightAngularOffset = currentToEndOffset.AngleBetween(currentToDestinationOffset + perpendicularDirection); + if (leftAngularOffset > rightAngularOffset) + angularOffset *= -1f; + + // Perform safety checks on the result of the underlying arccosines. + if (float.IsNaN(angularOffset)) + break; + + // Update rotation. + limbs.Limbs[i].Rotation += angularOffset * slowdownInterpolant * AngularOffsetAcceleration; + + // And limit it so that it doesn't look weird. + if (i > 0) + { + float behindRotation = (float)limbs.Limbs[i - 1].Rotation; + limbs.Limbs[i].Rotation = MathHelper.Clamp((float)limbs.Limbs[i].Rotation, behindRotation - AngularDeviationLenience, behindRotation + AngularDeviationLenience); + } + } + } + } +} diff --git a/InverseKinematics/IInverseKinematicsUpdateRule.cs b/InverseKinematics/IInverseKinematicsUpdateRule.cs new file mode 100644 index 0000000000..1e90ddefc1 --- /dev/null +++ b/InverseKinematics/IInverseKinematicsUpdateRule.cs @@ -0,0 +1,9 @@ +using Microsoft.Xna.Framework; + +namespace CalamityMod.InverseKinematics +{ + public interface IInverseKinematicsUpdateRule + { + void Update(LimbCollection limbs, Vector2 destination); + } +} diff --git a/InverseKinematics/Limb.cs b/InverseKinematics/Limb.cs new file mode 100644 index 0000000000..be5e1c43d2 --- /dev/null +++ b/InverseKinematics/Limb.cs @@ -0,0 +1,21 @@ +using Microsoft.Xna.Framework; +using Terraria; + +namespace CalamityMod.InverseKinematics +{ + public class Limb + { + // Doubles are used instead of floats as a means of providing sufficient precision to not cause erroneous results when + // doing approximations of derivative limits with small divisors. + public double Rotation; + public double Length; + public Vector2 ConnectPoint; + public Vector2 EndPoint => ConnectPoint + ((float)Rotation).ToRotationVector2() * (float)Length; + + public Limb(float rotation, float length) + { + Rotation = rotation; + Length = length; + } + } +} diff --git a/InverseKinematics/LimbCollection.cs b/InverseKinematics/LimbCollection.cs new file mode 100644 index 0000000000..071baa3122 --- /dev/null +++ b/InverseKinematics/LimbCollection.cs @@ -0,0 +1,55 @@ +using Microsoft.Xna.Framework; +using System.Linq; + +namespace CalamityMod.InverseKinematics +{ + public class LimbCollection + { + public Limb[] Limbs; + public IInverseKinematicsUpdateRule UpdateRule; + public Vector2 ConnectPoint => Limbs.First().ConnectPoint; + public Vector2 EndPoint => Limbs.Last().EndPoint; + public double TotalLength => Limbs.Sum(l => l.Length); + + public LimbCollection(IInverseKinematicsUpdateRule updateRule, int limbCount, float limbLength) + { + UpdateRule = updateRule; + + Limbs = new Limb[limbCount]; + for (int i = 0; i < limbCount; i++) + Limbs[i] = new Limb(0f, limbLength); + } + + public LimbCollection(IInverseKinematicsUpdateRule updateRule, params float[] limbLengths) + { + UpdateRule = updateRule; + + int limbCount = limbLengths.Length; + Limbs = new Limb[limbCount]; + for (int i = 0; i < limbCount; i++) + Limbs[i] = new Limb(0f, limbLengths[i]); + } + + public void UpdateConnectPoints(Vector2? connectPoint = null) + { + if (connectPoint.HasValue) + Limbs[0].ConnectPoint = connectPoint.Value; + + for (int i = 1; i < Limbs.Length; i++) + Limbs[i].ConnectPoint = Limbs[i - 1].EndPoint; + } + + public Limb this[int index] + { + get => Limbs[index]; + set => Limbs[index] = value; + } + + public void Update(Vector2 connectPoint, Vector2 destination) + { + UpdateRule.Update(this, destination); + Limbs[0].ConnectPoint = connectPoint; + UpdateConnectPoints(connectPoint); + } + } +} diff --git a/Items/Weapons/Summon/AresExoskeleton.cs b/Items/Weapons/Summon/AresExoskeleton.cs new file mode 100644 index 0000000000..c311bf1678 --- /dev/null +++ b/Items/Weapons/Summon/AresExoskeleton.cs @@ -0,0 +1,87 @@ +using Terraria.DataStructures; +using CalamityMod.Items.Materials; +using CalamityMod.Items.Weapons.Melee; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using CalamityMod.Projectiles.Summon.SmallAresArms; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class AresExoskeleton : ModItem + { + public const float MinionSlotsPerCannon = 3f; + + public const float NukeDamageFactor = 2.7f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Ares' Exoskeleton"); + Tooltip.SetDefault("Ares arms. STRONG cannons. BIG explosions. FUN"); + SacrificeTotal = 1; + } + + public override void SetDefaults() + { + Item.mana = 80; + Item.damage = 972; + Item.useStyle = ItemUseStyleID.HoldUp; + Item.noUseGraphic = true; + Item.width = Item.height = 56; + Item.useTime = Item.useAnimation = 9; + Item.noMelee = true; + Item.knockBack = 1f; + + Item.value = CalamityGlobalItem.RarityVioletBuyPrice; + Item.Calamity().customRarity = CalamityRarity.Violet; + + Item.UseSound = SoundID.Item117; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 10f; + Item.DamageType = DamageClass.Summon; + Item.Calamity().CannotBeEnchanted = true; + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + int? projectileToSummon = null; + int plasmaCannonID = ModContent.ProjectileType(); + int teslaCannonID = ModContent.ProjectileType(); + int laserCannonID = ModContent.ProjectileType(); + int gaussNukeID = ModContent.ProjectileType(); + + if (player.ownedProjectileCounts[plasmaCannonID] <= 0) + projectileToSummon = plasmaCannonID; + else if (player.ownedProjectileCounts[teslaCannonID] <= 0) + projectileToSummon = teslaCannonID; + else if (player.ownedProjectileCounts[laserCannonID] <= 0) + projectileToSummon = laserCannonID; + else if (player.ownedProjectileCounts[gaussNukeID] <= 0) + projectileToSummon = gaussNukeID; + + // Don't fire anything if no cannon type was selected. + if (!projectileToSummon.HasValue) + return false; + + int cannon = Projectile.NewProjectile(source, position, Vector2.Zero, projectileToSummon.Value, damage, knockback, player.whoAmI); + if (Main.projectile.IndexInRange(cannon)) + Main.projectile[cannon].originalDamage = Item.damage; + + return false; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(). + AddIngredient(). + AddIngredient(ItemID.WingsVortex). + AddIngredient(40). + AddIngredient(5). + AddTile(). + Register(); + } + } +} diff --git a/Items/Weapons/Summon/AresExoskeleton.png b/Items/Weapons/Summon/AresExoskeleton.png new file mode 100644 index 0000000000..5cb49c6e27 Binary files /dev/null and b/Items/Weapons/Summon/AresExoskeleton.png differ diff --git a/Projectiles/Boss/AresPlasmaFireball.cs b/Projectiles/Boss/AresPlasmaFireball.cs index c721d21a57..5c12567ab1 100644 --- a/Projectiles/Boss/AresPlasmaFireball.cs +++ b/Projectiles/Boss/AresPlasmaFireball.cs @@ -94,7 +94,6 @@ namespace CalamityMod.Projectiles.Boss Dust dust = Main.dust[num54]; dust.velocity *= 3f; - dust = Main.dust[num54]; num54 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 100, default, 0.8f); Main.dust[num54].position = Projectile.Center + Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * (float)Main.rand.NextDouble() * Projectile.width / 2f; @@ -105,8 +104,6 @@ namespace CalamityMod.Projectiles.Boss Main.dust[num54].noGravity = true; Main.dust[num54].fadeIn = 1f; Main.dust[num54].color = Color.Green * 0.5f; - - dust = Main.dust[num54]; } for (int num55 = 0; num55 < 20; num55++) { @@ -122,7 +119,6 @@ namespace CalamityMod.Projectiles.Boss Dust dust = Main.dust[num56]; dust.velocity *= 0.5f; - dust = Main.dust[num56]; } } } diff --git a/Projectiles/Summon/SmallAresArms/ArmPart1.png b/Projectiles/Summon/SmallAresArms/ArmPart1.png new file mode 100644 index 0000000000..527d34d8bf Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ArmPart1.png differ diff --git a/Projectiles/Summon/SmallAresArms/ArmPart2.png b/Projectiles/Summon/SmallAresArms/ArmPart2.png new file mode 100644 index 0000000000..bfa40d0935 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ArmPart2.png differ diff --git a/Projectiles/Summon/SmallAresArms/ArmTopShoulder.png b/Projectiles/Summon/SmallAresArms/ArmTopShoulder.png new file mode 100644 index 0000000000..7d3bdb7f69 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ArmTopShoulder.png differ diff --git a/Projectiles/Summon/SmallAresArms/CannonLaserbeam.cs b/Projectiles/Summon/SmallAresArms/CannonLaserbeam.cs new file mode 100644 index 0000000000..4543793648 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/CannonLaserbeam.cs @@ -0,0 +1,151 @@ +using CalamityMod.Projectiles.BaseProjectiles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using System; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class CannonLaserbeam : BaseLaserbeamProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public int OwnerIndex + { + get => Projectile.GetByUUID(Projectile.owner, Projectile.ai[1]); + set => Projectile.ai[1] = value; + } + + public const int LifetimeConst = 75; + public override float MaxScale => 0.5f + (float)Math.Cos(Main.GlobalTimeWrappedHourly * 10f) * 0.07f; + public override float MaxLaserLength => 1560f; + public override float Lifetime => LifetimeConst; + public override Color LaserOverlayColor => Color.White; + public override Color LightCastColor => LaserOverlayColor; + public override Texture2D LaserBeginTexture => ModContent.Request("CalamityMod/Projectiles/Boss/ThanatosBeamStart", AssetRequestMode.ImmediateLoad).Value; + public override Texture2D LaserMiddleTexture => ModContent.Request("CalamityMod/ExtraTextures/Lasers/ThanatosBeamMiddle", AssetRequestMode.ImmediateLoad).Value; + public override Texture2D LaserEndTexture => ModContent.Request("CalamityMod/ExtraTextures/Lasers/ThanatosBeamEnd", AssetRequestMode.ImmediateLoad).Value; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Exothermal Deathray"); + Main.projFrames[Projectile.type] = 5; + ProjectileID.Sets.MinionShot[Projectile.type] = true; + } + public override void SetDefaults() + { + Projectile.width = Projectile.height = 38; + Projectile.friendly = true; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.penetrate = -1; + Projectile.alpha = 255; + Projectile.localNPCHitCooldown = 14; + Projectile.scale = 0.5f; + Projectile.usesLocalNPCImmunity = true; + } + + public override float DetermineLaserLength() + { + float[] samples = new float[4]; + Collision.LaserScan(Projectile.Center, Projectile.velocity, Projectile.width * Projectile.scale, MaxLaserLength, samples); + return samples.Average(); + } + + public override void UpdateLaserMotion() + { + if (OwnerIndex == -1) + { + Projectile.Kill(); + return; + } + Projectile.rotation = Projectile.velocity.ToRotation() - MathHelper.PiOver2; + } + + public override void AttachToSomething() + { + if (OwnerIndex == -1 || !Main.projectile[OwnerIndex].active) + { + Projectile.Kill(); + return; + } + + float attachmentOffset = Main.projectile[OwnerIndex].width * Main.projectile[OwnerIndex].scale * 0.75f; + Projectile.Center = Main.projectile[OwnerIndex].Center + Main.projectile[OwnerIndex].rotation.ToRotationVector2() * attachmentOffset; + Projectile.rotation = Main.projectile[OwnerIndex].rotation; + Projectile.velocity = Projectile.rotation.ToRotationVector2(); + + // Update frames. + Projectile.frame = Projectile.frameCounter++ / 5 % Main.projFrames[Type]; + } + + public override bool ShouldUpdatePosition() => false; + + public override bool PreDraw(ref Color lightColor) + { + // This should never happen, but just in case. + if (Projectile.velocity == Vector2.Zero || Projectile.localAI[0] < 2f) + return false; + + Color beamColor = LaserOverlayColor; + Rectangle startFrameArea = LaserBeginTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame); + Rectangle middleFrameArea = LaserMiddleTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame); + Rectangle endFrameArea = LaserEndTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame); + + // Start texture drawing. + Main.EntitySpriteDraw(LaserBeginTexture, + Projectile.Center - Main.screenPosition, + startFrameArea, + beamColor, + Projectile.rotation, + startFrameArea.Size() * new Vector2(0.5f, 1f), + Projectile.scale, + SpriteEffects.None, + 0); + + // Prepare things for body drawing. + float laserBodyLength = LaserLength + middleFrameArea.Height; + Vector2 centerOnLaser = Projectile.Center; + + // Body drawing. + if (laserBodyLength > 0f) + { + float laserOffset = middleFrameArea.Height * Projectile.scale; + float incrementalBodyLength = 0f; + while (incrementalBodyLength + 1f < laserBodyLength) + { + Main.EntitySpriteDraw(LaserMiddleTexture, + centerOnLaser - Main.screenPosition, + middleFrameArea, + beamColor, + Projectile.rotation, + middleFrameArea.Size() * 0.5f, + Projectile.scale, + SpriteEffects.None, + 0); + incrementalBodyLength += laserOffset; + centerOnLaser += Projectile.velocity * laserOffset; + middleFrameArea.Y += LaserMiddleTexture.Height / Main.projFrames[Projectile.type]; + if (middleFrameArea.Y + middleFrameArea.Height > LaserMiddleTexture.Height) + middleFrameArea.Y = 0; + } + } + + Vector2 laserEndCenter = centerOnLaser - Main.screenPosition; + Main.EntitySpriteDraw(LaserEndTexture, + laserEndCenter, + endFrameArea, + beamColor, + Projectile.rotation, + endFrameArea.Size() * 0.5f, + Projectile.scale, + SpriteEffects.None, + 0); + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonCannon.cs b/Projectiles/Summon/SmallAresArms/ExoskeletonCannon.cs new file mode 100644 index 0000000000..28ef450832 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/ExoskeletonCannon.cs @@ -0,0 +1,154 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using CalamityMod.Items.Weapons.Summon; +using CalamityMod.InverseKinematics; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public abstract class ExoskeletonCannon : ModProjectile + { + public bool TargetingSomething => Projectile.ai[1] == 1f; + + public Player Owner => Main.player[Projectile.owner]; + + public LimbCollection Limbs = new(new CyclicCoordinateDescentUpdateRule(0.27f, MathHelper.PiOver2), 70f, 82f); + + public virtual bool UsesSuperpredictiveness => false; + + public virtual Vector2 DrawOffset => new((OwnerRestingOffset.X > 0f).ToDirectionInt() * 6f, -6f); + + public virtual Vector2 ConnectOffset => Vector2.Zero; + + public abstract int ShootRate { get; } + + public abstract float ShootSpeed { get; } + + public abstract Vector2 OwnerRestingOffset { get; } + + public abstract void ClampFirstLimbRotation(ref double limbRotation); + + public abstract void ShootAtTarget(NPC target, Vector2 shootDirection); + + public override void SetDefaults() + { + Projectile.width = 94; + Projectile.height = 40; + Projectile.friendly = true; + Projectile.tileCollide = false; + Projectile.netImportant = true; + Projectile.minion = true; + Projectile.minionSlots = AresExoskeleton.MinionSlotsPerCannon; + Projectile.penetrate = -1; + Projectile.timeLeft = 90000; + Projectile.scale = 1f; + Projectile.DamageType = DamageClass.Summon; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(Projectile.rotation); + writer.Write(Limbs?.Limbs?.Length ?? 0); + for (int i = 0; i < Limbs.Limbs.Length; i++) + writer.Write(Limbs[i].Rotation); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + Projectile.rotation = reader.ReadSingle(); + + int limbCount = Limbs.Limbs.Length; + for (int i = 0; i < limbCount; i++) + { + Limbs[i].Rotation = reader.ReadDouble(); + if (i >= 1) + Limbs[i].ConnectPoint = Limbs[i - 1].EndPoint; + } + } + + public override void AI() + { + // Update limbs. + if (Main.myPlayer == Projectile.owner) + { + Vector2 connectPosition = Main.LocalPlayer.Center + ConnectOffset; + connectPosition.X += (OwnerRestingOffset.X > 0f).ToDirectionInt() * Projectile.scale * 20f; + Vector2 endPosition = Owner.Center + OwnerRestingOffset; + endPosition += (Main.MouseWorld - endPosition) * 0.075f; + + ClampFirstLimbRotation(ref Limbs[0].Rotation); + Limbs.Update(connectPosition, endPosition); + + Projectile.netSpam = 0; + Projectile.netUpdate = true; + } + + Projectile.ai[1] = 0f; + Projectile.velocity = Vector2.Zero; + Projectile.Center = Limbs.EndPoint; + + // Look at the mouse if not targetting anything. + // If something is being targeted, look at them instead. + float idealRotation = Main.myPlayer != Projectile.owner ? Projectile.rotation : Projectile.AngleTo(Main.MouseWorld); + NPC potentialTarget = Projectile.Center.ClosestNPCAt(960f); + if (potentialTarget != null) + { + Projectile.ai[1] = 1f; + + idealRotation = Projectile.AngleTo(potentialTarget.Center); + if (UsesSuperpredictiveness) + idealRotation = CalamityUtils.CalculatePredictiveAimToTarget(Projectile.Center, potentialTarget, ShootSpeed).ToRotation(); + + if (Projectile.timeLeft % ShootRate == ShootRate - 1) + ShootAtTarget(potentialTarget, idealRotation.ToRotationVector2()); + } + + Projectile.rotation = Projectile.rotation.AngleLerp(idealRotation, 0.15f); + Projectile.spriteDirection = (Math.Cos(Projectile.rotation) > 0f).ToDirectionInt(); + } + + public void DrawLimbs() + { + for (int i = 0; i < Limbs.Limbs.Length; i++) + { + float scale = Projectile.scale; + float rotation = (float)Limbs[i].Rotation; + Vector2 segmentOriginFactor = new(0f, 0.5f); + SpriteEffects segmentDirection = SpriteEffects.FlipHorizontally; + Texture2D segmentTexture = ModContent.Request("CalamityMod/NPCs/ExoMechs/Ares/AresArmSegment").Value; + Rectangle segmentFrame = segmentTexture.Frame(1, 24, 0, (int)(Main.GlobalTimeWrappedHourly * 13f + i) % 24); + if (i == 0) + segmentTexture = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ArmPart1").Value; + if (i == 1) + segmentTexture = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ArmPart2").Value; + if (i <= 1) + { + segmentFrame = segmentTexture.Frame(); + segmentDirection = OwnerRestingOffset.X < 0f ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + if (OwnerRestingOffset.X < 0f) + { + segmentOriginFactor.X = 1f; + rotation += MathHelper.Pi; + } + } + else + scale *= 0.67f; + + Color segmentColor = Lighting.GetColor(Limbs[i].ConnectPoint.ToTileCoordinates()); + Vector2 segmentDrawPosition = Limbs[i].ConnectPoint - Main.screenPosition; + Main.spriteBatch.DrawLineBetter(Limbs[i].ConnectPoint, Limbs[i].EndPoint, Color.Cyan, 3f); + Main.EntitySpriteDraw(segmentTexture, segmentDrawPosition, segmentFrame, Projectile.GetAlpha(segmentColor), rotation, segmentFrame.Size() * segmentOriginFactor, scale, segmentDirection, 0); + } + + // Draw the shoulders on top of everything else. + Vector2 shoulderPosition = Limbs.ConnectPoint + DrawOffset * Projectile.scale; + Color shoulderColor = Lighting.GetColor(Limbs.ConnectPoint.ToTileCoordinates()); + Texture2D shoulderTexture = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ArmTopShoulder").Value; + SpriteEffects shoulderDirection = OwnerRestingOffset.X < 0f ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + Main.EntitySpriteDraw(shoulderTexture, shoulderPosition - Main.screenPosition, null, Projectile.GetAlpha(shoulderColor), 0f, shoulderTexture.Size() * 0.5f, Projectile.scale, shoulderDirection, 0); + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCannon.cs b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCannon.cs new file mode 100644 index 0000000000..30da9c4817 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCannon.cs @@ -0,0 +1,143 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.Audio; +using Microsoft.Xna.Framework.Graphics; +using CalamityMod.Sounds; +using CalamityMod.Items.Weapons.Summon; +using System; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class ExoskeletonGaussNukeCannon : ExoskeletonCannon + { + public int NukeRebuildTime => ShootRate - 45; + + public ref float RebuildTimer => ref Projectile.localAI[0]; + + public override Vector2 ConnectOffset => new((OwnerRestingOffset.X > 0f).ToDirectionInt() * 14f, -30f); + + public override int ShootRate => 210; + + public override float ShootSpeed => 16f; + + public override Vector2 OwnerRestingOffset => new(-190f, -102f); + + public override void ClampFirstLimbRotation(ref double limbRotation) + { + limbRotation = MathHelper.Pi - 0.2f; + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gauss Nuke"); + Main.projFrames[Type] = 2; + } + + public override void ShootAtTarget(NPC target, Vector2 shootDirection) + { + // Play the large gun fire sound. + SoundEngine.PlaySound(CommonCalamitySounds.LargeWeaponFireSound with { Volume = 0.4f }, Projectile.Center); + + // Start the rebuild timer. + RebuildTimer = 1f; + + // Shoot the fireball. This only happens for the owner client. + if (Main.myPlayer != Projectile.owner) + return; + + int nukeID = ModContent.ProjectileType(); + Vector2 laserVelocity = shootDirection * ShootSpeed; + int laser = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, laserVelocity, nukeID, (int)(Projectile.damage * AresExoskeleton.NukeDamageFactor), 0f, Projectile.owner); + if (Main.projectile.IndexInRange(laser)) + Main.projectile[laser].originalDamage = (int)(Projectile.originalDamage * AresExoskeleton.NukeDamageFactor); + } + + public override void PostAI() + { + Projectile.frame = 0; + if (RebuildTimer >= 1f) + { + RebuildTimer++; + Projectile.frame = 1; + } + + if (RebuildTimer >= NukeRebuildTime) + { + RebuildTimer = 0f; + Projectile.frame = 0; + } + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + + // The two stabilizers have two different shades of lighting, thus necessitating two different textures. + Texture2D stabilizer = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizer").Value; + Texture2D stabilizer2 = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizerBottom").Value; + Texture2D crystal = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCrystal").Value; + Texture2D core = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCore").Value; + Rectangle frame = texture.Frame(1, 2, 0, Projectile.frame); + + float stabilizerRotationInterpolant = (float)Math.Pow(Utils.GetLerpValue(NukeRebuildTime * 0.75f, NukeRebuildTime * 0.92f, RebuildTimer, true), 1.7); + Vector2 origin = frame.Size() * 0.5f; + Vector2 crystalOrigin = crystal.Size() * new Vector2(Projectile.spriteDirection == 1 ? 1f : 0f, 0.5f); + Vector2 stabilizerOrigin = stabilizer.Size() * new Vector2(0.5f, 1f); + Vector2 coreOrigin = core.Size() * new Vector2(Projectile.spriteDirection == 1 ? 0f : 1f, 0.5f); + Vector2 perpendicularStabilizerOffset = (Projectile.rotation + MathHelper.PiOver2).ToRotationVector2() * Projectile.scale * MathHelper.Lerp(18f, 10f, stabilizerRotationInterpolant); + + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + float rotation = Projectile.rotation; + if (Projectile.spriteDirection == -1) + rotation += MathHelper.Pi; + + DrawLimbs(); + + // Draw the nuke pieces when rebuilding. This is done before the cannon itself is drawn, to make it look like they're attached to it. + if (RebuildTimer >= 1f) + { + float componentDirection = rotation + MathHelper.Pi; + float stabilizerDirection = componentDirection; + if (Projectile.spriteDirection == -1) + stabilizerDirection += MathHelper.Pi; + + Vector2 aimDirection = Projectile.rotation.ToRotationVector2(); + + // Draw the crystal. + float crystalOffsetInterpolant = Utils.GetLerpValue(0f, NukeRebuildTime * 0.5f, RebuildTimer, true); + Vector2 crystalOffset = aimDirection * crystalOffsetInterpolant * Projectile.scale * (crystal.Width - 2f); + Main.EntitySpriteDraw(crystal, drawPosition + crystalOffset, null, Projectile.GetAlpha(lightColor), rotation, crystalOrigin, Projectile.scale, direction, 0); + + // Draw the stabilizers. + float stabilizerOffsetInterpolant = Utils.GetLerpValue(NukeRebuildTime * 0.5f, NukeRebuildTime * 0.75f, RebuildTimer, true); + float stabilizerOffsetMagnitude = MathHelper.Lerp(-stabilizer.Width * 0.3f, stabilizer.Width * 0.4f - 6f, stabilizerOffsetInterpolant) * Projectile.scale; + float leftStabilizerRotation = stabilizerDirection + MathHelper.Pi - (1f - stabilizerRotationInterpolant) * 0.42f; + float rightStabilizerRotation = stabilizerDirection + (1f - stabilizerRotationInterpolant) * 0.42f; + Vector2 stabilizerOffset = aimDirection * stabilizerOffsetMagnitude; + Color stabilizerColor = Projectile.GetAlpha(lightColor) * (float)Math.Pow(stabilizerOffsetInterpolant, 1.61); + Vector2 leftStabilizerPosition = drawPosition + stabilizerOffset - perpendicularStabilizerOffset * 0.8f; + Vector2 rightStabilizerPosition = drawPosition + stabilizerOffset + perpendicularStabilizerOffset; + SpriteEffects leftStabilizerDirection = direction; + SpriteEffects rightStabilizerDirection = direction ^ SpriteEffects.FlipHorizontally; + if (Projectile.spriteDirection == -1) + { + leftStabilizerDirection ^= SpriteEffects.FlipHorizontally; + rightStabilizerDirection ^= SpriteEffects.FlipHorizontally; + Utils.Swap(ref stabilizer, ref stabilizer2); + } + Main.EntitySpriteDraw(stabilizer, leftStabilizerPosition, null, stabilizerColor, leftStabilizerRotation, stabilizerOrigin, Projectile.scale, leftStabilizerDirection, 0); + Main.EntitySpriteDraw(stabilizer2, rightStabilizerPosition, null, stabilizerColor, rightStabilizerRotation, stabilizerOrigin, Projectile.scale, rightStabilizerDirection, 0); + + // Draw the core. + Vector2 coreDrawPosition = drawPosition + aimDirection * Projectile.scale * 4f; + Main.EntitySpriteDraw(core, coreDrawPosition, null, Projectile.GetAlpha(lightColor) * stabilizerRotationInterpolant, rotation, coreOrigin, Projectile.scale, direction, 0); + } + + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), rotation, origin, Projectile.scale, direction, 0); + + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCannon.png b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCannon.png new file mode 100644 index 0000000000..0487cfea74 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCannon.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCore.png b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCore.png new file mode 100644 index 0000000000..d2c503c190 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCore.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCrystal.png b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCrystal.png new file mode 100644 index 0000000000..4b71265a0b Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCrystal.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizer.png b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizer.png new file mode 100644 index 0000000000..29b08d3e2d Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizer.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizerBottom.png b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizerBottom.png new file mode 100644 index 0000000000..72b1fbe1c1 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizerBottom.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannon.cs b/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannon.cs new file mode 100644 index 0000000000..c06cb47898 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannon.cs @@ -0,0 +1,109 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.Audio; +using Microsoft.Xna.Framework.Graphics; +using CalamityMod.Sounds; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class ExoskeletonLaserCannon : ExoskeletonCannon + { + public ref float ShootCounter => ref Projectile.ai[0]; + + // This is how many small, regular lasers will happen before the laser will charge up and prepare a laserbeam. + public const int NormalLasersBeforeBeam = 6; + + public override Vector2 ConnectOffset => new((OwnerRestingOffset.X > 0f).ToDirectionInt() * 14f, -30f); + + public override int ShootRate => ShootCounter % NormalLasersBeforeBeam == 0f ? 150 : 36; + + public override float ShootSpeed => 13.5f; + + public override Vector2 OwnerRestingOffset => new(190f, -102f); + + public override void ClampFirstLimbRotation(ref double limbRotation) + { + limbRotation = -0.2f; + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Laser Cannon"); + Main.projFrames[Type] = 6; + } + + public override void ShootAtTarget(NPC target, Vector2 shootDirection) + { + // Play the laser cannon fire sound. + SoundEngine.PlaySound(CommonCalamitySounds.LaserCannonSound with { Volume = 0.4f }, Projectile.Center); + + // Create a burst of dust. + for (int i = 0; i < 24; i++) + { + Dust laserEnergy = Dust.NewDustPerfect(Projectile.Center + shootDirection * Projectile.width * Projectile.scale * 0.45f, 182); + laserEnergy.velocity = (MathHelper.TwoPi * i / 24f).ToRotationVector2() * 4f; + laserEnergy.scale = 1.1f; + laserEnergy.fadeIn = 0.4f; + laserEnergy.noGravity = true; + } + + // Shoot the laser. This only happens for the owner client. + if (Main.myPlayer != Projectile.owner) + return; + + int laserID = ModContent.ProjectileType(); + bool fireLaser = ShootCounter % NormalLasersBeforeBeam == NormalLasersBeforeBeam - 1f; + if (fireLaser) + laserID = ModContent.ProjectileType(); + + Vector2 laserVelocity = shootDirection * ShootSpeed; + int laser = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, laserVelocity, laserID, Projectile.damage, 0f, Projectile.owner); + if (Main.projectile.IndexInRange(laser)) + { + Main.projectile[laser].originalDamage = Projectile.originalDamage; + if (fireLaser) + Main.projectile[laser].ai[1] = Projectile.whoAmI; + } + + // Increment the shoot counter. This decides if the cannon fires a simple laser or a beam. + ShootCounter++; + Projectile.netUpdate = true; + } + + // Create some charge dust before firing a laserbeam. + public override void PostAI() + { + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Type]; + if (ShootCounter % NormalLasersBeforeBeam != NormalLasersBeforeBeam - 1f || !TargetingSomething) + return; + + Vector2 aimDirection = Projectile.rotation.ToRotationVector2(); + Dust laserEnergy = Dust.NewDustPerfect(Projectile.Center + aimDirection * Projectile.width * Projectile.scale * 0.51f, 182); + laserEnergy.velocity = aimDirection.RotatedByRandom(0.48f) * Main.rand.NextFloat(3f); + laserEnergy.scale = 1.1f; + laserEnergy.fadeIn = 0.4f; + laserEnergy.noGravity = true; + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + Texture2D glowmask = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannonGlowmask").Value; + Rectangle frame = texture.Frame(2, Main.projFrames[Type], TargetingSomething.ToInt(), Projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + float rotation = Projectile.rotation; + if (Projectile.spriteDirection == -1) + rotation += MathHelper.Pi; + + DrawLimbs(); + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), rotation, origin, Projectile.scale, direction, 0); + Main.EntitySpriteDraw(glowmask, drawPosition, frame, Projectile.GetAlpha(Color.White), rotation, origin, Projectile.scale, direction, 0); + + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannon.png b/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannon.png new file mode 100644 index 0000000000..bb40ea3449 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannon.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannonGlowmask.png b/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannonGlowmask.png new file mode 100644 index 0000000000..a3afe8e3fd Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannonGlowmask.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannon.cs b/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannon.cs new file mode 100644 index 0000000000..3c206d8433 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannon.cs @@ -0,0 +1,108 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.Audio; +using Microsoft.Xna.Framework.Graphics; +using CalamityMod.Items.Weapons.DraedonsArsenal; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class ExoskeletonPlasmaCannon : ExoskeletonCannon + { + public override int ShootRate => 32; + + public override float ShootSpeed => 13.5f; + + public override Vector2 OwnerRestingOffset => new(300f, 96f); + + public override void ClampFirstLimbRotation(ref double limbRotation) + { + limbRotation = 0.23f; + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Plasma Cannon"); + Main.projFrames[Type] = 6; + } + + public override void PostAI() + { + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Type]; + } + + public override void ShootAtTarget(NPC target, Vector2 shootDirection) + { + // Play the plasma caster fire sound. + SoundEngine.PlaySound(PlasmaCaster.FireSound with { Volume = 0.4f }, Projectile.Center); + + // Create a burst of dust. + for (int i = 0; i < 40; i++) + { + float dustSpeed = Main.rand.NextFloat(1.8f, 3f); + Vector2 dustVel = shootDirection * dustSpeed; + dustVel = dustVel.RotatedBy(-0.35f); + dustVel = dustVel.RotatedByRandom(2.0f * 0.35f); + int randomDustType = Main.rand.NextBool(2) ? 107 : 110; + + Dust plasma = Dust.NewDustDirect(Projectile.TopLeft, Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 200, default, 1.7f); + plasma.position = Projectile.Center + Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * (float)Main.rand.NextDouble() * Projectile.width / 2f; + plasma.position += shootDirection * 60f; + plasma.noGravity = true; + plasma.velocity *= Projectile.scale * 3f; + + plasma = Dust.NewDustDirect(Projectile.TopLeft, Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 100, default, 0.8f); + plasma.position = Projectile.Center + Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * (float)Main.rand.NextDouble() * Projectile.width / 2f; + plasma.position += shootDirection * 60f; + plasma.velocity *= Projectile.scale * 2f; + + plasma.noGravity = true; + plasma.fadeIn = 1f; + plasma.color = Color.Green * 0.5f; + } + for (int i = 0; i < 20; i++) + { + float dustSpeed = Main.rand.NextFloat(1.8f, 3f); + Vector2 dustVel = shootDirection * dustSpeed; + dustVel = dustVel.RotatedBy(-0.35f); + dustVel = dustVel.RotatedByRandom(2.0f * 0.35f); + int randomDustType = Main.rand.NextBool(2) ? 107 : 110; + + Dust plasma = Dust.NewDustDirect(Projectile.TopLeft, Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 0, default, 2f); + plasma.position = Projectile.Center + Vector2.UnitX.RotatedByRandom(MathHelper.Pi).RotatedBy(shootDirection.ToRotation()) * Projectile.width / 3f; + plasma.position += shootDirection * 60f; + plasma.noGravity = true; + plasma.velocity *= Projectile.scale * 0.5f; + } + + // Shoot the fireball. This only happens for the owner client. + if (Main.myPlayer != Projectile.owner) + return; + + Vector2 fireballVelocity = shootDirection * ShootSpeed; + int fireball = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, fireballVelocity, ModContent.ProjectileType(), Projectile.damage, 0f, Projectile.owner); + if (Main.projectile.IndexInRange(fireball)) + Main.projectile[fireball].originalDamage = Projectile.originalDamage; + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + Texture2D glowmask = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannonGlowmask").Value; + Rectangle frame = texture.Frame(2, Main.projFrames[Type], TargetingSomething.ToInt(), Projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + float rotation = Projectile.rotation; + if (Projectile.spriteDirection == -1) + rotation += MathHelper.Pi; + + DrawLimbs(); + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), rotation, origin, Projectile.scale, direction, 0); + Main.EntitySpriteDraw(glowmask, drawPosition, frame, Projectile.GetAlpha(Color.White), rotation, origin, Projectile.scale, direction, 0); + + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannon.png b/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannon.png new file mode 100644 index 0000000000..a603d3faf8 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannon.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannonGlowmask.png b/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannonGlowmask.png new file mode 100644 index 0000000000..60e386b179 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannonGlowmask.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannon.cs b/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannon.cs new file mode 100644 index 0000000000..1abf8a6db5 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannon.cs @@ -0,0 +1,76 @@ +using CalamityMod.Sounds; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.Audio; +using Microsoft.Xna.Framework.Graphics; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class ExoskeletonTeslaCannon : ExoskeletonCannon + { + public ref float TeslaOrbIndex => ref Projectile.ai[0]; + + public override int ShootRate => 30; + + public override float ShootSpeed => 12f; + + public override bool UsesSuperpredictiveness => true; + + public override Vector2 OwnerRestingOffset => new(-300f, 96f); + + public override void ClampFirstLimbRotation(ref double limbRotation) + { + limbRotation = MathHelper.Pi - 0.23f; + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Tesla Cannon"); + Main.projFrames[Type] = 6; + } + + public override void PostAI() + { + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Type]; + } + + public override void ShootAtTarget(NPC target, Vector2 shootDirection) + { + // Play the plasma bolt fire sound. + SoundEngine.PlaySound(CommonCalamitySounds.PlasmaBoltSound with { Volume = 0.4f }, Projectile.Center); + + // Shoot the tesla orb. This only happens for the owner client. + if (Main.myPlayer != Projectile.owner) + return; + + Vector2 teslaOrbVelocity = shootDirection * ShootSpeed; + int teslaOrb = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, teslaOrbVelocity, ModContent.ProjectileType(), Projectile.damage, 0f, Projectile.owner); + if (Main.projectile.IndexInRange(teslaOrb)) + { + Main.projectile[teslaOrb].originalDamage = Projectile.originalDamage; + Main.projectile[teslaOrb].ai[0] = TeslaOrbIndex++ % 6; + } + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + Texture2D glowmask = ModContent.Request("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannonGlowmask").Value; + Rectangle frame = texture.Frame(2, Main.projFrames[Type], TargetingSomething.ToInt(), Projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + float rotation = Projectile.rotation; + if (Projectile.spriteDirection == -1) + rotation += MathHelper.Pi; + + DrawLimbs(); + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), rotation, origin, Projectile.scale, direction, 0); + Main.EntitySpriteDraw(glowmask, drawPosition, frame, Projectile.GetAlpha(Color.White), rotation, origin, Projectile.scale, direction, 0); + + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannon.png b/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannon.png new file mode 100644 index 0000000000..21761e7ad1 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannon.png differ diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannonGlowmask.png b/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannonGlowmask.png new file mode 100644 index 0000000000..bf6a231509 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannonGlowmask.png differ diff --git a/Projectiles/Summon/SmallAresArms/MinionGaussBoom.cs b/Projectiles/Summon/SmallAresArms/MinionGaussBoom.cs new file mode 100644 index 0000000000..a5323cc3ee --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/MinionGaussBoom.cs @@ -0,0 +1,34 @@ +using CalamityMod.Projectiles.BaseProjectiles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class MinionGaussBoom : BaseMassiveExplosionProjectile + { + public override int Lifetime => 60; + + // No screenshake is used for the sake of gameplay convenience. + public override bool UsesScreenshake => false; + public override float GetScreenshakePower(float pulseCompletionRatio) => 0f; + public override Color GetCurrentExplosionColor(float pulseCompletionRatio) => Color.Lerp(Color.Yellow * 1.6f, Color.White, MathHelper.Clamp(pulseCompletionRatio * 2.2f, 0f, 1f)); + public override void SetStaticDefaults() => DisplayName.SetDefault("Gauss Hyperexplosion"); + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 2; + Projectile.friendly = true; + Projectile.tileCollide = false; + Projectile.penetrate = -1; + Projectile.timeLeft = Lifetime; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.DamageType = DamageClass.Summon; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 12; + } + + public override void PostAI() => Lighting.AddLight(Projectile.Center, 0.2f, 0.1f, 0f); + } +} diff --git a/Projectiles/Summon/SmallAresArms/MinionGaussNuke.cs b/Projectiles/Summon/SmallAresArms/MinionGaussNuke.cs new file mode 100644 index 0000000000..34b34d81b0 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/MinionGaussNuke.cs @@ -0,0 +1,62 @@ +using CalamityMod.ILEditing; +using CalamityMod.Items.Weapons.DraedonsArsenal; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.Audio; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class MinionGaussNuke : ModProjectile + { + public override void SetStaticDefaults() => DisplayName.SetDefault("Gauss Nuke"); + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 76; + Projectile.penetrate = -1; + Projectile.tileCollide = true; + Projectile.timeLeft = 180; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.DamageType = DamageClass.Summon; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 12; + } + + public override void AI() + { + // Handle rotation. + Projectile.rotation = Projectile.velocity.ToRotation(); + + // Home towards targets. + NPC potentialTarget = Projectile.Center.ClosestNPCAt(960f, false); + if (potentialTarget != null) + Projectile.velocity = Projectile.SuperhomeTowardsTarget(potentialTarget, 23f, 10f); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + Projectile.Kill(); + } + + public override void Kill(int timeLeft) + { + SoundEngine.PlaySound(TeslaCannon.FireSound, Projectile.Center); + if (Main.myPlayer == Projectile.owner) + { + int boom = Projectile.NewProjectile(Projectile.GetSource_Death(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + if (Main.projectile.IndexInRange(boom)) + { + Main.projectile[boom].ai[1] = 720f; + Main.projectile[boom].originalDamage = Projectile.originalDamage; + } + } + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/MinionGaussNuke.png b/Projectiles/Summon/SmallAresArms/MinionGaussNuke.png new file mode 100644 index 0000000000..a4b11364a1 Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/MinionGaussNuke.png differ diff --git a/Projectiles/Summon/SmallAresArms/MinionLaserBurst.cs b/Projectiles/Summon/SmallAresArms/MinionLaserBurst.cs new file mode 100644 index 0000000000..b8ff8c863b --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/MinionLaserBurst.cs @@ -0,0 +1,61 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.ID; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class MinionLaserBurst : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Boss/ThanatosLaser"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Exothermal Laser"); + Main.projFrames[Type] = 4; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 32; + Projectile.height = 32; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.tileCollide = true; + Projectile.netImportant = true; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.timeLeft = 420; + Projectile.Opacity = 0f; + Projectile.DamageType = DamageClass.Summon; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 12; + } + + public override void AI() + { + // Accelerate. + if (Projectile.velocity.Length() < 27f) + Projectile.velocity *= 1.024f; + + // Fade in. + Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity + 0.12f, 0f, 1f); + + // Handle frames and rotation. + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type]; + Projectile.rotation = Projectile.velocity.ToRotation(); + } + + public override bool PreDraw(ref Color lightColor) + { + lightColor.R = (byte)(255 * Projectile.Opacity); + lightColor.G = (byte)(255 * Projectile.Opacity); + lightColor.B = (byte)(255 * Projectile.Opacity); + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/MinionPlasmaBlast.cs b/Projectiles/Summon/SmallAresArms/MinionPlasmaBlast.cs new file mode 100644 index 0000000000..e7ef090a06 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/MinionPlasmaBlast.cs @@ -0,0 +1,83 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.Audio; +using Terraria.ID; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class MinionPlasmaBlast : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Boss/AresPlasmaFireball"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Volatile Plasma Blast"); + Main.projFrames[Type] = 6; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 36; + Projectile.height = 36; + Projectile.friendly = true; + Projectile.penetrate = 1; + Projectile.tileCollide = true; + Projectile.netImportant = true; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.timeLeft = 420; + Projectile.Opacity = 0f; + Projectile.DamageType = DamageClass.Summon; + } + + public override void AI() + { + // Accelerate. + if (Projectile.velocity.Length() < 23f) + Projectile.velocity *= 1.0175f; + + // Fade in. + Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity + 0.06667f, 0f, 1f); + + // Handle frames and rotation. + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type]; + Projectile.rotation = Projectile.velocity.ToRotation() - MathHelper.PiOver2; + + // Home towards targets. + NPC potentialTarget = Projectile.Center.ClosestNPCAt(900f, false); + if (potentialTarget != null) + Projectile.velocity = Projectile.SuperhomeTowardsTarget(potentialTarget, 23f, 10f); + } + + public override void Kill(int timeLeft) + { + SoundEngine.PlaySound(SoundID.Item93, Projectile.Center); + + // Release a spread of plasma gas. + if (Main.netMode != NetmodeID.MultiplayerClient && Projectile.ai[1] != -1f) + { + int type = ModContent.ProjectileType(); + for (int i = 0; i < 15; i++) + { + Vector2 plasmaVelocity = Main.rand.NextVector2Circular(5f, 5f); + int gas = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, plasmaVelocity, type, Projectile.damage, 0f, Main.myPlayer); + if (Main.projectile.IndexInRange(gas)) + Main.projectile[gas].originalDamage = Projectile.originalDamage; + } + } + } + + public override bool PreDraw(ref Color lightColor) + { + lightColor.R = (byte)(255 * Projectile.Opacity); + lightColor.G = (byte)(255 * Projectile.Opacity); + lightColor.B = (byte)(255 * Projectile.Opacity); + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/MinionPlasmaGas.cs b/Projectiles/Summon/SmallAresArms/MinionPlasmaGas.cs new file mode 100644 index 0000000000..efb16cfbb3 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/MinionPlasmaGas.cs @@ -0,0 +1,74 @@ +using CalamityMod.ILEditing; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using Terraria; +using Terraria.GameContent; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class MinionPlasmaGas : ModProjectile + { + public ref float LightPower => ref Projectile.ai[0]; + + public ref float Time => ref Projectile.ai[1]; + + public override void SetStaticDefaults() => DisplayName.SetDefault("Superheated Plasma Cloud"); + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 50; + Projectile.penetrate = -1; + Projectile.tileCollide = false; + Projectile.timeLeft = 150; + Projectile.scale = 1.5f; + Projectile.hide = true; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.DamageType = DamageClass.Summon; + Projectile.usesIDStaticNPCImmunity = true; + Projectile.idStaticNPCHitCooldown = 12; + } + + public override void AI() + { + // Decide scale and initial rotation on the first frame this projectile exists. + if (Projectile.localAI[0] == 0f) + { + Projectile.scale = Main.rand.NextFloat(1f, 1.7f); + Projectile.rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Projectile.localAI[0] = 1f; + } + + // Calculate light power. This checks below the position of the fog to check if this fog is underground. + // Without this, it may render over the fullblack that the game renders for obscured tiles. + float lightPowerBelow = Lighting.GetColor((int)Projectile.Center.X / 16, (int)Projectile.Center.Y / 16 + 6).ToVector3().Length() / (float)Math.Sqrt(3D); + LightPower = MathHelper.Lerp(LightPower, lightPowerBelow, 0.15f); + Projectile.Opacity = Utils.GetLerpValue(0f, 15f, Time, true) * Utils.GetLerpValue(0f, 60f, Projectile.timeLeft, true); + Projectile.rotation += Projectile.velocity.X * 0.004f; + Projectile.velocity *= 0.97f; + Time++; + } + + public override void DrawBehind(int index, List drawCacheProjsBehindNPCsAndTiles, List drawCacheProjsBehindNPCs, List drawCacheProjsBehindProjectiles, List drawCacheProjsOverWiresUI, List overWiresUI) + { + ILChanges.ProjectileDrawCacheAdditiveBlending.Add(index); + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Projectile.type].Value; + Vector2 origin = texture.Size() * 0.5f; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + float opacity = Utils.GetLerpValue(0f, 0.08f, LightPower, true) * Projectile.Opacity * 0.8f; + Color drawColor = new Color(141, 255, 105) * opacity; + Vector2 scale = Projectile.Size / texture.Size() * Projectile.scale * 1.35f; + Main.spriteBatch.Draw(texture, drawPosition, null, drawColor, Projectile.rotation, origin, scale, SpriteEffects.None, 0f); + return false; + } + } +} diff --git a/Projectiles/Summon/SmallAresArms/MinionPlasmaGas.png b/Projectiles/Summon/SmallAresArms/MinionPlasmaGas.png new file mode 100644 index 0000000000..d26f30cbff Binary files /dev/null and b/Projectiles/Summon/SmallAresArms/MinionPlasmaGas.png differ diff --git a/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs b/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs new file mode 100644 index 0000000000..9355ec4c08 --- /dev/null +++ b/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs @@ -0,0 +1,150 @@ +using CalamityMod.Projectiles.Boss; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon.SmallAresArms +{ + public class MinionTeslaOrb : ModProjectile + { + public ref float Identity => ref Projectile.ai[0]; + + public ref float Time => ref Projectile.ai[1]; + + public PrimitiveTrail LightningDrawer; + + public PrimitiveTrail LightningBackgroundDrawer; + + public const float DetachDistance = 1500f; + + public override string Texture => "CalamityMod/Projectiles/Boss/AresTeslaOrb"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Tesla Sphere"); + Main.projFrames[Projectile.type] = 4; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 10000; + } + + public override void SetDefaults() + { + Projectile.width = 32; + Projectile.height = 32; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.penetrate = -1; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.timeLeft = 420; + Projectile.Opacity = 0f; + Projectile.DamageType = DamageClass.Summon; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(Projectile.localAI[0]); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + Projectile.localAI[0] = reader.ReadSingle(); + } + + public override void AI() + { + // Accelerate. + if (Projectile.velocity.Length() < 21f) + Projectile.velocity *= 1.012f; + + // Handle fade effects. + Projectile.Opacity = Utils.GetLerpValue(0f, 4f, Time, true) * Utils.GetLerpValue(0f, 15f, Projectile.timeLeft, true); + + // Emit electric light. + Lighting.AddLight(Projectile.Center, 0.1f * Projectile.Opacity, 0.25f * Projectile.Opacity, 0.25f * Projectile.Opacity); + + // Handle frames. + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type]; + + Time++; + } + + public Projectile GetOrbToAttachTo() + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != Projectile.type || Main.projectile[i].ai[0] != Identity + 1f || !Main.projectile[i].active) + continue; + + if (!Main.projectile[i].WithinRange(Projectile.Center, DetachDistance)) + continue; + + return Main.projectile[i]; + } + + return null; + } + + internal float WidthFunction(float completionRatio) + { + return MathHelper.Lerp(0.75f, 1.85f, (float)Math.Sin(MathHelper.Pi * completionRatio)) * Projectile.scale; + } + + internal Color ColorFunction(float completionRatio) + { + float fadeToWhite = MathHelper.Lerp(0f, 0.65f, (float)Math.Sin(MathHelper.TwoPi * completionRatio + Main.GlobalTimeWrappedHourly * 4f) * 0.5f + 0.5f); + Color baseColor = Color.Lerp(Color.Cyan, Color.White, fadeToWhite); + return Color.Lerp(baseColor, Color.LightBlue, ((float)Math.Sin(MathHelper.Pi * completionRatio + Main.GlobalTimeWrappedHourly * 4f) * 0.5f + 0.5f) * 0.8f) * Projectile.Opacity; + } + + internal float BackgroundWidthFunction(float completionRatio) => WidthFunction(completionRatio) * 4f; + + internal Color BackgroundColorFunction(float completionRatio) + { + Color color = Color.CornflowerBlue * Projectile.Opacity * 0.4f; + return color; + } + + public override bool PreDraw(ref Color lightColor) + { + if (LightningDrawer is null) + LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction); + if (LightningBackgroundDrawer is null) + LightningBackgroundDrawer = new PrimitiveTrail(BackgroundWidthFunction, BackgroundColorFunction, PrimitiveTrail.RigidPointRetreivalFunction); + + Projectile orbToAttachTo = GetOrbToAttachTo(); + if (orbToAttachTo != null) + { + List arcPoints = AresTeslaOrb.DetermineElectricArcPoints(Projectile.Center, orbToAttachTo.Center, 117); + LightningBackgroundDrawer.Draw(arcPoints, -Main.screenPosition, 90); + LightningDrawer.Draw(arcPoints, -Main.screenPosition, 90); + } + + lightColor.R = (byte)(255 * Projectile.Opacity); + lightColor.G = (byte)(255 * Projectile.Opacity); + lightColor.B = (byte)(255 * Projectile.Opacity); + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); + return false; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + if (projHitbox.Intersects(targetHitbox)) + return true; + + float _ = 0f; + Projectile orbToAttachTo = GetOrbToAttachTo(); + if (orbToAttachTo != null && Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Projectile.Center, orbToAttachTo.Center, 8f, ref _)) + return true; + + return false; + } + } +} diff --git a/Utilities/MathematicalUtils.cs b/Utilities/MathematicalUtils.cs index bee4e29d61..0c8af6d4d2 100644 --- a/Utilities/MathematicalUtils.cs +++ b/Utilities/MathematicalUtils.cs @@ -199,6 +199,14 @@ namespace CalamityMod return dividend - (float)Math.Floor(dividend / divisor) * divisor; } + /// + /// Clamps the magnitude of a vector via safe normalization. + /// + /// The vector. + /// The minimum magnitude. + /// The maximum magnitude. + public static Vector2 ClampMagnitude(this Vector2 v, float min, float max) => v.SafeNormalize(Vector2.UnitY) * MathHelper.Clamp(v.Length(), min, max); + #region Easings /// /// Gets a value from 0 to 1 and returns an eased value.