Fixed crashes for ranged weapons.

Optimized code.
This commit is contained in:
Big Duckie
2022-07-05 16:08:31 -06:00
parent 8f5ec80722
commit eb2cb27e79
51 changed files with 513 additions and 501 deletions
@@ -17,6 +17,7 @@ public class AugmentedUzi : ModItem
public override void SetDefaults()
{
Item.damage = 32;
Item.DamageType = DamageClass.Ranged;
Item.width = 48;
Item.height = 38;
Item.useTime = 2;
@@ -38,25 +39,23 @@ public class AugmentedUzi : ModItem
return new Vector2(-12f, -8f);
}
public override bool CanConsumeAmmo(Item ammo, Player player)
public override bool CanConsumeAmmo(Item ammo, Player player)
{
return Utils.NextFloat(Main.rand) >= 0.7f;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Vector2 perturbedSpeed = Utils.RotatedByRandom(new Vector2(velocity.X, velocity.Y), (double)MathHelper.ToRadians(6f));
velocity.X = perturbedSpeed.X;
velocity.Y = perturbedSpeed.Y;
velocity = Utils.RotatedByRandom(velocity, (double)MathHelper.ToRadians(6f));
return true;
}
public override void AddRecipes()
{
Recipe val = CreateRecipe();
val.AddIngredient(ModContent.ItemType<MachinePistol>());
val.AddIngredient(ItemID.Uzi, 1);
val.AddTile(TileID.MythrilAnvil);
val.Register();
CreateRecipe()
.AddIngredient(ModContent.ItemType<MachinePistol>())
.AddIngredient(ItemID.Uzi)
.AddTile(TileID.MythrilAnvil)
.Register();
}
}
@@ -1,4 +1,3 @@
using FabusMod.Projectiles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
@@ -18,6 +17,7 @@ public class CosmicHacker : ModItem
public override void SetDefaults()
{
Item.damage = 82;
Item.DamageType = DamageClass.Ranged;
Item.width = 48;
Item.height = 36;
Item.useTime = 2;
@@ -39,29 +39,27 @@ public class CosmicHacker : ModItem
return new Vector2(-8f, -8f);
}
public override bool CanConsumeAmmo(Item ammo, Player player)
public override bool CanConsumeAmmo(Item ammo, Player player)
{
return Utils.NextFloat(Main.rand) >= 0.9f;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Vector2 perturbedSpeed = Utils.RotatedByRandom(new Vector2(velocity.X, velocity.Y), (double)MathHelper.ToRadians(5f));
velocity.X = perturbedSpeed.X;
velocity.Y = perturbedSpeed.Y;
velocity = Utils.RotatedByRandom(velocity, (double)MathHelper.ToRadians(5f));
if (type == 14)
{
type = ModContent.ProjectileType<RainbowBullet>();
type = ModContent.ProjectileType<Projectiles.RainbowBullet>();
}
return true;
}
public override void AddRecipes()
{
Recipe val = CreateRecipe();
val.AddIngredient(ModContent.ItemType<MachinePistolGolden>());
val.AddIngredient(ModContent.ItemType<Bars.RainbowChunk>(), 10);
val.AddTile(ModContent.TileType<global::FabusMod.Tiles.RainbowStation>());
val.Register();
CreateRecipe()
.AddIngredient(ModContent.ItemType<MachinePistolGolden>())
.AddIngredient(ModContent.ItemType<Bars.RainbowChunk>(), 10)
.AddTile(ModContent.TileType<global::FabusMod.Tiles.RainbowStation>())
.Register();
}
}
@@ -17,6 +17,7 @@ public class MachinePistol : ModItem
public override void SetDefaults()
{
Item.damage = 10;
Item.DamageType = DamageClass.Ranged;
Item.width = 50;
Item.height = 38;
Item.useTime = 2;
@@ -33,7 +34,7 @@ public class MachinePistol : ModItem
Item.rare = ItemRarityID.LightRed;
}
public override bool CanConsumeAmmo(Item ammo, Player player)
public override bool CanConsumeAmmo(Item ammo, Player player)
{
return Utils.NextFloat(Main.rand) >= 0.8f;
}
@@ -43,20 +44,18 @@ public class MachinePistol : ModItem
return new Vector2(-12f, -8f);
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Vector2 perturbedSpeed = Utils.RotatedByRandom(new Vector2(velocity.X, velocity.Y), (double)MathHelper.ToRadians(6f));
velocity.X = perturbedSpeed.X;
velocity.Y = perturbedSpeed.Y;
velocity = Utils.RotatedByRandom(velocity, (double)MathHelper.ToRadians(6f));
return true;
}
public override void AddRecipes()
{
Recipe val = CreateRecipe();
val.AddRecipeGroup("FabusMod:OrichalcumBar", 16);
val.AddIngredient(ItemID.Amethyst, 5);
val.AddTile(TileID.MythrilAnvil);
val.Register();
CreateRecipe()
.AddRecipeGroup("FabusMod:OrichalcumBar", 16)
.AddIngredient(ItemID.Amethyst, 5)
.AddTile(TileID.MythrilAnvil)
.Register();
}
}
@@ -17,6 +17,7 @@ public class MachinePistolGolden : ModItem
public override void SetDefaults()
{
Item.damage = 66;
Item.DamageType = DamageClass.Ranged;
Item.width = 50;
Item.height = 38;
Item.useTime = 2;
@@ -38,25 +39,23 @@ public class MachinePistolGolden : ModItem
return new Vector2(-12f, -8f);
}
public override bool CanConsumeAmmo(Item ammo, Player player)
public override bool CanConsumeAmmo(Item ammo, Player player)
{
return Utils.NextFloat(Main.rand) >= 0.8f;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Vector2 perturbedSpeed = Utils.RotatedByRandom(new Vector2(velocity.X, velocity.Y), (double)MathHelper.ToRadians(5f));
velocity.X = perturbedSpeed.X;
velocity.Y = perturbedSpeed.Y;
velocity = Utils.RotatedByRandom(velocity, (double)MathHelper.ToRadians(5f));
return true;
}
public override void AddRecipes()
{
Recipe val = CreateRecipe();
val.AddRecipeGroup("FabusMod:Verano", 1);
val.AddIngredient(ModContent.ItemType<Items.CraftingIngredients.GoddessGold>(), 6);
val.AddTile(TileID.LunarCraftingStation);
val.Register();
CreateRecipe()
.AddRecipeGroup("FabusMod:Verano")
.AddIngredient(ModContent.ItemType<Items.CraftingIngredients.GoddessGold>(), 6)
.AddTile(TileID.LunarCraftingStation)
.Register();
}
}
+14 -15
View File
@@ -17,6 +17,7 @@ public class Verano : ModItem
public override void SetDefaults()
{
Item.damage = 60;
Item.DamageType = DamageClass.Ranged;
Item.width = 48;
Item.height = 36;
Item.useTime = 2;
@@ -38,31 +39,29 @@ public class Verano : ModItem
return new Vector2(-12f, -8f);
}
public override bool CanConsumeAmmo(Item ammo, Player player)
public override bool CanConsumeAmmo(Item ammo, Player player)
{
return Utils.NextFloat(Main.rand) >= 0.8f;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Vector2 perturbedSpeed = Utils.RotatedByRandom(new Vector2(velocity.X, velocity.Y), (double)MathHelper.ToRadians(5f));
velocity.X = perturbedSpeed.X;
velocity.Y = perturbedSpeed.Y;
velocity = Utils.RotatedByRandom(velocity, (double)MathHelper.ToRadians(5f));
return true;
}
public override void AddRecipes()
{
Recipe val = CreateRecipe();
val.AddIngredient(ModContent.ItemType<AugmentedUzi>());
val.AddIngredient(ItemID.FragmentVortex, 12);
val.AddTile(TileID.LunarCraftingStation);
val.Register();
CreateRecipe()
.AddIngredient(ModContent.ItemType<AugmentedUzi>())
.AddIngredient(ItemID.FragmentVortex, 12)
.AddTile(TileID.LunarCraftingStation)
.Register();
Recipe val2 = CreateRecipe();
val2.AddIngredient(ModContent.ItemType<VeranoRime>());
val2.AddIngredient(ItemID.GreenDye, 1);
val2.AddTile(TileID.DyeVat);
val2.Register();
CreateRecipe()
.AddIngredient(ModContent.ItemType<VeranoRime>())
.AddIngredient(ItemID.GreenDye)
.AddTile(TileID.DyeVat)
.Register();
}
}
@@ -17,6 +17,7 @@ public class VeranoRime : ModItem
public override void SetDefaults()
{
Item.damage = 60;
Item.DamageType = DamageClass.Ranged;
Item.width = 56;
Item.height = 36;
Item.useTime = 2;
@@ -38,25 +39,23 @@ public class VeranoRime : ModItem
return new Vector2(-16f, 0f);
}
public override bool CanConsumeAmmo(Item ammo, Player player)
public override bool CanConsumeAmmo(Item ammo, Player player)
{
return Utils.NextFloat(Main.rand) >= 0.8f;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Vector2 perturbedSpeed = Utils.RotatedByRandom(new Vector2(velocity.X, velocity.Y), (double)MathHelper.ToRadians(5f));
velocity.X = perturbedSpeed.X;
velocity.Y = perturbedSpeed.Y;
velocity = Utils.RotatedByRandom(velocity, (double)MathHelper.ToRadians(5f));
return true;
}
public override void AddRecipes()
{
Recipe val = CreateRecipe();
val.AddIngredient(ModContent.ItemType<Verano>());
val.AddIngredient(ItemID.BlueDye, 1);
val.AddTile(TileID.DyeVat);
val.Register();
CreateRecipe()
.AddIngredient(ModContent.ItemType<Verano>())
.AddIngredient(ItemID.BlueDye)
.AddTile(TileID.DyeVat)
.Register();
}
}