 
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,2);
					MarisaMainShot(GetPlayerX-10,GetPlayerY+5,ShotSpeed,270,Damage,2);
				}

				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 == 12)
		{
			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=1.00;
let LowDamage=1.00;

let AdjustX=5;
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,2,0);
				MarisaShot(opX[1]-AdjustX,opY[1]+AdjustY,ShotSpeed,270,LowDamage,2,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,270,LowDamage,2,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage,2,3);

				MarisaShot(opX[0]+AdjustX,opY[0]+AdjustY,ShotSpeed,270,LowDamage,2,0);
				MarisaShot(opX[1]+AdjustX,opY[1]+AdjustY,ShotSpeed,270,LowDamage,2,1);
				MarisaShot(opX[2]+AdjustX,opY[2]+AdjustY,ShotSpeed,270,LowDamage,2,2);
				MarisaShot(opX[3]+AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage,2,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,270,LowDamage*BL3,3,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,3);

				MarisaShot(opX[0]+AdjustX,opY[0]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,0);
				MarisaShot(opX[1]+AdjustX,opY[1]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,1);
				MarisaShot(opX[2]+AdjustX,opY[2]+AdjustY,ShotSpeed,270,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,270,LowDamage,2,0);
				MarisaShot(opX[1]-AdjustX,opY[1]+AdjustY,ShotSpeed,270,LowDamage,2,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,270,LowDamage,2,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage,2,3);

				MarisaShot(opX[0]+AdjustX,opY[0]+AdjustY,ShotSpeed,270,LowDamage,2,0);
				MarisaShot(opX[1]+AdjustX,opY[1]+AdjustY,ShotSpeed,270,LowDamage,2,1);
				MarisaShot(opX[2]+AdjustX,opY[2]+AdjustY,ShotSpeed,270,LowDamage,2,2);
				MarisaShot(opX[3]+AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage,2,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,270,LowDamage*BL3,3,1);
				MarisaShot(opX[2]-AdjustX,opY[2]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,2);
				MarisaShot(opX[3]-AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,3);

				MarisaShot(opX[0]+AdjustX,opY[0]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,0);
				MarisaShot(opX[1]+AdjustX,opY[1]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,1);
				MarisaShot(opX[2]+AdjustX,opY[2]+AdjustY,ShotSpeed,270,LowDamage*BL3,3,2);
				MarisaShot(opX[3]+AdjustX,opY[3]+AdjustY,ShotSpeed,270,LowDamage*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[4],opY[4],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[5],opY[5],enemyX1,enemyY1);
			}
		}
		else if(OnOpShot[0]==1)
		{
			OnOpShot[1]=1;
			if(shotCount%3 == 0)
			{
				ThunderShot(opX[5],opY[5],enemyX0,enemyY0);
			}
		}
		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;

	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)
		{
			Enemydistance1=Enemydistance0;
			TargetID1=TargetID0;
			Enemydistance0=distance;
			TargetID0=enemyID;
		}
		else if(distance<=Enemydistance1)
		{
			Enemydistance1=distance;
			TargetID1=enemyID;
		}
		}
	}

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

}

task RingShot
{
let angle=0;
let expandcount=0;
let EffectCount=600;
loop
{
	angle+=3;
	if(GetKeyState(VK_SHOT)==KEY_HOLD && !OnMissed && MissTime==0)
	{
		if(expandcount>=15)
		{
			Radius=160;
		}
		expandcount+=1;
	}
	else
	{
		if(Radius>0)
		{
			Radius=0;
		}
		expandcount=0;
	}
	if(GetCommonDataDefault("OnMS",false)==true)
	{
		Radius=0;
	}
	yield;
}

}

}

task ThunderShot(x,y,gx,gy)
{
	if(GetCommonDataDefault("NoCollision",false)==true)
	{
		return;
	}
	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=64;
	let B=196;
	if(BurstLevel==3)
	{
		R=ColorRed;G=ColorGreen;B=ColorBlue;
	}
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(objE, i,120, R, G, B);
	}

	let TDC=1;
	let LowDamege=0.8*TDC;
	let HiDamege=0.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 ThunderEffect(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=64;
	let B=196;
	if(BurstLevel==3)
	{
		R=ColorRed;G=ColorGreen;B=ColorBlue;
	}
	ascent(i in 0..4)
	{
		ObjEffect_SetVertexColor(objE, i,120, R, G, B);
	}
	wait(2);
	Obj_Delete(objE);
}

task MarisaMainShot(let x,let y,let speed,let angle,let damage,let Type)
{
	let EliminateCount=0;
	let MaxEliminate=5;
	let EliminateCircle=2+EliminateIntensity/50;

	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);
	Obj_SetAlpha(obj,100);

	let R;
	let G;
	let B;

	R=255;G=64;B=196;

	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);
		}
		}
		if(EliminateMode)
		{
		if(GetEnemyShotCountEx(Obj_GetX(obj),Obj_GetY(obj),EliminateCircle,ALL)>0)
		{
			DeleteEnemyShotImmediatelyInCircle(SHOT,Obj_GetX(obj),Obj_GetY(obj),EliminateCircle);
			CreateMigicItem(Obj_GetX(obj),Obj_GetY(obj),8);
			EliminateCount+=1;
			if(EliminateCount>=MaxEliminate)
			{
			Obj_Delete(obj);
			}
		}
		}
		yield;
	}
}

task MarisaShot(let x,let y,let speed,let angle,let damage,let Type,let OpNum)
{
	let EliminateCount=0;
	let MaxEliminate=5;
	let EliminateCircle=1+EliminateIntensity/100;

	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);
	Obj_SetAlpha(obj,80);

	let R;
	let G;
	let B;

	R=255;G=64;B=196;

	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==4 || OpNum==5)
	{
		Obj_SetAlpha(obj,0);
		return;
	}

	while(!Obj_BeDeleted(obj))
	{

	Obj_SetX(obj,opX[OpNum]);
		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);
			}
		}
		/*
		if(EliminateMode)
		{
		if(GetEnemyShotCountEx(Obj_GetX(obj),Obj_GetY(obj),EliminateCircle,ALL)>0)
		{
			DeleteEnemyShotImmediatelyInCircle(SHOT,Obj_GetX(obj),Obj_GetY(obj),EliminateCircle);
			CreateMigicItem(Obj_GetX(obj),Obj_GetY(obj),8);
			EliminateCount+=1;
			if(EliminateCount>=MaxEliminate)
			{
			Obj_Delete(obj);
			}
		}
		}
		*/
		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_SetScale(objE,1.5,1.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_SetScale(objE,1.5,1.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,opX[OpNum]);
		yield;
	}
	Obj_Delete(objE);
}

