From da3b3f9f263ab14bf7de2e57c33fb3e47bc10c67 Mon Sep 17 00:00:00 2001 From: Altixal <73398287+Altixal@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:48:46 +0700 Subject: [PATCH] sandgun support port sup (no real change just made it use the new april thing) --- Items/CalamityGlobalItem.cs | 23 ------ Items/Placeables/AstralSand.cs | 3 + Items/Placeables/EutrophicSand.cs | 3 + Items/Placeables/SulphurousSand.cs | 3 + Projectiles/Typeless/SandBall.cs | 109 ++++++++++++++++------------- Tiles/AstralDesert/AstralSand.cs | 12 +--- 6 files changed, 69 insertions(+), 84 deletions(-) diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index eeb55e844c..23c56a8d45 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -1660,29 +1660,6 @@ 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) - { - if (ammo.type == ModContent.ItemType()) - { - type = ModContent.ProjectileType(); - damage.Flat += 5; - } - else if (ammo.type == ModContent.ItemType()) - { - type = ModContent.ProjectileType(); - damage.Flat += 5; - } - else if (ammo.type == ModContent.ItemType()) - { - type = ModContent.ProjectileType(); - 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 f2ad9b633a..2a2e4f9987 100644 --- a/Items/Placeables/AstralSand.cs +++ b/Items/Placeables/AstralSand.cs @@ -10,6 +10,9 @@ namespace CalamityMod.Items.Placeables public override void SetStaticDefaults() { Item.ResearchUnlockCount = 100; + + // +5 flat damage, equal to other sand variants + ItemID.Sets.SandgunAmmoProjectileData[Type] = new(ModContent.ProjectileType(), 5); } public override void SetDefaults() diff --git a/Items/Placeables/EutrophicSand.cs b/Items/Placeables/EutrophicSand.cs index c0e6ef79d3..202584c1e0 100644 --- a/Items/Placeables/EutrophicSand.cs +++ b/Items/Placeables/EutrophicSand.cs @@ -13,6 +13,9 @@ namespace CalamityMod.Items.Placeables { Item.ResearchUnlockCount = 100; ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); + + // +5 flat damage, equal to other sand variants + ItemID.Sets.SandgunAmmoProjectileData[Type] = new(ModContent.ProjectileType(), 5); } public override void SetDefaults() diff --git a/Items/Placeables/SulphurousSand.cs b/Items/Placeables/SulphurousSand.cs index b2a11c34f1..0dbe2a305f 100644 --- a/Items/Placeables/SulphurousSand.cs +++ b/Items/Placeables/SulphurousSand.cs @@ -11,6 +11,9 @@ namespace CalamityMod.Items.Placeables { Item.ResearchUnlockCount = 100; ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); + + // +5 flat damage, equal to other sand variants + ItemID.Sets.SandgunAmmoProjectileData[Type] = new(ModContent.ProjectileType(), 5); } public override void SetDefaults() diff --git a/Projectiles/Typeless/SandBall.cs b/Projectiles/Typeless/SandBall.cs index d40b38757e..b07b7f1ff3 100644 --- a/Projectiles/Typeless/SandBall.cs +++ b/Projectiles/Typeless/SandBall.cs @@ -9,99 +9,108 @@ using Terraria.ModLoader; namespace CalamityMod.Projectiles.Typeless { - public class AstralSandBallFalling : ModProjectile, ILocalizedModType + public class AstralSandBallFalling : SandBall { - public new string LocalizationCategory => "Projectiles.Typeless"; 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 OnKill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + public override bool Fired => false; + public override int TileType => ModContent.TileType(); + public override int ItemType => ModContent.ItemType(); + public override int DustType => 108; } - public class AstralSandBallGun : ModProjectile, ILocalizedModType + public class AstralSandBallGun : SandBall { - public new string LocalizationCategory => "Projectiles.Typeless"; public override string Texture => "CalamityMod/Projectiles/Typeless/SandBallAstral"; - public override void SetDefaults() => Projectile.FallingSandSetup(); - public override void AI() => Projectile.FallingSandAI(108); - public override void OnKill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + public override int TileType => ModContent.TileType(); + public override int ItemType => ModContent.ItemType(); + public override int DustType => 108; } - public class EutrophicSandBallGun : ModProjectile, ILocalizedModType + public class EutrophicSandBallGun : SandBall { - public new string LocalizationCategory => "Projectiles.Typeless"; 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 OnKill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + public override int TileType => ModContent.TileType(); + public override int ItemType => ModContent.ItemType(); + public override int DustType => 108; // Weirdly same dusts as Astral } - public class SulphurousSandBallGun : ModProjectile, ILocalizedModType + public class SulphurousSandBallGun : SandBall { - public new string LocalizationCategory => "Projectiles.Typeless"; public override string Texture => "CalamityMod/Projectiles/Typeless/SandBallSulphurous"; - public override void SetDefaults() => Projectile.FallingSandSetup(); - public override void AI() => Projectile.FallingSandAI(32); - public override void OnKill(int timeLeft) => Projectile.SpawnSand(ModContent.TileType(), ModContent.ItemType()); + public override int TileType => ModContent.TileType(); + public override int ItemType => ModContent.ItemType(); + // Uses normal sand dust } // All the setups go here to prevent mass blocks of copypasting - public static partial class FallingSandUtils + public abstract class SandBall : ModProjectile, ILocalizedModType { - internal static void FallingSandSetup(this Projectile proj, bool fired = true) - { - proj.knockBack = 6f; - proj.width = proj.height = 10; - proj.friendly = true; - proj.penetrate = -1; + public new string LocalizationCategory => "Projectiles.Typeless"; - if (fired) + // Whether or not it is a fired projectile + public virtual bool Fired => true; + // Associated tile type + public virtual int TileType => TileID.Sand; + // Associated item type + public virtual int ItemType => ItemID.SandBlock; + // Associated dust type + public virtual int DustType => DustID.Sand; + + public override void SetDefaults() + { + Projectile.knockBack = 6f; + Projectile.width = Projectile.height = 10; + Projectile.friendly = true; + Projectile.penetrate = -1; + + if (Fired) { - proj.MaxUpdates = 2; - proj.DamageType = DamageClass.Ranged; + Projectile.MaxUpdates = 2; + Projectile.DamageType = DamageClass.Ranged; } else - proj.hostile = true; + Projectile.hostile = true; } - public static void FallingSandAI(this Projectile proj, int DustID, bool fired = true) + // Using clones will not allow for custom dust types sadly + public override void AI() { if (Main.rand.NextBool()) { - int i = Dust.NewDust(proj.position, proj.width, proj.height, DustID); + int i = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustType); Main.dust[i].velocity.X *= 0.4f; - Main.dust[i].velocity.Y += fired ? 0f : proj.velocity.Y * 0.5f; + Main.dust[i].velocity.Y += Fired ? 0f : Projectile.velocity.Y * 0.5f; } - proj.ai[1]++; - proj.rotation += 0.1f; - if (proj.ai[1] >= 60f || !fired) + Projectile.ai[1]++; + Projectile.rotation += 0.1f; + if (Projectile.ai[1] >= 60f || !Fired) { - proj.ai[1] = 60f; - proj.velocity.Y += 0.2f; + Projectile.ai[1] = 60f; + Projectile.velocity.Y += 0.2f; } - if (proj.velocity.Y > 10f) - proj.velocity.Y = 10f; + if (Projectile.velocity.Y > 10f) + Projectile.velocity.Y = 10f; - Point p = proj.Center.ToTileCoordinates(); + Point p = Projectile.Center.ToTileCoordinates(); // Don't check out of bounds if (p.X < 0 || p.X >= Main.maxTilesX || p.Y < 0 || p.Y >= Main.maxTilesY) return; Tile placer = Main.tile[p.X, p.Y + 1]; - if (placer.HasTile && TileID.Sets.Platforms[placer.TileType] && proj.ai[1] >= 60f) - proj.Kill(); + if (placer.HasTile && TileID.Sets.Platforms[placer.TileType] && Projectile.ai[1] >= 60f) + Projectile.Kill(); } - public static void SpawnSand(this Projectile proj, int SandBlockID, int SandItemID) + public override void OnKill(int timeLeft) { - Point p = proj.Center.ToTileCoordinates(); + 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 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)) + if (placer.IsHalfBlock && Projectile.velocity.Y > 0f && Math.Abs(Projectile.velocity.Y) > Math.Abs(Projectile.velocity.X)) placer = Main.tile[p.X, --p.Y]; bool ValidTileBelow = true; @@ -125,7 +134,7 @@ namespace CalamityMod.Projectiles.Typeless if (ValidTileBelow) { - bool PlacedBlock = WorldGen.PlaceTile(p.X, p.Y, SandBlockID, false, true); + bool PlacedBlock = WorldGen.PlaceTile(p.X, p.Y, TileType, false, true); WorldGen.SquareTileFrame(p.X, p.Y); if (PlacedBlock && SlopeTileBelow) @@ -135,12 +144,12 @@ namespace CalamityMod.Projectiles.Typeless 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); + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 1, p.X, p.Y, TileType); } } // Give the block back if you literally can't place it else - Item.NewItem(proj.GetSource_DropAsItem(), proj.position, proj.width, proj.height, SandItemID); + Item.NewItem(Projectile.GetSource_DropAsItem(), Projectile.position, Projectile.width, Projectile.height, ItemType); } } } diff --git a/Tiles/AstralDesert/AstralSand.cs b/Tiles/AstralDesert/AstralSand.cs index 62d4e4544b..56e1f6fb34 100644 --- a/Tiles/AstralDesert/AstralSand.cs +++ b/Tiles/AstralDesert/AstralSand.cs @@ -37,6 +37,7 @@ namespace CalamityMod.Tiles.AstralDesert TileID.Sets.Conversion.Sand[Type] = true; TileID.Sets.ForAdvancedCollision.ForSandshark[Type] = true; TileID.Sets.Falling[Type] = true; + TileID.Sets.FallingBlockProjectile[Type] = new TileID.Sets.FallingBlockProjectileInfo(ModContent.ProjectileType(), 15); TileFraming.SetUpUniversalMerge(Type, TileID.Dirt, out tileAdjacency); TileFraming.SetUpUniversalMerge(Type, TileID.Stone, out secondTileAdjacency); @@ -57,17 +58,6 @@ namespace CalamityMod.Tiles.AstralDesert } public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { - if (j < Main.maxTilesY) - { - // tile[i, j+1] can still be null if it's on the edge of a chunk - 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); - WorldGen.SquareTileFrame(i, j); - return false; - } - } TileFraming.GetAdjacencyData(i, j, TileID.Dirt, out tileAdjacency[i, j]); TileFraming.GetAdjacencyData(i, j, TileID.Stone, out secondTileAdjacency[i, j]); TileFraming.GetAdjacencyData(i, j, ModContent.TileType(), out thirdTileAdjacency[i, j]);