diff --git a/Projectiles/CommonProjectileAI.cs b/Projectiles/CommonProjectileAI.cs new file mode 100644 index 0000000000..03e846d237 --- /dev/null +++ b/Projectiles/CommonProjectileAI.cs @@ -0,0 +1,623 @@ +using System; +using CalamityMod.CalPlayer; +using CalamityMod.Enums; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using static Terraria.ModLoader.ModContent; + +namespace CalamityMod.Projectiles; + +internal static class CommonProjectileAI +{ + public static void ChargingMinionAI(this Projectile projectile, float range, float maxPlayerDist, float extraMaxPlayerDist, float safeDist, int initialUpdates, float chargeDelayTime, float goToSpeed, float goBackSpeed, Vector2 returnOffset, float chargeCounterMax, float chargeSpeed, bool tileVision, bool ignoreTilesWhenCharging, int updateDifference = 1) + { + Player player = Main.player[projectile.owner]; + CalamityPlayer modPlayer = player.Calamity(); + 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 + updateDifference; + if (projectile.ai[1] > chargeDelayTime) + { + projectile.ai[1] = 1f; + projectile.ai[0] = 0f; + projectile.extraUpdates = initialUpdates; + // CIT 2OCT2024: This line was breaking how the game counted minions, + // which resulted in minions being counted extra times and despawning other minions, most notoriously with Resurrection Butterfly. + // As such, I have commented it out. + // 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; + bool isButterfly = projectile.type == 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 + float extraDist = (npc.width / 2) + (npc.height / 2); + + 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 (extraDist < maxDist && !tileVision) + canHit = Collision.CanHit(projectile.Center, 1, 1, npc.Center, 1, 1); + if (!foundTarget && targetDist < (maxDist + extraDist) && canHit) + { + maxDist = targetDist; + targetVec = npc.Center; + foundTarget = true; + } + } + } + //If no npc is specifically targetted or the selected enemy can't be found, check through the entire array + if (!foundTarget) + { + 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) + { + float extraDist = (npc.width / 2) + (npc.height / 2); + float targetDist = Vector2.Distance(npc.Center, projectile.Center); + bool canHit = true; + if (extraDist < maxDist && !tileVision) + canHit = Collision.CanHit(projectile.Center, 1, 1, npc.Center, 1, 1); + if (!foundTarget && targetDist < (maxDist + extraDist) && canHit) + { + maxDist = targetDist; + targetVec = npc.Center; + 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 + returnOffset; + 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 = projectile.Center; + 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.Bottom.Y <= player.Bottom.Y && + !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 inertia, bool autoHomes = true, int timeCheck = 120) + { + int target = playerToHeal; + Player player = Main.player[target]; + float homingSpeed = homingVelocity; + if (player.lifeMagnet) + homingSpeed *= 1.5f; + + Vector2 playerVector = player.Center - projectile.Center; + 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.LocalPlayer.moonLeech) + { + int healAmt = healing; + player.HealPlayer(healAmt, HealTextType.Local); + 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 * inertia + playerVector.X) / (inertia + 1f); + projectile.velocity.Y = (projectile.velocity.Y * inertia + playerVector.Y) / (inertia + 1f); + } + else if (player.lifeMagnet && projectile.timeLeft < timeCheck) + { + playerDist = homingVelocity / playerDist; + playerVector.X *= playerDist; + playerVector.Y *= playerDist; + projectile.velocity.X = (projectile.velocity.X * inertia + playerVector.X) / (inertia + 1f); + projectile.velocity.Y = (projectile.velocity.Y * inertia + playerVector.Y) / (inertia + 1f); + } + } + + 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; + } + } + } + + /// + /// Call this function in ModifyHitNPC to make your projectiles stick to enemies, needs StickyProjAI to be called in the AI of the projectile + /// + /// The projectile you're giving sticky behaviour to + /// How many projectiles of this type can stick to one enemy + public static void ModifyHitNPCSticky(this Projectile projectile, int maxStick) + { + Player player = Main.player[projectile.owner]; + Rectangle myRect = projectile.Hitbox; + + if (projectile.owner == Main.myPlayer) + { + for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) + { + NPC npc = Main.npc[npcIndex]; + //covers most edge cases like voodoo dolls + if (npc.active && !npc.dontTakeDamage && + ((projectile.friendly && (!npc.friendly || (npc.type == NPCID.Guide && projectile.owner < Main.maxPlayers && player.killGuide) || (npc.type == NPCID.Clothier && projectile.owner < Main.maxPlayers && player.killClothier))) || + (projectile.hostile && npc.friendly && !npc.dontTakeDamageFromHostiles)) && (projectile.owner < 0 || npc.immune[projectile.owner] == 0 || projectile.maxPenetrate == 1)) + { + if (npc.noTileCollide || !projectile.ownerHitCheck) + { + bool stickingToNPC; + //Solar Crawltipede tail has special collision + if (npc.type == NPCID.SolarCrawltipedeTail) + { + Rectangle rect = npc.Hitbox; + int crawltipedeHitboxMod = 8; + rect.X -= crawltipedeHitboxMod; + rect.Y -= crawltipedeHitboxMod; + rect.Width += crawltipedeHitboxMod * 2; + rect.Height += crawltipedeHitboxMod * 2; + stickingToNPC = projectile.Colliding(myRect, rect); + } + else + { + stickingToNPC = projectile.Colliding(myRect, npc.Hitbox); + } + if (stickingToNPC) + { + //reflect projectile if the npc can reflect it (like Selenians) + if (npc.reflectsProjectiles && projectile.CanBeReflected()) + { + npc.ReflectProjectile(projectile); + return; + } + + //let the projectile know it is sticking and the npc it is sticking too + projectile.ai[0] = 1f; + projectile.ai[1] = (float)npcIndex; + + //follow the NPC + projectile.velocity = (npc.Center - projectile.Center); + + projectile.netUpdate = true; + + //Count how many projectiles are attached, delete as necessary + Point[] array2 = new Point[maxStick]; + int projCount = 0; + for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) + { + Projectile proj = Main.projectile[projIndex]; + if (projIndex != projectile.whoAmI && proj.active && proj.owner == Main.myPlayer && proj.type == projectile.type && proj.ai[0] == 1f && proj.ai[1] == (float)npcIndex) + { + array2[projCount++] = new Point(projIndex, proj.timeLeft); + if (projCount >= array2.Length) + { + break; + } + } + } + if (projCount >= array2.Length) + { + int stuckProjAmt = 0; + for (int m = 1; m < array2.Length; m++) + { + if (array2[m].Y < array2[stuckProjAmt].Y) + { + stuckProjAmt = m; + } + } + Main.projectile[array2[stuckProjAmt].X].Kill(); + } + } + } + } + } + } + } + + public static void StickToTiles(this Projectile projectile, bool ignorePlatforms, bool stickToEverything) + { + try + { + int xLeft = (int)(projectile.position.X / 16f) - 1; + int xRight = (int)((projectile.position.X + (float)projectile.width) / 16f) + 2; + int yBottom = (int)(projectile.position.Y / 16f) - 1; + int yTop = (int)((projectile.position.Y + (float)projectile.height) / 16f) + 2; + if (xLeft < 0) + { + xLeft = 0; + } + if (xRight > Main.maxTilesX) + { + xRight = Main.maxTilesX; + } + if (yBottom < 0) + { + yBottom = 0; + } + if (yTop > Main.maxTilesY) + { + yTop = Main.maxTilesY; + } + for (int x = xLeft; x < xRight; x++) + { + for (int y = yBottom; y < yTop; y++) + { + Tile tile = Main.tile[x, y]; + bool platformCheck = true; + if (ignorePlatforms) + platformCheck = !TileID.Sets.Platforms[tile.TileType] && tile.TileType != TileID.PlanterBox; + bool tableCheck = false; + if (stickToEverything) + tableCheck = Main.tileSolidTop[tile.TileType] && tile.TileFrameY == 0; + if (tile != null && tile.HasUnactuatedTile && platformCheck && (Main.tileSolid[tile.TileType] || tableCheck)) + { + Vector2 tileSize; + tileSize.X = (float)(x * 16); + tileSize.Y = (float)(y * 16); + if (projectile.position.X + (float)projectile.width - 4f > tileSize.X && projectile.position.X + 4f < tileSize.X + 16f && projectile.position.Y + (float)projectile.height - 4f > tileSize.Y && projectile.position.Y + 4f < tileSize.Y + 16f) + { + projectile.velocity.X = 0f; + projectile.velocity.Y = -0.2f; + } + } + } + } + } + catch + { + } + } + + /// + /// Call this function in the ai of your projectile so it can stick to enemies, also requires ModifyHitNPCSticky to be called in ModifyHitNPC + /// + /// The projectile you're adding sticky behaviour to + /// Number of seconds you want a projectile to cling to an NPC + public static void StickyProjAI(this Projectile projectile, int timeLeft, bool findNewNPC = false) + { + if (projectile.ai[0] == 1f) + { + int seconds = timeLeft; + bool killProj = false; + bool spawnDust = false; + + //the projectile follows the NPC, even if it goes into blocks + projectile.tileCollide = false; + + //timer for triggering hit effects + projectile.localAI[0]++; + if (projectile.localAI[0] % 30f == 0f) + { + spawnDust = true; + } + + //So AI knows what NPC it is sticking to + int npcIndex = (int)projectile.ai[1]; + NPC npc = Main.npc[npcIndex]; + + //Kill projectile after so many seconds or if the NPC it is stuck to no longer exists + if (projectile.localAI[0] >= (float)(60 * seconds)) + { + killProj = true; + } + else if (!npcIndex.WithinBounds(Main.maxNPCs)) + { + killProj = true; + } + + else if (npc.active && !npc.dontTakeDamage) + { + //follow the NPC + projectile.Center = npc.Center - projectile.velocity * 2f; + projectile.gfxOffY = npc.gfxOffY; + + //if attached to npc, trigger npc hit effects every half a second + if (spawnDust) + { + npc.HitEffect(0, 1.0); + } + } + else + { + killProj = true; + } + + //Kill the projectile or reset stats if needed + if (killProj) + { + if (findNewNPC) + projectile.ai[0] = 0f; + else + projectile.Kill(); + } + } + } +} diff --git a/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs b/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs index e5c35b3a87..23defbd09c 100644 --- a/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs +++ b/Projectiles/DraedonsArsenal/StarSwallowerSummon.cs @@ -140,7 +140,6 @@ namespace CalamityMod.Projectiles.DraedonsArsenal PlayerSeparationAnxietyAI(player, ref minimumFrame, ref maximumFrame); FallThroughYPoint = player.Top.Y; } - Projectile.MinionAntiClump(); ManipulateFrames(minimumFrame, maximumFrame); } diff --git a/Projectiles/Healing/BurntSiennaProj.cs b/Projectiles/Healing/BurntSiennaProj.cs index 52efdc55f8..727296cc48 100644 --- a/Projectiles/Healing/BurntSiennaProj.cs +++ b/Projectiles/Healing/BurntSiennaProj.cs @@ -24,7 +24,6 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { Projectile.velocity *= 0.95f; - Projectile.HealingProjectile(3, (int)Projectile.ai[0], 6f, 15f, false); int dusty = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.GoldCoin, 0f, 0f, 100, default, 1f); Dust dust = Main.dust[dusty]; diff --git a/Projectiles/Healing/CactusHealOrb.cs b/Projectiles/Healing/CactusHealOrb.cs index 23f54b162e..868b2601d6 100644 --- a/Projectiles/Healing/CactusHealOrb.cs +++ b/Projectiles/Healing/CactusHealOrb.cs @@ -25,7 +25,6 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { Projectile.velocity.Y *= 0.98f; - Projectile.HealingProjectile(15, Projectile.owner, 12f, 15f, false); int dusty = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.TerraBlade, 0f, 0f, 100, new Color(0, 200, 0), 1.5f); Dust dust = Main.dust[dusty]; diff --git a/Projectiles/Healing/EssenceFlame.cs b/Projectiles/Healing/EssenceFlame.cs index d06bdfd4c6..610a4dd1e2 100644 --- a/Projectiles/Healing/EssenceFlame.cs +++ b/Projectiles/Healing/EssenceFlame.cs @@ -37,7 +37,6 @@ namespace CalamityMod.Projectiles.Healing { Projectile.frame = 0; } - Projectile.HealingProjectile((int)Projectile.ai[1], (int)Projectile.ai[0], 3.5f, 15f); return; } diff --git a/Projectiles/Healing/GladiatorHealOrb.cs b/Projectiles/Healing/GladiatorHealOrb.cs index e7c9296c9a..bbebf4fcd9 100644 --- a/Projectiles/Healing/GladiatorHealOrb.cs +++ b/Projectiles/Healing/GladiatorHealOrb.cs @@ -62,7 +62,7 @@ namespace CalamityMod.Projectiles.Healing public void PassiveBehavior() { float maxYVelocity = 2f; - CalamityUtils.StickToTiles(Projectile, false, false); + CommonProjectileAI.StickToTiles(Projectile, false, false); Projectile.velocity.X *= 0.99f; if (Projectile.velocity.Y < maxYVelocity) Projectile.velocity.Y += 0.02f; diff --git a/Projectiles/Magic/HadalUrnLamprey.cs b/Projectiles/Magic/HadalUrnLamprey.cs index a8b5030619..3e57137c2e 100644 --- a/Projectiles/Magic/HadalUrnLamprey.cs +++ b/Projectiles/Magic/HadalUrnLamprey.cs @@ -48,7 +48,6 @@ namespace CalamityMod.Projectiles.Magic { Projectile.rotation = Projectile.velocity.ToRotation(); } - //Sticky Behaviour Projectile.StickyProjAI(15); Projectile.frameCounter++; diff --git a/Projectiles/Magic/WaterLeechProj.cs b/Projectiles/Magic/WaterLeechProj.cs index a85083f258..6bb8d4bf4d 100644 --- a/Projectiles/Magic/WaterLeechProj.cs +++ b/Projectiles/Magic/WaterLeechProj.cs @@ -47,7 +47,6 @@ namespace CalamityMod.Projectiles.Magic { Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.Pi; } - //Sticky Behaviour Projectile.StickyProjAI(5); } diff --git a/Projectiles/Melee/BonebreakerProjectile.cs b/Projectiles/Melee/BonebreakerProjectile.cs index 41c5b560a3..b2f5d2d035 100644 --- a/Projectiles/Melee/BonebreakerProjectile.cs +++ b/Projectiles/Melee/BonebreakerProjectile.cs @@ -46,7 +46,6 @@ namespace CalamityMod.Projectiles.Melee } Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; } - //Sticky Behaviour Projectile.StickyProjAI(15); } diff --git a/Projectiles/Pets/PerforaMini.cs b/Projectiles/Pets/PerforaMini.cs index d11e8856f5..8ef9a80541 100644 --- a/Projectiles/Pets/PerforaMini.cs +++ b/Projectiles/Pets/PerforaMini.cs @@ -57,7 +57,6 @@ namespace CalamityMod.Projectiles.Pets { Projectile.timeLeft = 2; } - Projectile.FloatingPetAI(true, 0.1f); //Dust diff --git a/Projectiles/Pets/RotomPet.cs b/Projectiles/Pets/RotomPet.cs index f9920c8963..54291d3730 100644 --- a/Projectiles/Pets/RotomPet.cs +++ b/Projectiles/Pets/RotomPet.cs @@ -69,7 +69,6 @@ namespace CalamityMod.Projectiles.Pets UpdateForm(player); UpdateFrames(); - Projectile.FloatingPetAI(true, 0.05f); } diff --git a/Projectiles/Ranged/HydraHead.cs b/Projectiles/Ranged/HydraHead.cs index ae90151da0..1a12887c45 100644 --- a/Projectiles/Ranged/HydraHead.cs +++ b/Projectiles/Ranged/HydraHead.cs @@ -123,8 +123,6 @@ namespace CalamityMod.Projectiles.Ranged // Clamp the center so that it does not go too far from the return position. if (Projectile.Distance(returnPosition) > 120f) Projectile.Center = returnPosition + Projectile.DirectionFrom(returnPosition) * 120f; - - // Disallow heads from getting too close to each other. Projectile.MinionAntiClump(0.15f); } diff --git a/Projectiles/Rogue/DimensionTearingDiskProjectile.cs b/Projectiles/Rogue/DimensionTearingDiskProjectile.cs index bcb2876335..cda9d5b223 100644 --- a/Projectiles/Rogue/DimensionTearingDiskProjectile.cs +++ b/Projectiles/Rogue/DimensionTearingDiskProjectile.cs @@ -138,8 +138,6 @@ namespace CalamityMod.Projectiles.Rogue laser.DamageType = RogueDamageClass.Instance; } } - - // Stay stuck to the target. Projectile.StickyProjAI(6, true); // If still attached to a target, do nothing. @@ -209,8 +207,6 @@ namespace CalamityMod.Projectiles.Rogue // Provide a fixed amount of grind time so that DPS can't vary wildly. Projectile.timeLeft = 90; } - - // Apply sticky AI. Projectile.ModifyHitNPCSticky(3); } diff --git a/Projectiles/Rogue/EclipsesStealth.cs b/Projectiles/Rogue/EclipsesStealth.cs index bdf017b9f2..77e0bc3d4c 100644 --- a/Projectiles/Rogue/EclipsesStealth.cs +++ b/Projectiles/Rogue/EclipsesStealth.cs @@ -87,8 +87,6 @@ namespace CalamityMod.Projectiles.Rogue } } } - - // Sticky behavior. Lets the projectile impale enemies and sticks to its impaled enemy automatically. Projectile.StickyProjAI(10); } diff --git a/Projectiles/Rogue/GodsParanoiaProj.cs b/Projectiles/Rogue/GodsParanoiaProj.cs index 5c2bc3d735..ba9ca80eed 100644 --- a/Projectiles/Rogue/GodsParanoiaProj.cs +++ b/Projectiles/Rogue/GodsParanoiaProj.cs @@ -43,7 +43,6 @@ namespace CalamityMod.Projectiles.Rogue flame.velocity = Vector2.Zero; flame.noGravity = true; } - Projectile.StickyProjAI(50); if (Projectile.ai[0] == 1f) diff --git a/Projectiles/Rogue/JawsProjectile.cs b/Projectiles/Rogue/JawsProjectile.cs index cf28eed5b5..d06de31ee4 100644 --- a/Projectiles/Rogue/JawsProjectile.cs +++ b/Projectiles/Rogue/JawsProjectile.cs @@ -51,7 +51,6 @@ namespace CalamityMod.Projectiles.Rogue Main.dust[dust].noGravity = true; } } - //Sticky Behaviour Projectile.StickyProjAI(15); } diff --git a/Projectiles/Rogue/KelvinCatalystBoomerang.cs b/Projectiles/Rogue/KelvinCatalystBoomerang.cs index fbf1f6df10..d9c564f0cc 100644 --- a/Projectiles/Rogue/KelvinCatalystBoomerang.cs +++ b/Projectiles/Rogue/KelvinCatalystBoomerang.cs @@ -67,7 +67,6 @@ namespace CalamityMod.Projectiles.Rogue ReturnToPlayer(); break; case 2: - // Will target the targetted NPC that minions use btw Projectile.ChargingMinionAI(1200f, 1500f, 2200f, 150f, 1, 40f, 12f, 6f, new Vector2(0f, -60f), 40f, 12f, true, true); Projectile.localAI[0] += 1f; if (Projectile.localAI[0] >= 180) diff --git a/Projectiles/Rogue/LionfishProj.cs b/Projectiles/Rogue/LionfishProj.cs index 7d5cb2ecae..023b266700 100644 --- a/Projectiles/Rogue/LionfishProj.cs +++ b/Projectiles/Rogue/LionfishProj.cs @@ -65,7 +65,6 @@ namespace CalamityMod.Projectiles.Rogue } } } - //Sticky Behaviour Projectile.StickyProjAI(15); } diff --git a/Projectiles/Rogue/MetalShard.cs b/Projectiles/Rogue/MetalShard.cs index 83d25aece6..0622bbe146 100644 --- a/Projectiles/Rogue/MetalShard.cs +++ b/Projectiles/Rogue/MetalShard.cs @@ -37,7 +37,6 @@ namespace CalamityMod.Projectiles.Rogue if (Projectile.velocity.Y > 16f) Projectile.velocity.Y = 16f; } - //Sticky Behaviour Projectile.StickyProjAI(15); } diff --git a/Projectiles/Rogue/NastyChollaBol.cs b/Projectiles/Rogue/NastyChollaBol.cs index 82a59ad5dd..ddbf587f4c 100644 --- a/Projectiles/Rogue/NastyChollaBol.cs +++ b/Projectiles/Rogue/NastyChollaBol.cs @@ -32,7 +32,6 @@ namespace CalamityMod.Projectiles.Rogue { Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.ChlorophyteWeapon, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f); } - //Sticky Behaviour Projectile.StickyProjAI(15); if (Projectile.ai[0] != 1f) { diff --git a/Projectiles/Rogue/SnapClamProj.cs b/Projectiles/Rogue/SnapClamProj.cs index 2aff8e2686..12675173a0 100644 --- a/Projectiles/Rogue/SnapClamProj.cs +++ b/Projectiles/Rogue/SnapClamProj.cs @@ -45,7 +45,6 @@ namespace CalamityMod.Projectiles.Rogue Projectile.rotation += 0.4f * (float)Projectile.direction; Projectile.spriteDirection = Projectile.direction; } - //Sticky Behaviour Projectile.StickyProjAI(15); if (Projectile.ai[2] < 30f && Projectile.ai[0] != 1f) { diff --git a/Projectiles/Rogue/SnapClamStealth.cs b/Projectiles/Rogue/SnapClamStealth.cs index 12ddd3ee4b..d4f4a2cd02 100644 --- a/Projectiles/Rogue/SnapClamStealth.cs +++ b/Projectiles/Rogue/SnapClamStealth.cs @@ -47,7 +47,6 @@ namespace CalamityMod.Projectiles.Rogue Projectile.rotation += 0.4f * (float)Projectile.direction; Projectile.spriteDirection = Projectile.direction; } - //Sticky Behaviour Projectile.StickyProjAI(15); if (Projectile.ai[2] < 30f && Projectile.ai[0] != 1f) { diff --git a/Projectiles/Summon/AquaticStarMinion.cs b/Projectiles/Summon/AquaticStarMinion.cs index 8267a409ae..4a78c8a8fa 100644 --- a/Projectiles/Summon/AquaticStarMinion.cs +++ b/Projectiles/Summon/AquaticStarMinion.cs @@ -66,8 +66,6 @@ namespace CalamityMod.Projectiles.Summon // Does a dust effect where the minion spawns. Projectile.rotation += Projectile.velocity.X * 0.04f; - // Make the minion spin depending on how fast it is. - Projectile.ChargingMinionAI(1200f, 1500f, 2200f, 150f, 0, 24f, 15f, 4f, new Vector2(0f, -60f), 12f, 12f, false, false, 1); } diff --git a/Projectiles/Summon/AureusBomber.cs b/Projectiles/Summon/AureusBomber.cs index 52d7dd22ef..b8f427ad7e 100644 --- a/Projectiles/Summon/AureusBomber.cs +++ b/Projectiles/Summon/AureusBomber.cs @@ -62,8 +62,6 @@ namespace CalamityMod.Projectiles.Summon } Projectile.localAI[0] += 1f; } - - //anti sticking movement Projectile.MinionAntiClump(); //get in a line diff --git a/Projectiles/Summon/BelladonnaSpirit.cs b/Projectiles/Summon/BelladonnaSpirit.cs index 34f577a36c..feea46e3ca 100644 --- a/Projectiles/Summon/BelladonnaSpirit.cs +++ b/Projectiles/Summon/BelladonnaSpirit.cs @@ -32,7 +32,6 @@ namespace CalamityMod.Projectiles.Summon FollowPlayer(); if (Target != null) AttackTarget(); - Projectile.MinionAntiClump(); Projectile.spriteDirection = Target == null ? MathF.Sign(Projectile.velocity.X) : MathF.Sign(Target.Center.X - Projectile.Center.X); diff --git a/Projectiles/Summon/BlackHawkSummon.cs b/Projectiles/Summon/BlackHawkSummon.cs index 93d42c501c..b1ae973b7d 100644 --- a/Projectiles/Summon/BlackHawkSummon.cs +++ b/Projectiles/Summon/BlackHawkSummon.cs @@ -114,8 +114,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.timeLeft = 2; } } - - //Anti sticky movement to prevent overlapping minions Projectile.MinionAntiClump(); float maxDistance = 700f; diff --git a/Projectiles/Summon/Calamitamini.cs b/Projectiles/Summon/Calamitamini.cs index f1c755a738..bdaafb3318 100644 --- a/Projectiles/Summon/Calamitamini.cs +++ b/Projectiles/Summon/Calamitamini.cs @@ -73,7 +73,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.timeLeft = 2; } } - Projectile.MinionAntiClump(); Projectile.frameCounter++; diff --git a/Projectiles/Summon/Cataclymini.cs b/Projectiles/Summon/Cataclymini.cs index b67690cdcc..820f09e23f 100644 --- a/Projectiles/Summon/Cataclymini.cs +++ b/Projectiles/Summon/Cataclymini.cs @@ -66,7 +66,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.timeLeft = 2; } } - Projectile.MinionAntiClump(); Projectile.frameCounter++; diff --git a/Projectiles/Summon/Catastromini.cs b/Projectiles/Summon/Catastromini.cs index 956f049214..9666b486ca 100644 --- a/Projectiles/Summon/Catastromini.cs +++ b/Projectiles/Summon/Catastromini.cs @@ -79,7 +79,6 @@ namespace CalamityMod.Projectiles.Summon { Projectile.frame = 0; } - Projectile.ChargingMinionAI(Calamitamini.Range, Calamitamini.SeparationAnxietyMin, Calamitamini.SeparationAnxietyMax, Calamitamini.SafeDist, 0, 40f, 8f, 4f, new Vector2(0f, -60f), 40f, 8f, false, true); } diff --git a/Projectiles/Summon/CausticStaffSummon.cs b/Projectiles/Summon/CausticStaffSummon.cs index 501472f410..654f6293a7 100644 --- a/Projectiles/Summon/CausticStaffSummon.cs +++ b/Projectiles/Summon/CausticStaffSummon.cs @@ -71,8 +71,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.timeLeft = 2; } } - - //Anti sticky movement to prevent minions from stacking Projectile.MinionAntiClump(); //Set tile collision for only when trying to return to the player diff --git a/Projectiles/Summon/CelestialAxeMinion.cs b/Projectiles/Summon/CelestialAxeMinion.cs index 932f8ec4fb..7db74490e4 100644 --- a/Projectiles/Summon/CelestialAxeMinion.cs +++ b/Projectiles/Summon/CelestialAxeMinion.cs @@ -58,7 +58,6 @@ namespace CalamityMod.Projectiles.Summon } } Projectile.rotation += 0.075f; - Projectile.ChargingMinionAI(1600f, 1800f, 2500f, 400f, 1, 30f, 24f, 12f, new Vector2(0f, -60f), 30f, 16f, true, true); // Destroy trees in GFB, because it's an axe, and axes should do that diff --git a/Projectiles/Summon/CosmicViperSummon.cs b/Projectiles/Summon/CosmicViperSummon.cs index 0dffeca8d7..f9548599a1 100644 --- a/Projectiles/Summon/CosmicViperSummon.cs +++ b/Projectiles/Summon/CosmicViperSummon.cs @@ -111,7 +111,6 @@ 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); - Projectile.MinionAntiClump(); float detectRange = 2200f; diff --git a/Projectiles/Summon/DormantBrimseekerBab.cs b/Projectiles/Summon/DormantBrimseekerBab.cs index 183b6108fc..a2079fd6b0 100644 --- a/Projectiles/Summon/DormantBrimseekerBab.cs +++ b/Projectiles/Summon/DormantBrimseekerBab.cs @@ -97,7 +97,6 @@ namespace CalamityMod.Projectiles.Summon { Projectile.frame = (Projectile.localAI[1] == 1f).ToInt() * 4; } - Projectile.MinionAntiClump(0.1f); if (Projectile.Distance(player.Center) > 2700f) { diff --git a/Projectiles/Summon/EnchantedBladeSummon.cs b/Projectiles/Summon/EnchantedBladeSummon.cs index 12f42ec889..827d173448 100644 --- a/Projectiles/Summon/EnchantedBladeSummon.cs +++ b/Projectiles/Summon/EnchantedBladeSummon.cs @@ -78,7 +78,6 @@ namespace CalamityMod.Projectiles.Summon } CurrentState.Invoke(); - Projectile.MinionAntiClump(0.25f); if (!Main.dedServ) diff --git a/Projectiles/Summon/EndoCooperBody.cs b/Projectiles/Summon/EndoCooperBody.cs index 487ec89ec1..6f32dd23b5 100644 --- a/Projectiles/Summon/EndoCooperBody.cs +++ b/Projectiles/Summon/EndoCooperBody.cs @@ -137,7 +137,6 @@ namespace CalamityMod.Projectiles.Summon if (limbs.type != ModContent.ProjectileType() || !limbs.active) Projectile.Kill(); - Projectile.MinionAntiClump(); bool accelerate = false; if (Projectile.ai[0] == 2f) diff --git a/Projectiles/Summon/EndoHydraHead.cs b/Projectiles/Summon/EndoHydraHead.cs index d33f6bbb9f..4b2aba981a 100644 --- a/Projectiles/Summon/EndoHydraHead.cs +++ b/Projectiles/Summon/EndoHydraHead.cs @@ -156,7 +156,6 @@ namespace CalamityMod.Projectiles.Summon { Projectile.Center = returnPosition + Projectile.DirectionFrom(returnPosition) * 120f; } - Projectile.MinionAntiClump(0.15f); AdjustOldVelocityArray(); } diff --git a/Projectiles/Summon/EyeOfNightCell.cs b/Projectiles/Summon/EyeOfNightCell.cs index ffa1a756c0..a0b0e58b74 100644 --- a/Projectiles/Summon/EyeOfNightCell.cs +++ b/Projectiles/Summon/EyeOfNightCell.cs @@ -31,7 +31,6 @@ namespace CalamityMod.Projectiles.Summon { if (!Main.dedServ && Projectile.velocity.Length() > 5f) Dust.NewDustPerfect(Projectile.Center, (int)CalamityDusts.SulphurousSeaAcid).noGravity = true; - Projectile.StickyProjAI(3); } public override void OnKill(int timeLeft) diff --git a/Projectiles/Summon/FieryDraconid.cs b/Projectiles/Summon/FieryDraconid.cs index 2574c58132..4b8ceba47b 100644 --- a/Projectiles/Summon/FieryDraconid.cs +++ b/Projectiles/Summon/FieryDraconid.cs @@ -146,7 +146,6 @@ namespace CalamityMod.Projectiles.Summon public void DoPlayerHoverMovement() { - // Move away from other minions of the same type. Projectile.MinionAntiClump(0.1f); Vector2 hoverDestination = Owner.Top - Vector2.UnitY * 50f; diff --git a/Projectiles/Summon/GammaHead.cs b/Projectiles/Summon/GammaHead.cs index adad872278..b4fc0edb9d 100644 --- a/Projectiles/Summon/GammaHead.cs +++ b/Projectiles/Summon/GammaHead.cs @@ -187,8 +187,6 @@ namespace CalamityMod.Projectiles.Summon // Clamp the center so that it does not go too far from the return position. if (Projectile.Distance(returnPosition) > 120f) Projectile.Center = returnPosition + Projectile.DirectionFrom(returnPosition) * 120f; - - // Disallow heads from getting too close to each other. Projectile.MinionAntiClump(0.15f); } diff --git a/Projectiles/Summon/GastricBelcher.cs b/Projectiles/Summon/GastricBelcher.cs index c4523cdeee..71a09c85ce 100644 --- a/Projectiles/Summon/GastricBelcher.cs +++ b/Projectiles/Summon/GastricBelcher.cs @@ -92,8 +92,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.timeLeft = 2; } } - - //Anti sticky movement to prevent overlapping minions Projectile.MinionAntiClump(); //Find a target diff --git a/Projectiles/Summon/HerringAI.cs b/Projectiles/Summon/HerringAI.cs index 54ae7836db..21c5434bba 100644 --- a/Projectiles/Summon/HerringAI.cs +++ b/Projectiles/Summon/HerringAI.cs @@ -47,8 +47,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.rotation = (Projectile.spriteDirection == -1) ? Projectile.velocity.ToRotation() + MathHelper.Pi : Projectile.velocity.ToRotation(); Projectile.spriteDirection = (Projectile.velocity.X > 0).ToDirectionInt(); - // Although the sprite is invisible, we'll keep track of it's direction and rotation so we can later apply it to the decorative herrings. - Projectile.ChargingMinionAI(EnemyDistanceDetection, 1500f, 2200f, 150f, 0, 24f, 15f, 4f, new Vector2(0f, -60f), 12f, 12f, CalamityPlayer.areThereAnyDamnBosses, true, 1); // The AI of the minion. Projectile.netUpdate = true; diff --git a/Projectiles/Summon/IceClasperMinion.cs b/Projectiles/Summon/IceClasperMinion.cs index d99434a91f..f068af577a 100644 --- a/Projectiles/Summon/IceClasperMinion.cs +++ b/Projectiles/Summon/IceClasperMinion.cs @@ -56,7 +56,6 @@ namespace CalamityMod.Projectiles.Summon RamState(); break; } - Projectile.MinionAntiClump(0.5f); if (!Main.dedServ) diff --git a/Projectiles/Summon/MidnightSunUFO.cs b/Projectiles/Summon/MidnightSunUFO.cs index 502494bb28..38b5bb2507 100644 --- a/Projectiles/Summon/MidnightSunUFO.cs +++ b/Projectiles/Summon/MidnightSunUFO.cs @@ -131,7 +131,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.Center = player.Center; Projectile.netUpdate = true; } - Projectile.MinionAntiClump(0.35f); Projectile.rotation = Projectile.velocity.X * 0.03f; } diff --git a/Projectiles/Summon/MiniGuardianHealer.cs b/Projectiles/Summon/MiniGuardianHealer.cs index 53397e2946..53460bbd4c 100644 --- a/Projectiles/Summon/MiniGuardianHealer.cs +++ b/Projectiles/Summon/MiniGuardianHealer.cs @@ -82,7 +82,6 @@ namespace CalamityMod.Projectiles.Summon hasSetTimers = true; Projectile.netUpdate = true; } - Projectile.MinionAntiClump(); Player owner = Owner; diff --git a/Projectiles/Summon/PlaguebringerSummon.cs b/Projectiles/Summon/PlaguebringerSummon.cs index ffa626a95c..a50a6e83f4 100644 --- a/Projectiles/Summon/PlaguebringerSummon.cs +++ b/Projectiles/Summon/PlaguebringerSummon.cs @@ -60,7 +60,6 @@ namespace CalamityMod.Projectiles.Summon } if (!modPlayer.plaguebringerPatronSet) Projectile.Kill(); - Projectile.MinionAntiClump(); Projectile.ai[0]++; diff --git a/Projectiles/Summon/SandElementalHealer.cs b/Projectiles/Summon/SandElementalHealer.cs index 408e4982e2..2a12054087 100644 --- a/Projectiles/Summon/SandElementalHealer.cs +++ b/Projectiles/Summon/SandElementalHealer.cs @@ -97,7 +97,6 @@ namespace CalamityMod.Projectiles.Summon lightScalar *= Main.essScale; Lighting.AddLight(Projectile.Center, 0.7f * lightScalar, 0.6f * lightScalar, 0f * lightScalar); } - Projectile.MinionAntiClump(); if (Vector2.Distance(player.Center, Projectile.Center) > 400f) diff --git a/Projectiles/Summon/SlimePuppet.cs b/Projectiles/Summon/SlimePuppet.cs index 1e12d73113..d607367ab2 100644 --- a/Projectiles/Summon/SlimePuppet.cs +++ b/Projectiles/Summon/SlimePuppet.cs @@ -36,7 +36,6 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { - // Prevent clumping of other slime puppets near this one. Projectile.MinionAntiClump(); NPC potentialTarget = Projectile.Center.MinionHoming(800f, Owner); diff --git a/Projectiles/Summon/TacticalPlagueJet.cs b/Projectiles/Summon/TacticalPlagueJet.cs index 854d66152b..4b8e1625c0 100644 --- a/Projectiles/Summon/TacticalPlagueJet.cs +++ b/Projectiles/Summon/TacticalPlagueJet.cs @@ -191,8 +191,6 @@ namespace CalamityMod.Projectiles.Summon Main.projectile[projIndex].minion = false; } } - - // Prevent minion clumping while firing. Projectile.MinionAntiClump(0.25f); } } diff --git a/Projectiles/Summon/Valkyrie.cs b/Projectiles/Summon/Valkyrie.cs index ddcf3733dc..74f8021533 100644 --- a/Projectiles/Summon/Valkyrie.cs +++ b/Projectiles/Summon/Valkyrie.cs @@ -73,7 +73,6 @@ namespace CalamityMod.Projectiles.Summon { Projectile.spriteDirection = -Projectile.direction; } - Projectile.ChargingMinionAI(700f, 800f, 1200f, 150f, 0, 40f, 8f, 4f, new Vector2(0f, -60f), 40f, 8f, false, true); //Give off some light diff --git a/Projectiles/Typeless/FungalClumpMinion.cs b/Projectiles/Typeless/FungalClumpMinion.cs index 782a84cecd..b96d31acb4 100644 --- a/Projectiles/Typeless/FungalClumpMinion.cs +++ b/Projectiles/Typeless/FungalClumpMinion.cs @@ -95,8 +95,6 @@ namespace CalamityMod.Projectiles.Typeless { Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.BlueFairy, Projectile.velocity.X * 0.05f, Projectile.velocity.Y * 0.05f); } - - //Anti-sticky movement failsafe Projectile.MinionAntiClump(); //If too far from player, increase speed to chase after player diff --git a/Utilities/GenericAIUtils.cs b/Utilities/GenericAIUtils.cs deleted file mode 100644 index 49fbf5fa78..0000000000 --- a/Utilities/GenericAIUtils.cs +++ /dev/null @@ -1,626 +0,0 @@ -using System; -using CalamityMod.CalPlayer; -using CalamityMod.Enums; -using CalamityMod.Projectiles.Summon; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using static Terraria.ModLoader.ModContent; - -namespace CalamityMod -{ - public static partial class CalamityUtils - { - public static void ChargingMinionAI(this Projectile projectile, float range, float maxPlayerDist, float extraMaxPlayerDist, float safeDist, int initialUpdates, float chargeDelayTime, float goToSpeed, float goBackSpeed, Vector2 returnOffset, float chargeCounterMax, float chargeSpeed, bool tileVision, bool ignoreTilesWhenCharging, int updateDifference = 1) - { - 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 + updateDifference; - if (projectile.ai[1] > chargeDelayTime) - { - projectile.ai[1] = 1f; - projectile.ai[0] = 0f; - projectile.extraUpdates = initialUpdates; - // CIT 2OCT2024: This line was breaking how the game counted minions, - // which resulted in minions being counted extra times and despawning other minions, most notoriously with Resurrection Butterfly. - // As such, I have commented it out. - // 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; - bool isButterfly = projectile.type == 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 - float extraDist = (npc.width / 2) + (npc.height / 2); - - 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 (extraDist < maxDist && !tileVision) - canHit = Collision.CanHit(projectile.Center, 1, 1, npc.Center, 1, 1); - if (!foundTarget && targetDist < (maxDist + extraDist) && canHit) - { - maxDist = targetDist; - targetVec = npc.Center; - foundTarget = true; - } - } - } - //If no npc is specifically targetted or the selected enemy can't be found, check through the entire array - if (!foundTarget) - { - 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) - { - float extraDist = (npc.width / 2) + (npc.height / 2); - float targetDist = Vector2.Distance(npc.Center, projectile.Center); - bool canHit = true; - if (extraDist < maxDist && !tileVision) - canHit = Collision.CanHit(projectile.Center, 1, 1, npc.Center, 1, 1); - if (!foundTarget && targetDist < (maxDist + extraDist) && canHit) - { - maxDist = targetDist; - targetVec = npc.Center; - 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 + returnOffset; - 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 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 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 = projectile.Center; - 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.Bottom.Y <= player.Bottom.Y && - !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 inertia, bool autoHomes = true, int timeCheck = 120) - { - int target = playerToHeal; - Player player = Main.player[target]; - float homingSpeed = homingVelocity; - if (player.lifeMagnet) - homingSpeed *= 1.5f; - - Vector2 playerVector = player.Center - projectile.Center; - 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.LocalPlayer.moonLeech) - { - int healAmt = healing; - player.HealPlayer(healAmt, HealTextType.Local); - 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 * inertia + playerVector.X) / (inertia + 1f); - projectile.velocity.Y = (projectile.velocity.Y * inertia + playerVector.Y) / (inertia + 1f); - } - else if (player.lifeMagnet && projectile.timeLeft < timeCheck) - { - playerDist = homingVelocity / playerDist; - playerVector.X *= playerDist; - playerVector.Y *= playerDist; - projectile.velocity.X = (projectile.velocity.X * inertia + playerVector.X) / (inertia + 1f); - projectile.velocity.Y = (projectile.velocity.Y * inertia + playerVector.Y) / (inertia + 1f); - } - } - - /// - /// Call this function in the ai of your projectile so it can stick to enemies, also requires ModifyHitNPCSticky to be called in ModifyHitNPC - /// - /// The projectile you're adding sticky behaviour to - /// Number of seconds you want a projectile to cling to an NPC - public static void StickyProjAI(this Projectile projectile, int timeLeft, bool findNewNPC = false) - { - if (projectile.ai[0] == 1f) - { - int seconds = timeLeft; - bool killProj = false; - bool spawnDust = false; - - //the projectile follows the NPC, even if it goes into blocks - projectile.tileCollide = false; - - //timer for triggering hit effects - projectile.localAI[0]++; - if (projectile.localAI[0] % 30f == 0f) - { - spawnDust = true; - } - - //So AI knows what NPC it is sticking to - int npcIndex = (int)projectile.ai[1]; - NPC npc = Main.npc[npcIndex]; - - //Kill projectile after so many seconds or if the NPC it is stuck to no longer exists - if (projectile.localAI[0] >= (float)(60 * seconds)) - { - killProj = true; - } - else if (!npcIndex.WithinBounds(Main.maxNPCs)) - { - killProj = true; - } - - else if (npc.active && !npc.dontTakeDamage) - { - //follow the NPC - projectile.Center = npc.Center - projectile.velocity * 2f; - projectile.gfxOffY = npc.gfxOffY; - - //if attached to npc, trigger npc hit effects every half a second - if (spawnDust) - { - npc.HitEffect(0, 1.0); - } - } - else - { - killProj = true; - } - - //Kill the projectile or reset stats if needed - if (killProj) - { - if (findNewNPC) - projectile.ai[0] = 0f; - else - projectile.Kill(); - } - } - } - - /// - /// Call this function in ModifyHitNPC to make your projectiles stick to enemies, needs StickyProjAI to be called in the AI of the projectile - /// - /// The projectile you're giving sticky behaviour to - /// How many projectiles of this type can stick to one enemy - public static void ModifyHitNPCSticky(this Projectile projectile, int maxStick) - { - Player player = Main.player[projectile.owner]; - Rectangle myRect = projectile.Hitbox; - - if (projectile.owner == Main.myPlayer) - { - for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) - { - NPC npc = Main.npc[npcIndex]; - //covers most edge cases like voodoo dolls - if (npc.active && !npc.dontTakeDamage && - ((projectile.friendly && (!npc.friendly || (npc.type == NPCID.Guide && projectile.owner < Main.maxPlayers && player.killGuide) || (npc.type == NPCID.Clothier && projectile.owner < Main.maxPlayers && player.killClothier))) || - (projectile.hostile && npc.friendly && !npc.dontTakeDamageFromHostiles)) && (projectile.owner < 0 || npc.immune[projectile.owner] == 0 || projectile.maxPenetrate == 1)) - { - if (npc.noTileCollide || !projectile.ownerHitCheck) - { - bool stickingToNPC; - //Solar Crawltipede tail has special collision - if (npc.type == NPCID.SolarCrawltipedeTail) - { - Rectangle rect = npc.Hitbox; - int crawltipedeHitboxMod = 8; - rect.X -= crawltipedeHitboxMod; - rect.Y -= crawltipedeHitboxMod; - rect.Width += crawltipedeHitboxMod * 2; - rect.Height += crawltipedeHitboxMod * 2; - stickingToNPC = projectile.Colliding(myRect, rect); - } - else - { - stickingToNPC = projectile.Colliding(myRect, npc.Hitbox); - } - if (stickingToNPC) - { - //reflect projectile if the npc can reflect it (like Selenians) - if (npc.reflectsProjectiles && projectile.CanBeReflected()) - { - npc.ReflectProjectile(projectile); - return; - } - - //let the projectile know it is sticking and the npc it is sticking too - projectile.ai[0] = 1f; - projectile.ai[1] = (float)npcIndex; - - //follow the NPC - projectile.velocity = (npc.Center - projectile.Center); - - projectile.netUpdate = true; - - //Count how many projectiles are attached, delete as necessary - Point[] array2 = new Point[maxStick]; - int projCount = 0; - for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) - { - Projectile proj = Main.projectile[projIndex]; - if (projIndex != projectile.whoAmI && proj.active && proj.owner == Main.myPlayer && proj.type == projectile.type && proj.ai[0] == 1f && proj.ai[1] == (float)npcIndex) - { - array2[projCount++] = new Point(projIndex, proj.timeLeft); - if (projCount >= array2.Length) - { - break; - } - } - } - if (projCount >= array2.Length) - { - int stuckProjAmt = 0; - for (int m = 1; m < array2.Length; m++) - { - if (array2[m].Y < array2[stuckProjAmt].Y) - { - stuckProjAmt = m; - } - } - Main.projectile[array2[stuckProjAmt].X].Kill(); - } - } - } - } - } - } - } - - public static void StickToTiles(this Projectile projectile, bool ignorePlatforms, bool stickToEverything) - { - try - { - int xLeft = (int)(projectile.position.X / 16f) - 1; - int xRight = (int)((projectile.position.X + (float)projectile.width) / 16f) + 2; - int yBottom = (int)(projectile.position.Y / 16f) - 1; - int yTop = (int)((projectile.position.Y + (float)projectile.height) / 16f) + 2; - if (xLeft < 0) - { - xLeft = 0; - } - if (xRight > Main.maxTilesX) - { - xRight = Main.maxTilesX; - } - if (yBottom < 0) - { - yBottom = 0; - } - if (yTop > Main.maxTilesY) - { - yTop = Main.maxTilesY; - } - for (int x = xLeft; x < xRight; x++) - { - for (int y = yBottom; y < yTop; y++) - { - Tile tile = Main.tile[x, y]; - bool platformCheck = true; - if (ignorePlatforms) - platformCheck = !TileID.Sets.Platforms[tile.TileType] && tile.TileType != TileID.PlanterBox; - bool tableCheck = false; - if (stickToEverything) - tableCheck = Main.tileSolidTop[tile.TileType] && tile.TileFrameY == 0; - if (tile != null && tile.HasUnactuatedTile && platformCheck && (Main.tileSolid[tile.TileType] || tableCheck)) - { - Vector2 tileSize; - tileSize.X = (float)(x * 16); - tileSize.Y = (float)(y * 16); - if (projectile.position.X + (float)projectile.width - 4f > tileSize.X && projectile.position.X + 4f < tileSize.X + 16f && projectile.position.Y + (float)projectile.height - 4f > tileSize.Y && projectile.position.Y + 4f < tileSize.Y + 16f) - { - projectile.velocity.X = 0f; - projectile.velocity.Y = -0.2f; - } - } - } - } - } - catch - { - } - } - } -}