package hmggirlfront.entity;

import java.util.List;

import gvclib.entity.EntityB_Cratridge;
import gvclib.entity.living.AI_EntityMoveS_Squad;
import gvclib.entity.living.AI_EntityWeapon;
import gvclib.entity.living.AI_EntityWeapon_new;
import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.item.ItemGunBase;
import gvclib.item.ItemGun_Shield;
import hmggirlfront.mod_GirlFront;
import hmggirlfront.items.ItemDollAttachment;
import hmggirlfront.items.ItemDollGunBase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.Vec3d;

public class DollAI_MasterArm_H {
	public static void load(EntityDoll doll) {
		
		
		
		
		float sp = 0.08F;
		if(!(doll.getHealth() > 0)) {
			sp = 0.02F;
		}
		Vec3d looked = doll.getLookVec();
		
		
		
		//boolean exflag = mod_GirlFront.cfg_exprotion;
		boolean exflag = false;
		boolean tageflag = true;
		if(doll.getRidingEntity() != null && doll.getRidingEntity() instanceof EntityGVCLivingBase) {
			EntityGVCLivingBase vehicle = (EntityGVCLivingBase) doll.getRidingEntity();
			int i = vehicle.getPassengers().indexOf(doll);
			if(vehicle.vehicle_ridding_nofire[i]) {
				tageflag = false;
			}
		}
		
		if(tageflag)DollAI_EntityWeapon.getTargetEntity(doll, 40, 20, 40);
		int max = 15;
		int range = 30;
		int range2 = 30;
		ItemStack itemstack = doll.getHeldItemMainhand();
		if(!itemstack.isEmpty()){
			if (itemstack.getItem() instanceof ItemBow) 
	    	{
				//AI_EntityWeapon.Biped_Gun(doll, itemstack,exflag);
				{
					if (itemstack.getItem() instanceof ItemGunBase && !(itemstack.getItem() instanceof ItemGun_Shield)) 
			    	{
						ItemGunBase gun = (ItemGunBase) itemstack.getItem();
						doll.magazine = gun.getMaxDamage();
						doll.reload_time1 = gun.reloadtime * 2;
			    		String model = gun.bullet_model;
			    		String tex = gun.bullet_tex;
			    		String modelf = gun.bulletf_model;
			    		String texf = gun.bulletf_tex;
			        	{
			        		if(doll.cooltime > doll.rpm && doll.getRemain_L() > 0)
			    			{
			        			doll.counter1 = true;
			        			doll.cooltime = 0;
			    			}
			        		if(doll.counter1 && doll.gun_count1 > gun.mobcycle && doll.getRemain_L() > 0){
			        			SoundEvent sounds = SoundEvents.ENTITY_SKELETON_SHOOT;
			        			if(gun.fires != null) {
			        				sounds = gun.fires;
			        			}else if(gun.sound != null){
			        				sounds = SoundEvent.REGISTRY.getObject(new ResourceLocation(gun.modid, gun.sound));
			        			}
			        			int bulletid = 0;
			        			int powor = doll.power;
			        			float bure = doll.bure;
			        			float exlevel = gun.exlevel;
			        			ItemStack chest = doll.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
	            				if(!chest.isEmpty() &&  chest.getItem() instanceof ItemDollAttachment) {
	            					ItemDollAttachment am = (ItemDollAttachment) chest.getItem();
	            					if(am.bulletid == 1) {
	            						bulletid = 1;
	            					}
	            					exlevel = am.exlevel;
	            				}
			        			/*AI_EntityWeapon.Attacktask(doll, doll, gun.mobbullettype, gun.mobrange, 
			        					model, tex, modelf, texf,2, 
			        					sounds, 
			        					0, 0, 1.5, 1.0,doll.posX, doll.posY, doll.posZ,looked,doll.rotationYawHead, 20, 40,
			        					powor, gun.speed, bure, gun.exlevel, exflag, gun.shotgun_pellet, gun.gra, gun.bullet_time_max, bulletid);*/
	            				AI_EntityWeapon_new we = new AI_EntityWeapon_new(doll, doll);
								we.id = gun.mobbullettype;
								we.model = model;
								we.tex = tex;
								we.modelf = model;
								we.texf = tex;
								we.ftime = 0;
								we.sound = sounds;
								we.f = 0F;
								we.w = 0F;
								we.h = 1.5;
								we.z = 1.0;
								we.bx = 0.0F;
								we.by = 1.5;
								we.bz = 0.0;
								we.follow_rote = true;//向いている方向に
								we.xoffset = 0;
								we.yoffset = gun.fire_roteoffset_y * 2;
								we.px = doll.posX;
								we.py = doll.posY;
								we.pz = doll.posZ;
								we.lock = looked;
								we.rote = doll.rotationYawHead;
								we.maxy = 20;
								we.miny = 40;
								
								we.power = powor;
								we.damegetime = true;
								we.speed = gun.speed;
								we.bure = bure;
								we.ex = exlevel;
								we.extrue = exflag;
								we.kazu = doll.pellet;
								we.gra = gun.gra;
								we.maxtime = gun.bullet_time_max;
								we.dameid = bulletid;
								we.Attacktask(doll, doll, gun.mobrange);
			    				doll.gun_count1 = 0;
			    				if(doll.firetrue){
			    					if(!gun.bullet_c){
			    						EntityB_Cratridge var81 = new EntityB_Cratridge(doll.world, (EntityLivingBase) doll);
			    						var81.setModel(gun.cartridge_model);
			    						var81.setTex(gun.cartridge_tex);
			    						var81.setHeadingFromThrower(doll, doll.rotationPitch, doll.rotationYaw + 110, 0.0F,0.2F,5);
			    						if (!doll.world.isRemote) {
			    							doll.world.spawnEntity(var81);
			    						}
			    					}
			    					doll.setRemain_L(doll.getRemain_L() - 1);
			    				}
			    				++doll.countlimit1;
			    			}
			    			if(doll.countlimit1 >= gun.mobbarst){
			    				doll.gun_count1 = 0;
			    				doll.counter1 = false;
			    				doll.countlimit1 = 0;
			    			}
			        	}
			    		//max = gun.mobmax;
			    		//range = gun.mobrange;
			    	}
				}
				if (itemstack.getItem() instanceof ItemGunBase) 
		    	{
					ItemGunBase gun = (ItemGunBase) itemstack.getItem();
					max = gun.mobmax;
		    		range = (int) (gun.mobrange *0.75D);
		    		range2 = gun.mobrange;
		    		sp = (float) (sp * gun.motion);
		    		doll.sound = gun.soundre;
		    		doll.modid = gun.modid;
		    	}
	    	}
		}
		//AI_EntityMoveS_Squad.newmove(doll, 0, sp, 0, max, range, range2, 16);
		DollAI_EntityMoveS_Squad.newmove(doll, 0, sp, 0, max, range, range2, 16);
	}
}
