package hmggirlfront.entity;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;

public class DollAI_Reload {
	public static void load(EntityDoll doll) {
		if(doll.getRemain_L() <= 0 && doll.getRemain_S() > 0){
			++doll.reload1;
			if(doll.reload1 == doll.reload_time1/2){
				if(doll.modid != null && doll.sound != null)doll.playSound(SoundEvent.REGISTRY.getObject(new ResourceLocation(doll.modid, doll.sound)), 1.0F, 1.0F);
			}
			if(doll.reload1 >= doll.reload_time1){
				if(doll.getRemain_S() > doll.magazine) {
					doll.setRemain_L(doll.magazine);
					doll.setRemain_S(doll.getRemain_S() - doll.magazine);
				}else {
					doll.setRemain_L(doll.getRemain_S());
					doll.setRemain_S(0);
				}
				
				doll.reload1 = 0;
			}
		}
		if(doll.getRemain_R() <= 0){
			++doll.reload2;
			int time = 300 - doll.getArmID_L() * 10;
			if(time < 20) {
				time = 20;
			}
			if(doll.reload2 >= 200){
				doll.setRemain_R(1);
				doll.reload2 = 0;
				//doll.playSound(SoundEvent.REGISTRY.getObject(new ResourceLocation(doll.modid, doll.sound)), 1.0F, 1.0F);
			}
		}
	}
	
	public static void load(EntityDoll_Dummy doll) {
		if(doll.getRemain_L() <= 0 && doll.getRemain_S() > 0){
			++doll.reload1;
			if(doll.reload1 == doll.reload_time1/2){
				if(doll.modid != null && doll.sound != null)doll.playSound(SoundEvent.REGISTRY.getObject(new ResourceLocation(doll.modid, doll.sound)), 1.0F, 1.0F);
			}
			if(doll.reload1 >= doll.reload_time1){
				if(doll.getRemain_S() > doll.magazine) {
					doll.setRemain_L(doll.magazine);
					doll.setRemain_S(doll.getRemain_S() - doll.magazine);
				}else {
					doll.setRemain_L(doll.getRemain_S());
					doll.setRemain_S(0);
				}
				
				doll.reload1 = 0;
			}
		}
		if(doll.getRemain_R() <= 0){
			++doll.reload2;
			int time = 300 - doll.getArmID_L() * 10;
			if(time < 20) {
				time = 20;
			}
			if(doll.reload2 >= 200){
				doll.setRemain_R(1);
				doll.reload2 = 0;
				//doll.playSound(SoundEvent.REGISTRY.getObject(new ResourceLocation(doll.modid, doll.sound)), 1.0F, 1.0F);
			}
		}
	}
	
	public static void load_dummy(EntityDoll_Dummy doll) {
		if(doll.getRemain_L() <= 0)
		{
			++doll.reload1;
			if(doll.reload1 == doll.reload_time1/2){
				if(doll.modid != null && doll.sound != null)doll.playSound(SoundEvent.REGISTRY.getObject(new ResourceLocation(doll.modid, doll.sound)), 1.0F, 1.0F);
			}
			if(doll.reload1 >= doll.reload_time1){
				{
					doll.setRemain_L(doll.magazine);
				}
				doll.reload1 = 0;
			}
		}
		if(doll.getRemain_R() <= 0){
			++doll.reload2;
			int time = 300 - doll.getArmID_L() * 10;
			if(time < 20) {
				time = 20;
			}
			if(doll.reload2 >= 200){
				doll.setRemain_R(1);
				doll.reload2 = 0;
				//doll.playSound(SoundEvent.REGISTRY.getObject(new ResourceLocation(doll.modid, doll.sound)), 1.0F, 1.0F);
			}
		}
	}
}
