diff --git a/Buffs/Pets/YharonSonBuff.cs b/Buffs/Pets/YharonSonBuff.cs new file mode 100644 index 0000000000..2712c6ed07 --- /dev/null +++ b/Buffs/Pets/YharonSonBuff.cs @@ -0,0 +1,29 @@ +using CalamityMod.Projectiles.Pets; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Pets +{ + public class YharonSonBuff : ModBuff + { + public override void SetDefaults() + { + DisplayName.SetDefault("Son of Yharon"); + Description.SetDefault("You better not eat his dinner"); + Main.buffNoTimeDisplay[Type] = true; + Main.vanityPet[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + player.buffTime[buffIndex] = 18000; + player.Calamity().yharonPet = true; + bool petProjectileNotSpawned = player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0; + if (petProjectileNotSpawned && player.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(player.Top, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, player.whoAmI, 1f); + } + } + } +} diff --git a/Buffs/Pets/YharonSonBuff.png b/Buffs/Pets/YharonSonBuff.png new file mode 100644 index 0000000000..c2a94f5eb2 Binary files /dev/null and b/Buffs/Pets/YharonSonBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index bcac3459bf..02a458344b 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -357,6 +357,7 @@ namespace CalamityMod.CalPlayer public bool thirdSageH = true; public bool perfmini = false; public bool akato = false; + public bool yharonPet = false; public bool leviPet = false; public bool plaguebringerBab = false; public bool rotomPet = false; @@ -1495,6 +1496,7 @@ namespace CalamityMod.CalPlayer thirdSage = false; perfmini = false; akato = false; + yharonPet = false; leviPet = false; plaguebringerBab = false; rotomPet = false; diff --git a/Items/Pets/McNuggets.cs b/Items/Pets/McNuggets.cs new file mode 100644 index 0000000000..e8dd237a37 --- /dev/null +++ b/Items/Pets/McNuggets.cs @@ -0,0 +1,35 @@ +using CalamityMod.Buffs.Pets; +using CalamityMod.Projectiles.Pets; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Pets +{ + public class McNuggets : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("McNuggets"); + Tooltip.SetDefault("These chicken nuggets aren't for you to eat!"); + } + + public override void SetDefaults() + { + item.CloneDefaults(ItemID.ZephyrFish); + item.shoot = ModContent.ProjectileType(); + item.buffType = ModContent.BuffType(); + + item.value = Item.sellPrice(gold: 30); + item.Calamity().customRarity = CalamityRarity.Violet; + } + + public override void UseStyle(Player player) + { + if (player.whoAmI == Main.myPlayer && player.itemTime == 0) + { + player.AddBuff(item.buffType, 3600, true); + } + } + } +} diff --git a/Items/Pets/McNuggets.png b/Items/Pets/McNuggets.png new file mode 100644 index 0000000000..3c8432b60b Binary files /dev/null and b/Items/Pets/McNuggets.png differ diff --git a/Items/TreasureBags/YharonBag.cs b/Items/TreasureBags/YharonBag.cs index bc982e1c00..46f26046f9 100644 --- a/Items/TreasureBags/YharonBag.cs +++ b/Items/TreasureBags/YharonBag.cs @@ -66,6 +66,7 @@ namespace CalamityMod.Items.TreasureBags // Vanity DropHelper.DropItemChance(player, ModContent.ItemType(), 7); DropHelper.DropItemChance(player, ModContent.ItemType(), 10); + DropHelper.DropItemChance(player, ModContent.ItemType(), 10); DropHelper.DropItemCondition(player, ModContent.ItemType(), CalamityWorld.revenge); } } diff --git a/ModSupport/WeakReferenceSupport.cs b/ModSupport/WeakReferenceSupport.cs index 20aa9d4c3d..841a387884 100644 --- a/ModSupport/WeakReferenceSupport.cs +++ b/ModSupport/WeakReferenceSupport.cs @@ -570,7 +570,7 @@ namespace CalamityMod int type = NPCType(); int summon = ItemType(); List loot = new List() { ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), /*ItemType(), */ItemType() }; - List collection = new List() { ItemType(), ItemType(), ItemType(), ItemType(), ItemType() }; + List collection = new List() { ItemType(), ItemType(), ItemType(), ItemType(), ItemType(), ItemType() }; string instructions = $"Use a [i:{summon}] in the Jungle Biome"; string despawn = CalamityUtils.ColorMessage("Yharon found you too weak to stay near your gravestone.", new Color(0xFF, 0xA5, 0x00)); string bossLogTex = "CalamityMod/NPCs/Yharon/Yharon_BossChecklist"; diff --git a/NPCs/Yharon/Yharon.cs b/NPCs/Yharon/Yharon.cs index d9d796d1f7..c36aaa9ed3 100644 --- a/NPCs/Yharon/Yharon.cs +++ b/NPCs/Yharon/Yharon.cs @@ -2889,6 +2889,7 @@ namespace CalamityMod.NPCs.Yharon // Vanity DropHelper.DropItemChance(npc, ModContent.ItemType(), 7); DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); + DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); // Materials int soulFragMin = 15; diff --git a/Projectiles/Pets/YharonSonPet.cs b/Projectiles/Pets/YharonSonPet.cs new file mode 100644 index 0000000000..940a942be6 --- /dev/null +++ b/Projectiles/Pets/YharonSonPet.cs @@ -0,0 +1,410 @@ +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Pets +{ + public class YharonSonPet : ModProjectile + { + public Player player => Main.player[projectile.owner]; + private static int xFrameAmt = 3; + private static int yFrameAmt = 16; + + public int frameX = 0; + public int frameY = 0; + + public int CurrentFrame + { + get => frameX * yFrameAmt + frameY; + set + { + frameX = value / yFrameAmt; + frameY = value % yFrameAmt; + } + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Son of Yharon"); + Main.projPet[projectile.type] = true; + } + + public override void SetDefaults() + { + projectile.netImportant = true; + projectile.width = 104; + projectile.height = 82; + projectile.friendly = true; + projectile.penetrate = -1; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (projectile.frameCounter <= 1) + return false; + Texture2D texture = Main.projectileTexture[projectile.type]; + Vector2 origin = texture.Size() / new Vector2((float)xFrameAmt, (float)yFrameAmt) * 0.5f; + Rectangle frame = texture.Frame(xFrameAmt, yFrameAmt, frameX, frameY); + SpriteEffects spriteEffects = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, frame, lightColor, projectile.rotation, origin, projectile.scale, spriteEffects, 0f); + return false; + } + + private bool CurrentlySitting() => CurrentFrame == 0 || CurrentFrame == 3 || CurrentFrame == 4 || CurrentFrame >= 19; + private bool CurrentlyFlying() => CurrentFrame == 1 || CurrentFrame == 2 || CurrentFrame >= 5 && CurrentFrame <= 18; + + private void SittingFrames() + { + projectile.frameCounter++; + if (projectile.frameCounter % 6 == 0) + { + if (CurrentlyFlying()) + CurrentFrame = 3; + else if (CurrentFrame == 45) + CurrentFrame = 0; + else if (CurrentFrame != 0) + CurrentFrame++; + if (CurrentFrame == 5) + CurrentFrame = 0; + // Roughly 25.97% chance per second for blinking + if (Main.rand.NextBool(200) && CurrentFrame == 0) + CurrentFrame = 46; + // Roughly 3.9% chance per second for head shaking + if (Main.rand.NextBool(1500) && CurrentFrame == 0) + CurrentFrame = 19; + if (frameX >= xFrameAmt) + CurrentFrame = 0; + } + } + + private void FlyingFrames() + { + projectile.frameCounter++; + if (projectile.frameCounter % 6 == 0) + { + if (CurrentlySitting()) + CurrentFrame = 1; + else + CurrentFrame++; + if (CurrentFrame == 3) + CurrentFrame = 5; + if (CurrentFrame > 18) + CurrentFrame = 5; + // This should never happen at this stage but just in case + if (frameX >= xFrameAmt) + CurrentFrame = 0; + } + } + + private void PetDefaults() + { + if (!player.active) + { + projectile.active = false; + return; + } + CalamityPlayer modPlayer = player.Calamity(); + if (player.dead) + { + modPlayer.yharonPet = false; + } + if (modPlayer.yharonPet) + { + projectile.timeLeft = 2; + } + } + + public override void AI() + { + // Insert generic pet setup + PetDefaults(); + + // Fly toward the player if they are using Rocket Boots + if (player.rocketDelay2 > 0) + { + projectile.ai[0] = 1f; + } + + float xDist = player.Center.X - projectile.Center.X; + float yDist = player.Center.Y - projectile.Center.Y; + Vector2 playerVector = new Vector2(xDist, yDist); + float playerDist = playerVector.Length(); + + //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; + } + // Otherwise, make sure we're not going crazy in the y velocity and try to fly back toward the player + else if (playerDist > (CurrentlySitting() ? 300f : 200f)) + { + if (yDist > 0f && projectile.velocity.Y < 0f) + { + projectile.velocity.Y = 0f; + } + if (yDist < 0f && projectile.velocity.Y > 0f) + { + projectile.velocity.Y = 0f; + } + projectile.ai[0] = 1f; + } + + // Fly toward the player + if (projectile.ai[0] != 0f) + { + FlyingPetAI(); + } + // Try and sit down + else + { + SitDownAttempt(); + } + projectile.spriteDirection = projectile.direction; + DontSitInMidair(); + } + + private void DontSitInMidair() + { + if (CurrentlySitting()) + { + bool noSolidGround = true; + for (int i = (int)projectile.BottomLeft.X / 16; i < (int)projectile.BottomRight.X / 16; i++) + { + Tile tileBelow = CalamityUtils.ParanoidTileRetrieval(i, (int)(projectile.Bottom.Y / 16)); + if (tileBelow.IsTileSolidGround()) + { + noSolidGround = false; + break; + } + } + if (noSolidGround) + projectile.ai[0] = 1f; + } + } + + private void FlyingPetAI() + { + float passiveMvtFloat = 0.2f; + projectile.tileCollide = false; + float range = 200f; + float xDist = player.Center.X - projectile.Center.X; + float yDist = player.Center.Y - projectile.Center.Y; + yDist += Main.rand.NextFloat(-10, 20); + xDist += Main.rand.NextFloat(-10, 20); + xDist += 60f * -(float)player.direction; + yDist -= 60f; + Vector2 playerVector = new Vector2(xDist, yDist); + float playerDist = playerVector.Length(); + float returnSpeed = 12f; + + //If player is close enough, try and land + if (playerDist < range && player.velocity.Y == 0f && projectile.Bottom.Y <= player.Bottom.Y && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) + { + projectile.ai[0] = 0f; + if (projectile.velocity.Y < -6f) + { + projectile.velocity.Y = -6f; + } + } + + if (playerDist < 60f) + { + playerVector.X = projectile.velocity.X; + playerVector.Y = projectile.velocity.Y; + } + else + { + playerDist = returnSpeed / playerDist; + playerVector.X *= playerDist; + playerVector.Y *= playerDist; + } + if (projectile.velocity.X < playerVector.X) + { + projectile.velocity.X += passiveMvtFloat; + if (projectile.velocity.X < 0f) + { + projectile.velocity.X += passiveMvtFloat * 1.5f; + } + } + if (projectile.velocity.X > playerVector.X) + { + projectile.velocity.X -= passiveMvtFloat; + if (projectile.velocity.X > 0f) + { + projectile.velocity.X -= passiveMvtFloat * 1.5f; + } + } + if (projectile.velocity.Y < playerVector.Y) + { + projectile.velocity.Y += passiveMvtFloat; + if (projectile.velocity.Y < 0f) + { + projectile.velocity.Y += passiveMvtFloat * 1.5f; + } + } + if (projectile.velocity.Y > playerVector.Y) + { + projectile.velocity.Y -= passiveMvtFloat; + if (projectile.velocity.Y > 0f) + { + projectile.velocity.Y -= passiveMvtFloat * 1.5f; + } + } + if (projectile.velocity.X >= 0.5f) + { + projectile.direction = -1; + } + else if (projectile.velocity.X < -0.5f) + { + projectile.direction = 1; + } + else if (player.Center.X < projectile.Center.X) + { + projectile.direction = 1; + } + else if (player.Center.X > projectile.Center.X) + { + projectile.direction = -1; + } + + //Tilting + projectile.rotation = projectile.velocity.X * 0.075f; + + // Frames while flying + FlyingFrames(); + } + + private void SitDownAttempt() + { + projectile.tileCollide = true; + + bool tooRight = false; + bool tooLeft = false; + bool abovePlayer = false; + float xAdjust = 0.08f; + float xVelMax = 6.5f; + + if (player.Center.X < projectile.Center.X - 85f) + { + tooRight = true; + } + else if (player.Center.X > projectile.Center.X + 85f) + { + tooLeft = true; + } + + if (tooRight) + { + if (projectile.velocity.X > -3.5f) + { + projectile.velocity.X -= xAdjust; + } + else + { + projectile.velocity.X -= xAdjust * 0.25f; + } + } + else if (tooLeft) + { + if (projectile.velocity.X < 3.5f) + { + projectile.velocity.X += xAdjust; + } + else + { + projectile.velocity.X += xAdjust * 0.25f; + } + } + else + { + projectile.velocity.X *= 0.9f; + if (projectile.velocity.X >= 0f - xAdjust && projectile.velocity.X <= xAdjust) + { + projectile.velocity.X = 0f; + } + } + projectile.velocity.X *= 0.95f; + if (projectile.velocity.X > -0.1f && projectile.velocity.X < 0.1f) + { + projectile.velocity.X = 0f; + } + + if (player.Bottom.Y - 8f > projectile.Bottom.Y) + { + abovePlayer = true; + } + Collision.StepUp(ref projectile.position, ref projectile.velocity, projectile.width, projectile.height, ref projectile.stepSpeed, ref projectile.gfxOffY); + if (projectile.velocity.Y == 0f) + { + if (!abovePlayer && projectile.velocity.X != 0f) + { + int i = (int)projectile.Center.X / 16; + int j = (int)projectile.Center.Y / 16 + 1; + if (tooRight) + { + i--; + } + if (tooLeft) + { + i++; + } + WorldGen.SolidTile(i, j); + } + } + + // Cap X velocity when attempting to sit + if (projectile.velocity.X > xVelMax) + { + projectile.velocity.X = xVelMax; + } + if (projectile.velocity.X < -xVelMax) + { + projectile.velocity.X = -xVelMax; + } + + // Handle frames and sitting direction/rotation + bool sitting = projectile.position.X == projectile.oldPosition.X; + if (projectile.velocity.Y == 0f && sitting) + { + if (player.Center.X < projectile.Center.X) + { + projectile.direction = 1; + } + else if (player.Center.X > projectile.Center.X) + { + projectile.direction = -1; + } + projectile.rotation = 0f; + // Frames while sitting + SittingFrames(); + } + else + { + if (projectile.velocity.X >= 0.5f) + { + projectile.direction = -1; + } + else if (projectile.velocity.X < -0.5f) + { + projectile.direction = 1; + } + else if (player.Center.X < projectile.Center.X) + { + projectile.direction = 1; + } + else if (player.Center.X > projectile.Center.X) + { + projectile.direction = -1; + } + + projectile.rotation = projectile.velocity.X * 0.075f; + + // Frames while flying + FlyingFrames(); + } + } + } +} diff --git a/Projectiles/Pets/YharonSonPet.png b/Projectiles/Pets/YharonSonPet.png new file mode 100644 index 0000000000..083d66c522 Binary files /dev/null and b/Projectiles/Pets/YharonSonPet.png differ diff --git a/Utilities/GenericAIUtils.cs b/Utilities/GenericAIUtils.cs index 87e8070b90..dfa2a4aa2d 100644 --- a/Utilities/GenericAIUtils.cs +++ b/Utilities/GenericAIUtils.cs @@ -404,7 +404,7 @@ namespace CalamityMod float passiveMvtFloat = 0.5f; projectile.tileCollide = false; float range = 100f; - Vector2 projPos = new Vector2(projectile.Center.X, projectile.Center.Y); + Vector2 projPos = projectile.Center; float xDist = player.Center.X - projPos.X; float yDist = player.Center.Y - projPos.Y; yDist += Main.rand.NextFloat(-10, 20); @@ -418,7 +418,7 @@ namespace CalamityMod //If player is close enough, resume normal if (playerDist < range && player.velocity.Y == 0f && - projectile.position.Y + projectile.height <= player.position.Y + player.height && + projectile.Bottom.Y <= player.Bottom.Y && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) { if (projectile.velocity.Y < -6f)