
task Powor	//powerの値を変化させるタスク。バリア発動やP回復。
{
CheckMagicItem;
CheckPowerState;
let ChargeFlag=true;

loop
{
	if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="None" && !OnEvent && !IsForbidBomb && !OnMissed)
	{
		if(Power<1000){Power+=AutoReCharge;}
	}
	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(GetKeyState(VK_USER)==KEY_PUSH && Power>=1000 && BurstModeCount==0 && IsForbidBomb==false && !OnMissed)
	{
	//	Slow(1);
		PlaySE(SE[0]);
		WeaknessCount=0;
		BurstLevel=3;
		Burst;
		Shadow(600);
		loop
		{
		if(BurstMode==0)
		{
		break;
		}
		SetItemCollectLine(500);//アイテム回収されるy座標
		if(GetCommonDataDefault("BOSSDEFEAT",false)==false)
		{
			Power-=1000/600;
			if(OnBomb){Power-=1500/600;}
		}
		if(Power>1000){Power=1000;}
		if(MagicCounter>10000){MagicCounter=10000;}
		if(BurstRank>10000){BurstRank=10000;}
		if(BurstRank<0){BurstRank=0;}
		yield;
		}
	ChargeFlag=true;
	wait(5);
	if(OnCansellBomb)
	{
		Power=Power/2;
		MagicCounter=MagicCounter*2/3;
	}
	else
	{
		Power=Power/2;
		MagicCounter=MagicCounter/2;
	}
	BurstRank+=1000;
	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)
{//ミスしたときに一回実行
	miss+=1;
	SetPlayerInvincibility(240);
	BurstRank/=2;
	Power+=250;
	MagicCounter=MagicCounter/2;
	RushGauge=RushGauge/2;
	RaiseAutoBomb=false;
}
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//バーストのタスク。
{
	 	DeleteShot;
		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;
			DeleteShot;
			break;
		}
		if(Power<=0)
		{
			PlaySE(SE[1]);
			BurstMode=0;
			BurstLevel=0;
			Power=0;
			DeleteShot;
			break;
		}	
	yield;
	}
}


task DeleteShot
{
	SetPlayerInvincibility(120);
/*
	wait(5);
	let BulletNum=GetEnemyShotCount;
//	if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Apocalypse" && !OnMissed && !OnBomb)
//	{
	if(!OnMissed && !OnBomb)
	{
		Power+=BulletNum;
		MagicFragment+=BulletNum/2;
		SectionMagicFragment+=BulletNum/2;
		AddScore(MagicCounter*BulletNum);
		DeleteShotNumdraw(BulletNum,GetPlayerX,GetPlayerY,3);
	}
//	}
*/
	DeleteEnemyShot(SHOT);

}

task CommonDataSetting
{
loop
{
	if(GetCommonDataDefault("SectionShift",false)==true)
	{
		SectionMagicFragment=0;
		SetCommonData("SectionShift",false);
	}
/*
	if(GetCommonDataDefault("BOSSDEFEAT",false))
	{
		if(BurstMode==1)
		{
			BurstMode=0;
		}
	}
*/
	SetCommonData("MAGICPOWER",Power);
	SetCommonData("BURSTLEVEL",BurstLevel);
	SetCommonData("MAGICCOUNTER",MagicCounter);
	SetCommonData("MAGICFRAGMENT",MagicFragment);
	SetCommonData("SECTIONMAGICFRAGMENT",SectionMagicFragment);
	SetCommonData("BURSTRANK",BurstRank);

	if(BurstMode==0)
	{
	SetCommonData("MagicAbsorbShortRange",MagicAbsorbShortRange);
	SetCommonData("MagicAbsorbLongRange",MagicAbsorbLongRange);
	SetCommonData("BurstErazeCircleRangeRate",BurstErazeCircleRangeRate);
	}
	else
	{
	SetCommonData("MagicAbsorbShortRange",MagicAbsorbShortRange*(1+1/4*BurstRank/10000));
	SetCommonData("MagicAbsorbLongRange",MagicAbsorbLongRange*(1+1/4*BurstRank/10000));
	}
	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);
				RushGauge+=Dnum*4/2;
			}
			else
			{
				MagicFragment+=Dnum*4/2;
				SectionMagicFragment+=Dnum*4/2;
				DeleteBulletReCharge+=Dnum;
				DeleteShotNumdraw(Dnum,Dx,Dy,2);
				RushGauge-=Dnum*4/2;
			}
		}
		else
		{
			MagicFragment+=Dnum*4/2;
			SectionMagicFragment+=Dnum*4/2;
			MagicCounter+=Dnum*8;
			DeleteShotNumdraw(Dnum*8,Dx,Dy,1);
		}
		SetCommonData("DeleteBulletNum",0);
	}
yield;
}
}

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

	yield;
}
}
