diff --git a/Items/SummonItems/TownPets/PiggyLicense.cs b/Items/SummonItems/TownPets/PiggyLicense.cs new file mode 100644 index 0000000000..6d0ca49cad --- /dev/null +++ b/Items/SummonItems/TownPets/PiggyLicense.cs @@ -0,0 +1,67 @@ +using CalamityMod.NPCs.TownNPCs; +using CalamityMod.Packets; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Chat; +using Terraria.Enums; +using Terraria.ID; +using Terraria.Localization; +using Terraria.ModLoader; + +namespace CalamityMod.Items.SummonItems.TownPets +{ + public class PiggyLicense : ModItem + { + public override string Texture => "Terraria/Images/Item_" + ItemID.LicenseBunny; + public override void SetStaticDefaults() + { + Item.ResearchUnlockCount = 5; + } + + public override void SetDefaults() + { + Item.useStyle = ItemUseStyleID.HoldUp; + Item.consumable = true; + Item.useAnimation = 45; + Item.useTime = 45; + Item.UseSound = SoundID.Item92; + Item.width = 28; + Item.height = 28; + Item.maxStack = Item.CommonMaxStack; + Item.SetShopValues(ItemRarityColor.Green2, Item.buyPrice(0, 5)); + } + + public override bool? UseItem(Player player) + { + int npcType = ModContent.NPCType(); + if (player.ItemAnimationJustStarted && (!CalamityWorld.unlockedTownPig || NPC.AnyNPCs(npcType))) + { + if (player.whoAmI == Main.myPlayer) + { + SpawnPiggy(); + } + return true; + } + return false; + } + + public static void SpawnPiggy() + { + Color color = new(50, 255, 130); + if (Main.netMode == NetmodeID.MultiplayerClient) + { + if (!CalamityWorld.unlockedTownPig) + { + SyncTownPigLicensePacket.Send(); + } + } + else if (!CalamityWorld.unlockedTownPig) + { + CalamityWorld.unlockedTownPig = true; + ChatHelper.BroadcastChatMessage(NetworkText.FromKey("Mods.CalamityMod.Misc.PiggyLicense"), color); + CalamityNetcode.SyncWorld(); + } + } + } +} diff --git a/Localization/en-US/Mods.CalamityMod.Misc.hjson b/Localization/en-US/Mods.CalamityMod.Misc.hjson index 8d617226ec..2006538ff2 100644 --- a/Localization/en-US/Mods.CalamityMod.Misc.hjson +++ b/Localization/en-US/Mods.CalamityMod.Misc.hjson @@ -57,6 +57,7 @@ SevensBust: Bust! SevensDoubles: Doubles! SevensTriples: Triples! StylishHammerHit: Stylish! +PiggyLicense: The license teleports away to the Piggy delivery service... GenericConsumedText: "[c/8A8A8A:You have already consumed this item]" CelestialOnionText: You have already consumed a Celestial Onion. Consuming another would distort you. SanguineTangerineText: You have already consumed a Sanguine Tangerine. Eating any more would make your blood too thick to flow. diff --git a/Localization/en-US/Mods.CalamityMod.NPCs.hjson b/Localization/en-US/Mods.CalamityMod.NPCs.hjson index ac7691f508..b22cd0f65e 100644 --- a/Localization/en-US/Mods.CalamityMod.NPCs.hjson +++ b/Localization/en-US/Mods.CalamityMod.NPCs.hjson @@ -561,6 +561,36 @@ SeaKing: { } } +TownPiggy: { + DisplayName: Town Pig + Census.SpawnCondition: Use a Pig License + + Name: { + Oolong: Oolong + Napoleon: Napoleon + Waddles: Waddles + Crenando: Crenando + Olivia: Olivia + Wilbur: Wilbur + Pumbaa: Pumbaa + Peppa: Peppa + Conan: Conan + Reuben: Reuben + Porky: Porky + Hamm: Hamm + Runt: Runt + Roko: Roko + RichardHam: Richard Ham + Curly: Curly + } + + Chat: { + 0: Oink! + 1: Squeal... + 2: Snort! + } +} + DraconicSwarmer.DisplayName: Draconic Swarmer Dragonfolly.DisplayName: Dragonfolly Shoreskipper.DisplayName: Shoreskipper diff --git a/NPCs/TownNPCs/TownPiggy.cs b/NPCs/TownNPCs/TownPiggy.cs new file mode 100644 index 0000000000..5bcaa0b61f --- /dev/null +++ b/NPCs/TownNPCs/TownPiggy.cs @@ -0,0 +1,146 @@ +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.GameContent; +using Terraria.GameContent.Bestiary; +using Terraria.ID; +using Terraria.Localization; +using Terraria.ModLoader; +using Terraria.Utilities; + +namespace CalamityMod.NPCs.TownNPCs +{ + [AutoloadHead] + public class TownPiggy : ModNPC + { + public override void SetStaticDefaults() + { + Main.npcFrameCount[Type] = 8; + NPCID.Sets.ExtraFramesCount[Type] = 0; + NPCID.Sets.AttackFrameCount[Type] = 0; + NPCID.Sets.DangerDetectRange[Type] = 250; + NPCID.Sets.HatOffsetY[Type] = 6; + NPCID.Sets.ShimmerTownTransform[Type] = false; + NPCID.Sets.SpecificDebuffImmunity[Type][BuffID.Shimmer] = true; + NPCID.Sets.SpecificDebuffImmunity[Type][BuffID.Confused] = true; + NPCID.Sets.NPCFramingGroup[Type] = 8; + + NPCID.Sets.IsTownPet[Type] = true; + NPCID.Sets.CannotSitOnFurniture[Type] = false; + NPCID.Sets.TownNPCBestiaryPriority.Add(Type); + NPCID.Sets.PlayerDistanceWhilePetting[Type] = 32; + NPCID.Sets.IsPetSmallForPetting[Type] = true; + + NPCID.Sets.NPCBestiaryDrawModifiers drawModifiers = new() + { + Velocity = 0.25f, + }; + + NPCID.Sets.NPCBestiaryDrawOffset.Add(Type, drawModifiers); + } + + public override void SetDefaults() + { + NPC.townNPC = true; + NPC.friendly = true; + NPC.width = 20; + NPC.height = 20; + NPC.aiStyle = NPCAIStyleID.Passive; + NPC.damage = 0; + NPC.defense = 0; + NPC.lifeMax = 50; + NPC.HitSound = SoundID.NPCHit1; + NPC.DeathSound = SoundID.NPCDeath1; + NPC.knockBackResist = 0.5f; + NPC.housingCategory = 1; + //AnimationType = NPCID.TownBunny; + } + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + bestiaryEntry.Info.AddRange( + [ + BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface, + new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.TownPiggy") + ]); + } + + public override bool CanTownNPCSpawn(int numTownNPCs) + { + if (CalamityWorld.unlockedTownPig) + { + return true; + } + return false; + } + + public override void AI() + { + NPC.spriteDirection = NPC.direction; + } + + public override void FindFrame(int frameHeight) + { + if (NPC.velocity.X == 0) + NPC.frame.Y = 0; + else + { + if (NPC.frameCounter++ % 6 == 0) + { + NPC.frame.Y += frameHeight; + if (NPC.frame.Y >= frameHeight * Main.npcFrameCount[Type]) + { + NPC.frame.Y = frameHeight; + } + } + if (NPC.frame.Y < frameHeight) + NPC.frame.Y = frameHeight; + } + } + + public override List SetNPCNameList() => new List() + { + // Original names + this.GetLocalizedValue("Name.Curly"), + + // Reference names + this.GetLocalizedValue("Name.Oolong"), // Dragon Ball + this.GetLocalizedValue("Name.Napoleon"), // Animal Farm + this.GetLocalizedValue("Name.Waddles"), // Gravity Falls + this.GetLocalizedValue("Name.Crenando"), // Ganondorf + this.GetLocalizedValue("Name.Olivia"), // Olivia + this.GetLocalizedValue("Name.Wilbur"), // Charlotte's Web + this.GetLocalizedValue("Name.Pumbaa"), // The Lion King + this.GetLocalizedValue("Name.Peppa"), // Peppa Pig + this.GetLocalizedValue("Name.Conan"), // Conan the mighty pig + this.GetLocalizedValue("Name.Reuben"), // Minecraft: Story Mode + this.GetLocalizedValue("Name.Porky"), // Looney Tunes + this.GetLocalizedValue("Name.Hamm"), // Toy Story + this.GetLocalizedValue("Name.Runt"), // Chicken Little + this.GetLocalizedValue("Name.Roko"), // Roko's Basilisk + this.GetLocalizedValue("Name.RichardHamm"), // Pig from Clarkson's Farm named after Richard Hammond + + // Dedicated names + }; + + public override string GetChat() + { + WeightedRandom chat = new(); + + for (int i = 0; i <= 2; i++) + { + chat.Add(CalamityUtils.GetText("NPCs.TownPiggy.Chat." + i).Value); + } + + return chat; + } + + public override void SetChatButtons(ref string button, ref string button2) + { + button = Language.GetTextValue("UI.PetTheAnimal"); + } + } +} diff --git a/NPCs/TownNPCs/TownPiggy.png b/NPCs/TownNPCs/TownPiggy.png new file mode 100644 index 0000000000..7255ad1ca4 Binary files /dev/null and b/NPCs/TownNPCs/TownPiggy.png differ diff --git a/NPCs/TownNPCs/TownPiggy_Head.png b/NPCs/TownNPCs/TownPiggy_Head.png new file mode 100644 index 0000000000..4eee0bb14f Binary files /dev/null and b/NPCs/TownNPCs/TownPiggy_Head.png differ diff --git a/Packets/Entities/SyncTownPigLicensePacket.cs b/Packets/Entities/SyncTownPigLicensePacket.cs new file mode 100644 index 0000000000..0b9cff6f95 --- /dev/null +++ b/Packets/Entities/SyncTownPigLicensePacket.cs @@ -0,0 +1,20 @@ +using System.IO; +using CalamityMod.Items.SummonItems.TownPets; +using CalamityMod.NPCs.Abyss; +using Terraria; + +namespace CalamityMod.Packets +{ + internal sealed class SyncTownPigLicensePacket : CalamityPacket + { + public static SyncTownPigLicensePacket Instance { get; private set; } + + public static void Send(int toClient = -1, int ignoreClient = -1) + { + var packet = Instance.CreateBasePacket(); + packet.Send(toClient, ignoreClient); + } + + public override void HandlePacket(BinaryReader packet, int sender) => PiggyLicense.SpawnPiggy(); + } +} diff --git a/Systems/World/MiscWorldStateSystem.cs b/Systems/World/MiscWorldStateSystem.cs index ba62fb4ff6..e56491b6d0 100644 --- a/Systems/World/MiscWorldStateSystem.cs +++ b/Systems/World/MiscWorldStateSystem.cs @@ -56,6 +56,7 @@ namespace CalamityMod spawnedBandit = false; foundHomePermafrost = false; + unlockedTownPig = false; catName = false; dogName = false; @@ -92,6 +93,8 @@ namespace CalamityMod downed.Add("bandit"); if (foundHomePermafrost) downed.Add("archmageHome"); + if (unlockedTownPig) + downed.Add("townPig"); #region Save Pet Names if (catName) @@ -143,6 +146,7 @@ namespace CalamityMod AcidRainEvent.AcidRainEventIsOngoing = downed.Contains("acidRain"); spawnedBandit = downed.Contains("bandit"); foundHomePermafrost = downed.Contains("archmageHome"); + unlockedTownPig = downed.Contains("townPig"); #region Load Pet Names catName = downed.Contains("catName"); @@ -295,6 +299,7 @@ namespace CalamityMod flags12[2] = downedNuclearTerror; flags12[3] = downedBossRush; flags12[4] = DraedonMechdusa; + flags12[5] = unlockedTownPig; writer.Write(flags); writer.Write(flags2); @@ -449,6 +454,7 @@ namespace CalamityMod downedNuclearTerror = flags12[2]; downedBossRush = flags12[3]; DraedonMechdusa = flags12[4]; + unlockedTownPig = flags12[5]; RecipeUnlockHandler.ReceiveData(reader); diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index 8a789c3fd0..3ffb533837 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -79,6 +79,8 @@ namespace CalamityMod.World public static bool spawnedBandit = false; /// If true, the Archmage has lived in a house in this world. Solely used as a condition for dialogue. public static bool foundHomePermafrost = false; + /// If true, the Town Pig is able to move in. + public static bool unlockedTownPig = false; /// Used for allowing custom Town Cat patreon names. public static bool catName = false;