diff --git a/Buffs/Summon/MoonFistBuff.cs b/Buffs/Summon/MoonFistBuff.cs new file mode 100644 index 0000000000..d0de3b52a9 --- /dev/null +++ b/Buffs/Summon/MoonFistBuff.cs @@ -0,0 +1,34 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.DraedonsArsenal; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class MoonFistBuff : ModBuff + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Moon Fist"); + Description.SetDefault("Catch these hands"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.MoonFist = true; + + if (!modPlayer.MoonFist) + { + player.DelBuff(buffIndex); + buffIndex--; + } + else + player.buffTime[buffIndex] = 18000; + } + } +} diff --git a/Buffs/Summon/MoonFistBuff.png b/Buffs/Summon/MoonFistBuff.png new file mode 100644 index 0000000000..4f56b1091d Binary files /dev/null and b/Buffs/Summon/MoonFistBuff.png differ diff --git a/Buffs/Summon/PuffWarriorBuff.cs b/Buffs/Summon/PuffWarriorBuff.cs new file mode 100644 index 0000000000..4d02def7b0 --- /dev/null +++ b/Buffs/Summon/PuffWarriorBuff.cs @@ -0,0 +1,33 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Projectiles.Summon; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Summon +{ + public class PuffWarriorBuff : ModBuff + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Puff Warrior"); + Description.SetDefault("It confidently and excitedly protects you"); + Main.buffNoTimeDisplay[Type] = true; + Main.buffNoSave[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + CalamityPlayer modPlayer = player.Calamity(); + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + modPlayer.puffWarrior = true; + + if (modPlayer.puffWarrior) + player.buffTime[buffIndex] = 18000; + else + { + player.DelBuff(buffIndex); + buffIndex--; + } + } + } +} diff --git a/Buffs/Summon/PuffWarriorBuff.png b/Buffs/Summon/PuffWarriorBuff.png new file mode 100644 index 0000000000..354a7cfa73 Binary files /dev/null and b/Buffs/Summon/PuffWarriorBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 1577be6a62..22b5425f4c 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -938,6 +938,7 @@ namespace CalamityMod.CalPlayer public bool frostBlossom = false; public bool cinderBlossom = false; public bool belladonaSpirit = false; + public bool puffWarrior = false; public bool vileFeeder = false; public bool scabRipper = false; public bool midnightUFO = false; @@ -965,6 +966,7 @@ namespace CalamityMod.CalPlayer public bool eyeOfNight = false; public bool soulSeeker = false; public bool perditionBeacon = false; + public bool MoonFist = false; public bool AresCannons = false; public List PendingProjectilesToRespawn = new List(); @@ -1973,6 +1975,7 @@ namespace CalamityMod.CalPlayer frostBlossom = false; cinderBlossom = false; belladonaSpirit = false; + puffWarrior = false; vileFeeder = false; scabRipper = false; midnightUFO = false; @@ -2000,6 +2003,7 @@ namespace CalamityMod.CalPlayer eyeOfNight = false; soulSeeker = false; perditionBeacon = false; + MoonFist = false; AresCannons = false; disableVoodooSpawns = false; diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 1d2445d74e..9c9d5d0e92 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -16,6 +16,7 @@ using CalamityMod.EntitySources; using CalamityMod.Events; using CalamityMod.Items; using CalamityMod.Items.Accessories; +using CalamityMod.Items.Ammo; using CalamityMod.Items.Armor.Brimflame; using CalamityMod.Items.Armor.DesertProwler; using CalamityMod.Items.Armor.Silva; @@ -39,6 +40,7 @@ using CalamityMod.NPCs.NormalNPCs; using CalamityMod.NPCs.Other; using CalamityMod.NPCs.PlagueEnemies; using CalamityMod.NPCs.SupremeCalamitas; +using CalamityMod.NPCs.TownNPCs; using CalamityMod.Projectiles.Magic; using CalamityMod.Projectiles.Melee; using CalamityMod.Projectiles.Rogue; @@ -165,6 +167,9 @@ namespace CalamityMod.CalPlayer // Check if schematics are present on the mouse, for the sake of registering their recipes. CheckIfMouseItemIsSchematic(); + // Handle Androomba's Right Click function + AndroombaRightClick(); + // Update all particle sets for items. // This must be done here instead of in the item logic because these sets are not properly instanced // in the global classes. Attempting to update them there will cause multiple updates to one set for multiple items. @@ -520,7 +525,7 @@ namespace CalamityMod.CalPlayer // Allows the blazing aura to display if the accessory is vanity, but it deals no damage if (!blazingCursorDamage) - return; + return; // miscCounter is used to limit Calamity's hit rate. int framesPerHit = 60 / Calamity.HitsPerSecond; @@ -2450,7 +2455,7 @@ namespace CalamityMod.CalPlayer Player.statDefense += 20; Player.longInvince = true; Player.crimsonRegen = true; - healingPotBonus += 0.5f; + healingPotBonus += 0.5f; } // 50% movement speed bonus so that you don't feel like a snail in the early game. @@ -2855,10 +2860,10 @@ namespace CalamityMod.CalPlayer } if (bloodyWormTooth) - { + { Player.GetDamage() += 0.07f; - Player.GetAttackSpeed() += 0.07f; - } + Player.GetAttackSpeed() += 0.07f; + } if (filthyGlove) { @@ -3947,6 +3952,99 @@ namespace CalamityMod.CalPlayer } #endregion + #region Androomba Right Click + public void AndroombaRightClick() + { + if (Main.myPlayer != Player.whoAmI) + return; + + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC npc = Main.npc[i]; + if (npc is null || !npc.active) + return; + + bool holdingsol = ((Player.HeldItem.type >= ItemID.GreenSolution && Player.HeldItem.type <= ItemID.RedSolution) || Player.HeldItem.type == ModContent.ItemType()); + if (npc.Hitbox.Contains(Main.MouseWorld.ToPoint()) && holdingsol && Player.Distance(npc.Center) < 450) + { + Player.cursorItemIconEnabled = true; + Player.cursorItemIconID = Player.HeldItem.type; + Player.cursorItemIconText = ""; + npc.ShowNameOnHover = false; + + if (Main.mouseRight && Main.mouseRightRelease && Player.Distance(npc.Center) < 300) + { + npc.netUpdate = true; + + int soltype = 0; + if (Player.HeldItem.type == ModContent.ItemType()) + { + soltype = 5; + } + else + { + switch (Player.HeldItem.type) + { + case ItemID.GreenSolution: + soltype = 0; + break; + case ItemID.PurpleSolution: + soltype = 1; + break; + case ItemID.BlueSolution: + soltype = 2; + break; + case ItemID.DarkBlueSolution: + soltype = 3; + break; + case ItemID.RedSolution: + soltype = 4; + break; + } + } + if (npc.ai[3] != soltype || npc.ai[0] == 0) + { + Player.ConsumeItem(Player.HeldItem.type); + SoundEngine.PlaySound(SoundID.Item87); + if (Main.netMode == NetmodeID.SinglePlayer) + { + AndroombaFriendly.SwapSolution(npc.whoAmI, soltype); + } + else + { + var netMessage = Mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.SyncAndroombaSolution); + netMessage.Write(npc.whoAmI); + netMessage.Write(soltype); + netMessage.Send(); + } + if (npc.ai[0] == 0f) + { + if (Main.netMode == NetmodeID.SinglePlayer) + { + AndroombaFriendly.ChangeAI(npc.whoAmI, 1); + } + else + { + var netMessage = Mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.SyncAndroombaAI); + netMessage.Write(npc.whoAmI); + netMessage.Write(1); + netMessage.Send(); + } + } + if (Main.netMode == NetmodeID.Server) + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, i); + } + } + } + + else + npc.ShowNameOnHover = true; + } + } + #endregion + #region Potion Handling private void HandlePotions() { diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index 21d9595985..c0ec0cd579 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -3,6 +3,7 @@ using CalamityMod.Items; using CalamityMod.NPCs; using CalamityMod.NPCs.NormalNPCs; using CalamityMod.NPCs.Providence; +using CalamityMod.NPCs.TownNPCs; using CalamityMod.TileEntities; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -85,6 +86,18 @@ namespace CalamityMod if (Main.netMode != NetmodeID.MultiplayerClient) SuperDummy.DeleteDummies(); break; + case CalamityModMessageType.SyncAndroombaSolution: + int index = reader.ReadInt32(); + int solType = reader.ReadInt32(); + if (Main.netMode != NetmodeID.MultiplayerClient) + AndroombaFriendly.SwapSolution(index, solType); + break; + case CalamityModMessageType.SyncAndroombaAI: + int idx = reader.ReadInt32(); + int phase = reader.ReadInt32(); + if (Main.netMode != NetmodeID.MultiplayerClient) + AndroombaFriendly.ChangeAI(idx, phase); + break; case CalamityModMessageType.ServersideSpawnOldDuke: byte playerIndex2 = reader.ReadByte(); CalamityUtils.SpawnOldDuke(playerIndex2); @@ -313,6 +326,8 @@ namespace CalamityMod SyncCalamityNPCAIArray, SpawnSuperDummy, DeleteAllSuperDummies, + SyncAndroombaSolution, + SyncAndroombaAI, ServersideSpawnOldDuke, ArmoredDiggerCountdownSync, // TODO -- remove this mechanic entirely ProvidenceDyeConditionSync, // TODO -- this packetstorms if you hit Provi with spam weapons. It should ONLY send a packet if the status changes. diff --git a/Items/Critters/AndroombaItem.cs b/Items/Critters/AndroombaItem.cs new file mode 100644 index 0000000000..565323d392 --- /dev/null +++ b/Items/Critters/AndroombaItem.cs @@ -0,0 +1,36 @@ +using CalamityMod.NPCs.TownNPCs; +using CalamityMod.Rarities; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Critters +{ + public class AndroombaItem : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 5; + DisplayName.SetDefault("Androomba"); + Tooltip.SetDefault("Right click the roomba with a solution to insert it\n"+"While a solution is inserted, the roomba will start spreading its contents"); + } + + public override void SetDefaults() + { + Item.useStyle = ItemUseStyleID.Swing; + Item.autoReuse = true; + Item.useTurn = true; + Item.useAnimation = 25; + Item.useTime = 25; + Item.maxStack = 9999; + Item.consumable = true; + Item.noUseGraphic = true; + Item.value = Item.buyPrice(0, 0, 30, 0); + Item.width = 36; + Item.height = 16; + Item.makeNPC = (short)ModContent.NPCType(); + Item.rare = ModContent.RarityType(); + } + } +} diff --git a/Items/Critters/AndroombaItem.png b/Items/Critters/AndroombaItem.png new file mode 100644 index 0000000000..82ab4e0dbc Binary files /dev/null and b/Items/Critters/AndroombaItem.png differ diff --git a/Items/Critters/NanodroidDysfunctionalItem.cs b/Items/Critters/NanodroidDysfunctionalItem.cs new file mode 100644 index 0000000000..95fed65909 --- /dev/null +++ b/Items/Critters/NanodroidDysfunctionalItem.cs @@ -0,0 +1,34 @@ +using CalamityMod.NPCs.DraedonLabThings; +using CalamityMod.Rarities; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Critters +{ + public class NanodroidDysfunctionalItem : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 5; + DisplayName.SetDefault("Dysfunctional Nanodroid"); + } + + public override void SetDefaults() + { + Item.useStyle = ItemUseStyleID.Swing; + Item.autoReuse = true; + Item.useTurn = true; + Item.useAnimation = 15; + Item.useTime = 10; + Item.maxStack = 999; + Item.consumable = true; + Item.noUseGraphic = true; + Item.value = Item.buyPrice(0, 0, 30); + Item.width = 16; + Item.height = 10; + Item.makeNPC = (short)ModContent.NPCType(); + Item.rare = ModContent.RarityType(); + } + } +} diff --git a/Items/Critters/NanodroidDysfunctionalItem.png b/Items/Critters/NanodroidDysfunctionalItem.png new file mode 100644 index 0000000000..45b30b567f Binary files /dev/null and b/Items/Critters/NanodroidDysfunctionalItem.png differ diff --git a/Items/Critters/NanodroidItem.cs b/Items/Critters/NanodroidItem.cs new file mode 100644 index 0000000000..bea8a9f590 --- /dev/null +++ b/Items/Critters/NanodroidItem.cs @@ -0,0 +1,34 @@ +using CalamityMod.NPCs.DraedonLabThings; +using CalamityMod.Rarities; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Critters +{ + public class NanodroidItem : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 5; + DisplayName.SetDefault("Nanodroid"); + } + + public override void SetDefaults() + { + Item.useStyle = ItemUseStyleID.Swing; + Item.autoReuse = true; + Item.useTurn = true; + Item.useAnimation = 15; + Item.useTime = 10; + Item.maxStack = 999; + Item.consumable = true; + Item.noUseGraphic = true; + Item.value = Item.buyPrice(0, 0, 30); + Item.width = 16; + Item.height = 10; + Item.makeNPC = (short)ModContent.NPCType(); + Item.rare = ModContent.RarityType(); + } + } +} diff --git a/Items/Critters/NanodroidItem.png b/Items/Critters/NanodroidItem.png new file mode 100644 index 0000000000..a5e85a83bd Binary files /dev/null and b/Items/Critters/NanodroidItem.png differ diff --git a/Items/Critters/NanodroidPlagueGreenItem.cs b/Items/Critters/NanodroidPlagueGreenItem.cs new file mode 100644 index 0000000000..0f8c7343c2 --- /dev/null +++ b/Items/Critters/NanodroidPlagueGreenItem.cs @@ -0,0 +1,34 @@ +using CalamityMod.NPCs.DraedonLabThings; +using CalamityMod.Rarities; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Critters +{ + public class NanodroidPlagueGreenItem : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 5; + DisplayName.SetDefault("Green Plague Nanodroid"); + } + + public override void SetDefaults() + { + Item.useStyle = ItemUseStyleID.Swing; + Item.autoReuse = true; + Item.useTurn = true; + Item.useAnimation = 15; + Item.useTime = 10; + Item.maxStack = 999; + Item.consumable = true; + Item.noUseGraphic = true; + Item.value = Item.buyPrice(0, 0, 30); + Item.width = 16; + Item.height = 10; + Item.makeNPC = (short)ModContent.NPCType(); + Item.rare = ModContent.RarityType(); + } + } +} diff --git a/Items/Critters/NanodroidPlagueGreenItem.png b/Items/Critters/NanodroidPlagueGreenItem.png new file mode 100644 index 0000000000..ad42fbc338 Binary files /dev/null and b/Items/Critters/NanodroidPlagueGreenItem.png differ diff --git a/Items/Critters/NanodroidPlagueRedItem.cs b/Items/Critters/NanodroidPlagueRedItem.cs new file mode 100644 index 0000000000..2213d8e483 --- /dev/null +++ b/Items/Critters/NanodroidPlagueRedItem.cs @@ -0,0 +1,34 @@ +using CalamityMod.NPCs.DraedonLabThings; +using CalamityMod.Rarities; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Critters +{ + public class NanodroidPlagueRedItem : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 5; + DisplayName.SetDefault("Red Plague Nanodroid"); + } + + public override void SetDefaults() + { + Item.useStyle = ItemUseStyleID.Swing; + Item.autoReuse = true; + Item.useTurn = true; + Item.useAnimation = 15; + Item.useTime = 10; + Item.maxStack = 999; + Item.consumable = true; + Item.noUseGraphic = true; + Item.value = Item.buyPrice(0, 0, 30); + Item.width = 16; + Item.height = 10; + Item.makeNPC = (short)ModContent.NPCType(); + Item.rare = ModContent.RarityType(); + } + } +} diff --git a/Items/Critters/NanodroidPlagueRedItem.png b/Items/Critters/NanodroidPlagueRedItem.png new file mode 100644 index 0000000000..d94ddff161 Binary files /dev/null and b/Items/Critters/NanodroidPlagueRedItem.png differ diff --git a/Items/Weapons/Summon/PuffShroom.cs b/Items/Weapons/Summon/PuffShroom.cs new file mode 100644 index 0000000000..5218a9ab70 --- /dev/null +++ b/Items/Weapons/Summon/PuffShroom.cs @@ -0,0 +1,48 @@ +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class PuffShroom : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Puff Shroom"); + Tooltip.SetDefault("Summons a cute mushroom warrior to fight for you"); + } + + public override void SetDefaults() + { + Item.damage = 14; + Item.mana = 10; + Item.width = 32; + Item.height = 32; + Item.useTime = Item.useAnimation = 35; + Item.useStyle = ItemUseStyleID.Swing; + Item.noMelee = true; + Item.knockBack = 2f; + Item.value = CalamityGlobalItem.Rarity2BuyPrice; + Item.rare = ItemRarityID.Green; + Item.UseSound = SoundID.Item42; + Item.autoReuse = true; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 10f; + Item.DamageType = DamageClass.Summon; + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + if (player.altFunctionUse != 2) + { + int puffGuy = Projectile.NewProjectile(source, Main.MouseWorld, Vector2.Zero, type, damage, knockback, player.whoAmI); + if (Main.projectile.IndexInRange(puffGuy)) + Main.projectile[puffGuy].originalDamage = Item.damage; + } + return false; + } + } +} diff --git a/Items/Weapons/Summon/PuffShroom.png b/Items/Weapons/Summon/PuffShroom.png new file mode 100644 index 0000000000..3900cc431f Binary files /dev/null and b/Items/Weapons/Summon/PuffShroom.png differ diff --git a/Items/Weapons/Summon/WarloksMoonFist.cs b/Items/Weapons/Summon/WarloksMoonFist.cs new file mode 100644 index 0000000000..e304205ac6 --- /dev/null +++ b/Items/Weapons/Summon/WarloksMoonFist.cs @@ -0,0 +1,60 @@ +using Terraria.DataStructures; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Summon +{ + public class WarloksMoonFist : ModItem + { + public const int SlotCount = 4; + + public const int PunchCooldownTime = 36; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Warloks's Moon Fist"); + Tooltip.SetDefault("Summons a celestial fist to punch enemies for you\n" + + $"Takes up {SlotCount} minion slots"); + SacrificeTotal = 1; + } + + public override void SetDefaults() + { + Item.damage = 330; + Item.mana = 10; + Item.width = 50; + Item.height = 50; + Item.useTime = Item.useAnimation = 25; + Item.useStyle = ItemUseStyleID.Swing; + Item.noMelee = true; + Item.knockBack = 2f; + Item.value = CalamityGlobalItem.RarityPureGreenBuyPrice; + Item.rare = ItemRarityID.Purple; + Item.Calamity().customRarity = CalamityRarity.PureGreen; + Item.UseSound = SoundID.Item104; + Item.autoReuse = true; + Item.noUseGraphic = true; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 10f; + Item.DamageType = DamageClass.Summon; + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + if (player.altFunctionUse != 2) + { + int existingFists = player.ownedProjectileCounts[type]; + int p = Projectile.NewProjectile(source, Main.MouseWorld, Vector2.Zero, type, damage, knockback, player.whoAmI); + if (Main.projectile.IndexInRange(p)) + { + Main.projectile[p].originalDamage = Item.damage; + Main.projectile[p].ai[0] = existingFists; + } + } + return false; + } + } +} diff --git a/Items/Weapons/Summon/WarloksMoonFist.png b/Items/Weapons/Summon/WarloksMoonFist.png new file mode 100644 index 0000000000..75b87c2001 Binary files /dev/null and b/Items/Weapons/Summon/WarloksMoonFist.png differ diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index b8b544325e..41ae011d11 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -4800,6 +4800,7 @@ namespace CalamityMod.NPCs nearLab |= CalamityUtils.ManhattanDistance(checkPosition, CalamityWorld.JungleLabCenter / 16f) < 180f; nearLab |= CalamityUtils.ManhattanDistance(checkPosition, CalamityWorld.HellLabCenter / 16f) < 180f; nearLab |= CalamityUtils.ManhattanDistance(checkPosition, CalamityWorld.IceLabCenter / 16f) < 180f; + bool nearPlagueLab = CalamityUtils.ManhattanDistance(checkPosition, CalamityWorld.JungleLabCenter / 16f) < 180f; bool isLabWall = aboveSpawnTile.WallType == WallType() || aboveSpawnTile.WallType == WallType() || aboveSpawnTile.WallType == WallType(); isLabWall |= aboveSpawnTile.WallType == WallType() || aboveSpawnTile.WallType == WallType() || aboveSpawnTile.WallType == WallType(); @@ -4808,7 +4809,21 @@ namespace CalamityMod.NPCs WeightedRandom pool = new WeightedRandom(); pool.Add(NPCID.None, 0f); - pool.Add(NPCType(), 0.2f); + pool.Add(NPCType(), 0.025f); + pool.Add(NPCType(), 0.001f); + // Normal droids are replaced with plague droids in the Jungle Lab. + if (nearPlagueLab) + { + pool.Add(NPCType(), 0.025f); + pool.Add(NPCType(), 0.025f); + pool.Add(NPCType(), 0.02f); + } + else + { + pool.Add(NPCType(), 0.05f); + pool.Add(NPCType(), 0.05f); + } + int typeToSpawn = pool.Get(); if (typeToSpawn != NPCID.None) diff --git a/NPCs/DraedonLabThings/Androomba.cs b/NPCs/DraedonLabThings/Androomba.cs new file mode 100644 index 0000000000..2bd9af1e9d --- /dev/null +++ b/NPCs/DraedonLabThings/Androomba.cs @@ -0,0 +1,259 @@ +using CalamityMod.BiomeManagers; +using CalamityMod.Items.Critters; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.GameContent; +using Terraria.GameContent.Bestiary; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.DraedonLabThings +{ + public class Androomba : ModNPC + { + public SoundStyle HurrySound = new("CalamityMod/Sounds/Custom/WulfrumDroidHurry", 2) { PitchVariance = 0.3f }; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Androomba"); + Main.npcFrameCount[NPC.type] = 22; + NPCID.Sets.CountsAsCritter[NPC.type] = true; + Main.npcCatchable[NPC.type] = true; + NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); + } + + public override void SetDefaults() + { + NPC.aiStyle = -1; + AIType = -1; + NPC.damage = 0; + NPC.width = 40; + NPC.height = 16; + NPC.lifeMax = 80; + NPC.knockBackResist = 0f; + NPC.noGravity = true; + NPC.noTileCollide = false; + NPC.chaseable = false; + NPC.HitSound = SoundID.NPCHit4; + NPC.DeathSound = SoundID.NPCDeath44; + NPC.catchItem = (short)ModContent.ItemType(); + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + DrawOffsetY = -17; + } + + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { + + // Will move to localization whenever that is cleaned up. + new FlavorTextBestiaryInfoElement("Slowly moving back and forth, these contraptions operate endlessly with the fruitless goal of cleaning the now long abandoned labs.") + }); + } + + public override void AI() + { + // Gravity + NPC.velocity.Y = MathHelper.Clamp(NPC.velocity.Y + 0.4f, -15f, 15f); + NPC.spriteDirection = (int)NPC.ai[2]; + switch (NPC.ai[0]) + { + // Idle + case 0: + { + if (NPC.ai[1] == 0) + { + NPC.ai[2] = Main.rand.NextBool(2) ? -1 : 1; + } + NPC.ai[1]++; + NPC.velocity.X = NPC.ai[2] * 2; + if (!Collision.CanHit(NPC.Center - Vector2.UnitX * NPC.ai[2] * 8f, 2, 2, NPC.Center + Vector2.UnitX * NPC.ai[2] * 32f, 8, 8)) + { + NPC.ai[2] *= -1; + } + // If she sees someone, start running + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (Collision.CanHit(NPC.position, NPC.width, NPC.height, player.position, player.width, player.height)) + { + ChangeAI(1); + } + } + } + break; + // Surprise and explode animations + case 1: + case 3: + { + NPC.velocity.X = 0; + if (NPC.ai[1] == 0) + { + if (NPC.ai[0] == 1) + { + SoundEngine.PlaySound(HurrySound, NPC.Center); + } + if (NPC.ai[0] == 3) + { + NPC.catchItem = 0; + SoundEngine.PlaySound(NPC.DeathSound, NPC.Center); + } + } + NPC.ai[1]++; + } + break; + // Run!!! + case 2: + { + NPC.ai[1]++; + NPC.velocity.X = NPC.ai[2] * 4; + if (NPC.collideX) + { + ChangeAI(3); + } + else if (NPC.ai[1] > 480) // If the roomba is somehow still alive after 8 seconds and there are no players, calm down + { + for (int i = 0; i < Main.maxPlayers; i++) + { + if (!Collision.CanHit(NPC.position, NPC.width, NPC.height, Main.player[i].position, Main.player[i].width, Main.player[i].height)) + { + ChangeAI(0); + } + } + } + } + break; + // Fatal eror (corpse) + case 4: + { + NPC.velocity = Vector2.Zero; + NPC.ai[1]++; + if (NPC.ai[1] > 1200) + { + NPC.active = false; + } + NPC.damage = 10; // Stay aware from fire, kids + } + break; + } + + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (player is null || !player.active) + continue; + + if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) + { + Main.BestiaryTracker.Kills.RegisterKill(NPC); + break; + } + } + } + + public void ChangeAI(int phase) + { + NPC.ai[0] = phase; + NPC.ai[1] = 0; + NPC.netUpdate = true; + } + + public override bool? CanBeHitByItem(Player player, Item item) => null; + + public override bool? CanBeHitByProjectile(Projectile projectile) => null; + + public override void FindFrame(int frameHeight) + { + /* + -Frame 0: Idle + -Frames 1-4: Moving + -Frames 5-6: Surprised animation + -Frames 7-12: Escaping loop + -Frames 13-17: Exploding animation + -Frames 18-21: Debris loop + */ + NPC.frameCounter += 1.0; + if (NPC.frameCounter > 6.0) + { + NPC.frameCounter = 0.0; + NPC.frame.Y += frameHeight; + } + + // Idle + if (NPC.ai[0] == 0 || NPC.IsABestiaryIconDummy) + { + if (NPC.frame.Y > frameHeight * 4) + { + NPC.frameCounter = 0.0; + NPC.frame.Y = 1; + } + } + // Suprise! + else if (NPC.ai[0] == 1) + { + if (NPC.frame.Y < frameHeight * 5) + { + NPC.frameCounter = 0.0; + NPC.frame.Y = frameHeight * 5; + } + if (NPC.frame.Y > frameHeight * 6) + { + ChangeAI(2); + } + } + // Run + else if (NPC.ai[0] == 2) + { + if (NPC.frame.Y < frameHeight * 7 || NPC.frame.Y > frameHeight * 12) + { + NPC.frameCounter = 0.0; + NPC.frame.Y = frameHeight * 7; + } + } + // Explode + else if (NPC.ai[0] == 3) + { + if (NPC.frame.Y < frameHeight * 13) + { + NPC.frameCounter = 0.0; + NPC.frame.Y = frameHeight * 13; + } + if (NPC.frame.Y > frameHeight * 17) + { + ChangeAI(4); + } + } + // Fire + else + { + if (NPC.frame.Y < frameHeight * 18 || NPC.frame.Y > frameHeight * 21) + { + NPC.frameCounter = 0.0; + NPC.frame.Y = frameHeight * 18; + } + } + if (NPC.frame.Y >= frameHeight * 15 && NPC.active) + { + Lighting.AddLight(NPC.Center, 0.8f, 0.03f, 0.1f); + } + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int i = 0; i < 6; i++) + Dust.NewDustDirect(NPC.position, NPC.width, NPC.height, 226); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + Texture2D critterTexture = TextureAssets.Npc[NPC.type].Value; + Texture2D glowmask = ModContent.Request("CalamityMod/NPCs/DraedonLabThings/Androomba_Glow").Value; + Vector2 drawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + drawPosition.Y += DrawOffsetY; + SpriteEffects direction = NPC.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(critterTexture, drawPosition, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + spriteBatch.Draw(glowmask, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + return false; + } + } +} diff --git a/NPCs/DraedonLabThings/Androomba.png b/NPCs/DraedonLabThings/Androomba.png new file mode 100644 index 0000000000..6fde70d5f4 Binary files /dev/null and b/NPCs/DraedonLabThings/Androomba.png differ diff --git a/NPCs/DraedonLabThings/Androomba_Glow.png b/NPCs/DraedonLabThings/Androomba_Glow.png new file mode 100644 index 0000000000..c87224aa37 Binary files /dev/null and b/NPCs/DraedonLabThings/Androomba_Glow.png differ diff --git a/NPCs/DraedonLabThings/Nanodroid.cs b/NPCs/DraedonLabThings/Nanodroid.cs new file mode 100644 index 0000000000..33f330c15f --- /dev/null +++ b/NPCs/DraedonLabThings/Nanodroid.cs @@ -0,0 +1,78 @@ +using CalamityMod.BiomeManagers; +using CalamityMod.Items.Critters; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using Terraria.GameContent.Bestiary; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.DraedonLabThings +{ + public class Nanodroid : ModNPC + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Nanodroid"); + Main.npcFrameCount[NPC.type] = 8; + NPCID.Sets.CountsAsCritter[NPC.type] = true; + Main.npcCatchable[NPC.type] = true; + } + + public override void SetDefaults() + { + NPC.CloneDefaults(NPCID.LightningBug); + NPC.width = 16; + NPC.height = 12; + NPC.HitSound = SoundID.NPCHit4; + NPC.DeathSound = SoundID.NPCDeath44; + NPC.catchItem = (short)ModContent.ItemType(); + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + } + + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { + + // Will move to localization whenever that is cleaned up. + new FlavorTextBestiaryInfoElement("Not every creation has to be large and flashy to be a success, sometimes it's good to take a step back and appreciate how much that smaller things such as these devices contribute.") + }); + } + + public override void AI() + { + Lighting.AddLight(NPC.Center, 0.2f, 0.2f, 0.4f); + } + + public override bool? CanBeHitByItem(Player player, Item item) => null; + + public override bool? CanBeHitByProjectile(Projectile projectile) => null; + + public override void FindFrame(int frameHeight) + { + NPC.spriteDirection = NPC.direction; + NPC.frameCounter += 0.3f; + NPC.frameCounter %= Main.npcFrameCount[NPC.type]; + int frame = (int)NPC.frameCounter; + NPC.frame.Y = frame * frameHeight; + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int i = 0; i < 6; i++) + Dust.NewDustDirect(NPC.position, NPC.width, NPC.height, 226); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + Texture2D critterTexture = TextureAssets.Npc[NPC.type].Value; + Texture2D glowmask = ModContent.Request("CalamityMod/NPCs/DraedonLabThings/Nanodroid_Glow").Value; + Vector2 drawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + SpriteEffects direction = NPC.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(critterTexture, drawPosition, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + spriteBatch.Draw(glowmask, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + return false; + } + } +} diff --git a/NPCs/DraedonLabThings/Nanodroid.png b/NPCs/DraedonLabThings/Nanodroid.png new file mode 100644 index 0000000000..c7b96ffeb1 Binary files /dev/null and b/NPCs/DraedonLabThings/Nanodroid.png differ diff --git a/NPCs/DraedonLabThings/NanodroidDysfunctional.cs b/NPCs/DraedonLabThings/NanodroidDysfunctional.cs new file mode 100644 index 0000000000..dd53400a23 --- /dev/null +++ b/NPCs/DraedonLabThings/NanodroidDysfunctional.cs @@ -0,0 +1,84 @@ +using CalamityMod.Items.Critters; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.DraedonLabThings +{ + public class NanodroidDysfunctional : ModNPC + { + public override void SetStaticDefaults() + { + this.HideFromBestiary(); + DisplayName.SetDefault("Nanodroid"); + Main.npcFrameCount[NPC.type] = 8; + NPCID.Sets.CountsAsCritter[NPC.type] = true; + Main.npcCatchable[NPC.type] = true; + } + + public override void SetDefaults() + { + NPC.CloneDefaults(NPCID.LightningBug); + NPC.width = 16; + NPC.height = 12; + NPC.HitSound = SoundID.NPCHit4; + NPC.DeathSound = SoundID.NPCDeath44; + NPC.catchItem = (short)ModContent.ItemType(); + } + + public override void AI() + { + if (NPC.localAI[2] > 3f) + { + Lighting.AddLight(NPC.Center, 0.25f, 0.1f, 0f); + } + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (player is null || !player.active) + continue; + + if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) + { + NPC nPC = new NPC(); + nPC.SetDefaults(ModContent.NPCType()); + Main.BestiaryTracker.Sights.RegisterWasNearby(nPC); + break; + } + } + } + + public override bool? CanBeHitByItem(Player player, Item item) => null; + + public override bool? CanBeHitByProjectile(Projectile projectile) => null; + + public override void FindFrame(int frameHeight) + { + NPC.spriteDirection = NPC.direction; + NPC.frameCounter += 0.3f; + NPC.frameCounter %= Main.npcFrameCount[NPC.type]; + int frame = (int)NPC.frameCounter; + NPC.frame.Y = frame * frameHeight; + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int i = 0; i < 6; i++) + Dust.NewDustDirect(NPC.position, NPC.width, NPC.height, 226); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + Texture2D critterTexture = TextureAssets.Npc[NPC.type].Value; + Texture2D glowmask = ModContent.Request("CalamityMod/NPCs/DraedonLabThings/NanodroidDysfunctional_Glow").Value; + Vector2 drawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + SpriteEffects direction = NPC.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(critterTexture, drawPosition, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + spriteBatch.Draw(glowmask, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + return false; + } + } +} diff --git a/NPCs/DraedonLabThings/NanodroidDysfunctional.png b/NPCs/DraedonLabThings/NanodroidDysfunctional.png new file mode 100644 index 0000000000..425918f9b5 Binary files /dev/null and b/NPCs/DraedonLabThings/NanodroidDysfunctional.png differ diff --git a/NPCs/DraedonLabThings/NanodroidDysfunctional_Glow.png b/NPCs/DraedonLabThings/NanodroidDysfunctional_Glow.png new file mode 100644 index 0000000000..f669b79c3e Binary files /dev/null and b/NPCs/DraedonLabThings/NanodroidDysfunctional_Glow.png differ diff --git a/NPCs/DraedonLabThings/NanodroidPlagueGreen.cs b/NPCs/DraedonLabThings/NanodroidPlagueGreen.cs new file mode 100644 index 0000000000..29f75f5f61 --- /dev/null +++ b/NPCs/DraedonLabThings/NanodroidPlagueGreen.cs @@ -0,0 +1,84 @@ +using CalamityMod.Items.Critters; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.DraedonLabThings +{ + public class NanodroidPlagueGreen : ModNPC + { + public override void SetStaticDefaults() + { + this.HideFromBestiary(); + DisplayName.SetDefault("Nanodroid"); + Main.npcFrameCount[NPC.type] = 8; + NPCID.Sets.CountsAsCritter[NPC.type] = true; + Main.npcCatchable[NPC.type] = true; + } + + public override void SetDefaults() + { + NPC.CloneDefaults(NPCID.LightningBug); + NPC.width = 16; + NPC.height = 12; + NPC.HitSound = SoundID.NPCHit4; + NPC.DeathSound = SoundID.NPCDeath44; + NPC.catchItem = (short)ModContent.ItemType(); + } + + public override void AI() + { + if (NPC.localAI[2] > 3f) + { + Lighting.AddLight(NPC.Center, 0.03f, 0.3f, 0.05f); + } + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (player is null || !player.active) + continue; + + if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) + { + NPC nPC = new NPC(); + nPC.SetDefaults(ModContent.NPCType()); + Main.BestiaryTracker.Sights.RegisterWasNearby(nPC); + break; + } + } + } + + public override bool? CanBeHitByItem(Player player, Item item) => null; + + public override bool? CanBeHitByProjectile(Projectile projectile) => null; + + public override void FindFrame(int frameHeight) + { + NPC.spriteDirection = NPC.direction; + NPC.frameCounter += 0.3f; + NPC.frameCounter %= Main.npcFrameCount[NPC.type]; + int frame = (int)NPC.frameCounter; + NPC.frame.Y = frame * frameHeight; + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int i = 0; i < 6; i++) + Dust.NewDustDirect(NPC.position, NPC.width, NPC.height, 226); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + Texture2D critterTexture = TextureAssets.Npc[NPC.type].Value; + Texture2D glowmask = ModContent.Request("CalamityMod/NPCs/DraedonLabThings/NanodroidPlagueGreen_Glow").Value; + Vector2 drawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + SpriteEffects direction = NPC.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(critterTexture, drawPosition, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + spriteBatch.Draw(glowmask, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + return false; + } + } +} diff --git a/NPCs/DraedonLabThings/NanodroidPlagueGreen.png b/NPCs/DraedonLabThings/NanodroidPlagueGreen.png new file mode 100644 index 0000000000..62353a847e Binary files /dev/null and b/NPCs/DraedonLabThings/NanodroidPlagueGreen.png differ diff --git a/NPCs/DraedonLabThings/NanodroidPlagueGreen_Glow.png b/NPCs/DraedonLabThings/NanodroidPlagueGreen_Glow.png new file mode 100644 index 0000000000..bc451b69e1 Binary files /dev/null and b/NPCs/DraedonLabThings/NanodroidPlagueGreen_Glow.png differ diff --git a/NPCs/DraedonLabThings/NanodroidPlagueRed.cs b/NPCs/DraedonLabThings/NanodroidPlagueRed.cs new file mode 100644 index 0000000000..4c494fde59 --- /dev/null +++ b/NPCs/DraedonLabThings/NanodroidPlagueRed.cs @@ -0,0 +1,84 @@ +using CalamityMod.Items.Critters; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.DraedonLabThings +{ + public class NanodroidPlagueRed : ModNPC + { + public override void SetStaticDefaults() + { + this.HideFromBestiary(); + DisplayName.SetDefault("Nanodroid"); + Main.npcFrameCount[NPC.type] = 8; + NPCID.Sets.CountsAsCritter[NPC.type] = true; + Main.npcCatchable[NPC.type] = true; + } + + public override void SetDefaults() + { + NPC.CloneDefaults(NPCID.LightningBug); + NPC.width = 16; + NPC.height = 12; + NPC.HitSound = SoundID.NPCHit4; + NPC.DeathSound = SoundID.NPCDeath44; + NPC.catchItem = (short)ModContent.ItemType(); + } + + public override void AI() + { + if (NPC.localAI[2] > 3f) + { + Lighting.AddLight(NPC.Center, 0.3f, 0.03f, 0f); + } + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (player is null || !player.active) + continue; + + if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) + { + NPC nPC = new NPC(); + nPC.SetDefaults(ModContent.NPCType()); + Main.BestiaryTracker.Sights.RegisterWasNearby(nPC); + break; + } + } + } + + public override bool? CanBeHitByItem(Player player, Item item) => null; + + public override bool? CanBeHitByProjectile(Projectile projectile) => null; + + public override void FindFrame(int frameHeight) + { + NPC.spriteDirection = NPC.direction; + NPC.frameCounter += 0.3f; + NPC.frameCounter %= Main.npcFrameCount[NPC.type]; + int frame = (int)NPC.frameCounter; + NPC.frame.Y = frame * frameHeight; + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int i = 0; i < 6; i++) + Dust.NewDustDirect(NPC.position, NPC.width, NPC.height, 226); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + Texture2D critterTexture = TextureAssets.Npc[NPC.type].Value; + Texture2D glowmask = ModContent.Request("CalamityMod/NPCs/DraedonLabThings/NanodroidPlagueRed_Glow").Value; + Vector2 drawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + SpriteEffects direction = NPC.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(critterTexture, drawPosition, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + spriteBatch.Draw(glowmask, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + return false; + } + } +} diff --git a/NPCs/DraedonLabThings/NanodroidPlagueRed.png b/NPCs/DraedonLabThings/NanodroidPlagueRed.png new file mode 100644 index 0000000000..3fe30d653e Binary files /dev/null and b/NPCs/DraedonLabThings/NanodroidPlagueRed.png differ diff --git a/NPCs/DraedonLabThings/NanodroidPlagueRed_Glow.png b/NPCs/DraedonLabThings/NanodroidPlagueRed_Glow.png new file mode 100644 index 0000000000..7a5b6df398 Binary files /dev/null and b/NPCs/DraedonLabThings/NanodroidPlagueRed_Glow.png differ diff --git a/NPCs/DraedonLabThings/Nanodroid_Glow.png b/NPCs/DraedonLabThings/Nanodroid_Glow.png new file mode 100644 index 0000000000..8367fc1715 Binary files /dev/null and b/NPCs/DraedonLabThings/Nanodroid_Glow.png differ diff --git a/NPCs/DraedonLabThings/RepairUnitCritter.cs b/NPCs/DraedonLabThings/RepairUnitCritter.cs index efc179de13..a22735ebf7 100644 --- a/NPCs/DraedonLabThings/RepairUnitCritter.cs +++ b/NPCs/DraedonLabThings/RepairUnitCritter.cs @@ -124,6 +124,19 @@ namespace CalamityMod.NPCs.DraedonLabThings break; } Time++; + + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (player is null || !player.active) + continue; + + if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) + { + Main.BestiaryTracker.Kills.RegisterKill(NPC); + break; + } + } } public void WalkAroundOnGround() diff --git a/NPCs/NormalNPCs/Piggy.cs b/NPCs/NormalNPCs/Piggy.cs index ed38f0d9a4..95357c79b4 100644 --- a/NPCs/NormalNPCs/Piggy.cs +++ b/NPCs/NormalNPCs/Piggy.cs @@ -46,6 +46,24 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.Calamity().VulnerableToSickness = true; } + public override void AI() + { + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (player is null || !player.active) + continue; + + if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) + { + NPC nPC = new NPC(); + nPC.SetDefaults(ModContent.NPCType()); + Main.BestiaryTracker.Kills.RegisterKill(nPC); + break; + } + } + } + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { diff --git a/NPCs/TownNPCs/AndroombaFriendly.cs b/NPCs/TownNPCs/AndroombaFriendly.cs new file mode 100644 index 0000000000..68c0945c1c --- /dev/null +++ b/NPCs/TownNPCs/AndroombaFriendly.cs @@ -0,0 +1,271 @@ +using CalamityMod.BiomeManagers; +using CalamityMod.Items.Critters; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System.Collections.Generic; +using System.IO; +using Terraria; +using Terraria.Audio; +using Terraria.GameContent; +using Terraria.GameContent.Bestiary; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.TownNPCs +{ + public class AndroombaFriendly : ModNPC + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Androomba Pal"); + Main.npcFrameCount[NPC.type] = 9; + Main.npcCatchable[NPC.type] = true; + } + + public override void SetDefaults() + { + NPC.aiStyle = -1; + AIType = -1; + NPC.damage = 0; + NPC.width = 36; + NPC.height = 16; + NPC.lifeMax = 80; + NPC.friendly = true; + NPC.townNPC = true; + NPC.knockBackResist = 0f; + NPC.noGravity = true; + NPC.noTileCollide = false; + NPC.chaseable = false; + NPC.HitSound = SoundID.NPCHit4; + NPC.DeathSound = SoundID.NPCDeath44; + NPC.catchItem = (short)ModContent.ItemType(); + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + NPC.dontTakeDamage = true; + } + + public override bool CanChat() => false; + + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { + // Will move to localization whenever that is cleaned up. + new FlavorTextBestiaryInfoElement("Easily reversed engineered, these robots can be made to spread whatever you put into them, giving them a new purpose.") + }); + } + + public override void AI() + { + // Gravity + NPC.velocity.Y = MathHelper.Clamp(NPC.velocity.Y + 0.4f, -15f, 15f); + NPC.spriteDirection = (int)NPC.ai[2]; + switch (NPC.ai[0]) + { + case 0: + { + if (NPC.ai[1] == 0) + { + Player closest = Main.player[Player.FindClosest(NPC.position, 9999, 9999)]; + NPC.ai[2] = (closest.position.X <= NPC.position.X) ? 1 : -1; + } + } + break; + // Main + case 1: + { + NPC.ai[1]++; + NPC.velocity.X = NPC.ai[2] * 2; + if (!Collision.CanHit(NPC.Center - Vector2.UnitX * NPC.ai[2] * 8f, 2, 2, NPC.Center + Vector2.UnitX * NPC.ai[2] * 32f, 8, 8)) + { + ChangeAIHook(2); + } + Convert((int)NPC.ai[3]); + } + break; + // Turn + case 2: + { + NPC.velocity.X = 0; + Convert((int)NPC.ai[3]); + } + break; + } + + for (int i = 0; i < Main.maxPlayers; i++) + { + Player player = Main.player[i]; + if (player is null || !player.active) + continue; + + if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) + { + Main.BestiaryTracker.Chats.RegisterChatStartWith(NPC); + break; + } + } + } + + public void Convert(int conversionType) + { + int x = (int)(NPC.Center.X / 16f); + int y = (int)(NPC.Center.Y / 16f); + if (conversionType <= 4) + { + ConvertType type = ConvertType.Pure; + switch (conversionType) + { + case 0: + type = ConvertType.Pure; + break; + case 1: + type = ConvertType.Corrupt; + break; + case 2: + type = ConvertType.Hallow; + break; + case 4: + type = ConvertType.Crimson; + break; + } + AstralBiome.ConvertFromAstral(x - 2, x + 2, y - 2, y + 2, type); + WorldGen.Convert(x, y, conversionType, 2); + } + else + { + AstralBiome.ConvertToAstral(x - 2, x + 2, y - 2, y + 2); + } + } + + public void ChangeAIHook(int phase) + { + if (Main.netMode == NetmodeID.SinglePlayer) + { + ChangeAI(NPC.whoAmI, phase); + } + else + { + var netMessage = Mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.SyncAndroombaAI); + netMessage.Write(NPC.whoAmI); + netMessage.Write(phase); + netMessage.Send(); + } + } + + public static void ChangeAI(int index, int phase) + { + NPC npc = Main.npc[index]; + + if (npc is null || !npc.active) + return; + + npc.ai[0] = phase; + npc.ai[1] = 0; + npc.netUpdate = true; + if (Main.netMode == NetmodeID.Server) + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, index); + } + + public static void SwapSolution(int index, int solutionType) + { + NPC npc = Main.npc[index]; + + if (npc is null || !npc.active) + return; + + npc.ai[3] = solutionType; + npc.netUpdate = true; + if (Main.netMode == NetmodeID.Server) + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, index); + } + + public override bool? CanBeHitByItem(Player player, Item item) => null; + + public override bool? CanBeHitByProjectile(Projectile projectile) => null; + + public override void FindFrame(int frameHeight) + { + /* + -Frame 0: Asleep + -Frames 1-4: Moving + -Frames 5-9: Turning + */ + NPC.frameCounter += 1.0; + if (NPC.frameCounter > 6.0) + { + NPC.frameCounter = 0.0; + NPC.frame.Y += frameHeight; + } + + // Idle + if (NPC.ai[0] == 1 || NPC.IsABestiaryIconDummy) + { + if (NPC.frame.Y > frameHeight * 4) + { + NPC.frameCounter = 0.0; + NPC.frame.Y = frameHeight; + } + } + // Turnaround + else if (NPC.ai[0] == 2) + { + if (NPC.frame.Y < frameHeight * 5) + { + NPC.frameCounter = 0.0; + NPC.frame.Y = frameHeight * 5; + } + if (NPC.frame.Y > frameHeight * 8) + { + NPC.frame.Y = frameHeight; + NPC.ai[2] *= -1; + ChangeAIHook(1); + } + } + // Sleep + else + { + NPC.frame.Y = 0; + } + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int i = 0; i < 6; i++) + Dust.NewDustDirect(NPC.position, NPC.width, NPC.height, 226); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + Texture2D critterTexture = TextureAssets.Npc[NPC.type].Value; + string pathextenstion = "Pure"; + switch (NPC.ai[3]) + { + case 0: + pathextenstion = "Pure"; + break; + case 1: + pathextenstion = "Corruption"; + break; + case 2: + pathextenstion = "Hallow"; + break; + case 3: + pathextenstion = "Mushroom"; + break; + case 4: + pathextenstion = "Crimson"; + break; + case 5: + pathextenstion = "Astral"; + break; + } + Texture2D glowmask = ModContent.Request("CalamityMod/NPCs/TownNPCs/AndroombaFriendly_" + pathextenstion).Value; + Vector2 drawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + drawPosition.Y += DrawOffsetY; + SpriteEffects direction = NPC.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + spriteBatch.Draw(critterTexture, drawPosition, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + spriteBatch.Draw(glowmask, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, direction, 0f); + return false; + } + } +} diff --git a/NPCs/TownNPCs/AndroombaFriendly.png b/NPCs/TownNPCs/AndroombaFriendly.png new file mode 100644 index 0000000000..6ce44bc163 Binary files /dev/null and b/NPCs/TownNPCs/AndroombaFriendly.png differ diff --git a/NPCs/TownNPCs/AndroombaFriendly_Astral.png b/NPCs/TownNPCs/AndroombaFriendly_Astral.png new file mode 100644 index 0000000000..77b257df5b Binary files /dev/null and b/NPCs/TownNPCs/AndroombaFriendly_Astral.png differ diff --git a/NPCs/TownNPCs/AndroombaFriendly_Corruption.png b/NPCs/TownNPCs/AndroombaFriendly_Corruption.png new file mode 100644 index 0000000000..d95047a0fc Binary files /dev/null and b/NPCs/TownNPCs/AndroombaFriendly_Corruption.png differ diff --git a/NPCs/TownNPCs/AndroombaFriendly_Crimson.png b/NPCs/TownNPCs/AndroombaFriendly_Crimson.png new file mode 100644 index 0000000000..c050371364 Binary files /dev/null and b/NPCs/TownNPCs/AndroombaFriendly_Crimson.png differ diff --git a/NPCs/TownNPCs/AndroombaFriendly_Hallow.png b/NPCs/TownNPCs/AndroombaFriendly_Hallow.png new file mode 100644 index 0000000000..2a91270657 Binary files /dev/null and b/NPCs/TownNPCs/AndroombaFriendly_Hallow.png differ diff --git a/NPCs/TownNPCs/AndroombaFriendly_Mushroom.png b/NPCs/TownNPCs/AndroombaFriendly_Mushroom.png new file mode 100644 index 0000000000..8fb03ced68 Binary files /dev/null and b/NPCs/TownNPCs/AndroombaFriendly_Mushroom.png differ diff --git a/NPCs/TownNPCs/AndroombaFriendly_Pure.png b/NPCs/TownNPCs/AndroombaFriendly_Pure.png new file mode 100644 index 0000000000..330bda78a5 Binary files /dev/null and b/NPCs/TownNPCs/AndroombaFriendly_Pure.png differ diff --git a/Projectiles/Summon/MoonFist.cs b/Projectiles/Summon/MoonFist.cs new file mode 100644 index 0000000000..962f0947ee --- /dev/null +++ b/Projectiles/Summon/MoonFist.cs @@ -0,0 +1,251 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Audio; +using CalamityMod.Items.Weapons.Summon; +using CalamityMod.Buffs.Summon; +using System.IO; +using Terraria.GameContent.Drawing; +using CalamityMod.Dusts; + +namespace CalamityMod.Projectiles.Summon +{ + public class MoonFist : ModProjectile + { + public int DelayUntilNextPunch; + + public int FistIndex => (int)Projectile.ai[0]; + + public ref float AttackTimer => ref Projectile.ai[1]; + + public ref float FrameTimer => ref Projectile.localAI[0]; + + public float FistInterpolant + { + get + { + float projectileCounts = Owner.ownedProjectileCounts[Type]; + + // Use a midway interpolant if the projectile count is one. This makes the fist use middle positions instead of + // sitting awkwardly to the left. + if (projectileCounts <= 1f) + return 0.5f; + + return FistIndex / (projectileCounts - 1f); + } + } + + public Player Owner => Main.player[Projectile.owner]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Cosmic Fist"); + Main.projFrames[Type] = 18; + ProjectileID.Sets.MinionSacrificable[Projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true; + } + + public override void SetDefaults() + { + Projectile.width = 48; + Projectile.height = 48; + Projectile.minion = true; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.netImportant = true; + Projectile.alpha = 255; + Projectile.minionSlots = WarloksMoonFist.SlotCount; + Projectile.penetrate = -1; + Projectile.MaxUpdates = 2; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = Projectile.MaxUpdates * 10; + Projectile.netImportant = true; + Projectile.timeLeft = 90000; + Projectile.DamageType = DamageClass.Summon; + } + + public override void SendExtraAI(BinaryWriter writer) => writer.Write(DelayUntilNextPunch); + + public override void ReceiveExtraAI(BinaryReader reader) => DelayUntilNextPunch = reader.ReadInt32(); + + public override void AI() + { + ApplyMinionBuffs(); + + NPC potentialTarget = Owner.Center.ClosestNPCAt(1650f); + if (potentialTarget is null) + HoverNearOwner(); + else + AttackTarget(potentialTarget); + + FrameTimer++; + Projectile.frameCounter++; + if (DelayUntilNextPunch > 0) + DelayUntilNextPunch--; + + // Fade in. + Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity + 0.1f, 0f, 1f); + } + + public void ApplyMinionBuffs() + { + // Maintain or remove the Mechworm buff from the owner. + Owner.AddBuff(ModContent.BuffType(), 3600); + if (Owner.dead) + Owner.Calamity().MoonFist = false; + if (Owner.Calamity().MoonFist) + Projectile.timeLeft = 2; + } + + public void HoverNearOwner() + { + float hoverOffsetAngle = MathHelper.Lerp(-MathHelper.PiOver2, MathHelper.PiOver2, FistInterpolant); + Vector2 hoverDestination = Owner.Center - Vector2.UnitY.RotatedBy(hoverOffsetAngle) * (Owner.height + 70f); + Projectile.velocity *= 0.7f; + Projectile.Center = Vector2.Lerp(Projectile.Center, hoverDestination, 0.13333f); + + // Use idle frames. + float frameInterpolant = (FrameTimer / 50f + FistInterpolant) % 1f; + Projectile.frame = (int)Math.Round(MathHelper.Lerp(0f, 5f, frameInterpolant)); + + // Determine direction and rotation. + Projectile.rotation = Projectile.rotation.AngleTowards(0f, 0.333f); + Projectile.spriteDirection = Owner.direction; + + // Reset the attack timer. + AttackTimer = 0f; + } + + public void AttackTarget(NPC target) + { + int reelBackTime = 32; + int homeDelay = 27; + int attackTime = 150; + int attackCycleInterval = reelBackTime + attackTime; + + // Teleport to the enemy if it's far away. + if (!Projectile.WithinRange(target.Center, 1200f)) + { + Vector2 teleportDestination = target.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(250f, 300f); + DoTeleport(teleportDestination); + } + + Projectile.rotation = Projectile.AngleTo(target.Center); + Projectile.spriteDirection = (target.Center.X < Projectile.Center.X).ToDirectionInt(); + if (Projectile.spriteDirection == -1) + Projectile.rotation += MathHelper.Pi; + + // Clench the fist and hover near the target. + if (AttackTimer <= reelBackTime) + { + Projectile.frame = (int)Math.Round(MathHelper.Lerp(6f, 11f, AttackTimer / reelBackTime)); + + // Reel back and look at the target. + float hoverOffset = MathHelper.Lerp(200f, 480f, AttackTimer / reelBackTime); + hoverOffset += MathHelper.Lerp(-10f, 75f, Projectile.identity % 9f / 1f); + float spin = MathHelper.Lerp(-0.27f, 0.27f, Projectile.identity / 7f % 1f); + Vector2 hoverDestination = target.Center - target.SafeDirectionTo(target.Center, Vector2.UnitY).RotatedBy(spin) * hoverOffset; + Vector2 idealVelocity = Projectile.SafeDirectionTo(hoverDestination) * MathHelper.Min(25f, Projectile.Distance(hoverDestination)); + + Projectile.Center = Vector2.Lerp(Projectile.Center, hoverDestination, 0.02f); + Projectile.velocity = Vector2.Lerp(Projectile.velocity, idealVelocity, 0.03f).MoveTowards(idealVelocity, 0.5f); + + // Fly towards the target at an incredibly fast speed. + if (AttackTimer == reelBackTime) + { + SoundEngine.PlaySound(SoundID.DD2_WyvernDiveDown, Projectile.Center); + Projectile.velocity = CalamityUtils.CalculatePredictiveAimToTarget(Projectile.Center, target, 40f); + Projectile.netUpdate = true; + } + } + else if (DelayUntilNextPunch <= 0) + { + // Home towards the target briefly after the initial charge. + if (AttackTimer >= reelBackTime + homeDelay) + Projectile.velocity = Projectile.SuperhomeTowardsTarget(target, 34f, 24f); + } + + // Increment the attack timer. + AttackTimer = (AttackTimer + 1f) % attackCycleInterval; + } + + public void DoTeleport(Vector2 end) + { + Vector2 start = Projectile.Center; + for (int i = 0; i < 75; i++) + { + Vector2 dustDrawPosition = Vector2.Lerp(start, end, i / 74f); + + Dust magic = Dust.NewDustPerfect(dustDrawPosition, 267); + magic.velocity = -Vector2.UnitY * Main.rand.NextFloat(0.2f, 0.235f); + magic.color = Color.LightCyan; + magic.color.A = 0; + magic.scale = 0.8f; + magic.fadeIn = 1.4f; + magic.noGravity = true; + } + + if (Main.netMode == NetmodeID.MultiplayerClient) + return; + + for (int i = 0; i < 6; i++) + { + int magic = Projectile.NewProjectile(Projectile.GetSource_FromAI(), start, Vector2.Zero, ModContent.ProjectileType(), 0, 0f); + Main.projectile[magic].timeLeft -= i * 2; + magic = Projectile.NewProjectile(Projectile.GetSource_FromAI(), end, Vector2.Zero, ModContent.ProjectileType(), 0, 0f); + Main.projectile[magic].timeLeft -= i * 2; + } + Projectile.Center = end; + Projectile.netUpdate = true; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + // Rebound on collision. + if (DelayUntilNextPunch > 0 || AttackTimer <= 0f) + return; + + // Create some cool particles to go with the hit. + Vector2 impactPoint = Vector2.Lerp(Projectile.Center, target.Hitbox.ClosestPointInRect(Projectile.Center), 0.5f); + for (int i = 0; i < 7; i++) + { + ParticleOrchestrator.RequestParticleSpawn(false, ParticleOrchestraType.StardustPunch, new() + { + PositionInWorld = impactPoint + Vector2.UnitY * Main.rand.NextFloatDirection() * 10f, + MovementVector = Main.rand.NextVector2Unit() * Main.rand.NextFloat(3f, 9.6f) + }); + } + for (int i = 0; i < 15; i++) + { + int dustID = Main.rand.NextBool() ? (int)CalamityDusts.BlueCosmilite : (int)CalamityDusts.PurpleCosmilite; + + Dust cosmicDust = Dust.NewDustPerfect(impactPoint + Main.rand.NextVector2Circular(10f, 10f), dustID); + cosmicDust.velocity = Projectile.velocity.RotatedByRandom(0.6f) * 0.2f; + cosmicDust.scale = Main.rand.NextFloat(1f, 1.4f); + cosmicDust.noGravity = true; + if (Main.rand.NextBool(5)) + cosmicDust.scale += 0.45f; + } + + SoundEngine.PlaySound(SoundID.Item74 with { Pitch = -0.36f }, Projectile.Center); + DelayUntilNextPunch = WarloksMoonFist.PunchCooldownTime - 10; + Projectile.velocity = Projectile.SafeDirectionTo(target.Center, -Vector2.UnitY).RotatedBy(0.16f) * Projectile.velocity.Length() * -0.45f; + Projectile.netUpdate = true; + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + Rectangle frame = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, direction, 0); + return false; + } + } +} diff --git a/Projectiles/Summon/MoonFist.png b/Projectiles/Summon/MoonFist.png new file mode 100644 index 0000000000..5e74b5957e Binary files /dev/null and b/Projectiles/Summon/MoonFist.png differ diff --git a/Projectiles/Summon/MoonFistTeleportVisual.cs b/Projectiles/Summon/MoonFistTeleportVisual.cs new file mode 100644 index 0000000000..ed4e267d83 --- /dev/null +++ b/Projectiles/Summon/MoonFistTeleportVisual.cs @@ -0,0 +1,69 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System.Collections.Generic; +using Terraria; +using Terraria.GameContent; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class MoonFistTeleportVisual : ModProjectile + { + public override void SetStaticDefaults() => DisplayName.SetDefault("Light"); + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 2; + Projectile.tileCollide = false; + Projectile.ignoreWater = true; + Projectile.hide = true; + Projectile.timeLeft = 45; + Projectile.MaxUpdates = 2; + Projectile.penetrate = -1; + } + + public override void AI() + { + Projectile.Opacity = Utils.GetLerpValue(0f, 12f, Projectile.timeLeft); + Projectile.scale = Utils.GetLerpValue(45f, 5f, Projectile.timeLeft); + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D telegraphTexture = TextureAssets.Projectile[Projectile.type].Value; + Color telegraphColor = Color.White * Projectile.Opacity * 0.2f; + telegraphColor.A = 0; + + for (int i = 0; i < 35; i++) + { + Vector2 drawPosition = Projectile.Center + (MathHelper.TwoPi * i / 5f + Main.GlobalTimeWrappedHourly * 3f).ToRotationVector2() * 2f; + drawPosition -= Main.screenPosition; + + Vector2 scale = new Vector2(0.58f, 1f) * Projectile.scale; + scale *= MathHelper.Lerp(0.015f, 1f, i / 35f); + + Main.spriteBatch.Draw(telegraphTexture, drawPosition, null, telegraphColor, 0f, telegraphTexture.Size() * 0.5f, scale, 0, 0f); + } + return false; + } + + public override void Kill(int timeLeft) + { + for (int i = 0; i < 20; i++) + { + Dust magic = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(30f, 30f), 267); + magic.color = Color.SkyBlue; + magic.scale = 1.1f; + magic.fadeIn = 0.6f; + magic.velocity = Main.rand.NextVector2Circular(2f, 2f); + magic.velocity = Vector2.Lerp(magic.velocity, -Vector2.UnitY * magic.velocity.Length(), Main.rand.NextFloat(0.65f, 1f)); + magic.noGravity = true; + } + } + + public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) + { + behindNPCsAndTiles.Add(index); + } + } +} diff --git a/Projectiles/Summon/MoonFistTeleportVisual.png b/Projectiles/Summon/MoonFistTeleportVisual.png new file mode 100644 index 0000000000..f51029ba21 Binary files /dev/null and b/Projectiles/Summon/MoonFistTeleportVisual.png differ diff --git a/Projectiles/Summon/PuffCloud.cs b/Projectiles/Summon/PuffCloud.cs new file mode 100644 index 0000000000..d5cf51400d --- /dev/null +++ b/Projectiles/Summon/PuffCloud.cs @@ -0,0 +1,43 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class PuffCloud : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Cloud"); + Main.projFrames[Projectile.type] = 7; + ProjectileID.Sets.MinionShot[Projectile.type] = true; + } + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 16; + Projectile.friendly = true; + Projectile.minion = true; + Projectile.minionSlots = 0f; + Projectile.ignoreWater = true; + Projectile.penetrate = 1; + Projectile.tileCollide = false; + } + + public override void AI() + { + Lighting.AddLight(Projectile.Center, Color.Cyan.ToVector3()); + Projectile.velocity *= 0.97f; + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; + + Projectile.frameCounter++; + if (Projectile.frameCounter % 4 == 3) + { + Projectile.frame++; + if (Projectile.frame >= Main.projFrames[Projectile.type]) + Projectile.Kill(); + } + } + } +} diff --git a/Projectiles/Summon/PuffCloud.png b/Projectiles/Summon/PuffCloud.png new file mode 100644 index 0000000000..5b35dcb43b Binary files /dev/null and b/Projectiles/Summon/PuffCloud.png differ diff --git a/Projectiles/Summon/PuffWarrior.cs b/Projectiles/Summon/PuffWarrior.cs new file mode 100644 index 0000000000..4908f63cd8 --- /dev/null +++ b/Projectiles/Summon/PuffWarrior.cs @@ -0,0 +1,184 @@ +using CalamityMod.Buffs.Summon; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.WorldBuilding; + +namespace CalamityMod.Projectiles.Summon +{ + public class PuffWarrior : ModProjectile + { + public Player Owner => Main.player[Projectile.owner]; + + public Tile GroundTile => CalamityUtils.ParanoidTileRetrieval((int)(Projectile.Bottom.X / 16), (int)(Projectile.Bottom.Y / 16) + 1); + + public bool Jumping => !GroundTile.IsTileSolidGround() || Math.Abs(Projectile.velocity.Y) > 5f; + + public ref float JumpCountdown => ref Projectile.localAI[1]; + + public const float Gravity = 0.425f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Puff Warrior"); + Main.projFrames[Projectile.type] = 10; + ProjectileID.Sets.MinionSacrificable[Projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true; + } + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 36; + Projectile.netImportant = true; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.minionSlots = 1f; + Projectile.timeLeft = 90000; + Projectile.penetrate = -1; + Projectile.minion = true; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 18; + Projectile.tileCollide = true; + } + + public override void AI() + { + ProvidePlayerMinionBuffs(); + DetermineFrames(); + + NPC potentialTarget = Projectile.Center.MinionHoming(660f, Owner); + if (potentialTarget is null) + { + HopToOwner(out Vector2 guardSpot); + TeleportToFarOffDestination(guardSpot); + } + else + HopToTarget(potentialTarget); + + Projectile.spriteDirection = (Projectile.velocity.X > 0).ToDirectionInt(); + Projectile.rotation = Jumping ? Projectile.rotation + MathHelper.Pi / 10f * Projectile.spriteDirection : 0f; + + while (Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height)) + Projectile.position.Y -= 10f; + + // Enforce gravity. + if (Projectile.velocity.Y < 16f) + Projectile.velocity.Y += Gravity; + } + + internal void ProvidePlayerMinionBuffs() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + + // Verify player/minion state integrity. The minion cannot stay alive if the + // owner is dead or if the caller of the AI is invalid. + if (Projectile.type != ModContent.ProjectileType()) + return; + + if (Owner.dead) + Owner.Calamity().puffWarrior = false; + if (Owner.Calamity().puffWarrior) + Projectile.timeLeft = 2; + } + + internal void DetermineFrames() + { + int startingFrame = Jumping ? Main.projFrames[Projectile.type] - 3 : 0; + int endingFrame = Jumping ? Main.projFrames[Projectile.type] - 4 : Main.projFrames[Projectile.type] - 4; + + if (Jumping) + JumpCountdown = 12f; + else if (Math.Abs(Projectile.velocity.Y) <= Gravity && JumpCountdown > 0) + { + startingFrame = Main.projFrames[Projectile.type] - 1; + endingFrame = Main.projFrames[Projectile.type] - 1; + JumpCountdown--; + } + + if (Projectile.frame < startingFrame) + Projectile.frame = startingFrame; + + Projectile.frameCounter++; + if (Projectile.frameCounter % 6 == 5) + Projectile.frame++; + + if (Projectile.frame >= endingFrame) + Projectile.frame = startingFrame; + } + + internal void TeleportToFarOffDestination(Vector2 guardSpot) + { + bool obstructionBetweenSpot = Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, guardSpot, 4, 4); + bool outOfRangeOfSpot = !Projectile.WithinRange(guardSpot, obstructionBetweenSpot ? 700f : 1900f); + if (Main.myPlayer == Projectile.owner && outOfRangeOfSpot) + { + Projectile.Center = guardSpot; + Projectile.netUpdate = true; + } + } + + internal void HopToOwner(out Vector2 guardSpot) + { + guardSpot = Owner.Center; + guardSpot.X += Owner.direction * 40f * (Projectile.identity % 14f + Projectile.identity / 14 * 0.2f); + + Vector2 searchPoint = guardSpot - Vector2.UnitY * 420f; + + // Ensure that the search point is not outside of the world (which would result in index problems in the search). + searchPoint.Y = MathHelper.Clamp(searchPoint.Y, 32f, Main.maxTilesY * 16f - 32f); + + // Adjust the destination to be at the lowest point. + WorldUtils.Find(searchPoint.ToTileCoordinates(), Searches.Chain(new Searches.Down(Main.maxTilesY + 2), new Conditions.IsSolid()), out Point guardPoint); + guardSpot = guardPoint.ToWorldCoordinates(8f, 16f); + + if (!Jumping && MathHelper.Distance(guardSpot.X, Projectile.Center.X) > 10f) + { + Projectile.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(Projectile.Center, guardSpot, Gravity, 12f); + Projectile.netUpdate = true; + } + } + + internal void HopToTarget(NPC target) + { + Vector2 attackPosition = target.Center; + float attackPositionOffsetDirection = (target.velocity.X > 0).ToDirectionInt() * Math.Sign(Projectile.Center.X - target.Center.X); + attackPosition.X += attackPositionOffsetDirection * 22f * (Projectile.identity % 14f + Projectile.identity / 14 * 0.2f); + + Vector2 searchPoint = attackPosition - Vector2.UnitY * 360f; + + // Ensure that the search point is not outside of the world (which would result in index problems in the search). + searchPoint.Y = MathHelper.Clamp(searchPoint.Y, 32f, Main.maxTilesY * 16f - 32f); + + // Adjust the destination to be at the lowest point. + WorldUtils.Find(searchPoint.ToTileCoordinates(), Searches.Chain(new Searches.Down(Main.maxTilesY + 2), new Conditions.IsSolid()), out Point guardPoint); + attackPosition = guardPoint.ToWorldCoordinates(); + + if (!Jumping) + { + Projectile.position += new Vector2(Projectile.spriteDirection * 4f, -4f); + Projectile.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(Projectile.Center, attackPosition, Gravity, 17f); + if (Main.myPlayer == Projectile.owner && Projectile.WithinRange(attackPosition, 360f)) + { + for (int i = 0; i < 3; i++) + { + Vector2 shootPosition = Projectile.Top + Vector2.UnitY * (8f + i * 3f); + Vector2 shootVelocity = (target.Center - shootPosition).SafeNormalize(Vector2.UnitY) * 14f; + Projectile.NewProjectile(Projectile.GetSource_FromThis(), shootPosition, shootVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + } + } + Projectile.netUpdate = true; + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + if (Projectile.oldVelocity.Length() > 6f) + Projectile.velocity = oldVelocity * 0.5f; + else + Projectile.velocity.X = 0f; + return false; + } + } +} diff --git a/Projectiles/Summon/PuffWarrior.png b/Projectiles/Summon/PuffWarrior.png new file mode 100644 index 0000000000..55eb0dd8de Binary files /dev/null and b/Projectiles/Summon/PuffWarrior.png differ diff --git a/World/AstralBiome.cs b/World/AstralBiome.cs index b2774e32f9..2c59c7d6b7 100644 --- a/World/AstralBiome.cs +++ b/World/AstralBiome.cs @@ -528,346 +528,381 @@ namespace CalamityMod.World if (Main.tile[x, y] != null) { - if (WallID.Sets.Conversion.Grass[wallType]) + if (wallType != WallID.None && wallType != ModContent.WallType() && wallType != ModContent.WallType() && + wallType != ModContent.WallType() && wallType != ModContent.WallType() && + wallType != ModContent.WallType() && wallType != ModContent.WallType() && + wallType != ModContent.WallType() && wallType != ModContent.WallType() && + wallType != ModContent.WallType()) { - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (WallID.Sets.Conversion.HardenedSand[wallType]) - { - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (WallID.Sets.Conversion.Sandstone[wallType]) - { - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (WallID.Sets.Conversion.Stone[wallType]) - { - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else - { - switch (wallType) + if (WallID.Sets.Conversion.Grass[wallType]) { - case WallID.DirtUnsafe: - case WallID.DirtUnsafe1: - case WallID.DirtUnsafe2: - case WallID.DirtUnsafe3: - case WallID.DirtUnsafe4: - case WallID.Cave6Unsafe: - case WallID.Dirt: - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.SnowWallUnsafe: - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.DesertFossil: - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.IceUnsafe: - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case WallID.LivingWood: - Main.tile[x, y].WallType = (ushort)ModContent.WallType(); - WorldGen.SquareWallFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (WallID.Sets.Conversion.HardenedSand[wallType]) + { + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (WallID.Sets.Conversion.Sandstone[wallType]) + { + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (WallID.Sets.Conversion.Stone[wallType]) + { + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else + { + switch (wallType) + { + case WallID.DirtUnsafe: + case WallID.DirtUnsafe1: + case WallID.DirtUnsafe2: + case WallID.DirtUnsafe3: + case WallID.DirtUnsafe4: + case WallID.Cave6Unsafe: + case WallID.Dirt: + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.SnowWallUnsafe: + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.DesertFossil: + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.IceUnsafe: + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case WallID.LivingWood: + Main.tile[x, y].WallType = (ushort)ModContent.WallType(); + WorldGen.SquareWallFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + } } } - if (TileID.Sets.Conversion.Grass[type] && !TileID.Sets.GrassSpecial[type]) + + if (type >= TileID.Dirt && type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType() && type != ModContent.TileType() && + type != ModContent.TileType()) { - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Stone[type] || Main.tileMoss[type]) - { - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Sand[type]) - { - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.HardenedSand[type]) - { - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Sandstone[type]) - { - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else if (TileID.Sets.Conversion.Ice[type]) - { - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - else - { - Tile tile = Main.tile[x, y]; - switch (type) + if (TileID.Sets.Conversion.Grass[type] && !TileID.Sets.GrassSpecial[type]) { - case TileID.Dirt: - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.SnowBlock: - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.Silt: - case TileID.Slush: - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.DesertFossil: - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.ClayBlock: - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.Vines: - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.LivingWood: - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - break; - case TileID.Copper: - case TileID.Iron: - case TileID.Silver: - case TileID.Gold: - case TileID.Tin: - case TileID.Lead: - case TileID.Tungsten: - case TileID.Platinum: - if (convertOre) - { - Main.tile[x, y].TileType = (ushort)ModContent.TileType(); - WorldGen.SquareTileFrame(x, y, true); - NetMessage.SendTileSquare(-1, x, y, 1); - } - break; - case TileID.LeafBlock: - case TileID.Sunflower: - WorldGen.KillTile(x, y); - if (Main.netMode == NetmodeID.MultiplayerClient) - { - NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y); - } - break; - case TileID.LargePiles: - if (tile.TileFrameX <= 1170) - { - RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 0, 1170, 0, 18); - } - if (tile.TileFrameX >= 1728) - { - RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1728, 1872, 0, 18); - } - if (tile.TileFrameX >= 1404 && tile.TileFrameX <= 1710) - { - RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1404, 1710, 0, 18); - } - break; - case TileID.LargePiles2: - if (tile.TileFrameX >= 1566 && tile.TileFrameY < 36) - { - RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 1566, 1872, 0, 18); - } - if (tile.TileFrameX >= 756 && tile.TileFrameX <= 900) - { - RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 756, 900, 0, 18); - } - break; - case TileID.SmallPiles: - if (tile.TileFrameY == 18) - { - ushort newType; - if (tile.TileFrameX >= 1476 && tile.TileFrameX <= 1674) - { - newType = (ushort)ModContent.TileType(); - } - else if (tile.TileFrameX <= 558 || (tile.TileFrameX >= 1368 && tile.TileFrameX <= 1458)) - { - newType = (ushort)ModContent.TileType(); - } - else if (tile.TileFrameX >= 900 && tile.TileFrameX <= 1098) - { - newType = (ushort)ModContent.TileType(); - } - else - { - break; - } - int leftMost = x; - if (tile.TileFrameX % 36 != 0) //this means it's the right tile of the two - { - leftMost--; - } - if (Main.tile[leftMost, y] != null) - { - Main.tile[leftMost, y].TileType = newType; - WorldGen.SquareTileFrame(leftMost, y, true); - NetMessage.SendTileSquare(-1, leftMost, y, 1); - } - if (Main.tile[leftMost + 1, y] != null) - { - Main.tile[leftMost + 1, y].TileType = newType; - WorldGen.SquareTileFrame(leftMost + 1, y, true); - NetMessage.SendTileSquare(-1, leftMost + 1, y, 1); - } - while (Main.tile[leftMost, y].TileFrameX >= 216) - { - if (Main.tile[leftMost, y] != null) - Main.tile[leftMost, y].TileFrameX -= 216; - if (Main.tile[leftMost + 1, y] != null) - Main.tile[leftMost + 1, y].TileFrameX -= 216; - } - } - else if (tile.TileFrameY == 0) - { - ushort newType3; - if (tile.TileFrameX >= 972 && tile.TileFrameX <= 1062) - { - newType3 = (ushort)ModContent.TileType(); - } - else if (tile.TileFrameX <= 486) - { - newType3 = (ushort)ModContent.TileType(); - } - else if (tile.TileFrameX >= 648 && tile.TileFrameX <= 846) - { - newType3 = (ushort)ModContent.TileType(); - } - else - { - break; - } - Main.tile[x, y].TileType = newType3; - while (Main.tile[x, y].TileFrameX >= 108) //REFRAME IT - { - Main.tile[x, y].TileFrameX -= 108; - } + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Stone[type] || Main.tileMoss[type]) + { + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Sand[type]) + { + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.HardenedSand[type]) + { + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Sandstone[type]) + { + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else if (TileID.Sets.Conversion.Ice[type]) + { + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + else + { + Tile tile = Main.tile[x, y]; + switch (type) + { + case TileID.Dirt: + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); WorldGen.SquareTileFrame(x, y, true); NetMessage.SendTileSquare(-1, x, y, 1); - } - break; - case TileID.Stalactite: - int topMost = tile.TileFrameY <= 54 ? (tile.TileFrameY % 36 == 0 ? y : y - 1) : y; - bool twoTall = tile.TileFrameY <= 54; - bool hanging = tile.TileFrameY <= 18 || tile.TileFrameY == 72; - ushort newType2; - if (tile.TileFrameX >= 378 && tile.TileFrameX <= 414) //DESERT - { - newType2 = (ushort)ModContent.TileType(); - } - else if ((tile.TileFrameX >= 54 && tile.TileFrameX <= 90) || (tile.TileFrameX >= 216 && tile.TileFrameX <= 360)) - { - newType2 = (ushort)ModContent.TileType(); - } - else if (tile.TileFrameX <= 36) - { - newType2 = (ushort)ModContent.TileType(); - } - else - { break; - } + case TileID.SnowBlock: + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.Silt: + case TileID.Slush: + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.DesertFossil: + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.ClayBlock: + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.Vines: + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.LivingWood: + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + break; + case TileID.Copper: + case TileID.Iron: + case TileID.Silver: + case TileID.Gold: + case TileID.Tin: + case TileID.Lead: + case TileID.Tungsten: + case TileID.Platinum: + if (convertOre) + { + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + break; + case TileID.LeafBlock: + case TileID.Sunflower: + WorldGen.KillTile(x, y); + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y); + } + break; + case TileID.LargePiles: + if (tile.TileFrameX <= 1170) + { + RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 0, 1170, 0, 18); + } + if (tile.TileFrameX >= 1728) + { + RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1728, 1872, 0, 18); + } + if (tile.TileFrameX >= 1404 && tile.TileFrameX <= 1710) + { + RecursiveReplaceToAstral(TileID.LargePiles, (ushort)ModContent.TileType(), x, y, 324, 1404, 1710, 0, 18); + } + break; + case TileID.LargePiles2: + if (tile.TileFrameX >= 1566 && tile.TileFrameY < 36) + { + RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 1566, 1872, 0, 18); + } + if (tile.TileFrameX >= 756 && tile.TileFrameX <= 900) + { + RecursiveReplaceToAstral(TileID.LargePiles2, (ushort)ModContent.TileType(), x, y, 324, 756, 900, 0, 18); + } + break; + case TileID.SmallPiles: + if (tile.TileFrameY == 18) + { + ushort newType; + if (tile.TileFrameX >= 1476 && tile.TileFrameX <= 1674) + { + newType = (ushort)ModContent.TileType(); + } + else if (tile.TileFrameX <= 558 || (tile.TileFrameX >= 1368 && tile.TileFrameX <= 1458)) + { + newType = (ushort)ModContent.TileType(); + } + else if (tile.TileFrameX >= 900 && tile.TileFrameX <= 1098) + { + newType = (ushort)ModContent.TileType(); + } + else + { + break; + } + int leftMost = x; + if (tile.TileFrameX % 36 != 0) //this means it's the right tile of the two + { + leftMost--; + } + if (Main.tile[leftMost, y] != null) + { + Main.tile[leftMost, y].TileType = newType; + WorldGen.SquareTileFrame(leftMost, y, true); + NetMessage.SendTileSquare(-1, leftMost, y, 1); + } + if (Main.tile[leftMost + 1, y] != null) + { + Main.tile[leftMost + 1, y].TileType = newType; + WorldGen.SquareTileFrame(leftMost + 1, y, true); + NetMessage.SendTileSquare(-1, leftMost + 1, y, 1); + } + while (Main.tile[leftMost, y].TileFrameX >= 216) + { + if (Main.tile[leftMost, y] != null) + Main.tile[leftMost, y].TileFrameX -= 216; + if (Main.tile[leftMost + 1, y] != null) + Main.tile[leftMost + 1, y].TileFrameX -= 216; + } + } + else if (tile.TileFrameY == 0) + { + ushort newType3; + if (tile.TileFrameX >= 972 && tile.TileFrameX <= 1062) + { + newType3 = (ushort)ModContent.TileType(); + } + else if (tile.TileFrameX <= 486) + { + newType3 = (ushort)ModContent.TileType(); + } + else if (tile.TileFrameX >= 648 && tile.TileFrameX <= 846) + { + newType3 = (ushort)ModContent.TileType(); + } + else + { + break; + } + Main.tile[x, y].TileType = newType3; + while (Main.tile[x, y].TileFrameX >= 108) //REFRAME IT + { + Main.tile[x, y].TileFrameX -= 108; + } + WorldGen.SquareTileFrame(x, y, true); + NetMessage.SendTileSquare(-1, x, y, 1); + } + break; + case TileID.Stalactite: + int topMost = tile.TileFrameY <= 54 ? (tile.TileFrameY % 36 == 0 ? y : y - 1) : y; + bool twoTall = tile.TileFrameY <= 54; + bool hanging = tile.TileFrameY <= 18 || tile.TileFrameY == 72; + ushort newType2; + if (tile.TileFrameX >= 378 && tile.TileFrameX <= 414) //DESERT + { + newType2 = (ushort)ModContent.TileType(); + } + else if ((tile.TileFrameX >= 54 && tile.TileFrameX <= 90) || (tile.TileFrameX >= 216 && tile.TileFrameX <= 360)) + { + newType2 = (ushort)ModContent.TileType(); + } + else if (tile.TileFrameX <= 36) + { + newType2 = (ushort)ModContent.TileType(); + } + else + { + break; + } - //Set types - if (Main.tile[x, topMost] != null) - { - Main.tile[x, topMost].TileType = newType2; - } - if (twoTall) - { - if (Main.tile[x, topMost + 1] != null) - Main.tile[x, topMost + 1].TileType = newType2; - } - - //Fix frames - while (Main.tile[x, topMost].TileFrameX >= 54) - { + //Set types if (Main.tile[x, topMost] != null) - Main.tile[x, topMost].TileFrameX -= 54; + { + Main.tile[x, topMost].TileType = newType2; + } if (twoTall) { if (Main.tile[x, topMost + 1] != null) - Main.tile[x, topMost + 1].TileFrameX -= 54; + Main.tile[x, topMost + 1].TileType = newType2; } - } - if (Main.tile[x, topMost] != null) - { - WorldGen.SquareTileFrame(x, topMost, true); - NetMessage.SendTileSquare(-1, x, topMost, 1); - } - - if (Main.tile[x, topMost + 1] != null) - { - WorldGen.SquareTileFrame(x, topMost + 1, true); - NetMessage.SendTileSquare(-1, x, topMost + 1, 1); - } - - if (hanging) - { - ConvertToAstral(x, topMost - 1); - break; - } - else - { - if (twoTall) + //Fix frames + while (Main.tile[x, topMost].TileFrameX >= 54) { - ConvertToAstral(x, topMost + 2); + if (Main.tile[x, topMost] != null) + Main.tile[x, topMost].TileFrameX -= 54; + if (twoTall) + { + if (Main.tile[x, topMost + 1] != null) + Main.tile[x, topMost + 1].TileFrameX -= 54; + } + } + + if (Main.tile[x, topMost] != null) + { + WorldGen.SquareTileFrame(x, topMost, true); + NetMessage.SendTileSquare(-1, x, topMost, 1); + } + + if (Main.tile[x, topMost + 1] != null) + { + WorldGen.SquareTileFrame(x, topMost + 1, true); + NetMessage.SendTileSquare(-1, x, topMost + 1, 1); + } + + if (hanging) + { + ConvertToAstral(x, topMost - 1); break; } - ConvertToAstral(x, topMost + 1); + else + { + if (twoTall) + { + ConvertToAstral(x, topMost + 2); + break; + } + ConvertToAstral(x, topMost + 1); + break; + } + case TileID.OasisPlants: + Main.tile[x, y].Get().HasTile = false; + NetMessage.SendTileSquare(-1, x, y, 1); break; - } - case TileID.OasisPlants: - Main.tile[x, y].Get().HasTile = false; - NetMessage.SendTileSquare(-1, x, y, 1); - break; + } } } } } } + public static void ConvertFromAstral(int startX, int endX, int startY, int endY, ConvertType convert) + { + for (int x = startX; x <= endX; x++) + { + for (int y = startY; y <= endY; y++) + { + ConvertFromAstral(x, y, convert); + } + } + } + public static void ConvertFromAstral(int x, int y, ConvertType convert, bool tileframe = true) { Tile tile = Main.tile[x, y]; @@ -1075,6 +1110,7 @@ namespace CalamityMod.World { ReplaceAstralStalactite(TileID.Stalactite, TileID.IceBlock, x, y); } + if (TileID.Sets.Conversion.Grass[type] || type == TileID.Dirt) { WorldGen.SquareTileFrame(x, y);