package hmggirlfront.entity.vehicle;

import java.util.List;

import gvclib.mod_GVCLib;
import gvclib.entity.living.AI_TankSet;
import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.entity.living.EntityMobVehicleBase;
import gvclib.entity.living.ISoldier;
import gvclib.entity.living.PL_TankMove;
import gvclib.event.GVCSoundEvent;
import gvclib.network.GVCLMessageKeyPressed;
import gvclib.network.GVCLPacketHandler;
import hmggirlfront.mod_GirlFront;
import hmggirlfront.entity.EntityDoll;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class EntityVe_IFV extends EntityMobVehicleBase
{

    public EntityVe_IFV(World worldIn)
    {
        super(worldIn);
        this.setSize(4F, 3.0F);
        this.setcanDespawn(1);
        this.setVehicleLock(true);
        this.riddng_freehand = false;
        this.hud_icon = "hmggirlfront:textures/hud/apc.png";
        //this.render_hud_icon_hori = true;
        //this.hud_icon_hori = "hmggirlfront:textures/hud/heli_hori.png";
        this.render_hud_information_1 = "L-Click:Fire";
        this.render_hud_information_2 = "R-Click:Zoom";
        this.render_hud_information_3 = "C-KEY:Smoke";
        this.render_hud_information_4 = "X-KEY:ChangeWeapon";
        this.render_hud_information_5 = "V-KEY:ALLY-Boarding";
        this.render_hud_information_6 = "B-KEY:ALLY-Get off";
        
        
        vehicletype = 2;
        ridding_roteplayer = false;
        roodbreak = mod_GirlFront.cfg_vehicle_breakblock;
        this.spawn_item = mod_GirlFront.ve_ifv;
        
        vehicle_ridding_nofire[0] = true;
        vehicle_ridding_nofire[1] = false;
        vehicle_ridding_nofire[2] = false;
        vehicle_ridding_nofire[3] = false;
        vehicle_ridding_nofire[4] = false;
        
        this.sp = 0.03F;
        this.turnspeed = 2F;
		this.ridding_invisible = false;
		this.riddng_opentop = false;
		this.renderhud = true;
		this.thmax = 5F;
		this.thmin = -2F;
		this.thmaxa = 0.2F;
		this.thmina = -0.15F;
		this.stepHeight = 1.5F;
		this.riddng_maximum = 5;
		riddingx[0]=0.0D;
		riddingy[0]=2.4D;
		riddingz[0]=0.0D;
		{
			riddingx[1]=0.8D;
			riddingy[1]=0.5D;
			riddingz[1]=0.3D;
			
			riddingx[2]=-0.8D;
			riddingy[2]=0.5D;
			riddingz[2]=0.3D;
			
			riddingx[3]=0.8D;
			riddingy[3]=0.5D;
			riddingz[3]=-0.7D;
			
			riddingx[4]=-0.8D;
			riddingy[4]=0.5D;
			riddingz[4]=-0.7D;
			
		}
		
		
		ridding_view_x=0F;
		ridding_view_y=-2F;
		ridding_view_z=-5F;
		ridding_view_gunner_x=0F;
		ridding_view_gunner_y=2F;
		ridding_view_gunner_z=1F;
		
		antibullet_0 = 0.0F;
		antibullet_1 = 0.5F;
		antibullet_2 = 1.0F;
		antibullet_3 = 1.1F;
		this.ridding_damege = 0.5F;
		
		{
			this.weapon1true = true;
    		this.weapon1key = 0;
    		this.w1name = "25mmMC";
    		this.ammo1 = 4;
    		this.magazine = 8;
    		this.reload_time1 = 80;
    		this.reloadsoundset1 = 40;
    		this.reloadsound1 = GVCSoundEvent.reload_mg;
    		this.w1cycle = 1;
    		this.w1barst = 1;
    		this.weapon1 = 1;
    		{
    			this.bullet_type1[0] = 1;
        		this.bullet_model1[0] = "gvclib:textures/entity/bulletaaa.obj";
        		this.bullet_tex1[0] = "gvclib:textures/entity/bulletaaa.png";
        		this.fire_model1[0]= "gvclib:textures/entity/msmoke.mqo";
        		this.fire_tex1[0] = "gvclib:textures/entity/msmoke.png";
        		this.fire_time1[0] = 16;
        		this.sound_fire1[0] = "gvclib.fire_30mm";
        		this.fire_pointx1[0] = 0;
        		this.fire_pointy1[0] = 2.65F;
        		this.fire_pointz1[0] = 3.0F;
        		this.basis_pointx1[0] = 0;
        		this.basis_pointy1[0] = 2.65F;
        		this.basis_pointz1[0] = 1.4F;
        		this.fire_yoffset1[0] = 0;
        		this.rotationfollowing1[0] = true;
        		this.rotation_player1[0] = true;
        		this.rotationfirepoint1[0] = false;
        		this.bullet_damage1[0] = 10;
        		this.bullet_speed1[0] = 3.0F;
        		this.bullet_bure1[0] = 1F;
        		this.bullet_expower1[0] = 1.0F;
        		this.bullet_ex1[0] = false;
        		this.bullet_kazu1[0] = 1;
        		this.bullet_gravity1[0] = 0.025D;
        		this.bullet_livingtime1[0] = 80;
    		}
			this.mob_min_range = 15;
			this.mob_max_range = 50;
			this.mob_w1range = 50;
			this.mob_w1range_max_y = 20;
			this.mob_w1range_min_y = 5;
		}
		
		mob_min_range = 10;
		mob_max_range = 30;
		
		{
			this.weapon4true = true;
    		this.weapon4key = 0;
    		this.w4name = "Smoke";
    		this.ammo4 = 4;
    		this.magazine4 = 1;
    		this.reload_time4 = 300;
    		this.reloadsoundset4 = 40;
    		this.reloadsound4 = GVCSoundEvent.reload_mg;
    		this.w4cycle = 1;
    		this.w4barst = 1;
    		this.weapon4 = 1;
    		{
    			this.bullet_type4[0] = 9;
    			this.bullet_model4[0] =  "gvclib:textures/entity/grenade.mqo";
    			this.bullet_tex4[0] =  "gvclib:textures/entity/grenade.png";
    			this.fire_model4[0]=  "gvclib:textures/entity/grenade.mqo";
    			this.fire_tex4[0] =  "gvclib:textures/entity/grenade.png";
        		this.fire_time4[0] =  1;
        		this.sound_fire4[0] =  "gvclib.fire_grenade";
        		this.fire_pointx4[0] = 0F;
        		this.fire_pointy4[0] =  2.65F;
        		this.fire_pointz4[0] =  1.4F;
        		this.basis_pointx4[0] =  0;
        		this.basis_pointy4[0] =  2.65F;
        		this.basis_pointz4[0] =  1.4F;
        		this.fire_yoffset4[0] =  1;
        		this.rotationfollowing4[0]  = true;
        		this.rotation_player4[0] =  true;
        		this.rotationfirepoint4[0] =  false;
        		this.bullet_damage4[0] =  0;
        		this.bullet_speed4[0] =  1.2F;
        		this.bullet_bure4[0] =  0F;
        		this.bullet_expower4[0] =  5.0F;
        		this.bullet_exsmoke4[0] =  true;
        		this.bullet_ex4[0] =  false;
        		this.bullet_kazu4[0] =  1;
        		this.bullet_gravity4[0] =  0.025D;
        		this.bullet_livingtime4[0] =  30;
    		}
		}
		
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(200D);
        this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(20D);
    }

    public boolean processInteract(EntityPlayer player, EnumHand hand)
    {
    	ItemStack itemstack = player.getHeldItem(hand);
        boolean flag = !itemstack.isEmpty();
        if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.idoll_parts)
        {
        	if(this.getHealth() < this.getMaxHealth()) {
				this.setHealth(this.getHealth() + 10);
    			itemstack.shrink(1);
    			this.playSound(SoundEvents.BLOCK_ANVIL_LAND, 5F, 2F);
			}
        	return true;
        }
       /* else if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.dollgun_galil)
        {
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	this.setArmID_L(1);
        	this.setRemain_R(2);
        	return true;
        }
        else if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.dollgun_m1911)
        {
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	this.setArmID_L(0);
        	this.setRemain_R(8);
        	return true;
        }*/
        else  if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.ve_weaponchange)
        {
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	if(this.getArmID_L() == 0) {
        		this.setArmID_L(1);
        		this.setRemain_R(2);
        	}else {
        		this.setArmID_L(0);
        		this.setRemain_R(8);
        	}
        	return true;
        }
        else if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.dollgun_fn49)
        {
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	this.setArmID_R(1);
        	return true;
        }
        else if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.dollgun_p38)
        {
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	this.setArmID_R(0);
        	return true;
        }
        else{
        	super.processInteract(player, hand);
        	return true;
        }
        
    }
    
    public boolean spawn = false;
    public void onUpdate() {
		super.onUpdate();
		this.setcanDespawn(1);
		this.riddng_freehand = false;
		float f1 = this.rotationYawHead * (2 * (float) Math.PI / 360);
		this.roadattack();
		this.setcanDespawn(1);
		//this.typeHeli(GVCSoundEvent.sound_heli);
		this.setVehicleLock(true);
		if(this.getArmID_R() == 1) {
			vehicle_ridding_nofire[1] = true;
	        vehicle_ridding_nofire[2] = true;
	        vehicle_ridding_nofire[3] = true;
	        vehicle_ridding_nofire[4] = true;
		}else {
			vehicle_ridding_nofire[1] = false;
	        vehicle_ridding_nofire[2] = false;
	        vehicle_ridding_nofire[3] = false;
	        vehicle_ridding_nofire[4] = false;
		}
		if(this.getArmID_L() == 1){
			this.weapon2type = 1;
			{
				this.weapon2true = true;
	    		this.weapon2key = 0;
	    		this.w2name = "ATM";
	    		this.ammo2 = 20;
	    		this.magazine2 = 2;
	    		this.reload_time2 = 100;
	    		this.reloadsoundset2 = 40;
	    		this.reloadsound2 = GVCSoundEvent.reload_cannon;
	    		this.w2cycle = 1;
	    		this.w2barst = 1;
	    		this.weapon2 = 1;
	    		this.w2crossfire = true;
	    			this.bullet_type2[0] = 8;
	        		this.bullet_model2[0] = "gvclib:textures/entity/BulletMissile.mqo";
	        		this.bullet_tex2[0] = "gvclib:textures/entity/BulletMissile.png";
	        		this.fire_model2[0]= "gvclib:textures/entity/mflash.mqo";
	        		this.fire_tex2[0] = "gvclib:textures/entity/mflash.png";
	        		this.fire_time2[0] = 5;
	        		this.sound_fire2[0] = "gvclib.fire_missile";
	        		this.fire_pointx2[0] = 1.6F;
	        		this.fire_pointy2[0] = 3.1F;
	        		this.fire_pointz2[0] = 0.6F;
	        		this.basis_pointx1[0] = 1.6F;
	        		this.basis_pointy1[0] = 3.1F;
	        		this.basis_pointz1[0] = 0F;
	        		this.fire_yoffset2[0] = 0;
	        		this.rotationfollowing2[0] = true;
	        		this.rotationfirepoint2[0] = true;
	        		this.bullet_damage2[0] = 60;
	        		this.bullet_speed2[0] = 2F;
	        		this.bullet_bure2[0] = 1.0F;
	        		this.bullet_expower2[0] = 4;
	        		this.bullet_ex2[0] = false;
	        		this.bullet_kazu2[0] = 1;
	        		this.bullet_gravity2[0] = 0.029D;
	        		this.bullet_livingtime2[0] = 80;
			}
		}else {
			this.weapon2type = 1;
			{
				this.weapon2true = true;
	    		this.weapon2key = 0;
	    		this.w2name = "76mmRocket";
	    		this.ammo2 = 3;
	    		this.magazine2 = 8;
	    		this.reload_time2 = 100;
	    		this.reloadsoundset2 = 40;
	    		this.reloadsound2 = GVCSoundEvent.reload_cannon;
	    		this.w2cycle = 1;
	    		this.w2barst = 1;
	    		this.weapon2 = 1;
	    		this.w2crossfire = true;
	    			this.bullet_type2[0] = 3;
	        		this.bullet_model2[0] = "gvclib:textures/entity/BulletRocket.obj";
	        		this.bullet_tex2[0] = "gvclib:textures/entity/BulletRocket.png";
	        		this.fire_model2[0]= "gvclib:textures/entity/mflash.mqo";
	        		this.fire_tex2[0] = "gvclib:textures/entity/mflash.png";
	        		this.fire_time2[0] = 5;
	        		this.sound_fire2[0] = "gvclib.fire_roket";
	        		this.fire_pointx2[0] = 1.6F;
	        		this.fire_pointy2[0] = 3.1F;
	        		this.fire_pointz2[0] = 0.6F;
	        		this.basis_pointx1[0] = 1.6F;
	        		this.basis_pointy1[0] = 3.1F;
	        		this.basis_pointz1[0] = 0F;
	        		this.fire_yoffset2[0] = 0;
	        		this.rotationfollowing2[0] = true;
	        		this.rotationfirepoint2[0] = true;
	        		this.bullet_damage2[0] = 15;
	        		this.bullet_speed2[0] = 3F;
	        		this.bullet_bure2[0] = 1.0F;
	        		this.bullet_expower2[0] = 2;
	        		this.bullet_ex2[0] = false;
	        		this.bullet_kazu2[0] = 1;
	        		this.bullet_gravity2[0] = 0.029D;
	        		this.bullet_livingtime2[0] = 80;
			}
		}
		if(this.getArmID_S() == 1) {
			this.render_hud_scaleup_text1 = false;
			this.render_hud_scaleup_text2 = true;
		}else {
			this.render_hud_scaleup_text1 = true;
			this.render_hud_scaleup_text2 = false;
		}
		
		this.ContMobRidding();
		
		if (this.canBeSteered() && this.getControllingPassenger() != null && this.getHealth() > 0.0F)
		{
			if(this.getControllingPassenger() instanceof EntityPlayer)
			{
				EntityPlayer entitylivingbase = (EntityPlayer) this.getControllingPassenger();
				this.setcanDespawn(1);
				this.rotation  = entitylivingbase.rotationYawHead;
				this.rotationp = entitylivingbase.rotationPitch;
				//String dd = String.format("%1$3d", (int)entitylivingbase.rotationYawHead);
				//System.out.println(String.format(dd));
				Vec3d looked = entitylivingbase.getLookVec();
				PL_TankMove.move2(entitylivingbase, this, sp, turnspeed);

				boolean left = mod_GVCLib.proxy.leftclick();
				boolean right = mod_GVCLib.proxy.rightclick();
				boolean jump = mod_GVCLib.proxy.jumped();
				boolean kx = mod_GVCLib.proxy.keyx();
				boolean kg = mod_GVCLib.proxy.keyg();
				boolean kc = mod_GVCLib.proxy.keyc();
				if (left) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(11, this.getEntityId()));
					this.server1 = true;
				}
				if (right) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(12, this.getEntityId()));
				}
				if (jump) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(13, this.getEntityId()));
				}
				if (kx) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(14, this.getEntityId()));
				}
				if (kg) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(15, this.getEntityId()));
				}
				if (kc) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(16, this.getEntityId()));
				}

				if (serverx) {
					if(cooltime3 >= 5){
						if(this.getArmID_S() == 1) {
							this.setArmID_S(0);
						}else {
							this.setArmID_S(1);
						}
						this.playSound(GVCSoundEvent.reload_shell, 1.0F, 1.0F);
						cooltime3 = 0;
					}
					this.serverx = false;
				}

				if (this.server1) {
					if(this.getArmID_S() == 1){
	    				if(cooltime2 >= ammo2){
	    					this.counter2 = true;
	    		            cooltime2 = 0;
	    				}
	    				if(this.weapon2true) {
	    					this.weapon2active(looked, entitylivingbase);
	        		    }
	    			}else {
	    				if(cooltime >= ammo1){
	    					this.counter1 = true;
	    		            cooltime = 0;
	    				}
	    				if(this.weapon1true) {
	    					this.weapon1active(looked, entitylivingbase);
	        		    }
	    			}
					this.server1 = false;
				}

				if (this.serverc) {
					{
	    				if(cooltime4 >= ammo4){
	    					this.counter4 = true;
	    		            cooltime4 = 0;
	    				}
	    				if(this.weapon4true) {
	    					this.weapon4active(looked, entitylivingbase);
	        		    }
	    			}
					this.serverc = false;
				}
				

			}//player
			else if(this.getControllingPassenger() instanceof EntityGVCLivingBase) {
				
			}
		}
		
		AI_TankSet.set2(this, GVCSoundEvent.sound_tank, f1, sp, 0.1F);
		
    }

   
}