import java.awt.Image;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

public class OrangePool 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];
	private boolean rescue;
	private static int[] value = {500,10000};
	private static int[] cost = {10,200};
	
	public static void loadImages (ClassLoader loader) throws IOException {
		final String path = "images/";
		images[0] = ImageIO.read(loader.getResourceAsStream(path+"orangepool.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 checkHitObj( Obj o ) {
		int objX = o.getX();
		int objY = o.getY();
		int objZ = o.getZ();
		int platformSize = getSize()/2;
		int platformX = getX();
		int platformY = getY();
		int platformZ = getZ();
		int offsetX = (Body.MAXSIZE - getSize())*7/32-28;
		int offsetY = (Body.MAXSIZE - getSize())*6/16-40;
			if ( objZ == 0 ){	//空中の物は移動させない
				if ((platformX + offsetX)<=(objX) && (objX)<=(platformX + offsetX + platformSize)){	//X軸比較
					if ((platformY + offsetY)<=(objY) && (objY)<=(platformY + offsetY + platformSize)){	//Y軸比較
						objHitProcess( o );
						return 1;
					}
				}
			}
		return 0;
	}

	@Override	
	public int objHitProcess( Obj o ) {
		if ( o.objType == Obj.Type.YUKKURI ){
			Body b = (Body)o;
			b.giveJuice();
			if ( b.isDirty() == true ) {
				b.dirty = false;
			}
			if ( rescue ) {
				if ( b.isDead() && !b.isCrashed() ){
					b.revival();
				}
				b.setCantDie();
			}
			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 OrangePool(int initX, int initY, Direction initDir) {
		super(initX, initY, ObjEX.Direction.BACK);
		objEXList.add(this);
		switch ( initDir ) {	//方向データを仮利用
		case BACK:
		default:
			rescue = false;
			type = 0;
			break;
		case THISSIDE:
			rescue = true;
			type = 1;
			break;
		}
		objType = Type.PLATFORM;
	}
}