using Decimation.Content.Buffs.Debuffs;
using Decimation.Content.Items.Amulets;
using Decimation.Content.Projectiles;
using Decimation.Lib.Amulets.Synergy;
using Decimation.Lib.Util;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Decimation.Content.Synergies
{
    internal class FireAmuletSynergy : AmuletSynergyAdapter
    {
        private const int AddedLavaTime = 500;

        public override void Update(DecimationPlayer modPlayer)
        {
            if (modPlayer.player.lavaMax > 0) modPlayer.player.lavaMax += AddedLavaTime;
        }

        public override void OnHitNPC(DecimationPlayer modPlayer, NPC target, Item weapon, ref int damages,
            ref bool crit)
        {
            if (weapon.type.IsFireWeapon()) target.AddBuff(ModContent.BuffType<Singed>(), 500);
        }

        public override void OnHitPlayer(DecimationPlayer modPlayer, Player target, Item weapon, ref int damages,
            ref bool crit)
        {
            if (weapon.type.IsFireWeapon()) target.AddBuff(ModContent.BuffType<Singed>(), 500);
        }

        private class FireAmuletSynergyFieryGreatswordEffect : GlobalItem
        {
            public override bool UseItem(Item item, Player player)
            {
                if (item.type == ItemID.FieryGreatsword &&
                    player.HasEquippedAmulet(ModContent.ItemType<FireAmulet>()))
                {
                    int proj = Projectile.NewProjectile(player.Center + player.Directions * new Vector2(24, -16),
                        player.Directions * new Vector2(6, 0), ModContent.ProjectileType<ArachnusFireball>(), 30,
                        5f, player.whoAmI);
                    Main.projectile[proj].hostile = false;
                    Main.projectile[proj].friendly = true;
                }

                return true;
            }
        }

        private class FireAmuletSynergyFlamarangEffect : GlobalProjectile
        {
            public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
            {
                if (projectile.type.IsFireMeleeProjectile() &&
                    Main.LocalPlayer.HasEquippedAmulet(ModContent.ItemType<FireAmulet>()))
                {
                    target.AddBuff(ModContent.BuffType<Singed>(), 500);
                }
            }

            public override void OnHitPlayer(Projectile projectile, Player target, int damage, bool crit)
            {
                if (projectile.type.IsFireMeleeProjectile() &&
                    Main.LocalPlayer.HasEquippedAmulet(ModContent.ItemType<FireAmulet>()))
                {
                    target.AddBuff(ModContent.BuffType<Singed>(), 500);
                }
            }
        }
    }
}