
task ChargeFilmSE//高速巻き時のSEを出すタスク。Deleteして無理やり中断している
{
loop
{
if(GetCommonDataDefault("DoubleSpoilerStageMenu",false)==false)
{
	if(Charge<100)
	{
		if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD)
		{
			PlaySE(SE[5]);
		}
		while(GetKeyState(VK_SLOWMOVE)==KEY_HOLD && GetKeyState(VK_SHOT)==KEY_HOLD && Charge<100){wait(1);}
	}
	DeleteSE(SE[5]);
	if(FinderMode==true)
	{
		while(FinderMode==true){wait(1);}
		wait(70);
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			wait(30);
		}
	}
}
wait(1);
}
}

task ChargeFilmFinishSE//100%になったときに鳴るSEのタスク
{
loop
{
if(GetCommonDataDefault("DoubleSpoilerStageMenu",false)==false)
{
	if(Charge==100)
	{
		PlaySE(SE[2]);
		while(Charge==100){wait(1);}
	}
}
wait(1);
}
}

task ChargeFilm//通常時と高速巻き時の装填速度。高速巻き時の装填速度は若干初めが遅い
{
let PlusCharge=0;
let PlusChargeCount=0;
let RapidPlusCharge=0;
let RapidPlusChargeCount=0;
loop
{
if(GetCommonDataDefault("DoubleSpoilerStageMenu",false)==false)
{
	if(Charge<100)
	{
		if((GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && (GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD))
		{
			ChargeEffect;
			Charge+=0.125;
			Charge+=RapidPlusCharge;
			if(RapidPlusChargeCount<5)
			{
				Charge-=0.0625;
				Charge+=PlusCharge;
				RapidPlusCharge=0;
			}
			else if(RapidPlusChargeCount<70)
			{
				RapidPlusCharge=3*RapidPlusChargeCount/560;
			}
			else
			{
				RapidPlusCharge=0.375;
			}
			RapidPlusChargeCount+=1;
		}
		else
		{
			Charge+=0.0625;
			Charge+=PlusCharge;
			if(PlusChargeCount<60)
			{
				PlusCharge=PlusChargeCount/480;
			}
			else
			{
				PlusCharge=0.125;
			}
			RapidPlusChargeCount=0;
		}
		PlusChargeCount+=1;
	}
	else
	{
		Charge=100;
	}
	if(FinderMode==true)
	{
		while(FinderMode==true){wait(1);}
		PlusChargeCount=0;
		RapidPlusChargeCount=0;
		wait(70);
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			wait(30);
		}
	}
}
wait(1);
}
}
let SpeedChange=false;
task SetSpeedChange//自機のスピード制御。ファインダーモードではスピード０
{
loop
{
	if(SpeedChange==true || GetCommonDataDefault("TimeStop",false)==true || GetCommonDataDefault("DefeatBoss",false)==true)
	{
		loop
		{
		SetSpeed(0, 0);
		if(SpeedChange==false){
		wait(1);
		break;}
		if(FinderMode==false){
		wait(1);
		break;}
		wait(1);
		}

	}
	else if((GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && (GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD))
	{
		SetSpeed(5.0, 0.5);
	}
	else
	{
		SetSpeed(5.0, 2.3);
	}
wait(1);
}
}

task CameraDirChange//カメラを回転させる
{
loop
{
if(GetCommonDataDefault("DoubleSpoilerStageMenu",false)==false)
{
	if(GetKeyState(VK_USER)==KEY_PUSH)
	{
		PlaySE(SE[7]);
		CameraDir+=90;
	}
}
wait(1);
}
}

task EffectItemCreate//アイテム取得時のエフェクト
{
		let scax=1;
		let scay=1;
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBorder);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -4, -4);
		ObjEffect_SetVertexXY(obj, 1, 4,  -4);
		ObjEffect_SetVertexXY(obj, 2, 4, 4);
		ObjEffect_SetVertexXY(obj, 3,  -4,  4);
		
		ObjEffect_SetVertexUV(obj, 0,  173,  119);
		ObjEffect_SetVertexUV(obj, 1,  180, 119);
		ObjEffect_SetVertexUV(obj, 2, 180,  126);
		ObjEffect_SetVertexUV(obj, 3, 173, 126);
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,255,150,150,255);
			}	
		let speed=5;
		let angle=rand(0,360);
		let lightangle=rand(0,360);
		loop(50)
		{
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,205+50*cos(lightangle),150,150,255);
			}
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			speed-=0.1;
			wait(1);
		}

		loop(50)
		{
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,205+50*cos(lightangle),150,150,255);
			}
			let sangle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(sangle),Obj_GetY(obj)+speed*sin(sangle));
			speed+=0.3;
			ObjEffect_SetScale(obj, scax,scay);
			scax-=0.02;
			scay-=0.02;
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<10)
			{
				Obj_Delete(obj);
			}
			wait(1);
		}
		Obj_Delete(obj);
}

task dummyshot(let enemyID,let dx,let dy)//写真内に敵がいた場合敵座標に弾を発生させる
{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,dx,dy);
		Obj_SetSpeed(obj,0);
		Obj_SetAngle(obj,0);
		ObjShot_SetDamage(obj,501);
		ObjShot_SetPenetration(obj,1);
		ObjShot_SetGraphic(obj,121);
		Obj_SetAlpha(obj,0);
	//	ObjShot_SetBombResist(obj,true);
		while(!Obj_BeDeleted(obj))
		{
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			if(Obj_IsIntersected(obj) && enemyID==1 && GetCommonDataDefault("Playermissed",false)==false)
			{
				BossCapture=true;
			}
		}
		else
		{
			if(Obj_IsIntersected(obj) && enemyID==0 && GetCommonDataDefault("Playermissed",false)==false)
			{
				BossCapture=true;
			}
		}
		wait(1);
		}
		Obj_Delete(obj);
}

function dxdy(i,j,dis2,finderangle,CAngle,size)//カメラの中心からカメラの端までのX座標
{
	let a=dis2*cos(finderangle+CAngle-270)+size*i*cos(CAngle+CameraDir)+size*j*sin(-CAngle-CameraDir);
	return(a);
}
function dxdy2(i,j,dis2,finderangle,CAngle,size)//カメラの中心からカメラの端までのY座標
{
	let a=dis2*sin(finderangle+CAngle-270)+size*i*sin(CAngle+CameraDir)+size*j*cos(-CAngle-CameraDir);
	return(a);
}

task ShootTimeOut//ファインダーモードをタイムアウトしたときに呼び出される
{
//	wait(5);
	wait(1);
	Charge=50;
	if(GetCommonDataDefault("BunSpell",false)==false)
	{
	TimeSlowEffect;
	}
	else
	{
		SetCommonData("PlayerPhotoTimeStop",true);
		wait(5);
		if(GetPlayerScriptName=="HATATE.txt")
		{
			Charge=50;
		}	
		wait(25);
	}
}

task TimeSlowEffect//写真を撮ったときやタイムアウトになったときに呼び出される。本家では時間停止するが、無理なのでスローに
{
wait(1);
if(GetCommonDataDefault("BunSpell",false)==false)
{
Slow(2);
}
wait(10);
Slow(0);
}


function PhotoSelect(obj,obj9,No,DX,DY, scax,scay)//変数（PhotoSelectCorsol）にしたがってスペル終了時拡大写真を選択する。Adjust使って見た目よくしてる
{
let CX=GetCenterX;
let CY=GetCenterY-55;
let AdJust=0;
let AdJustsize=0;
let MoveFrame=10;
let size=0.9;
	if(PhotoSelectCorsol==No)
	{
		loop
		{
			if(AdJust<MoveFrame)
			{
				AdJust+=1;
			}
			Obj_SetPosition(obj,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj, scax+(size-scax)*AdJust/MoveFrame,scay+(size-scay)*AdJust/MoveFrame);
			Obj_SetPosition(obj9,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj9, scax+(size-scax)*AdJust/MoveFrame,scay+(size-scay)*AdJust/MoveFrame);
			if(PhotoSelectCorsol!=No)
			{
				break;
			}
			if(GetCommonDataDefault("PhotoEraze",false)==true)
			{
				Obj_Delete(obj);
				Obj_Delete(obj9);
				break;
			}

			if(AdJust==MoveFrame)
			{
				SetCommonData("PhotoSaveReady",true);
			}
			else
			{
				SetCommonData("PhotoSaveReady",false);
			}
			yield;	
		}
	}
	if(PhotoSelectCorsol!=No)
	{
		loop
		{
			if(AdJust>0)
			{
				AdJust-=1;
			}
			Obj_SetPosition(obj,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj, scax+(1-scax)*AdJust/MoveFrame,scay+(1-scay)*AdJust/MoveFrame);
			Obj_SetPosition(obj9,DX+(CX-DX)*AdJust/MoveFrame,DY+(CY-DY)*AdJust/MoveFrame);
			ObjEffect_SetScale(obj9, scax+(1-scax)*AdJust/MoveFrame,scay+(1-scay)*AdJust/MoveFrame);
			if(PhotoSelectCorsol==No)
			{
				break;
			}
			if(GetCommonDataDefault("PhotoEraze",false)==true)
			{
				Obj_Delete(obj);
				Obj_Delete(obj9);
				break;
			}
			//wait(1);
yield;	
		}
	}
}


task PhotoSelectChange//スペル終了時写真選択するための変数を変えるタスク
{
while(GetCommonDataDefault("ShootingEnd",false)==false){yield;}
let num=photoNo;
PhotoSelectCorsol=GetCommonDataDefault("BestShootNo",0);
yield;
loop
{
	if(GetKeyState(VK_LEFT) == KEY_PUSH)
	{
		PhotoSelectCorsol-=1;
		if(PhotoSelectCorsol<=-1)
		{
			PhotoSelectCorsol=num-1;
		}
	}
	if(GetKeyState(VK_RIGHT) == KEY_PUSH)
	{
		PhotoSelectCorsol+=1;
		if(PhotoSelectCorsol>=num)
		{
			PhotoSelectCorsol=0;
		}
	}
	yield;
}
}

task LoadDoubleSpoilerData
{//スペル側で設定したスコアポイントを反映
	wait(60);
	shotPoint = GetCommonDataDefault("ShotBasePoint",[100, 150, 400, 110, 40, 70, 80, 130, 200, 70, 60, 200, 150]);
}