//メイン＆サブショット
task TShot
{//メイン
	let pShot=false;
	ShotCheck;
	let Speed=22.5;
	let MainDamage=3.0;
	let DamageRate=1;
	loop
	{
		while(!pShot){yield;}
		if(IsPlayerSpellActive){DamageRate=0.5;}
		else{DamageRate=1.0;}

		MainShot(GetPlayerX()+8, GetPlayerY(), Speed, 270, MainDamage, 1, 20);
		MainShot(GetPlayerX()-8, GetPlayerY(), Speed, 270, MainDamage, 1, 20);
		PlaySE(SE_SHOT);

		loop(3){yield;}
	}

	task ShotCheck
	{
		loop
		{
			if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD) && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot && !IsPlayerSpellActive && !OnSpell)
			{
			pShot=true;

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}

	task MainShot(x,y,speed,angle,damage,pene,id)
	{
		let obj=CreatePlayerShotA1(x,y,speed,angle,damage,pene,id);
		let scale=1;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		Obj_SetRenderPriorityI(obj,40);
		let OldX;
		let OldY;
		while(!Obj_IsDeleted(obj))
		{
			OldX=ObjMove_GetX(obj);
			OldY=ObjMove_GetY(obj);
			yield;
		}
		HitEffect(OldX,OldY,speed,angle);
		Obj_Delete(obj);
	}

	task HitEffect(x,y,speed,angle)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,32,64,48,96);

		ObjRender_SetPosition(obj,x+1,y-18,0);
		speed/=8;
		let Alpha=0.75;
		let R=255;
		let G=255;
		let B=255;
		loop(15)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
		//	ObjRender_SetAngleZ(obj,angle);
			Alpha-=0.25/15;
			yield;
		}

		ObjPrim_SetDestCenter(obj,32,32,48,64);

		loop(5)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
		//	ObjRender_SetAngleZ(obj,angle);
			Alpha-=0.25/5;
			yield;
		}

		ObjPrim_SetDestCenter(obj,32,0,48,32);

		loop(5)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
		//	ObjRender_SetAngleZ(obj,angle);
			Alpha-=0.25/5;
			yield;
		}
		Obj_Delete(obj);
	}

}

task TShot2
{//サブ
	let pShot=false;
	ShotCheck;
	let LaserDamage=0.6;
	let FireDamage=1.2;
	let AuraFireDamage=1.8;
	let DamageRate=1;
	let ShotAngle_P1=[270,0,0,0];
	let ShotAngle_P2=[250,290,0,0];
	let ShotAngle_P3=[290,250,270,0];
	let ShotAngle_P4=[275,264,270,270];
	let ShotAngle=[ShotAngle_P1,ShotAngle_P2,ShotAngle_P3,ShotAngle_P4];
	LaserDraw(ShotAngle);
	let LaserLagCount=6;
	let AuraShotCount=0;
	loop
	{
		while(!pShot){LaserLagCount=6;yield;}
		if(IsPlayerSpellActive){DamageRate=0.5;}
		else{DamageRate=1.0;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			ascent(i in 0..PlayerPower_Int)
			{
			FireShot(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],FireDamage,i);
			}
			AuraShotCount+=1;
			if(AuraShotCount%4==0)
			{
				ascent(i in 0..PlayerPower_Int)
				{
				let ra=rand(30,45);
				if(i<=1)
				{
				AuraFireShot(OptionX[i],OptionY[i],90+ra,AuraFireDamage,i);
				AuraFireShot(OptionX[i],OptionY[i],90-ra,AuraFireDamage,i);
				}
				else
				{
				AuraFireShot(OptionX[i],OptionY[i],270+ra,AuraFireDamage,i);
				AuraFireShot(OptionX[i],OptionY[i],270-ra,AuraFireDamage,i);
				}
				}
			}
			yield;
		}
		else
		{
			ascent(i in 0..PlayerPower_Int)
			{
			if(i<=1)
			{
			if(LaserLagCount<=0)
			{
			LaserShot(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],LaserDamage,i);
			}
			}
			else
			{
			LaserShot(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],LaserDamage,i);
			}
			}
		}
		ascent(i in 0..4)
		{
		if(LaserImpactFlag[i]>0)
		{
		LaserImpactFlag[i]=LaserImpactFlag[i]-1;
		}
		}

		LaserLagCount--;
		loop(1){yield;}
	}

	task ShotCheck
	{
		loop
		{
			if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD) && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot && !IsPlayerSpellActive && !OnSpell)
			{
			pShot=true;

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}
}

task AuraFireShot(x,y,angle,damage,Opnum)
{
	let speed=3;
	let obj=CreatePlayerShotA1(x,y,speed,angle,damage,1,22);
	let scale=1.0;
	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	let count=0;
	let OldX=x;
	let OldY=y;
	let Alpha=255;
	loop(20)
	{
		if(Obj_IsDeleted(obj)){break;}
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		if(ObjCol_GetIntersectedCount(obj)>0)
		{
		HitEffect(OldX,OldY,speed,angle)
		}
		yield;
	}
	loop(5)
	{
		if(Obj_IsDeleted(obj)){break;}
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		ObjRender_SetAlpha(obj,Alpha);
		Alpha-=255/5;
		yield;
	}

	Obj_Delete(obj);

	task HitEffect(x,y,speed,angle)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,96,160,128,192);

		ObjRender_SetPosition(obj,x,y,0);

		let Alpha=0.1;
		let R=255;
		let G=255;
		let B=255;

		loop(15)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleZ(obj,angle+90);
			Alpha-=0.1/15;
			yield;
		}
		Obj_Delete(obj);
	}
}

task FireShot(x,y,angle,damage,Opnum)
{
	angle+=rand(-5,5);
	let speed=16;
	let obj=CreatePlayerShotA1(x,y,speed,angle,damage,1,21);
	Obj_SetRenderPriorityI(obj,40);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	let count=0;
	let OldX=x;
	let OldY=y;
	let Alpha=255;
	let Rate=1;
	loop(45)
	{
		if(Obj_IsDeleted(obj)){break;}
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		ObjMove_SetSpeed(obj,speed);
		if(speed>3){speed-=0.65;}
		if(ObjCol_GetIntersectedCount(obj)>0)
		{
		HitEffect(OldX,OldY,speed,angle)
		}
		ObjShot_SetDamage(obj,damage*Rate);
		Rate-=0.25/45;
		yield;
	}
	loop(15)
	{
		if(Obj_IsDeleted(obj)){break;}
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		ObjMove_SetSpeed(obj,speed);
		if(speed>3.5){speed-=0.65;}
		ObjRender_SetAlpha(obj,Alpha);
		Alpha-=255/15;
		yield;
	}
	Obj_Delete(obj);

	task HitEffect(x,y,speed,angle)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,96,160,128,192);

		ObjRender_SetPosition(obj,x,y,0);
		if(speed>3){speed=3;}
		let Alpha=0.1;
		let R=255;
		let G=255;
		let B=255;

		loop(15)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleZ(obj,angle+90);
			Alpha-=0.1/15;
			yield;
		}
		Obj_Delete(obj);
	}
}

let LaserPoint=[[0,0],[0,0],[0,0],[0,0]];
let LaserImpactFlag=[0,0,0,0];

task LaserShot(x,y,angle,damage,Opnum)
{
	let speed=16.875;
	let obj=CreatePlayerShotA1(x,y,speed,angle,damage,1,21);
	Obj_SetRenderPriorityI(obj,20);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	ObjRender_SetAlpha(obj,0);
	let count=0;
	let OldX=x;
	let OldY=y;
	let dx=0;
	let dy=0;
	while(!Obj_IsDeleted(obj))
	{
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		ObjMove_SetX(obj,OptionX[Opnum]+dx);
		ObjMove_SetY(obj,OptionY[Opnum]+dy);
		dx+=speed*cos(angle);
		dy+=speed*sin(angle);
		if(GetVirtualKeyState(VK_SHOT)==KEY_PULL){break;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH){break;}
		if(GetPlayerState!=STATE_NORMAL){break;}
		if(!IsPermitPlayerShot){break;}
		let TempLaserPoint=LaserPoint[Opnum];
		let LaserLeng=((OptionY[Opnum]-LaserPoint[Opnum][1])^2+(OptionX[Opnum]-LaserPoint[Opnum][0])^2)^0.5;
		let Leng=((OptionY[Opnum]-ObjMove_GetY(obj))^2+(OptionX[Opnum]-ObjMove_GetX(obj))^2)^0.5;
		if(LaserLeng<Leng)
		{
			let TempLaserPoint=LaserPoint[Opnum];
			TempLaserPoint[0]=OldX;
			TempLaserPoint[1]=OldY;
			LaserPoint[Opnum]=TempLaserPoint;
		}

		yield;
	}

	if(GetVirtualKeyState(VK_SHOT)!=KEY_PULL && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH)
	{
		let TempLaserPoint=LaserPoint[Opnum];
		TempLaserPoint[0]=OldX;
		TempLaserPoint[1]=OldY;
		LaserPoint[Opnum]=TempLaserPoint;
		if(OldY>-16)
		{
			HitEffect(OldX,OldY,speed,angle);
			LaserImpactFlag[Opnum]=2;
		}
	}
	else
	{

	}
	Obj_Delete(obj);

	task HitEffect(x,y,speed,angle)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,64,34,80,61);

		ObjRender_SetPosition(obj,x,y,0);
		speed/=4;
		let Scale=1;
		let Alpha=0.5;
		let R=255;
		let G=100;
		let B=255;
		loop(12)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
			ObjRender_SetAngleZ(obj,angle+90);
			Alpha-=0.5/15;
			Scale-=1/15;
			yield;
		}
		Obj_Delete(obj);
	}
}

task LaserDraw(ShotAngle)
{
loop
{
	while(OnSpell || GetPlayerState!=STATE_NORMAL || !IsPermitPlayerShot){yield;}
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH)
	{
		if(GetVirtualKeyState(VK_SHOT)==KEY_HOLD){break;}
		yield;
	}
	if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE)
	{
	LaserPoint=[[0,0],[0,0],[0,0],[0,0]];
	LaserEffect(2);
	LaserEffect(3);
	LaserEffect(0);
	LaserEffect(1);
	while( GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD)
	{
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PULL){break;}
		if(OnSpell){break;}
		if(GetPlayerState!=STATE_NORMAL){break;}
		if(!IsPermitPlayerShot){break;}
		yield;
	}
	}
	else{yield;}
}
	task LaserEffect(num)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,80,0,96,256);
		let Alpha=1.0;
		let R=255;
		let G=255;
		let B=255;
	//	ObjRender_SetScaleXYZ(obj,5,5,5);
	//	ObjRender_SetAngleX(obj,180);
		ObjRender_SetAngleZ(obj,ShotAngle[PlayerPower_Int-1][num]-90);
		let LengMax=0;
		let ScaleX=0;
		let LagCount=6;
		LaserSourceEffect(num);
		let AnimeCount=0;
		while( (GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD ))
		{
			if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH){break;}
			if(OnSpell){break;}
			if(GetPlayerState!=STATE_NORMAL){break;}
			if(!IsPermitPlayerShot){break;}
			if(LaserImpactFlag[num]>0)
			{
				R=100;G=100;B=255;
			}
			else
			{
				R=255;G=255;B=255;
			}

			ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,ScaleX,1,1);

			let Leng=((OptionY[num]-LaserPoint[num][1])^2+(OptionX[num]-LaserPoint[num][0])^2)^0.5;
			LengMax+=16.875;
			if(LaserPoint[num][0]==0 && LaserPoint[num][1]==0)
			{
				if(num>=2)
				{
				Leng=LengMax;
				}
				else
				{
				if(LagCount>0){LengMax=0;Leng=LengMax;}
				}
			}
			if(Leng>LengMax){Leng=LengMax;}

			if(ScaleX<1){ScaleX+=0.5;}

			ObjPrim_SetVertexUVT(obj, 0, 64, AnimeCount);
			ObjPrim_SetVertexUVT(obj, 1, 80, AnimeCount);
			ObjPrim_SetVertexUVT(obj, 2, 80, Leng+AnimeCount);
			ObjPrim_SetVertexUVT(obj, 3, 64, Leng+AnimeCount);

			ObjPrim_SetVertexPosition(obj, 0, -8, 0, -0);
			ObjPrim_SetVertexPosition(obj, 1, 8, 0, -0);
			ObjPrim_SetVertexPosition(obj, 2, 8, Leng, 0);
			ObjPrim_SetVertexPosition(obj, 3, -8, Leng, 0);

			LagCount--;
			AnimeCount-=64/5;
			yield;
		}
		loop(3)
		{
			if(LaserImpactFlag[num]>0)
			{
				R=100;G=100;B=255;
			}
			else
			{
				R=255;G=255;B=255;
			}

			ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,ScaleX,1,1);

			let Leng=((OptionY[num]-LaserPoint[num][1])^2+(OptionX[num]-LaserPoint[num][0])^2)^0.5;
			LengMax+=16.875;
			if(LaserPoint[num][0]==0 && LaserPoint[num][1]==0)
			{
				if(num>=2)
				{
				Leng=LengMax;
				}
				else
				{
				if(LagCount>0){LengMax=0;Leng=LengMax;}
				}
			}
			if(Leng>LengMax){Leng=LengMax;}

			ScaleX-=0.5;

			ObjPrim_SetVertexUVT(obj, 0, 64, AnimeCount);
			ObjPrim_SetVertexUVT(obj, 1, 80, AnimeCount);
			ObjPrim_SetVertexUVT(obj, 2, 80, Leng+AnimeCount);
			ObjPrim_SetVertexUVT(obj, 3, 64, Leng+AnimeCount);

			ObjPrim_SetVertexPosition(obj, 0, -8, 0, -0);
			ObjPrim_SetVertexPosition(obj, 1, 8, 0, -0);
			ObjPrim_SetVertexPosition(obj, 2, 8, Leng, 0);
			ObjPrim_SetVertexPosition(obj, 3, -8, Leng, 0);

			LagCount--;
			AnimeCount-=64/5;
			yield;
		}

		Obj_Delete(obj);

		task LaserSourceEffect(num)
		{
			let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
			ObjPrim_SetTexture(obj,IMG_SHOT);
			ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
			ObjPrim_SetVertexCount(obj, 4);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			Obj_SetRenderPriorityI(obj,43);
			ObjRender_SetAngleZ(obj,0);

			ObjPrim_SetDestCenter(obj,96,192,128,224);
			let Scale=1.25;
			let ScaleTheta=0;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
			let Xangle=-90;
			let Yangle=90;
			let Zangle=0;
			loop(3)
			{
				ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
				ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
				Xangle+=30;
				Yangle-=30;
				Zangle+=30;
				yield;
			}
			while(GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD)
			{
				if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH){break;}
				if(OnSpell){break;}
				if(GetPlayerState!=STATE_NORMAL){break;}
				if(!IsPermitPlayerShot){break;}
				ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
				ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
				ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
				Scale=1.00+0.25*cos(ScaleTheta);
				Zangle+=30;
				ScaleTheta+=45;
				yield;
			}
			loop(3)
			{
				ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
				ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
				Xangle-=30;
				Yangle+=30;
				Zangle+=30;
				yield;
			}
			Obj_Delete(obj);
		}
	}
}