From f95e6571dfe874eae9a976eacae293e71da5e612 Mon Sep 17 00:00:00 2001 From: DominicKarma <51094361+DominicKarma@users.noreply.github.com> Date: Tue, 28 Sep 2021 20:19:19 -0500 Subject: [PATCH] Fixed rotation issues with Artemis' deathray --- NPCs/ExoMechs/Apollo/Apollo.cs | 27 ++-- Projectiles/Boss/ApolloChargeTelegraph.cs | 4 +- Projectiles/Boss/ArtemisLaserBeamStart.cs | 169 +++++++++++----------- 3 files changed, 98 insertions(+), 102 deletions(-) diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs index 8c458f9663..63d522428f 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -845,13 +845,13 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo // Save the charge locations and create telegraph beams int type = ModContent.ProjectileType(); - // Play a charge sound - Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"), npc.Center); - for (int i = 0; i < maxCharges; i++) { if (chargeLocations[i] == default) { + // Play a charge sound + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"), npc.Center); + switch (i) { case 0: @@ -869,17 +869,18 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo default: break; } - } - } - // Draw telegraph beams - if (Main.netMode != NetmodeID.MultiplayerClient) - { - int telegraph = Projectile.NewProjectile(chargeLocations[0], Vector2.Zero, type, 0, 0f, Main.myPlayer, 0f, npc.whoAmI); - if (Main.projectile.IndexInRange(telegraph)) - { - Main.projectile[telegraph].ModProjectile().ChargePositions = chargeLocations; - Main.projectile[telegraph].netUpdate = true; + + // Draw telegraph beams + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int telegraph = Projectile.NewProjectile(chargeLocations[0], Vector2.Zero, type, 0, 0f, Main.myPlayer, 0f, npc.whoAmI); + if (Main.projectile.IndexInRange(telegraph)) + { + Main.projectile[telegraph].ModProjectile().ChargePositions = chargeLocations; + Main.projectile[telegraph].netUpdate = true; + } + } } } diff --git a/Projectiles/Boss/ApolloChargeTelegraph.cs b/Projectiles/Boss/ApolloChargeTelegraph.cs index 693d19aaa9..a86159d4ab 100644 --- a/Projectiles/Boss/ApolloChargeTelegraph.cs +++ b/Projectiles/Boss/ApolloChargeTelegraph.cs @@ -77,9 +77,9 @@ namespace CalamityMod.Projectiles.Boss public Color TelegraphPrimitiveColor(float completionRatio) { - float opacity = MathHelper.Lerp(0.18f, 0.43f, projectile.Opacity); + float opacity = MathHelper.Lerp(0.18f, 0.48f, projectile.Opacity); opacity *= CalamityUtils.Convert01To010(completionRatio); - opacity *= (float)System.Math.Pow(MathHelper.Lerp(0.9f, 0.125f, projectile.ai[0] / (ChargePositions.Length - 1f)), 2D); + opacity *= (float)System.Math.Pow(MathHelper.Lerp(0.9f, 0.2f, projectile.ai[0] / (ChargePositions.Length - 1f)), 2D); if (completionRatio > 0.95f) opacity = 0.0000001f; return Color.Green * opacity; diff --git a/Projectiles/Boss/ArtemisLaserBeamStart.cs b/Projectiles/Boss/ArtemisLaserBeamStart.cs index fcf09f5f38..449e5e21a7 100644 --- a/Projectiles/Boss/ArtemisLaserBeamStart.cs +++ b/Projectiles/Boss/ArtemisLaserBeamStart.cs @@ -14,25 +14,25 @@ namespace CalamityMod.Projectiles.Boss { public class ArtemisLaserBeamStart : ModProjectile { - public override string Texture => "CalamityMod/Projectiles/Boss/AresLaserBeamStart"; + public override string Texture => "CalamityMod/Projectiles/Boss/AresLaserBeamStart"; - public NPC ThingToAttachTo => Main.npc.IndexInRange((int)projectile.ai[0]) ? Main.npc[(int)projectile.ai[0]] : null; - public ref float Time => ref projectile.localAI[0]; - public ref float LengthOfLaser => ref projectile.localAI[1]; - public const int Lifetime = 180; - public const float BeamPosOffset = 16f; - private const int maxFrames = 5; - private int frameDrawn = 0; + public NPC ThingToAttachTo => Main.npc.IndexInRange((int)projectile.ai[0]) ? Main.npc[(int)projectile.ai[0]] : null; + public ref float Time => ref projectile.localAI[0]; + public ref float LengthOfLaser => ref projectile.localAI[1]; + public const int Lifetime = 180; + public const float BeamPosOffset = 16f; + private const int maxFrames = 5; + private int frameDrawn = 0; - public override void SetStaticDefaults() + public override void SetStaticDefaults() { DisplayName.SetDefault("Artemis Deathray"); - } + } public override void SetDefaults() { - projectile.Calamity().canBreakPlayerDefense = true; - projectile.width = 30; + projectile.Calamity().canBreakPlayerDefense = true; + projectile.width = 30; projectile.height = 30; projectile.hostile = true; projectile.alpha = 255; @@ -44,45 +44,45 @@ namespace CalamityMod.Projectiles.Boss public override void SendExtraAI(BinaryWriter writer) { - writer.Write(frameDrawn); - writer.Write(Time); - writer.Write(LengthOfLaser); + writer.Write(frameDrawn); + writer.Write(Time); + writer.Write(LengthOfLaser); } public override void ReceiveExtraAI(BinaryReader reader) { - frameDrawn = reader.ReadInt32(); - Time = reader.ReadSingle(); - LengthOfLaser = reader.ReadSingle(); + frameDrawn = reader.ReadInt32(); + Time = reader.ReadSingle(); + LengthOfLaser = reader.ReadSingle(); } public override void AI() { - // Difficulty modes - bool malice = CalamityWorld.malice || BossRushEvent.BossRushActive; - bool death = CalamityWorld.death || malice; - bool revenge = CalamityWorld.revenge || malice; - bool expertMode = Main.expertMode || malice; + // Difficulty modes + bool malice = CalamityWorld.malice || BossRushEvent.BossRushActive; + bool death = CalamityWorld.death || malice; + bool revenge = CalamityWorld.revenge || malice; + bool expertMode = Main.expertMode || malice; - // Die if the thing to attach to disappears. - if (ThingToAttachTo is null || !ThingToAttachTo.active || ThingToAttachTo.Calamity().newAI[0] != 3f) - { - projectile.Kill(); - return; - } + // Die if the thing to attach to disappears. + if (ThingToAttachTo is null || !ThingToAttachTo.active || ThingToAttachTo.Calamity().newAI[0] != 3f) + { + projectile.Kill(); + return; + } - // The direction of the host NPC. - Vector2 hostNPCDirection = Vector2.Normalize(new Vector2(ThingToAttachTo.ai[1], ThingToAttachTo.ai[2]) - ThingToAttachTo.Center); + projectile.rotation = ThingToAttachTo.velocity.ToRotation(); + projectile.velocity = (projectile.rotation - MathHelper.PiOver2).ToRotationVector2(); - // Offset to move the beam forward so that it starts in Artemis' focus jewel thing. - float beamStartForwardsOffset = -70f; + // Offset to move the beam forward so that it starts in Artemis' focus jewel thing. + float beamStartForwardsOffset = 80f; - // Set the starting location of the beam to the center of the NPC. - projectile.Center = ThingToAttachTo.Center; - // Add a fixed offset to align with the NPC's spritesheet (?) - projectile.position += hostNPCDirection * BeamPosOffset + new Vector2(0f, -ThingToAttachTo.gfxOffY); - // Add the forwards offset, measured in pixels. - projectile.position += hostNPCDirection * beamStartForwardsOffset; + // Set the starting location of the beam to the center of the NPC. + projectile.Center = ThingToAttachTo.Center; + // Add a fixed offset to align with the NPC's spritesheet (?) + projectile.position += projectile.velocity * BeamPosOffset + new Vector2(0f, -ThingToAttachTo.gfxOffY); + // Add the forwards offset, measured in pixels. + projectile.position += projectile.velocity * beamStartForwardsOffset; Time++; if (Time >= Lifetime) @@ -91,17 +91,12 @@ namespace CalamityMod.Projectiles.Boss return; } - float scale = 1f; - projectile.scale = (float)Math.Sin(Time * MathHelper.Pi / Lifetime) * 10f * scale; + float scale = 1f; + projectile.scale = (float)Math.Sin(Time * MathHelper.Pi / Lifetime) * 10f * scale; if (projectile.scale > scale) projectile.scale = scale; - projectile.rotation = ThingToAttachTo.velocity.ToRotation(); - projectile.velocity = projectile.rotation.ToRotationVector2(); - - projectile.rotation = ThingToAttachTo.velocity.ToRotation() - MathHelper.PiOver2; - - float arraySize = 3f; + float arraySize = 3f; Vector2 samplingPoint = projectile.Center; float[] samples = new float[(int)arraySize]; Collision.LaserScan(samplingPoint, projectile.velocity, projectile.width * projectile.scale, 4800f, samples); @@ -116,13 +111,13 @@ namespace CalamityMod.Projectiles.Boss if (!Collision.CanHitLine(ThingToAttachTo.Center, 1, 1, Main.player[ThingToAttachTo.target].Center, 1, 1)) laserLength = 4800f; - float amount = 0.5f; - LengthOfLaser = MathHelper.Lerp(LengthOfLaser, laserLength, amount); + float amount = 0.5f; + LengthOfLaser = MathHelper.Lerp(LengthOfLaser, laserLength, amount); - // Spawn dust at the end of the beam - int dustType = (int)CalamityDusts.Brimstone; - Vector2 dustPos = projectile.Center + projectile.velocity * (LengthOfLaser - 14f); - for (int i = 0; i < 2; i++) + // Spawn dust at the end of the beam + int dustType = (int)CalamityDusts.Brimstone; + Vector2 dustPos = projectile.Center + projectile.velocity * (LengthOfLaser - 14f); + for (int i = 0; i < 2; i++) { float dustRot = projectile.velocity.ToRotation() + ((Main.rand.Next(2) == 1) ? -1f : 1f) * MathHelper.PiOver2; float dustVelMult = (float)Main.rand.NextDouble() * 2f + 2f; @@ -136,7 +131,7 @@ namespace CalamityMod.Projectiles.Boss { Vector2 dustRot = projectile.velocity.RotatedBy(MathHelper.PiOver2, default) * ((float)Main.rand.NextDouble() - 0.5f) * projectile.width; int dust = Dust.NewDust(dustPos + dustRot - Vector2.One * 4f, 8, 8, dustType, 0f, 0f, 100, default, 1.5f); - Main.dust[dust].velocity *= 0.5f; + Main.dust[dust].velocity *= 0.5f; Main.dust[dust].velocity.Y = -Math.Abs(Main.dust[dust].velocity.Y); } @@ -149,48 +144,48 @@ namespace CalamityMod.Projectiles.Boss if (projectile.velocity == Vector2.Zero) return false; - Texture2D beamStart = Main.projectileTexture[projectile.type]; - Texture2D beamMiddle = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/AresLaserBeamMiddle"); - Texture2D beamEnd = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/AresLaserBeamEnd"); + Texture2D beamStart = Main.projectileTexture[projectile.type]; + Texture2D beamMiddle = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/AresLaserBeamMiddle"); + Texture2D beamEnd = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/AresLaserBeamEnd"); - float drawLength = LengthOfLaser; + float drawLength = LengthOfLaser; Color color = new Color(250, 100, 100, 0); - if (Time % 5 == 0) - { - frameDrawn++; - if (frameDrawn >= maxFrames) - frameDrawn = 0; - } + if (Time % 5 == 0) + { + frameDrawn++; + if (frameDrawn >= maxFrames) + frameDrawn = 0; + } - // Draw start of beam - Vector2 vector = projectile.Center - Main.screenPosition; + // Draw start of beam + Vector2 vector = projectile.Center - Main.screenPosition; Rectangle? sourceRectangle = new Rectangle(0, beamStart.Height / maxFrames * frameDrawn, beamStart.Width, beamStart.Height / maxFrames); - spriteBatch.Draw(beamStart, vector, sourceRectangle, color, projectile.rotation, new Vector2(beamStart.Width, beamStart.Height / maxFrames) / 2f, projectile.scale, SpriteEffects.None, 0f); + spriteBatch.Draw(beamStart, vector, sourceRectangle, color, projectile.rotation, new Vector2(beamStart.Width, beamStart.Height / maxFrames) / 2f, projectile.scale, SpriteEffects.None, 0f); - // Draw middle of beam - drawLength -= (beamStart.Height / maxFrames / 2 + beamEnd.Height / maxFrames) * projectile.scale; + // Draw middle of beam + drawLength -= (beamStart.Height / maxFrames / 2 + beamEnd.Height / maxFrames) * projectile.scale; Vector2 center = projectile.Center; - center += projectile.velocity * projectile.scale * beamStart.Height / maxFrames / 2f; + center += projectile.velocity * projectile.scale * beamStart.Height / maxFrames / 2f; if (drawLength > 0f) { float i = 0f; - int middleFrameDrawn = frameDrawn; - while (i + 1f < drawLength) + int middleFrameDrawn = frameDrawn; + while (i + 1f < drawLength) { - Rectangle rectangle = new Rectangle(0, beamMiddle.Height / maxFrames * middleFrameDrawn, beamMiddle.Width, beamMiddle.Height / maxFrames); + Rectangle rectangle = new Rectangle(0, beamMiddle.Height / maxFrames * middleFrameDrawn, beamMiddle.Width, beamMiddle.Height / maxFrames); - if (drawLength - i < rectangle.Height) + if (drawLength - i < rectangle.Height) rectangle.Height = (int)(drawLength - i); spriteBatch.Draw(beamMiddle, center - Main.screenPosition, rectangle, color, projectile.rotation, new Vector2(rectangle.Width / 2f, 0f), projectile.scale, SpriteEffects.None, 0f); - middleFrameDrawn++; - if (middleFrameDrawn >= maxFrames) - middleFrameDrawn = 0; + middleFrameDrawn++; + if (middleFrameDrawn >= maxFrames) + middleFrameDrawn = 0; - i += rectangle.Height * projectile.scale; - center += projectile.velocity * rectangle.Height * projectile.scale; + i += rectangle.Height * projectile.scale; + center += projectile.velocity * rectangle.Height * projectile.scale; rectangle.Y += beamMiddle.Height / maxFrames; if (rectangle.Y + rectangle.Height > beamMiddle.Height / maxFrames) @@ -198,10 +193,10 @@ namespace CalamityMod.Projectiles.Boss } } - // Draw end of beam + // Draw end of beam Vector2 vector2 = center - Main.screenPosition; - sourceRectangle = new Rectangle(0, beamEnd.Height / maxFrames * frameDrawn, beamEnd.Width, beamEnd.Height / maxFrames); - spriteBatch.Draw(beamEnd, vector2, sourceRectangle, color, projectile.rotation, new Vector2(beamEnd.Width, beamEnd.Height / maxFrames) / 2f, projectile.scale, SpriteEffects.None, 0f); + sourceRectangle = new Rectangle(0, beamEnd.Height / maxFrames * frameDrawn, beamEnd.Width, beamEnd.Height / maxFrames); + spriteBatch.Draw(beamEnd, vector2, sourceRectangle, color, projectile.rotation, new Vector2(beamEnd.Width, beamEnd.Height / maxFrames) / 2f, projectile.scale, SpriteEffects.None, 0f); return false; } @@ -227,12 +222,12 @@ namespace CalamityMod.Projectiles.Boss public override void OnHitPlayer(Player target, int damage, bool crit) { - target.AddBuff(ModContent.BuffType(), 300); - } + target.AddBuff(ModContent.BuffType(), 300); + } - public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) + public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) { - target.Calamity().lastProjectileHit = projectile; - } + target.Calamity().lastProjectileHit = projectile; + } } }