 
task Shot//メインショットのタスク。
{
let ShotSpeed=18;

let HiDamage=2.8;
let LowDamage=2.8;

loop
{
		if(GetKeyState(VK_SHOT)==KEY_PUSH)
		{
			ShotCountIncrease=9;
		}
		if(ShotCountIncrease>0)
		{
			ShotCountIncrease-=1;
		}
		if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD))
		{
			OnShot=1;
		}
		else
		{
			OnShot=0;
			RockOnAvailableCounter=0;
		}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			OnSlow=1;
		}
		else
		{
			OnSlow=0;
			RockOnAvailableCounter=0;
		}
		if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && shotCount==-1 && !OnMissed && GetCommonDataDefault("TitleMenu",false)==false && MissTime==0)
		{
			shotCount = 0;
		}
			if(shotCount%3 == 0)
			{
				if(!OnMissed  && GetCommonDataDefault("TitleMenu",false)==false)
				{
					PlaySE(SE[2]);
				}
				if(BurstLevel==0)
				{
					if(OnSlow)
					{
					MarisaMainShot(GetPlayerX+10,GetPlayerY+5,ShotSpeed,270,LowDamage,0);
					MarisaMainShot(GetPlayerX-10,GetPlayerY+5,ShotSpeed,270,LowDamage,0);
					}
					else
					{
					MarisaMainShot(GetPlayerX+10,GetPlayerY+5,ShotSpeed,270,HiDamage,0);
					MarisaMainShot(GetPlayerX-10,GetPlayerY+5,ShotSpeed,270,HiDamage,0);
					}
				}

				if(BurstLevel==3)
				{
					if(OnSlow)
					{
					MarisaMainShot(GetPlayerX+10,GetPlayerY+5,ShotSpeed,270,LowDamage*BL3,3);
					MarisaMainShot(GetPlayerX-10,GetPlayerY+5,ShotSpeed,270,LowDamage*BL3,3);
					}
					else
					{
					MarisaMainShot(GetPlayerX+10,GetPlayerY+5,ShotSpeed,270,HiDamage*BL3,3);
					MarisaMainShot(GetPlayerX-10,GetPlayerY+5,ShotSpeed,270,HiDamage*BL3,3);
					}
				}
			}
		if(shotCount >= 0)
		{
			shotCount++;
		}

		if(shotCount == 9)
		{
			if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD || ShotCountIncrease>0) && !OnMissed && GetCommonDataDefault("TitleMenu",false)==false)
			{
				shotCount = 0;
			}
			else
			{
				shotCount=-1;
			}
		}
yield;
}
}

task SubShot//オプションからのショット。高速、低速で変化する。
{
let a=7.5;

let ShotSpeed=18;

let HiDamage=0.800;
let LowDamage=0.800;

let AdjustX=0;
let AdjustY=-5;
let Grad=10;
let ShotAngle=[267.5,272.5,265,275];

let ShotAngleAdjust=0;
loop
{
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			if(shotCount%3 == 0)
			{
				//
				if(BurstLevel==0)
				{
					ascent(i in 0..4)
					{
						if(TargetX[i]==-1)
						{
							MarisaShot(opX[i]-AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],HiDamage,0,0);
							MarisaShot(opX[i]+AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],HiDamage,0,0);
						}
						else
						{
						ShotAngleAdjust=atan2(TargetY[i]-GetPlayerY,TargetX[i]-GetPlayerX);
						MarisaShot(opX[i]-AdjustX,opY[i]+AdjustY,ShotSpeed,atan2(TargetY[i]+50*sin(ShotAngleAdjust)-opY[i],TargetX[i]+50*cos(ShotAngleAdjust)-opX[i]),LowDamage,0,0);
						MarisaShot(opX[i]+AdjustX,opY[i]+AdjustY,ShotSpeed,atan2(TargetY[i]+50*sin(ShotAngleAdjust)-opY[i],TargetX[i]+50*cos(ShotAngleAdjust)-opX[i]),LowDamage,0,0);	
						}
					}
				}

				if(BurstLevel==3)
				{
					ascent(i in 0..4)
					{
						if(TargetX[i]==-1)
						{
							MarisaShot(opX[i]-AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],LowDamage*BL3,3,0);
							MarisaShot(opX[i]+AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],LowDamage*BL3,3,0);
						}
						else
						{
						ShotAngleAdjust=atan2(TargetY[i]-GetPlayerY,TargetX[i]-GetPlayerX);
						MarisaShot(opX[i]-AdjustX,opY[i]+AdjustY,ShotSpeed,atan2(TargetY[i]+50*sin(ShotAngleAdjust)-opY[i],TargetX[i]+50*cos(ShotAngleAdjust)-opX[i]),LowDamage*BL3,3,0);
						MarisaShot(opX[i]+AdjustX,opY[i]+AdjustY,ShotSpeed,atan2(TargetY[i]+50*sin(ShotAngleAdjust)-opY[i],TargetX[i]+50*cos(ShotAngleAdjust)-opX[i]),LowDamage*BL3,3,0);
						}
					}
				}
			}
		}
		else
		{
			if(shotCount%3 == 0)
			{
				if(BurstLevel==0)
				{
					ascent(i in 0..4)
					{
						MarisaShot(opX[i]-AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],HiDamage,0,0);
						MarisaShot(opX[i]+AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],HiDamage,0,0);
					}
				}

				if(BurstLevel==3)
				{
					ascent(i in 0..4)
					{
						MarisaShot(opX[i]-AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],HiDamage*BL3,3,0);
						MarisaShot(opX[i]+AdjustX,opY[i]+AdjustY,ShotSpeed,ShotAngle[i],HiDamage*BL3,3,0);
					}
				}
			}
		}
yield;
}
}

task TargetDecidion(x,y)
{
	if(GetCommonDataDefault("DisableSearch",false)){return;}
	let ShotDistance=((GetPlayerX-x)^2+(GetPlayerY-y)^2)^0.5;
	RockOnAvailableCounter+=4;

	if(ShotDistance<=32)
	{
		RockOnAvailableCounter+=16;
	}
	else if(ShotDistance<=256)
	{
		RockOnAvailableCounter+=16*(256-ShotDistance)/(256-32);
	}

	if(RockOnAvailableCounter<80){return;}
	RockOnAvailableCounter-=80;

	let MinDistance=1000^2;
	let Distance=0;
	let dx=0;
	let dy=0;
	let TargetID=0;
	ascent(enemy in EnumEnemyBegin..EnumEnemyEnd)
	{
		let enemyID = EnumEnemyGetID(enemy);
		let enemyX=GetEnemyInfo(enemyID,ENEMY_X);
		let enemyY=GetEnemyInfo(enemyID,ENEMY_Y);
		let enemyLife=GetEnemyInfo(enemyID,ENEMY_LIFE);
		if(enemyX>=GetClipMinX-96 && enemyX<=GetClipMaxX+96 && enemyY>=GetClipMinY-96 && enemyY<=GetClipMaxY+32 && enemyLife<25000)
		{
			Distance=(x-enemyX)^2+(y-enemyY)^2;
			if(Distance<MinDistance)
			{
				MinDistance=Distance;
				TargetID=enemyID;
			}
		}
	}
	
	EnemyChaser(TargetID);
}

task EnemyChaser(enemyID){

	let OptionRockOn=false;
	ascent(i in 0..4)
	{
		if(TargetX[i]==-1)
		{
		PlaySE(SE[6]);
		RockON[i]=true;
		while(GetEnemyInfoDefault(enemyID, ENEMY_LIFE,-1)>0 && OnShot && OnSlow && !OnMissed && GetCommonDataDefault("DisableSearch",false)==false)
		{
			TargetX[i]=GetEnemyInfoDefault(enemyID, ENEMY_X,0);
			TargetY[i]=GetEnemyInfoDefault(enemyID, ENEMY_Y,0);
			OptionRockOn=true;
			yield;
		}
		TargetX[i]=-1;
		TargetY[i]=-1;
		RockON[i]=false;
		if(OptionRockOn){return;}
		}
	}

	}

task MarisaMainShot(let x,let y,let speed,let angle,let damage,let Type)
{
	if(RockON[0] && RockON[1] && RockON[2] && RockON[3])
	{
		damage+=0.3;
	}

	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj,x,y);
	Obj_SetSpeed(obj,speed);
	Obj_SetAngle(obj,angle);
	ObjShot_SetDamage(obj,damage);
	ObjShot_SetPenetration(obj,1);
	ObjShot_SetGraphic(obj,Type+1);
	Obj_SetAlpha(obj,100);

	let R;
	let G;
	let B;

	R=127;G=255;B=127;

	if(Type==3)
	{
	R=ColorRed;G=ColorGreen;B=ColorBlue;
	DummyMainShot(obj,x,y,speed,angle,R,G,B);
	Obj_SetAlpha(obj,0);
	}

	while(!Obj_BeDeleted(obj))
	{
		if(Obj_IsIntersected(obj))
		{
		MainShotHit(Obj_GetX(obj),Obj_GetY(obj));

		if(OnSlow)
		{
		if(!RockON[0] || !RockON[1] || !RockON[2] || !RockON[3])
		{
		TargetDecidion(Obj_GetX(obj),Obj_GetY(obj));
		}
		}

		if(GetCommonDataDefault("LightMode_ShotEffect",0)==0)
		{
		ShotHit(Obj_GetX(obj)+speed/2*cos(angle),Obj_GetY(obj)+speed/2*sin(angle),angle,2, speed / 6,R,G,B);
		ShotHit(Obj_GetX(obj)+speed*3/2*cos(angle),Obj_GetY(obj)+speed*3/2*sin(angle),angle,2, speed*3 / 6,R,G,B);
		}
		}
		yield;
	}
}


task MarisaShot(let x,let y,let speed,let angle,let damage,let Type,let OpNum)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj,x,y);
	Obj_SetSpeed(obj,speed);
	Obj_SetAngle(obj,angle);
	ObjShot_SetDamage(obj,damage);
	ObjShot_SetPenetration(obj,1);
	ObjShot_SetGraphic(obj,Type+1);
	Obj_SetAlpha(obj,80);
	Obj_SetAutoDelete(obj,false);

	let R;
	let G;
	let B;

	R=127;G=255;B=127;

	if(Type==3)
	{
	R=ColorRed;G=ColorGreen;B=ColorBlue;
	DummyShot(obj,x,y,speed,angle,R,G,B,OpNum);
	Obj_SetAlpha(obj,0);
	}

	if(OpNum==5)
	{
		Obj_SetAlpha(obj,0);
		return;
	}

	loop(60)
	{
		if(Obj_IsIntersected(obj))
		{
			if(GetCommonDataDefault("LightMode_ShotEffect",0)==0)
			{
			ShotHit(Obj_GetX(obj)+speed/2*cos(angle),Obj_GetY(obj)+speed/2*sin(angle),angle,2, speed / 6,R,G,B);
			Obj_Delete(obj);
			}
		}
		if(Obj_BeDeleted(obj)){break;}
		yield;
	}
	Obj_Delete(obj);
}

task DummyMainShot(obj,x,y,speed,angle,R,G,B)
{
	let objE = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(objE, imgShot3);
	ObjEffect_SetPrimitiveType(objE, PRIMITIVE_TRIANGLEFAN);
	Obj_SetPosition(objE,x,y);
	Obj_SetSpeed(objE,speed);
	Obj_SetAngle(objE,angle);
	ObjEffect_CreateVertex(objE, 4);
	ObjEffect_SetRenderState(objE,ADD);
	ObjEffect_SetLayer(objE,2);

/*	
	ObjEffect_SetVertexXY(objE, 0, -4, -32);
	ObjEffect_SetVertexXY(objE, 1, 4, -32);
	ObjEffect_SetVertexXY(objE, 2, 4, 32);
	ObjEffect_SetVertexXY(objE, 3, -4, 32);

	ObjEffect_SetVertexUV(objE, 0, 20, 0);
	ObjEffect_SetVertexUV(objE, 1, 28, 0);
	ObjEffect_SetVertexUV(objE, 2, 28, 64);
	ObjEffect_SetVertexUV(objE, 3, 20, 64);
*/
	ObjEffect_SetVertexXY(objE, 0, -16, -32);
	ObjEffect_SetVertexXY(objE, 1, 16, -32);
	ObjEffect_SetVertexXY(objE, 2, 16, 32);
	ObjEffect_SetVertexXY(objE, 3, -16, 32);

	ObjEffect_SetVertexUV(objE, 0, 32, 0);
	ObjEffect_SetVertexUV(objE, 1, 64, 0);
	ObjEffect_SetVertexUV(objE, 2, 64, 64);
	ObjEffect_SetVertexUV(objE, 3, 32, 64);

	//ObjEffect_SetScale(objE,1.1*2.5,0.8*2.5);
	ObjEffect_SetScale(objE,2.0,2.0);
	ObjEffect_SetAngle(objE,0,0,angle+90);

	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(objE, i,50, R, G, B);
	}
	while(!Obj_BeDeleted(obj))
	{
		yield;
	}
	Obj_Delete(objE);
}

task DummyShot(obj,x,y,speed,angle,R,G,B,OpNum)
{
	let objE = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(objE, imgShot3);
	ObjEffect_SetPrimitiveType(objE, PRIMITIVE_TRIANGLEFAN);
	Obj_SetPosition(objE,x,y);
	Obj_SetSpeed(objE,speed);
	Obj_SetAngle(objE,angle);
	ObjEffect_CreateVertex(objE, 4);
	ObjEffect_SetRenderState(objE,ADD);
	ObjEffect_SetLayer(objE,2);

/*	
	ObjEffect_SetVertexXY(objE, 0, -4, -32);
	ObjEffect_SetVertexXY(objE, 1, 4, -32);
	ObjEffect_SetVertexXY(objE, 2, 4, 32);
	ObjEffect_SetVertexXY(objE, 3, -4, 32);

	ObjEffect_SetVertexUV(objE, 0, 20, 0);
	ObjEffect_SetVertexUV(objE, 1, 28, 0);
	ObjEffect_SetVertexUV(objE, 2, 28, 64);
	ObjEffect_SetVertexUV(objE, 3, 20, 64);
*/
	ObjEffect_SetVertexXY(objE, 0, -16, -32);
	ObjEffect_SetVertexXY(objE, 1, 16, -32);
	ObjEffect_SetVertexXY(objE, 2, 16, 32);
	ObjEffect_SetVertexXY(objE, 3, -16, 32);

	ObjEffect_SetVertexUV(objE, 0, 32, 0);
	ObjEffect_SetVertexUV(objE, 1, 64, 0);
	ObjEffect_SetVertexUV(objE, 2, 64, 64);
	ObjEffect_SetVertexUV(objE, 3, 32, 64);

	//ObjEffect_SetScale(objE,1.1*2.5,0.8*2.5);
	ObjEffect_SetScale(objE,2.0,2.0);
	ObjEffect_SetAngle(objE,0,0,angle+90);

	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(objE, i,50, R, G, B);
	}

	while(!Obj_BeDeleted(obj))
	{
		yield;
	}

	Obj_Delete(objE);

}