diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index ce92cdd26f..319c41ee69 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -4,6 +4,7 @@ using CalamityMod.Buffs.StatBuffs; using CalamityMod.CalPlayer; using CalamityMod.Events; using CalamityMod.Items.Accessories; +using CalamityMod.Items.Placeables; using CalamityMod.Items.Potions; using CalamityMod.Items.VanillaArmorChanges; using CalamityMod.Items.Weapons.Melee; @@ -1522,6 +1523,13 @@ namespace CalamityMod.Items #endregion #region Ammo + public override void PickAmmo(Item weapon, Item ammo, Player player, ref int type, ref float speed, ref StatModifier damage, ref float knockback) + { + // Sandgun with Calamity sands work like vanilla non-plain sand, +5 flat damage + if (weapon.type == ItemID.Sandgun && (ammo.type == ModContent.ItemType() || ammo.type == ModContent.ItemType() || ammo.type == ModContent.ItemType())) + damage.Flat += 5; + } + public override bool CanConsumeAmmo(Item weapon, Item ammo, Player player) => Main.rand.NextFloat() <= player.Calamity().rangedAmmoCost; public static bool HasEnoughAmmo(Player player, Item item, int ammoConsumed) diff --git a/Items/Placeables/AstralSand.cs b/Items/Placeables/AstralSand.cs index 25fa12e309..d30909f55d 100644 --- a/Items/Placeables/AstralSand.cs +++ b/Items/Placeables/AstralSand.cs @@ -1,4 +1,5 @@ -using Terraria.ID; +using CalamityMod.Projectiles.Typeless; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Items.Placeables @@ -16,10 +17,9 @@ namespace CalamityMod.Items.Placeables Item.width = 16; Item.height = 16; Item.maxStack = 999; - // item.ammo = AmmoID.Sand; - // item.shoot = ModContent.ProjectileType(); - // item.notAmmo = true; - // item.shootSpeed = 15f; + Item.ammo = AmmoID.Sand; + Item.shoot = ModContent.ProjectileType(); + Item.notAmmo = true; Item.useStyle = ItemUseStyleID.Swing; Item.useTurn = true; Item.useAnimation = 15; diff --git a/Items/Placeables/EutrophicSand.cs b/Items/Placeables/EutrophicSand.cs index eb8add1d02..7e8f6b0a05 100644 --- a/Items/Placeables/EutrophicSand.cs +++ b/Items/Placeables/EutrophicSand.cs @@ -1,4 +1,5 @@ using CalamityMod.Items.Placeables.Walls; +using CalamityMod.Projectiles.Typeless; using Terraria.ModLoader; using Terraria.ID; @@ -24,6 +25,9 @@ namespace CalamityMod.Items.Placeables Item.width = 13; Item.height = 10; Item.maxStack = 999; + Item.ammo = AmmoID.Sand; + Item.shoot = ModContent.ProjectileType(); + Item.notAmmo = true; } public override void AddRecipes() diff --git a/Items/Placeables/SulphurousSand.cs b/Items/Placeables/SulphurousSand.cs index 543e412329..f1581c7b19 100644 --- a/Items/Placeables/SulphurousSand.cs +++ b/Items/Placeables/SulphurousSand.cs @@ -1,5 +1,7 @@ -using Terraria.ID; +using CalamityMod.Projectiles.Typeless; +using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Items.Placeables { public class SulphurousSand : ModItem @@ -22,6 +24,9 @@ namespace CalamityMod.Items.Placeables Item.width = 13; Item.height = 10; Item.maxStack = 999; + Item.ammo = AmmoID.Sand; + Item.shoot = ModContent.ProjectileType(); + Item.notAmmo = true; } public override void AddRecipes() diff --git a/Projectiles/Typeless/AstralFallingSand.cs b/Projectiles/Typeless/AstralFallingSand.cs deleted file mode 100644 index 4b1de2ed1f..0000000000 --- a/Projectiles/Typeless/AstralFallingSand.cs +++ /dev/null @@ -1,59 +0,0 @@ -using CalamityMod.Tiles.AstralDesert; -using Microsoft.Xna.Framework; -using System; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Projectiles.Typeless -{ - public class AstralFallingSand : ModProjectile - { - public override void SetDefaults() - { - Projectile.knockBack = 6f; - Projectile.width = 10; - Projectile.height = 10; - Projectile.aiStyle = -1; - Projectile.friendly = true; - Projectile.hostile = true; - Projectile.penetrate = -1; - } - - public override void Kill(int timeLeft) - { - Point p = Projectile.Center.ToTileCoordinates(); - // If the sand is dying outside the world border, cancel placing sand. - if (p.X < 0 || p.X >= Main.maxTilesX || p.Y < 0 || p.Y >= Main.maxTilesY) - return; - Tile t = Main.tile[p.X, p.Y]; - - // If the sand hit a half brick, but was mostly going downwards (at a lower than 45 degree angle), then stack atop the half brick. - if (t.IsHalfBlock && Projectile.velocity.Y > 0f && Math.Abs(Projectile.velocity.Y) > Math.Abs(Projectile.velocity.X)) - t = Main.tile[p.X, --p.Y]; - - // Under no circumstances can falling sand destroy minecart tracks. - if (!t.HasTile && t.TileType != TileID.MinecartTrack) - { - WorldGen.PlaceTile(p.X, p.Y, ModContent.TileType(), false, true); - WorldGen.SquareTileFrame(p.X, p.Y); - } - } - - public override void AI() - { - if (Main.rand.NextBool(2)) - { - int i = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 108, 0f, Projectile.velocity.Y * 0.5f); - Main.dust[i].velocity.X *= 0.2f; - } - Projectile.velocity.Y += 0.2f; - Projectile.rotation += 0.1f; - if (Projectile.velocity.Y > 10f) - { - Projectile.velocity.Y = 10f; - } - base.AI(); - } - } -} diff --git a/Projectiles/Typeless/AstralFallingSand.png b/Projectiles/Typeless/AstralFallingSand.png deleted file mode 100644 index b174c0674f..0000000000 Binary files a/Projectiles/Typeless/AstralFallingSand.png and /dev/null differ diff --git a/Projectiles/Typeless/SandBall.cs b/Projectiles/Typeless/SandBall.cs new file mode 100644 index 0000000000..e30e1eca39 --- /dev/null +++ b/Projectiles/Typeless/SandBall.cs @@ -0,0 +1,184 @@ +using CalamityMod.Tiles.Abyss; +using CalamityMod.Tiles.AstralDesert; +using CalamityMod.Tiles.SunkenSea; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class AstralSandBallFalling : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Typeless/SandBallAstral"; + public override void SetDefaults() => Projectile.FallingSandSetup(false); + public override void AI() => Projectile.FallingSandAI(108, false); + public override void Kill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + } + + public class AstralSandBallGun : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Typeless/SandBallAstral"; + public override void SetDefaults() => Projectile.FallingSandSetup(); + public override void AI() => Projectile.FallingSandAI(108); + public override void Kill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + } + + public class EutrophicSandBallGun : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Typeless/SandBallEutrophic"; + public override void SetDefaults() => Projectile.FallingSandSetup(); + public override void AI() => Projectile.FallingSandAI(108); // Weirdly same dusts as Astral + public override void Kill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + } + + public class SulphurousSandBallGun : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Typeless/SandBallSulphurous"; + public override void SetDefaults() => Projectile.FallingSandSetup(); + public override void AI() => Projectile.FallingSandAI(32); + public override void Kill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + } + + // All the setups go here to prevent mass blocks of copypasting + public static partial class FallingSandUtils + { + internal static void FallingSandSetup(this Projectile proj, bool fired = true) + { + proj.knockBack = 6f; + proj.width = proj.height = 10; + proj.friendly = true; + proj.penetrate = -1; + + if (fired) + { + proj.MaxUpdates = 2; + proj.DamageType = DamageClass.Ranged; + } + else + proj.hostile = true; + } + + public static void FallingSandAI(this Projectile proj, int DustID, bool fired = true) + { + if (Main.rand.NextBool(2)) + { + int i = Dust.NewDust(proj.position, proj.width, proj.height, DustID); + Main.dust[i].velocity.X *= 0.4f; + Main.dust[i].velocity.Y += fired ? 0f : proj.velocity.Y * 0.5f; + } + + proj.ai[1]++; + proj.rotation += 0.1f; + if (proj.ai[1] >= 60f || !fired) + { + proj.ai[1] = 60f; + proj.velocity.Y += 0.2f; + } + if (proj.velocity.Y > 10f) + proj.velocity.Y = 10f; + } + + public static void SpawnSand(this Projectile proj, int SandBlockID, int SandItemID) + { + Point p = proj.Center.ToTileCoordinates(); + // If the sand is dying outside the world border, cancel placing sand. + if (p.X < 0 || p.X >= Main.maxTilesX || p.Y < 0 || p.Y >= Main.maxTilesY) + return; + Tile placer = Main.tile[p.X, p.Y]; + + // If the sand hit a half brick, but was mostly going downwards (at a lower than 45 degree angle), then stack atop the half brick. + if (placer.IsHalfBlock && proj.velocity.Y > 0f && Math.Abs(proj.velocity.Y) > Math.Abs(proj.velocity.X)) + placer = Main.tile[p.X, --p.Y]; + + bool ValidTileBelow = true; + bool SlopeTileBelow = false; + + // Attempt to place sand and unslope tile below if available + // Under no circumstances can falling sand destroy minecart tracks. + if (!placer.HasTile && placer.TileType != TileID.MinecartTrack) + { + if (p.Y + 1 < Main.maxTilesY) + { + Tile under = Main.tile[p.X, p.Y + 1]; + if (under.HasTile) + { + if (under.TileType == TileID.MinecartTrack) + ValidTileBelow = false; + else if (under.IsHalfBlock || under.Slope != 0) + SlopeTileBelow = true; + } + } + + if (ValidTileBelow) + { + bool PlacedBlock = WorldGen.PlaceTile(p.X, p.Y, SandBlockID, false, true); + WorldGen.SquareTileFrame(p.X, p.Y); + + if (PlacedBlock && SlopeTileBelow) + { + WorldGen.SlopeTile(p.X, p.Y + 1); + if (Main.netMode != NetmodeID.SinglePlayer) + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 14, p.X, p.Y + 1); + } + if (PlacedBlock && Main.netMode != NetmodeID.SinglePlayer) + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 1, p.X, p.Y, SandBlockID); + } + } + // Give the block back if you literally can't place it + else + Item.NewItem(proj.GetSource_DropAsItem(), proj.position, proj.width, proj.height, SandItemID); + } + + /* + if (!Main.tile[num1014, num1015].active() && num1016 >= 0) + { + bool flag11 = false; + bool flag12 = false; + if (num1015 < Main.maxTilesY - 2) + { + Tile tile2 = Main.tile[num1014, num1015 + 1]; + if (tile2 != null && tile2.active()) + { + if (tile2.active() && tile2.type == 314) + { + flag12 = true; + } + if (tile2.active() && WorldGen.BlockBelowMakesSandFall(num1014, num1015)) + { + flag12 = true; + } + } + } + if (!flag12) + { + flag11 = WorldGen.PlaceTile(num1014, num1015, num1016, false, true, -1, 0); + } + if (!flag12 && Main.tile[num1014, num1015].active() && (int)Main.tile[num1014, num1015].type == num1016) + { + if (Main.tile[num1014, num1015 + 1].halfBrick() || Main.tile[num1014, num1015 + 1].slope() != 0) + { + WorldGen.SlopeTile(num1014, num1015 + 1, 0, false); + if (Main.netMode != 0) + { + NetMessage.SendData(17, -1, -1, null, 14, (float)num1014, (float)(num1015 + 1), 0f, 0, 0, 0); + } + } + if (Main.netMode != 0) + { + NetMessage.SendData(17, -1, -1, null, 1, (float)num1014, (float)num1015, (float)num1016, 0, 0, 0); + } + } + else if (!flag11 && num1017 > 0) + { + num1010 = Item.NewItem(this.GetItemSource_DropAsItem(), (int)this.position.X, (int)this.position.Y, this.width, this.height, num1017, 1, false, 0, false, false); + } + } + else if (num1017 > 0) + { + num1010 = Item.NewItem(this.GetItemSource_DropAsItem(), (int)this.position.X, (int)this.position.Y, this.width, this.height, num1017, 1, false, 0, false, false); + } + */ + } +} diff --git a/Projectiles/Typeless/SandBallAstral.png b/Projectiles/Typeless/SandBallAstral.png new file mode 100644 index 0000000000..5c300cd04f Binary files /dev/null and b/Projectiles/Typeless/SandBallAstral.png differ diff --git a/Projectiles/Typeless/SandBallEutrophic.png b/Projectiles/Typeless/SandBallEutrophic.png new file mode 100644 index 0000000000..ea5808c936 Binary files /dev/null and b/Projectiles/Typeless/SandBallEutrophic.png differ diff --git a/Projectiles/Typeless/SandBallSulphurous.png b/Projectiles/Typeless/SandBallSulphurous.png new file mode 100644 index 0000000000..cbe48f1656 Binary files /dev/null and b/Projectiles/Typeless/SandBallSulphurous.png differ diff --git a/Tiles/AstralDesert/AstralSand.cs b/Tiles/AstralDesert/AstralSand.cs index c64bde4cee..9b6d881fa2 100644 --- a/Tiles/AstralDesert/AstralSand.cs +++ b/Tiles/AstralDesert/AstralSand.cs @@ -64,7 +64,7 @@ namespace CalamityMod.Tiles.AstralDesert if (!Main.tile[i, j + 1].HasTile) { Main.tile[i, j].Get().HasTile = false; - Projectile.NewProjectile(new EntitySource_TileBreak(i, j), new Vector2(i * 16f + 8f, j * 16f + 8f), Vector2.Zero, ModContent.ProjectileType(), 15, 0f); + Projectile.NewProjectile(new EntitySource_TileBreak(i, j), new Vector2(i * 16f + 8f, j * 16f + 8f), Vector2.Zero, ModContent.ProjectileType(), 15, 0f); WorldGen.SquareTileFrame(i, j); return false; }