From 8ba2beed8577d96a5670ee7a47f165d544d62abb Mon Sep 17 00:00:00 2001 From: CongratsIsTrash <1q2w3e4dasd@gmail.com> Date: Thu, 12 Dec 2024 14:39:32 -0500 Subject: [PATCH] Fixed Demonshade Devil resummon exploit Also made it move much faster, and refactored its code --- Items/Armor/Demonshade/DemonshadeHelm.cs | 2 +- Projectiles/Typeless/DemonshadeRedDevil.cs | 137 ++++++++------------- 2 files changed, 49 insertions(+), 90 deletions(-) diff --git a/Items/Armor/Demonshade/DemonshadeHelm.cs b/Items/Armor/Demonshade/DemonshadeHelm.cs index a3a13900f7..2e854e84d2 100644 --- a/Items/Armor/Demonshade/DemonshadeHelm.cs +++ b/Items/Armor/Demonshade/DemonshadeHelm.cs @@ -65,7 +65,7 @@ namespace CalamityMod.Items.Armor.Demonshade { int damage = (int)player.GetTotalDamage().ApplyTo(DevilDamage); - var devil = Projectile.NewProjectileDirect(source, player.Center, -Vector2.UnitY, ModContent.ProjectileType(), damage, 0f, Main.myPlayer, 0f, 0f); + var devil = Projectile.NewProjectileDirect(source, player.Center, -Vector2.UnitY, ModContent.ProjectileType(), damage, 0f, Main.myPlayer, 2f, 0f); devil.originalDamage = DevilDamage; } } diff --git a/Projectiles/Typeless/DemonshadeRedDevil.cs b/Projectiles/Typeless/DemonshadeRedDevil.cs index 2e1a342110..6a464560cb 100644 --- a/Projectiles/Typeless/DemonshadeRedDevil.cs +++ b/Projectiles/Typeless/DemonshadeRedDevil.cs @@ -14,6 +14,9 @@ namespace CalamityMod.Projectiles.Typeless public new string LocalizationCategory => "Projectiles.Typeless"; public int dust = 3; + public ref float State => ref Projectile.ai[0]; // 0 = attacking, 1 = returning, 2 = initial spawn + public ref float Timer => ref Projectile.ai[1]; + public override void SetStaticDefaults() { Main.projFrames[Type] = 5; @@ -55,6 +58,7 @@ namespace CalamityMod.Projectiles.Typeless Projectile.timeLeft = 2; } } + dust--; if (dust >= 0) { @@ -65,57 +69,41 @@ namespace CalamityMod.Projectiles.Typeless Main.dust[brimDust].scale *= 1.15f; } } + Projectile.frameCounter++; if (Projectile.frameCounter > 8) { - Projectile.frame++; Projectile.frameCounter = 0; + Projectile.frame++; + if (Projectile.frame > 4) + Projectile.frame = 0; } - if (Projectile.frame > 4) - { - Projectile.frame = 0; - } + float lights = (float)Main.rand.Next(90, 111) * 0.01f; lights *= Main.essScale; Lighting.AddLight(Projectile.Center, 1f * lights, 0f * lights, 0.15f * lights); + Projectile.rotation = Projectile.velocity.X * 0.04f; if ((double)Math.Abs(Projectile.velocity.X) > 0.2) { Projectile.spriteDirection = -Projectile.direction; } - float attackRange = 2000f; - bool decelerate = false; - if (Projectile.ai[0] == 2f) + + if (State == 2f) { - Projectile.ai[1] += 1f; - Projectile.extraUpdates = 1; - if (Projectile.ai[1] > 40f) + Timer++; + if (Timer > 60f) { - Projectile.ai[1] = 1f; - Projectile.ai[0] = 0f; - Projectile.extraUpdates = 0; - Projectile.numUpdates = 0; + Timer = 1f; + State = 0f; Projectile.netUpdate = true; } - else - { - decelerate = true; - } - } - if (decelerate) - { return; } - Vector2 projPos = Projectile.position; + + Vector2 attackPos = Projectile.position; + float attackRange = 2000f; bool canAttack = false; - if (Projectile.ai[0] != 1f) - { - Projectile.tileCollide = false; - } - if (Projectile.tileCollide && WorldGen.SolidTile(Framing.GetTileSafely((int)Projectile.Center.X / 16, (int)Projectile.Center.Y / 16))) - { - Projectile.tileCollide = false; - } if (player.HasMinionAttackTargetNPC) { NPC npc = Main.npc[player.MinionAttackTargetNPC]; @@ -125,7 +113,7 @@ namespace CalamityMod.Projectiles.Typeless if (!canAttack && npcDist < attackRange) { attackRange = npcDist; - projPos = npc.Center; + attackPos = npc.Center; canAttack = true; } } @@ -140,68 +128,54 @@ namespace CalamityMod.Projectiles.Typeless if ((!canAttack && npcDist < attackRange) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, nPC2.position, nPC2.width, nPC2.height)) { attackRange = npcDist; - projPos = nPC2.Center; + attackPos = nPC2.Center; canAttack = true; } } } } - float separationAnxietyDist = 2000f; - if (canAttack) - { - separationAnxietyDist = 3000f; - } + + float separationAnxietyDist = canAttack ? 3000f: 2000f; if (Vector2.Distance(player.Center, Projectile.Center) > separationAnxietyDist) { - Projectile.ai[0] = 1f; - Projectile.tileCollide = false; + State = 1f; Projectile.netUpdate = true; } - if (canAttack && Projectile.ai[0] == 0f) + if (canAttack && State == 0f) { - Vector2 projDirection = projPos - Projectile.Center; + Vector2 projDirection = attackPos - Projectile.Center; float projDist = projDirection.Length(); projDirection.Normalize(); if (projDist > 200f) { - float scaleFactor2 = 16f; //8 - projDirection *= scaleFactor2; + projDirection *= 25f; Projectile.velocity = (Projectile.velocity * 40f + projDirection) / 41f; } else { - projDirection *= -4f; + projDirection *= -9f; Projectile.velocity = (Projectile.velocity * 40f + projDirection) / 41f; } } else { - bool isReturning = false; - if (!isReturning) - { - isReturning = Projectile.ai[0] == 1f; - } - float returnSpeed = 5f; //6 - if (isReturning) - { - returnSpeed = 12f; //15 - } - Vector2 center2 = Projectile.Center; - Vector2 playerDirection = player.Center - center2 + new Vector2(0f, -30f); //-60 + bool isReturning = State == 1f; + float returnSpeed = isReturning ? 24f : 15f; + + Vector2 playerDirection = player.Center - Projectile.Center + new Vector2(0f, -30f); float playerDist = playerDirection.Length(); - if (playerDist > 200f && returnSpeed < 6.5f) //200 and 8 + if (playerDist > 200f && returnSpeed < 10f) { - returnSpeed = 6.5f; //8 + returnSpeed = 18f; } if (playerDist < 150f && isReturning && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height)) { - Projectile.ai[0] = 0f; + State = 0f; Projectile.netUpdate = true; } if (playerDist > 2000f) { - Projectile.position.X = player.Center.X - (float)(Projectile.width / 2); - Projectile.position.Y = player.Center.Y - (float)(Projectile.height / 2); + Projectile.Center = player.Center; Projectile.netUpdate = true; } if (playerDist > 70f) @@ -210,34 +184,29 @@ namespace CalamityMod.Projectiles.Typeless playerDirection *= returnSpeed; Projectile.velocity = (Projectile.velocity * 40f + playerDirection) / 41f; } - else if (Projectile.velocity.X == 0f && Projectile.velocity.Y == 0f) + else if (Projectile.velocity == Vector2.Zero) { - Projectile.velocity.X = -0.2f; - Projectile.velocity.Y = -0.1f; + Projectile.velocity = new Vector2(-0.2f, -0.1f); } } - if (Projectile.ai[1] > 0f) + if (Timer > 0f) { - Projectile.ai[1] += (float)Main.rand.Next(1, 4); + Timer += Main.rand.Next(1, 2 + 1); } - if (Projectile.ai[1] > 80f) + if (Timer > 80f) { - Projectile.ai[1] = 0f; + Timer = 0f; Projectile.netUpdate = true; } - if (Projectile.ai[0] == 0f) + if (State == 0f) { - float speed = 24f; - int projType = ProjectileID.UnholyTridentFriendly; - if (canAttack && Projectile.ai[1] == 0f) + if (canAttack && Timer == 0f) { - Projectile.ai[1] += 1f; - if (Main.myPlayer == Projectile.owner && Collision.CanHitLine(Projectile.Center, Projectile.width, Projectile.height, projPos, 0, 0)) + Timer += 1f; + if (Main.myPlayer == Projectile.owner && Collision.CanHitLine(Projectile.Center, Projectile.width, Projectile.height, attackPos, 0, 0)) { - Vector2 velocity = projPos - Projectile.Center; - velocity.Normalize(); - velocity *= speed; - int trident = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, projType, Projectile.damage, 0f, Main.myPlayer); + Vector2 velocity = Vector2.Normalize(attackPos - Projectile.Center) * 24f; + int trident = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ProjectileID.UnholyTridentFriendly, Projectile.damage, 0f, Main.myPlayer); if (trident.WithinBounds(Main.maxProjectiles)) { Main.projectile[trident].timeLeft = 300; @@ -251,16 +220,6 @@ namespace CalamityMod.Projectiles.Typeless } } - public override bool PreDraw(ref Color lightColor) - { - SpriteEffects spriteEffects = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; - Texture2D texture2D13 = Terraria.GameContent.TextureAssets.Projectile[Type].Value; - int framing = Terraria.GameContent.TextureAssets.Projectile[Type].Value.Height / Main.projFrames[Type]; - int y6 = framing * Projectile.frame; - Main.spriteBatch.Draw(texture2D13, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, framing)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)framing / 2f), Projectile.scale, spriteEffects, 0); - return false; - } - public override bool? CanDamage() => false; } }