diff --git a/Items/Weapons/Melee/Murasama.cs b/Items/Weapons/Melee/Murasama.cs index 731ec4afcf..96056ec929 100644 --- a/Items/Weapons/Melee/Murasama.cs +++ b/Items/Weapons/Melee/Murasama.cs @@ -6,7 +6,6 @@ using Terraria; using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; -using Terraria.ID; namespace CalamityMod.Items.Weapons.Melee { diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 6b3323c9c9..a664be8030 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -2102,408 +2102,6 @@ namespace CalamityMod.Projectiles } } - public static void HealingProjectile(Projectile projectile, int healing, int playerToHeal, float homingVelocity, float N, bool autoHomes = true, int timeCheck = 120) - { - int target = playerToHeal; - Player player = Main.player[target]; - float homingSpeed = homingVelocity; - if (player.lifeMagnet) - homingSpeed *= 1.5f; - - Vector2 projPos = new Vector2(projectile.Center.X, projectile.Center.Y); - float xDist = player.Center.X - projPos.X; - float yDist = player.Center.Y - projPos.Y; - Vector2 playerVector = new Vector2(xDist, yDist); - float playerDist = playerVector.Length(); - if (playerDist < 50f && projectile.position.X < player.position.X + player.width && projectile.position.X + projectile.width > player.position.X && projectile.position.Y < player.position.Y + player.height && projectile.position.Y + projectile.height > player.position.Y) - { - if (projectile.owner == Main.myPlayer && !Main.player[Main.myPlayer].moonLeech) - { - int healAmt = healing; - player.HealEffect(healAmt, false); - player.statLife += healAmt; - if (player.statLife > player.statLifeMax2) - { - player.statLife = player.statLifeMax2; - } - NetMessage.SendData(MessageID.SpiritHeal, -1, -1, null, target, healAmt, 0f, 0f, 0, 0, 0); - } - projectile.Kill(); - } - if (autoHomes) - { - playerDist = homingSpeed / playerDist; - playerVector.X *= playerDist; - playerVector.Y *= playerDist; - projectile.velocity.X = (projectile.velocity.X * N + playerVector.X) / (N + 1f); - projectile.velocity.Y = (projectile.velocity.Y * N + playerVector.Y) / (N + 1f); - } - else if (player.lifeMagnet && projectile.timeLeft < timeCheck) - { - playerDist = homingVelocity / playerDist; - playerVector.X *= playerDist; - playerVector.Y *= playerDist; - projectile.velocity.X = (projectile.velocity.X * N + playerVector.X) / (N + 1f); - projectile.velocity.Y = (projectile.velocity.Y * N + playerVector.Y) / (N + 1f); - } - } - - public static void ChargingMinionAI(Projectile projectile, float range, float maxPlayerDist, float extraMaxPlayerDist, float safeDist, int initialUpdates, float chargeDelayTime, float goToSpeed, float goBackSpeed, float chargeCounterMax, float chargeSpeed, bool tileVision, bool ignoreTilesWhenCharging) - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - - //Anti sticky movement to prevent stacking - float antiStickMvt = 0.05f; - for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) - { - Projectile proj = Main.projectile[projIndex]; - bool typeCheck = proj.type == projectile.type; - if (projIndex != projectile.whoAmI && proj.active && proj.owner == projectile.owner && typeCheck && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= antiStickMvt; - } - else - { - projectile.velocity.X += antiStickMvt; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= antiStickMvt; - } - else - { - projectile.velocity.Y += antiStickMvt; - } - } - } - - //Breather time between charges as like a reset - bool chargeDelay = false; - if (projectile.ai[0] == 2f) - { - projectile.ai[1] += 1f; - projectile.extraUpdates = initialUpdates + (projectile.type == ModContent.ProjectileType() ? 2 : 1); - if (projectile.ai[1] > chargeDelayTime) - { - projectile.ai[1] = 1f; - projectile.ai[0] = 0f; - projectile.extraUpdates = initialUpdates; - projectile.numUpdates = 0; - projectile.netUpdate = true; - } - else - { - chargeDelay = true; - } - } - if (chargeDelay) - { - return; - } - - //Find a target - float maxDist = range; - Vector2 targetVec = projectile.position; - bool foundTarget = false; - Vector2 half = new Vector2(0.5f); - //Prioritize the targeted enemy if possible - if (player.HasMinionAttackTargetNPC) - { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy(projectile, false)) - { - //Check the size of the target to make it easier to hit fat targets like Levi - Vector2 sizeCheck = npc.position + npc.Size * half; - float targetDist = Vector2.Distance(npc.Center, projectile.Center); - //Some minions will ignore tiles when choosing a target like Ice Claspers, others will not - bool canHit = true; - if (!tileVision) - canHit = Collision.CanHitLine(projectile.position, projectile.width, projectile.height, npc.position, npc.width, npc.height); - if (!foundTarget && targetDist < maxDist && canHit) - { - maxDist = targetDist; - targetVec = sizeCheck; - foundTarget = true; - } - } - } - //If no npc is specifically targetted, check through the entire array - else - { - for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) - { - NPC npc = Main.npc[npcIndex]; - if (npc.CanBeChasedBy(projectile, false)) - { - Vector2 sizeCheck = npc.position + npc.Size * half; - float targetDist = Vector2.Distance(npc.Center, projectile.Center); - bool canHit = true; - if (!tileVision) - canHit = Collision.CanHitLine(projectile.position, projectile.width, projectile.height, npc.position, npc.width, npc.height); - if (!foundTarget && targetDist < maxDist && canHit) - { - maxDist = targetDist; - targetVec = sizeCheck; - foundTarget = true; - } - } - } - } - - //If the player is too far, return to the player. Range is increased while attacking something. - float distBeforeForcedReturn = maxPlayerDist; - if (foundTarget) - { - distBeforeForcedReturn = extraMaxPlayerDist; - } - if (Vector2.Distance(player.Center, projectile.Center) > distBeforeForcedReturn) - { - projectile.ai[0] = 1f; - projectile.netUpdate = true; - } - - //Go to the target if you found one - if (foundTarget && projectile.ai[0] == 0f) - { - //Some minions don't ignore tiles while charging like brittle stars - projectile.tileCollide = !ignoreTilesWhenCharging; - Vector2 targetSpot = targetVec - projectile.Center; - float targetDist = targetSpot.Length(); - targetSpot.Normalize(); - //Tries to get the minion in the sweet spot of 200 pixels away but the minion also charges so idk what good it does - if (targetDist > 200f) - { - float speed = goToSpeed; //8 - targetSpot *= speed; - projectile.velocity = (projectile.velocity * 40f + targetSpot) / 41f; - } - else - { - float speed = -goBackSpeed; //-4 - targetSpot *= speed; - projectile.velocity = (projectile.velocity * 40f + targetSpot) / 41f; //41 - } - } - - //Movement for idle or returning to the player - else - { - //Ignore tiles so they don't get stuck everywhere like Optic Staff - projectile.tileCollide = false; - - bool returningToPlayer = false; - if (!returningToPlayer) - { - returningToPlayer = projectile.ai[0] == 1f; - } - - //Player distance calculations - Vector2 playerVec = player.Center - projectile.Center + new Vector2(0f, -60f); - float playerDist = playerVec.Length(); - - //If the minion is actively returning, move faster - float playerHomeSpeed = 6f; - if (returningToPlayer) - { - playerHomeSpeed = 15f; - } - //Move somewhat faster if the player is kinda far~ish - if (playerDist > 200f && playerHomeSpeed < 8f) - { - playerHomeSpeed = 8f; - } - //Return to normal if close enough to the player - if (playerDist < safeDist && returningToPlayer && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) - { - projectile.ai[0] = 0f; - projectile.netUpdate = true; - } - //Teleport to the player if abnormally far - if (playerDist > 2000f) - { - projectile.position.X = player.Center.X - (float)(projectile.width / 2); - projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); - projectile.netUpdate = true; - } - //If more than 70 pixels away, move toward the player - if (playerDist > 70f) - { - playerVec.Normalize(); - playerVec *= playerHomeSpeed; - projectile.velocity = (projectile.velocity * 40f + playerVec) / 41f; - } - //Minions never stay still - else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) - { - projectile.velocity.X = -0.15f; - projectile.velocity.Y = -0.05f; - } - } - - //Increment attack counter randomly - if (projectile.ai[1] > 0f) - { - projectile.ai[1] += (float)Main.rand.Next(1, 4); - } - //If high enough, prepare to attack - if (projectile.ai[1] > chargeCounterMax) - { - projectile.ai[1] = 0f; - projectile.netUpdate = true; - } - - //Charge at an enemy if not on cooldown - if (projectile.ai[0] == 0f) - { - if (projectile.ai[1] == 0f && foundTarget && maxDist < 500f) - { - projectile.ai[1] += 1f; - if (Main.myPlayer == projectile.owner) - { - projectile.ai[0] = 2f; - Vector2 targetPos = targetVec - projectile.Center; - targetPos.Normalize(); - projectile.velocity = targetPos * chargeSpeed; //8 - projectile.netUpdate = true; - } - } - } - } - - public static void FloatingPetAI(Projectile projectile, bool faceRight, float tiltFloat, bool lightPet = false) - { - Player player = Main.player[projectile.owner]; - - //anti sticking movement as a failsafe - float SAImovement = 0.05f; - for (int index = 0; index < Main.projectile.Length; index++) - { - Projectile proj = Main.projectile[index]; - bool flag23 = Main.projPet[proj.type]; - if (index != projectile.whoAmI && proj.active && proj.owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= SAImovement; - } - else - { - projectile.velocity.X += SAImovement; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= SAImovement; - } - else - { - projectile.velocity.Y += SAImovement; - } - } - } - - float passiveMvtFloat = 0.5f; - projectile.tileCollide = false; - float range = 100f; - Vector2 projPos = new Vector2(projectile.Center.X, projectile.Center.Y); - float xDist = player.Center.X - projPos.X; - float yDist = player.Center.Y - projPos.Y; - yDist += Main.rand.NextFloat(-10, 20); - xDist += Main.rand.NextFloat(-10, 20); - //Light pets lead the player, normal pets trail the player - xDist += 60f * (lightPet ? (float)player.direction : -(float)player.direction); - yDist -= 60f; - Vector2 playerVector = new Vector2(xDist, yDist); - float playerDist = playerVector.Length(); - float returnSpeed = 18f; - - //If player is close enough, resume normal - if (playerDist < range && player.velocity.Y == 0f && - projectile.position.Y + projectile.height <= player.position.Y + player.height && - !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) - { - if (projectile.velocity.Y < -6f) - { - projectile.velocity.Y = -6f; - } - } - - //Teleport to player if too far - if (playerDist > 2000f) - { - projectile.position.X = player.Center.X - projectile.width / 2; - projectile.position.Y = player.Center.Y - projectile.height / 2; - projectile.netUpdate = true; - } - - if (playerDist < 50f) - { - if (Math.Abs(projectile.velocity.X) > 2f || Math.Abs(projectile.velocity.Y) > 2f) - { - projectile.velocity *= 0.99f; - } - passiveMvtFloat = 0.01f; - } - else - { - if (playerDist < 100f) - { - passiveMvtFloat = 0.1f; - } - if (playerDist > 300f) - { - passiveMvtFloat = 1f; - } - playerDist = returnSpeed / playerDist; - playerVector.X *= playerDist; - playerVector.Y *= playerDist; - } - if (projectile.velocity.X < playerVector.X) - { - projectile.velocity.X += passiveMvtFloat; - if (passiveMvtFloat > 0.05f && projectile.velocity.X < 0f) - { - projectile.velocity.X += passiveMvtFloat; - } - } - if (projectile.velocity.X > playerVector.X) - { - projectile.velocity.X -= passiveMvtFloat; - if (passiveMvtFloat > 0.05f && projectile.velocity.X > 0f) - { - projectile.velocity.X -= passiveMvtFloat; - } - } - if (projectile.velocity.Y < playerVector.Y) - { - projectile.velocity.Y += passiveMvtFloat; - if (passiveMvtFloat > 0.05f && projectile.velocity.Y < 0f) - { - projectile.velocity.Y += passiveMvtFloat * 2f; - } - } - if (projectile.velocity.Y > playerVector.Y) - { - projectile.velocity.Y -= passiveMvtFloat; - if (passiveMvtFloat > 0.05f && projectile.velocity.Y > 0f) - { - projectile.velocity.Y -= passiveMvtFloat * 2f; - } - } - if (projectile.velocity.X >= 0.25f) - { - projectile.direction = faceRight ? 1 : -1; - } - else if (projectile.velocity.X < -0.25f) - { - projectile.direction = faceRight ? -1 : 1; - } - //Tilting and change directions - projectile.spriteDirection = projectile.direction; - projectile.rotation = projectile.velocity.X * tiltFloat; - } public static void ExpandHitboxBy(Projectile projectile, int width, int height) { projectile.position = projectile.Center; diff --git a/Projectiles/DraedonsArsenal/PulseRifleShot.cs b/Projectiles/DraedonsArsenal/PulseRifleShot.cs index f501dd16a5..d4db6eaaad 100644 --- a/Projectiles/DraedonsArsenal/PulseRifleShot.cs +++ b/Projectiles/DraedonsArsenal/PulseRifleShot.cs @@ -128,19 +128,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal if (!target.boss) { - if (target.HitSound != SoundID.NPCHit1 && target.HitSound != SoundID.NPCHit6 && target.HitSound != SoundID.NPCHit7 && - target.HitSound != SoundID.NPCHit8 && target.HitSound != SoundID.NPCHit9 && target.HitSound != SoundID.NPCHit12 && - target.HitSound != SoundID.NPCHit13 && target.HitSound != SoundID.NPCHit14 && target.HitSound != SoundID.NPCHit18 && - target.HitSound != SoundID.NPCHit19 && target.HitSound != SoundID.NPCHit20 && target.HitSound != SoundID.NPCHit21 && - target.HitSound != SoundID.NPCHit22 && target.HitSound != SoundID.NPCHit23 && target.HitSound != SoundID.NPCHit24 && - target.HitSound != SoundID.NPCHit25 && target.HitSound != SoundID.NPCHit26 && target.HitSound != SoundID.NPCHit27 && - target.HitSound != SoundID.NPCHit28 && target.HitSound != SoundID.NPCHit29 && target.HitSound != SoundID.NPCHit31 && - target.HitSound != SoundID.NPCHit32 && target.HitSound != SoundID.NPCHit33 && target.HitSound != SoundID.NPCHit35 && - target.HitSound != SoundID.NPCHit37 && target.HitSound != SoundID.NPCHit38 && target.HitSound != SoundID.NPCHit40 && - target.HitSound != SoundID.NPCHit43 && target.HitSound != SoundID.NPCHit44 && target.HitSound != SoundID.NPCHit45 && - target.HitSound != SoundID.NPCHit46 && target.HitSound != SoundID.NPCHit47 && target.HitSound != SoundID.NPCHit48 && - target.HitSound != SoundID.NPCHit50 && target.HitSound != SoundID.NPCHit51 && target.HitSound != SoundID.NPCHit55 && - target.HitSound != SoundID.NPCHit56 && target.HitSound != SoundID.NPCHit57) + if (target.Inorganic()) { damage += target.lifeMax / 250; } diff --git a/Projectiles/DraedonsArsenal/TeslaCannonShot.cs b/Projectiles/DraedonsArsenal/TeslaCannonShot.cs index 01ac483735..e2b8ab0df7 100644 --- a/Projectiles/DraedonsArsenal/TeslaCannonShot.cs +++ b/Projectiles/DraedonsArsenal/TeslaCannonShot.cs @@ -143,11 +143,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal { if (projectile.ai[1] >= 0f) { - if (target.HitSound != SoundID.NPCHit4 && target.HitSound != SoundID.NPCHit41 && target.HitSound != SoundID.NPCHit2 && - target.HitSound != SoundID.NPCHit5 && target.HitSound != SoundID.NPCHit11 && target.HitSound != SoundID.NPCHit30 && - target.HitSound != SoundID.NPCHit34 && target.HitSound != SoundID.NPCHit36 && target.HitSound != SoundID.NPCHit42 && - target.HitSound != SoundID.NPCHit49 && target.HitSound != SoundID.NPCHit52 && target.HitSound != SoundID.NPCHit53 && - target.HitSound != SoundID.NPCHit54 && target.HitSound != null) + if (target.Organic()) { target.velocity.X = 0f; target.velocity.Y = 0f; diff --git a/Projectiles/Healing/AtaxiaHealOrb.cs b/Projectiles/Healing/AtaxiaHealOrb.cs index 1e2d73cc27..f886f3a334 100644 --- a/Projectiles/Healing/AtaxiaHealOrb.cs +++ b/Projectiles/Healing/AtaxiaHealOrb.cs @@ -23,7 +23,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 5.5f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 5.5f, 15f); int dusty = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 127, 0f, 0f, 100, default, 2f); Dust dust = Main.dust[dusty]; dust.noGravity = true; diff --git a/Projectiles/Healing/AuricOrb.cs b/Projectiles/Healing/AuricOrb.cs index 9fc7f6454e..60995c3d47 100644 --- a/Projectiles/Healing/AuricOrb.cs +++ b/Projectiles/Healing/AuricOrb.cs @@ -41,7 +41,7 @@ namespace CalamityMod.Projectiles.Healing } } - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 6f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 6f, 15f); return; } diff --git a/Projectiles/Healing/BurntSiennaProj.cs b/Projectiles/Healing/BurntSiennaProj.cs index 13e5238014..c6c3346e9d 100644 --- a/Projectiles/Healing/BurntSiennaProj.cs +++ b/Projectiles/Healing/BurntSiennaProj.cs @@ -26,7 +26,7 @@ namespace CalamityMod.Projectiles.Healing projectile.velocity.X *= 0.95f; projectile.velocity.Y *= 0.95f; - CalamityGlobalProjectile.HealingProjectile(projectile, 3, (int)projectile.ai[0], 6f, 15f, false); + projectile.HealingProjectile(3, (int)projectile.ai[0], 6f, 15f, false); int dusty = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 246, 0f, 0f, 100, default, 1f); Dust dust = Main.dust[dusty]; dust.noGravity = true; diff --git a/Projectiles/Healing/CactusHealOrb.cs b/Projectiles/Healing/CactusHealOrb.cs index 30d4d0449d..654c25a857 100644 --- a/Projectiles/Healing/CactusHealOrb.cs +++ b/Projectiles/Healing/CactusHealOrb.cs @@ -25,7 +25,7 @@ namespace CalamityMod.Projectiles.Healing { projectile.velocity.Y *= 0.98f; - CalamityGlobalProjectile.HealingProjectile(projectile, 25, projectile.owner, 12f, 15f); + projectile.HealingProjectile(25, projectile.owner, 12f, 15f); int dusty = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 107, 0f, 0f, 100, new Color(0, 200, 0), 1.5f); Dust dust = Main.dust[dusty]; dust.noGravity = true; diff --git a/Projectiles/Healing/EarthHealOrb.cs b/Projectiles/Healing/EarthHealOrb.cs index 701590c6cc..6c936348f5 100644 --- a/Projectiles/Healing/EarthHealOrb.cs +++ b/Projectiles/Healing/EarthHealOrb.cs @@ -23,7 +23,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 8f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 8f, 15f); int dusty = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 74, 0f, 0f, 100, default, 1f); Dust dust = Main.dust[dusty]; dust.noGravity = true; diff --git a/Projectiles/Healing/EssenceFlame.cs b/Projectiles/Healing/EssenceFlame.cs index f497e31bbd..2080699aaf 100644 --- a/Projectiles/Healing/EssenceFlame.cs +++ b/Projectiles/Healing/EssenceFlame.cs @@ -38,7 +38,7 @@ namespace CalamityMod.Projectiles.Healing projectile.frame = 0; } - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 3.5f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 3.5f, 15f); return; } diff --git a/Projectiles/Healing/Exoheal.cs b/Projectiles/Healing/Exoheal.cs index 745d106fe4..bcbfbf33d0 100644 --- a/Projectiles/Healing/Exoheal.cs +++ b/Projectiles/Healing/Exoheal.cs @@ -23,7 +23,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 8f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 8f, 15f); int dusty = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1f); Dust dust = Main.dust[dusty]; dust.noGravity = true; diff --git a/Projectiles/Healing/FungalHeal.cs b/Projectiles/Healing/FungalHeal.cs index 35edf8c598..dbe1764206 100644 --- a/Projectiles/Healing/FungalHeal.cs +++ b/Projectiles/Healing/FungalHeal.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Healing projectile.localAI[0] += 1f; } - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 5f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 5f, 15f); float num494 = projectile.velocity.X * 0.334f; float num495 = -(projectile.velocity.Y * 0.334f); int num496 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 56, 0f, 0f, 100, default, 0.5f); diff --git a/Projectiles/Healing/GodSlayerHealOrb.cs b/Projectiles/Healing/GodSlayerHealOrb.cs index a1f66abfb7..bb6d057f40 100644 --- a/Projectiles/Healing/GodSlayerHealOrb.cs +++ b/Projectiles/Healing/GodSlayerHealOrb.cs @@ -23,7 +23,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 6.5f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 6.5f, 15f); int dusty = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 173, 0f, 0f, 100, default, 2f); Dust dust = Main.dust[dusty]; dust.noGravity = true; diff --git a/Projectiles/Healing/ManaOverloaderHealOrb.cs b/Projectiles/Healing/ManaOverloaderHealOrb.cs index d470be1db8..bfd57807c9 100644 --- a/Projectiles/Healing/ManaOverloaderHealOrb.cs +++ b/Projectiles/Healing/ManaOverloaderHealOrb.cs @@ -23,7 +23,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 3f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 3f, 15f); int dusty = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 175, 0f, 0f, 100, default, 1.3f); Dust dust = Main.dust[dusty]; dust.noGravity = true; diff --git a/Projectiles/Healing/PhoenixHeal.cs b/Projectiles/Healing/PhoenixHeal.cs index b53ddd51e7..0434f84892 100644 --- a/Projectiles/Healing/PhoenixHeal.cs +++ b/Projectiles/Healing/PhoenixHeal.cs @@ -24,7 +24,7 @@ namespace CalamityMod.Projectiles.Healing { projectile.velocity.X *= 0.95f; projectile.velocity.Y *= 0.95f; - CalamityGlobalProjectile.HealingProjectile(projectile, 10, (int)projectile.ai[0], 6f, 15f, false, 360); + projectile.HealingProjectile(10, (int)projectile.ai[0], 6f, 15f, false, 360); float num498 = projectile.velocity.X * 0.2f; float num499 = -(projectile.velocity.Y * 0.2f); int num500 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 244, 0f, 0f, 100, default, 1f); diff --git a/Projectiles/Healing/RainHeal.cs b/Projectiles/Healing/RainHeal.cs index 31a8effd9a..329c8fdb07 100644 --- a/Projectiles/Healing/RainHeal.cs +++ b/Projectiles/Healing/RainHeal.cs @@ -25,7 +25,7 @@ namespace CalamityMod.Projectiles.Healing { projectile.velocity.X *= 0.985f; projectile.velocity.Y *= 0.985f; - CalamityGlobalProjectile.HealingProjectile(projectile, 8, projectile.owner, 12f, 15f, false); + projectile.HealingProjectile(8, projectile.owner, 12f, 15f, false); float num498 = projectile.velocity.X * 0.2f; float num499 = -(projectile.velocity.Y * 0.2f); diff --git a/Projectiles/Healing/RoyalHeal.cs b/Projectiles/Healing/RoyalHeal.cs index 39eadfa9e7..7d0b933b52 100644 --- a/Projectiles/Healing/RoyalHeal.cs +++ b/Projectiles/Healing/RoyalHeal.cs @@ -21,7 +21,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 5.5f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 5.5f, 15f); for (int num493 = 0; num493 < 3; num493++) { float num494 = projectile.velocity.X * 0.334f * (float)num493; diff --git a/Projectiles/Healing/ShinobiHealOrb.cs b/Projectiles/Healing/ShinobiHealOrb.cs index b6a6ae38ee..f1a9380519 100644 --- a/Projectiles/Healing/ShinobiHealOrb.cs +++ b/Projectiles/Healing/ShinobiHealOrb.cs @@ -25,7 +25,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], projectile.owner, 6f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], projectile.owner, 6f, 15f); for (int num468 = 0; num468 < 3; num468++) { diff --git a/Projectiles/Healing/SilvaOrb.cs b/Projectiles/Healing/SilvaOrb.cs index 0c0edd5ea3..9bece10e72 100644 --- a/Projectiles/Healing/SilvaOrb.cs +++ b/Projectiles/Healing/SilvaOrb.cs @@ -41,7 +41,7 @@ namespace CalamityMod.Projectiles.Healing } } - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 6f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 6f, 15f); return; } diff --git a/Projectiles/Healing/TerracottaProj.cs b/Projectiles/Healing/TerracottaProj.cs index 5f8df0b108..e9fdc8ca58 100644 --- a/Projectiles/Healing/TerracottaProj.cs +++ b/Projectiles/Healing/TerracottaProj.cs @@ -26,7 +26,7 @@ namespace CalamityMod.Projectiles.Healing projectile.velocity.X *= 0.95f; projectile.velocity.Y *= 0.95f; - CalamityGlobalProjectile.HealingProjectile(projectile, 9, (int)projectile.ai[0], 8f, 15f, false, 300); + projectile.HealingProjectile(9, (int)projectile.ai[0], 8f, 15f, false, 300); float num498 = projectile.velocity.X * 0.2f; float num499 = -(projectile.velocity.Y * 0.2f); int num500 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 246, 0f, 0f, 100, default, 1f); diff --git a/Projectiles/Healing/TransfusionTrail.cs b/Projectiles/Healing/TransfusionTrail.cs index e085edeb0b..cf1d9d6fbc 100644 --- a/Projectiles/Healing/TransfusionTrail.cs +++ b/Projectiles/Healing/TransfusionTrail.cs @@ -21,7 +21,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 6.5f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 6.5f, 15f); float num494 = projectile.velocity.X * 0.334f; float num495 = -(projectile.velocity.Y * 0.334f); int num496 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 183, 0f, 0f, 100, default, 0.7f); diff --git a/Projectiles/Healing/XerocHealOrb.cs b/Projectiles/Healing/XerocHealOrb.cs index f216c96e4a..c5d09d22e5 100644 --- a/Projectiles/Healing/XerocHealOrb.cs +++ b/Projectiles/Healing/XerocHealOrb.cs @@ -23,7 +23,7 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - CalamityGlobalProjectile.HealingProjectile(projectile, (int)projectile.ai[1], (int)projectile.ai[0], 5.5f, 15f); + projectile.HealingProjectile((int)projectile.ai[1], (int)projectile.ai[0], 5.5f, 15f); float num498 = projectile.velocity.X * 0.2f; float num499 = -(projectile.velocity.Y * 0.2f); int num500 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 58, 0f, 0f, 100, default, 2f); diff --git a/Projectiles/Magic/AtlantisSpear.cs b/Projectiles/Magic/AtlantisSpear.cs index 2c753aa87b..8702e8bb35 100644 --- a/Projectiles/Magic/AtlantisSpear.cs +++ b/Projectiles/Magic/AtlantisSpear.cs @@ -3,7 +3,6 @@ using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using Terraria.ID; namespace CalamityMod.Projectiles.Magic { diff --git a/Projectiles/Pets/Akato.cs b/Projectiles/Pets/Akato.cs index 226e7e542a..6aa169688e 100644 --- a/Projectiles/Pets/Akato.cs +++ b/Projectiles/Pets/Akato.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Pets { projectile.timeLeft = 2; } - CalamityGlobalProjectile.FloatingPetAI(projectile, true, 0.02f); + projectile.FloatingPetAI(true, 0.02f); projectile.frameCounter++; if (projectile.frameCounter > 6) { diff --git a/Projectiles/Pets/BabyGhostBell.cs b/Projectiles/Pets/BabyGhostBell.cs index 3159bd7951..d85eb5a67f 100644 --- a/Projectiles/Pets/BabyGhostBell.cs +++ b/Projectiles/Pets/BabyGhostBell.cs @@ -52,7 +52,7 @@ namespace CalamityMod.Projectiles.Pets { Lighting.AddLight(projectile.Center, 0.1f, 0.3f, 0.5f); } - CalamityGlobalProjectile.FloatingPetAI(projectile, false, 0.05f, true); + projectile.FloatingPetAI(false, 0.05f, true); projectile.frameCounter++; if (projectile.frameCounter > 6) { diff --git a/Projectiles/Pets/LeviPet.cs b/Projectiles/Pets/LeviPet.cs index a883f0c6b3..8a0f51d3f5 100644 --- a/Projectiles/Pets/LeviPet.cs +++ b/Projectiles/Pets/LeviPet.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Pets { projectile.timeLeft = 2; } - CalamityGlobalProjectile.FloatingPetAI(projectile, false, 0.05f); + projectile.FloatingPetAI(false, 0.05f); projectile.frameCounter++; if (projectile.frameCounter > 6) { diff --git a/Projectiles/Pets/PerforaMini.cs b/Projectiles/Pets/PerforaMini.cs index ae31133bdb..41a0dabd19 100644 --- a/Projectiles/Pets/PerforaMini.cs +++ b/Projectiles/Pets/PerforaMini.cs @@ -53,7 +53,7 @@ namespace CalamityMod.Projectiles.Pets projectile.timeLeft = 2; } - CalamityGlobalProjectile.FloatingPetAI(projectile, true, 0.1f); + projectile.FloatingPetAI(true, 0.1f); //Dust if (Main.rand.NextBool(50)) diff --git a/Projectiles/Pets/PlaguebringerBab.cs b/Projectiles/Pets/PlaguebringerBab.cs index 74cfaa9c89..09f00c3a14 100644 --- a/Projectiles/Pets/PlaguebringerBab.cs +++ b/Projectiles/Pets/PlaguebringerBab.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Pets { projectile.timeLeft = 2; } - CalamityGlobalProjectile.FloatingPetAI(projectile, false, 0.05f); + projectile.FloatingPetAI(false, 0.05f); projectile.frameCounter++; if (projectile.frameCounter > 6) { diff --git a/Projectiles/Pets/RotomPet.cs b/Projectiles/Pets/RotomPet.cs index 543ca7435f..241890e028 100644 --- a/Projectiles/Pets/RotomPet.cs +++ b/Projectiles/Pets/RotomPet.cs @@ -73,7 +73,7 @@ namespace CalamityMod.Projectiles.Pets dust += 1f; } - CalamityGlobalProjectile.FloatingPetAI(projectile, true, 0.05f); + projectile.FloatingPetAI(true, 0.05f); projectile.frameCounter++; if (projectile.frameCounter > 6) diff --git a/Projectiles/Pets/SCalPet.cs b/Projectiles/Pets/SCalPet.cs index 8fdbf5f476..20b29b0c08 100644 --- a/Projectiles/Pets/SCalPet.cs +++ b/Projectiles/Pets/SCalPet.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Pets { projectile.timeLeft = 2; } - CalamityGlobalProjectile.FloatingPetAI(projectile, false, 0.05f); + projectile.FloatingPetAI(false, 0.05f); projectile.frameCounter++; if (projectile.frameCounter > 6) { diff --git a/Projectiles/Pets/ThirdSage.cs b/Projectiles/Pets/ThirdSage.cs index 1f0df37832..af9b8a81ec 100644 --- a/Projectiles/Pets/ThirdSage.cs +++ b/Projectiles/Pets/ThirdSage.cs @@ -42,7 +42,7 @@ namespace CalamityMod.Projectiles.Pets { projectile.timeLeft = 2; } - CalamityGlobalProjectile.FloatingPetAI(projectile, true, 0.1f); + projectile.FloatingPetAI(true, 0.1f); //Animation projectile.frameCounter++; if (projectile.frameCounter > 6) diff --git a/Projectiles/Ranged/AMRShot.cs b/Projectiles/Ranged/AMRShot.cs index 04af628f94..08b817254f 100644 --- a/Projectiles/Ranged/AMRShot.cs +++ b/Projectiles/Ranged/AMRShot.cs @@ -4,7 +4,6 @@ using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using Terraria.ID; namespace CalamityMod.Projectiles.Ranged { diff --git a/Projectiles/Ranged/ImpactRound.cs b/Projectiles/Ranged/ImpactRound.cs index 72e536c9d0..c471d98944 100644 --- a/Projectiles/Ranged/ImpactRound.cs +++ b/Projectiles/Ranged/ImpactRound.cs @@ -51,19 +51,7 @@ namespace CalamityMod.Projectiles.Ranged { damageMult += 0.25; } - if (target.HitSound != SoundID.NPCHit1 && target.HitSound != SoundID.NPCHit6 && target.HitSound != SoundID.NPCHit7 && - target.HitSound != SoundID.NPCHit8 && target.HitSound != SoundID.NPCHit9 && target.HitSound != SoundID.NPCHit12 && - target.HitSound != SoundID.NPCHit13 && target.HitSound != SoundID.NPCHit14 && target.HitSound != SoundID.NPCHit18 && - target.HitSound != SoundID.NPCHit19 && target.HitSound != SoundID.NPCHit20 && target.HitSound != SoundID.NPCHit21 && - target.HitSound != SoundID.NPCHit22 && target.HitSound != SoundID.NPCHit23 && target.HitSound != SoundID.NPCHit24 && - target.HitSound != SoundID.NPCHit25 && target.HitSound != SoundID.NPCHit26 && target.HitSound != SoundID.NPCHit27 && - target.HitSound != SoundID.NPCHit28 && target.HitSound != SoundID.NPCHit29 && target.HitSound != SoundID.NPCHit31 && - target.HitSound != SoundID.NPCHit32 && target.HitSound != SoundID.NPCHit33 && target.HitSound != SoundID.NPCHit35 && - target.HitSound != SoundID.NPCHit37 && target.HitSound != SoundID.NPCHit38 && target.HitSound != SoundID.NPCHit40 && - target.HitSound != SoundID.NPCHit43 && target.HitSound != SoundID.NPCHit44 && target.HitSound != SoundID.NPCHit45 && - target.HitSound != SoundID.NPCHit46 && target.HitSound != SoundID.NPCHit47 && target.HitSound != SoundID.NPCHit48 && - target.HitSound != SoundID.NPCHit50 && target.HitSound != SoundID.NPCHit51 && target.HitSound != SoundID.NPCHit55 && - target.HitSound != SoundID.NPCHit56 && target.HitSound != SoundID.NPCHit57) + if (target.Inorganic()) { damageMult += 0.1; } diff --git a/Projectiles/Summon/ApexShark.cs b/Projectiles/Summon/ApexShark.cs index 21a06feb9d..3a062aa18b 100644 --- a/Projectiles/Summon/ApexShark.cs +++ b/Projectiles/Summon/ApexShark.cs @@ -94,31 +94,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && - flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); bool flag24 = false; if (projectile.ai[0] == 2f) { diff --git a/Projectiles/Summon/AquaticStarMinion.cs b/Projectiles/Summon/AquaticStarMinion.cs index 10eed0167d..896416b87e 100644 --- a/Projectiles/Summon/AquaticStarMinion.cs +++ b/Projectiles/Summon/AquaticStarMinion.cs @@ -64,7 +64,7 @@ namespace CalamityMod.Projectiles.Summon } projectile.rotation += projectile.velocity.X * 0.04f; - CalamityGlobalProjectile.ChargingMinionAI(projectile, 600f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, false); + projectile.ChargingMinionAI(600f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, false); } public override bool OnTileCollide(Vector2 oldVelocity) => false; diff --git a/Projectiles/Summon/AureusBomber.cs b/Projectiles/Summon/AureusBomber.cs index 13463aec45..a4be169099 100644 --- a/Projectiles/Summon/AureusBomber.cs +++ b/Projectiles/Summon/AureusBomber.cs @@ -70,32 +70,7 @@ namespace CalamityMod.Projectiles.Summon } //anti sticking movement - float SAImovement = 0.05f; - float width = (float) projectile.width; - for (int indexNPC = 0; indexNPC < Main.projectile.Length; indexNPC++) - { - Projectile proj = Main.projectile[indexNPC]; - bool myType = proj.type == ModContent.ProjectileType(); - if (indexNPC != projectile.whoAmI && proj.active && proj.owner == projectile.owner && myType && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= SAImovement; - } - else - { - projectile.velocity.X += SAImovement; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= SAImovement; - } - else - { - projectile.velocity.Y += SAImovement; - } - } - } + projectile.MinionAntiClump(); //get in a line Vector2 idlePosition = player.Center; diff --git a/Projectiles/Summon/BelladonnaSpirit.cs b/Projectiles/Summon/BelladonnaSpirit.cs index 298940e9d5..fcc0f64794 100644 --- a/Projectiles/Summon/BelladonnaSpirit.cs +++ b/Projectiles/Summon/BelladonnaSpirit.cs @@ -142,32 +142,7 @@ namespace CalamityMod.Projectiles.Summon } projectile.velocity.Y = (targetPosition.Y - projectile.Center.Y + potentialTarget.spriteDirection * 75f) / 90f; } - float SAImovement = 0.05f; - for (int index = 0; index < Main.projectile.Length; index++) - { - Projectile proj = Main.projectile[index]; - if (index != projectile.whoAmI && - proj.active && proj.owner == projectile.owner && - proj.type == projectile.type && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= SAImovement; - } - else - { - projectile.velocity.X += SAImovement; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= SAImovement; - } - else - { - projectile.velocity.Y += SAImovement; - } - } - } + projectile.MinionAntiClump(); } } } diff --git a/Projectiles/Summon/BlackHawkGlow.png b/Projectiles/Summon/BlackHawkGlow.png new file mode 100644 index 0000000000..24479cb839 Binary files /dev/null and b/Projectiles/Summon/BlackHawkGlow.png differ diff --git a/Projectiles/Summon/BlackHawkSummon.cs b/Projectiles/Summon/BlackHawkSummon.cs index 6161961044..c0974c50fd 100644 --- a/Projectiles/Summon/BlackHawkSummon.cs +++ b/Projectiles/Summon/BlackHawkSummon.cs @@ -1,6 +1,8 @@ using CalamityMod.Buffs.Summon; using CalamityMod.CalPlayer; +using CalamityMod.Projectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using Terraria; using Terraria.ID; @@ -9,8 +11,6 @@ namespace CalamityMod.Projectiles.Summon { public class BlackHawkSummon : ModProjectile { - private const float PushawayForce = 0.05f; - public override void SetStaticDefaults() { DisplayName.SetDefault("Black Hawk"); @@ -37,45 +37,52 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { + //Set namespaces Player player = Main.player[projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); + CalamityGlobalProjectile modProj = projectile.Calamity(); + + //On spawn effects if (projectile.localAI[0] == 0f) { - projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); - projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; - int num226 = 36; - for (int num227 = 0; num227 < num226; num227++) + //Set constants + modProj.spawnedPlayerMinionDamageValue = player.MinionDamage(); + modProj.spawnedPlayerMinionProjectileDamageValue = projectile.damage; + //Spawn dust + int dustAmt = 36; + for (int dustIndex = 0; dustIndex < dustAmt; dustIndex++) { - Vector2 vector6 = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.75f; - vector6 = vector6.RotatedBy((double)((float)(num227 - (num226 / 2 - 1)) * 6.28318548f / (float)num226), default) + projectile.Center; - Vector2 vector7 = vector6 - projectile.Center; - int num228 = Dust.NewDust(vector6 + vector7, 0, 0, 258, vector7.X * 1.75f, vector7.Y * 1.75f, 100, default, 1.1f); - Main.dust[num228].noGravity = true; - Main.dust[num228].velocity = vector7; + Vector2 direction = Vector2.Normalize(projectile.velocity) * new Vector2(projectile.width / 2f, projectile.height) * 0.75f; + direction = direction.RotatedBy((double)((dustIndex - (dustAmt / 2f - 1f)) * MathHelper.TwoPi / dustAmt), default) + projectile.Center; + Vector2 dustVel = direction - projectile.Center; + int fire = Dust.NewDust(direction + dustVel, 0, 0, 258, dustVel.X * 1.75f, dustVel.Y * 1.75f, 100, default, 1.1f); + Main.dust[fire].noGravity = true; + Main.dust[fire].velocity = dustVel; } projectile.localAI[0] += 1f; } - if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + + //Flexible minion damage update + if (player.MinionDamage() != modProj.spawnedPlayerMinionDamageValue) { - int damage2 = (int)((float)projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / - projectile.Calamity().spawnedPlayerMinionDamageValue * - player.MinionDamage()); + int damage2 = (int)((float)modProj.spawnedPlayerMinionProjectileDamageValue / + modProj.spawnedPlayerMinionDamageValue * player.MinionDamage()); projectile.damage = damage2; } + + //Update frames projectile.frameCounter++; if (projectile.frameCounter >= 4) { projectile.frame++; projectile.frameCounter = 0; } - if (projectile.frame >= 3) + if (projectile.frame >= Main.projFrames[projectile.type]) { projectile.frame = 0; } - float num633 = 700f; - float num634 = 1300f; - float num635 = 2600f; - float num636 = 600f; + + //Set up buff and timeLeft bool flag64 = projectile.type == ModContent.ProjectileType(); player.AddBuff(ModContent.BuffType(), 3600); if (flag64) @@ -89,171 +96,203 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - for (int k = 0; k < Main.maxProjectiles; k++) - { - Projectile otherProj = Main.projectile[k]; - // Short circuits to make the loop as fast as possible - if (!otherProj.active || otherProj.owner != projectile.owner || !otherProj.minion || k == projectile.whoAmI) - continue; - // If the other projectile is indeed a Black Hawk owned by the same player and they're too close, nudge them away. - bool isBlackHawk = otherProj.type == projectile.type; - float taxicabDist = Math.Abs(projectile.position.X - otherProj.position.X) + Math.Abs(projectile.position.Y - otherProj.position.Y); - if (isBlackHawk && taxicabDist < projectile.width) - { - if (projectile.position.X < otherProj.position.X) - projectile.velocity.X = projectile.velocity.X - PushawayForce; - else - projectile.velocity.X = projectile.velocity.X + PushawayForce; + //Anti sticky movement to prevent overlapping minions + projectile.MinionAntiClump(); - if (projectile.position.Y < otherProj.position.Y) - projectile.velocity.Y = projectile.velocity.Y - PushawayForce; - else - projectile.velocity.Y = projectile.velocity.Y + PushawayForce; - } - } - Vector2 vector46 = projectile.position; - bool flag25 = false; + float maxDistance = 700f; + Vector2 targetVec = projectile.position; + Vector2 half = new Vector2(0.5f); + bool foundTarget = false; + //If targeting something, prioritize that enemy if (player.HasMinionAttackTargetNPC) { NPC npc = Main.npc[player.MinionAttackTargetNPC]; if (npc.CanBeChasedBy(projectile, false)) { - float num646 = Vector2.Distance(npc.Center, projectile.Center); - if (!flag25 && num646 < num633) + //Adding a check on the NPC's size allows it to target big things like Providence + Vector2 sizeCheck = npc.position + npc.Size * half; + //Calculate distance between target and the projectile to know if it's too far or not + float targetDist = Vector2.Distance(npc.Center, projectile.Center); + if (!foundTarget && targetDist < maxDistance) { - vector46 = npc.Center; - flag25 = true; + maxDistance = targetDist; + targetVec = sizeCheck; + foundTarget = true; } } } else { - for (int num645 = 0; num645 < Main.maxNPCs; num645++) + for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) { - NPC nPC2 = Main.npc[num645]; - if (nPC2.CanBeChasedBy(projectile, false)) + NPC npc = Main.npc[npcIndex]; + if (npc.CanBeChasedBy(projectile, false)) { - float num646 = Vector2.Distance(nPC2.Center, projectile.Center); - if (!flag25 && num646 < num633) + Vector2 sizeCheck = npc.position + npc.Size * half; + float targetDist = Vector2.Distance(npc.Center, projectile.Center); + if (!foundTarget && targetDist < maxDistance) { - num633 = num646; - vector46 = nPC2.Center; - flag25 = true; + maxDistance = targetDist; + targetVec = sizeCheck; + foundTarget = true; } } } } - float num647 = num634; - if (flag25) + + //If too far, make the minion start returning to the player. + float separationAnxietyDist = 1300f; + if (foundTarget) { - num647 = num635; + //Max travel distance increases if targeting something + separationAnxietyDist = 2600f; } - if (Vector2.Distance(player.Center, projectile.Center) > num647) + if (Vector2.Distance(player.Center, projectile.Center) > separationAnxietyDist) { projectile.ai[0] = 1f; projectile.netUpdate = true; } - if (flag25 && projectile.ai[0] == 0f) + + //If a target is found, move toward it + if (foundTarget && projectile.ai[0] == 0f) { - Vector2 vector47 = vector46 - projectile.Center; - float num648 = vector47.Length(); - vector47.Normalize(); - if (num648 > 200f) + Vector2 vecToTarget = targetVec - projectile.Center; + float targetDist = vecToTarget.Length(); + vecToTarget.Normalize(); + //If farther than 200 pixels, move toward it + if (targetDist > 200f) { - float scaleFactor2 = 18f; //12 - vector47 *= scaleFactor2; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; + float speedMult = 18f; + vecToTarget *= speedMult; + projectile.velocity = (projectile.velocity * 40f + vecToTarget) / 41f; } + //Otherwise, back it up slowly else { - float num649 = 9f; - vector47 *= -num649; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; + float speedMult = -9f; + vecToTarget *= speedMult; + projectile.velocity = (projectile.velocity * 40f + vecToTarget) / 41f; } } + + //If not targeting something, act passively else { - bool flag26 = false; - if (!flag26) + bool returningToPlayer = false; + if (!returningToPlayer) { - flag26 = projectile.ai[0] == 1f; + returningToPlayer = projectile.ai[0] == 1f; } - float num650 = 12f; - if (flag26) + //Move faster if actively returning to the player + float speedMult = 12f; + if (returningToPlayer) { - num650 = 30f; + speedMult = 30f; } - Vector2 center2 = projectile.Center; - Vector2 vector48 = player.Center - center2 + new Vector2(0f, -120f); - float num651 = vector48.Length(); - if (num651 > 200f && num650 < 16f) + Vector2 vecToPlayer = player.Center - projectile.Center + new Vector2(0f, -120f); + float playerDist = vecToPlayer.Length(); + //Speed up if near the player + if (playerDist < 200f && speedMult < 16f) { - num650 = 16f; + speedMult = 16f; } - if (num651 < num636 && flag26) + //If close enough to the player, return to normal + if (playerDist < 600f && returningToPlayer) { projectile.ai[0] = 0f; projectile.netUpdate = true; } - if (num651 > 2000f) + //If abnormally far, teleport to the player + if (playerDist > 2000f) { projectile.position.X = player.Center.X - (float)(projectile.width / 2); projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); projectile.netUpdate = true; } - if (num651 > 70f) + //Move toward player if more than 70 pixels away + if (playerDist > 70f) { - vector48.Normalize(); - vector48 *= num650; - projectile.velocity = (projectile.velocity * 40f + vector48) / 41f; + vecToPlayer.Normalize(); + vecToPlayer *= speedMult; + projectile.velocity = (projectile.velocity * 40f + vecToPlayer) / 41f; } + //Move if still else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) { projectile.velocity.X = -0.15f; projectile.velocity.Y = -0.05f; } } - if (flag25) + + //Update rotation + if (foundTarget) { - projectile.rotation = (vector46 - projectile.Center).ToRotation() + 3.14159274f; + projectile.rotation = projectile.rotation.AngleTowards(projectile.AngleTo(targetVec) + MathHelper.Pi, 0.1f); } else { - projectile.rotation = projectile.velocity.ToRotation() + 3.14159274f; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.Pi; } + + //Increment attack cooldown if (projectile.ai[1] > 0f) { - projectile.ai[1] += (float)Main.rand.Next(1, 4); + projectile.ai[1] += Main.rand.Next(1, 4); } + //Set the minion to be ready for attack if (projectile.ai[1] > 90f) { projectile.ai[1] = 0f; projectile.netUpdate = true; } - if (projectile.ai[0] == 0f) + + //Return if on attack cooldown, has no target, or returning to the player + if (projectile.ai[0] != 0f || !foundTarget || projectile.ai[1] != 0f) + return; + + //Shoot a bullet + if (Main.myPlayer == projectile.owner) { - float scaleFactor3 = 6f; - int num658 = ModContent.ProjectileType(); - if (flag25 && projectile.ai[1] == 0f) - { - Main.PlaySound(SoundID.Item20, projectile.Center); - projectile.ai[1] += 2f; - if (Main.myPlayer == projectile.owner) - { - Vector2 value19 = vector46 - projectile.Center; - value19.Normalize(); - value19 *= scaleFactor3; - _ = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, value19.X, value19.Y, num658, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - projectile.netUpdate = true; - } - } + float projSpeed = 6f; + int projType = ModContent.ProjectileType(); + Main.PlaySound(SoundID.Item20, projectile.Center); + projectile.ai[1] += 2f; + Vector2 velocity = targetVec - projectile.Center; + velocity.Normalize(); + velocity *= projSpeed; + Projectile.NewProjectile(projectile.Center, velocity, projType, projectile.damage, projectile.knockBack, projectile.owner); + projectile.netUpdate = true; } } - public override bool CanDamage() + //Does no contact damage + public override bool CanDamage() => false; + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { + Texture2D texture = Main.projectileTexture[projectile.type]; + int frameHeight = texture.Height / Main.projFrames[projectile.type]; + int y6 = frameHeight * projectile.frame; + SpriteEffects spriteEffects = SpriteEffects.None; + if (projectile.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; + + spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture.Width, frameHeight)), projectile.GetAlpha(lightColor), projectile.rotation, new Vector2(texture.Width / 2f, frameHeight / 2f), projectile.scale, spriteEffects, 0f); return false; } + + //Pretty glowmask + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/BlackHawkGlow"); + int frameHeight = texture.Height / Main.projFrames[projectile.type]; + int y6 = frameHeight * projectile.frame; + SpriteEffects spriteEffects = SpriteEffects.None; + if (projectile.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; + + spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture.Width, frameHeight)), Color.White, projectile.rotation, new Vector2(texture.Width / 2f, frameHeight / 2f), projectile.scale, spriteEffects, 0f); + } } } diff --git a/Projectiles/Summon/BloodClotMinion.cs b/Projectiles/Summon/BloodClotMinion.cs index abdaff6b43..982d7bd55b 100644 --- a/Projectiles/Summon/BloodClotMinion.cs +++ b/Projectiles/Summon/BloodClotMinion.cs @@ -89,30 +89,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - for (int num534 = 0; num534 < Main.maxProjectiles; num534++) - { - if (num534 != projectile.whoAmI && Main.projectile[num534].active && Main.projectile[num534].owner == projectile.owner && - Main.projectile[num534].type == ModContent.ProjectileType() && - Math.Abs(projectile.position.X - Main.projectile[num534].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num534].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num534].position.X) - { - projectile.velocity.X = projectile.velocity.X - 0.05f; - } - else - { - projectile.velocity.X = projectile.velocity.X + 0.05f; - } - if (projectile.position.Y < Main.projectile[num534].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - 0.05f; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + 0.05f; - } - } - } + projectile.MinionAntiClump(); float num535 = projectile.position.X; float num536 = projectile.position.Y; float num537 = 1300f; diff --git a/Projectiles/Summon/BrimstoneElementalMinion.cs b/Projectiles/Summon/BrimstoneElementalMinion.cs index 2535a9eba8..a80580b3e7 100644 --- a/Projectiles/Summon/BrimstoneElementalMinion.cs +++ b/Projectiles/Summon/BrimstoneElementalMinion.cs @@ -102,30 +102,7 @@ namespace CalamityMod.Projectiles.Summon } float num633 = 700f; float num636 = 400f; //150 - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); Vector2 vector46 = projectile.position; bool flag25 = false; if (projectile.ai[0] != 1f) diff --git a/Projectiles/Summon/BrittleStarMinion.cs b/Projectiles/Summon/BrittleStarMinion.cs index 4b1675e06e..5e2699a5a7 100644 --- a/Projectiles/Summon/BrittleStarMinion.cs +++ b/Projectiles/Summon/BrittleStarMinion.cs @@ -64,7 +64,7 @@ namespace CalamityMod.Projectiles.Summon } projectile.rotation += projectile.velocity.X * 0.04f; - CalamityGlobalProjectile.ChargingMinionAI(projectile, 600f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, false); + projectile.ChargingMinionAI(600f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, false); } public override bool OnTileCollide(Vector2 oldVelocity) => false; diff --git a/Projectiles/Summon/CalamariMinion.cs b/Projectiles/Summon/CalamariMinion.cs index a862090b95..e7d201fed8 100644 --- a/Projectiles/Summon/CalamariMinion.cs +++ b/Projectiles/Summon/CalamariMinion.cs @@ -134,32 +134,7 @@ namespace CalamityMod.Projectiles.Summon { projectile.localAI[0] -= 1f; } - int num3; - for (int num534 = 0; num534 < Main.maxProjectiles; num534 = num3 + 1) - { - if (num534 != projectile.whoAmI && Main.projectile[num534].active && Main.projectile[num534].owner == projectile.owner && - Main.projectile[num534].type == ModContent.ProjectileType() && - Math.Abs(projectile.position.X - Main.projectile[num534].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num534].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num534].position.X) - { - projectile.velocity.X = projectile.velocity.X - 0.05f; - } - else - { - projectile.velocity.X = projectile.velocity.X + 0.05f; - } - if (projectile.position.Y < Main.projectile[num534].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - 0.05f; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + 0.05f; - } - } - num3 = num534; - } + projectile.MinionAntiClump(); Vector2 vector = projectile.position; float num10 = 3000f; //300 bool flag = false; diff --git a/Projectiles/Summon/Calamitamini.cs b/Projectiles/Summon/Calamitamini.cs index 1470c5ef20..7ac5313243 100644 --- a/Projectiles/Summon/Calamitamini.cs +++ b/Projectiles/Summon/Calamitamini.cs @@ -78,30 +78,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); bool flag24 = false; if (flag24) { diff --git a/Projectiles/Summon/Cataclymini.cs b/Projectiles/Summon/Cataclymini.cs index 176ad6c9f0..c3dfac0236 100644 --- a/Projectiles/Summon/Cataclymini.cs +++ b/Projectiles/Summon/Cataclymini.cs @@ -77,30 +77,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); bool flag24 = false; if (flag24) { diff --git a/Projectiles/Summon/Catastromini.cs b/Projectiles/Summon/Catastromini.cs index 22838ed06f..3232dff49a 100644 --- a/Projectiles/Summon/Catastromini.cs +++ b/Projectiles/Summon/Catastromini.cs @@ -86,7 +86,7 @@ namespace CalamityMod.Projectiles.Summon projectile.frame = 0; } - CalamityGlobalProjectile.ChargingMinionAI(projectile, 700f, 1100f, 2400f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, true); + projectile.ChargingMinionAI(700f, 1100f, 2400f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, true); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Summon/CausticStaffSummon.cs b/Projectiles/Summon/CausticStaffSummon.cs index 8a691e51c9..6b8c0ea620 100644 --- a/Projectiles/Summon/CausticStaffSummon.cs +++ b/Projectiles/Summon/CausticStaffSummon.cs @@ -82,22 +82,7 @@ namespace CalamityMod.Projectiles.Summon } //Anti sticky movement to prevent minions from stacking - float antiStickyFloat = 0.05f; - for (int index = 0; index < Main.maxProjectiles; ++index) - { - Projectile proj = Main.projectile[index]; - if (index != projectile.whoAmI && proj.active && (proj.owner == projectile.owner && proj.type == projectile.type) && (double) Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - projectile.velocity.X -= antiStickyFloat; - else - projectile.velocity.X += antiStickyFloat; - if (projectile.position.Y < proj.position.Y) - projectile.velocity.Y -= antiStickyFloat; - else - projectile.velocity.Y += antiStickyFloat; - } - } + projectile.MinionAntiClump(); //Set tile collision for only when trying to return to the player projectile.tileCollide = projectile.ai[0] != 1f; diff --git a/Projectiles/Summon/CloudElementalMinion.cs b/Projectiles/Summon/CloudElementalMinion.cs index d2f752e333..757990b8bf 100644 --- a/Projectiles/Summon/CloudElementalMinion.cs +++ b/Projectiles/Summon/CloudElementalMinion.cs @@ -101,7 +101,7 @@ namespace CalamityMod.Projectiles.Summon projectile.frame = 0; } - CalamityGlobalProjectile.ChargingMinionAI(projectile, 500f, 800f, 1200f, 400f, 0, 30f, 8f, -4f, 40f, 8f, false, true); + projectile.ChargingMinionAI(500f, 800f, 1200f, 400f, 0, 30f, 8f, -4f, 40f, 8f, false, true); } } } diff --git a/Projectiles/Summon/CosmicEnergySpiral.cs b/Projectiles/Summon/CosmicEnergySpiral.cs index 45717ba2b1..64fe2da558 100644 --- a/Projectiles/Summon/CosmicEnergySpiral.cs +++ b/Projectiles/Summon/CosmicEnergySpiral.cs @@ -70,30 +70,6 @@ namespace CalamityMod.Projectiles.Summon float num634 = 1600f; //800 float num635 = 2400f; //1200 float num636 = 800f; - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } projectile.rotation += projectile.velocity.X * 0.1f; Vector2 vector46 = projectile.position; bool flag25 = false; diff --git a/Projectiles/Summon/CosmicViperGlow.png b/Projectiles/Summon/CosmicViperGlow.png new file mode 100644 index 0000000000..4f35f5fc00 Binary files /dev/null and b/Projectiles/Summon/CosmicViperGlow.png differ diff --git a/Projectiles/Summon/CosmicViperSummon.cs b/Projectiles/Summon/CosmicViperSummon.cs index 9964b27bfd..48d29995ab 100644 --- a/Projectiles/Summon/CosmicViperSummon.cs +++ b/Projectiles/Summon/CosmicViperSummon.cs @@ -92,31 +92,7 @@ namespace CalamityMod.Projectiles.Summon float colorScale = (float)projectile.alpha / 255f; Lighting.AddLight((int)projectile.Center.X / 16, (int)projectile.Center.Y / 16, 1f * colorScale, 0.1f * colorScale, 1f * colorScale); - float antiStickyFloat = 0.05f; - for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) - { - Projectile proj = Main.projectile[projIndex]; - bool flag23 = proj.type == ModContent.ProjectileType(); - if (projIndex != projectile.whoAmI && proj.active && proj.owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= antiStickyFloat; - } - else - { - projectile.velocity.X += antiStickyFloat; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= antiStickyFloat; - } - else - { - projectile.velocity.Y += antiStickyFloat; - } - } - } + projectile.MinionAntiClump(); float detectRange = 700f; Vector2 targetVec = projectile.position; @@ -292,19 +268,31 @@ namespace CalamityMod.Projectiles.Summon } } - public override bool CanDamage() => false; + public override bool CanDamage() => false; - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { Texture2D texture = Main.projectileTexture[projectile.type]; - int frameHeight = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; + int frameHeight = texture.Height / Main.projFrames[projectile.type]; int y6 = frameHeight * projectile.frame; SpriteEffects spriteEffects = SpriteEffects.None; if (projectile.spriteDirection == -1) spriteEffects = SpriteEffects.FlipHorizontally; spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture.Width, frameHeight)), projectile.GetAlpha(lightColor), projectile.rotation, new Vector2(texture.Width / 2f, frameHeight / 2f), projectile.scale, spriteEffects, 0f); - return false; + return false; + } + + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = ModContent.GetTexture("CalamityMod/Projectiles/Summon/CosmicViperGlow"); + int frameHeight = texture.Height / Main.projFrames[projectile.type]; + int y6 = frameHeight * projectile.frame; + SpriteEffects spriteEffects = SpriteEffects.None; + if (projectile.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; + + spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture.Width, frameHeight)), Color.White, projectile.rotation, new Vector2(texture.Width / 2f, frameHeight / 2f), projectile.scale, spriteEffects, 0f); } } } diff --git a/Projectiles/Summon/CosmilampMinion.cs b/Projectiles/Summon/CosmilampMinion.cs index 5480dfd431..17203f10dc 100644 --- a/Projectiles/Summon/CosmilampMinion.cs +++ b/Projectiles/Summon/CosmilampMinion.cs @@ -83,32 +83,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - int num3; - for (int num534 = 0; num534 < Main.maxProjectiles; num534 = num3 + 1) - { - if (num534 != projectile.whoAmI && Main.projectile[num534].active && Main.projectile[num534].owner == projectile.owner && - Main.projectile[num534].type == ModContent.ProjectileType() && - Math.Abs(projectile.position.X - Main.projectile[num534].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num534].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num534].position.X) - { - projectile.velocity.X = projectile.velocity.X - 0.05f; - } - else - { - projectile.velocity.X = projectile.velocity.X + 0.05f; - } - if (projectile.position.Y < Main.projectile[num534].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - 0.05f; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + 0.05f; - } - } - num3 = num534; - } + projectile.MinionAntiClump(); float num535 = projectile.position.X; float num536 = projectile.position.Y; float num537 = 3000f; @@ -142,7 +117,7 @@ namespace CalamityMod.Projectiles.Summon } else { - for (int num542 = 0; num542 < Main.maxNPCs; num542 = num3 + 1) + for (int num542 = 0; num542 < Main.maxNPCs; num542++) { if (Main.npc[num542].CanBeChasedBy(projectile, false)) { @@ -157,7 +132,6 @@ namespace CalamityMod.Projectiles.Summon flag19 = true; } } - num3 = num542; } } } @@ -168,9 +142,9 @@ namespace CalamityMod.Projectiles.Summon { num546 = 18f; } - Vector2 vector42 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num547 = Main.player[projectile.owner].Center.X - vector42.X; - float num548 = Main.player[projectile.owner].Center.Y - vector42.Y - 60f; + Vector2 vector42 = projectile.Center; + float num547 = player.Center.X - vector42.X; + float num548 = player.Center.Y - vector42.Y - 60f; float num549 = (float)Math.Sqrt((double)(num547 * num547 + num548 * num548)); if (num549 < 400f && projectile.ai[0] == 1f && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) { @@ -240,7 +214,7 @@ namespace CalamityMod.Projectiles.Summon } } projectile.rotation = projectile.velocity.X * 0.05f; - if ((double)Math.Abs(projectile.velocity.X) > 0.2) + if (Math.Abs(projectile.velocity.X) > 0.2f) { projectile.spriteDirection = -projectile.direction; return; diff --git a/Projectiles/Summon/DankCreeperMinion.cs b/Projectiles/Summon/DankCreeperMinion.cs index 38f8d3d8c6..0b171bea53 100644 --- a/Projectiles/Summon/DankCreeperMinion.cs +++ b/Projectiles/Summon/DankCreeperMinion.cs @@ -75,32 +75,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - int num3; - for (int num534 = 0; num534 < Main.maxProjectiles; num534 = num3 + 1) - { - if (num534 != projectile.whoAmI && Main.projectile[num534].active && Main.projectile[num534].owner == projectile.owner && - Main.projectile[num534].type == ModContent.ProjectileType() && - Math.Abs(projectile.position.X - Main.projectile[num534].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num534].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num534].position.X) - { - projectile.velocity.X = projectile.velocity.X - 0.05f; - } - else - { - projectile.velocity.X = projectile.velocity.X + 0.05f; - } - if (projectile.position.Y < Main.projectile[num534].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - 0.05f; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + 0.05f; - } - } - num3 = num534; - } + projectile.MinionAntiClump(); float num535 = projectile.position.X; float num536 = projectile.position.Y; float num537 = 1300f; @@ -134,7 +109,7 @@ namespace CalamityMod.Projectiles.Summon } else { - for (int num542 = 0; num542 < Main.maxNPCs; num542 = num3 + 1) + for (int num542 = 0; num542 < Main.maxNPCs; num542++) { if (Main.npc[num542].CanBeChasedBy(projectile, false)) { @@ -149,7 +124,6 @@ namespace CalamityMod.Projectiles.Summon flag19 = true; } } - num3 = num542; } } } diff --git a/Projectiles/Summon/DormantBrimseekerBab.cs b/Projectiles/Summon/DormantBrimseekerBab.cs index 3ea9f935e3..ff9228c5b2 100644 --- a/Projectiles/Summon/DormantBrimseekerBab.cs +++ b/Projectiles/Summon/DormantBrimseekerBab.cs @@ -110,32 +110,7 @@ namespace CalamityMod.Projectiles.Summon projectile.frame = (projectile.localAI[1] == 1f).ToInt() * 4; } - float acceleration = 0.1f; - for (int index = 0; index < Main.projectile.Length; index++) - { - Projectile proj = Main.projectile[index]; - if (index != projectile.whoAmI && - proj.active && proj.owner == projectile.owner && - proj.type == projectile.type && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= acceleration; - } - else - { - projectile.velocity.X += acceleration; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= acceleration; - } - else - { - projectile.velocity.Y += acceleration; - } - } - } + projectile.MinionAntiClump(0.1f); if (projectile.Distance(player.Center) > 2700f) { projectile.Center = player.Center; diff --git a/Projectiles/Summon/ElementalAxeMinion.cs b/Projectiles/Summon/ElementalAxeMinion.cs index ce28882f0f..d1b0e7c858 100644 --- a/Projectiles/Summon/ElementalAxeMinion.cs +++ b/Projectiles/Summon/ElementalAxeMinion.cs @@ -70,7 +70,7 @@ namespace CalamityMod.Projectiles.Summon } projectile.rotation += 0.075f; - CalamityGlobalProjectile.ChargingMinionAI(projectile, 1600f, 1800f, 2500f, 400f, 1, 30f, 24f, -12f, 30f, 16f, true, true); + projectile.ChargingMinionAI(1600f, 1800f, 2500f, 400f, 1, 30f, 24f, -12f, 30f, 16f, true, true); } public override Color? GetAlpha(Color lightColor) diff --git a/Projectiles/Summon/EndoCooperBody.cs b/Projectiles/Summon/EndoCooperBody.cs index ba3d445edc..17e694bac3 100644 --- a/Projectiles/Summon/EndoCooperBody.cs +++ b/Projectiles/Summon/EndoCooperBody.cs @@ -110,7 +110,6 @@ namespace CalamityMod.Projectiles.Summon float longdistance = AttackMode != 2 ? 1300f : 1200f; float longestdistance = AttackMode != 2 ? 2600f : 2500f; float idledistance = AttackMode != 2 ? 600f : 400f; - float SAImovement = 0.05f; float chasespeed1 = 30f; float chasespeed2 = 18f; float firerate = 30f; @@ -140,32 +139,8 @@ namespace CalamityMod.Projectiles.Summon if (limbs.type != ModContent.ProjectileType() || !limbs.active) projectile.Kill(); - - for (int num638 = 0; num638 < Main.projectile.Length; num638++) - { - Projectile proj = Main.projectile[num638]; - bool flag23 = proj.type == ModContent.ProjectileType(); - bool limbsfind = proj.type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && proj.active && proj.owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X -= SAImovement; - } - else - { - projectile.velocity.X += SAImovement; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y -= SAImovement; - } - else - { - projectile.velocity.Y += SAImovement; - } - } - } + + projectile.MinionAntiClump(); bool flag24 = false; if (projectile.ai[0] == 2f) { diff --git a/Projectiles/Summon/FungalClumpMinion.cs b/Projectiles/Summon/FungalClumpMinion.cs index 30f30591d3..56c2114325 100644 --- a/Projectiles/Summon/FungalClumpMinion.cs +++ b/Projectiles/Summon/FungalClumpMinion.cs @@ -95,31 +95,7 @@ namespace CalamityMod.Projectiles.Summon } //Anti-sticky movement failsafe - float SAIMovement = 0.05f; - for (int i = 0; i < Main.maxProjectiles; i++) - { - Projectile proj = Main.projectile[i]; - bool typeCheck = proj.type == ModContent.ProjectileType(); - if (i != projectile.whoAmI && proj.active && proj.owner == projectile.owner && typeCheck && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < (float)projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= SAIMovement; - } - else - { - projectile.velocity.X += SAIMovement; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= SAIMovement; - } - else - { - projectile.velocity.Y += SAIMovement; - } - } - } + projectile.MinionAntiClump(); //If summoned by Amalgam, trail poisonous seawater if (Math.Abs(projectile.velocity.X) > 0.1f || Math.Abs(projectile.velocity.Y) > 0.1f) diff --git a/Projectiles/Summon/GastricBelcher.cs b/Projectiles/Summon/GastricBelcher.cs index a262d973a0..e189e999c6 100644 --- a/Projectiles/Summon/GastricBelcher.cs +++ b/Projectiles/Summon/GastricBelcher.cs @@ -104,31 +104,7 @@ namespace CalamityMod.Projectiles.Summon } //Anti sticky movement to prevent overlapping minions - float antiStickMvt = 0.05f; - for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) - { - Projectile proj = Main.projectile[projIndex]; - bool correctMinion = proj.type == ModContent.ProjectileType(); - if (projIndex != projectile.whoAmI && proj.active && proj.owner == projectile.owner && correctMinion && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= antiStickMvt; - } - else - { - projectile.velocity.X += antiStickMvt; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= antiStickMvt; - } - else - { - projectile.velocity.Y += antiStickMvt; - } - } - } + projectile.MinionAntiClump(); //Find a target float maxDistance = 700f; diff --git a/Projectiles/Summon/HerringMinion.cs b/Projectiles/Summon/HerringMinion.cs index 70170bf0da..36d87f9dba 100644 --- a/Projectiles/Summon/HerringMinion.cs +++ b/Projectiles/Summon/HerringMinion.cs @@ -93,7 +93,7 @@ namespace CalamityMod.Projectiles.Summon } } - CalamityGlobalProjectile.ChargingMinionAI(projectile, 600f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 7f, false, true); + projectile.ChargingMinionAI(600f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 7f, false, true); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Summon/HowlsHeartCalcifer.cs b/Projectiles/Summon/HowlsHeartCalcifer.cs index b1a47f7f6c..1cf16cd768 100644 --- a/Projectiles/Summon/HowlsHeartCalcifer.cs +++ b/Projectiles/Summon/HowlsHeartCalcifer.cs @@ -46,7 +46,7 @@ namespace CalamityMod.Projectiles.Summon } } Lighting.AddLight(projectile.Center, 0.75f, 0.485f, 0f); - CalamityGlobalProjectile.FloatingPetAI(projectile, false, 0.04f, true); + projectile.FloatingPetAI(false, 0.04f, true); projectile.frameCounter++; if (projectile.frameCounter > 6) { diff --git a/Projectiles/Summon/HowlsHeartHowl.cs b/Projectiles/Summon/HowlsHeartHowl.cs index 42d0372e46..caf409d2de 100644 --- a/Projectiles/Summon/HowlsHeartHowl.cs +++ b/Projectiles/Summon/HowlsHeartHowl.cs @@ -85,22 +85,6 @@ namespace CalamityMod.Projectiles.Summon } //Anti sticky movement although there should only be one - float antiStickyFloat = 0.05f; - for (int index = 0; index < Main.maxProjectiles; ++index) - { - Projectile proj = Main.projectile[index]; - if (index != projectile.whoAmI && proj.active && (proj.owner == projectile.owner && proj.type == projectile.type) && (double)Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - projectile.velocity.X -= antiStickyFloat; - else - projectile.velocity.X += antiStickyFloat; - if (projectile.position.Y < proj.position.Y) - projectile.velocity.Y -= antiStickyFloat; - else - projectile.velocity.Y += antiStickyFloat; - } - } //Set tile collision for only when trying to return to the player projectile.tileCollide = projectile.ai[0] != 1f; diff --git a/Projectiles/Summon/IceClasperMinion.cs b/Projectiles/Summon/IceClasperMinion.cs index b3b25e0066..b50e92bebc 100644 --- a/Projectiles/Summon/IceClasperMinion.cs +++ b/Projectiles/Summon/IceClasperMinion.cs @@ -89,7 +89,7 @@ namespace CalamityMod.Projectiles.Summon } } - CalamityGlobalProjectile.ChargingMinionAI(projectile, 700f, 1000f, 2200f, 150f, 0, 40f, 9f, -4f, 40f, 9f, true, true); + projectile.ChargingMinionAI(700f, 1000f, 2200f, 150f, 0, 40f, 9f, -4f, 40f, 9f, true, true); projectile.rotation = projectile.velocity.ToRotation() - 1.57f; } diff --git a/Projectiles/Summon/IceSentryShard.cs b/Projectiles/Summon/IceSentryShard.cs index 379392a9e5..7a1f1de402 100644 --- a/Projectiles/Summon/IceSentryShard.cs +++ b/Projectiles/Summon/IceSentryShard.cs @@ -22,22 +22,11 @@ namespace CalamityMod.Projectiles.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Frost Shard"); - Main.projFrames[projectile.type] = 5; ProjectileID.Sets.SentryShot[projectile.type] = true; } public override void AI() { - projectile.frameCounter++; - if (projectile.frameCounter > 4) - { - projectile.frameCounter = 0; - projectile.frame++; - } - - if (projectile.frame >= 5) - projectile.frame = 0; - projectile.velocity.Y += 0.2f; if (projectile.localAI[0] == 0f || projectile.localAI[0] == 2f) { diff --git a/Projectiles/Summon/LuxorsGiftSummon.cs b/Projectiles/Summon/LuxorsGiftSummon.cs index 24c948fd58..29066770e9 100644 --- a/Projectiles/Summon/LuxorsGiftSummon.cs +++ b/Projectiles/Summon/LuxorsGiftSummon.cs @@ -94,7 +94,7 @@ namespace CalamityMod.Projectiles.Summon } } - CalamityGlobalProjectile.ChargingMinionAI(projectile, 700f, 1000f, 2200f, 150f, 0, 40f, 9f, -4f, 40f, 9f, true, true); + projectile.ChargingMinionAI(700f, 1000f, 2200f, 150f, 0, 40f, 9f, -4f, 40f, 9f, true, true); projectile.rotation = projectile.velocity.ToRotation() + 1.57f; } diff --git a/Projectiles/Summon/MagicAxe.cs b/Projectiles/Summon/MagicAxe.cs index 89f3639975..c1c75c88fd 100644 --- a/Projectiles/Summon/MagicAxe.cs +++ b/Projectiles/Summon/MagicAxe.cs @@ -48,30 +48,7 @@ namespace CalamityMod.Projectiles.Summon projectile.alpha -= 50; float num634 = 1200f; float num635 = 2500f; - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.projectile.Length; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); if (projectile.ai[1] <= 30) { projectile.ai[1]++; diff --git a/Projectiles/Summon/MagicRifle.cs b/Projectiles/Summon/MagicRifle.cs index 28dd81754b..e59667cb4c 100644 --- a/Projectiles/Summon/MagicRifle.cs +++ b/Projectiles/Summon/MagicRifle.cs @@ -7,229 +7,230 @@ using Terraria.ModLoader; namespace CalamityMod.Projectiles.Summon { public class MagicRifle : ModProjectile - { + { private int counter = 0; private bool canHome = false; - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Rifle"); - ProjectileID.Sets.MinionShot[projectile.type] = true; - } + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Rifle"); + ProjectileID.Sets.MinionShot[projectile.type] = true; + } - public override void SetDefaults() - { - projectile.width = 30; - projectile.height = 30; - projectile.netImportant = true; - projectile.friendly = true; - projectile.ignoreWater = true; - projectile.minionSlots = 0f; - projectile.timeLeft = 180; - projectile.penetrate = -1; - projectile.tileCollide = false; - projectile.minion = true; - } + public override void SetDefaults() + { + projectile.width = 30; + projectile.height = 30; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 0f; + projectile.timeLeft = 180; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.minion = true; + } - public override void AI() - { - Player player = Main.player[projectile.owner]; - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.projectile.Length; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + public override void AI() + { + //Set player namespace + Player player = Main.player[projectile.owner]; + + //Anti sticky movement to prevent overlapping minions + projectile.MinionAntiClump(); + + //Try not to do anything at first if (counter <= 30) { counter++; canHome = true; } - float homingRange = MagicHat.Range; - float num634 = 1600f; - float num635 = 2600f; - float num636 = 600f; - Vector2 vector46 = projectile.position; - bool flag25 = false; - if (player.HasMinionAttackTargetNPC) - { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy(projectile, false) && canHome) - { - float num646 = Vector2.Distance(npc.Center, projectile.Center); - if (!flag25 && num646 < homingRange) - { - homingRange = num646; - vector46 = npc.Center; - flag25 = true; - } - } - } - else - { - for (int num645 = 0; num645 < Main.npc.Length; num645++) - { - NPC nPC2 = Main.npc[num645]; - if (nPC2.CanBeChasedBy(projectile, false) && canHome) - { - float num646 = Vector2.Distance(nPC2.Center, projectile.Center); - if (!flag25 && num646 < homingRange) - { - homingRange = num646; - vector46 = nPC2.Center; - flag25 = true; - } - } - } - } - float num647 = num634; - if (flag25) - { - num647 = num635; - } - if (Vector2.Distance(player.Center, projectile.Center) > num647) - { - projectile.ai[0] = 1f; - projectile.netUpdate = true; - } - if (flag25 && projectile.ai[0] == 0f) - { - Vector2 vector47 = vector46 - projectile.Center; - float num648 = vector47.Length(); - vector47.Normalize(); - if (num648 > 200f) - { - float scaleFactor2 = 18f; //12 - vector47 *= scaleFactor2; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; - } - else - { - float num649 = 9f; - vector47 *= -num649; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; - } - } - else - { - bool flag26 = false; - if (!flag26) - { - flag26 = projectile.ai[0] == 1f; - } - float num650 = 12f; - if (flag26) - { - num650 = 30f; - } - Vector2 center2 = projectile.Center; - Vector2 vector48 = player.Center - center2 + new Vector2(0f, -120f); - float num651 = vector48.Length(); - if (num651 > 200f && num650 < 16f) - { - num650 = 16f; - } - if (num651 < num636 && flag26) - { - projectile.ai[0] = 0f; - projectile.netUpdate = true; - } - if (num651 > 2000f) - { - projectile.position.X = player.Center.X - (float)(projectile.width / 2); - projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); - projectile.netUpdate = true; - } - if (num651 > 70f) - { - vector48.Normalize(); - vector48 *= num650; - projectile.velocity = (projectile.velocity * 40f + vector48) / 41f; - } - else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) - { - projectile.velocity.X = -0.15f; - projectile.velocity.Y = -0.05f; - } - } - if (flag25) - { - projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); - projectile.rotation = (vector46 - projectile.Center).ToRotation() + (projectile.spriteDirection == 1 ? MathHelper.ToRadians(315) : MathHelper.ToRadians(135)); - } - else - { - projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); - projectile.rotation = projectile.velocity.ToRotation() + (projectile.spriteDirection == 1 ? MathHelper.ToRadians(315) : MathHelper.ToRadians(135)); - } - if (projectile.ai[1] > 0f) - { - projectile.ai[1] += (float)Main.rand.Next(1, 4); - } - if (projectile.ai[1] > 90f) - { - projectile.ai[1] = 0f; - projectile.netUpdate = true; - } - if (projectile.ai[0] == 0f) - { - float scaleFactor3 = 6f; - int projType = ModContent.ProjectileType(); - if (flag25 && projectile.ai[1] == 0f) - { - if (Main.rand.NextBool(6)) + float homingRange = MagicHat.Range; + Vector2 targetVec = projectile.position; + Vector2 half = new Vector2(0.5f); + bool foundTarget = false; + //If targeting something, prioritize that enemy + if (player.HasMinionAttackTargetNPC) + { + NPC npc = Main.npc[player.MinionAttackTargetNPC]; + if (npc.CanBeChasedBy(projectile, false) && canHome) + { + //Adding a check on the NPC's size allows it to target big things like Providence + Vector2 sizeCheck = npc.position + npc.Size * half; + //Calculate distance between target and the projectile to know if it's too far or not + float targetDist = Vector2.Distance(npc.Center, projectile.Center); + if (!foundTarget && targetDist < homingRange) { - Main.PlaySound(SoundID.Item, (int)projectile.position.X, (int)projectile.position.Y, 20, 0.1f); + homingRange = targetDist; + targetVec = sizeCheck; + foundTarget = true; } - projectile.ai[1] += 1f; - if (Main.myPlayer == projectile.owner) - { - Vector2 value19 = vector46 - projectile.Center; - value19.Normalize(); - value19 *= scaleFactor3; - Main.PlaySound(SoundID.Item40, projectile.position); - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, value19.X, value19.Y, projType, projectile.damage, 0f, Main.myPlayer, 0f, 0f); - projectile.netUpdate = true; - } - } - } - } + } + } + else + { + for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) + { + NPC npc = Main.npc[npcIndex]; + if (npc.CanBeChasedBy(projectile, false) && canHome) + { + Vector2 sizeCheck = npc.position + npc.Size * half; + float targetDist = Vector2.Distance(npc.Center, projectile.Center); + if (!foundTarget && targetDist < homingRange) + { + homingRange = targetDist; + targetVec = sizeCheck; + foundTarget = true; + } + } + } + } - public override Color? GetAlpha(Color lightColor) - { - return new Color(148, 0, 211, projectile.alpha); - } + //If too far, make the minion start returning to the player. + float separationAnxietyDist = 1600f; + if (foundTarget) + { + //Max travel distance increases if targeting something + separationAnxietyDist = 2600f; + } + if (Vector2.Distance(player.Center, projectile.Center) > separationAnxietyDist) + { + projectile.ai[0] = 1f; + projectile.netUpdate = true; + } - public override bool CanDamage() - { - return false; - } + //If a target is found, move toward it + if (foundTarget && projectile.ai[0] == 0f) + { + Vector2 vecToTarget = targetVec - projectile.Center; + float targetDist = vecToTarget.Length(); + vecToTarget.Normalize(); + //If farther than 200 pixels, move toward it + if (targetDist > 200f) + { + float speedMult = 18f; //12 + vecToTarget *= speedMult; + projectile.velocity = (projectile.velocity * 40f + vecToTarget) / 41f; + } + //Otherwise, back it up slowly + else + { + float speedMult = -9f; + vecToTarget *= speedMult; + projectile.velocity = (projectile.velocity * 40f + vecToTarget) / 41f; + } + } - public override void Kill(int timeLeft) - { - for (int i = 0; i < 10; i++) - { - Vector2 dspeed = new Vector2(Main.rand.NextFloat(-7f, 7f), Main.rand.NextFloat(-7f, 7f)); - int dust = Dust.NewDust(projectile.Center, 1, 1, 66, dspeed.X, dspeed.Y, 160, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 0.75f); - Main.dust[dust].noGravity = true; - } - } - } + //If not targeting something, act passively + else + { + bool returningToPlayer = false; + if (!returningToPlayer) + { + returningToPlayer = projectile.ai[0] == 1f; + } + //Move faster if actively returning to the player + float speedMult = 12f; + if (returningToPlayer) + { + speedMult = 30f; + } + Vector2 vecToPlayer = player.Center - projectile.Center + new Vector2(0f, -120f); + float playerDist = vecToPlayer.Length(); + //Speed up if near the player + if (playerDist < 200f && speedMult < 16f) + { + speedMult = 16f; + } + //If close enough to the player, return to normal + if (playerDist < 600f && returningToPlayer) + { + projectile.ai[0] = 0f; + projectile.netUpdate = true; + } + //If abnormally far, teleport to the player + if (playerDist > 2000f) + { + projectile.position.X = player.Center.X - (float)(projectile.width / 2); + projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); + projectile.netUpdate = true; + } + //Move toward player if more than 70 pixels away + if (playerDist > 70f) + { + vecToPlayer.Normalize(); + vecToPlayer *= speedMult; + projectile.velocity = (projectile.velocity * 40f + vecToPlayer) / 41f; + } + //Move if still + else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) + { + projectile.velocity.X = -0.15f; + projectile.velocity.Y = -0.05f; + } + } + + //Update rotation + if (foundTarget) + { + projectile.spriteDirection = projectile.direction = ((targetVec.X - projectile.Center.X) > 0).ToDirectionInt(); + projectile.rotation = projectile.rotation.AngleTowards(projectile.AngleTo(targetVec) + (projectile.spriteDirection == 1 ? MathHelper.ToRadians(45) : MathHelper.ToRadians(135)), 0.1f); + } + else + { + projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); + projectile.rotation = projectile.velocity.ToRotation() + (projectile.spriteDirection == 1 ? MathHelper.ToRadians(45) : MathHelper.ToRadians(135)); + } + + //Increment attack cooldown + if (projectile.ai[1] > 0f) + { + projectile.ai[1] += Main.rand.Next(1, 4); + } + //Set the minion to be ready for attack + if (projectile.ai[1] > 90f) + { + projectile.ai[1] = 0f; + projectile.netUpdate = true; + } + + //Return if on attack cooldown, has no target, or returning to the player + if (projectile.ai[0] != 0f || !foundTarget || projectile.ai[1] != 0f) + return; + + //Shoot a bullet + if (Main.myPlayer == projectile.owner) + { + float projSpeed = 6f; + int projType = ModContent.ProjectileType(); + if (Main.rand.NextBool(6)) + { + Main.PlaySound(SoundID.Item, (int)projectile.position.X, (int)projectile.position.Y, 20, 0.1f); + } + projectile.ai[1] += 1f; + if (Main.myPlayer == projectile.owner) + { + Vector2 velocity = targetVec - projectile.Center; + velocity.Normalize(); + velocity *= projSpeed; + Main.PlaySound(SoundID.Item40, projectile.position); + Projectile.NewProjectile(projectile.Center, velocity, projType, projectile.damage, 0f, projectile.owner); + projectile.netUpdate = true; + } + } + } + + public override Color? GetAlpha(Color lightColor) => new Color(148, 0, 211, projectile.alpha); + + public override bool CanDamage() => false; + + public override void Kill(int timeLeft) + { + for (int i = 0; i < 10; i++) + { + Vector2 dspeed = new Vector2(Main.rand.NextFloat(-7f, 7f), Main.rand.NextFloat(-7f, 7f)); + int dust = Dust.NewDust(projectile.Center, 1, 1, 66, dspeed.X, dspeed.Y, 160, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 0.75f); + Main.dust[dust].noGravity = true; + } + } + } } diff --git a/Projectiles/Summon/MagicUmbrella.cs b/Projectiles/Summon/MagicUmbrella.cs index ed47093b0a..6ee1a99dbe 100644 --- a/Projectiles/Summon/MagicUmbrella.cs +++ b/Projectiles/Summon/MagicUmbrella.cs @@ -45,31 +45,7 @@ namespace CalamityMod.Projectiles.Summon float num634 = 1600f; float num635 = 2200f; float num636 = 150f; - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.projectile.Length; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && - flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); if (counter <= 30) { counter++; diff --git a/Projectiles/Summon/MidnightSunUFO.cs b/Projectiles/Summon/MidnightSunUFO.cs index e76c7ae6f6..e7ee1b1540 100644 --- a/Projectiles/Summon/MidnightSunUFO.cs +++ b/Projectiles/Summon/MidnightSunUFO.cs @@ -102,30 +102,7 @@ namespace CalamityMod.Projectiles.Summon ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); } - float acceleration = 0.35f; - for (int index = 0; index < Main.projectile.Length; index++) - { - Projectile proj = Main.projectile[index]; - if (index != projectile.whoAmI && proj.active && proj.owner == projectile.owner && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= acceleration; - } - else - { - projectile.velocity.X += acceleration; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= acceleration; - } - else - { - projectile.velocity.Y += acceleration; - } - } - } + projectile.MinionAntiClump(0.35f); } else { @@ -162,30 +139,7 @@ namespace CalamityMod.Projectiles.Summon { projectile.velocity = (projectile.velocity * 15f + projectile.DirectionTo(player.Center - new Vector2(player.direction * -80f, 160f)) * 19f) / 16f; - float acceleration = 0.35f; - for (int index = 0; index < Main.projectile.Length; index++) - { - Projectile proj = Main.projectile[index]; - if (index != projectile.whoAmI && proj.active && proj.owner == projectile.owner && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= acceleration; - } - else - { - projectile.velocity.X += acceleration; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= acceleration; - } - else - { - projectile.velocity.Y += acceleration; - } - } - } + projectile.MinionAntiClump(0.35f); projectile.rotation = projectile.velocity.X * 0.03f; } } diff --git a/Projectiles/Summon/MiniGuardianAttack.cs b/Projectiles/Summon/MiniGuardianAttack.cs index d1243adabb..33161fc7c2 100644 --- a/Projectiles/Summon/MiniGuardianAttack.cs +++ b/Projectiles/Summon/MiniGuardianAttack.cs @@ -285,16 +285,16 @@ namespace CalamityMod.Projectiles.Summon else AI(1, num535, num536, player); } - if ((double)projectile.velocity.X > 0.25) + if (projectile.velocity.X > 0.25f) { projectile.direction = -1; } - else if ((double)projectile.velocity.X < -0.25) + else if (projectile.velocity.X < -0.25f) { projectile.direction = 1; } - if ((double)Math.Abs(projectile.velocity.X) > 0.2) + if (Math.Abs(projectile.velocity.X) > 0.2f) { projectile.spriteDirection = -projectile.direction; } diff --git a/Projectiles/Summon/MiniGuardianDefense.cs b/Projectiles/Summon/MiniGuardianDefense.cs index 388f980c70..1adb554fc5 100644 --- a/Projectiles/Summon/MiniGuardianDefense.cs +++ b/Projectiles/Summon/MiniGuardianDefense.cs @@ -283,16 +283,16 @@ namespace CalamityMod.Projectiles.Summon else AI(1, num535, num536, player); } - if ((double)projectile.velocity.X > 0.25) + if (projectile.velocity.X > 0.25f) { projectile.direction = -1; } - else if ((double)projectile.velocity.X < -0.25) + else if (projectile.velocity.X < -0.25f) { projectile.direction = 1; } - if ((double)Math.Abs(projectile.velocity.X) > 0.2) + if (Math.Abs(projectile.velocity.X) > 0.2f) { projectile.spriteDirection = -projectile.direction; } diff --git a/Projectiles/Summon/PhantomGuy.cs b/Projectiles/Summon/PhantomGuy.cs index 9f1f5e8449..4f1247aec7 100644 --- a/Projectiles/Summon/PhantomGuy.cs +++ b/Projectiles/Summon/PhantomGuy.cs @@ -72,30 +72,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); float num633 = 3000f; float num634 = 3500f; float num635 = 4000f; diff --git a/Projectiles/Summon/PinkButterfly.cs b/Projectiles/Summon/PinkButterfly.cs index 0c3f9fca5c..7f9af97df4 100644 --- a/Projectiles/Summon/PinkButterfly.cs +++ b/Projectiles/Summon/PinkButterfly.cs @@ -92,30 +92,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); bool flag24 = false; if (flag24) { diff --git a/Projectiles/Summon/PlaguePrincess.cs b/Projectiles/Summon/PlaguePrincess.cs index da7e5be419..b8fd4170ea 100644 --- a/Projectiles/Summon/PlaguePrincess.cs +++ b/Projectiles/Summon/PlaguePrincess.cs @@ -120,47 +120,24 @@ namespace CalamityMod.Projectiles.Summon } //anti sticking movement - float antiStickFloat = 0.05f; - for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) - { - Projectile proj = Main.projectile[projIndex]; - bool projCheck = proj.type == ModContent.ProjectileType(); - if (projIndex != projectile.whoAmI && proj.active && proj.owner == projectile.owner && projCheck && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < (float)projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X = projectile.velocity.X - antiStickFloat; - } - else - { - projectile.velocity.X = projectile.velocity.X + antiStickFloat; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - antiStickFloat; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + antiStickFloat; - } - } - } + projectile.MinionAntiClump(); //anti-sticking also applies to the player + float antiStickFloat = 0.05f; if (projectile.position.X < player.position.X) { - projectile.velocity.X = projectile.velocity.X - antiStickFloat; + projectile.velocity.X -= antiStickFloat; } else { - projectile.velocity.X = projectile.velocity.X + antiStickFloat; + projectile.velocity.X += antiStickFloat; } if (projectile.position.Y < player.position.Y) { - projectile.velocity.Y = projectile.velocity.Y - antiStickFloat; + projectile.velocity.Y -= antiStickFloat; } else { - projectile.velocity.Y = projectile.velocity.Y + antiStickFloat; + projectile.velocity.Y += antiStickFloat; } bool cancelAttack = false; diff --git a/Projectiles/Summon/PlaguebringerSummon.cs b/Projectiles/Summon/PlaguebringerSummon.cs index a0ce382e93..0f5a496e48 100644 --- a/Projectiles/Summon/PlaguebringerSummon.cs +++ b/Projectiles/Summon/PlaguebringerSummon.cs @@ -82,31 +82,7 @@ namespace CalamityMod.Projectiles.Summon if (!modPlayer.plaguebringerPatronSet) projectile.Kill(); - float SAIMovement = 0.05f; - for (int i = 0; i < Main.maxProjectiles; i++) - { - Projectile proj = Main.projectile[i]; - bool minionTypeCheck = proj.type == ModContent.ProjectileType() || Main.projPet[proj.type]; - if (i != projectile.whoAmI && proj.active && proj.owner == projectile.owner && minionTypeCheck && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= SAIMovement; - } - else - { - projectile.velocity.X += SAIMovement; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= SAIMovement; - } - else - { - projectile.velocity.Y += SAIMovement; - } - } - } + projectile.MinionAntiClump(); int buffType = ModContent.BuffType(); float range = auraRange; diff --git a/Projectiles/Summon/PlantSummon.cs b/Projectiles/Summon/PlantSummon.cs index 0a541b502b..6c790344dc 100644 --- a/Projectiles/Summon/PlantSummon.cs +++ b/Projectiles/Summon/PlantSummon.cs @@ -119,32 +119,9 @@ namespace CalamityMod.Projectiles.Summon float num634 = 1300f; float num635 = 2600f; float num636 = 600f; - float num637 = 0.05f; //idle movement - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); if (!enraged) { diff --git a/Projectiles/Summon/PurpleButterfly.cs b/Projectiles/Summon/PurpleButterfly.cs index d185e45d2a..0927822a9d 100644 --- a/Projectiles/Summon/PurpleButterfly.cs +++ b/Projectiles/Summon/PurpleButterfly.cs @@ -8,281 +8,104 @@ using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Summon { - public class PurpleButterfly : ModProjectile - { - public int dust = 3; + public class PurpleButterfly : ModProjectile + { + public int dust = 3; - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Purple Butterfly"); - Main.projFrames[projectile.type] = 4; - ProjectileID.Sets.MinionSacrificable[projectile.type] = true; - ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; - } + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Purple Butterfly"); + Main.projFrames[projectile.type] = 4; + ProjectileID.Sets.MinionSacrificable[projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; + } - public override void SetDefaults() - { - projectile.width = 30; - projectile.height = 30; - projectile.netImportant = true; - projectile.friendly = true; - projectile.ignoreWater = true; - projectile.minionSlots = 1f; - projectile.timeLeft = 18000; - projectile.penetrate = -1; - projectile.tileCollide = false; - projectile.timeLeft *= 5; - projectile.minion = true; - } + public override void SetDefaults() + { + projectile.width = 30; + projectile.height = 30; + projectile.netImportant = true; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.minionSlots = 1f; + projectile.timeLeft = 18000; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.timeLeft *= 5; + projectile.minion = true; + } - public override void AI() - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - if (dust > 0) - { - projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); - projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; - int num226 = 36; - for (int num227 = 0; num227 < num226; num227++) - { - Vector2 vector6 = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.5f; - vector6 = vector6.RotatedBy((double)((float)(num227 - (num226 / 2 - 1)) * 6.28318548f / (float)num226), default) + projectile.Center; - Vector2 vector7 = vector6 - projectile.Center; - int num228 = Dust.NewDust(vector6 + vector7, 0, 0, 173, vector7.X, vector7.Y, 100, default, 1.8f); - Main.dust[num228].noGravity = true; - } - dust--; - } - if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) - { - int damage2 = (int)((float)projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / - projectile.Calamity().spawnedPlayerMinionDamageValue * - player.MinionDamage()); - projectile.damage = damage2; - } - if ((double)Math.Abs(projectile.velocity.X) > 0.2) - { - projectile.spriteDirection = -projectile.direction; - } - projectile.rotation = projectile.velocity.X * 0.02f; - projectile.frameCounter++; - if (projectile.frameCounter > 6) - { - projectile.frame++; - projectile.frameCounter = 0; - } - if (projectile.frame > 3) - { - projectile.frame = 0; - } - Lighting.AddLight(projectile.Center, 0.3f, 0f, 0.5f); - float num633 = 1200f; - float num634 = 1500f; - float num635 = 2400f; - float num636 = 150f; - bool flag64 = projectile.type == ModContent.ProjectileType(); - player.AddBuff(ModContent.BuffType(), 3600); - if (flag64) - { - if (player.dead) - { - modPlayer.resButterfly = false; - } - if (modPlayer.resButterfly) - { - projectile.timeLeft = 2; - } - } - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && - flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } - bool flag24 = false; - if (projectile.ai[0] == 2f) - { - projectile.ai[1] += 1f; - projectile.extraUpdates = 1; - if (projectile.ai[1] > 30f) - { - projectile.ai[1] = 1f; - projectile.ai[0] = 0f; - projectile.extraUpdates = 0; - projectile.numUpdates = 0; - projectile.netUpdate = true; - } - else - { - flag24 = true; - } - } - if (flag24) - { - return; - } - Vector2 vector46 = projectile.position; - bool flag25 = false; - if (player.HasMinionAttackTargetNPC) - { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if ((npc.CanBeChasedBy(projectile, false) || npc.type == NPCID.DukeFishron) && npc.active) - { - float num646 = Vector2.Distance(npc.Center, projectile.Center); - if (!flag25 && num646 < num633) - { - num633 = num646; - vector46 = npc.Center; - flag25 = true; - } - } - } - else - { - for (int num645 = 0; num645 < Main.maxNPCs; num645++) - { - NPC nPC2 = Main.npc[num645]; - if ((nPC2.CanBeChasedBy(projectile, false) || nPC2.type == NPCID.DukeFishron) && nPC2.active) - { - float num646 = Vector2.Distance(nPC2.Center, projectile.Center); - if (!flag25 && num646 < num633) - { - num633 = num646; - vector46 = nPC2.Center; - flag25 = true; - } - } - } - } - float num647 = num634; - if (flag25) - { - num647 = num635; - } - if (Vector2.Distance(player.Center, projectile.Center) > num647) - { - projectile.ai[0] = 1f; - projectile.netUpdate = true; - } - if (flag25 && projectile.ai[0] == 0f) - { - Vector2 vector47 = vector46 - projectile.Center; - float num648 = vector47.Length(); - vector47.Normalize(); - if (num648 > 200f) - { - float scaleFactor2 = 18f; - vector47 *= scaleFactor2; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; - } - else - { - float num649 = 9f; - vector47 *= -num649; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; - } - } - else - { - bool flag26 = false; - if (!flag26) - { - flag26 = projectile.ai[0] == 1f; - } - float num650 = 10f; - if (flag26) - { - num650 = 24f; - } - Vector2 center2 = projectile.Center; - Vector2 vector48 = player.Center - center2 + new Vector2(40f, -40f); - float num651 = vector48.Length(); - if (num651 > 200f && num650 < 12f) - { - num650 = 12f; - } - if (num651 < num636 && flag26 && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) - { - projectile.ai[0] = 0f; - projectile.netUpdate = true; - } - if (num651 > 2000f) - { - projectile.position.X = player.Center.X - (float)(projectile.width / 2); - projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); - projectile.netUpdate = true; - } - if (num651 > 70f) - { - vector48.Normalize(); - vector48 *= num650; - projectile.velocity = (projectile.velocity * 40f + vector48) / 41f; - } - else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) - { - projectile.velocity.X = -0.15f; - projectile.velocity.Y = -0.05f; - } - } - if (projectile.ai[1] > 0f) - { - projectile.ai[1] += (float)Main.rand.Next(1, 3); - } - if (projectile.ai[1] > 30f) - { - projectile.ai[1] = 0f; - projectile.netUpdate = true; - } - if (projectile.ai[0] == 0f) - { - if (projectile.ai[1] == 0f && flag25 && num633 < 300f) - { - projectile.ai[1] += 1f; - if (Main.myPlayer == projectile.owner) - { - projectile.ai[0] = 2f; - Vector2 value20 = vector46 - projectile.Center; - value20.Normalize(); - projectile.velocity = value20 * 12f; - projectile.netUpdate = true; - } - } - } - } + public override void AI() + { + Player player = Main.player[projectile.owner]; + CalamityPlayer modPlayer = player.Calamity(); + if (dust > 0) + { + projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage(); + projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage; + int num226 = 36; + for (int num227 = 0; num227 < num226; num227++) + { + Vector2 vector6 = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.5f; + vector6 = vector6.RotatedBy((double)((float)(num227 - (num226 / 2 - 1)) * 6.28318548f / (float)num226), default) + projectile.Center; + Vector2 vector7 = vector6 - projectile.Center; + int num228 = Dust.NewDust(vector6 + vector7, 0, 0, 173, vector7.X, vector7.Y, 100, default, 1.8f); + Main.dust[num228].noGravity = true; + } + dust--; + } + if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue) + { + int damage2 = (int)((float)projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / + projectile.Calamity().spawnedPlayerMinionDamageValue * + player.MinionDamage()); + projectile.damage = damage2; + } + if (Math.Abs(projectile.velocity.X) > 0.2f) + { + projectile.spriteDirection = -projectile.direction; + } + projectile.rotation = projectile.velocity.X * 0.02f; + projectile.frameCounter++; + if (projectile.frameCounter > 6) + { + projectile.frame++; + projectile.frameCounter = 0; + } + if (projectile.frame > 3) + { + projectile.frame = 0; + } + Lighting.AddLight(projectile.Center, 0.3f, 0f, 0.5f); + projectile.ChargingMinionAI(1200f, 1500f, 2400f, 150f, 0, 30f, 18f, -9f, 30f, 12f, true, true); + bool flag64 = projectile.type == ModContent.ProjectileType(); + player.AddBuff(ModContent.BuffType(), 3600); + if (flag64) + { + if (player.dead) + { + modPlayer.resButterfly = false; + } + if (modPlayer.resButterfly) + { + projectile.timeLeft = 2; + } + } + } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - SpriteEffects spriteEffects = projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; - Texture2D texture2D13 = Main.projectileTexture[projectile.type]; - int num214 = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; - int y6 = num214 * 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, num214)), projectile.GetAlpha(lightColor), projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), projectile.scale, spriteEffects, 0f); - return false; - } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + SpriteEffects spriteEffects = projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + Texture2D texture2D13 = Main.projectileTexture[projectile.type]; + int num214 = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; + int y6 = num214 * 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, num214)), projectile.GetAlpha(lightColor), projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), projectile.scale, spriteEffects, 0f); + return false; + } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.immune[projectile.owner] = 6; - } - } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.immune[projectile.owner] = 6; + } + } } diff --git a/Projectiles/Summon/SandElementalHealer.cs b/Projectiles/Summon/SandElementalHealer.cs index da82cdfa6e..ffa5c68efd 100644 --- a/Projectiles/Summon/SandElementalHealer.cs +++ b/Projectiles/Summon/SandElementalHealer.cs @@ -101,30 +101,7 @@ namespace CalamityMod.Projectiles.Summon float num = (float)Main.rand.Next(90, 111) * 0.01f; num *= Main.essScale; Lighting.AddLight(projectile.Center, 0.7f * num, 0.6f * num, 0f * num); - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); if (Vector2.Distance(player.Center, projectile.Center) > 400f) { projectile.ai[0] = 1f; diff --git a/Projectiles/Summon/SandElementalMinion.cs b/Projectiles/Summon/SandElementalMinion.cs index b7237d3873..2f60590d2d 100644 --- a/Projectiles/Summon/SandElementalMinion.cs +++ b/Projectiles/Summon/SandElementalMinion.cs @@ -93,30 +93,7 @@ namespace CalamityMod.Projectiles.Summon float num = (float)Main.rand.Next(90, 111) * 0.01f; num *= Main.essScale; Lighting.AddLight(projectile.Center, 0.7f * num, 0.6f * num, 0f * num); - float num637 = 0.05f; - for (int num638 = 0; num638 < Main.maxProjectiles; num638++) - { - bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType(); - if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width) - { - if (projectile.position.X < Main.projectile[num638].position.X) - { - projectile.velocity.X = projectile.velocity.X - num637; - } - else - { - projectile.velocity.X = projectile.velocity.X + num637; - } - if (projectile.position.Y < Main.projectile[num638].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num637; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num637; - } - } - } + projectile.MinionAntiClump(); Vector2 vector46 = projectile.position; bool flag25 = false; if (projectile.ai[0] != 1f) diff --git a/Projectiles/Summon/SandnadoMinion.cs b/Projectiles/Summon/SandnadoMinion.cs index 97a1517504..26dae11135 100644 --- a/Projectiles/Summon/SandnadoMinion.cs +++ b/Projectiles/Summon/SandnadoMinion.cs @@ -77,31 +77,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - float num8 = 0.1f; - float num9 = (float)projectile.width * 2f; - for (int j = 0; j < Main.maxProjectiles; j++) - { - if (j != projectile.whoAmI && Main.projectile[j].active && Main.projectile[j].owner == projectile.owner && Main.projectile[j].type == projectile.type && - Math.Abs(projectile.position.X - Main.projectile[j].position.X) + Math.Abs(projectile.position.Y - Main.projectile[j].position.Y) < num9) - { - if (projectile.position.X < Main.projectile[j].position.X) - { - projectile.velocity.X = projectile.velocity.X - num8; - } - else - { - projectile.velocity.X = projectile.velocity.X + num8; - } - if (projectile.position.Y < Main.projectile[j].position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - num8; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + num8; - } - } - } + projectile.MinionAntiClump(0.1f); Vector2 vector = projectile.position; float num10 = 900f; bool flag = false; diff --git a/Projectiles/Summon/SonOfYharon.cs b/Projectiles/Summon/SonOfYharon.cs index 09870b4627..4a2c8758ab 100644 --- a/Projectiles/Summon/SonOfYharon.cs +++ b/Projectiles/Summon/SonOfYharon.cs @@ -107,7 +107,7 @@ namespace CalamityMod.Projectiles.Summon } } - CalamityGlobalProjectile.ChargingMinionAI(projectile, 1000f, 2000f, 3000f, 500f, 1, 30f, 8f, -4f, 40f, 8f, true, true); + projectile.ChargingMinionAI(1000f, 2000f, 3000f, 500f, 1, 30f, 8f, -4f, 40f, 8f, true, true); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Summon/TacticalPlagueEngineSummon.cs b/Projectiles/Summon/TacticalPlagueEngineSummon.cs index d462974ff6..253acc9c81 100644 --- a/Projectiles/Summon/TacticalPlagueEngineSummon.cs +++ b/Projectiles/Summon/TacticalPlagueEngineSummon.cs @@ -168,32 +168,7 @@ namespace CalamityMod.Projectiles.Summon } } } - float SAImovement = 0.25f; - for (int index = 0; index < Main.projectile.Length; index++) - { - Projectile proj = Main.projectile[index]; - if (index != projectile.whoAmI && - proj.active && proj.owner == projectile.owner && - proj.type == projectile.type && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X -= SAImovement; - } - else - { - projectile.velocity.X += SAImovement; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y -= SAImovement; - } - else - { - projectile.velocity.Y += SAImovement; - } - } - } + projectile.MinionAntiClump(0.25f); } } diff --git a/Projectiles/Summon/Valkyrie.cs b/Projectiles/Summon/Valkyrie.cs index 3260742985..0c492c0bc0 100644 --- a/Projectiles/Summon/Valkyrie.cs +++ b/Projectiles/Summon/Valkyrie.cs @@ -83,7 +83,7 @@ namespace CalamityMod.Projectiles.Summon projectile.spriteDirection = -projectile.direction; } - CalamityGlobalProjectile.ChargingMinionAI(projectile, 700f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, true); + projectile.ChargingMinionAI(700f, 800f, 1200f, 150f, 0, 40f, 8f, -4f, 40f, 8f, false, true); //Give off some light float lightScalar = (float)Main.rand.Next(90, 111) * 0.01f; diff --git a/Projectiles/Summon/VileFeederSummon.cs b/Projectiles/Summon/VileFeederSummon.cs index 57d908f2f7..f226988dca 100644 --- a/Projectiles/Summon/VileFeederSummon.cs +++ b/Projectiles/Summon/VileFeederSummon.cs @@ -90,31 +90,7 @@ namespace CalamityMod.Projectiles.Summon player.MinionDamage()); projectile.damage = damage2; } - float antiStickyFloat = 0.05f; - for (int index = 0; index < Main.maxProjectiles; index++) - { - Projectile proj = Main.projectile[index]; - bool flag23 = proj.type == ModContent.ProjectileType(); - if (index != projectile.whoAmI && proj.active && proj.owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - proj.position.X) + Math.Abs(projectile.position.Y - proj.position.Y) < (float)projectile.width) - { - if (projectile.position.X < proj.position.X) - { - projectile.velocity.X = projectile.velocity.X - antiStickyFloat; - } - else - { - projectile.velocity.X = projectile.velocity.X + antiStickyFloat; - } - if (projectile.position.Y < proj.position.Y) - { - projectile.velocity.Y = projectile.velocity.Y - antiStickyFloat; - } - else - { - projectile.velocity.Y = projectile.velocity.Y + antiStickyFloat; - } - } - } + projectile.MinionAntiClump(); projectile.frameCounter++; if (projectile.frameCounter > 3) { diff --git a/Projectiles/Summon/WulfrumDroid.cs b/Projectiles/Summon/WulfrumDroid.cs index 8e27dc9cfc..cbc19cb5d6 100644 --- a/Projectiles/Summon/WulfrumDroid.cs +++ b/Projectiles/Summon/WulfrumDroid.cs @@ -87,22 +87,7 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } - float num6 = 0.05f; - float width = (float) projectile.width; - for (int index = 0; index < Main.maxProjectiles; ++index) - { - if (index != projectile.whoAmI && Main.projectile[index].active && (Main.projectile[index].owner == projectile.owner && Main.projectile[index].type == projectile.type) && (double) Math.Abs(projectile.position.X - Main.projectile[index].position.X) + (double) Math.Abs(projectile.position.Y - Main.projectile[index].position.Y) < (double) width) - { - if ((double) projectile.position.X < (double) Main.projectile[index].position.X) - projectile.velocity.X -= num6; - else - projectile.velocity.X += num6; - if ((double) projectile.position.Y < (double) Main.projectile[index].position.Y) - projectile.velocity.Y -= num6; - else - projectile.velocity.Y += num6; - } - } + projectile.MinionAntiClump(); Vector2 vector2_3 = projectile.position; float num7 = 450f; bool flag = false; diff --git a/Projectiles/Typeless/FiniteUse/GrenadeRound.cs b/Projectiles/Typeless/FiniteUse/GrenadeRound.cs index 4c7eb86114..a4c1a88fbf 100644 --- a/Projectiles/Typeless/FiniteUse/GrenadeRound.cs +++ b/Projectiles/Typeless/FiniteUse/GrenadeRound.cs @@ -61,19 +61,7 @@ namespace CalamityMod.Projectiles.Typeless.FiniteUse public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) { - if (target.HitSound != SoundID.NPCHit1 && target.HitSound != SoundID.NPCHit6 && target.HitSound != SoundID.NPCHit7 && - target.HitSound != SoundID.NPCHit8 && target.HitSound != SoundID.NPCHit9 && target.HitSound != SoundID.NPCHit12 && - target.HitSound != SoundID.NPCHit13 && target.HitSound != SoundID.NPCHit14 && target.HitSound != SoundID.NPCHit18 && - target.HitSound != SoundID.NPCHit19 && target.HitSound != SoundID.NPCHit20 && target.HitSound != SoundID.NPCHit21 && - target.HitSound != SoundID.NPCHit22 && target.HitSound != SoundID.NPCHit23 && target.HitSound != SoundID.NPCHit24 && - target.HitSound != SoundID.NPCHit25 && target.HitSound != SoundID.NPCHit26 && target.HitSound != SoundID.NPCHit27 && - target.HitSound != SoundID.NPCHit28 && target.HitSound != SoundID.NPCHit29 && target.HitSound != SoundID.NPCHit31 && - target.HitSound != SoundID.NPCHit32 && target.HitSound != SoundID.NPCHit33 && target.HitSound != SoundID.NPCHit35 && - target.HitSound != SoundID.NPCHit37 && target.HitSound != SoundID.NPCHit38 && target.HitSound != SoundID.NPCHit40 && - target.HitSound != SoundID.NPCHit43 && target.HitSound != SoundID.NPCHit44 && target.HitSound != SoundID.NPCHit45 && - target.HitSound != SoundID.NPCHit46 && target.HitSound != SoundID.NPCHit47 && target.HitSound != SoundID.NPCHit48 && - target.HitSound != SoundID.NPCHit50 && target.HitSound != SoundID.NPCHit51 && target.HitSound != SoundID.NPCHit55 && - target.HitSound != SoundID.NPCHit56 && target.HitSound != SoundID.NPCHit57) + if (target.Inorganic()) { damage += target.lifeMax / 20; //500 + 200 = 700 + (100000 / 20 = 5000) = 5700 * 2 (explosion) = 11400 = 11.4% of boss HP } diff --git a/Projectiles/Typeless/FiniteUse/MagnumRound.cs b/Projectiles/Typeless/FiniteUse/MagnumRound.cs index bedca6384a..42422f79ae 100644 --- a/Projectiles/Typeless/FiniteUse/MagnumRound.cs +++ b/Projectiles/Typeless/FiniteUse/MagnumRound.cs @@ -1,6 +1,4 @@ using CalamityMod.CalPlayer; -using CalamityMod.NPCs.NormalNPCs; -using CalamityMod.NPCs.Providence; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -31,12 +29,7 @@ namespace CalamityMod.Projectiles.Typeless.FiniteUse public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) { - if ((target.HitSound != SoundID.NPCHit4 && target.HitSound != SoundID.NPCHit41 && target.HitSound != SoundID.NPCHit2 && - target.HitSound != SoundID.NPCHit5 && target.HitSound != SoundID.NPCHit11 && target.HitSound != SoundID.NPCHit30 && - target.HitSound != SoundID.NPCHit34 && target.HitSound != SoundID.NPCHit36 && target.HitSound != SoundID.NPCHit42 && - target.HitSound != SoundID.NPCHit49 && target.HitSound != SoundID.NPCHit52 && target.HitSound != SoundID.NPCHit53 && - target.HitSound != SoundID.NPCHit54 && target.HitSound != null) || target.type == ModContent.NPCType() || - target.type == ModContent.NPCType() || target.type == ModContent.NPCType()) + if (target.Organic()) { damage += target.lifeMax / 25; //400 + 80 = 480 + (100000 / 25 = 4000) = 4480, if crit = 5600 = 5.6% of boss HP } diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 6d0668e0c0..0a4d0b339c 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -2,7 +2,10 @@ using CalamityMod.CalPlayer; using CalamityMod.Items; using CalamityMod.Items.Tools.ClimateChange; using CalamityMod.NPCs; +using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.Providence; using CalamityMod.Projectiles; +using CalamityMod.Projectiles.Summon; using CalamityMod.Tiles; using CalamityMod.Tiles.Abyss; using CalamityMod.Tiles.Astral; @@ -239,6 +242,52 @@ namespace CalamityMod damage = 0D; return true; } + + /// + /// Check if an NPC is organic + /// + /// The NPC attacked. + /// Whether or not the NPC is organic. + public static bool Organic(this NPC target) + { + if ((target.HitSound != SoundID.NPCHit4 && target.HitSound != SoundID.NPCHit41 && target.HitSound != SoundID.NPCHit2 && + target.HitSound != SoundID.NPCHit5 && target.HitSound != SoundID.NPCHit11 && target.HitSound != SoundID.NPCHit30 && + target.HitSound != SoundID.NPCHit34 && target.HitSound != SoundID.NPCHit36 && target.HitSound != SoundID.NPCHit42 && + target.HitSound != SoundID.NPCHit49 && target.HitSound != SoundID.NPCHit52 && target.HitSound != SoundID.NPCHit53 && + target.HitSound != SoundID.NPCHit54 && target.HitSound != null) || target.type == ModContent.NPCType() || + target.type == ModContent.NPCType()) + { + return true; + } + return false; + } + + /// + /// Check if an NPC is inorganic + /// + /// The NPC attacked. + /// Whether or not the NPC is inorganic. + public static bool Inorganic(this NPC target) + { + if (target.HitSound != SoundID.NPCHit1 && target.HitSound != SoundID.NPCHit6 && target.HitSound != SoundID.NPCHit7 && + target.HitSound != SoundID.NPCHit8 && target.HitSound != SoundID.NPCHit9 && target.HitSound != SoundID.NPCHit12 && + target.HitSound != SoundID.NPCHit13 && target.HitSound != SoundID.NPCHit14 && target.HitSound != SoundID.NPCHit18 && + target.HitSound != SoundID.NPCHit19 && target.HitSound != SoundID.NPCHit20 && target.HitSound != SoundID.NPCHit21 && + target.HitSound != SoundID.NPCHit22 && target.HitSound != SoundID.NPCHit23 && target.HitSound != SoundID.NPCHit24 && + target.HitSound != SoundID.NPCHit25 && target.HitSound != SoundID.NPCHit26 && target.HitSound != SoundID.NPCHit27 && + target.HitSound != SoundID.NPCHit28 && target.HitSound != SoundID.NPCHit29 && target.HitSound != SoundID.NPCHit31 && + target.HitSound != SoundID.NPCHit32 && target.HitSound != SoundID.NPCHit33 && target.HitSound != SoundID.NPCHit35 && + target.HitSound != SoundID.NPCHit37 && target.HitSound != SoundID.NPCHit38 && target.HitSound != SoundID.NPCHit40 && + target.HitSound != SoundID.NPCHit43 && target.HitSound != SoundID.NPCHit44 && target.HitSound != SoundID.NPCHit45 && + target.HitSound != SoundID.NPCHit46 && target.HitSound != SoundID.NPCHit47 && target.HitSound != SoundID.NPCHit48 && + target.HitSound != SoundID.NPCHit50 && target.HitSound != SoundID.NPCHit51 && target.HitSound != SoundID.NPCHit55 && + target.HitSound != SoundID.NPCHit56 && target.HitSound != SoundID.NPCHit57 && target.type != ModContent.NPCType() && + target.type != ModContent.NPCType() && target.type != ModContent.NPCType()) + { + return true; + } + return false; + } #endregion #region Item Utilities @@ -676,6 +725,414 @@ namespace CalamityMod } return newDamage; } + + public static void MinionAntiClump(this Projectile projectile, float pushForce = 0.05f) + { + for (int k = 0; k < Main.maxProjectiles; k++) + { + Projectile otherProj = Main.projectile[k]; + // Short circuits to make the loop as fast as possible + if (!otherProj.active || otherProj.owner != projectile.owner || !otherProj.minion || k == projectile.whoAmI) + continue; + + // If the other projectile is indeed the same owned by the same player and they're too close, nudge them away. + bool sameProjType = otherProj.type == projectile.type; + float taxicabDist = Math.Abs(projectile.position.X - otherProj.position.X) + Math.Abs(projectile.position.Y - otherProj.position.Y); + if (sameProjType && taxicabDist < projectile.width) + { + if (projectile.position.X < otherProj.position.X) + projectile.velocity.X -= pushForce; + else + projectile.velocity.X += pushForce; + + if (projectile.position.Y < otherProj.position.Y) + projectile.velocity.Y -= pushForce; + else + projectile.velocity.Y += pushForce; + } + } + } + + public static void ChargingMinionAI(this Projectile projectile, float range, float maxPlayerDist, float extraMaxPlayerDist, float safeDist, int initialUpdates, float chargeDelayTime, float goToSpeed, float goBackSpeed, float chargeCounterMax, float chargeSpeed, bool tileVision, bool ignoreTilesWhenCharging) + { + Player player = Main.player[projectile.owner]; + CalamityPlayer modPlayer = player.Calamity(); + + //Anti sticky movement to prevent stacking + projectile.MinionAntiClump(); + + //Breather time between charges as like a reset + bool chargeDelay = false; + if (projectile.ai[0] == 2f) + { + projectile.ai[1] += 1f; + projectile.extraUpdates = initialUpdates + (projectile.type == ModContent.ProjectileType() ? 2 : 1); + if (projectile.ai[1] > chargeDelayTime) + { + projectile.ai[1] = 1f; + projectile.ai[0] = 0f; + projectile.extraUpdates = initialUpdates; + projectile.numUpdates = 0; + projectile.netUpdate = true; + } + else + { + chargeDelay = true; + } + } + if (chargeDelay) + { + return; + } + + //Find a target + float maxDist = range; + Vector2 targetVec = projectile.position; + bool foundTarget = false; + Vector2 half = new Vector2(0.5f); + bool isButterfly = projectile.type == ModContent.ProjectileType(); + //Prioritize the targeted enemy if possible + if (player.HasMinionAttackTargetNPC) + { + NPC npc = Main.npc[player.MinionAttackTargetNPC]; + bool fishronCheck = npc.type == NPCID.DukeFishron && npc.active && isButterfly; + if (npc.CanBeChasedBy(projectile, false) || fishronCheck) + { + //Check the size of the target to make it easier to hit fat targets like Levi + Vector2 sizeCheck = npc.position + npc.Size * half; + float targetDist = Vector2.Distance(npc.Center, projectile.Center); + //Some minions will ignore tiles when choosing a target like Ice Claspers, others will not + bool canHit = true; + if (!tileVision) + canHit = Collision.CanHitLine(projectile.position, projectile.width, projectile.height, npc.position, npc.width, npc.height); + if (!foundTarget && targetDist < maxDist && canHit) + { + maxDist = targetDist; + targetVec = sizeCheck; + foundTarget = true; + } + } + } + //If no npc is specifically targetted, check through the entire array + else + { + for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) + { + NPC npc = Main.npc[npcIndex]; + bool fishronCheck = npc.type == NPCID.DukeFishron && npc.active && isButterfly; + if (npc.CanBeChasedBy(projectile, false) || fishronCheck) + { + Vector2 sizeCheck = npc.position + npc.Size * half; + float targetDist = Vector2.Distance(npc.Center, projectile.Center); + bool canHit = true; + if (!tileVision) + canHit = Collision.CanHitLine(projectile.position, projectile.width, projectile.height, npc.position, npc.width, npc.height); + if (!foundTarget && targetDist < maxDist && canHit) + { + maxDist = targetDist; + targetVec = sizeCheck; + foundTarget = true; + } + } + } + } + + //If the player is too far, return to the player. Range is increased while attacking something. + float distBeforeForcedReturn = maxPlayerDist; + if (foundTarget) + { + distBeforeForcedReturn = extraMaxPlayerDist; + } + if (Vector2.Distance(player.Center, projectile.Center) > distBeforeForcedReturn) + { + projectile.ai[0] = 1f; + projectile.netUpdate = true; + } + + //Go to the target if you found one + if (foundTarget && projectile.ai[0] == 0f) + { + //Some minions don't ignore tiles while charging like brittle stars + projectile.tileCollide = !ignoreTilesWhenCharging; + Vector2 targetSpot = targetVec - projectile.Center; + float targetDist = targetSpot.Length(); + targetSpot.Normalize(); + //Tries to get the minion in the sweet spot of 200 pixels away but the minion also charges so idk what good it does + if (targetDist > 200f) + { + float speed = goToSpeed; //8 + targetSpot *= speed; + projectile.velocity = (projectile.velocity * 40f + targetSpot) / 41f; + } + else + { + float speed = -goBackSpeed; //-4 + targetSpot *= speed; + projectile.velocity = (projectile.velocity * 40f + targetSpot) / 41f; //41 + } + } + + //Movement for idle or returning to the player + else + { + //Ignore tiles so they don't get stuck everywhere like Optic Staff + projectile.tileCollide = false; + + bool returningToPlayer = false; + if (!returningToPlayer) + { + returningToPlayer = projectile.ai[0] == 1f; + } + + //Player distance calculations + Vector2 playerVec = player.Center - projectile.Center + new Vector2(0f, -60f); + float playerDist = playerVec.Length(); + + //If the minion is actively returning, move faster + float playerHomeSpeed = 6f; + if (returningToPlayer) + { + playerHomeSpeed = 15f; + } + //Move somewhat faster if the player is kinda far~ish + if (playerDist > 200f && playerHomeSpeed < 8f) + { + playerHomeSpeed = 8f; + } + //Return to normal if close enough to the player + if (playerDist < safeDist && returningToPlayer && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) + { + projectile.ai[0] = 0f; + projectile.netUpdate = true; + } + //Teleport to the player if abnormally far + if (playerDist > 2000f) + { + projectile.position.X = player.Center.X - (float)(projectile.width / 2); + projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); + projectile.netUpdate = true; + } + //If more than 70 pixels away, move toward the player + if (playerDist > 70f) + { + playerVec.Normalize(); + playerVec *= playerHomeSpeed; + projectile.velocity = (projectile.velocity * 40f + playerVec) / 41f; + } + //Minions never stay still + else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) + { + projectile.velocity.X = -0.15f; + projectile.velocity.Y = -0.05f; + } + } + + //Increment attack counter randomly + if (projectile.ai[1] > 0f) + { + projectile.ai[1] += (float)Main.rand.Next(1, 4); + } + //If high enough, prepare to attack + if (projectile.ai[1] > chargeCounterMax) + { + projectile.ai[1] = 0f; + projectile.netUpdate = true; + } + + //Charge at an enemy if not on cooldown + if (projectile.ai[0] == 0f) + { + if (projectile.ai[1] == 0f && foundTarget && maxDist < 500f) + { + projectile.ai[1] += 1f; + if (Main.myPlayer == projectile.owner) + { + projectile.ai[0] = 2f; + Vector2 targetPos = targetVec - projectile.Center; + targetPos.Normalize(); + projectile.velocity = targetPos * chargeSpeed; //8 + projectile.netUpdate = true; + } + } + } + } + + public static void FloatingPetAI(this Projectile projectile, bool faceRight, float tiltFloat, bool lightPet = false) + { + Player player = Main.player[projectile.owner]; + + //anti sticking movement as a failsafe + float SAImovement = 0.05f; + for (int k = 0; k < Main.maxProjectiles; k++) + { + Projectile otherProj = Main.projectile[k]; + // Short circuits to make the loop as fast as possible + if (!otherProj.active || otherProj.owner != projectile.owner || !Main.projPet[otherProj.type] || k == projectile.whoAmI) + continue; + + // If the other projectile is indeed another pet owned by the same player and they're too close, nudge them away. + bool isPet = Main.projPet[otherProj.type]; + float taxicabDist = Math.Abs(projectile.position.X - otherProj.position.X) + Math.Abs(projectile.position.Y - otherProj.position.Y); + if (isPet && taxicabDist < projectile.width) + { + if (projectile.position.X < otherProj.position.X) + projectile.velocity.X -= SAImovement; + else + projectile.velocity.X += SAImovement; + + if (projectile.position.Y < otherProj.position.Y) + projectile.velocity.Y -= SAImovement; + else + projectile.velocity.Y += SAImovement; + } + } + + float passiveMvtFloat = 0.5f; + projectile.tileCollide = false; + float range = 100f; + Vector2 projPos = new Vector2(projectile.Center.X, projectile.Center.Y); + float xDist = player.Center.X - projPos.X; + float yDist = player.Center.Y - projPos.Y; + yDist += Main.rand.NextFloat(-10, 20); + xDist += Main.rand.NextFloat(-10, 20); + //Light pets lead the player, normal pets trail the player + xDist += 60f * (lightPet ? (float)player.direction : -(float)player.direction); + yDist -= 60f; + Vector2 playerVector = new Vector2(xDist, yDist); + float playerDist = playerVector.Length(); + float returnSpeed = 18f; + + //If player is close enough, resume normal + if (playerDist < range && player.velocity.Y == 0f && + projectile.position.Y + projectile.height <= player.position.Y + player.height && + !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) + { + if (projectile.velocity.Y < -6f) + { + projectile.velocity.Y = -6f; + } + } + + //Teleport to player if too far + if (playerDist > 2000f) + { + projectile.position.X = player.Center.X - projectile.width / 2; + projectile.position.Y = player.Center.Y - projectile.height / 2; + projectile.netUpdate = true; + } + + if (playerDist < 50f) + { + if (Math.Abs(projectile.velocity.X) > 2f || Math.Abs(projectile.velocity.Y) > 2f) + { + projectile.velocity *= 0.99f; + } + passiveMvtFloat = 0.01f; + } + else + { + if (playerDist < 100f) + { + passiveMvtFloat = 0.1f; + } + if (playerDist > 300f) + { + passiveMvtFloat = 1f; + } + playerDist = returnSpeed / playerDist; + playerVector.X *= playerDist; + playerVector.Y *= playerDist; + } + if (projectile.velocity.X < playerVector.X) + { + projectile.velocity.X += passiveMvtFloat; + if (passiveMvtFloat > 0.05f && projectile.velocity.X < 0f) + { + projectile.velocity.X += passiveMvtFloat; + } + } + if (projectile.velocity.X > playerVector.X) + { + projectile.velocity.X -= passiveMvtFloat; + if (passiveMvtFloat > 0.05f && projectile.velocity.X > 0f) + { + projectile.velocity.X -= passiveMvtFloat; + } + } + if (projectile.velocity.Y < playerVector.Y) + { + projectile.velocity.Y += passiveMvtFloat; + if (passiveMvtFloat > 0.05f && projectile.velocity.Y < 0f) + { + projectile.velocity.Y += passiveMvtFloat * 2f; + } + } + if (projectile.velocity.Y > playerVector.Y) + { + projectile.velocity.Y -= passiveMvtFloat; + if (passiveMvtFloat > 0.05f && projectile.velocity.Y > 0f) + { + projectile.velocity.Y -= passiveMvtFloat * 2f; + } + } + if (projectile.velocity.X >= 0.25f) + { + projectile.direction = faceRight ? 1 : -1; + } + else if (projectile.velocity.X < -0.25f) + { + projectile.direction = faceRight ? -1 : 1; + } + //Tilting and change directions + projectile.spriteDirection = projectile.direction; + projectile.rotation = projectile.velocity.X * tiltFloat; + } + + public static void HealingProjectile(this Projectile projectile, int healing, int playerToHeal, float homingVelocity, float N, bool autoHomes = true, int timeCheck = 120) + { + int target = playerToHeal; + Player player = Main.player[target]; + float homingSpeed = homingVelocity; + if (player.lifeMagnet) + homingSpeed *= 1.5f; + + Vector2 projPos = new Vector2(projectile.Center.X, projectile.Center.Y); + float xDist = player.Center.X - projPos.X; + float yDist = player.Center.Y - projPos.Y; + Vector2 playerVector = new Vector2(xDist, yDist); + float playerDist = playerVector.Length(); + if (playerDist < 50f && projectile.position.X < player.position.X + player.width && projectile.position.X + projectile.width > player.position.X && projectile.position.Y < player.position.Y + player.height && projectile.position.Y + projectile.height > player.position.Y) + { + if (projectile.owner == Main.myPlayer && !Main.player[Main.myPlayer].moonLeech) + { + int healAmt = healing; + player.HealEffect(healAmt, false); + player.statLife += healAmt; + if (player.statLife > player.statLifeMax2) + { + player.statLife = player.statLifeMax2; + } + NetMessage.SendData(MessageID.SpiritHeal, -1, -1, null, target, healAmt, 0f, 0f, 0, 0, 0); + } + projectile.Kill(); + } + if (autoHomes) + { + playerDist = homingSpeed / playerDist; + playerVector.X *= playerDist; + playerVector.Y *= playerDist; + projectile.velocity.X = (projectile.velocity.X * N + playerVector.X) / (N + 1f); + projectile.velocity.Y = (projectile.velocity.Y * N + playerVector.Y) / (N + 1f); + } + else if (player.lifeMagnet && projectile.timeLeft < timeCheck) + { + playerDist = homingVelocity / playerDist; + playerVector.X *= playerDist; + playerVector.Y *= playerDist; + projectile.velocity.X = (projectile.velocity.X * N + playerVector.X) / (N + 1f); + projectile.velocity.Y = (projectile.velocity.Y * N + playerVector.Y) / (N + 1f); + } + } #endregion #region Tile Utilities