using Decimation.Lib.Items;
using Decimation.Lib.Util;
using Decimation.Lib.Util.Builder;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Decimation.Content.Items.Accessories
{
    public class VeilOfVengeance : DecimationAccessory
    {
        protected override string ItemName => "Veil of Vengeance";

        protected override string ItemTooltip => "Increases length of invincibility after taking damage\n" +
                                                 "Causes stars to fall after taking damage\n" +
                                                 "Releases wasps and increase movement speed after taking damage\n" +
                                                 "Attackers have 20% chances to be poisoned";

        protected override void InitAccessory()
        {
            item.width = 26;
            item.height = 32;
            item.value = Item.buyPrice(gold: 19, silver: 70);
            item.rare = Rarity.LightPurple.GetRarityValue();
        }

        public override void UpdateAccessory(Player player, bool hideVisual)
        {
            player.longInvince = true;
            player.starCloak = true;
            
            base.UpdateAccessory(player, hideVisual);
        }

        protected override ModRecipe GetRecipe()
        {
            return new RecipeBuilder(this)
                .WithIngredient(ModContent.ItemType<WaspNecklace>())
                .WithIngredient(ItemID.StarVeil)
                .WithIngredient(ItemID.SoulofMight, 20)
                .WithStation(TileID.TinkerersWorkbench)
                .Build();
        }
    }

    internal class VeilofVengeancePoisonEffect : GlobalNPC
    {
        public override void OnHitPlayer(NPC npc, Player target, int damage, bool crit)
        {
            if (target.HasEquippedAccessory(ModContent.ItemType<VeilOfVengeance>()) && Main.rand.NextBool(5))
                npc.AddBuff(BuffID.Poisoned, 300);

            base.OnHitPlayer(npc, target, damage, crit);
        }
    }
}