import java.awt.Image;
import java.io.IOException;

import javax.imageio.ImageIO;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class BreedingPool extends ObjEX implements java.io.Serializable {
	static final long serialVersionUID = 1L;

	public static List<ObjEX> objEXList = new ArrayList<ObjEX>();
	
	public int type = 0;
	public static final int hitCheckObjType = 1;
	public static final int size = 128;
	private static final int images_num = 1; //このクラスの総使用画像数
	private static final int anime_pattern = 1; //このクラスのアニメーション数
	private static int AnimeImagesNum[] = {1};//アニメごとに何枚使うか
	private static Image[] images = new Image[images_num];
	protected Random rnd = new Random();
	
	private boolean highDensity;
	private boolean rapidGrowth;
	private static int[] value = {1000,4000,4000,10000};
	private static int[] cost = {50,180,180,350};
	
	
	public static void loadImages (ClassLoader loader) throws IOException {
		final String path = "images/";
		images[0] = ImageIO.read(loader.getResourceAsStream(path+"breedingpool.png"));		
		images[0] = images[0].getScaledInstance(size*9/8, size*3/4, Image.SCALE_AREA_AVERAGING);
	}

	public Image getImage(){
		return images[0];
	}

	@Override
	public int getSize() {
		return size;
	}

	@Override
	public int getHitCheckObjType() {
		return hitCheckObjType;
	}

	@Override
	public int objHitProcess( Obj o ) {
		if ( o.objType == Obj.Type.YUKKURI ){
			Body p = (Body)o;
			if ( p.isDead() == false && (int)age % ((highDensity==true)?4:10) == 0 ) {
				int babyType;
				babyType = p.getType();
				if ((babyType == Reimu.type) && rnd.nextBoolean()) {
					babyType = WasaReimu.type;
				}
				else if ((babyType == WasaReimu.type) && rnd.nextBoolean()) {
					babyType = Reimu.type;
				}
				if ((p.isSick() || p.isSick()) || p.isDamaged() || p.isDamaged()) {
					babyType = Tarinai.type;
				}
				p.babyTypes.add(babyType);
				p.hasBaby = true;
				if (rapidGrowth == true){
					p.rapidPregnantPeriod();
				}	
				Cash.addCash(-getCost());
			}
		}
		return 0;
	}

	@Override
	public int getValue() {
		return value[type];
	}

	@Override
	public int getCost() {
		return cost[type];
	}

	@Override
	public void removeListData(){
		objEXList.remove(this);
	}
	
	public BreedingPool(int initX, int initY, Direction initDir) {
		super(initX, initY, ObjEX.Direction.BACK);
		objEXList.add(this);
		switch ( initDir ) {	//方向データを仮利用
		case BACK:
		default:
			highDensity = false;
			rapidGrowth = false;
			break;
		case THISSIDE:
			highDensity = true;
			rapidGrowth = false;
			break;
		case RIGHT:
			highDensity = false;
			rapidGrowth = true;
			break;
		case LEFT:
			highDensity = true;
			rapidGrowth = true;
			break;
	}
		objType = Type.PLATFORM;
		type = initDir.ordinal();
	}
}