package hmggirlfront.entity.npc;

import hmggirlfront.items.ItemDollAttachment;
import hmggirlfront.items.ItemDollGunBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;

public class NPCDollAI_Level {
	public static void load(EntityNPC_Doll doll) {
		
		
		ItemStack main = doll.getHeldItemMainhand();
		if(!main.isEmpty()){
			doll.mainitem = main;
			if (main.getItem() instanceof ItemDollGunBase) 
	    	{
				ItemDollGunBase gun = (ItemDollGunBase) main.getItem();
				doll.bullet_type = gun.magazine;
				doll.evasion = gun.doll_evasion + doll.getArmID_L() * 2;
				doll.power = gun.powor;
				doll.bure = gun.bure;
				int rp = gun.mobammo - (int)(doll.getArmID_L()/2);
				if (rp <= gun.mobcycle * gun.mobbarst) {
					doll.rpm = gun.mobcycle * gun.mobbarst + 1;
				} else {
					doll.rpm = rp;
				}
				doll.setArmID_A(gun.doll_hp);
				doll.doll_size = gun.doll_size;
				doll.doll_skill = gun.doll_skill;
				doll.doll_autoskill = gun.doll_autoskill;
	    	}
		}
		doll.evasion_base = doll.evasion;
		doll.power_base = doll.power;
		doll.bure_base = doll.bure;
		doll.rpm_base = doll.rpm;
		
		ItemStack head = doll.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
		if(!head.isEmpty() &&  head.getItem() instanceof ItemDollAttachment) {
			ItemDollAttachment am = (ItemDollAttachment) head.getItem();
			if(am.id == 101)
			{
				
			}
		}
		ItemStack chest = doll.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
		if(!chest.isEmpty() &&  chest.getItem() instanceof ItemDollAttachment) {
			ItemDollAttachment am = (ItemDollAttachment) chest.getItem();
			doll.power = (int) (doll.power *  am.power);
			doll.bure = doll.bure * am.bure;
			if(am.bulletid == 1) {
				doll.bullet_type_am = "+AP";
			}
		}
		
		ItemStack legs = doll.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
		if(!legs.isEmpty() &&  legs.getItem() instanceof ItemDollAttachment) {
			ItemDollAttachment am = (ItemDollAttachment) legs.getItem();
			if(am.id == 80)
			{
				doll.evasion = doll.evasion + am.doll_evasion;
				doll.bure = doll.bure * am.doll_bure;
			}
		}
		
		if(doll.evasion >= 90) {
			doll.evasion = 90;
		}
		
		
		if(doll.getHealth() < doll.getMaxHealth()) {
			if(doll.getRemain_A() > 0) {
				doll.setHealth(doll.getHealth() + 1);
				doll.setRemain_A(doll.getRemain_A() - 1);
				doll.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F);
			}
		}
		
		//レベル1の時の処理。なおワールドリログ時にも呼ばれる
		{
			if(doll.getArmID_L() == 1 && doll.reset) {
				doll.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D + doll.getArmID_L() + doll.getArmID_A());
				doll.setHealth((float) (20D + doll.getArmID_L() + doll.getArmID_A()));
				doll.reset = false;
			}
		}
	}
}
