using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Decimation.Content.Items.Weapons;
using Decimation.Lib.Items;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Decimation.Content.Projectiles
{
   internal class SiphonArrow : DecimationProjectile
    {
        protected override void Init()
        {
            projectile.width = 14;
            projectile.height = 32;
            projectile.aiStyle = 1;
            DamageType = DecimationWeapon.DamageType.Ranged;
            projectile.penetrate = 1;
            projectile.timeLeft = 600;
            projectile.tileCollide = true;
            projectile.arrow = true;
            aiType = ProjectileID.WoodenArrowFriendly;
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            Heal(damage);
        }

        public override void OnHitPlayer(Player target, int damage, bool crit)
        {
            Heal(damage);
        }

        public override void OnHitPvp(Player target, int damage, bool crit)
        {
            Heal(damage);
        }

        private void Heal(int damage)
        {
            int healAmount = (int)(damage * (Main.rand.Next(26) / 100f));

            Player player = Main.player[projectile.owner];
            player.statLife += healAmount;
            player.HealEffect(healAmount);
        }

        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            return true;
        }
    }
}
