
task Powor	//powerの値を変化させるタスク。バリア発動やP回復。
{
let ChargeFlag=true;
let RushChargeFlag=true;;
let DefeatCount=0;
let SpecialCount=0;
	if(Power>1000){Power=1000;}
	if(MagicCounter>MagicCounterLimit){MagicCounter=MagicCounterLimit;}
	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;
	//	SetPlayerInvincibility(90);
	//}
	if(GetCommonDataDefault("TrueBossLastAttack",false)==true && GetCommonDataDefault("BossLife",0)>0)
	{
		if(!OnBomb && GetTimeOfPlayerInvincibility==0)
		{
		Power+=1000/600;
		}
		if(Power>1000){Power=1000;}
	}
	if(GetKeyState(VK_USER)==KEY_PUSH && Power>=1000 && BurstModeCount==0 && IsForbidBomb==false && !OnMissed)
	{
	//	Slow(1);

		PlaySE(SE[0]);
		WeaknessCount=0;
		PurityRateCount*=2;
		BurstLevel=3;

	//	Burst;
	//	Shadow(600);

		SetPlayerInvincibility(90);

		if(RushGauge>=1000)
		{
			while(GetKeyState(VK_USER)==KEY_PUSH || GetKeyState(VK_USER)==KEY_HOLD)
			{
			if(SpecialCount>=30)
			{
				PlaySE("seBomb_ReimuA.wav");
				UseRushBurstCount+=1;
				SpecialEffect;
				if(RushGauge>=1000)
				{
					Power=1000;
					RushFlag=true;
					RushChargeFlag=true;
					RushOn;
				}
				break;
			}
			SpecialCount+=1;
			yield;
			}
			SpecialCount=0;
		}

		Burst;
		UseBurstCount+=1;
		Shadow(600);

		loop
		{
			if(BurstMode==0)
			{
				break;
			}
			SetItemCollectLine(500);//アイテム回収されるy座標
			if(GetCommonDataDefault("BurstStop",false)==true)
			{

			}
			else
			{
				Power-=1000/600;
				if(PlayerType=="C" && !RushFlag){Power-=1000/1200;}
				if(OnBomb)
				{
					Power-=1000/600;
					if(PlayerType=="C"&& !RushFlag){Power-=1000/1200;}
				}
				
			}
			if(trunc(RushGauge)>=1000 && RushChargeFlag)
			{
			RushChargeEffect;
			RushChargeFlag=false;
			}

			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;
		}
	Ah_RechargeCheck;
	ChargeFlag=true;
	BL3=4/3;
	if(RushFlag){RushGauge=0;BurstRank+=1000;
	RushChargeFlag=true;
	}
	wait(5);
	//if(RushFlag){MagicCounter*=0.9;}
	if(OnCansellBomb)
	{
		Power=0;
	}
	else
	{
		Power/=2;
	}
	RushFlag=false;
	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;
}

if(trunc(RushGauge)>=1000 && RushChargeFlag)
{
RushChargeEffect;
RushChargeFlag=false;
}

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

if(miss<GetMissCount)
{//ミスしたときに一回実行
	while(MissTime>0){yield;}
	miss+=1;
	RushChargeFlag=true;
	SetPlayerInvincibility(180);
	BulletErase(120);
	BurstRank*=0.5;
	Power+=250;
	PurityRateCount=0;
	if(Power>1000){Power=1000;}
	MagicCounter*=0.9;
	RushGauge*=0.75;
	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
{
	BL3=5/3;
}

task StartDeleteShot
{
	SetPlayerInvincibility(90);

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

	BulletErase(30);
}

task EndDeleteShot
{
	SetPlayerInvincibility(90);
	BulletErase(30);
}

task CommonDataSetting
{
SetCommonData("PLAYERTYPE",PlayerType);
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("MAGICCOUNTERLIMIT",MagicCounterLimit);
	SetCommonData("SECTIONMAGICFRAGMENT",SectionMagicFragment);
	SetCommonData("BURSTRANK",BurstRank);
	SetCommonData("RUSHGAUGE",RushGauge);
	SetCommonData("RUSHFLAG",RushFlag);
	yield;
}
}

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

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

		MagicFragment+=Dnum;
		SectionMagicFragment+=Dnum;

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

			}
			else
			{
				DeleteBulletReCharge+=Dnum/2;
				DeleteShotNumdraw(Dnum/2,Dx,Dy,2);
			}
		}
		else
		{
			MagicCounter+=Dnum*8;
			DeleteShotNumdraw(Dnum*8,Dx,Dy,1);
		}
		if(Power>1000){Power=1000;}
		if(MagicCounter>MagicCounterLimit){MagicCounter=MagicCounterLimit;}
		SetCommonData("DeleteBulletNum",0);
	}
yield;
}
}

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

	yield;
}
}
