using Decimation.Content.Items.Misc;
using Decimation.Content.NPCs.Bloodshot;
using Decimation.Lib.Items;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Decimation.Content.Items.Boss.Bloodshot
{
    internal class BloodiedMaw : DecimationItem
    {
        protected override string ItemName => "Bloodied Maw";
        protected override string ItemTooltip => "{$CommonItemTooltip.RightClickToOpen}";

        protected override void Init()
        {
            item.width = 20;
            item.height = 24;
            item.consumable = true;
            item.useStyle = 4;
            item.useAnimation = 30;
            item.useTime = 30;

            this.item.maxStack = 1;
        }

        public override bool CanUseItem(Player player)
        {
            return !Main.dayTime || !NPC.AnyNPCs(ModContent.NPCType<BloodshotEye>());
        }

        public override bool UseItem(Player player)
        {
            if (Main.netMode == 0)
            {
                Main.PlaySound(15, (int) player.position.X, (int) player.position.Y, 0);
                NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType<BloodshotEye>());
            }
            else
            {
                ModPacket packet = this.mod.GetPacket();
                packet.Write((byte) DecimationModMessageType.SpawnBoss);
                packet.Write(ModContent.NPCType<BloodshotEye>());
                packet.Write(player.whoAmI);
                packet.Send();
            }

            return true;
        }

        protected override ModRecipe GetRecipe()
        {
            ModRecipe recipe = GetNewModRecipe(this, 1, TileID.DemonAltar);

            recipe.AddIngredient(ModContent.ItemType<BloodiedEssence>(), 10);
            recipe.AddIngredient(ItemID.Lens);

            return recipe;
        }
    }
}