
task Powor	//powerの値を変化させるタスク。バリア発動やP回復。
{
let ChargeFlag=true;
let DefeatCount=0;
let SpecialCount=0;
	if(Power>1000){Power=1000;}
	if(MagicCounter>10000){MagicCounter=10000;}
	if(MagicCounter<0){MagicCounter=0;}
	if(BurstRank>10000){BurstRank=10000;}
	if(BurstRank<0){BurstRank=0;}
	if(RushGauge>1000){RushGauge=1000;}
	if(RushGauge<-1000){RushGauge=-1000;}
loop
{
	//if(Power>1000){Power=1000;}
	//if(MagicCounter>10000){MagicCounter=10000;}
	//if(MagicCounter<0){MagicCounter=0;}
	//if(BurstRank>10000){BurstRank=10000;}
	//if(BurstRank<0){BurstRank=0;}
	//if(RushGauge>1000){RushGauge=1000;}
	//if(RushGauge<-1000){RushGauge=-1000;}
	if(GetCommonDataDefault("SELECTEDDIFFICULT","None")!="Extream")
	{
		RushGauge=0;
	}
	if(GetKeyState(VK_USER)==KEY_PUSH && Power>=1000 && BurstModeCount==0 && IsForbidBomb==false && !OnMissed)
	{
	//	Slow(1);
		PlaySE(SE[0]);
		WeaknessCount=0;
		PurityRateCount*=2;
		BurstLevel=3;
		if(PNRate<0)
		{
			PNRate=-100;
		}
		else
		{
			PNRate=100;
		}
		Burst;
		Shadow(600);
		if(absolute(RushGauge)>=1000)
		{
			while(GetKeyState(VK_USER)==KEY_PUSH || GetKeyState(VK_USER)==KEY_HOLD)
			{
			if(SpecialCount>=30)
			{
			PlaySE("seBomb_ReimuA.wav");
				SpecialEffect;
				if(RushGauge>=1000)
				{
					Power=1000;
					RashFlag=true;
					RushOn;
				}
				else if(RushGauge<=-1000)
				{
					Power=1000;
					CoolFlag=true;
					CoolOn;
				}
				break;
			}
			Power-=1000/600;
			if(OnBomb){Power-=1000/600;}
			SpecialCount+=1;
			yield;
			}
			SpecialCount=0;
		}
		loop
		{
			if(BurstMode==0)
			{
				break;
			}
			SetItemCollectLine(500);//アイテム回収されるy座標
			if(GetCommonDataDefault("BurstStop",false)==true)
			{

			}
			else
			{
				Power-=1000/600;
				if(OnBomb){Power-=1000/600;}
			}
			if(Power>1000){Power=1000;}
			if(MagicCounter>10000){MagicCounter=10000;}
			if(BurstRank>10000){BurstRank=10000;}
			if(BurstRank<0){BurstRank=0;}
			if(RushGauge>1000){RushGauge=1000;}
			if(RushGauge<-1000){RushGauge=-1000;}
		yield;
		}
	ChargeFlag=true;
	BL3=4/3;
	PurityRateCount/=2;
	if(RashFlag || CoolFlag){RushGauge=0;PNRate=0;BurstRank+=1000;}
	RashFlag=false;
	CoolFlag=false;
	wait(5);
	if(OnCansellBomb)
	{
		Power=Power/2;
		MagicCounter=MagicCounter*2/3;
	}
	else
	{
		Power=Power/2;
		MagicCounter=MagicCounter/2;
	}
	BurstRank+=1000;
	if(BurstRank>10000){BurstRank=10000;}
	BurstModeCount=10;
	}
	//Slow(0);
if(BurstModeCount>0)
{
	BurstModeCount-=1;
}

if(trunc(Power)>=1000 && ChargeFlag && BurstMode==0)
{
PowerChargeEffect;
ChargeFlag=false;
}

SetItemCollectLine(AutoItemCollectLine);//アイテム回収されるy座標
//SetCommonData("KEKKAI",false);

if(miss<GetMissCount)
{//ミスしたときに一回実行
	while(MissTime>0){yield;}
	miss+=1;
	SetPlayerInvincibility(180);
	BulletErase(120);
	BurstRank/=2;
	Power+=250;
	PurityRateCount=0;
	if(Power>1000){Power=1000;}
	MagicCounter=MagicCounter/2;
	RushGauge=RushGauge/2;
	RaiseAutoBomb=false;
}
yield;
}
}
///////////////////////////////////////////////////////////////////////


task BulletErase(time)
{
loop(time)
{
DeleteEnemyShot(SHOT);
yield;
}
}

//////////////////////////////////////////////
task CheckMagicItem
{
let ItemCheck=0;
let XY=[];
let ItemPerFrame=60;
loop
{
	ItemCheck=length(GetCommonDataDefault("ItemXY",[]));
	if(ItemCheck>0)
	{
		loop(ItemPerFrame)
		{
			XY=GetCommonDataDefault("ItemXY",[]);

			CreateMigicItem(XY[0],XY[1],XY[2]);
	
			loop(3)
			{
				XY=erase(XY, 0);
			}

			if(length(XY)==0)
			{
				SetCommonData("ItemXY",[]);
				break;
			}
			else
			{
				SetCommonData("ItemXY",XY);
			}
		}
	}
yield;
}
}

//////////////////////////////////////////////////////////////////////////////

task Burst//バーストのタスク。
{
	 	StartDeleteShot;
		BurstMode=1;
		BurstStartEffect;
		wait(5);
		parin;
		while(BurstMode==1){yield};

	//	PlaySE(SE[1]);

		BurstEndEffect;
		BurstMode=0;
}


task parin//バリア割りのタスク。
{
	wait(3);
	loop
	{
		if(BurstMode==0)
		{
			BurstLevel=0;
			EndDeleteShot;
			break;
		}
		if(Power<=0)
		{
			PlaySE(SE[1]);
			BurstMode=0;
			BurstLevel=0;
			Power=0;
			EndDeleteShot;
			break;
		}	
	yield;
	}
}

task RushOn
{
	MagicCounter=10000;
	BL3=5/3;
}

task CoolOn
{
	MagicCounter=10000;
	SetPlayerInvincibility(300);
	BulletErase(240);
}

task StartDeleteShot
{
	SetPlayerInvincibility(120);

	wait(1);
	let BulletNum=GetEnemyShotCount;
	if(!OnMissed && !OnBomb)
	{
		Power+=BulletNum;
		MagicFragment+=BulletNum;
		SectionMagicFragment+=BulletNum;
		AddScore(10*MagicCounter*BulletNum);
		DeleteShotNumdraw(BulletNum,GetPlayerX,GetPlayerY,3);
	}

	BulletErase(60);
}

task EndDeleteShot
{
	SetPlayerInvincibility(120);
	BulletErase(60);
}

task CommonDataSetting
{
loop
{
	if(GetCommonDataDefault("SectionShift",false)==true)
	{
		SectionMagicFragment=0;
		wait(5);
		SetCommonData("SectionShift",false);
	}
	if(GetCommonDataDefault("ClearFragmentBonus",false))
	{
	//	MagicFragment=0;
	}
	SetCommonData("MAGICPOWER",Power);
	SetCommonData("BURSTLEVEL",BurstLevel);
	SetCommonData("MAGICCOUNTER",MagicCounter);
	SetCommonData("MAGICFRAGMENT",MagicFragment);
	SetCommonData("SECTIONMAGICFRAGMENT",SectionMagicFragment);
	SetCommonData("BURSTRANK",BurstRank);
	SetCommonData("RUSHGAUGE",RushGauge);
	if(RashFlag)
	{
		SetCommonData("BurstErazeCircleRangeRate",0);
	}
	else if(CoolFlag)
	{
		SetCommonData("BurstErazeCircleRangeRate",BurstErazeCircleRangeRate*(1+0.25*BurstRank/10000)*1.5);
	}
	else
	{
	SetCommonData("BurstErazeCircleRangeRate",BurstErazeCircleRangeRate*(1+0.25*BurstRank/10000)*(1-0.25*RushGauge/1000));
	}
	yield;
}
}

task DeleteBulletCheck
{
DeleteBulletReChargeTask;
let Dnum;
let Dx;
let Dy;

loop
{
	if(GetCommonDataDefault("DeleteBulletNum",0)>0)
	{
		Dnum=GetCommonDataDefault("DeleteBulletNum",0)/2;
		Dx=GetCommonDataDefault("DeleteBulletX",0);
		Dy=GetCommonDataDefault("DeleteBulletY",0);

		if(BurstMode==0)
		{
			if(GetKeyState(VK_SLOWMOVE)==KEY_FREE)
			{
				MagicFragment+=Dnum*4/2;
				SectionMagicFragment+=Dnum*4/2;
				MagicCounter+=Dnum*4;
				DeleteShotNumdraw(Dnum*4,Dx,Dy,1);

				if(absolute(RushGauge)!=1000)
				{
				RushGauge+=Dnum*4/8;
				}
			}
			else
			{
				MagicFragment+=Dnum*4/2;
				SectionMagicFragment+=Dnum*4/2;
				DeleteBulletReCharge+=Dnum;
				DeleteShotNumdraw(Dnum,Dx,Dy,2);

				if(absolute(RushGauge)!=1000)
				{
				RushGauge-=Dnum*4/8;
				}
			}
		}
		else
		{
			MagicFragment+=Dnum*4/2;
			SectionMagicFragment+=Dnum*4/2;
			MagicCounter+=Dnum*8;
			DeleteShotNumdraw(Dnum*8,Dx,Dy,1);
		}
		if(Power>1000){Power=1000;}
		if(MagicCounter>10000){MagicCounter=10000;}
		SetCommonData("DeleteBulletNum",0);
	}
yield;
}
}

task DeleteBulletReChargeTask
{
loop
{
	if(DeleteBulletReCharge>0)
	{
	loop(10)
	{
	if(DeleteBulletReCharge>0)
	{
		if(Power<1000){Power+=1;}
		DeleteBulletReCharge-=1;
	}
	}
	}

	yield;
}
}
