From fcd7b0adca86e8d1227c4fc9903bcc87a67ea99f Mon Sep 17 00:00:00 2001 From: Phupperbat Date: Sun, 30 Jan 2022 21:29:44 -0500 Subject: [PATCH] Turned Squirrel Squire into a sentry (Forgive me for my sins) --- Buffs/Summon/SquirrelSquireBuff.cs | 37 ---- Buffs/Summon/SquirrelSquireBuff.png | Bin 693 -> 0 bytes CalPlayer/CalamityPlayer.cs | 2 - Items/Weapons/Summon/SquirrelSquireStaff.cs | 4 +- ModSupport/WeakReferenceSupport.cs | 1 - Projectiles/Summon/SquirrelSquireAcorn.cs | 2 +- Projectiles/Summon/SquirrelSquireMinion.cs | 204 +++----------------- 7 files changed, 34 insertions(+), 216 deletions(-) delete mode 100644 Buffs/Summon/SquirrelSquireBuff.cs delete mode 100644 Buffs/Summon/SquirrelSquireBuff.png diff --git a/Buffs/Summon/SquirrelSquireBuff.cs b/Buffs/Summon/SquirrelSquireBuff.cs deleted file mode 100644 index 1f74d53b1f..0000000000 --- a/Buffs/Summon/SquirrelSquireBuff.cs +++ /dev/null @@ -1,37 +0,0 @@ -using CalamityMod.CalPlayer; -using CalamityMod.Projectiles.Summon; -using Terraria; -using Terraria.ModLoader; - -namespace CalamityMod.Buffs.Summon -{ - public class SquirrelSquireBuff : ModBuff - { - public override void SetDefaults() - { - DisplayName.SetDefault("Squirrel Squire"); - Description.SetDefault("The squirrel squire will protect you"); - Main.buffNoTimeDisplay[Type] = true; - Main.buffNoSave[Type] = true; - //Main.persistentBuff[Type] = true; - } - - public override void Update(Player player, ref int buffIndex) - { - CalamityPlayer modPlayer = player.Calamity(); - if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) - { - modPlayer.squirrel = true; - } - if (!modPlayer.squirrel) - { - player.DelBuff(buffIndex); - buffIndex--; - } - else - { - player.buffTime[buffIndex] = 18000; - } - } - } -} diff --git a/Buffs/Summon/SquirrelSquireBuff.png b/Buffs/Summon/SquirrelSquireBuff.png deleted file mode 100644 index aeb6f89db1682be6b777bed804b8d417e401c702..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 693 zcmV;m0!safP)Px#AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy24YJ`L;(K){{a7>y{D4^00IL^L_t(o!{wK;Yg17ahrg7d9a=)P z1u3>Pm5PwId5IRKq@)fyWXoERiklz=9Q^~jRVZ|D5<{m<1qTP6#Eiu>ZMrl~%~S%0 z#HyeO5(je<@5y_OUD^x%Est~Wd*|N!-E+>p&o^;12|%M#Y;uYUj!*dj`c89DH~E5> z$C?1Q9xWRk7xD$y4~8Bt9qX|6D&yMzD;hEE&6m%xf`H$vLuNb@aZcn=6FMwx9s9mL z1Z2;-xr=kDLR{)Zkoa;2$0wSq!;j8^8T6thJ3_yropc4zC z_KnDT0$M^sOQPPHHSdhmw-W%wTm5pUbe^sO|NI|VcN&UziWS4wc`n%^&vK;-z}>ki z*8!wr=AJ(>NQlmyfG;}vH@YkJpXc-M_z#YErH-^O7)$^F01|XXSad~LNk%$Pa%p95 bbYXO9Z*BlFgjnqF00000NkvXXu0mjf9@Q#` diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 6b00c1c965..f4f419856f 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -999,7 +999,6 @@ namespace CalamityMod.CalPlayer public bool aValkyrie = false; public bool apexShark = false; public bool gastricBelcher = false; - public bool squirrel = false; public bool hauntedDishes = false; public bool stormjaw = false; public bool sGod = false; @@ -2026,7 +2025,6 @@ namespace CalamityMod.CalPlayer endoCooper = false; apexShark = false; gastricBelcher = false; - squirrel = false; hauntedDishes = false; stormjaw = false; SPG = false; diff --git a/Items/Weapons/Summon/SquirrelSquireStaff.cs b/Items/Weapons/Summon/SquirrelSquireStaff.cs index 2c28e91909..f2a50917cb 100644 --- a/Items/Weapons/Summon/SquirrelSquireStaff.cs +++ b/Items/Weapons/Summon/SquirrelSquireStaff.cs @@ -31,6 +31,7 @@ namespace CalamityMod.Items.Weapons.Summon item.shoot = ModContent.ProjectileType(); item.shootSpeed = 10f; item.summon = true; + item.sentry = true; } public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) @@ -41,7 +42,8 @@ namespace CalamityMod.Items.Weapons.Summon speedX = 0; speedY = 0; Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0f, 30f); - //projectile.ai[1] is attack cooldown. Setting it here prevents immediate attacks + player.UpdateMaxTurrets(); + //projectile.ai[1] is attack cooldown. Setting it here prevents immediate attacks } return false; } diff --git a/ModSupport/WeakReferenceSupport.cs b/ModSupport/WeakReferenceSupport.cs index e8c05a499a..431e769339 100644 --- a/ModSupport/WeakReferenceSupport.cs +++ b/ModSupport/WeakReferenceSupport.cs @@ -874,7 +874,6 @@ namespace CalamityMod { sAssociation.Call("AddMinionInfo", summonItem, summonBuff, summonProjectile); } - RegisterSummon(ItemType(), BuffType(), ProjectileType()); RegisterSummon(ItemType(), BuffType(), ProjectileType()); RegisterSummon(ItemType(), BuffType(), ProjectileType()); RegisterSummon(ItemType(), BuffType(), ProjectileType()); diff --git a/Projectiles/Summon/SquirrelSquireAcorn.cs b/Projectiles/Summon/SquirrelSquireAcorn.cs index c7beca9b89..244818d328 100644 --- a/Projectiles/Summon/SquirrelSquireAcorn.cs +++ b/Projectiles/Summon/SquirrelSquireAcorn.cs @@ -10,7 +10,7 @@ namespace CalamityMod.Projectiles.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Acorn"); - ProjectileID.Sets.MinionShot[projectile.type] = true; + ProjectileID.Sets.SentryShot[projectile.type] = true; } public override void SetDefaults() diff --git a/Projectiles/Summon/SquirrelSquireMinion.cs b/Projectiles/Summon/SquirrelSquireMinion.cs index 3f4c919c43..efb1d978a6 100644 --- a/Projectiles/Summon/SquirrelSquireMinion.cs +++ b/Projectiles/Summon/SquirrelSquireMinion.cs @@ -11,28 +11,7 @@ namespace CalamityMod.Projectiles.Summon { public class SquirrelSquireMinion : ModProjectile { - public int StuckTimer; - public bool TryingToGetCloseToOwner - { - get => projectile.ai[0] == 1f; - set => projectile.ai[0] = value.ToInt(); - } public ref float AttackTimer => ref projectile.ai[1]; - public bool OnSolidGround - { - get - { - bool groundSolid = false; - for (int i = (int)projectile.Left.X / 16 - 1; i < (int)projectile.Right.X / 16 + 1; i++) - { - bool bottomTileSolid = CalamityUtils.ParanoidTileRetrieval(i, (int)projectile.Bottom.Y / 16).IsTileSolidGround(); - bool firstTileDownSolid = CalamityUtils.ParanoidTileRetrieval(i, (int)projectile.Bottom.Y / 16 + 1).IsTileSolidGround(); - bool secondTileDownSolid = CalamityUtils.ParanoidTileRetrieval(i, (int)projectile.Bottom.Y / 16 + 2).IsTileSolidGround(); - groundSolid |= bottomTileSolid || firstTileDownSolid || secondTileDownSolid; - } - return projectile.velocity.Y == 0f && groundSolid; - } - } public bool Attacking { get => projectile.localAI[1] == 1f; @@ -45,7 +24,7 @@ namespace CalamityMod.Projectiles.Summon DisplayName.SetDefault("Squirrel Squire"); ProjectileID.Sets.MinionSacrificable[projectile.type] = true; ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true; - Main.projFrames[projectile.type] = 17; + Main.projFrames[projectile.type] = 17; //About half of these frames are now unused, but I'll still keep them here incase } public override void SetDefaults() @@ -55,18 +34,13 @@ namespace CalamityMod.Projectiles.Summon projectile.netImportant = true; projectile.friendly = true; projectile.ignoreWater = true; - projectile.minionSlots = 1f; - projectile.timeLeft = 18000; + projectile.timeLeft = Projectile.SentryLifeTime; projectile.penetrate = -1; - projectile.tileCollide = false; - projectile.timeLeft *= 5; + projectile.tileCollide = true; projectile.minion = true; + projectile.sentry = true; } - public override void SendExtraAI(BinaryWriter writer) => writer.Write(StuckTimer); - - public override void ReceiveExtraAI(BinaryReader reader) => StuckTimer = reader.ReadInt32(); - public override void AI() { if (projectile.localAI[0] == 0f) @@ -82,28 +56,23 @@ namespace CalamityMod.Projectiles.Summon projectile.damage = trueDamage; } + projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f); projectile.frameCounter++; - VerifyIdentity(); - if (!projectile.WithinRange(Owner.Center, 1000f) || TryingToGetCloseToOwner || Collision.SolidCollision(projectile.position + Vector2.One * 4f, projectile.width - 8, projectile.height - 8)) - { - // Once far off, don't go back to normal until 350 pixels away from the owner or less. - TryingToGetCloseToOwner = !projectile.WithinRange(Owner.Center, 350f) && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height); - - ReturnToOwner(); - if (!projectile.WithinRange(Owner.Center, 2000f)) - { - projectile.Center = Owner.Center; - projectile.netUpdate = true; - } - projectile.tileCollide = false; - return; - } - Attacking = false; NPC potentialTarget = projectile.Center.MinionHoming(800f, Owner, false); if (potentialTarget is null) - FollowOwner(); + { + if (projectile.frameCounter > 3) + { + projectile.frame++; + projectile.frameCounter = 0; + } + if (projectile.frame > 3) + { + projectile.frame = 0; + } + } else { Attacking = true; @@ -112,6 +81,7 @@ namespace CalamityMod.Projectiles.Summon projectile.rotation = 0f; projectile.tileCollide = true; + projectile.StickToTiles(false, false); } public void DoInitializationEffects() @@ -130,144 +100,30 @@ namespace CalamityMod.Projectiles.Summon } } - public void VerifyIdentity() - { - Owner.AddBuff(ModContent.BuffType(), 3600); - if (projectile.type == ModContent.ProjectileType()) - { - if (Owner.dead) - Owner.Calamity().squirrel = false; - if (Owner.Calamity().squirrel) - projectile.timeLeft = 2; - } - } - - public void ReturnToOwner() - { - projectile.frame = 12 + projectile.frameCounter / 8 % 4; - projectile.velocity = projectile.velocity.MoveTowards(projectile.SafeDirectionTo(Owner.Top) * 8f, 0.8f); - projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt(); - projectile.rotation = projectile.velocity.X * 0.025f; - } - - public void AttemptToJumpToDestination(Vector2 destination) - { - if (OnSolidGround) - { - float jumpSpeed = MathHelper.Lerp(8f, 13f, Utils.InverseLerp(100f, 250f, MathHelper.Distance(projectile.Center.X, destination.X), true)); - projectile.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(projectile.Center, Owner.Center, 0.4f, jumpSpeed); - projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt(); - projectile.netUpdate = true; - projectile.frame = 4; - } - else - { - if (projectile.frameCounter % 5 == 4 && projectile.frame < 7) - projectile.frame++; - } - } - - public void FollowOwner() - { - projectile.rotation = 0f; - - // Slow down and just idly vibe if close enough to the owner. - float horizontalDistanceFromOwner = MathHelper.Distance(projectile.Center.X, Owner.Center.X); - float verticalDistanceFromOwner = MathHelper.Distance(projectile.Center.Y, Owner.Center.Y); - if (horizontalDistanceFromOwner < 100f && verticalDistanceFromOwner < 450f) - { - projectile.velocity.X *= 0.94f; - if (OnSolidGround) - { - projectile.frame = projectile.frameCounter / 5 % 4; - projectile.velocity *= 0.9f; - } - StuckTimer = 0; - } - - // Otherwise try to catch up with them on foot. - else - { - AttemptToJumpToDestination(Owner.Center); - // Determine if there's something in the way of this minion and its owner. - if (!Collision.CanHit(projectile.position, projectile.width, projectile.height, Owner.Center, 2, 2) || MathHelper.Distance(projectile.position.X, projectile.oldPosition.X) < 1f) - { - StuckTimer++; - - // If stuck for a sufficiently long time fly to the owner again. - if (StuckTimer > 180) - { - TryingToGetCloseToOwner = true; - StuckTimer = 0; - projectile.netUpdate = true; - } - } - else if (StuckTimer > 0) - StuckTimer--; - } - - // Enforce gravity. - projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f); - } - public void AttackTarget(NPC target) { float horizontalDistanceFromTarget = MathHelper.Distance(projectile.Center.X, target.Center.X); + AttackTimer++; - // Determine if the minion is stuck. - if (MathHelper.Distance(projectile.position.X, projectile.oldPosition.X) < 1f) + // Pelt the target with acorns. + projectile.frame = 8 + (int)(AttackTimer / 6.4) % 4; + if (Main.myPlayer == projectile.owner && AttackTimer % 30f == 27f) { - StuckTimer++; + projectile.spriteDirection = (target.Center.X > projectile.Center.X).ToDirectionInt(); + Vector2 acornSpawnPosition = projectile.Center + new Vector2(projectile.spriteDirection * 6f, 10f); + float acornShootSpeed = MathHelper.Lerp(15f, 32f, projectile.Distance(target.Center) / 800f); + Vector2 acornShootVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(acornSpawnPosition, target.Top + target.velocity * 25f, SquirrelSquireAcorn.Gravity, acornShootSpeed); - // If stuck for a sufficiently long time fly to the owner again. - if (StuckTimer > 180) - { - TryingToGetCloseToOwner = true; - StuckTimer = 0; - projectile.netUpdate = true; - } + if (projectile.WithinRange(target.Center, 200f)) + acornShootVelocity = (target.Center - acornSpawnPosition).SafeNormalize(-Vector2.UnitY) * acornShootSpeed; + + Projectile.NewProjectile(acornSpawnPosition, acornShootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); } - else if (StuckTimer > 0) - StuckTimer--; - - if (horizontalDistanceFromTarget > 350f) - AttemptToJumpToDestination(target.Center); - else if (OnSolidGround) - { - projectile.velocity.X *= 0.94f; - if (OnSolidGround) - { - projectile.frame = projectile.frameCounter / 5 % 4; - projectile.velocity *= 0.9f; - } - AttackTimer++; - - // Pelt the target with acorns. - projectile.frame = 8 + (int)(AttackTimer / 6.4) % 4; - if (Main.myPlayer == projectile.owner && AttackTimer % 30f == 27f) - { - projectile.spriteDirection = (target.Center.X > projectile.Center.X).ToDirectionInt(); - Vector2 acornSpawnPosition = projectile.Center + new Vector2(projectile.spriteDirection * 6f, 10f); - float acornShootSpeed = MathHelper.Lerp(15f, 32f, projectile.Distance(target.Center) / 800f); - Vector2 acornShootVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(acornSpawnPosition, target.Top + target.velocity * 25f, SquirrelSquireAcorn.Gravity, acornShootSpeed); - - if (projectile.WithinRange(target.Center, 200f)) - acornShootVelocity = (target.Center - acornSpawnPosition).SafeNormalize(-Vector2.UnitY) * acornShootSpeed; - - Projectile.NewProjectile(acornSpawnPosition, acornShootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); - } - } - projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f); + projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f); } public override bool CanDamage() => false; - public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough) - { - fallThrough = !Attacking && projectile.Bottom.Y < Owner.Top.Y; - return true; - } - public override bool OnTileCollide(Vector2 oldVelocity) => false; public override void Kill(int timeLeft)