using System.Collections.Generic;
using Decimation.Content.Items.Misc.CondensedSouls;
using Decimation.Content.Items.Ores;
using Decimation.Content.Projectiles;
using Decimation.Content.Tiles;
using Decimation.Lib.Items;
using Decimation.Lib.Util;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Decimation.Content.Items.Accessories.Wings
{
    [AutoloadEquip(EquipType.Wings)]
    internal class ScarabWings : DecimationAccessory
    {
        protected override string ItemName => "Scarab Wings";
        protected override string ItemTooltip => "Blessed by the sun";

        protected override void InitAccessory()
        {
            item.width = 26;
            item.height = 26;
            item.rare = Rarity.Red.GetRarityValue();

            this.item.value = Item.buyPrice(0, 5);
        }

        public override void UpdateAccessory(Player player, bool hideVisual)
        {
            player.wingTimeMax = 240;
            Lighting.AddLight((int)(player.position.X + player.width / 2f) / 16,
                (int)(player.position.Y + player.height / 2f) / 16, 1.05f, 0.95f, 0.55f);

            if ((int)player.wingTime % 2 == 1)
                Projectile.NewProjectile(player.Center, new Vector2(0, 0), ModContent.ProjectileType<Ember>(), 25, 5,
                    player.whoAmI);
        }

        public override void VerticalWingSpeeds(Player player, ref float ascentWhenFalling, ref float ascentWhenRising,
            ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend)
        {
            ascentWhenFalling = 0.85f;
            ascentWhenRising = 0.15f;
            maxCanAscendMultiplier = 1f;
            maxAscentMultiplier = 3f;
            constantAscend = 0.135f;
        }

        public override void HorizontalWingSpeeds(Player player, ref float speed, ref float acceleration)
        {
            speed = 9f;
            acceleration *= 2.5f;
        }

        protected override List<ModRecipe> GetRecipes()
        {
            ModRecipe recipe = GetNewModRecipe(this, 1, new List<int> { ModContent.TileType<TitanForge>() });

            recipe.AddIngredient(ItemID.BeetleWings);
            recipe.AddIngredient(ItemID.WingsSolar);
            recipe.AddIngredient(ModContent.ItemType<CondensedSpite>(), 2);
            recipe.AddIngredient(ModContent.ItemType<DenziumBar>(), 5);

            return new List<ModRecipe> { recipe };
        }
    }
}