package hmggirlfront.entity.vehicle;

import java.util.List;

import gvclib.mod_GVCLib;
import gvclib.entity.living.AI_EntityWeapon;
import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.entity.living.EntityMobVehicleBase;
import gvclib.entity.living.ISoldier;
import gvclib.entity.living.PL_AirCraftMove;
import gvclib.entity.living.PL_Weapon;
import gvclib.entity.living.cnt.VehicleCNT_Boat;
import gvclib.entity.living.cnt.VehicleCNT_Tank;
import gvclib.entity.living.cnt.ai.AI_GetTarget_OnRidding;
import gvclib.event.GVCSoundEvent;
import gvclib.network.GVCLMessageKeyPressed;
import gvclib.network.GVCLPacketHandler;
import gvclib.world.GVCExplosionBase;
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.monster.IMob;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class EntityVe_CB90 extends EntityMobVehicleBase
{
    public EntityVe_CB90(World worldIn)
    {
        super(worldIn);
        this.setSize(6.0F, 2.4F);
        this.hud_icon = "gvclib:textures/hud/tank64.png";

        this.render_hud_information_5 = "V-KEY:ALLY-Boarding";
        this.render_hud_information_6 = "B-KEY:ALLY-Get off";
        
        //this.difficulty_adjustment = mod_GVCR2.cfg_damage_relief_vehicle;
        
        this.spawn_item = mod_GirlFront.ve_cb90;
        
        this.sp = 0.035F;
        this.turnspeed = 1.5F;
        this.rotationp_max = -50F;
        this.rotationp_min = 10F;
		this.ridding_invisible = false;
		this.riddng_opentop = false;
		this.ridding_roteplayer = false;
		this.ridding_roteplayerPitch = 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 = 7;
		riddingx[0] = 0.0;
		riddingy[0] = 0.7;
		riddingz[0] = 2;
		this.ridding_view1_x = 0.0F;
		this.ridding_view1_y = -1.0F;
		this.ridding_view1_z = 0.0F;
		{
			riddingx[1]=0.0D;
			riddingy[1]=1.7D;
			riddingz[1]=0.0D;
			
			riddingx[2]=1.0D;
			riddingy[2]=1.5D;
			riddingz[2]=-1.0D;
			riddingx[3]=-1.0D;
			riddingy[3]=1.5D;
			riddingz[3]=-1.0D;
			
			riddingx[4]=1.0D;
			riddingy[4]=1.0D;
			riddingz[4]=-3.5D;
			riddingx[5]=-1.0D;
			riddingy[5]=1.0D;
			riddingz[5]=-3.5D;
			
			riddingx[6]=0.0D;
			riddingy[6]=1.3D;
			riddingz[6]=-2.1D;
		}
		 vehicle_ridding_nofire[0] = true;
	     vehicle_ridding_nofire[1] = true;
	     vehicle_ridding_nofire[2] = false;
	     vehicle_ridding_nofire[3] = false;
		
		antibullet_0 = 0.0F;
		antibullet_1 = 0.5F;
		antibullet_2 = 1.0F;
		antibullet_3 = 1.0F;
		this.ridding_damege = 0.75F;
		
		this.roodbreak = mod_GirlFront.cfg_vehicle_breakblock;
		
		/*{
			cloud = 2;
			cloud_x[0] = 0.5D;
			cloud_x[1] = -0.5D;
			cloud_y[0] = cloud_y[1] = 1D;
			cloud_z[0] = cloud_z[1] = -3.2D;
		}*/
		
		mob_min_range = 20;
		mob_max_range = 60;
		
		{
			this.ridding_rotation_lock = false;
	        this.rotation_max = 180F;
	        this.rotationp_max = -90F;
	        this.rotationp_min = 90F;
			
			
			this.weapon1true = false;
			this.weapon1key = 0;
			this.ammo1 = 3;
			this.magazine = 30;
			reload_time1 = 100;
			this.w1name = "MachineGun";
			this.w1cycle = 1;
			this.w1barst = 1;
			this.weapon1 = 1;
			{
				this.bullet_type1[0] = 0;
				this.bullet_model1[0] = "gvclib:textures/entity/BulletNormal.obj";
				this.bullet_tex1[0] = "gvclib:textures/entity/BulletNormal.png";
				this.fire_model1[0] = "gvclib:textures/entity/mflash.mqo";
				this.fire_tex1[0] = "gvclib:textures/entity/mflash.png";
				this.fire_time1[0] = 2;
				this.sound_fire1[0] = "gvclib.fire_rifle";
				this.fire_pointx1[0] = 0;
				this.fire_pointy1[0] = 2.6F;
				this.fire_pointz1[0] = 2.3F;
				this.basis_pointx1[0] = 0;
        		this.basis_pointy1[0] = 2.6F;
        		this.basis_pointz1[0] = 1.0F;
				this.fire_yoffset1[0] = 0;
				this.rotationfollowing1[0] = true;
        		this.rotation_player1[0] = true;
        		this.rotationfirepoint1[0] = false;
        		this.rotation_mob_head1[0] = true;
        		this.rotation_firepointbxbz1[0] = true;
        		this.arm_x[0] = 0.0F;
        		this.arm_z[0] = 0.0F;
				this.bullet_damage1[0] = 8;
				this.bullet_speed1[0] = 3.5F;
				this.bullet_bure1[0] = 1.0F;
				this.bullet_expower1[0] = 0F;
				this.bullet_ex1[0] = false;
				this.bullet_kazu1[0] = 1;
				this.bullet_gravity1[0] = 0.029D;
				this.bullet_livingtime1[0] = 80;

			}
			this.mob_min_range = 30;
			this.mob_max_range = 50;
			this.mob_w1range = 30;
			this.mob_w1range_max_y = 20;
			this.mob_w1range_min_y = 5;
		}
		
		
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(300D);
        this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(20D);
    }
    
    
    public boolean spawn = false;
    public void onUpdate() {
		super.onUpdate();
		this.roadattack();
		//this.typeBoat();
		VehicleCNT_Boat.load(this, GVCSoundEvent.sound_car);
		this.ContMobRidding();
		
		
		if(this.getPassengers().size() > 1 && this.getArmID_L() != 1)
        {
        	// int i = this.getPassengers().indexOf(entity);
        	 //if (i == 1) 
        	 if(this.getPassengers().get(1) != null){
     			if (this.getPassengers().get(1) instanceof EntityPlayer) {
     				EntityPlayer entitylivingbase = (EntityPlayer)this.getPassengers().get(1);
     				this.setcanDespawn(1);
     				this.rotation_1  = entitylivingbase.rotationYawHead;
     				this.rotation  = entitylivingbase.rotationYawHead;
     				this.rotationp_1 = entitylivingbase.rotationPitch;
     				Vec3d looked = entitylivingbase.getLookVec();
     				
     				
     			}else
     			if (this.getPassengers().get(1) instanceof EntityDoll) {
     				EntityDoll entitylivingbase = (EntityDoll)this.getPassengers().get(1);
     				if(entitylivingbase.getattacktask()) {
     					
     				}else {
     					entitylivingbase.rotationYawHead = this.rotationYaw;
     				}
     				this.rotation_1  = entitylivingbase.rotationYawHead;
     				this.rotation  = entitylivingbase.rotationYawHead;
     				this.rotationp_1 = entitylivingbase.rotationPitch;
     				Vec3d looked = entitylivingbase.getLookVec();
     				AI_EntityWeapon.getTargetEntity(entitylivingbase, this.mob_w1range, this.mob_w1range_max_y, this.mob_w1range_min_y);
     				if(AI_EntityWeapon.getRange(entitylivingbase, this.mob_w1range, this.mob_w1range_max_y, this.mob_w1range_min_y)){
     					if(cooltime >= ammo1 && this.getRemain_L() > 0){
     						this.counter1 = true;
     			            cooltime = 0;
     					}
     					//if(this.weapon1true) 
     					{
     	    		    	this.weapon1activeMob(looked, entitylivingbase, 0);
     	    		    }
     				}
     			}
     		}
        }
    }
   

   protected void onDeathUpdate() {
		++this.deathTicks;
		int x = this.world.rand.nextInt(4);
		int y = this.world.rand.nextInt(5);
		int z = this.world.rand.nextInt(4);
		if (this.deathTicks == 1 && !this.world.isRemote) {
			GVCExplosionBase.ExplosionKai(this, this, this.posX + 0, this.posY + 0, this.posZ + 0, 3, false,  false);
		}
		if (this.deathTicks == 200 && !this.world.isRemote) {
			this.setDead();
		}
	}
}