package alcoholmod.Mathioks.item;

import alcoholmod.Mathioks.ExtendedPlayer;
import alcoholmod.Mathioks.Final.JutsuItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.UUID;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class ItemChidori
  extends JutsuItem
{
  @SideOnly(Side.CLIENT)
  public EnumRarity func_77613_e(ItemStack par1ItemStack)
  {
    return EnumRarity.epic;
  }
  
  public void func_77663_a(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
  {
    if ((EntityPlayer)par3Entity != null) {
      if (field_77990_d == null)
      {
        field_77990_d = new NBTTagCompound();
        field_77990_d.func_74778_a("Owner", ((EntityPlayer)par3Entity).func_70005_c_());
        field_77990_d.func_74768_a("counter", 0);
        field_77990_d.func_74757_a("Ready", false);
      }
    }
    if (field_77990_d != null)
    {
      EntityPlayer player = (EntityPlayer)par3Entity;
      ExtendedPlayer props = ExtendedPlayer.get(player);
      if ((props.getCurrentMana() >= 200 + props.getNinjutsu() / 600) && (!field_77990_d.func_74767_n("Ready"))) {
        field_77990_d.func_74757_a("Ready", true);
      }
      if ((props.getCurrentMana() < 200 + props.getNinjutsu() / 600) && (field_77990_d.func_74767_n("Ready") == true)) {
        field_77990_d.func_74757_a("Ready", false);
      }
      int counter = field_77990_d.func_74762_e("counter");
      if (counter > 0)
      {
        counter--;
        field_77990_d.func_74768_a("counter", counter);
        if (counter > 0)
        {
          if ((((EntityPlayer)par3Entity).func_70090_H()) || (field_70170_p.func_147439_a(MathHelper.func_76128_c(field_70165_t), MathHelper.func_76128_c(field_70163_u - 0.2D - field_70129_M), MathHelper.func_76128_c(field_70161_v)) == Blocks.field_150355_j))
          {
            List list = par2World.func_72872_a(Entity.class, AxisAlignedBB.func_72330_a(field_70165_t - 10.0D, field_70163_u - 3.0D, field_70161_v - 10.0D, field_70165_t + 10.0D, field_70163_u + 3.0D, field_70161_v + 10.0D));
            if ((EntityPlayer)par3Entity != null) {
              for (int k2 = 0; k2 < list.size(); k2++) {
                if (!field_72995_K)
                {
                  Entity entity = (Entity)list.get(k2);
                  String user = ((EntityPlayer)par3Entity).func_110124_au().toString();
                  double d0 = entity.func_70011_f(field_70165_t, field_70163_u, field_70161_v);
                  if ((entity instanceof EntityLiving)) {
                    if ((entity instanceof EntityLivingBase))
                    {
                      ((EntityLivingBase)entity).func_70690_d(new PotionEffect(field_76421_dfield_76415_H, 20, 4));
                      entity.func_70097_a(DamageSource.func_76365_a(player), 1.0F);
                    }
                  }
                  if ((entity instanceof EntityPlayer)) {
                    if (!entity.func_110124_au().toString().equals(user))
                    {
                      ((EntityLivingBase)entity).func_70690_d(new PotionEffect(field_76421_dfield_76415_H, 20, 4));
                      entity.func_70097_a(DamageSource.func_76365_a(player), 1.0F);
                    }
                  }
                }
              }
            }
          }
          List list = par2World.func_72872_a(Entity.class, AxisAlignedBB.func_72330_a(field_70165_t - 2.0D, field_70163_u - 1.0D, field_70161_v - 2.0D, field_70165_t + 2.0D, field_70163_u + 1.0D, field_70161_v + 2.0D));
          if (player != null) {
            for (int k2 = 0; k2 < list.size(); k2++) {
              if (!field_72995_K)
              {
                Entity entity = (Entity)list.get(k2);
                String user = player.func_110124_au().toString();
                double d0 = entity.func_70011_f(field_70165_t, field_70163_u, field_70161_v);
                if ((entity instanceof EntityLiving)) {
                  if ((entity instanceof EntityLivingBase))
                  {
                    ((EntityLivingBase)entity).func_70690_d(new PotionEffect(field_76421_dfield_76415_H, 100, 2));
                    ((EntityLivingBase)entity).func_70690_d(new PotionEffect(field_76430_jfield_76415_H, 100, -1));
                    entity.func_70097_a(DamageSource.func_76365_a(player), 75.0F + props.getNinjutsu() / 60);
                  }
                }
                if ((entity instanceof EntityPlayer)) {
                  if (!entity.func_110124_au().toString().equals(user))
                  {
                    ((EntityLivingBase)entity).func_70690_d(new PotionEffect(field_76421_dfield_76415_H, 100, 2));
                    ((EntityLivingBase)entity).func_70690_d(new PotionEffect(field_76430_jfield_76415_H, 100, -1));
                    entity.func_70097_a(DamageSource.func_76365_a(player), 75.0F + props.getNinjutsu() / 60);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  public ItemStack func_77659_a(ItemStack Par1ItemStack, World Par2World, EntityPlayer Par3EntityPlayer)
  {
    if (field_77990_d.func_74767_n("Ready") == true)
    {
      int counter = field_77990_d.func_74762_e("counter");
      if (field_77990_d.func_74779_i("Owner").equals(Par3EntityPlayer.func_70005_c_()))
      {
        Par3EntityPlayer.func_70024_g(-Math.sin(Math.toRadians(field_70759_as)) * 8.0D, 0.0D, Math.cos(Math.toRadians(field_70759_as)) * 8.0D);
        if (!field_72995_K)
        {
          EntityPlayer player = Par3EntityPlayer;
          ExtendedPlayer props = ExtendedPlayer.get(player);
          if (props.getCurrentMana() >= 200 + props.getNinjutsu() / 600)
          {
            counter = 30;
            field_77990_d.func_74768_a("counter", counter);
            Par3EntityPlayer.func_146105_b(new ChatComponentText("Chidori!"));
            props.consumeMana(200 + props.getNinjutsu() / 600);
          }
          else if (!field_72995_K)
          {
            Par3EntityPlayer.func_146105_b(new ChatComponentText("You don't have enough chakra"));
          }
        }
      }
      else if (!field_72995_K)
      {
        Par3EntityPlayer.func_146105_b(new ChatComponentText("You Are not The owner of this Item"));
      }
    }
    return Par1ItemStack;
  }
  
  @SideOnly(Side.CLIENT)
  public void func_77624_a(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
  {
    EntityPlayer player = par2EntityPlayer;
    ExtendedPlayer props = ExtendedPlayer.get(player);
    if (field_77990_d != null) {
      par3List.add(EnumChatFormatting.AQUA + "Owner: " + field_77990_d.func_74779_i("Owner"));
    }
    par3List.add(EnumChatFormatting.DARK_AQUA + "A high concentration of lightning");
    par3List.add(EnumChatFormatting.DARK_AQUA + "chakra around the user's hand");
    par3List.add(EnumChatFormatting.DARK_AQUA + "Increases speed, damages and paralyzes");
    par3List.add(EnumChatFormatting.DARK_AQUA + "Anything on your path");
    par3List.add(EnumChatFormatting.DARK_RED + "Chakra Cost: " + (200 + props.getNinjutsu() / 600));
    par3List.add(EnumChatFormatting.DARK_RED + "Damage: " + (75 + props.getNinjutsu() / 60));
  }
}