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

let Damage=2.0;

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) && shotCount==-1 && !OnMissed && GetCommonDataDefault("TitleMenu",false)==false && GetCommonDataDefault("OnMS",false)==false && MissTime==0)
		{
			shotCount = 0;
		}
			if(shotCount%3 == 0)
			{
				if(!OnMissed  && GetCommonDataDefault("TitleMenu",false)==false)
				{
					PlaySE(SE[2]);
				}
				if(BurstLevel==0)
				{
					MarisaMainShot(GetPlayerX+10,GetPlayerY+5,ShotSpeed,270,Damage,4);
					MarisaMainShot(GetPlayerX-10,GetPlayerY+5,ShotSpeed,270,Damage,4);
				}

				if(BurstLevel==3)
				{
					MarisaMainShot(GetPlayerX+10,GetPlayerY+5,ShotSpeed,270,Damage*BL3,3);
					MarisaMainShot(GetPlayerX-10,GetPlayerY+5,ShotSpeed,270,Damage*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 && GetCommonDataDefault("OnMS",false)==false)
			{
				shotCount = 0;
			}
			else
			{
				shotCount=-1;
			}
		}
yield;
}
}

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

let ShotSpeed=18;

let HiDamage=0.800;
let LowDamage=1.800;

let AdjustX=0;
let AdjustY=-5;
let Grad=10;

SearchShot;
loop
{
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			if(shotCount%3 == 0)
			{
				if(BurstLevel==0)
				{
				MarisaShot(opX[0]-AdjustX,opY[0]+AdjustY,ShotSpeed,270,LowDamage,4,0);
				MarisaShot(opX[1]-AdjustX,opY[1]+AdjustY,ShotSpeed,260,LowDamage,4,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,280,LowDamage,4,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage,4,3);

				}

				if(BurstLevel==3)
				{
				MarisaShot(opX[0]-AdjustX,opY[0]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,0);
				MarisaShot(opX[1]-AdjustX,opY[1]+AdjustY,ShotSpeed,260,LowDamage*BL3,3,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,280,LowDamage*BL3,3,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,3);

				}
			}
		}
		else
		{
			if(shotCount%3 == 0)
			{
				if(BurstLevel==0)
				{
				MarisaShot(opX[0]-AdjustX,opY[0]+AdjustY,ShotSpeed,260,HiDamage,4,0);
				MarisaShot(opX[1]-AdjustX,opY[1]+AdjustY,ShotSpeed,260,HiDamage,4,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,260,HiDamage,4,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,260,HiDamage,4,3);

				MarisaShot(opX[0]+AdjustX,opY[0]+AdjustY,ShotSpeed,280,HiDamage,4,0);
				MarisaShot(opX[1]+AdjustX,opY[1]+AdjustY,ShotSpeed,280,HiDamage,4,1);
				MarisaShot(opX[2]+AdjustX,opY[2]+AdjustY,ShotSpeed,280,HiDamage,4,2);
				MarisaShot(opX[3]+AdjustX,opY[3]+AdjustY,ShotSpeed,280,HiDamage,4,3);

				}

				if(BurstLevel==3)
				{
				MarisaShot(opX[0]-AdjustX,opY[0]+AdjustY,ShotSpeed,260,HiDamage*BL3,3,0);
				MarisaShot(opX[1]-AdjustX,opY[1]+AdjustY,ShotSpeed,260,HiDamage*BL3,3,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,260,HiDamage*BL3,3,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,260,HiDamage*BL3,3,3);

				MarisaShot(opX[0]+AdjustX,opY[0]+AdjustY,ShotSpeed,280,HiDamage*BL3,3,0);
				MarisaShot(opX[1]+AdjustX,opY[1]+AdjustY,ShotSpeed,280,HiDamage*BL3,3,1);
				MarisaShot(opX[2]+AdjustX,opY[2]+AdjustY,ShotSpeed,280,HiDamage*BL3,3,2);
				MarisaShot(opX[3]+AdjustX,opY[3]+AdjustY,ShotSpeed,280,HiDamage*BL3,3,3);
				}
			}
		}
yield;
}
}

task SearchShot
{
let Radius=0;
RingShot;
let damage=0.5;
let enemyID;
let enemyX1=0;
let enemyY1=0;
let enemyX2=0;
let enemyY2=0;
let enemyX3=0;
let enemyY3=0;
let enemyX0=0;
let enemyY0=0;

loop
{
		if(GetCommonDataDefault("UNKNOWN",false)==false)
		{
		enemyID = NearestEnemysearch;
		}

		
		if(enemyID[0]>=0)
		{
			enemyX0=GetEnemyInfo(enemyID[0],ENEMY_X);
			enemyY0=GetEnemyInfo(enemyID[0],ENEMY_Y);
		}
		if(enemyID[1]>=0)
		{
			enemyX1=GetEnemyInfo(enemyID[1],ENEMY_X);
			enemyY1=GetEnemyInfo(enemyID[1],ENEMY_Y);
		}
		if(enemyID[2]>=0)
		{
			enemyX2=GetEnemyInfo(enemyID[2],ENEMY_X);
			enemyY2=GetEnemyInfo(enemyID[2],ENEMY_Y);
		}
		if(enemyID[3]>=0)
		{
			enemyX3=GetEnemyInfo(enemyID[3],ENEMY_X);
			enemyY3=GetEnemyInfo(enemyID[3],ENEMY_Y);
		}

		if(((enemyX0-GetPlayerX)^2+(enemyY0-GetPlayerY)^2)^0.5<=Radius && enemyID[0]>=0)
		{
			OnOpShot[0]=1;
			if(shotCount%3 == 0)
			{
				ThunderShot(opX[0],opY[0],enemyX0,enemyY0);
			}
		}
		else
		{
			OnOpShot[0]=0;
		}
		if(((enemyX1-GetPlayerX)^2+(enemyY1-GetPlayerY)^2)^0.5<=Radius && enemyID[1]>=0)
		{
			OnOpShot[1]=1;
			if(shotCount%3 == 0)
			{
				ThunderShot(opX[1],opY[1],enemyX1,enemyY1);
			}
		}
		else
		{
			OnOpShot[1]=0;
		}
		if(((enemyX2-GetPlayerX)^2+(enemyY2-GetPlayerY)^2)^0.5<=Radius && enemyID[2]>=0)
		{
			OnOpShot[2]=1;
			if(shotCount%3 == 0)
			{
				ThunderShot(opX[2],opY[2],enemyX2,enemyY2);
			}
		}
		else
		{
			OnOpShot[2]=0;
		}
		if(((enemyX3-GetPlayerX)^2+(enemyY3-GetPlayerY)^2)^0.5<=Radius && enemyID[3]>=0)
		{
			OnOpShot[3]=1;
			if(shotCount%3 == 0)
			{
				ThunderShot(opX[3],opY[3],enemyX3,enemyY3);
			}
		}
		else
		{
			OnOpShot[3]=0;
		}
yield;
}

function NearestEnemysearch
{
	//let TargetID=[-1,-1,-1,-1];
	//let Enemydistance=[500,500,500,500];
	let TargetID0=-1;
	let Enemydistance0=500;
	let TargetID1=-1;
	let Enemydistance1=500;
	let TargetID2=-1;
	let Enemydistance2=500;
	let TargetID3=-1;
	let Enemydistance3=500;

	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+96 && enemyLife<25000)
		{
		let distance=((GetPlayerY-enemyY)^2+(GetPlayerX-enemyX)^2)^0.5;

		if(distance<=Enemydistance0)
		{
			Enemydistance3=Enemydistance2;
			TargetID3=TargetID2;
			Enemydistance2=Enemydistance1;
			TargetID2=TargetID1;
			Enemydistance1=Enemydistance0;
			TargetID1=TargetID0;
			Enemydistance0=distance;
			TargetID0=enemyID;
		}
		else if(distance<=Enemydistance1)
		{
			Enemydistance3=Enemydistance2;
			TargetID3=TargetID2;
			Enemydistance2=Enemydistance1;
			TargetID2=TargetID1;
			Enemydistance1=distance;
			TargetID1=enemyID;
		}
		else if(distance<=Enemydistance2)
		{
			Enemydistance3=Enemydistance2;
			TargetID3=TargetID2;
			Enemydistance2=distance;
			TargetID2=enemyID;
		}
		else if(distance<=Enemydistance3)
		{
			Enemydistance3=distance;
			TargetID3=enemyID;
		}
		}
	}

	let TargetID=[TargetID0,TargetID1,TargetID2,TargetID3];
	return TargetID;

}

task RingShot
{
let angle=0;
let expandcount=0;
loop
{
	if(Radius!=0)
	{
	ascent(i in 0..12)
	{
	RingShotEffect(Radius,angle+i*30);
	}
	}
	angle+=3;
	if(GetKeyState(VK_SHOT)==KEY_HOLD && !OnMissed && MissTime==0)
	{
		if(Radius<160 && expandcount>=10)
		{
			Radius+=8;
		}
		expandcount+=1;
	}
	else
	{
		if(Radius>0)
		{
			Radius=0;
		}
		expandcount=0;
	}
	if(GetCommonDataDefault("OnMS",false)==true)
	{
		Radius=0;
		expandcount=0;
	}
	yield;
	
	task RingShotEffect(Radius,angle)
	{

	let objE = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(objE, imgLight);
	ObjEffect_SetPrimitiveType(objE, PRIMITIVE_TRIANGLEFAN);
	Obj_SetPosition(objE,GetPlayerX+Radius*cos(angle),GetPlayerY+Radius*sin(angle));
	ObjEffect_CreateVertex(objE, 4);
	ObjEffect_SetRenderState(objE,ADD);
	ObjEffect_SetLayer(objE,2);
	
	ObjEffect_SetVertexXY(objE, 0, -32, -32);
	ObjEffect_SetVertexXY(objE, 1, 32, -32);
	ObjEffect_SetVertexXY(objE, 2, 32, 32);
	ObjEffect_SetVertexXY(objE, 3, -32, 32);

	let randrect=rand(0,256);
	ObjEffect_SetVertexUV(objE, 0, 0, 0);
	ObjEffect_SetVertexUV(objE, 1,64, 0);
	ObjEffect_SetVertexUV(objE, 2, 64, 64);
	ObjEffect_SetVertexUV(objE, 3, 0, 64);

	ObjEffect_SetScale(objE,0.5,0.5);
	ObjEffect_SetAngle(objE,0,0,rand(0,256));

	let R=255;
	let G=50;
	let B=255;
	if(BurstLevel==3)
	{
		R=ColorRed;G=ColorGreen;B=ColorBlue;
	}
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(objE, i,150, R, G, B);
	}
	wait(1);
	Obj_Delete(objE);
	}
}

}

}

task ThunderShot(x,y,gx,gy)
{
	let angle=atan2(gy-y,gx-x);
	let distance=((gy-y)^2+(gx-x)^2)^0.5;
	let objE = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(objE, imgThunder);
	ObjEffect_SetPrimitiveType(objE, PRIMITIVE_TRIANGLEFAN);
	Obj_SetPosition(objE,x,y);
	ObjEffect_CreateVertex(objE, 4);
	ObjEffect_SetRenderState(objE,ADD);
	ObjEffect_SetLayer(objE,2);
	
	ObjEffect_SetVertexXY(objE, 0, -24, -0);
	ObjEffect_SetVertexXY(objE, 1, 24, -0);
	ObjEffect_SetVertexXY(objE, 2, 24, distance);
	ObjEffect_SetVertexXY(objE, 3, -24, distance);

	let randrect=rand(0,256);
	ObjEffect_SetVertexUV(objE, 0, 0, 0);
	ObjEffect_SetVertexUV(objE, 1, 48, 0);
	ObjEffect_SetVertexUV(objE, 2, 48, randrect);
	ObjEffect_SetVertexUV(objE, 3, 0, randrect);

	ObjEffect_SetScale(objE,1,1);
	ObjEffect_SetAngle(objE,0,0,angle-90);

	let R=255;
	let G=50;
	let B=255;
	if(BurstLevel==3)
	{
		R=ColorRed;G=ColorGreen;B=ColorBlue;
	}
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(objE, i,120, R, G, B);
	}
	let ThunderWay=0;
	ascent(i in 0..4)
	{
		ThunderWay+=OnOpShot[i];
	}
	let TDC=0;
	if(ThunderWay==1){TDC=1.00;}
	if(ThunderWay==2){TDC=0.55;}
	if(ThunderWay==3){TDC=0.40;}
	if(ThunderWay==4){TDC=0.35;}
	let LowDamege=2.0*TDC;
	let HiDamege=2.8*TDC;

	if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
	{
		if(BurstLevel==0)
		{
			MarisaShot(gx,gy,18,270,LowDamege,2,5);
		}
		if(BurstLevel==3)
		{
			MarisaShot(gx,gy,18,270,LowDamege*BL3,2,5);
		}
		ObjEffect_SetScale(objE,1.5,1);
	}
	else
	{
		if(BurstLevel==0)
		{
		MarisaShot(gx,gy,18,270,HiDamege,2,5);
		}
		if(BurstLevel==3)
		{
		MarisaShot(gx,gy,18,270,HiDamege*BL3,2,5);
		}
	}
	wait(3);
	Obj_Delete(objE);
}

task MarisaMainShot(let x,let y,let speed,let angle,let damage,let Type)
{

	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=255;G=50;B=255;

	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(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);

	let R;
	let G;
	let B;

	R=255;G=50;B=255;

	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;
	}

	while(!Obj_BeDeleted(obj))
	{
	if(OpNum<=3)
	{
		Obj_SetX(obj,x);
	}
		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);
			}
		}
		yield;
	}
}

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_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_SetAngle(objE,0,0,angle+90);

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

