

task BombCheck
{
loop
{
	if(OnBomb)
	{
		if(SectionMagicFragment>0)
		{
			SectionMagicFragment-=floor(SectionMagicFragment/5000)+1;

			if(BurstMode==1)
			{
				SectionMagicFragment-=floor(SectionMagicFragment/5000)+1;
			}
			if(SectionMagicFragment<0){SectionMagicFragment=0;}
		}
		BurstRank-=12;
		if(BurstRank<0){BurstRank=0;}
		MagicCounter-=floor(MagicCounter/10000)+1;;
		if(MagicCounter<0){MagicCounter=0;}
	}
yield;
}
}


let MainShotCreateItemJudg=0;

function MainShotHit(x,y)
{
	if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Arrange"){return;}
	if(MainShotCreateItemJudg<6)
	{
		MainShotCreateItemJudg+=1;
		return;
	}
	else
	{
		MainShotCreateItemJudg=0;
	}
	let PowerPlus=0.5;
	let CounterPlus=10;
	let ScorePlus=MagicCounter;
	let FragmentPlus=1;

	if(BurstMode==1)
	{
		ScorePlus=MagicCounter*10;
		RushGauge+=1;
	}

	if(Power<1000 && BurstMode==0)
	{
		Power+=PowerPlus;
		if(Power>1000){Power=1000;}
	}

	MagicCounter+=CounterPlus;
	if(MagicCounter>MagicCounterLimit){MagicCounter=MagicCounterLimit;}


	AddScore(ScorePlus);
	MagicFragment+=FragmentPlus;
	SectionMagicFragment+=FragmentPlus;
	//PlaySE("se\seScore.wav");
}

task CreateMigicItem(x,y,type)
{
		if(type==-1)
		{
			Weakness;
			return;
		}

		if(WeaknessCount>0 && type!=-1){return;}
		let DifficultChargeAmp=1;
		let DifficultCounterAmp=1;
		let DifficultScoreAmp=1;
		let DifficultFragmentAmp=1;

		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgItemStar);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		let AnimeNumCount=rand_int(0,14);
		let AnimeNum=0;

		ObjEffect_SetVertexXY(obj, 0, -52/2, -40/2);
		ObjEffect_SetVertexXY(obj, 1, 52/2,  -40/2);
		ObjEffect_SetVertexXY(obj, 2, 52/2, 40/2);
		ObjEffect_SetVertexXY(obj, 3,  -52/2,  40/2);

		ObjEffect_SetVertexUV(obj, 0,  0,  0+80*AnimeNum);
		ObjEffect_SetVertexUV(obj, 1,  104, 0+80*AnimeNum);
		ObjEffect_SetVertexUV(obj, 2, 104,  80+80*AnimeNum);
		ObjEffect_SetVertexUV(obj, 3, 0, 80+80*AnimeNum);

			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,155,255,255,255);
			}	

		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let StandardSpeed=rand(3,10);
		let angle=atan2(GetPlayerY-y,GetPlayerX-x)+180+rand(-150,150);
		if(type==4 || type==41 || type==42 || type==6 || type==61 || type==62)
		{
			StandardSpeed*=1.5;
		}
		if(type==4 || type==41 || type==42 || type==6 || type==61 || type==62)
		{
			StandardSpeed=rand(3,15);
		}
		let speed=StandardSpeed;
		let lightangle=rand(0,360);
		let ZAngle=0;
		let ZRotateAngle=rand(-15,15);
		let ZRotateAngle=0;
		let Scale;
		let DiScale;
		let R;
		let G;
		let B;
		let Alpha=100;
		let VAlpha=25;

		let Alpha=50;
		let VAlpha=25;

		let PowerPlus;
		let CounterPlus;
		let ScorePlus;
		let FragmentPlus=1;
		let RushGaugePlus=0;
		let amp=1;
		let BurstRankPlus=0;


		let RushGaugeAdjustPower=1;
		let RushGaugeAdjustMagic=1;
		let RushGaugeAdjustScore=1;
		let RushGaugeAdjustFragment=1;
		let RushGaugeAdjustRankUp=1;
		let RushGaugeAdjustRankDown=1;

		let LimitPlus=0;
		let CounterPlusBonus=0;

		if(type==1)//緑アイテム　近接撃破時に出現
		{
			Scale=1.5;
			DiScale=0.015;
			R=127;
			G=255;
			B=127;
			PowerPlus=1;
			CounterPlus=12;
			ScorePlus=2*MagicCounter;
			BurstRankPlus=0;
			FragmentPlus=1*1;
			RushGaugePlus=0.15;
		}
		if(type==1.5)//緑アイテム大　近接撃破時に出現
		{
			Scale=2.0;
			DiScale=0.02;
			R=127;
			G=255;
			B=127;
			PowerPlus=1*2;
			CounterPlus=12*2;
			ScorePlus=2*MagicCounter*2;
			BurstRankPlus=0*2;
			FragmentPlus=1*1*2;
			RushGaugePlus=0.15*2;
		}
		if(type==2)//青アイテム　近接打ち込み時に出現
		{
			Scale=1;
			DiScale=0.005;
			R=127;
			G=127;
			B=255;
			PowerPlus=1.5;
			CounterPlus=10;
			ScorePlus=MagicCounter;
		//	BurstRankPlus=-1;
			RushGaugePlus=0.3;
		}
		if(type==3)//得大赤アイテム　撃破時に出現
		{
			Scale=2;
			DiScale=0.020;
			R=255;
			G=127;
			B=127;
			PowerPlus=10;
			CounterPlus=25;
			ScorePlus=20*MagicCounter;
			FragmentPlus=3;
			BurstRankPlus=-30*RushGaugeAdjustRankDown;
			RushGaugePlus=0.5;
		}

		if(type==5)//得大白アイテム　撃破時に出現
		{
			Scale=2;
			DiScale=0.020;
			R=255;
			G=255;
			B=255;
			PowerPlus=5*DifficultChargeAmp;
			CounterPlus=25*DifficultCounterAmp;
			ScorePlus=MagicCounter*200*DifficultScoreAmp;
			BurstRankPlus=5*RushGaugeAdjustRankUp;
			FragmentPlus=3;
			RushGaugePlus=1.5;
			LimitPlus=100;
			CounterPlusBonus=12;
		}
		if(type==6)//小白アイテム1　変換時に出現
		{
			Alpha=100;
			VAlpha=25;
			Scale=1;
			DiScale=0.010;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp;
			CounterPlus=7*DifficultCounterAmp;
			ScorePlus=MagicCounter*10*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
			BurstRankPlus=0.5*RushGaugeAdjustRankUp;
			RushGaugePlus=0.5;
			LimitPlus=20;
			CounterPlusBonus=3;
		}
		if(type==61)//中白アイテム2　変換時に出現
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.2;
			DiScale=0.012;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*2;
			CounterPlus=7*DifficultCounterAmp*2;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*2;
			FragmentPlus=1*DifficultFragmentAmp*2;
			BurstRankPlus=1*RushGaugeAdjustRankUp*2;
			RushGaugePlus=0.5*2;
			LimitPlus=20*2;
			CounterPlusBonus=3*2;
		}
		if(type==62)//大白アイテム3　変換時に出現
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.5;
			DiScale=0.015;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*4;
			CounterPlus=7*DifficultCounterAmp*4;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*4;
			FragmentPlus=1*DifficultFragmentAmp*4;
			BurstRankPlus=1*RushGaugeAdjustRankUp*4;
			RushGaugePlus=0.5*4;
			LimitPlus=20*4;
			CounterPlusBonus=3*4;
		}

		if(type==6.5)//小白アイテム1　変換時に出現
		{
			Alpha=100;
			VAlpha=25;
			Scale=1*1.5;
			DiScale=0.010*1.5;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*3;
			CounterPlus=7*DifficultCounterAmp*3;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*3;
			FragmentPlus=1*DifficultFragmentAmp*3;
			BurstRankPlus=1*RushGaugeAdjustRankUp*3;
			RushGaugePlus=0.5*3;
			LimitPlus=20*3;
			CounterPlusBonus=3*3;
		}
		if(type==61.5)//中白アイテム2　変換時に出現
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.2*1.5;
			DiScale=0.012*1.5;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*2*3;
			CounterPlus=7*DifficultCounterAmp*2*3;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*2*3;
			FragmentPlus=1*DifficultFragmentAmp*2*3;
			BurstRankPlus=1*RushGaugeAdjustRankUp*2*3;
			RushGaugePlus=0.5*2*3;
			LimitPlus=20*2*3;
			CounterPlusBonus=3*2*3;
		}
		if(type==62.5)//大白アイテム3　変換時に出現
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.5*1.5;
			DiScale=0.015*1.5;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*4*3;
			CounterPlus=7*DifficultCounterAmp*4*3;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*4*3;
			FragmentPlus=1*DifficultFragmentAmp*4*3;
			BurstRankPlus=1*RushGaugeAdjustRankUp*4*3;
			RushGaugePlus=0.5*4*3;
			LimitPlus=20*4*3;
			CounterPlusBonus=3*4*3;
		}

		if(type==8)//小白アイテム 近接打ち込み時発生
		{
			Scale=1;
			DiScale=0.010;
			R=255;
			G=255;
			B=255;
			PowerPlus=1.0*DifficultChargeAmp;
			CounterPlus=10*DifficultCounterAmp;
			ScorePlus=MagicCounter*10*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
			BurstRankPlus=1*RushGaugeAdjustRankUp;
			RushGaugePlus=1.5;
			LimitPlus=30;
			CounterPlusBonus=5;
		}

		if(type==85)//小白アイテム　弾消し時発生
		{
			Scale=1;
			DiScale=0.010;
			R=255;
			G=255;
			B=255;
			PowerPlus=1.0*DifficultChargeAmp;
			CounterPlus=7*DifficultCounterAmp;
			ScorePlus=MagicCounter*10*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
			BurstRankPlus=1*RushGaugeAdjustRankUp;
			RushGaugePlus=0.3;
			LimitPlus=10;
			CounterPlusBonus=3;
		}

		if(type==85.5)//小白アイテム　弾消し時発生
		{
			Scale=1*2;
			DiScale=0.010*2;
			R=255;
			G=255;
			B=255;
			PowerPlus=1.0*DifficultChargeAmp*10;
			CounterPlus=7*DifficultCounterAmp*10;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*10;
			FragmentPlus=1*DifficultFragmentAmp*10;
			BurstRankPlus=1*RushGaugeAdjustRankUp*10;
			RushGaugePlus=0.3*10;
			LimitPlus=10*10;
			CounterPlusBonus=3*10;
		}

		if(type==10)//白アイテム近接敵撃破
		{
			Scale=1.5;
			DiScale=0.015;
			R=255;
			G=255;
			B=255;
			PowerPlus=0.5;
			CounterPlus=12;
			ScorePlus=2*10*MagicCounter;
			BurstRankPlus=1*RushGaugeAdjustRankUp;
			FragmentPlus=1*1;
			RushGaugePlus=1.0;
			LimitPlus=40;
			CounterPlusBonus=6;
		}
		if(type==10.5)//白アイテム
		{
			Scale=2.0;
			DiScale=0.02;
			R=255;
			G=255;
			B=255;
			PowerPlus=0.5*2;
			CounterPlus=12*2;
			ScorePlus=2*10*MagicCounter*2;
			BurstRankPlus=1*RushGaugeAdjustRankUp*2;
			FragmentPlus=1*1*2;
			RushGaugePlus=1.0*2;
			LimitPlus=40*2;
			CounterPlusBonus=6*2;
		}
		if(type==101)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=0;
			G=250;
			B=154;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=10*DifficultCounterAmp;
			ScorePlus=MagicCounter*10*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;

			ScorePlus+=(GetPlayerLife-1)*300000;
			ScorePlus+=(GetPlayerBomb)*100000;
			ScorePlus+=50*SectionMagicFragment;
		}

		if(type==102)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=255;
			G=100;
			B=0;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=10*2*DifficultCounterAmp;
			ScorePlus=MagicCounter*20*DifficultScoreAmp;
			FragmentPlus=2*DifficultFragmentAmp;

			ScorePlus+=(GetPlayerLife-1)*300000*2;
			ScorePlus+=(GetPlayerBomb)*100000*2;
			ScorePlus+=50*SectionMagicFragment*2;
		}

		if(type==103)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=148;
			G=0;
			B=211;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=10*3*DifficultCounterAmp;
			ScorePlus=MagicCounter*30*DifficultScoreAmp;
			FragmentPlus=3*DifficultFragmentAmp;

			ScorePlus+=(GetPlayerLife-1)*300000*3;
			ScorePlus+=(GetPlayerBomb)*100000*3;
			ScorePlus+=50*SectionMagicFragment*3;
		}

		if(type==104)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=0;
			G=100;
			B=255;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=10*4*DifficultCounterAmp;
			ScorePlus=MagicCounter*40*DifficultScoreAmp;
			FragmentPlus=4*DifficultFragmentAmp;

			ScorePlus+=(GetPlayerLife-1)*300000*4;
			ScorePlus+=(GetPlayerBomb)*100000*4;
			ScorePlus+=50*SectionMagicFragment*4;
		}
		if(type==105)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=255;
			G=255;
			B=0;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=10*5*DifficultCounterAmp;
			ScorePlus=MagicCounter*50*DifficultScoreAmp;
			FragmentPlus=5*DifficultFragmentAmp;

			ScorePlus+=(GetPlayerLife-1)*300000*5;
			ScorePlus+=(GetPlayerBomb)*100000*5;
			ScorePlus+=50*SectionMagicFragment*5;
		}
		if(type==106)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			let Mcolor=MagicHueDifine(rand_int(0,360));
			R=Mcolor[0];
			G=Mcolor[1];
			B=Mcolor[2];
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=10*10*DifficultCounterAmp;
			ScorePlus=MagicCounter*100*DifficultScoreAmp;
			FragmentPlus=10*DifficultFragmentAmp;

			ScorePlus+=(GetPlayerLife-1)*300000*10;
			ScorePlus+=(GetPlayerBomb)*100000*10;
			ScorePlus+=50*SectionMagicFragment*10;
		}

		if(!RushFlag)
		{
			LimitPlus=0;
			if(BurstMode)
			{
				CounterPlus*=3;
			}
		}
		else
		{
			FragmentPlus*=2;
		}
		DiScale=0.00;
		Scale*=0.75;
			Alpha=150;
			VAlpha=25;
		if(type<100)
		{

		}
		if(type>100)
		{

		}
		else if(type==-1 || type==2 || type==2 || type==8 || type==7 || type==75 || type==9 || type==15 || type==25 || type==45)
		{
			loop(5)
			{
				lightangle+=12;
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha+VAlpha*cos(lightangle),R,G,B);
				}
				Obj_SetAngle(obj,angle);
				Obj_SetSpeed(obj,speed);
				speed-=StandardSpeed/15;
				Scale-=DiScale*2;
				ObjEffect_SetScale(obj,Scale,Scale);
			AnimeNumCount+=1;
			if(AnimeNumCount%15<=7)
			{
			AnimeNum=trunc(AnimeNumCount%15);
			ObjEffect_SetAngle(obj,0,0,ZAngle);
			}
			else
			{
			AnimeNum=trunc(15-AnimeNumCount%15);
			ObjEffect_SetAngle(obj,0,180,ZAngle);
			}
			ObjEffect_SetVertexUV(obj, 0,  0,  0+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 1,  104, 0+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 2, 104,  80+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 3, 0, 80+80*AnimeNum);

				yield;
			}
		}
		else
		{
			speed=speed*2;
			StandardSpeed=speed;
			loop(15)
			{
				lightangle+=12;
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha+VAlpha*cos(lightangle),R,G,B);
				}
				Obj_SetAngle(obj,angle);
				Obj_SetSpeed(obj,speed);
				speed-=StandardSpeed/15;
				Scale-=DiScale*2;
				ObjEffect_SetScale(obj,Scale,Scale);
			AnimeNumCount+=1;
			if(AnimeNumCount%15<=7)
			{
			AnimeNum=trunc(AnimeNumCount%15);
			ObjEffect_SetAngle(obj,0,0,ZAngle);
			}
			else
			{
			AnimeNum=trunc(15-AnimeNumCount%15);
			ObjEffect_SetAngle(obj,0,180,ZAngle);
			}
			ObjEffect_SetVertexUV(obj, 0,  0,  0+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 1,  104, 0+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 2, 104,  80+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 3, 0, 80+80*AnimeNum);

	
				yield;
			}
		}

		let AddRushFlag=false;
		if(type==2 || type==5 || type==6 || type==61 || type==62 || type==66 || type==8 || type==85 || type==10)
		{
			if(RushFlag || CoolFlag){}
			else{AddRushFlag=true;}
		}

		while(!Obj_BeDeleted(obj))
		{
		//	Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(sangle),Obj_GetY(obj)+speed*sin(sangle));
			ZAngle+=ZRotateAngle;
			ObjEffect_SetAngle(obj,0,0,ZAngle);
			Scale-=DiScale;
			ObjEffect_SetScale(obj,Scale,Scale);
			if(speed<30)
			{
			speed+=0.25;
			}
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha+VAlpha*cos(lightangle),R,G,B);
			}
			let sangle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetAngle(obj,sangle);
			Obj_SetSpeed(obj,speed);
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<35)
			{
				if(Power<1000 && BurstMode==0)
				{
					Power+=PowerPlus;
					if(Power>1000){Power=1000;}
				}

				if(MagicCounter<MagicCounterLimit)
				{
					MagicCounter+=CounterPlus;
					if(MagicCounter>MagicCounterLimit){MagicCounter=MagicCounterLimit;}
				}
				MagicCounterLimit+=LimitPlus;
				AddScore(ScorePlus);
				MagicFragment+=FragmentPlus;
				SectionMagicFragment+=FragmentPlus;
				BurstRank+=BurstRankPlus;
				if(BurstRank>10000){BurstRank=10000;}
				if(BurstRank<0){BurstRank=0;}
				if(absolute(RushGauge)!=1000)
				{
				RushGauge+=RushGaugePlus;
				if(RushGauge>1000){RushGauge=1000;}
				}

				PlaySE(SE[7]);

				Obj_Delete(obj);
			}
			AnimeNumCount+=1;
			if(AnimeNumCount%15<=7)
			{
			AnimeNum=trunc(AnimeNumCount%15);
			ObjEffect_SetAngle(obj,0,0,ZAngle);
			}
			else
			{
			AnimeNum=trunc(15-AnimeNumCount%15);
			ObjEffect_SetAngle(obj,0,180,ZAngle);
			}
			ObjEffect_SetVertexUV(obj, 0,  0,  0+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 1,  104, 0+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 2, 104,  80+80*AnimeNum);
			ObjEffect_SetVertexUV(obj, 3, 0, 80+80*AnimeNum);

		yield;
		}
}

task Weakness
{
	let WCount=30;
	if(RushGauge>0)
	{
		WCount=30*(1+RushGauge/1000);
	}
	else if(RushGauge<0)
	{
		WCount=30*(1+0.5*RushGauge/1000);
	}
	if(WeaknessCount<WCount)
	{
		WeaknessCount=WCount;
	}
}
