Sandgun now works with more sand

Changed how sand AI works a little
This commit is contained in:
Altixal committed 2023-03-22 20:34:55 +07:00
1 parent d34979ca73
commit 1a2fe01998
11 files changed
+208 -66

No files matched your search

+8
View File
@@ -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<AstralSand>() || ammo.type == ModContent.ItemType<EutrophicSand>() || ammo.type == ModContent.ItemType<SulphurousSand>()))
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)
+5 -5
View File
@@ -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<AstralSandgun>();
// item.notAmmo = true;
// item.shootSpeed = 15f;
Item.ammo = AmmoID.Sand;
Item.shoot = ModContent.ProjectileType<AstralSandBallGun>();
Item.notAmmo = true;
Item.useStyle = ItemUseStyleID.Swing;
Item.useTurn = true;
Item.useAnimation = 15;
+4
View File
@@ -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<EutrophicSandBallGun>();
Item.notAmmo = true;
}
public override void AddRecipes()
+6 -1
View File
@@ -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<SulphurousSandBallGun>();
Item.notAmmo = true;
}
public override void AddRecipes()
-59
View File
@@ -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<AstralSand>(), 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();
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 B

+184
View File
@@ -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<AstralSand>(), ModContent.ItemType<Items.Placeables.AstralSand>());
}
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<AstralSand>(), ModContent.ItemType<Items.Placeables.AstralSand>());
}
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<EutrophicSand>(), ModContent.ItemType<Items.Placeables.EutrophicSand>());
}
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<SulphurousSand>(), ModContent.ItemType<Items.Placeables.SulphurousSand>());
}
// 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);
}
*/
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

+1 -1
View File
@@ -64,7 +64,7 @@ namespace CalamityMod.Tiles.AstralDesert
if (!Main.tile[i, j + 1].HasTile)
{
Main.tile[i, j].Get<TileWallWireStateData>().HasTile = false;
Projectile.NewProjectile(new EntitySource_TileBreak(i, j), new Vector2(i * 16f + 8f, j * 16f + 8f), Vector2.Zero, ModContent.ProjectileType<AstralFallingSand>(), 15, 0f);
Projectile.NewProjectile(new EntitySource_TileBreak(i, j), new Vector2(i * 16f + 8f, j * 16f + 8f), Vector2.Zero, ModContent.ProjectileType<AstralSandBallFalling>(), 15, 0f);
WorldGen.SquareTileFrame(i, j);
return false;
}