diff --git a/Gores/IceClasper/IceClasper.png b/Gores/IceClasper/IceClasper.png new file mode 100644 index 0000000000..e5e3930e27 Binary files /dev/null and b/Gores/IceClasper/IceClasper.png differ diff --git a/Gores/IceClasper/IceClasper2.png b/Gores/IceClasper/IceClasper2.png new file mode 100644 index 0000000000..fc5985858c Binary files /dev/null and b/Gores/IceClasper/IceClasper2.png differ diff --git a/Gores/IceClasper/IceClasper3.png b/Gores/IceClasper/IceClasper3.png new file mode 100644 index 0000000000..bc516c2e9d Binary files /dev/null and b/Gores/IceClasper/IceClasper3.png differ diff --git a/Gores/ImpiousImmolator/ImpiousImmolator.png b/Gores/ImpiousImmolator/ImpiousImmolator.png new file mode 100644 index 0000000000..69ec8765c3 Binary files /dev/null and b/Gores/ImpiousImmolator/ImpiousImmolator.png differ diff --git a/Gores/ImpiousImmolator/ImpiousImmolator2.png b/Gores/ImpiousImmolator/ImpiousImmolator2.png new file mode 100644 index 0000000000..ca773be7a1 Binary files /dev/null and b/Gores/ImpiousImmolator/ImpiousImmolator2.png differ diff --git a/Gores/ImpiousImmolator/ImpiousImmolator3.png b/Gores/ImpiousImmolator/ImpiousImmolator3.png new file mode 100644 index 0000000000..8f1e1a7d8b Binary files /dev/null and b/Gores/ImpiousImmolator/ImpiousImmolator3.png differ diff --git a/Gores/LuminousCorvina/LuminousCorvina.png b/Gores/LuminousCorvina/LuminousCorvina.png new file mode 100644 index 0000000000..e65da49586 Binary files /dev/null and b/Gores/LuminousCorvina/LuminousCorvina.png differ diff --git a/Gores/LuminousCorvina/LuminousCorvina2.png b/Gores/LuminousCorvina/LuminousCorvina2.png new file mode 100644 index 0000000000..72afa6a54d Binary files /dev/null and b/Gores/LuminousCorvina/LuminousCorvina2.png differ diff --git a/Gores/LuminousCorvina/LuminousCorvina3.png b/Gores/LuminousCorvina/LuminousCorvina3.png new file mode 100644 index 0000000000..8bb28adcc1 Binary files /dev/null and b/Gores/LuminousCorvina/LuminousCorvina3.png differ diff --git a/Gores/MantisShrimp/MantisShrimp.png b/Gores/MantisShrimp/MantisShrimp.png new file mode 100644 index 0000000000..ec026b5b2c Binary files /dev/null and b/Gores/MantisShrimp/MantisShrimp.png differ diff --git a/Gores/MantisShrimp/MantisShrimp2.png b/Gores/MantisShrimp/MantisShrimp2.png new file mode 100644 index 0000000000..a4342e23ab Binary files /dev/null and b/Gores/MantisShrimp/MantisShrimp2.png differ diff --git a/Gores/MantisShrimp/MantisShrimp3.png b/Gores/MantisShrimp/MantisShrimp3.png new file mode 100644 index 0000000000..e221daf830 Binary files /dev/null and b/Gores/MantisShrimp/MantisShrimp3.png differ diff --git a/Gores/Melter/Melter.png b/Gores/Melter/Melter.png new file mode 100644 index 0000000000..ee97b31043 Binary files /dev/null and b/Gores/Melter/Melter.png differ diff --git a/Gores/Melter/Melter2.png b/Gores/Melter/Melter2.png new file mode 100644 index 0000000000..2f1f1c9ab8 Binary files /dev/null and b/Gores/Melter/Melter2.png differ diff --git a/Gores/Melter/Melter3.png b/Gores/Melter/Melter3.png new file mode 100644 index 0000000000..a24a71dd66 Binary files /dev/null and b/Gores/Melter/Melter3.png differ diff --git a/Gores/MorayEel/MorayEel.png b/Gores/MorayEel/MorayEel.png new file mode 100644 index 0000000000..a934215ae9 Binary files /dev/null and b/Gores/MorayEel/MorayEel.png differ diff --git a/Gores/MorayEel/MorayEel2.png b/Gores/MorayEel/MorayEel2.png new file mode 100644 index 0000000000..22b442ac98 Binary files /dev/null and b/Gores/MorayEel/MorayEel2.png differ diff --git a/Gores/MorayEel/MorayEel3.png b/Gores/MorayEel/MorayEel3.png new file mode 100644 index 0000000000..548d458f34 Binary files /dev/null and b/Gores/MorayEel/MorayEel3.png differ diff --git a/Gores/Oarfish/OarfishBody.png b/Gores/Oarfish/OarfishBody.png new file mode 100644 index 0000000000..50ea356a3d Binary files /dev/null and b/Gores/Oarfish/OarfishBody.png differ diff --git a/Gores/Oarfish/OarfishHead.png b/Gores/Oarfish/OarfishHead.png new file mode 100644 index 0000000000..14f397c7eb Binary files /dev/null and b/Gores/Oarfish/OarfishHead.png differ diff --git a/Gores/Oarfish/OarfishTail.png b/Gores/Oarfish/OarfishTail.png new file mode 100644 index 0000000000..cd7acee3bf Binary files /dev/null and b/Gores/Oarfish/OarfishTail.png differ diff --git a/Items/MomentumCapacitor.cs b/Items/MomentumCapacitor.cs index 043a578d32..3019595d1b 100644 --- a/Items/MomentumCapacitor.cs +++ b/Items/MomentumCapacitor.cs @@ -16,7 +16,7 @@ namespace CalamityMod.Items { SacrificeTotal = 1; DisplayName.SetDefault("Momentum Capacitor"); - Tooltip.SetDefault("While using the Momentum Capacitor,\n" + "your top speed will continuously and uncontrollably increase"); + Tooltip.SetDefault("While using the Momentum Capacitor,\n" + "your top speed will continuously and uncontrollably increase\n" + "This effect only works if there are no bosses alive"); } public override void SetDefaults() @@ -41,11 +41,14 @@ namespace CalamityMod.Items public override bool? UseItem(Player player) { - CalamityPlayer modPlayer = player.Calamity(); - modPlayer.momentumCapacitorTime = TotalFadeTime; - modPlayer.momentumCapacitorBoost += Main.rand.NextFloat(0.5f, 3.5f) * MomentumChargePerFrame; - if (modPlayer.momentumCapacitorBoost >= MaxMomentumCharge) - modPlayer.momentumCapacitorBoost = MaxMomentumCharge; + if (!CalamityPlayer.areThereAnyDamnBosses) + { + CalamityPlayer modPlayer = player.Calamity(); + modPlayer.momentumCapacitorTime = TotalFadeTime; + modPlayer.momentumCapacitorBoost += Main.rand.NextFloat(0.5f, 3.5f) * MomentumChargePerFrame; + if (modPlayer.momentumCapacitorBoost >= MaxMomentumCharge) + modPlayer.momentumCapacitorBoost = MaxMomentumCharge; + } return null; } } diff --git a/Items/Placeables/VernalSoil.cs b/Items/Placeables/VernalSoil.cs new file mode 100644 index 0000000000..38c41092d7 --- /dev/null +++ b/Items/Placeables/VernalSoil.cs @@ -0,0 +1,28 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables +{ + public class VernalSoil : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Vernal Soil"); + SacrificeTotal = 10; + } + + public override void SetDefaults() + { + Item.createTile = ModContent.TileType(); + Item.useStyle = ItemUseStyleID.Swing; + Item.useTurn = true; + Item.useAnimation = 15; + Item.useTime = 10; + Item.autoReuse = true; + Item.consumable = true; + Item.width = 16; + Item.height = 16; + Item.maxStack = 999; + } + } +} diff --git a/Items/Placeables/VernalSoil.png b/Items/Placeables/VernalSoil.png new file mode 100644 index 0000000000..a0a8c2c4e1 Binary files /dev/null and b/Items/Placeables/VernalSoil.png differ diff --git a/Items/Weapons/Ranged/Hydra.cs b/Items/Weapons/Ranged/Hydra.cs index 7dd910afcc..9df87596f6 100644 --- a/Items/Weapons/Ranged/Hydra.cs +++ b/Items/Weapons/Ranged/Hydra.cs @@ -1,6 +1,6 @@ -using CalamityMod.CalPlayer; -using CalamityMod.Projectiles.Ranged; +using CalamityMod.Projectiles.Ranged; using Microsoft.Xna.Framework; +using System; using Terraria; using Terraria.DataStructures; using Terraria.ID; @@ -11,59 +11,152 @@ namespace CalamityMod.Items.Weapons.Ranged { public class Hydra : ModItem { - public static readonly SoundStyle FireSound = new("CalamityMod/Sounds/Item/Hydra"); + //Editable stats: + public const int BulletsPerShot = 4; + public const float ShotSpread = 10f; //in degrees + public const int TimeToSpawnHead = 3; //in seconds + public const int MaximumHeadCount = 3; + + public int HeadID = ModContent.ProjectileType(); + public int HeadSpawnTimer = 0; + + //There could be new sounds for these. Vanilla sounds for now. + public static readonly SoundStyle SpawnSound = SoundID.Item60; + public static readonly SoundStyle LaunchSound = SoundID.Item1; public override void SetStaticDefaults() { DisplayName.SetDefault("Hydra"); - Tooltip.SetDefault("Fires a spread of explosive bullets"); + Tooltip.SetDefault("Fusion of heavy machinery and Lernaean blood\n" + + "Fires a spread of " + BulletsPerShot + " toxic bullets\n"+ + "Grows a gun-head every " + TimeToSpawnHead + " seconds, up to a maximum of " + MaximumHeadCount + " heads\n" + + "Left-click to command any existing heads to fire\n" + + "Right-click to launch the heads for powerful explosive damage"); SacrificeTotal = 1; + ItemID.Sets.ItemsThatAllowRepeatedRightClick[Item.type] = true; } public override void SetDefaults() { - Item.damage = 120; - Item.DamageType = DamageClass.Ranged; Item.width = 66; Item.height = 30; - Item.useTime = 33; - Item.useAnimation = 33; Item.useStyle = ItemUseStyleID.Shoot; Item.noMelee = true; - Item.knockBack = 10f; - Item.value = CalamityGlobalItem.Rarity9BuyPrice; - Item.rare = ItemRarityID.Yellow; - Item.UseSound = FireSound; - Item.autoReuse = true; - Item.shootSpeed = 12f; - Item.shoot = ModContent.ProjectileType(); + Item.damage = 50; + Item.DamageType = DamageClass.Ranged; + Item.useAnimation = Item.useTime = 60; Item.useAmmo = AmmoID.Bullet; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 10f; + Item.knockBack = 10f; + Item.autoReuse = true; + Item.value = CalamityGlobalItem.Rarity8BuyPrice; + Item.rare = ItemRarityID.Yellow; + Item.UseSound = null; //does so in Shoot Item.Calamity().canFirePointBlankShots = true; } - public override Vector2? HoldoutOffset() + public override bool CanConsumeAmmo(Item ammo, Player player) => player.altFunctionUse == 2 ? false : true; + + public override void UpdateInventory(Player player) { - return new Vector2(-5, 0); + //Spawn heads while holding + if (player.ActiveItem().type == Item.type && player.ownedProjectileCounts[HeadID] < MaximumHeadCount) + { + HeadSpawnTimer++; + if (HeadSpawnTimer >= TimeToSpawnHead * 60) + { + HeadSpawnTimer = 0; + SoundEngine.PlaySound(SpawnSound, player.Center); + Projectile.NewProjectile(Item.GetSource_FromThis(), player.Top + Vector2.UnitY * 8f, Vector2.Zero, HeadID, 0, 0, player.whoAmI); + } + } + else if (player.ActiveItem().type != Item.type || player.dead || !player.active) + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + //Destroy all heads + if (Main.projectile[i].type == HeadID && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].active) + Main.projectile[i].Kill(); + } + HeadSpawnTimer = 0; + } + } + + public override bool AltFunctionUse(Player player) + { + //Does nothing if there's no heads + if (player.ownedProjectileCounts[HeadID] <= 0) + return false; + + //Otherwise, launch the guns + for (int i = 0; i < Main.maxProjectiles; i++) + { + SoundEngine.PlaySound(LaunchSound, player.Center); + if (Main.projectile[i].type == HeadID && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].active) + Main.projectile[i].ai[1] = -1f; + } + return false; } public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - for (int index = 0; index < 8; ++index) + Vector2 shootDirection = velocity.SafeNormalize(Vector2.Zero); + for (int i = 0; i < 4; i++) { - float SpeedX = velocity.X + Main.rand.Next(-40, 41) * 0.05f; - float SpeedY = velocity.Y + Main.rand.Next(-40, 41) * 0.05f; - Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI); + int CurrentHeadCount = player.ownedProjectileCounts[HeadID]; + //Exponentially louder the more heads, slightly + SoundStyle FireSound = new("CalamityMod/Sounds/Item/Hydra") { Volume = 0.3f + (float)(Math.Pow(CurrentHeadCount, 1.5D) * 0.2f) }; + SoundEngine.PlaySound(FireSound, player.Center); + + Vector2 spreadDirection = shootDirection.RotatedByRandom(MathHelper.ToRadians(ShotSpread / 2f)); + float spreadVelocity = Item.shootSpeed * Main.rand.NextFloat(1f, 1.4f); + Vector2 newPos = player.MountedCenter + shootDirection * 50f; + + Projectile.NewProjectile(source, newPos, spreadVelocity * spreadDirection, Item.shoot, damage, knockback, player.whoAmI); + } + + for (int i = 0; i < Main.maxProjectiles; i++) + { + //Force all heads to shoot + if (Main.projectile[i].type == HeadID && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].active) + Main.projectile[i].ai[1] = 1f; } return false; } + public override void HoldItem(Player player) => player.Calamity().mouseWorldListener = true; + + public override void UseStyle(Player player, Rectangle heldItemFrame) + { + player.direction = Math.Sign((player.Calamity().mouseWorld - player.Center).X); + float itemRotation = player.compositeFrontArm.rotation + MathHelper.PiOver2 * player.gravDir; + + Vector2 itemPosition = player.MountedCenter + itemRotation.ToRotationVector2() * 7f; + Vector2 itemSize = new Vector2(Item.width, Item.height); + Vector2 itemOrigin = new Vector2(-17, 3); + CalamityUtils.CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin); + base.UseStyle(player, heldItemFrame); + } + + public override void UseItemFrame(Player player) + { + player.direction = Math.Sign((player.Calamity().mouseWorld - player.Center).X); + + float animProgress = 1 - player.itemTime / (float)player.itemTimeMax; + float rotation = (player.Center - player.Calamity().mouseWorld).ToRotation() * player.gravDir + MathHelper.PiOver2; + if (animProgress < 0.4f) + rotation += -0.45f * (float)Math.Pow((0.4f - animProgress) / 0.4f, 2) * player.direction; + + player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, rotation); + } + public override void AddRecipes() { CreateRecipe(). - AddIngredient(ItemID.Shotgun). - AddIngredient(ItemID.IllegalGunParts). - AddRecipeGroup("IronBar", 20). - AddIngredient(ItemID.Ectoplasm, 20). + AddIngredient(ItemID.QuadBarrelShotgun). + AddIngredient(ItemID.Nanites, 25). + AddIngredient(ItemID.VialofVenom, 25). AddTile(TileID.MythrilAnvil). Register(); } diff --git a/Items/Weapons/Summon/BelladonnaSpiritStaff.cs b/Items/Weapons/Summon/BelladonnaSpiritStaff.cs index bddd3cbd4e..700e3d6eb6 100644 --- a/Items/Weapons/Summon/BelladonnaSpiritStaff.cs +++ b/Items/Weapons/Summon/BelladonnaSpiritStaff.cs @@ -12,13 +12,13 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Belladonna Spirit Staff"); - Tooltip.SetDefault("Summons a cute forest spirit that scatters toxic petals"); + Tooltip.SetDefault("Summons a cute forest spirit that flings magical toxic petals"); SacrificeTotal = 1; } public override void SetDefaults() { - Item.damage = 5; + Item.damage = 30; Item.mana = 10; Item.width = 40; Item.height = 42; @@ -31,7 +31,6 @@ namespace CalamityMod.Items.Weapons.Summon Item.UseSound = SoundID.Item44; 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) diff --git a/Items/Weapons/Summon/CinderBlossomStaff.cs b/Items/Weapons/Summon/CinderBlossomStaff.cs index 351fe0e30b..82eb094474 100644 --- a/Items/Weapons/Summon/CinderBlossomStaff.cs +++ b/Items/Weapons/Summon/CinderBlossomStaff.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Cinder Blossom Staff"); - Tooltip.SetDefault("Summons a really hot flower over your head\n" + + Tooltip.SetDefault("Summons scorching flower over your head\n" + "There can only be one flower"); SacrificeTotal = 1; } @@ -21,8 +21,8 @@ namespace CalamityMod.Items.Weapons.Summon { Item.damage = 25; Item.mana = 10; - Item.width = 46; - Item.height = 46; + Item.width = 50; + Item.height = 56; Item.useTime = Item.useAnimation = 30; Item.useStyle = ItemUseStyleID.Swing; Item.noMelee = true; @@ -31,10 +31,11 @@ namespace CalamityMod.Items.Weapons.Summon Item.rare = ItemRarityID.Orange; Item.UseSound = SoundID.Item34; Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 10f; Item.DamageType = DamageClass.Summon; } + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { CalamityUtils.KillShootProjectiles(true, type, player); @@ -43,6 +44,7 @@ namespace CalamityMod.Items.Weapons.Summon Main.projectile[p].originalDamage = Item.damage; return false; } + public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Summon/EtherealSubjugator.cs b/Items/Weapons/Summon/EtherealSubjugator.cs index 17c2215f30..49ec3e3d51 100644 --- a/Items/Weapons/Summon/EtherealSubjugator.cs +++ b/Items/Weapons/Summon/EtherealSubjugator.cs @@ -15,14 +15,13 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Ethereal Subjugator"); - Tooltip.SetDefault("Summons a phantom to protect you\n" + - "Each phantom takes only half of a minion slot"); + Tooltip.SetDefault("Summons a phantom to protect you"); SacrificeTotal = 1; } public override void SetDefaults() { - Item.damage = 45; + Item.damage = 200; Item.mana = 10; Item.width = 66; Item.height = 70; diff --git a/Localization/enUS.hjson b/Localization/en-US.hjson similarity index 100% rename from Localization/enUS.hjson rename to Localization/en-US.hjson diff --git a/NPCs/Abyss/LuminousCorvina.cs b/NPCs/Abyss/LuminousCorvina.cs index 7da0ea8f42..89aa499e84 100644 --- a/NPCs/Abyss/LuminousCorvina.cs +++ b/NPCs/Abyss/LuminousCorvina.cs @@ -326,6 +326,12 @@ namespace CalamityMod.NPCs.Abyss { Dust.NewDust(NPC.position, NPC.width, NPC.height, 139, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("LuminousCorvina").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("LuminousCorvina2").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("LuminousCorvina3").Type, 1f); + } } } } diff --git a/NPCs/Abyss/MorayEel.cs b/NPCs/Abyss/MorayEel.cs index ea03aac09f..7fa9262eec 100644 --- a/NPCs/Abyss/MorayEel.cs +++ b/NPCs/Abyss/MorayEel.cs @@ -129,6 +129,12 @@ namespace CalamityMod.NPCs.Abyss { Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("MorayEel").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("MorayEel2").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("MorayEel3").Type, 1f); + } } } } diff --git a/NPCs/Abyss/OarfishBody.cs b/NPCs/Abyss/OarfishBody.cs index 6b605de16d..18d2a3a209 100644 --- a/NPCs/Abyss/OarfishBody.cs +++ b/NPCs/Abyss/OarfishBody.cs @@ -137,6 +137,8 @@ namespace CalamityMod.NPCs.Abyss { Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("OarfishBody").Type, 1f); } } } diff --git a/NPCs/Abyss/OarfishHead.cs b/NPCs/Abyss/OarfishHead.cs index a9f818b180..bb142a2b19 100644 --- a/NPCs/Abyss/OarfishHead.cs +++ b/NPCs/Abyss/OarfishHead.cs @@ -349,6 +349,8 @@ namespace CalamityMod.NPCs.Abyss { Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("OarfishHead").Type, 1f); } } diff --git a/NPCs/Abyss/OarfishTail.cs b/NPCs/Abyss/OarfishTail.cs index 4fec13d088..bdafdfc74a 100644 --- a/NPCs/Abyss/OarfishTail.cs +++ b/NPCs/Abyss/OarfishTail.cs @@ -137,6 +137,8 @@ namespace CalamityMod.NPCs.Abyss { Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("OarfishTail").Type, 1f); } } } diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index cd999d2690..738bee7c55 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -1301,7 +1301,7 @@ namespace CalamityMod.NPCs else if (CalamityLists.DestroyerIDs.Contains(npc.type)) { npc.lifeMax = (int)(npc.lifeMax * 1.25); - npc.scale *= CalamityWorld.death ? 2.5f : 1.5f; + npc.scale *= CalamityWorld.death ? 2f : 1.5f; npc.npcSlots = 10f; } else if (npc.type == NPCID.Probe) @@ -1309,7 +1309,7 @@ namespace CalamityMod.NPCs if (CalamityWorld.death) npc.lifeMax = (int)(npc.lifeMax * 2.0); - npc.scale *= CalamityWorld.death ? 2f : 1.2f; + npc.scale *= CalamityWorld.death ? 1.5f : 1.2f; } else if (npc.type == NPCID.SkeletronPrime) { @@ -2564,14 +2564,16 @@ namespace CalamityMod.NPCs #endregion #region Strike NPC + // Incoming defense to this function is already affected by the vanilla debuffs Ichor (-15) and Betsy's Curse (-40), and cannot be below zero. public override bool StrikeNPC(NPC npc, ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit) { // Don't bother tampering with the damage if it is already zero. - // Zero damage does not happen in the base game and is always indicative of antibutcher in Calamity. + // Zero damage does not happen in the base game; if something has been set to zero damage by another mod, it's really not intended to do damage. if (damage == 0D) - return false; + return true; - // Override hand/head eye 'death' code and use custom 'death' code instead, this is here just in case the AI code fails + // Safety for ML's eyes on Rev+ so that the boss doesn't remain invulnerable forever + // TODO -- this is very old, is it still needed? if (CalamityWorld.revenge || BossRushEvent.BossRushActive) { if (npc.type == NPCID.MoonLordHand || npc.type == NPCID.MoonLordHead) @@ -2589,16 +2591,19 @@ namespace CalamityMod.NPCs } } + // Armor penetration has already been applied as bonus damage. // Yellow Candle provides +5% damage which ignores both DR and defense. - // However, armor penetration bonus damage has already been applied, so it's slightly higher than it should be. + // This means Yellow Candle is buffing armor penetration and technically not ignoring defense, + // but it's small enough to let it slide. double yellowCandleDamage = 0.05 * damage; // Apply modifications to enemy's current defense based on Calamity debuffs. // As with defense and DR, flat reductions apply first, then multiplicative reductions. + // + // Ozzatron 05JAN2023: fixed doubled armor pen, this time for real int effectiveDefense = defense - (marked > 0 && DR <= 0f ? MarkedforDeath.DefenseReduction : 0) - (wither > 0 ? WitherDebuff.DefenseReduction : 0) - - (int)Main.LocalPlayer.GetArmorPenetration() - miscDefenseLoss; // Defense can never be negative and has a minimum value of zero. @@ -2622,6 +2627,8 @@ namespace CalamityMod.NPCs } // Large Deus worm takes reduced damage to last a long enough time. + // TODO -- WHY DOES DEUS HAVE THIS UNDOCUMENTED MULTIPLIER HERE?? + // this should be in ModifyHitNPC for deus himself if (CalamityLists.AstrumDeusIDs.Contains(npc.type) && newAI[0] == 0f) damage *= 0.8; @@ -2632,9 +2639,13 @@ namespace CalamityMod.NPCs if (damage == 0D) return false; - // Cancel out vanilla defense math by reversing the calculation vanilla is about to perform. - // While roundabout, this is safer than returning false to stop vanilla damage calculations entirely. - // Other mods will probably expect the vanilla code to run and may compensate for it themselves. + // Immediately after StrikeNPC runs, vanilla does the following 3 things: + // 1 - Reduces damage by vanilla effective defense + // 2 - Doubles damage if it's a crit + // 3 - Multiplies by vanilla takenDamageMultiplier if it's over 1.0 + // + // The following line cancels out vanilla defense calculations, since we just did our own above. + // We return true to allow all 3 to run, but cancel out #1, meaning crits and Crawltipede still work. damage = Main.CalculateDamageNPCsTake((int)damage, -defense); return true; } @@ -4493,6 +4504,9 @@ namespace CalamityMod.NPCs } } + // + // DAAWNLIGHT SPIRIT ORIGIN AIM IMPLEMENTATION + // int bullseyeType = ProjectileType(); Projectile bullseye = null; for (int i = 0; i < Main.maxProjectiles; i++) @@ -4564,6 +4578,7 @@ namespace CalamityMod.NPCs } } + // Plague Reaper deals 1.1x damage to Plagued enemies if (!projectile.npcProj && !projectile.trap) { if (projectile.CountsAsClass() && modPlayer.plagueReaper && pFlames > 0) @@ -4602,7 +4617,8 @@ namespace CalamityMod.NPCs damage = (int)(damage * 0.1); } - // TODO -- What in god's name is this? + // Generalized pierce resistance that stacks with all other resistances for some specific bosses defined in a list. + // The actual resistance formula isn't really a problem, but the implementation of this desperately needs refactoring. private void PierceResistGlobal(Projectile projectile, NPC npc, ref int damage) { // Thanatos segments do not trigger pierce resistance if they are closed diff --git a/NPCs/NormalNPCs/IceClasper.cs b/NPCs/NormalNPCs/IceClasper.cs index d2e88be8e0..0faec74453 100644 --- a/NPCs/NormalNPCs/IceClasper.cs +++ b/NPCs/NormalNPCs/IceClasper.cs @@ -283,6 +283,12 @@ namespace CalamityMod.NPCs.NormalNPCs { Dust.NewDust(NPC.position, NPC.width, NPC.height, 92, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("IceClasper").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("IceClasper2").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("IceClasper3").Type, 1f); + } } } diff --git a/NPCs/NormalNPCs/ImpiousImmolator.cs b/NPCs/NormalNPCs/ImpiousImmolator.cs index c4463a4926..9016e7326d 100644 --- a/NPCs/NormalNPCs/ImpiousImmolator.cs +++ b/NPCs/NormalNPCs/ImpiousImmolator.cs @@ -284,6 +284,12 @@ namespace CalamityMod.NPCs.NormalNPCs { Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.ProfanedFire, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("ImpiousImmolator").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("ImpiousImmolator2").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("ImpiousImmolator3").Type, 1f); + } } } } diff --git a/NPCs/NormalNPCs/MantisShrimp.cs b/NPCs/NormalNPCs/MantisShrimp.cs index 391bb6be5d..bc7eeda2d9 100644 --- a/NPCs/NormalNPCs/MantisShrimp.cs +++ b/NPCs/NormalNPCs/MantisShrimp.cs @@ -138,6 +138,12 @@ namespace CalamityMod.NPCs.NormalNPCs { Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("MantisShrimp").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("MantisShrimp2").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("MantisShrimp3").Type, 1f); + } } } } diff --git a/NPCs/PlagueEnemies/Melter.cs b/NPCs/PlagueEnemies/Melter.cs index fa752e314a..6912725a29 100644 --- a/NPCs/PlagueEnemies/Melter.cs +++ b/NPCs/PlagueEnemies/Melter.cs @@ -81,6 +81,12 @@ namespace CalamityMod.NPCs.PlagueEnemies { Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Plague, hitDirection, -1f, 0, default, 1f); } + if (Main.netMode != NetmodeID.Server) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Melter").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Melter2").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Melter3").Type, 1f); + } } } diff --git a/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs b/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs index f42aa70cd1..edc11c60ef 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs @@ -144,7 +144,7 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.realLife = npc.whoAmI; int index = npc.whoAmI; - int totalSegments = death ? 60 : 80; + int totalSegments = 80; if (Main.getGoodWorld) totalSegments *= 2; diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 026b57fa0d..2f022602fe 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -2467,7 +2467,7 @@ namespace CalamityMod.Projectiles } #endregion - #region CanDamage + #region CanDamage + CanHit public override bool? CanDamage(Projectile projectile) { if (projectile.hostile && (projectile.damage - (int)(damageReduction * (Main.expertMode ? 0.25f : 0.5f)) <= 0)) @@ -2497,6 +2497,16 @@ namespace CalamityMod.Projectiles } return null; } + + // Cultist lightning orbs cannot hit players specifically. This could probably be switched to CanDamage? + public override bool CanHitPlayer(Projectile projectile, Player target) + { + if (projectile.type == ProjectileID.CultistBossLightningOrb) + { + return false; + } + return true; + } #endregion #region Drawing @@ -2662,17 +2672,6 @@ namespace CalamityMod.Projectiles } #endregion - #region CanHit - public override bool CanHitPlayer(Projectile projectile, Player target) - { - if (projectile.type == ProjectileID.CultistBossLightningOrb) - { - return false; - } - return true; - } - #endregion - #region LifeSteal public static bool CanSpawnLifeStealProjectile(float healMultiplier, float healAmount) { diff --git a/Projectiles/Ranged/ExoCrystalArrow.cs b/Projectiles/Ranged/ExoCrystalArrow.cs index 799d2a1713..0fb55bfe35 100644 --- a/Projectiles/Ranged/ExoCrystalArrow.cs +++ b/Projectiles/Ranged/ExoCrystalArrow.cs @@ -129,7 +129,6 @@ namespace CalamityMod.Projectiles.Ranged int lightning = Projectile.NewProjectile(Projectile.GetSource_FromThis(), lightningSpawnPosition, lightningShootVelocity, ModContent.ProjectileType(), lightningDamage, 0f, Projectile.owner); if (Main.projectile.IndexInRange(lightning)) { - Main.projectile[lightning].CritChance = Projectile.CritChance; Main.projectile[lightning].ai[0] = lightningShootVelocity.ToRotation(); Main.projectile[lightning].ai[1] = Main.rand.Next(100); } diff --git a/Projectiles/Ranged/ExoFlare.cs b/Projectiles/Ranged/ExoFlare.cs index 1d4475778c..45e1e85147 100644 --- a/Projectiles/Ranged/ExoFlare.cs +++ b/Projectiles/Ranged/ExoFlare.cs @@ -76,7 +76,7 @@ namespace CalamityMod.Projectiles.Ranged float colorInterpolation = (float)Math.Cos(Projectile.timeLeft / 16f + Main.GlobalTimeWrappedHourly / 20f + i / (float)Projectile.oldPos.Length * MathHelper.Pi) * 0.5f + 0.5f; Color color = Color.Lerp(Color.LightGreen, Color.LightPink, colorInterpolation) * 0.4f; color.A = 0; - Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY) + new Vector2(-25f, -25f); Color outerColor = color; Color innerColor = color * 0.5f; float intensity = 0.9f + 0.15f * (float)Math.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi); diff --git a/Projectiles/Ranged/ExoLight.cs b/Projectiles/Ranged/ExoLight.cs index eb4fe298d0..df4c7a12e3 100644 --- a/Projectiles/Ranged/ExoLight.cs +++ b/Projectiles/Ranged/ExoLight.cs @@ -145,7 +145,7 @@ namespace CalamityMod.Projectiles.Ranged Color.SlateGray }) * Projectile.Opacity; color.A = 0; - Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY) + new Vector2(-15f, -15f); Color outerColor = color; Color innerColor = color * 0.5f; float intensity = 0.9f + 0.15f * (float)Math.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi); diff --git a/Projectiles/Ranged/HydraHead.cs b/Projectiles/Ranged/HydraHead.cs new file mode 100644 index 0000000000..fbf084a037 --- /dev/null +++ b/Projectiles/Ranged/HydraHead.cs @@ -0,0 +1,250 @@ +using CalamityMod.DataStructures; +using CalamityMod.Items.Weapons.Ranged; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class HydraHead : ModProjectile + { + public override string Texture => "CalamityMod/Items/Weapons/Ranged/Hydra"; + + public Vector2 CurrentPositionOffset; + public Vector2 IdealPositionOffset; + public Vector2[] OldVelocities = new Vector2[20]; + public Player Owner => Main.player[Projectile.owner]; + + public ref float Time => ref Projectile.ai[0]; + public ref float AttackType => ref Projectile.ai[1]; + + public Vector2 DrawStartPosition + { + get + { + if (Projectile.owner < 0 || Projectile.owner >= Main.player.Length) + return Vector2.Zero; + return Main.player[Projectile.owner].Top + Vector2.UnitY * 8f; + } + } + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Hydra Head"); + } + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 30; //66x30 sprite + Projectile.friendly = true; + Projectile.netImportant = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.timeLeft = 600; + Projectile.penetrate = 1; + Projectile.DamageType = DamageClass.Ranged; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.WritePackedVector2(CurrentPositionOffset); + writer.WritePackedVector2(IdealPositionOffset); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + CurrentPositionOffset = reader.ReadPackedVector2(); + IdealPositionOffset = reader.ReadPackedVector2(); + } + + public override void AI() + { + if (Owner.dead || !Owner.active || Owner.ActiveItem().type != ModContent.ItemType()) + Projectile.Kill(); + else + Projectile.timeLeft = 2; //Infinite lifespan + + Vector2 returnPosition = DrawStartPosition + CurrentPositionOffset; + + if (Projectile.localAI[0] == 0f) + { + PerformInitializationEffects(); + Projectile.localAI[0] = 1f; + } + + Vector2 aimDestination = Owner.Calamity().mouseWorld; + float idealRotation = Projectile.AngleTo(aimDestination); + if (Time < 0f) + Projectile.rotation = MathHelper.Lerp(Projectile.rotation, idealRotation, (Time + 15f) / 15f); + else + Projectile.rotation = idealRotation; + + Projectile.Center = new Vector2(Projectile.Center.X, MathHelper.Clamp(Projectile.Center.Y, 1f, returnPosition.Y - 8f)); + MoveTowardsDestination(returnPosition); + AdjustOldVelocityArray(); + + PerformAttacks(aimDestination); + } + + public void PerformInitializationEffects() + { + int totalHeads = Owner.ownedProjectileCounts[Projectile.type]; + CurrentPositionOffset = IdealPositionOffset = new Vector2(Main.rand.NextFloat(-72f - 8f * totalHeads, 72f + 8f * totalHeads), -Main.rand.NextFloat(8f, 84f + 4f * totalHeads)); + Projectile.netUpdate = true; + } + + public void MoveTowardsDestination(Vector2 returnPosition) + { + float distanceFromTarget = Projectile.Distance(returnPosition); + if (distanceFromTarget > 7f) + { + float flySpeed = MathHelper.Lerp(2f, 17f, Utils.GetLerpValue(10f, 70f, distanceFromTarget, true)); + Projectile.velocity = (Projectile.velocity * 9f + Projectile.SafeDirectionTo(returnPosition) * flySpeed) / 10f; + } + + int totalHeads = Owner.ownedProjectileCounts[Projectile.type]; + int moveRate = 40 + totalHeads * 4; + + // Reset the ideal offset from time to time. + Time++; + if (Time % moveRate == moveRate - 1f) + IdealPositionOffset = new Vector2(Main.rand.NextFloat(-72f - 8f * totalHeads, 72f + 8f * totalHeads), -Main.rand.NextFloat(8f, 84f + 4f * totalHeads)); + + if (Vector2.Distance(IdealPositionOffset, CurrentPositionOffset) > 0.2f) + CurrentPositionOffset = Vector2.Lerp(CurrentPositionOffset, IdealPositionOffset, 0.125f); + + // Clamp the Y position. + if (Projectile.Center.Y > Owner.Top.Y - 46f) + Projectile.Center = new Vector2(Projectile.Center.X, Owner.Top.Y - 46f); + + // Clamp the center so that it does not go too far from the return position. + if (Projectile.Distance(returnPosition) > 120f) + Projectile.Center = returnPosition + Projectile.DirectionFrom(returnPosition) * 120f; + + // Disallow heads from getting too close to each other. + Projectile.MinionAntiClump(0.15f); + } + + public void AdjustOldVelocityArray() + { + for (int i = OldVelocities.Length - 1; i > 0; i--) + OldVelocities[i] = OldVelocities[i - 1]; + + OldVelocities[0] = Projectile.velocity; + } + + public void PerformAttacks(Vector2 aimDestination) + { + Item heldItem = Owner.ActiveItem(); + + Vector2 shootDirection = Projectile.SafeDirectionTo(aimDestination); + + //Normal shot + if (AttackType > 0f) + { + //Calculation for damage and co + Owner.PickAmmo(heldItem, out _, out float itemVelocity, out int itemDamage, out float itemKB, out _); + int type = ModContent.ProjectileType(); + for (int i = 0; i < 4; i++) + { + Vector2 spreadDirection = shootDirection.RotatedByRandom(MathHelper.ToRadians(Hydra.ShotSpread / 2f)); + float spreadVelocity = itemVelocity * Main.rand.NextFloat(1f, 1.4f); + Vector2 shootPos = Projectile.Center + shootDirection * 24f; + + Projectile.NewProjectile(Projectile.GetSource_FromThis(), shootPos, spreadVelocity * spreadDirection, type, itemDamage, itemKB, Projectile.owner); + } + + //Minor recoil + Projectile.rotation -= MathHelper.ToRadians(25f) * Math.Sign(Projectile.rotation); + Time = -15f; //Reset the movement shift and let it recoil normally + Projectile.velocity += shootDirection * -10f; + + //Reset the attack + AttackType = 0f; + } + //Yeet + else if (AttackType < 0f) + { + //Calculation for damage and co + Owner.PickAmmo(heldItem, out _, out float itemVelocity, out int itemDamage, out float itemKB, out _); + int gunType = ModContent.ProjectileType(); + int gunDamage = itemDamage * 3; + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, itemVelocity * shootDirection, gunType, gunDamage, itemKB, Projectile.owner); + + Projectile.Kill(); + } + } + + public override void Kill(int timeLeft) + { + if (Main.dedServ) + return; + + for (int i = 0; i < 10; i++) + Dust.NewDustPerfect(Projectile.Center, 171, Main.rand.NextVector2CircularEdge(4f, 4f)).noGravity = true; + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D chain = ModContent.Request("CalamityMod/Projectiles/Ranged/HydraHeadChain").Value; + Vector2 end = Projectile.Center + (Projectile.spriteDirection == 1).ToInt() * 10 * Vector2.UnitX; + + List controlPoints = new List + { + DrawStartPosition + }; + for (int i = 0; i < OldVelocities.Length; i++) + { + // Incorporate the past movement into neck turns, giving it rubber band-like movment. + // Become less responsive at the neck ends. Having the ends have typical movement can look strange sometimes. + float swayResponsiveness = Utils.GetLerpValue(0f, 6f, i, true) * Utils.GetLerpValue(OldVelocities.Length, OldVelocities.Length - 6f, i, true); + Vector2 swayTotalOffset = OldVelocities[i] * swayResponsiveness; + controlPoints.Add(Vector2.Lerp(DrawStartPosition, end, i / (float)OldVelocities.Length) + swayTotalOffset); + } + controlPoints.Add(end); + + int chainPointCount = (int)(Vector2.Distance(controlPoints.First(), controlPoints.Last()) / 5f); + if (chainPointCount < 12) + chainPointCount = 12; + BezierCurve bezierCurve = new BezierCurve(controlPoints.ToArray()); + List chainPoints = bezierCurve.GetPoints(chainPointCount); + + for (int i = 0; i < chainPoints.Count; i++) + { + Vector2 positionAtPoint = chainPoints[i]; + if (Vector2.Distance(positionAtPoint, Projectile.Center) < 10f) + continue; + float angleAtPoint = i == chainPoints.Count - 1 ? (end - chainPoints[i]).ToRotation() : (chainPoints[i + 1] - chainPoints[i]).ToRotation(); + angleAtPoint += MathHelper.PiOver2; + Main.EntitySpriteDraw(chain, + positionAtPoint - Main.screenPosition, + null, + Color.Lerp(Color.White, Color.Transparent, 0.6f), + angleAtPoint, + chain.Size() / 2f, + 1f, + SpriteEffects.None, + 0); + } + + Texture2D headTexture = ModContent.Request(Texture).Value; + Main.EntitySpriteDraw(headTexture, + Projectile.Center - Main.screenPosition + Vector2.UnitY * Projectile.gfxOffY, + null, + lightColor, + Projectile.rotation, + Projectile.Size * 0.5f, + Projectile.scale, + Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, + 0); + + return false; + } + + public override bool? CanDamage() => false; + } +} \ No newline at end of file diff --git a/Projectiles/Ranged/HydraHeadChain.png b/Projectiles/Ranged/HydraHeadChain.png new file mode 100644 index 0000000000..688841e42b Binary files /dev/null and b/Projectiles/Ranged/HydraHeadChain.png differ diff --git a/Projectiles/Ranged/HydraHeadLaunch.cs b/Projectiles/Ranged/HydraHeadLaunch.cs new file mode 100644 index 0000000000..0d2efcabc4 --- /dev/null +++ b/Projectiles/Ranged/HydraHeadLaunch.cs @@ -0,0 +1,66 @@ +using CalamityMod.Sounds; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.Audio; + +namespace CalamityMod.Projectiles.Ranged +{ + public class HydraHeadLaunch : ModProjectile + { + public override string Texture => "CalamityMod/Items/Weapons/Ranged/Hydra"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Hydra Head"); + } + + public override void SetDefaults() + { + Projectile.width = 66; + Projectile.height = 30; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.timeLeft = 360; + Projectile.MaxUpdates = 3; + Projectile.penetrate = 1; + Projectile.DamageType = DamageClass.Ranged; + Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration; + } + + //Normal hitbox size for explosion, rotated otherwise + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => (Projectile.ai[1] < 1f ? Projectile.RotatingHitboxCollision(targetHitbox.TopLeft(), targetHitbox.Size()) : null); + + public override void AI() + { + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.ToRadians(Projectile.ai[0]); + Projectile.ai[0] += 12f; + } + + public override void Kill(int timeLeft) + { + Projectile.ai[1] = 1f; + Projectile.ExpandHitboxBy(180); + Projectile.Damage(); + + float randAngle = Main.rand.NextFloat(1f, 2f); + //8-pointed star + for (int i = 0; i < 8; i++) + { + float angle = MathHelper.Pi * randAngle - i * MathHelper.TwoPi / 8f; + float nextAngle = MathHelper.Pi * randAngle - (i + 2) * MathHelper.TwoPi / 8f; + Vector2 start = angle.ToRotationVector2(); + Vector2 end = nextAngle.ToRotationVector2(); + for (int j = 0; j < 30; j++) + { + Dust starDust = Dust.NewDustPerfect(Projectile.Center, 267); + starDust.scale = 1.5f; + starDust.velocity = Vector2.Lerp(start, end, j / 30f) * 12f; + starDust.color = Color.Orchid; + starDust.noGravity = true; + } + } + SoundEngine.PlaySound(CommonCalamitySounds.LargeWeaponFireSound, Projectile.Center); + } + } +} \ No newline at end of file diff --git a/Projectiles/Ranged/HydrasBlood.cs b/Projectiles/Ranged/HydrasBlood.cs new file mode 100644 index 0000000000..39e6f8b577 --- /dev/null +++ b/Projectiles/Ranged/HydrasBlood.cs @@ -0,0 +1,65 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class HydrasBlood : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Magic/VitriolicViperSpit"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Hydra's Blood"); + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 14; + Projectile.height = 26; + Projectile.friendly = true; + Projectile.timeLeft = 90; + Projectile.MaxUpdates = 5; + Projectile.penetrate = 1; + Projectile.DamageType = DamageClass.Ranged; + Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => Projectile.RotatingHitboxCollision(targetHitbox.TopLeft(), targetHitbox.Size()); + + public override void AI() + { + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; + if (Projectile.timeLeft < 85 && Main.rand.NextBool(3)) + { + Dust dust = Dust.NewDustDirect(Projectile.Center, 1, 1, 171); + dust.velocity = Projectile.velocity.RotatedByRandom(MathHelper.ToRadians(5f)) * -0.5f; + dust.scale = Main.rand.NextFloat(0.3f, 1.6f); + dust.noGravity = true; + } + } + + public override void Kill(int timeLeft) + { + for (int i = 0; i < 14; i++) + { + Dust dust = Dust.NewDustDirect(Projectile.position, 14, 14, 171); + dust.scale = Main.rand.NextFloat(0.3f, 1.6f); + dust.noGravity = true; + } + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(BuffID.Venom, 300); + } + + public override void OnHitPvp(Player target, int damage, bool crit) + { + target.AddBuff(BuffID.Venom, 300); + } + } +} diff --git a/Projectiles/Summon/BelladonnaPetal.cs b/Projectiles/Summon/BelladonnaPetal.cs index cf26e0fd6d..4812eb10e4 100644 --- a/Projectiles/Summon/BelladonnaPetal.cs +++ b/Projectiles/Summon/BelladonnaPetal.cs @@ -1,49 +1,146 @@ using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.Audio; +using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Summon { public class BelladonnaPetal : ModProjectile { + public Player Owner => Main.player[Projectile.owner]; + + public ref float AITimer => ref Projectile.ai[0]; // The timer for the AI to do it's actions. + + public ref float CheckForFiring => ref Projectile.ai[1]; // Check for when it's about to fire, so we can put one-time effects and sounds. + + public NPC targetFound; // A variable where the potential target will be written on. + public override void SetStaticDefaults() { - DisplayName.SetDefault("Bullet"); + DisplayName.SetDefault("Belladonna Petal"); ProjectileID.Sets.MinionShot[Projectile.type] = true; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 5; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; } public override void SetDefaults() { - Projectile.width = 10; - Projectile.height = 12; + Projectile.width = 14; + Projectile.height = 24; Projectile.friendly = true; Projectile.minion = true; Projectile.minionSlots = 0f; Projectile.ignoreWater = true; + Projectile.tileCollide = false; Projectile.penetrate = 1; - Projectile.timeLeft = 360; + Projectile.timeLeft = 130; Projectile.DamageType = DamageClass.Summon; } + public override void AI() - { - Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; - Projectile.velocity.X *= 0.99f; - if (Projectile.velocity.Y < 9f) - Projectile.velocity.Y += 0.085f; - Projectile.tileCollide = Projectile.timeLeft <= 180; + { + if (Owner.HasMinionAttackTargetNPC) // If the Owner has selected for a target manually, go for that one. + { + NPC manualTarget = Main.npc[Owner.MinionAttackTargetNPC]; + Behaviour(manualTarget); + } + else // If not, go for the closest one. + { + NPC potentialTarget = Projectile.Center.MinionHoming(1200f, Owner); + Behaviour(potentialTarget); + } + + AITimer++; + AITimer = (AITimer > 60f) ? 60f : AITimer; // AITimer can reach only a maximun of 60. + Lighting.AddLight(Projectile.Center, 0.5f, 1f, 0.3f); // Gives it a jungl-y green color. } + + #region Methods + + public void Behaviour(NPC target) + { + if (target != null && AITimer >= 60f) // If the target is found, and 1 second has passed, do effects and go to the target. + { + Projectile.alpha = 0; + for (int i = 0; i < 5; i++) + { + Dust gotTarget = Dust.NewDustPerfect(Projectile.Center, DustID.Grass); + gotTarget.velocity = Main.rand.NextVector2Circular(2f, 2f); + gotTarget.noGravity = true; + } + if (CheckForFiring == 0f) // Check for it so it doesn't update the velocity indefinetly, meaning it would be homing. + { + Projectile.velocity = CalamityUtils.CalculatePredictiveAimToTarget(Projectile.Center, targetFound, 20f); + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; + SoundEngine.PlaySound(SoundID.Grass, Projectile.Center); + CheckForFiring = 1f; + Projectile.netUpdate= true; + } + } + else if (target != null && AITimer < 60f) // If there's target, but 1 second hasn't passed, rotate to point at the target, while still having gravity. + { + Projectile.velocity.Y += 0.2f; + Projectile.rotation = MathHelper.Lerp(Projectile.rotation, (target.Center - Projectile.Center).ToRotation() + MathHelper.PiOver2, AITimer / 60f); + // (AITimer / 60f) because 60 is maximum time of the timer. + targetFound = target; + // Puts the potentialTarget on this variable that won't update constantly so the projectile doesn't become incredibly homing. + Projectile.netUpdate = true; + } + else // If there's no target when shot (For example when the enemy has been killed), just fall. + { + AITimer = 0f; // Restart the timer, just so if a target appears again it looks smoother. + Projectile.alpha += 2; + Projectile.velocity.Y += 0.2f; + Projectile.rotation += 0.05f; // Continues spinning until it dies. + Projectile.netUpdate = true; + } + } + public override void Kill(int timeLeft) { for (int i = 0; i < 5; i++) { - Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.Grass); - dust.velocity = Main.rand.NextVector2Circular(2f, 2f); - dust.noGravity = true; + Dust projDeath = Dust.NewDustPerfect(Projectile.Center, DustID.Grass); + projDeath.velocity = Main.rand.NextVector2Circular(2f, 2f); + projDeath.noGravity = true; } } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + + public override bool? CanDamage() // If the projectile is going to the target, do damage, if not, don't. { - target.AddBuff(BuffID.Poisoned, 240); + if (targetFound != null && AITimer >= 60f) + { + return null; + } + + return false; } + + public override bool OnTileCollide(Vector2 oldVelocity) => false; + + public override bool PreDraw(ref Color lightColor) // Code taken from ExampleMod to make the trail. + { + Main.instance.LoadProjectile(Projectile.type); + Texture2D texture = TextureAssets.Projectile[Projectile.type].Value; + + if (CheckForFiring == 1f) + { + Vector2 drawOrigin = new Vector2(texture.Width * 0.5f, Projectile.height * 0.5f); + for (int k = 0; k < Projectile.oldPos.Length; k++) + { + Vector2 drawPos = (Projectile.oldPos[k] - Main.screenPosition) + drawOrigin + new Vector2(0f, Projectile.gfxOffY); + Color color = Projectile.GetAlpha(lightColor) * ((Projectile.oldPos.Length - k) / (float)Projectile.oldPos.Length); + Main.EntitySpriteDraw(texture, drawPos, null, color, Projectile.rotation, drawOrigin, Projectile.scale, SpriteEffects.None, 0); + } + } + return true; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => target.AddBuff(BuffID.Poisoned, 240); + + #endregion } } diff --git a/Projectiles/Summon/BelladonnaPetal.png b/Projectiles/Summon/BelladonnaPetal.png index ddd5d1aac1..43bc9ac92d 100644 Binary files a/Projectiles/Summon/BelladonnaPetal.png and b/Projectiles/Summon/BelladonnaPetal.png differ diff --git a/Projectiles/Summon/BelladonnaSpirit.cs b/Projectiles/Summon/BelladonnaSpirit.cs index 2f36c44848..36d433023e 100644 --- a/Projectiles/Summon/BelladonnaSpirit.cs +++ b/Projectiles/Summon/BelladonnaSpirit.cs @@ -5,15 +5,20 @@ using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Summon { public class BelladonnaSpirit : ModProjectile { + public Player Owner => Main.player[Projectile.owner]; + public CalamityPlayer moddedOwner => Owner.Calamity(); + public float PetalFireTimer { get => Projectile.ai[0]; set => Projectile.ai[0] = value; } + public override void SetStaticDefaults() { DisplayName.SetDefault("Belladonna Spirit"); @@ -29,9 +34,7 @@ namespace CalamityMod.Projectiles.Summon Projectile.netImportant = true; Projectile.friendly = true; Projectile.minionSlots = 1; - Projectile.timeLeft = 18000; Projectile.penetrate = -1; - Projectile.timeLeft *= 5; Projectile.minion = true; Projectile.tileCollide = false; Projectile.DamageType = DamageClass.Summon; @@ -39,124 +42,126 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { - Player player = Main.player[Projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - if (Projectile.localAI[0] == 0f) + CheckMinionExistance(); // Checks if the minion can still exist. + SpawnEffect(); // Makes a dust effect where the minion spawns. + DoAnimation(); // Does the animation of the minion. + PointInDirection(); // Points in the right directions. + FollowPlayer(); // Vibes around the player. + Projectile.MinionAntiClump(); // The minions push eachother to not clump. + + NPC potentialTarget = Projectile.Center.MinionHoming(1200f, Owner); + if (potentialTarget is not null) { - Initialize(player); - Projectile.localAI[0] = 1f; + TargetNPC(); } - if (Projectile.frameCounter++ > 6f) + } + + #region Methods + + public void CheckMinionExistance() + { + Owner.AddBuff(ModContent.BuffType(), 1); + if (Projectile.type == ModContent.ProjectileType()) { - Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Projectile.type]; - Projectile.frameCounter = 0; - } - bool isCorrectProjectile = Projectile.type == ModContent.ProjectileType(); - player.AddBuff(ModContent.BuffType(), 3600); - if (isCorrectProjectile) - { - if (player.dead) + if (Owner.dead) { - modPlayer.belladonaSpirit = false; + moddedOwner.belladonaSpirit = false; } - if (modPlayer.belladonaSpirit) + if (moddedOwner.belladonaSpirit) { Projectile.timeLeft = 2; } } - - if (Projectile.velocity.X > 0.25f) - Projectile.spriteDirection = -1; - else if (Projectile.velocity.X < -0.25f) - Projectile.spriteDirection = 1; - - NPC potentialTarget = Projectile.Center.MinionHoming(1200f, player); - if (potentialTarget is null) - { - Vector2 targetPosition = player.Bottom; - FollowPlayer(player, targetPosition); - } - else - { - TargetNPC(potentialTarget); - } - Projectile.MinionAntiClump(); } - public void Initialize(Player player) + + public void SpawnEffect() { - for (int i = 0; i < 45; i++) + if (Projectile.localAI[0] == 0f) { - float angle = MathHelper.TwoPi / 45f * i; - Vector2 velocity = angle.ToRotationVector2() * 4f; - Dust dust = Dust.NewDustPerfect(Projectile.Center + velocity * 2.75f, 39, velocity); - dust.noGravity = true; + for (int i = 0; i < 45; i++) + { + float angle = MathHelper.TwoPi / 45f * i; + Vector2 velocity = angle.ToRotationVector2() * 4f; + Dust dust = Dust.NewDustPerfect(Projectile.Center + velocity * 2.75f, 39, velocity); + dust.noGravity = true; + } + Projectile.localAI[0] = 1f; } } - public void FollowPlayer(Player player, Vector2 targetPosition) + + public void DoAnimation() { - Projectile.velocity.X = (player.Center.X + player.direction * 75f - Projectile.Center.X) / 60f; - if (Projectile.Distance(player.Center) > 2500f || - targetPosition.Y - Projectile.Top.Y > 360f) + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type]; + } + + public void PointInDirection() + { + NPC potentialTarget = Projectile.Center.MinionHoming(1200f, Owner); + if (potentialTarget is not null) // If there's a target look at the target. { - Projectile.Center = player.Center; + Projectile.spriteDirection = ((potentialTarget.Center.X - Projectile.Center.X) < 0).ToDirectionInt(); + } + else // If there's not a target, the minion just points where it's going. + { + if (Math.Abs(Projectile.velocity.X) > 0.01f) + Projectile.spriteDirection = -Math.Sign(Projectile.velocity.X); + } + } + + public void FollowPlayer() + { + if (Projectile.WithinRange(Owner.Center, 1200f) && !Projectile.WithinRange(Owner.Center, 300f)) // If the minion starts to get far, force the minion to go to you. + { + Projectile.velocity = (Owner.Center - Projectile.Center) / 30f; + Projectile.netUpdate= true; + } + else if (!Projectile.WithinRange(Owner.Center, 160f)) // The minion will change directions to you if it's going away from you, meaning it'll just hover around you. + { + Projectile.velocity = (Projectile.velocity * 37f + Projectile.SafeDirectionTo(Owner.Center) * 17f) / 40f; Projectile.netUpdate = true; } - else if (targetPosition.Y - Projectile.Top.Y < -550f) + + // Teleport to the owner if sufficiently far away. + if (!Projectile.WithinRange(Owner.Center, 1200f)) { - Projectile.velocity.Y += Math.Sign(targetPosition.Y - targetPosition.Y) * 0.08f; - } - else - { - Projectile.velocity.Y = (targetPosition.Y - Projectile.Center.Y) / 60f; + Projectile.position = Owner.Center; + Projectile.velocity *= 0.3f; + Projectile.netUpdate = true; } } - public void TargetNPC(NPC target) + + public void TargetNPC() { - Vector2 targetPosition = target.Center; - if (Math.Abs(targetPosition.X - Projectile.Center.X) < 180f) - { - Projectile.velocity.X *= 0.95f; - PetalFireTimer++; - if (Main.myPlayer == Projectile.owner) - FirePetals(target); - } - else - { - Projectile.velocity.X += (targetPosition.X - Projectile.Center.X + target.spriteDirection * 75f > 0).ToDirectionInt() * 0.5f; - Projectile.velocity.X = MathHelper.Clamp(Projectile.velocity.X, -12f, 12f); - } - Projectile.velocity.Y = (targetPosition.Y - Projectile.Center.Y + target.spriteDirection * 75f) / 90f; + PetalFireTimer++; + Projectile.velocity.Y -= MathHelper.Lerp(0, 0.005f, PetalFireTimer % 75f); + // The minion will slowly go up until it throws the petal. + // This essentially makes the minion stay above you and trigger the "Turn back to player", it'll do this continuously, giving the effect of bouncing. + PetalFireTimer = (PetalFireTimer == 76f) ? 1f : PetalFireTimer; // The timer cannot go above 75f. + if (Main.myPlayer == Projectile.owner) + FirePetals(); + Projectile.netUpdate = true; } - public void FirePetals(NPC target) + + public void FirePetals() { int petalID = ModContent.ProjectileType(); - if (PetalFireTimer % 20f == 19f) + if (PetalFireTimer % 75f == 0f) // Every 75 frames, throws a petal. { - for (int i = -1; i <= 1; i++) + Vector2 petalShootVelocity = (-Vector2.UnitY * Main.rand.NextFloat(7f, 9f)) + Projectile.velocity; + // Throws the petal upwards with a random force and inherits the minion's speed. + int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, petalShootVelocity, petalID, Projectile.damage, Projectile.knockBack, Projectile.owner); + if (Main.projectile.IndexInRange(p)) { - float angle = Main.rand.NextFloat(-0.1f, 0.1f) + i * 0.05f; - Vector2 petalSpawnPosition = Projectile.Center - Vector2.UnitY * 6f; - Vector2 petalShootVelocity = Projectile.SafeDirectionTo(target.Center).RotatedBy(angle) * 7.5f; - int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), petalSpawnPosition, petalShootVelocity, petalID, Projectile.damage, Projectile.knockBack, Projectile.owner); - if (Main.projectile.IndexInRange(p)) - Main.projectile[p].originalDamage = Projectile.originalDamage; - } - } - - if (PetalFireTimer % 180f == 179f) - { - for (int i = 0; i < 5; i++) - { - float angle = MathHelper.Lerp(MathHelper.ToRadians(-Main.rand.NextFloat(30f, 36f)), MathHelper.ToRadians(Main.rand.NextFloat(30f, 36f)), i / 4f); - Vector2 petalSpawnPosition = Projectile.Center - Vector2.UnitY * 6f; - Vector2 petalShootVelocity = -Vector2.UnitY.RotatedBy(angle) * 9f; - int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), petalSpawnPosition, petalShootVelocity, petalID, Projectile.damage, Projectile.knockBack, Projectile.owner); - if (Main.projectile.IndexInRange(p)) - Main.projectile[p].originalDamage = Projectile.originalDamage; + Main.projectile[p].originalDamage = Projectile.originalDamage; + Main.projectile[p].rotation = Main.rand.NextFloat(0, MathHelper.TwoPi); } + Projectile.netUpdate = true; } } public override bool? CanDamage() => false; + + #endregion } } diff --git a/Projectiles/Summon/Cinder.cs b/Projectiles/Summon/Cinder.cs index 7781c50d54..04dc668e6b 100644 --- a/Projectiles/Summon/Cinder.cs +++ b/Projectiles/Summon/Cinder.cs @@ -1,18 +1,16 @@ -using CalamityMod.Buffs.DamageOverTime; -using Microsoft.Xna.Framework; -using System; +using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Summon { public class Cinder : ModProjectile { + public Player Owner => Main.player[Projectile.owner]; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - public const float FallAcceleration = 0.185f; - public const float FallSpeedMax = 16; - public const float FallDelay = 300; public override void SetStaticDefaults() { DisplayName.SetDefault("Cinder"); @@ -21,9 +19,10 @@ namespace CalamityMod.Projectiles.Summon public override void SetDefaults() { - Projectile.width = 6; + Projectile.width = 12; Projectile.height = 12; Projectile.friendly = true; + Projectile.tileCollide = false; Projectile.penetrate = 3; Projectile.timeLeft = 300; Projectile.usesIDStaticNPCImmunity = true; @@ -34,61 +33,17 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { - if (Projectile.velocity.X != Projectile.velocity.X) - { - Projectile.velocity.X *= -0.1f; - } - if (Projectile.velocity.X != Projectile.velocity.X) - { - Projectile.velocity.X *= -0.5f; - } - if (Projectile.velocity.Y != Projectile.velocity.Y && Projectile.velocity.Y > 1f) - { - Projectile.velocity.Y *= -0.5f; - } - Projectile.ai[0]++; - if (Projectile.ai[0] > 5f) - { - Projectile.ai[0] = 5f; - if (Projectile.velocity.Y == 0f && Projectile.velocity.X != 0f) - { - Projectile.velocity.X *= 0.97f; - if (Math.Abs(Projectile.velocity.X) < 0.01) - { - Projectile.velocity.X = 0f; - Projectile.netUpdate = true; - } - } - } + SpawnDust(); + Lighting.AddLight(Projectile.Center, Color.Orange.ToVector3()); + } - if (Projectile.ai[0] >= FallDelay && Projectile.velocity.Y < FallSpeedMax) - { - Projectile.velocity.Y += FallAcceleration; - } - - Projectile.rotation += Projectile.velocity.X * 0.1f; - int idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 6, 0f, 0f, 100, default, 1f); - Main.dust[idx].position += new Vector2(2f); - Main.dust[idx].scale += Main.rand.NextFloat(0.5f); - Main.dust[idx].noGravity = true; - Main.dust[idx].velocity.Y -= 2f; - if (Main.rand.NextBool(2)) - { - idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 6, 0f, 0f, 100, default, 1f); - Main.dust[idx].position += new Vector2(2f); - Main.dust[idx].scale += 0.3f + Main.rand.NextFloat(0.5f); - Main.dust[idx].noGravity = true; - Main.dust[idx].velocity.Y -= 2f; - } - if (Projectile.velocity.Y < 0.25f && Projectile.velocity.Y > 0.15f) - { - Projectile.velocity.X *= 0.8f; - } - Projectile.rotation = -Projectile.velocity.X * 0.05f; - if (Projectile.velocity.Y > 16f) - { - Projectile.velocity.Y = 16f; - } + public void SpawnDust() + { + int bootlegTexture = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Torch, 0f, 0f, 100, default, 1f); + Main.dust[bootlegTexture].position += new Vector2(2f); + Main.dust[bootlegTexture].scale += 0.3f + Main.rand.NextFloat(0.5f); + Main.dust[bootlegTexture].noGravity = true; + Main.dust[bootlegTexture].velocity.Y -= 2f; } public override bool OnTileCollide(Vector2 oldVelocity) => false; diff --git a/Projectiles/Summon/CinderBlossom.cs b/Projectiles/Summon/CinderBlossom.cs index 532633b8c6..4cf387ca12 100644 --- a/Projectiles/Summon/CinderBlossom.cs +++ b/Projectiles/Summon/CinderBlossom.cs @@ -4,15 +4,21 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Summon { public class CinderBlossom : ModProjectile { - public float Time + public Player Owner => Main.player[Projectile.owner]; + + public CalamityPlayer moddedOwner => Owner.Calamity(); + + public float DelayBetweenShooting { get => Projectile.ai[0]; set => Projectile.ai[0] = value; } + public override void SetStaticDefaults() { DisplayName.SetDefault("Cinder Blossom"); @@ -22,73 +28,75 @@ namespace CalamityMod.Projectiles.Summon public override void SetDefaults() { - Projectile.width = 36; - Projectile.height = 40; + Projectile.width = 42; + Projectile.height = 42; Projectile.netImportant = true; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.minionSlots = 1f; - Projectile.timeLeft = 18000; Projectile.penetrate = -1; Projectile.tileCollide = false; - Projectile.timeLeft *= 5; Projectile.minion = true; Projectile.DamageType = DamageClass.Summon; } public override void AI() { - bool isCorrectMinion = Projectile.type == ModContent.ProjectileType(); - Player player = Main.player[Projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - player.AddBuff(ModContent.BuffType(), 3600); - if (isCorrectMinion) + CheckMinionExistance(); // Checks if the minion can still exist. + EffectWhenSpawned(); // Makes a dust effect when it spawns + + NPC potentialTarget = Projectile.Center.MinionHoming(1200f, Owner); + if (Projectile.owner == Main.myPlayer) { - if (player.dead) + if (potentialTarget != null) { - modPlayer.cinderBlossom = false; + if (DelayBetweenShooting % 35f == 0f) // Shoots once every 35 frames. + { + Vector2 velocity = CalamityUtils.CalculatePredictiveAimToTarget(Projectile.Center, potentialTarget, 20f); + int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + if (Main.projectile.IndexInRange(p)) + Main.projectile[p].originalDamage = Projectile.originalDamage; + Projectile.netUpdate = true; + } + DelayBetweenShooting++; + DelayBetweenShooting = (DelayBetweenShooting == 36f) ? 0f : DelayBetweenShooting; // The timer cannot go above 35. } - if (modPlayer.cinderBlossom) + } + + Projectile.Center = Owner.Center - Vector2.UnitY * 60f; + Projectile.rotation += MathHelper.ToRadians((potentialTarget is not null) ? 3f * (potentialTarget.Center.X - Projectile.Center.X > 0).ToDirectionInt() : 1.5f * Owner.direction); + // The projectile normally will spin in the direction of the player. + // If an enemy is detected, it will spin faster, in the direction of where the enemy is. + Lighting.AddLight(Projectile.Center, Color.Orange.ToVector3()); + } + + public void CheckMinionExistance() + { + Owner.AddBuff(ModContent.BuffType(), 1); + if (Projectile.type == ModContent.ProjectileType()) + { + if (Owner.dead) + { + moddedOwner.cinderBlossom = false; + } + if (moddedOwner.cinderBlossom) { Projectile.timeLeft = 2; } } - Projectile.Center = player.Center + Vector2.UnitY * (player.gfxOffY - 60f); - if (player.gravDir == -1f) - Projectile.position.Y += 120f; - Projectile.position.X = (int)Projectile.position.X; - Projectile.position.Y = (int)Projectile.position.Y; - Projectile.position = Projectile.position.Floor(); - Projectile.rotation += MathHelper.ToRadians(1.5f) * player.direction; + } + public void EffectWhenSpawned() + { if (Projectile.localAI[0] == 0f) { - Initialize(player); - Projectile.localAI[0] = 1f; - } - if (Projectile.owner == Main.myPlayer) - { - NPC potentialTarget = Projectile.Center.MinionHoming(700f, player); - if (potentialTarget != null) + for (int i = 0; i < 36; i++) { - if (Time++ % 35f == 34f && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, potentialTarget.position, potentialTarget.width, potentialTarget.height)) - { - Vector2 velocity = Projectile.SafeDirectionTo(potentialTarget.Center) * Main.rand.NextFloat(10f, 18f); - int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); - if (Main.projectile.IndexInRange(p)) - Main.projectile[p].originalDamage = Projectile.originalDamage; - } + Dust dust = Dust.NewDustPerfect(Projectile.Center, 6); + dust.noGravity = true; + dust.velocity = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(2f, 6f); } - } - Lighting.AddLight(Projectile.Center, Color.Orange.ToVector3()); - } - public void Initialize(Player player) - { - for (int i = 0; i < 36; i++) - { - Dust dust = Dust.NewDustPerfect(Projectile.Center, 6); - dust.noGravity = true; - dust.velocity = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(2f, 6f); + Projectile.localAI[0] = 1f; } } diff --git a/Projectiles/Summon/GhostFire.cs b/Projectiles/Summon/GhostFire.cs index 855bfd6bce..b8533cfe3a 100644 --- a/Projectiles/Summon/GhostFire.cs +++ b/Projectiles/Summon/GhostFire.cs @@ -1,49 +1,135 @@ -using Microsoft.Xna.Framework; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Summon { public class GhostFire : ModProjectile { public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public bool ableToHit = true; + public NPC target; public override void SetStaticDefaults() { - DisplayName.SetDefault("Fire"); + DisplayName.SetDefault("Ghastly Particle"); ProjectileID.Sets.MinionShot[Projectile.type] = true; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; } public override void SetDefaults() { - Projectile.width = 4; - Projectile.height = 4; + Projectile.width = Projectile.height = 16; Projectile.friendly = true; Projectile.tileCollide = false; - Projectile.penetrate = -1; - Projectile.extraUpdates = 100; - Projectile.timeLeft = 80; - Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 50; + Projectile.penetrate = 200; + Projectile.extraUpdates = 3; + Projectile.timeLeft = 600; Projectile.minion = true; Projectile.minionSlots = 0f; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 50; Projectile.DamageType = DamageClass.Summon; } + public override bool? CanDamage() => ableToHit ? (bool?)null : false; public override void AI() { - Projectile.localAI[0] += 1f; - if (Projectile.localAI[0] > 6f) + Player player = Main.player[Projectile.owner]; + Projectile.localAI[0] += 1f / (Projectile.extraUpdates + 1); + + if (Projectile.penetrate < 200) //If an enemy has already been hit by the projectile, prevents any further homing capabilities { - Vector2 vector33 = Projectile.position; - vector33 -= Projectile.velocity * 0.25f; - Projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 180, 0f, 0f, 0, default, 0.2f); - Main.dust[num448].position = vector33; - Main.dust[num448].noGravity = true; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; + if (Projectile.timeLeft > 60) { Projectile.timeLeft = 60; } //The projectile start shrinking and slowing down. it can still hit for a bit during this, to allow a bit of multi-target if the enemies are really close to eachother. + Projectile.velocity *= 0.88f; } + else if (Projectile.localAI[0] < 60f) //If the projectile hasn't been alive for 1 second yet, slow it down more every frame and prevent any homing capabilities. + { + Projectile.velocity *= 0.93f; + } + else FindTarget(player); //No barricades stand in our way. FIND AND KILL! + + if (Projectile.timeLeft <= 20) //removes projectile's ability to hit when it is super close to death because it will have been visually shrunk to almost nothing in PreDraw + { + ableToHit = false; + } + } + public void FindTarget(Player player) + { + float maxDistance = 3000f; + bool foundTarget = false; + if (player.HasMinionAttackTargetNPC) //Targetted enemy takes priority for homing no matter what. + { + NPC npc = Main.npc[player.MinionAttackTargetNPC]; + if (npc.CanBeChasedBy(Projectile, false)) + { + float targetDist = Vector2.Distance(npc.Center, Projectile.Center); + if (targetDist < maxDistance) + { + maxDistance = targetDist; + foundTarget = true; + target = npc; + } + } + } + if (!foundTarget) + { + for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) + { + NPC npc = Main.npc[npcIndex]; + if (npc.CanBeChasedBy(Projectile, false)) + { + float targetDist = Vector2.Distance(npc.Center, Projectile.Center); + if (targetDist < maxDistance) + { + maxDistance = targetDist; + foundTarget = true; + target = npc; + } + } + } + } + if (!foundTarget) //If the enemy that the projectile was heading towards died prematurely, slow down the projectile if there are no new targets. + { + Projectile.velocity *= 0.98f; + } + else KillTheThing(target); //If there is an npc found, seek and destroy. + } + public void KillTheThing(NPC npc) + { + Projectile.velocity = Projectile.SuperhomeTowardsTarget(npc, 50f/(Projectile.extraUpdates+1), 60f / (Projectile.extraUpdates + 1), 1f / (Projectile.extraUpdates + 1)); //predictionStrength is lessened to account for extra updates, otherwise the projectile tends to copy fast NPC movement 1:1. Not Cool. + } + public override bool PreDraw(ref Color lightColor) //photoviscerator ball drawcode, slightly edited + { + Texture2D lightTexture = ModContent.Request("CalamityMod/ExtraTextures/SmallGreyscaleCircle").Value; + for (int i = 0; i < Projectile.oldPos.Length; i++) + { + float colorInterpolation = (float)Math.Cos(Projectile.timeLeft / 32f + Main.GlobalTimeWrappedHourly / 20f + i / (float)Projectile.oldPos.Length * MathHelper.Pi) * 0.5f + 0.5f; + Color color = Color.Lerp(Color.Cyan, Color.LightBlue, colorInterpolation) * 0.4f; + color.A = 0; + Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY) + new Vector2 (-28f, -28f); //Last vector is to offset the circle so that it is displayed where the hitbox actually is, instead of a bit down and to the right. + Color outerColor = color; + Color innerColor = color * 0.5f; + float intensity = 0.9f + 0.15f * (float)Math.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi); + intensity *= MathHelper.Lerp(0.15f, 1f, 1f - i / (float)Projectile.oldPos.Length); + if (Projectile.timeLeft <= 60) //Shrinks to nothing when projectile is nearing death + { + intensity *= Projectile.timeLeft / 60f; + } + // Become smaller the futher along the old positions we are. + Vector2 outerScale = new Vector2(1f) * intensity; + Vector2 innerScale = new Vector2(1f) * intensity * 0.7f; + outerColor *= intensity; + innerColor *= intensity; + Main.EntitySpriteDraw(lightTexture, drawPosition, null, outerColor, 0f, lightTexture.Size() * 0.5f, outerScale * 0.6f, SpriteEffects.None, 0); + Main.EntitySpriteDraw(lightTexture, drawPosition, null, innerColor, 0f, lightTexture.Size() * 0.5f, innerScale * 0.6f, SpriteEffects.None, 0); + } + return false; } } } diff --git a/Projectiles/Summon/PhantomGuy.cs b/Projectiles/Summon/PhantomGuy.cs index e22c0e9ae4..c72e629c16 100644 --- a/Projectiles/Summon/PhantomGuy.cs +++ b/Projectiles/Summon/PhantomGuy.cs @@ -26,7 +26,7 @@ namespace CalamityMod.Projectiles.Summon Projectile.netImportant = true; Projectile.friendly = true; Projectile.ignoreWater = true; - Projectile.minionSlots = 0.5f; + Projectile.minionSlots = 1f; Projectile.timeLeft = 18000; Projectile.penetrate = -1; Projectile.tileCollide = false; @@ -36,6 +36,9 @@ namespace CalamityMod.Projectiles.Summon Projectile.DamageType = DamageClass.Summon; } + public int shootTimeCounter = 0; + bool canShoot = false; + public override void AI() { Player player = Main.player[Projectile.owner]; @@ -80,7 +83,7 @@ namespace CalamityMod.Projectiles.Summon if (npc.CanBeChasedBy(Projectile, false)) { float num646 = Vector2.Distance(npc.Center, Projectile.Center); - if (!flag25 && num646 < num633) + if (num646 < num633) { num633 = num646; vector46 = npc.Center; @@ -194,24 +197,37 @@ namespace CalamityMod.Projectiles.Summon } if (Projectile.ai[0] == 0f) { - float scaleFactor3 = 6f; - int num658 = ModContent.ProjectileType(); if (flag25 && Projectile.ai[1] == 0f) { - SoundEngine.PlaySound(SoundID.Item20, Projectile.position); Projectile.ai[1] += 1f; if (Main.myPlayer == Projectile.owner) { - Vector2 value19 = vector46 - Projectile.Center; - value19.Normalize(); - value19 *= scaleFactor3; - int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, value19.X, value19.Y, num658, Projectile.damage, 0f, Main.myPlayer, 0f, 0f); - if (Main.projectile.IndexInRange(p)) - Main.projectile[p].originalDamage = Projectile.originalDamage; + canShoot = true; Projectile.netUpdate = true; } } } + if (canShoot) + { + shootTimeCounter++; + + if (shootTimeCounter % 20 == 0 && shootTimeCounter <= 60) + { + SoundEngine.PlaySound(SoundID.Item20, Projectile.position); + float randomRadius = Main.rand.Next(10, 14); + Vector2 randomVelocity = Main.rand.NextVector2CircularEdge(randomRadius, randomRadius); + Projectile.velocity -= randomVelocity*0.22f; //funny recoil + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, randomVelocity.X, randomVelocity.Y, ModContent.ProjectileType(), Projectile.damage, 0f, Main.myPlayer, 0f, 0f); + Projectile.netUpdate = true; + } + if (shootTimeCounter > 200) + { + canShoot = false; + shootTimeCounter = 0; + Projectile.netUpdate = true; + } + + } } public override Color? GetAlpha(Color lightColor) diff --git a/Systems/WorldgenManagementSystem.cs b/Systems/WorldgenManagementSystem.cs index dcf531afdd..ebea619fad 100644 --- a/Systems/WorldgenManagementSystem.cs +++ b/Systems/WorldgenManagementSystem.cs @@ -32,7 +32,7 @@ namespace CalamityMod.Systems int islandIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Floating Island Houses")); if (islandIndex != -1) { - tasks.Insert(islandIndex + 2, new PassLegacy("EvilIsland", (progress, config) => + tasks.Insert(islandIndex + 2, new PassLegacy("Evil Island", (progress, config) => { progress.Message = "Corrupting a floating island"; WorldEvilIsland.PlaceEvilIsland(); @@ -52,6 +52,20 @@ namespace CalamityMod.Systems CustomTemple.NewJungleTemple(); }); + int hiveIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Hives")); + tasks[JungleTempleIndex] = new PassLegacy("Giant Hive", (progress, config) => + { + progress.Message = "Building a giant beehive"; + int attempts = 0; + while (attempts < 1000) + { + attempts++; + Point origin = WorldGen.RandomWorldPoint((int)Main.worldSurface, 20, Main.maxTilesY - (int)Main.worldSurface - 100, 20); + if (MiscWorldgenRoutines.CanPlaceGiantHive(origin, WorldGen.structures)) + break; + } + }); + int JungleTempleIndex2 = tasks.FindIndex(genpass => genpass.Name.Equals("Temple")); tasks[JungleTempleIndex2] = new PassLegacy("Temple", (progress, config) => { @@ -66,7 +80,7 @@ namespace CalamityMod.Systems int TrapsIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Traps")); if (TrapsIndex != -1) { - tasks.Insert(TrapsIndex + 1, new PassLegacy("SunkenSea", (progress, config) => + tasks.Insert(TrapsIndex + 1, new PassLegacy("Sunken Sea", (progress, config) => { progress.Message = "Partially flooding an overblown desert"; int sunkenSeaX = WorldGen.UndergroundDesertLocation.Left; @@ -88,7 +102,7 @@ namespace CalamityMod.Systems if (FinalIndex != -1) { int currentFinalIndex = FinalIndex; - tasks.Insert(++currentFinalIndex, new PassLegacy("GemDepthAdjustment", (progress, config) => + tasks.Insert(++currentFinalIndex, new PassLegacy("Gem Depth Adjustment", (progress, config) => { progress.Message = "Reallocating gem deposits to match cavern depth"; MiscWorldgenRoutines.SmartGemGen(); @@ -98,7 +112,7 @@ namespace CalamityMod.Systems //Not touching this yet because the Crags will be reworked in the future #region BrimstoneCrag - tasks.Insert(++currentFinalIndex, new PassLegacy("BrimstoneCrag", (progress, config) => + tasks.Insert(++currentFinalIndex, new PassLegacy("Brimstone Crag", (progress, config) => { progress.Message = "Uncovering the ruins of a fallen empire"; @@ -134,21 +148,21 @@ namespace CalamityMod.Systems int SulphurIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes")); if (SulphurIndex != -1) { - tasks.Insert(SulphurIndex + 1, new PassLegacy("SulphurSea", (progress, config) => + tasks.Insert(SulphurIndex + 1, new PassLegacy("Sulphur Sea", (progress, config) => { progress.Message = "Polluting one of the oceans"; SulphurousSea.PlaceSulphurSea(); })); } - tasks.Insert(++currentFinalIndex, new PassLegacy("SpecialShrines", (progress, config) => + tasks.Insert(++currentFinalIndex, new PassLegacy("Special Shrines", (progress, config) => { progress.Message = "Placing hidden shrines"; UndergroundShrines.PlaceShrines(); })); - tasks.Insert(++currentFinalIndex, new PassLegacy("DraedonStructures", (progress, config) => + tasks.Insert(++currentFinalIndex, new PassLegacy("Draedon Structures", (progress, config) => { progress.Message = "Rust and Dust"; List workshopPositions = new List(); @@ -191,7 +205,7 @@ namespace CalamityMod.Systems Abyss.PlaceAbyss(); })); - tasks.Insert(++currentFinalIndex, new PassLegacy("SulphurSea2", (progress, config) => + tasks.Insert(++currentFinalIndex, new PassLegacy("Sulphur Sea 2", (progress, config) => { progress.Message = "Further polluting one of the oceans"; SulphurousSea.SulphurSeaGenerationAfterAbyss(); diff --git a/Tiles/Furniture/ChaosCandle.cs b/Tiles/Furniture/ChaosCandle.cs index 15604d6fba..6d59836a4d 100644 --- a/Tiles/Furniture/ChaosCandle.cs +++ b/Tiles/Furniture/ChaosCandle.cs @@ -71,7 +71,7 @@ namespace CalamityMod.Tiles.Furniture public override bool RightClick(int i, int j) { - CalamityUtils.RightClickBreak(i, j); + CalamityUtils.LightHitWire(Type, i, j, 1, 1); return true; } } diff --git a/Tiles/Furniture/Fountains/AbyssFountainTile.cs b/Tiles/Furniture/Fountains/AbyssFountainTile.cs index 7d49acf4ea..b7cb48fa38 100644 --- a/Tiles/Furniture/Fountains/AbyssFountainTile.cs +++ b/Tiles/Furniture/Fountains/AbyssFountainTile.cs @@ -1,8 +1,10 @@ using CalamityMod.Items.Placeables.Furniture.Fountains; using Microsoft.Xna.Framework; using Terraria; +using Terraria.Audio; using Terraria.DataStructures; using Terraria.GameContent.ObjectInteractions; +using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; @@ -19,7 +21,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override void NearbyEffects(int i, int j, bool closer) { - if (Main.tile[i, j].TileFrameX < 36) + if (Main.tile[i, j].TileFrameX >= 36) CalamityGlobalTile.SetActiveFountainColor(ModContent.Find("CalamityMod/AbyssWater").Slot); } @@ -60,6 +62,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override bool RightClick(int i, int j) { CalamityUtils.LightHitWire(Type, i, j, 2, 4); + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); return true; } diff --git a/Tiles/Furniture/Fountains/AbyssFountainTile.png b/Tiles/Furniture/Fountains/AbyssFountainTile.png index 68927bab25..145dd37d5c 100644 Binary files a/Tiles/Furniture/Fountains/AbyssFountainTile.png and b/Tiles/Furniture/Fountains/AbyssFountainTile.png differ diff --git a/Tiles/Furniture/Fountains/AbyssFountainTile_Highlight.png b/Tiles/Furniture/Fountains/AbyssFountainTile_Highlight.png index 1d1e01fe1a..6288ffd19a 100644 Binary files a/Tiles/Furniture/Fountains/AbyssFountainTile_Highlight.png and b/Tiles/Furniture/Fountains/AbyssFountainTile_Highlight.png differ diff --git a/Tiles/Furniture/Fountains/AstralFountainTile.cs b/Tiles/Furniture/Fountains/AstralFountainTile.cs index 042d6ae760..8bcc5d495d 100644 --- a/Tiles/Furniture/Fountains/AstralFountainTile.cs +++ b/Tiles/Furniture/Fountains/AstralFountainTile.cs @@ -2,8 +2,10 @@ using CalamityMod.Items.Placeables.Furniture.Fountains; using Microsoft.Xna.Framework; using Terraria; +using Terraria.Audio; using Terraria.DataStructures; using Terraria.GameContent.ObjectInteractions; +using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; @@ -20,7 +22,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override void NearbyEffects(int i, int j, bool closer) { - if (Main.tile[i, j].TileFrameX < 36) + if (Main.tile[i, j].TileFrameX >= 36) CalamityGlobalTile.SetActiveFountainColor(ModContent.Find("CalamityMod/AstralWater").Slot); } @@ -61,6 +63,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override bool RightClick(int i, int j) { CalamityUtils.LightHitWire(Type, i, j, 2, 4); + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); return true; } diff --git a/Tiles/Furniture/Fountains/AstralFountainTile.png b/Tiles/Furniture/Fountains/AstralFountainTile.png index 126498ac4d..d727da44c5 100644 Binary files a/Tiles/Furniture/Fountains/AstralFountainTile.png and b/Tiles/Furniture/Fountains/AstralFountainTile.png differ diff --git a/Tiles/Furniture/Fountains/AstralFountainTile_Highlight.png b/Tiles/Furniture/Fountains/AstralFountainTile_Highlight.png index 169f6ac0a3..b9b2a85f47 100644 Binary files a/Tiles/Furniture/Fountains/AstralFountainTile_Highlight.png and b/Tiles/Furniture/Fountains/AstralFountainTile_Highlight.png differ diff --git a/Tiles/Furniture/Fountains/SulphurousFountainTile.cs b/Tiles/Furniture/Fountains/SulphurousFountainTile.cs index 597f60a3f1..dd0c8e6797 100644 --- a/Tiles/Furniture/Fountains/SulphurousFountainTile.cs +++ b/Tiles/Furniture/Fountains/SulphurousFountainTile.cs @@ -1,8 +1,10 @@ using CalamityMod.Items.Placeables.Furniture.Fountains; using Microsoft.Xna.Framework; using Terraria; +using Terraria.Audio; using Terraria.DataStructures; using Terraria.GameContent.ObjectInteractions; +using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; @@ -19,7 +21,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override void NearbyEffects(int i, int j, bool closer) { - if (Main.tile[i, j].TileFrameX < 36) + if (Main.tile[i, j].TileFrameX >= 36) CalamityGlobalTile.SetActiveFountainColor(ModContent.Find("CalamityMod/SulphuricWater").Slot); } @@ -60,6 +62,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override bool RightClick(int i, int j) { CalamityUtils.LightHitWire(Type, i, j, 2, 4); + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); return true; } diff --git a/Tiles/Furniture/Fountains/SulphurousFountainTile.png b/Tiles/Furniture/Fountains/SulphurousFountainTile.png index 9dfcecd6e6..ddbdeb2212 100644 Binary files a/Tiles/Furniture/Fountains/SulphurousFountainTile.png and b/Tiles/Furniture/Fountains/SulphurousFountainTile.png differ diff --git a/Tiles/Furniture/Fountains/SulphurousFountainTile_Highlight.png b/Tiles/Furniture/Fountains/SulphurousFountainTile_Highlight.png index 31243c312d..92589b7b11 100644 Binary files a/Tiles/Furniture/Fountains/SulphurousFountainTile_Highlight.png and b/Tiles/Furniture/Fountains/SulphurousFountainTile_Highlight.png differ diff --git a/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs b/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs index 4a8fb520f0..699f5f2202 100644 --- a/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs +++ b/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs @@ -1,8 +1,10 @@ using CalamityMod.Items.Placeables.Furniture.Fountains; using Microsoft.Xna.Framework; using Terraria; +using Terraria.Audio; using Terraria.DataStructures; using Terraria.GameContent.ObjectInteractions; +using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; @@ -19,7 +21,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override void NearbyEffects(int i, int j, bool closer) { - if (Main.tile[i, j].TileFrameX < 36) + if (Main.tile[i, j].TileFrameX >= 36) CalamityGlobalTile.SetActiveFountainColor(ModContent.Find("CalamityMod/SunkenSeaWater").Slot); } @@ -60,6 +62,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override bool RightClick(int i, int j) { CalamityUtils.LightHitWire(Type, i, j, 2, 4); + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); return true; } diff --git a/Tiles/Furniture/Fountains/SunkenSeaFountainTile.png b/Tiles/Furniture/Fountains/SunkenSeaFountainTile.png index e8ceb8d0a1..2e964dcf1a 100644 Binary files a/Tiles/Furniture/Fountains/SunkenSeaFountainTile.png and b/Tiles/Furniture/Fountains/SunkenSeaFountainTile.png differ diff --git a/Tiles/Furniture/Fountains/SunkenSeaFountainTile_Highlight.png b/Tiles/Furniture/Fountains/SunkenSeaFountainTile_Highlight.png index 5866fcb8b8..4364cf01ee 100644 Binary files a/Tiles/Furniture/Fountains/SunkenSeaFountainTile_Highlight.png and b/Tiles/Furniture/Fountains/SunkenSeaFountainTile_Highlight.png differ diff --git a/Tiles/Furniture/LanternCenterTile.cs b/Tiles/Furniture/LanternCenterTile.cs index 5b903a48ad..fc0a3bbffe 100644 --- a/Tiles/Furniture/LanternCenterTile.cs +++ b/Tiles/Furniture/LanternCenterTile.cs @@ -1,6 +1,7 @@ using CalamityMod.Items.Placeables.Furniture; using Microsoft.Xna.Framework; using Terraria; +using Terraria.Audio; using Terraria.DataStructures; using Terraria.GameContent.Events; using Terraria.GameContent.ObjectInteractions; @@ -58,6 +59,7 @@ namespace CalamityMod.Tiles.Furniture { CalamityUtils.LightHitWire(Type, i, j, 3, 3); LanternNight.ToggleManualLanterns(); + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); return true; } diff --git a/Tiles/Furniture/TranquilityCandle.cs b/Tiles/Furniture/TranquilityCandle.cs index 5002998856..67e621f03a 100644 --- a/Tiles/Furniture/TranquilityCandle.cs +++ b/Tiles/Furniture/TranquilityCandle.cs @@ -71,7 +71,7 @@ namespace CalamityMod.Tiles.Furniture public override bool RightClick(int i, int j) { - CalamityUtils.RightClickBreak(i, j); + CalamityUtils.LightHitWire(Type, i, j, 1, 1); return true; } } diff --git a/Tiles/VernalSoil.cs b/Tiles/VernalSoil.cs new file mode 100644 index 0000000000..87402dc7cd --- /dev/null +++ b/Tiles/VernalSoil.cs @@ -0,0 +1,69 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles +{ + public class VernalSoil : ModTile + { + public override void SetStaticDefaults() + { + Main.tileSolid[Type] = true; + Main.tileBlockLight[Type] = true; + + CalamityUtils.MergeWithGeneral(Type); + + TileID.Sets.CanBeDugByShovel[Type] = true; + + DustType = 38; + ItemDrop = ModContent.ItemType(); + ModTranslation name = CreateMapEntryName(); + name.SetDefault("Vernal Soil"); + AddMapEntry(new Color(80, 120, 0), name); + HitSound = SoundID.Dig; + } + + public override void RandomUpdate(int i, int j) + { + int j2 = j - 1; + if (j2 < 10) + j2 = 10; + + if (Main.tile[i, j2].LiquidAmount == 0) + { + if (WorldGen.genRand.NextBool(15)) + { + bool placeBulb = true; + int minDistanceFromOtherBulbs = 5; + for (int k = i - minDistanceFromOtherBulbs; k < i + minDistanceFromOtherBulbs; k += 2) + { + for (int l = j - minDistanceFromOtherBulbs; l < j + minDistanceFromOtherBulbs; l += 2) + { + if (k > 1 && k < Main.maxTilesX - 2 && l > 1 && l < Main.maxTilesY - 2 && Main.tile[k, l].HasTile && Main.tile[k, l].TileType == TileID.PlanteraBulb) + { + placeBulb = false; + break; + } + } + } + + /*if (placeBulb) + { + WorldGen.Place2x2(i, j2, TileID.PlanteraBulb, 0); + WorldGen.SquareTileFrame(i, j2); + WorldGen.SquareTileFrame(i + 2, j2); + WorldGen.SquareTileFrame(i - 1, j2); + if (Main.tile[i, j2].TileType == TileID.PlanteraBulb && Main.netMode == NetmodeID.Server) + NetMessage.SendTileSquare(-1, i, j2, 5); + }*/ + } + } + } + + public override void NumDust(int i, int j, bool fail, ref int num) + { + num = fail ? 1 : 3; + } + } +} diff --git a/Tiles/VernalSoil.png b/Tiles/VernalSoil.png new file mode 100644 index 0000000000..8c1e2f1c56 Binary files /dev/null and b/Tiles/VernalSoil.png differ diff --git a/Utilities/ProjectileUtils.cs b/Utilities/ProjectileUtils.cs index c3ba722111..08d11d7696 100644 --- a/Utilities/ProjectileUtils.cs +++ b/Utilities/ProjectileUtils.cs @@ -152,9 +152,11 @@ namespace CalamityMod /// The projectile that should home. /// The target. /// The inertia of the movement change. - public static Vector2 SuperhomeTowardsTarget(this Projectile projectile, NPC target, float homingSpeed, float inertia) + /// The ratio for how much the projectile aims ahead of the target. 1f is normal predictiveness. 0.01f is the lowest possible value, equating to no practical predictiveness. + public static Vector2 SuperhomeTowardsTarget(this Projectile projectile, NPC target, float homingSpeed, float inertia, float predictionStrength = 1f) { - Vector2 idealVelocity = CalculatePredictiveAimToTarget(projectile.Center, target, homingSpeed); + if (predictionStrength < 0.01f) { predictionStrength = 0.01f; } + Vector2 idealVelocity = CalculatePredictiveAimToTarget(projectile.Center, target, homingSpeed/predictionStrength) * predictionStrength; return (projectile.velocity * (inertia - 1f) + idealVelocity) / inertia; } #endregion diff --git a/World/MiscWorldgenRoutines.cs b/World/MiscWorldgenRoutines.cs index 130ec4a78b..bddfb5e755 100644 --- a/World/MiscWorldgenRoutines.cs +++ b/World/MiscWorldgenRoutines.cs @@ -1,4 +1,5 @@ -using CalamityMod.Items.Materials; +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Materials; using CalamityMod.Items.Potions; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Tiles; @@ -15,6 +16,7 @@ using Terraria; using Terraria.ID; using Terraria.IO; using Terraria.ModLoader; +using Terraria.Utilities; using Terraria.WorldBuilding; namespace CalamityMod.World @@ -175,6 +177,498 @@ namespace CalamityMod.World } #endregion + #region Giant Hive + public static bool CanPlaceGiantHive(Point origin, StructureMap structures) + { + if (!structures.CanPlace(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100))) + return false; + + if (TooCloseToImportantLocations(origin)) + return false; + + Ref ref1 = new Ref(0); + Ref ref2 = new Ref(0); + Ref ref3 = new Ref(0); + WorldUtils.Gen(origin, new Shapes.Circle(15), Actions.Chain(new Modifiers.IsSolid(), new Actions.Scanner(ref1), new Modifiers.OnlyTiles(60, 59), new Actions.Scanner(ref2), new Modifiers.OnlyTiles(60), new Actions.Scanner(ref3))); + if (ref2.Value / (float)ref1.Value < 0.75f || ref3.Value < 2) + return false; + + int num = 0; + int[] array = new int[1000]; + int[] array2 = new int[1000]; + Vector2 larvaLocation = origin.ToVector2(); + int numHiveTunnels = WorldGen.genRand.Next(10, 13); + + for (int i = 0; i < numHiveTunnels; i++) + { + Vector2 vector2 = larvaLocation; + int num3 = WorldGen.genRand.Next(2, 5); + for (int j = 0; j < num3; j++) + vector2 = CreateHiveTunnel((int)larvaLocation.X, (int)larvaLocation.Y, WorldGen.genRand); + + larvaLocation = vector2; + array[num] = (int)larvaLocation.X; + array2[num] = (int)larvaLocation.Y; + num++; + } + + FrameOutAllHiveContents(origin, 50); + + for (int k = 0; k < num; k++) + { + int num4 = array[k]; + int y = array2[k]; + int num5 = 1; + if (WorldGen.genRand.NextBool()) + num5 = -1; + + bool flag = false; + while (WorldGen.InWorld(num4, y, 10) && BadSpotForHoneyFall(num4, y)) + { + num4 += num5; + if (Math.Abs(num4 - array[k]) > 50) + { + flag = true; + break; + } + } + + if (!flag) + { + num4 += num5; + if (!SpotActuallyNotInHive(num4, y)) + { + CreateBlockedHoneyCube(num4, y); + CreateDentForHoneyFall(num4, y, num5); + } + } + } + + CreateStandForLarva(larvaLocation); + + // Generate a second larva stand + Vector2 secondLarvaLocation = default; + int maxAttempts = 1000; + for (int l = 0; l < maxAttempts; l++) + { + Vector2 vector3 = larvaLocation; + vector3.X += WorldGen.genRand.Next(-50, 51); + vector3.Y += WorldGen.genRand.Next(-50, 51); + if (WorldGen.InWorld((int)vector3.X, (int)vector3.Y) && Vector2.Distance(larvaLocation, vector3) > 10f && !Main.tile[(int)vector3.X, (int)vector3.Y].HasTile && Main.tile[(int)vector3.X, (int)vector3.Y].WallType == WallID.HiveUnsafe) + { + secondLarvaLocation = vector3; + CreateStandForLarva(vector3); + break; + } + } + + // Honey chests + Vector2 honeyChestLocation = default; + for (int l = 0; l < maxAttempts; l++) + { + Vector2 vector3 = larvaLocation; + vector3.X += WorldGen.genRand.Next(-100, 101); + vector3.Y += WorldGen.genRand.Next(-100, 101); + if (WorldGen.InWorld((int)vector3.X, (int)vector3.Y) && Vector2.Distance(larvaLocation, vector3) > 10f && Vector2.Distance(secondLarvaLocation, vector3) > 10f && !Main.tile[(int)vector3.X, (int)vector3.Y].HasTile && Main.tile[(int)vector3.X, (int)vector3.Y].WallType == WallID.HiveUnsafe) + { + honeyChestLocation = vector3; + CreateStandAndPlaceHoneyChest(vector3); + break; + } + } + for (int l = 0; l < maxAttempts; l++) + { + Vector2 vector3 = larvaLocation; + vector3.X += WorldGen.genRand.Next(-100, 101); + vector3.Y += WorldGen.genRand.Next(-100, 101); + if (WorldGen.InWorld((int)vector3.X, (int)vector3.Y) && Vector2.Distance(larvaLocation, vector3) > 10f && Vector2.Distance(secondLarvaLocation, vector3) > 10f && Vector2.Distance(honeyChestLocation, vector3) > 10f && !Main.tile[(int)vector3.X, (int)vector3.Y].HasTile && Main.tile[(int)vector3.X, (int)vector3.Y].WallType == WallID.HiveUnsafe) + { + CreateStandAndPlaceHoneyChest(vector3); + break; + } + } + + structures.AddProtectedStructure(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 5); + return true; + } + + private static void FrameOutAllHiveContents(Point origin, int squareHalfWidth) + { + int num = Math.Max(10, origin.X - squareHalfWidth); + int num2 = Math.Min(Main.maxTilesX - 10, origin.X + squareHalfWidth); + int num3 = Math.Max(10, origin.Y - squareHalfWidth); + int num4 = Math.Min(Main.maxTilesY - 10, origin.Y + squareHalfWidth); + for (int i = num; i < num2; i++) + { + for (int j = num3; j < num4; j++) + { + Tile tile = Main.tile[i, j]; + if (tile.HasTile && tile.TileType == TileID.Hive) + WorldGen.SquareTileFrame(i, j); + + if (tile.WallType == WallID.HiveUnsafe) + WorldGen.SquareWallFrame(i, j); + } + } + } + + private static Vector2 CreateHiveTunnel(int i, int j, UnifiedRandom random) + { + double num = random.Next(20, 26); + float num2 = random.Next(30, 41); + float num3 = Main.maxTilesX / 4200; + num3 = (num3 + 1f) / 2f; + num *= (double)num3; + num2 *= num3; + + double num4 = num; + Vector2 result = default; + result.X = i; + result.Y = j; + Vector2 vector = default; + vector.X = random.Next(-10, 11) * 0.2f; + vector.Y = random.Next(-10, 11) * 0.2f; + while (num > 0.0 && num2 > 0f) + { + if (result.Y > (Main.maxTilesY - 250)) + num2 = 0f; + + num = num4 * (double)(1f + random.Next(-20, 20) * 0.01f); + num2 -= 1f; + int num5 = (int)(result.X - num); + int num6 = (int)(result.X + num); + int num7 = (int)(result.Y - num); + int num8 = (int)(result.Y + num); + if (num5 < 1) + num5 = 1; + + if (num6 > Main.maxTilesX - 1) + num6 = Main.maxTilesX - 1; + + if (num7 < 1) + num7 = 1; + + if (num8 > Main.maxTilesY - 1) + num8 = Main.maxTilesY - 1; + + for (int k = num5; k < num6; k++) + { + for (int l = num7; l < num8; l++) + { + if (!WorldGen.InWorld(k, l, 50)) + { + num2 = 0f; + } + else + { + if (Main.tile[k - 10, l].WallType == WallID.LihzahrdBrickUnsafe) + num2 = 0f; + + if (Main.tile[k + 10, l].WallType == WallID.LihzahrdBrickUnsafe) + num2 = 0f; + + if (Main.tile[k, l - 10].WallType == WallID.LihzahrdBrickUnsafe) + num2 = 0f; + + if (Main.tile[k, l + 10].WallType == WallID.LihzahrdBrickUnsafe) + num2 = 0f; + } + + if (l < Main.worldSurface && Main.tile[k, l - 5].WallType == WallID.None) + num2 = 0f; + + float num9 = Math.Abs(k - result.X); + float num10 = Math.Abs(l - result.Y); + double num11 = Math.Sqrt(num9 * num9 + num10 * num10); + if (num11 < num4 * 0.4 * (1.0 + random.Next(-10, 11) * 0.005)) + { + Main.tile[k, l].LiquidAmount = byte.MaxValue; + Main.tile[k, l].Get().LiquidType = LiquidID.Honey; + Main.tile[k, l].WallType = WallID.HiveUnsafe; + Main.tile[k, l].Get().HasTile = false; + Main.tile[k, l].Get().IsHalfBlock = false; + Main.tile[k, l].Get().Slope = SlopeType.Solid; + } + else if (num11 < num4 * 0.75 * (1.0 + random.Next(-10, 11) * 0.005)) + { + Main.tile[k, l].LiquidAmount = 0; + if (Main.tile[k, l].WallType != WallID.HiveUnsafe) + { + Main.tile[k, l].Get().HasTile = true; + Main.tile[k, l].Get().IsHalfBlock = false; + Main.tile[k, l].Get().Slope = SlopeType.Solid; + Main.tile[k, l].TileType = TileID.Hive; + } + } + + if (num11 < num4 * 0.6 * (1.0 + random.Next(-10, 11) * 0.005)) + { + Main.tile[k, l].WallType = WallID.HiveUnsafe; + if (random.NextBool()) + { + Main.tile[k, l].LiquidAmount = byte.MaxValue; + Main.tile[k, l].Get().LiquidType = LiquidID.Honey; + } + } + } + } + + result += vector; + num2 -= 1f; + vector.Y += random.Next(-10, 11) * 0.05f; + vector.X += random.Next(-10, 11) * 0.05f; + } + + return result; + } + + private static bool TooCloseToImportantLocations(Point origin) + { + int x = origin.X; + int y = origin.Y; + int num = 150; + for (int i = x - num; i < x + num; i += 10) + { + if (i <= 0 || i > Main.maxTilesX - 1) + continue; + + for (int j = y - num; j < y + num; j += 10) + { + if (j > 0 && j <= Main.maxTilesY - 1) + { + if (Main.tile[i, j].HasTile && Main.tile[i, j].TileType == TileID.LihzahrdBrick) + return true; + + if (Main.tile[i, j].WallType == WallID.CrimstoneUnsafe || Main.tile[i, j].WallType == WallID.EbonstoneUnsafe || Main.tile[i, j].WallType == WallID.LihzahrdBrickUnsafe) + return true; + } + } + } + + return false; + } + + private static void CreateDentForHoneyFall(int x, int y, int dir) + { + dir *= -1; + y++; + int num = 0; + while ((num < 4 || WorldGen.SolidTile(x, y)) && x > 10 && x < Main.maxTilesX - 10) + { + num++; + x += dir; + if (WorldGen.SolidTile(x, y)) + { + WorldGen.PoundTile(x, y); + if (!Main.tile[x, y + 1].HasTile) + { + Main.tile[x, y + 1].Get().HasTile = true; + Main.tile[x, y + 1].TileType = TileID.Hive; + } + } + } + } + + private static void CreateBlockedHoneyCube(int x, int y) + { + for (int i = x - 1; i <= x + 2; i++) + { + for (int j = y - 1; j <= y + 2; j++) + { + if (i >= x && i <= x + 1 && j >= y && j <= y + 1) + { + Main.tile[i, j].Get().HasTile = false; + Main.tile[i, j].LiquidAmount = byte.MaxValue; + Main.tile[i, j].Get().LiquidType = LiquidID.Honey; + } + else + { + Main.tile[i, j].Get().HasTile = true; + Main.tile[i, j].TileType = TileID.Hive; + } + } + } + } + + private static bool SpotActuallyNotInHive(int x, int y) + { + for (int i = x - 1; i <= x + 2; i++) + { + for (int j = y - 1; j <= y + 2; j++) + { + if (i < 10 || i > Main.maxTilesX - 10) + return true; + + if (Main.tile[i, j].HasTile && Main.tile[i, j].TileType != TileID.Hive) + return true; + } + } + + return false; + } + + private static bool BadSpotForHoneyFall(int x, int y) + { + if (Main.tile[x, y].HasTile && Main.tile[x, y + 1].HasTile && Main.tile[x + 1, y].HasTile) + return !Main.tile[x + 1, y + 1].HasTile; + + return true; + } + + public static void CreateStandForLarva(Vector2 position) + { + WorldGen.larvaX[WorldGen.numLarva] = Utils.Clamp((int)position.X, 5, Main.maxTilesX - 5); + WorldGen.larvaY[WorldGen.numLarva] = Utils.Clamp((int)position.Y, 5, Main.maxTilesY - 5); + WorldGen.numLarva++; + if (WorldGen.numLarva >= WorldGen.larvaX.Length) + WorldGen.numLarva = WorldGen.larvaX.Length - 1; + + int num = (int)position.X; + int num2 = (int)position.Y; + for (int i = num - 1; i <= num + 1 && i > 0 && i < Main.maxTilesX; i++) + { + for (int j = num2 - 2; j <= num2 + 1 && j > 0 && j < Main.maxTilesY; j++) + { + if (j != num2 + 1) + { + Main.tile[i, j].Get().HasTile = false; + continue; + } + + Main.tile[i, j].Get().HasTile = true; + Main.tile[i, j].TileType = TileID.Hive; + Main.tile[i, j].Get().Slope = SlopeType.Solid; + Main.tile[i, j].Get().IsHalfBlock = false; + } + } + } + + public static void CreateStandAndPlaceHoneyChest(Vector2 position) + { + int chestPlacementX = Utils.Clamp((int)position.X, 5, Main.maxTilesX - 5); + int chestPlacementY = Utils.Clamp((int)position.Y, 5, Main.maxTilesY - 5); + + int num = (int)position.X; + int num2 = (int)position.Y; + for (int i = num; i <= num + 1 && i > 0 && i < Main.maxTilesX; i++) + { + for (int j = num2 - 1; j <= num2 + 1 && j > 0 && j < Main.maxTilesY; j++) + { + if (j != num2 + 1) + { + Main.tile[i, j].Get().HasTile = false; + continue; + } + + Main.tile[i, j].Get().HasTile = true; + Main.tile[i, j].TileType = TileID.Hive; + Main.tile[i, j].Get().Slope = SlopeType.Solid; + Main.tile[i, j].Get().IsHalfBlock = false; + } + } + + int num144 = chestPlacementX; + int num145 = chestPlacementY; + for (int num146 = num144; num146 <= num144 + 1; num146++) + { + for (int num147 = num145 - 1; num147 <= num145 + 1; num147++) + { + if (num147 != num145 + 1) + { + Main.tile[num146, num147].Get().HasTile = false; + } + else + { + Main.tile[num146, num147].Get().HasTile = true; + Main.tile[num146, num147].TileType = TileID.Hive; + Main.tile[num146, num147].Get().Slope = SlopeType.Solid; + Main.tile[num146, num147].Get().IsHalfBlock = false; + } + } + } + + int chestID = WorldGen.PlaceChest(num144, num145, 21, false, 29); + FillHoneyChest(chestID, WorldGen.genRand); + } + + // Honey chest stuff, this is also used by the Hive Planetoid + private static int[] FocusLootHoney = new int[] + { + ItemID.NaturesGift, + ItemID.Bezoar, + ItemID.FlowerBoots, + ItemID.BeeMinecart + }; + + private static int[] PotionLootHoney = new int[] + { + ItemID.LifeforcePotion, + ItemID.RegenerationPotion, + ItemID.ManaRegenerationPotion, + ItemID.HeartreachPotion, + ModContent.ItemType() + }; + + private static int[] BarLootHoney = new int[] + { + WorldGen.silverBar == TileID.Silver ? ItemID.SilverBar : ItemID.TungstenBar, + WorldGen.goldBar == TileID.Gold ? ItemID.GoldBar : ItemID.PlatinumBar + }; + + public static void FillHoneyChest(int id, UnifiedRandom random) + { + Chest chest = Main.chest[id]; + int index = 0; + + chest.item[index++].SetDefaults(random.Next(FocusLootHoney)); + + if (random.Next(3) <= 1) + { + chest.item[index].SetDefaults(random.Next(BarLootHoney)); + chest.item[index].SetDefaults(random.Next(7, 15)); + } + else + { + chest.item[index].SetDefaults(ItemID.GoldCoin); + chest.item[index++].stack = random.Next(3, 5); + } + + if (random.NextBool()) + { + chest.item[index].SetDefaults(random.Next(PotionLootHoney)); + chest.item[index++].stack = random.Next(1, 4); + } + else + { + chest.item[index].SetDefaults(ItemID.BottledHoney); + chest.item[index++].stack = random.Next(3, 7); + } + + if (random.NextBool()) + { + chest.item[index].SetDefaults(ItemID.Stinger); + chest.item[index++].stack = random.Next(4, 6); + } + else + { + chest.item[index].SetDefaults(ItemID.JungleSpores); + chest.item[index++].stack = random.Next(3, 5); + } + + if (random.NextBool()) + { + chest.item[index].SetDefaults(ItemID.RecallPotion); + chest.item[index++].stack = random.Next(1, 4); + } + else + { + chest.item[index].SetDefaults(ItemID.JungleTorch); + chest.item[index++].stack = random.Next(18, 36); + } + + } + #endregion + #region Place Rox Shrine public static void PlaceRoxShrine() { @@ -189,7 +683,7 @@ namespace CalamityMod.World { if ((Main.tile[x, y].TileFrameX == 18 && Main.tile[x, y].TileFrameY == 0) || (Main.tile[x, y].TileFrameX == 45 && Main.tile[x, y].TileFrameY == 0)) { - if (WorldGen.genRand.Next(3) == 0) + if (WorldGen.genRand.NextBool(3)) { for (int dx = -1; dx < 2; dx++) { diff --git a/World/Planets/MudPlanet.cs b/World/Planets/MudPlanet.cs index 448c019893..2bcf890cd9 100644 --- a/World/Planets/MudPlanet.cs +++ b/World/Planets/MudPlanet.cs @@ -109,7 +109,7 @@ namespace CalamityMod.World.Planets { int testX = origin.X + _random.Next(-radius, radius); int testY = origin.Y + _random.Next(-radius, radius); - if (WorldGen.EmptyTileCheck(testX - 1, testX + 1, testY - 1, testY + 1) && _tiles[testX, testY].WallType == WallID.HiveUnsafe) + if (WorldGen.EmptyTileCheck(testX - 1, testX + 1, testY - 1, testY + 1) && _tiles[testX, testY].WallType == WallID.HiveUnsafe) { for (int floorX = testX - 1; floorX <= testX + 1; floorX++) { @@ -119,7 +119,7 @@ namespace CalamityMod.World.Planets } //Place chest int chestID = WorldGen.PlaceChest(testX, testY + 1, 21, false, 29); - FillHoneyChest(chestID); + MiscWorldgenRoutines.FillHoneyChest(chestID, WorldGen.genRand); placedChest = true; } } @@ -237,7 +237,7 @@ namespace CalamityMod.World.Planets } //Potion loot - if (_random.Next(2) == 0) + if (_random.NextBool()) { chest.item[index].SetDefaults(_random.Next(PotionLoot)); chest.item[index++].stack = _random.Next(1, 4); @@ -249,7 +249,7 @@ namespace CalamityMod.World.Planets } //Weaponry - if (_random.Next(2) == 0) + if (_random.NextBool()) { chest.item[index].SetDefaults(_random.Next(new int[] { ItemID.Shuriken, ItemID.ThrowingKnife })); chest.item[index++].stack = _random.Next(50, 100); @@ -261,7 +261,7 @@ namespace CalamityMod.World.Planets } //Recall potion - if (_random.Next(2) == 0) + if (_random.NextBool()) { chest.item[index].SetDefaults(ItemID.RecallPotion); chest.item[index++].stack = _random.Next(1, 4); @@ -273,89 +273,5 @@ namespace CalamityMod.World.Planets } } - - //--------------------- - //HONEY CHEST STUFF - //--------------------- - - private int[] FocusLootHoney = new int[] - { - ItemID.NaturesGift, - ItemID.Bezoar, - ItemID.SharpeningStation - }; - - private int[] PotionLootHoney = new int[] - { - ItemID.LifeforcePotion, - ItemID.RegenerationPotion, - ItemID.ManaRegenerationPotion, - ItemID.HeartreachPotion, - ModContent.ItemType() - }; - - private int[] BarLootHoney = new int[] - { - WorldGen.silverBar == TileID.Silver ? ItemID.SilverBar : ItemID.TungstenBar, - WorldGen.goldBar == TileID.Gold ? ItemID.GoldBar : ItemID.PlatinumBar - }; - - private void FillHoneyChest(int id) - { - Chest chest = Main.chest[id]; - int index = 0; - - //Focus loot - chest.item[index++].SetDefaults(_random.Next(FocusLootHoney)); - - //Bars - if (_random.Next(3) <= 1) - { - chest.item[index].SetDefaults(_random.Next(BarLootHoney)); - chest.item[index].SetDefaults(_random.Next(7, 15)); - } - else - { - chest.item[index].SetDefaults(ItemID.GoldCoin); - chest.item[index++].stack = _random.Next(3, 5); // 3 or 4 gold coins - } - - //Potion loot - if (_random.Next(2) == 0) - { - chest.item[index].SetDefaults(_random.Next(PotionLootHoney)); - chest.item[index++].stack = _random.Next(1, 4); - } - else //Healing potion - { - chest.item[index].SetDefaults(ItemID.BottledHoney); - chest.item[index++].stack = _random.Next(3, 7); - } - - //Weaponry - if (_random.Next(2) == 0) - { - chest.item[index].SetDefaults(ItemID.Stinger); - chest.item[index++].stack = _random.Next(4, 6); - } - else - { - chest.item[index].SetDefaults(ItemID.JungleSpores); - chest.item[index++].stack = _random.Next(3, 5); - } - - //Recall potion - if (_random.Next(2) == 0) - { - chest.item[index].SetDefaults(ItemID.RecallPotion); - chest.item[index++].stack = _random.Next(1, 4); - } - else //glowsticks - { - chest.item[index].SetDefaults(ItemID.YellowTorch); - chest.item[index++].stack = _random.Next(18, 36); - } - - } } }