//　敵よりちょっと上で、弾より下のレイヤー
let Item_layer	= 49;

//　スピード最高値
let max_sp		= 3;

//　魔理沙A、超人状態のアイテム落下減速
let spd			= 0.8;

function LifeFragment(x,y){
	let obj		= CreateItemU2(1,x,y,x,y-32,1000);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,2,max_sp);
	return obj;
}

function SpellFragment(x,y){
	let obj		= CreateItemU2(7,x,y,x,y-32,1000);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,2,max_sp);
	return obj;
}

function ExtendSpell(x,y){
	let obj		= CreateItemU2(12,x,y,x,y-32,10000);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,1,max_sp);
	return obj;
}

function ExtendLife(x,y){
	let obj		= CreateItemU2(13,x,y,x,y-32,10000);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,1,max_sp);
	return obj;
}

function SmallPower(x,y){
	let obj		= CreateItemU2(9,x,y,x,y-32,0);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,1,max_sp);
	return obj;
}

function BigPower(x,y){
	let obj		= CreateItemU2(11,x,y,x,y-32,0);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,1,max_sp);
	return obj;
}

function FullPower(x,y){
	let obj		= CreateItemU2(14,x,y,x,y-32,10000);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,1,max_sp);
	return obj;
}

function AddPoints(x,y){
	let obj			= CreateItemU2(10, x, y, x, y-32, 0 );
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,1,max_sp);
	return obj;
}

function SkillUp(x,y){
	let obj		= CreateItemU2(30,x,y,x,y-32,0);
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ItemMain(obj,1.6,1.6);
	return obj;
}

//　動き
task ItemMain(obj,sca_plus,speed){
	let P2Aflgc	= 0;
	let sca1	= 0;
	let scaA	= 0;
	
	while( sca1<1 && !Obj_IsDeleted(obj) ){
		if(sca1<1){scaA+=5;}
		sca1=1*sin(scaA);
		ObjRender_SetScaleXYZ(obj,sca1*sca_plus,sca1*sca_plus,0);
		ObjRender_SetAngleXYZ(obj,0,0,-sca1*720);
		yield;
	}
	ObjMove_SetAngle(obj,90);
	ObjMove_SetAcceleration(obj,0.01);
	ObjMove_SetMaxSpeed(obj,speed);	
	while( !Obj_IsDeleted(obj) ){
		let ix		= ObjMove_GetX(obj);
		let iy		= ObjMove_GetY(obj);
		let width	= GetAreaCommonData("Pepper","ItemGetWidth",0);
		let AIG		= GetCommonData("AutoItemGet", false );
		
		
		if(ix < MinX-64 && ix > MaxX+64 && iy < MinY-64 && iy > MaxY+64){
			break;
		}
		
		if(ix<GetPlayerX+(64+width) && ix>GetPlayerX-(64+width)
		&& iy<GetPlayerY+(64+width) && iy>GetPlayerY-(64+width) && GetPlayerState==STATE_NORMAL){
			ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
			break;
		}
		
		let now_gauge	= GetAreaCommonData("ST_System","Gauge",0);
		if(GetPlayerY<CenY-128 && now_gauge>0 && GetPlayerState==STATE_NORMAL){
			ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
			break;
		}
		
		let GetItemflg	= GetAreaCommonData("Bomb","Item",true);
		if(GetItemflg && GetPlayerID=="MPP_PLAYER01B"){
			Dyson(obj);
			break;
		}
		
		if( GetPlayerID == "MPP_PLAYER02A" && AIG ){
			if( IsPlayerSpellActive ){
				ObjMove_SetAngle(obj,90);
				ObjMove_SetSpeed(obj,spd);
				P2Aflgc++;
			}
			else if( P2Aflgc > 0 ){
				ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
				P2Aflgc = 0;
			}
		}
		
		yield;
	}
}

//----------------------------------------------------------------------------------------//
//--------------------------------ここから特殊挙動アイテム--------------------------------//

task ChargeFragment(x,y,speed,angle,acc,acp,mx,kill){
	let obj		= CreateItemU1(15,x,y,1000);
	let ix		= ObjMove_GetX(obj);
	let iy		= ObjMove_GetY(obj);
	let P2Aflgc	= 0;
	let sca1	= 0;
	let scaA	= 0;
	let count	= 0;
	let flg		= 0;
	let sca		= 1;
	
	ObjMove_AddPatternA2(obj,0,speed,angle,acc,acp,mx);
	ObjItem_SetRenderScoreEnable(obj,false);
	
	while( sca1<1 && !Obj_IsDeleted(obj) ){
		if(sca1<1){scaA+=5;}
		sca1=1*sin(scaA);
		ObjRender_SetScaleXYZ(obj,sca1,sca1,0);
		ObjRender_SetAngleXYZ(obj,0,0,-sca1*720);
		yield;
	}
	sca1=0;
	scaA=0;
	while(!Obj_IsDeleted(obj)){
		ix			= ObjMove_GetX(obj);
		iy			= ObjMove_GetY(obj);
		let AIG		= GetCommonData("AutoItemGet", false );
		
		if(ix < MinX-64 && ix > MaxX+64 && iy < MinY-64 && iy > MaxY+64){
			break;
		}
		
		count++;
		if(kill<count||flg!=0){
			if(sca1<sca){scaA+=5;}
			sca1=sca*sin(scaA);
			if(sca1>=sca){break;}
		}
		
		ObjRender_SetScaleXYZ(obj,sca-sca1,sca-sca1,0);
		ObjRender_SetAngleXYZ(obj,0,0,sca1*720);
		
		let width	= GetAreaCommonData("Pepper","ItemGetWidth",0);
		
		if(ix<GetPlayerX+(64+width) && ix>GetPlayerX-(64+width)
		&& iy<GetPlayerY+(64+width) && iy>GetPlayerY-(64+width) && GetPlayerState==STATE_NORMAL){
			ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
			break;
		}
		
		let now_gauge	= GetAreaCommonData("ST_System","Gauge",0);
		if(GetPlayerY<CenY-128 && now_gauge>0 && GetPlayerState==STATE_NORMAL){
			ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
			break;
		}
		
		let GetItemflg	= GetAreaCommonData("Bomb","Item",true);
		if(GetItemflg && GetPlayerID=="MPP_PLAYER01B"){
			Dyson(obj);
			break;
		}
		
		if( GetPlayerID == "MPP_PLAYER02A" && AIG ){
			if( IsPlayerSpellActive ){
				ObjMove_SetAngle(obj,90);
				ObjMove_SetSpeed(obj,spd);
				P2Aflgc++;
			}
			else if( P2Aflgc > 0 ){
				ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
				P2Aflgc = 0;
			}
		}
		
		yield;
	}
}

task BigPower2(x,y,ang){
	let obj		= CreateItemU2(11,x,y,x,y-32,0);
	let P2Aflgc	= 0;
	let sca1	= 0;
	let scaA	= 0;
	let count	= 0;
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	ObjMove_SetAngle(obj,ang);
	ObjMove_SetSpeed(obj,4);
	ObjMove_SetAcceleration(obj,-0.05);
	ObjMove_SetMaxSpeed(obj,10);
	
	while( sca1<1 || ObjMove_GetSpeed(obj)>0 ){
		if(sca1<1){scaA+=5;}
		sca1=1*sin(scaA);
		ObjRender_SetScaleXYZ(obj,sca1,sca1,0);
		ObjRender_SetAngleXYZ(obj,0,0,-sca1*720);
		yield;
	}
	ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_DOWN);
	while(!Obj_IsDeleted(obj)){
		let ix		= ObjMove_GetX(obj);
		let iy		= ObjMove_GetY(obj);
		let width	= GetAreaCommonData("Pepper","ItemGetWidth",0);
		let AIG		= GetCommonData("AutoItemGet", false );
		
		if(ix < MinX-64 && ix > MaxX+64 && iy < MinY-64 && iy > MaxY+64){
			break;
		}
		
		if(ix<GetPlayerX+(64+width) && ix>GetPlayerX-(64+width)
		&& iy<GetPlayerY+(64+width) && iy>GetPlayerY-(64+width) && GetPlayerState==STATE_NORMAL){
			ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
			break;
		}
		
		let now_gauge	= GetAreaCommonData("ST_System","Gauge",0);
		if(GetPlayerY<CenY-128 && now_gauge>0 && GetPlayerState==STATE_NORMAL){
			ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
			break;
		}
		
		let GetItemflg	= GetAreaCommonData("Bomb","Item",true);
		if(GetItemflg && GetPlayerID=="MPP_PLAYER01B"){
			Dyson(obj);
			break;
		}
		
		if( GetPlayerID == "MPP_PLAYER02A" && AIG ){
			if( IsPlayerSpellActive ){
				ObjMove_SetAngle(obj,90);
				ObjMove_SetSpeed(obj,spd);
				P2Aflgc++;
			}
			else if( P2Aflgc > 0 ){
				ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
				P2Aflgc = 0;
			}
		}
		
		yield;
	}
}

task SkillUpSmall(x,y,wait){
	let obj		= CreateItemU2(23,x,y,x,y-32,0);
	let sca		= 1.2;
	let sca1	= 0;
	let scaA	= 0;
	let dis		= 64;
	
	ObjItem_SetRenderScoreEnable(obj,false);
	
	while( sca1<1 && !Obj_IsDeleted(obj) ){
		if(sca1<1){scaA+=5;}
		sca1=1*sin(scaA);
		ObjRender_SetScaleXYZ(obj,sca1,sca1,0);
		
		yield;
	}
	loop(wait){yield;}
	if(GetPlayerState==STATE_NORMAL){
		ObjItem_SetDefinedMovePatternA1(obj,ITEM_MOVE_TOPLAYER);
	}
}

task Dyson(obj){
	ObjMove_SetSpeed(obj,0);
	ObjMove_SetAcceleration(obj,0.06);
	ObjMove_SetMaxSpeed(obj,10);
	while(!Obj_IsDeleted(obj)){
		ObjMove_SetAngle(obj,GetAngleToPlayer(obj));
		yield;
	}
}