using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Terraria.GameContent.Creative;
using TalesOfTheKingMod.Content.Projectiles.OnFireFlame;
namespace TalesOfTheKingMod.Content.Items.Ranged.FossilFuel
{
public class FossilFuel : ModItem
{
public override void SetDefaults()
{
// Combat prop
Item.damage = 11;
Item.DamageType = DamageClass.Ranged;
Item.crit = 0;
Item.useTime = 2;
Item.useAnimation = 30;
Item.knockBack = 0.1f;
Item.autoReuse = true;
Item.reuseDelay = 10;
Item.consumeAmmoOnLastShotOnly = true;
// Visual prop
Item.width = 58;
Item.height = 18;
Item.scale = 1f;
Item.useStyle = ItemUseStyleID.Shoot;
Item.rare = ItemRarityID.Green;
// Other prop
Item.value = Item.sellPrice(0, 0, 40, 0);
Item.UseSound = SoundID.Item34;
Item.noMelee = true;
Item.shoot = ProjectileID.PurificationPowder;
Item.shootSpeed = 21f;
Item.useAmmo = AmmoID.Gel;
}
public override bool CanUseItem(Player player)
{
return !player.wet;
}
public override void AddRecipes()
{
Recipe recipe1 = Recipe.Create(ModContent.ItemType<FossilFuel>());
recipe1.AddIngredient(ItemID.FossilOre, 12);
recipe1.AddIngredient(ItemID.Torch, 20);
recipe1.AddRecipeGroup(RecipeGroupID.IronBar, 8);
recipe1.AddTile(TileID.Anvils);
recipe1.Register();
}
public override void SetStaticDefaults()
{
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; // How many items need for research in Journey Mode
}
public override bool CanConsumeAmmo(Item ammo, Player player) => Main.rand.Next(101) <= 20; // Chance in % to not consume ammo
public override Vector2? HoldoutOffset() => new Vector2(-3f, 0f); // Offset editor in pixel
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
velocity = velocity.RotatedByRandom(MathHelper.ToRadians(0));
int NumProjectiles = Main.rand.Next(1, 1);
for (int i = 0; i < NumProjectiles; i++)
{
Vector2 NewVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(2));
NewVelocity *= 1f - Main.rand.NextFloat(0.2f);
if (type == ProjectileID.PurificationPowder)
{
type = ModContent.ProjectileType<OnFireFlame>();
}
Projectile.NewProjectileDirect(
source,
position,
NewVelocity,
type,
damage,
knockback,
player.whoAmI
);
}
return false;
}
}
}