let dirCurrent = GetCurrentScriptDirectory();
let typeEnd = 0;
let END_FAILED = 1;
let END_SUCCESS = 2;
let BossPosition=[0,0];
let SpellCardBonus=10;
let DefeatTime=0;
let objScene;
let objBoss;
let pathUseSpell = dirCurrent ~ "../se/seUseSpellCard.wav";

@Initialize
{
	SetCommonData("GrazeAchieve",500);
	LoadSound(pathUseSpell);
	Play_SE(pathUseSpell);
	SetAutoDeleteObject(true);
	objBoss = GetEnemyBossObjectID();
	objScene = GetEnemyBossSceneObjectID();

	T_SCB();
	MagicCircle();
}

@MainLoop
{
	DefeatTime+=1;
	if(length(GetEnemyBossObjectID)>0)
	{
		BossPosition[0]=ObjRender_GetX(GetEnemyBossObjectID()[0]);
		BossPosition[1]=ObjRender_GetY(GetEnemyBossObjectID()[0]);
	}
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_END_BOSS_STEP)
	{
		//次の敵動作へ
		if(typeEnd == 0)
		{
			//スペルカード取得失敗
			typeEnd = END_FAILED;
		}
	}
	case(EV_GAIN_SPELL)
	{
		LoadSound(dirCurrent ~ "../se/seGetSpellCardBonus.wav");
		Play_SE(dirCurrent ~ "../se/seGetSpellCardBonus.wav");
		//スペルカード取得

		let ChallengeArray=[];
		let GetArray=[];
		let FirstArray=[];
		let ScoreArray=[];
		let EarlyArray=[];
		alternative(GetAreaCommonData("TUNING","PlayerCharacter",0))
		case(0)
		{
			ChallengeArray=GetAreaCommonData("SPELL_RECORD","Reimu_Challenge",[]);
			GetArray=GetAreaCommonData("SPELL_RECORD","Reimu_Get",[]);
			FirstArray=GetAreaCommonData("SPELL_RECORD","Reimu_First",[]);
			ScoreArray=GetAreaCommonData("SPELL_RECORD","Reimu_Score",[]);
			EarlyArray=GetAreaCommonData("SPELL_RECORD","Reimu_Early",[]);
		}
		case(1)
		{
			ChallengeArray=GetAreaCommonData("SPELL_RECORD","Marisa_Challenge",[]);
			GetArray=GetAreaCommonData("SPELL_RECORD","Marisa_Get",[]);
			FirstArray=GetAreaCommonData("SPELL_RECORD","Marisa_First",[]);
			ScoreArray=GetAreaCommonData("SPELL_RECORD","Marisa_Score",[]);
			EarlyArray=GetAreaCommonData("SPELL_RECORD","Marisa_Early",[]);
		}

		if(!IsReplay)
		{
			if(GetArray[GetCommonData("SpellNumber",0)]==0)
			{
				FirstArray[GetCommonData("SpellNumber",0)]=ChallengeArray[GetCommonData("SpellNumber",0)];
				alternative(GetAreaCommonData("TUNING","PlayerCharacter",0))
				case(0){SetAreaCommonData("SPELL_RECORD","Reimu_First",FirstArray);}
				case(1){SetAreaCommonData("SPELL_RECORD","Marisa_First",FirstArray);}
			}

			if(ScoreArray[GetCommonData("SpellNumber",0)]<SpellCardBonus)
			{
				ScoreArray[GetCommonData("SpellNumber",0)]=SpellCardBonus;
				alternative(GetAreaCommonData("TUNING","PlayerCharacter",0))
				case(0){SetAreaCommonData("SPELL_RECORD","Reimu_Score",ScoreArray);}
				case(1){SetAreaCommonData("SPELL_RECORD","Marisa_Score",ScoreArray);}
			}

			if(EarlyArray[GetCommonData("SpellNumber",0)]>DefeatTime)
			{
				EarlyArray[GetCommonData("SpellNumber",0)]=DefeatTime;
				alternative(GetAreaCommonData("TUNING","PlayerCharacter",0))
				case(0){SetAreaCommonData("SPELL_RECORD","Reimu_Early",EarlyArray);}
				case(1){SetAreaCommonData("SPELL_RECORD","Marisa_Early",EarlyArray);}
			}

			GetArray[GetCommonData("SpellNumber",0)]=GetArray[GetCommonData("SpellNumber",0)]+1;
			alternative(GetAreaCommonData("TUNING","PlayerCharacter",0))
			case(0){SetAreaCommonData("SPELL_RECORD","Reimu_Get",GetArray);}
			case(1){SetAreaCommonData("SPELL_RECORD","Marisa_Get",GetArray);}
		}

		typeEnd = END_SUCCESS;
		let GA=GetCommonData("GrazeAchieve",0);
		let M=100+GetGraze/GA*100;
		M=floor(M);
		SpellCardBonus=floor(SpellCardBonus*M/100);
		if(SpellCardBonus>GetCommonData("Ori_SpellCardBonus",10)*2)
		{
			SpellCardBonus=GetCommonData("Ori_SpellCardBonus",10)*2;
		}
		AddScore(SpellCardBonus);
	}
}

task T_SCB
{
	let GrazeRate=1;
	let MissCount=0;
	let BombCount=0;
	let SCB_GetFlag=1;
	let OriSCB=GetCommonData("Ori_SpellCardBonus",10);
	//OriSCB=ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE);
	let OriTimer=ObjEnemyBossScene_GetInfo(objScene,INFO_ORGTIMERF);
	let Timer=ObjEnemyBossScene_GetInfo(objScene,INFO_TIMERF);
	SpellCardBonus=OriSCB;
	let str_SCB=IntToString(SpellCardBonus);
	while(length(str_SCB)<8)
	{
		str_SCB=IntToString(0)~str_SCB;
	}

	DrawSCB;
	SetCommonData("SpellCardBonus",SpellCardBonus);

	loop(300)
	{
		GrazeRate=1+GetGraze*0.01;
	//	SpellCardBonus=OriSCB*GrazeRate;//SCBグレイズ倍率上昇
	//	SpellCardBonus=OriSCB+GetGraze*500;//SCBグレイズ倍率上昇
		str_SCB=IntToString(SpellCardBonus);
		while(length(str_SCB)<8)
		{
		str_SCB=IntToString(0)~str_SCB;
		}
		MissCount=ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT);
		BombCount=ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT);
		if(MissCount!=0 || BombCount!=0){SCB_GetFlag=0;}
		yield;
	}
	OriTimer-=300;
	if(GetCommonData("DurableSpell",false))
	{
		SpellCardBonus=OriSCB;
		SetCommonData("SpellCardBonus",SpellCardBonus);
		str_SCB=IntToString(SpellCardBonus);
	}
	while(typeEnd==0)
	{
		if(!GetCommonData("DurableSpell",false))
		{
			Timer=ObjEnemyBossScene_GetInfo(objScene,INFO_TIMERF);
			SpellCardBonus=OriSCB*Timer/OriTimer;//SCB時間現象
			GrazeRate=1+GetGraze*0.01;
		//	SpellCardBonus*=GrazeRate;//SCBグレイズ倍率上昇
		//	SpellCardBonus=OriSCB+GetGraze*500;//SCBグレイズ倍率上昇
			SpellCardBonus=floor(SpellCardBonus);
			SetCommonData("SpellCardBonus",SpellCardBonus);
			str_SCB=IntToString(SpellCardBonus);
		}
		while(length(str_SCB)<8)
		{
			str_SCB=IntToString(0)~str_SCB;
		}
		MissCount=ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT);
		BombCount=ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT);
		if(MissCount!=0 || BombCount!=0){SCB_GetFlag=0;}
		yield;
	}

	task DrawSCB
	{
		let DrawY=30;
		let text="Bonus";
		ascent(i in 0..length(text))
		{
			DrawLetter(280-144-8*length(text)+8*i,DrawY,text[i]);
			loop(1){yield;}
		}

		ascent(i in 0..length(str_SCB))
		{
			DrawNum(360-144-8*length(str_SCB)+8*i,DrawY,i);
			loop(1){yield;}
		}

		text="History";
		ascent(i in 0..length(text))
		{
			DrawLetter(284-8*length(text)+8*i,DrawY,text[i]);
			loop(1){yield;}
		}

		text="×";
		ascent(i in 0..length(text))
		{
			DrawLetter2(176,DrawY+11,text);
			loop(1){yield;}
		}

		ascent(i in 0..1)
		{
			DrawMagnification(184+4+8*i,DrawY+11,i);
			loop(1){yield;}
		}

		DrawLetter2(194,DrawY+10,".");
		loop(1){yield;}

		ascent(i in 1..3)
		{
			DrawMagnification(184+8*(i+1),DrawY+11,i);
			loop(1){yield;}
		}

		let ChallengeArray=[];
		let GetArray=[];

		alternative(GetAreaCommonData("TUNING","PlayerCharacter",0))
		case(0)
		{
			ChallengeArray=GetAreaCommonData("SPELL_RECORD","Reimu_Challenge",[]);
			GetArray=GetAreaCommonData("SPELL_RECORD","Reimu_Get",[]);
		}
		case(1)
		{
			ChallengeArray=GetAreaCommonData("SPELL_RECORD","Marisa_Challenge",[]);
			GetArray=GetAreaCommonData("SPELL_RECORD","Marisa_Get",[]);
		}

		let str_gnum=IntToString(GetArray[GetCommonData("SpellNumber",0)]);
		ascent(i in 0..length(str_gnum))
		{
			DrawNum2(320-8*length(str_gnum)+8*i,DrawY,str_gnum[i]);
			loop(1){yield;}
		}

		DrawLetter(324,DrawY,"/");
		loop(1){yield;}

		let str_cnum=IntToString(ChallengeArray[GetCommonData("SpellNumber",0)]);
		ascent(i in 0..length(str_cnum))
		{
			DrawNum2(360-8*length(str_cnum)+8*i,DrawY,str_cnum[i]);
			loop(1){yield;}
		}

		task DrawNum(x,y,number)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, str_SCB[number]);
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj,16+x);
			ObjRender_SetY(obj, y);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let Alpha=255;
			let scale=3;
			loop(15)
			{
				scale-=2/15;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				if(GetPlayerY<=160)
				{		
					Alpha=(GetPlayerY/160)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			while(typeEnd==0)
			{
				if(!SCB_GetFlag){break;}
				ObjText_SetText(obj, str_SCB[number]);
				if(GetPlayerY<=160)
				{		
				Alpha=(GetPlayerY/160)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			Obj_Delete(obj);
			if(typeEnd==0 && number==0)
			{
			let text2="false";
			ascent(i in 0..length(text2))
			{
				DrawLetter(360-144-8*length(text2)+8*i,DrawY,text2[i]);
			}
			}
		}

		task DrawNum2(x,y,number)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, number);
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj,16+x);
			ObjRender_SetY(obj, y);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let Alpha=255;
			let scale=3;
			loop(15)
			{
				scale-=2/15;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				if(GetPlayerY<=128)
				{		
					Alpha=(GetPlayerY/128)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			while(typeEnd==0)
			{
				if(GetPlayerY<=128)
				{		
					Alpha=(GetPlayerY/128)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			Obj_Delete(obj);
		}

		task DrawLetter(x,y,letter)
		{
//			let color=[255,255,255];
//			color=SetSpellCardColor(Name);

			let obj = ObjText_Create();
			ObjText_SetText(obj,letter);
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj,16+x);
			ObjRender_SetY(obj, y);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let Alpha=255;
			let scale=3;
			loop(15)
			{
				scale-=2/15;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				if(GetPlayerY<=128)
				{		
					Alpha=(GetPlayerY/128)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			while(typeEnd==0)
			{				
				if(GetPlayerY<=128)
				{		
					Alpha=(GetPlayerY/128)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			Obj_Delete(obj);
		}

		task DrawMagnification(x,y,number)
		{
			let GA=GetCommonData("GrazeAchieve",0);
			let M=100+GetGraze/GA*100;
			let obj = ObjText_Create();
			ObjText_SetText(obj, IntToString(M%(10^(2-number+1))/(10^(2-number))));
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj,16+x);
			ObjRender_SetY(obj, y);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let Alpha=255;
			let scale=3;
			loop(15)
			{
				scale-=2/15;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				if(GetPlayerY<=160)
				{		
					Alpha=(GetPlayerY/160)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			while(typeEnd==0)
			{
				if(!SCB_GetFlag){break;}
				let M=100+GetGraze/GA*100;
				ObjText_SetText(obj, IntToString(M%(10^(2-number+1))/(10^(2-number))));
				if(GetPlayerY<=160)
				{		
				Alpha=(GetPlayerY/160)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			Obj_Delete(obj);
		}

		task DrawLetter2(x,y,letter)
		{
//			let color=[255,255,255];
//			color=SetSpellCardColor(Name);

			let obj = ObjText_Create();
			ObjText_SetText(obj,letter);
			ObjText_SetFontSize(obj, 12);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
//			ObjText_SetFontColorBottom(obj, color[0], color[1], color[2]);
			ObjText_SetFontBorderType(obj, BORDER_NONE);
			ObjText_SetFontBorderColor(obj,0, 255, 0);
			ObjText_SetFontBorderWidth(obj, 0);
			Obj_SetRenderPriorityI(obj, 72);
			ObjRender_SetX(obj,16+x);
			ObjRender_SetY(obj, y);
			//ObjText_SetFontType(obj,"ＭＳ 明朝");

			ObjText_SetMaxWidth(obj,360);
			let Alpha=255;
			let scale=3;
			loop(15)
			{
				scale-=2/15;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				if(GetPlayerY<=128)
				{		
					Alpha=(GetPlayerY/128)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			while(typeEnd==0)
			{
				if(!SCB_GetFlag){break;}		
				if(GetPlayerY<=128)
				{		
					Alpha=(GetPlayerY/128)*255;
				}
				else{Alpha=255;}
				ObjRender_SetAlpha(obj,Alpha);
				yield;
			}
			Obj_Delete(obj);
		}

	}
}

task MagicCircle()
{
	let AX=rand(0,360);
	let AXP=rand(1.5,2.5)*(floor(rand(0,1.999))*2-1);
	let AY=rand(0,360);
	let AYP=rand(1.5,2.5)*(floor(rand(0,1.999))*2-1);
	let AZ=rand(0,360);
	let AZP=3;
	let AX2=rand(0,360);
	let AXP2=rand(1.5,2.5)*(floor(rand(0,1.999))*2-1);
	let AY2=rand(0,360);
	let AYP2=rand(1.5,2.5)*(floor(rand(0,1.999))*2-1);
	let AZ2=rand(0,360);
	let AZP2=3;

	let color=[255,255,255];

	if(GetAreaCommonData("TUNING","Effect",1)==1)
	{
		MC(AX,AXP,AY,AYP,AZ,AZP);
		MC(AX2,AXP2,AY2,AYP2,AZ2,AZP2);
	}

	task MC(AngleX,AngleXPlus,AngleY,AngleYPlus,AngleZ,AngleZPlus)
	{
		let ex;
		let ey;
		let objBoss = GetEnemyBossObjectID()[0];
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/Default_MagicCircle.png");//オブジェクトとテスクチャを関連付け
		ObjRender_SetPosition(obj, 0, 0, 0);
		Obj_SetRenderPriority(obj, 0.31);
		ObjSprite2D_SetSourceRect(obj, 0, 0,256, 256);
		ObjSprite2D_SetDestRect(obj, -128, -128, 128, 128);
	//	ObjRender_SetColor(obj, 150, 150, 150);
		ObjRender_SetAlpha(obj, 255);

		let AlphaRate=1;
		let scale=0;
		ascent(i in 0 .. 60)
		{
			ex=ObjRender_GetX(objBoss);
			ey=ObjRender_GetY(objBoss);
			ObjRender_SetPosition(obj, ex, ey, 0);
			let alpha = i/120*AlphaRate;
			ObjRender_SetColor(obj, color[0]*alpha, color[1]*alpha, color[2]*alpha);
		//	ObjRender_SetScaleXYZ(obj, 2*alpha, 2*alpha, 2*alpha);
			ObjRender_SetAngleXYZ(obj,AngleX,AngleY,AngleZ);
			MCBlur(ex,ey,alpha*AlphaRate,scale,AngleX,AngleY,AngleZ);
			AngleX+=AngleXPlus;
			AngleY+=AngleYPlus;
			AngleZ+=AngleZPlus;
			if(length(GetEnemyBossObjectID())>0)
			{
				let Dis=((ObjRender_GetY(GetEnemyBossObjectID()[0])-GetPlayerY)^2+(ObjRender_GetX(GetEnemyBossObjectID()[0])-GetPlayerX)^2)^0.5;
				if(Dis<150)
				{
					AlphaRate=0.1+0.9*Dis/150;
				}
				else
				{
					AlphaRate=1;
				}
				scale+=1/60;
				ObjRender_SetScaleXYZ(obj, scale, scale, scale);
			}
			if(typeEnd!=0){break;}
			yield;
		}
		while(typeEnd == 0)
		{
			if(length(GetEnemyBossObjectID())>0)
			{
				ex=ObjRender_GetX(GetEnemyBossObjectID()[0]);
				ey=ObjRender_GetY(GetEnemyBossObjectID()[0]);
			}
			ObjRender_SetPosition(obj, ex, ey, 0);
			let alpha = 0.5*AlphaRate;
			ObjRender_SetColor(obj, color[0]*alpha, color[1]*alpha, color[2]*alpha);
			ObjRender_SetAngleXYZ(obj,AngleX,AngleY,AngleZ);
			MCBlur(ex,ey,AlphaRate,1,AngleX,AngleY,AngleZ);
			AngleX+=AngleXPlus;
			AngleY+=AngleYPlus;
			AngleZ+=AngleZPlus;
			if(length(GetEnemyBossObjectID())>0)
			{
				let Dis=((ObjRender_GetY(GetEnemyBossObjectID()[0])-GetPlayerY)^2+(ObjRender_GetX(GetEnemyBossObjectID()[0])-GetPlayerX)^2)^0.5;
				if(Dis<150)
				{
					AlphaRate=0.1+0.9*Dis/150;
				}
				else
				{
					AlphaRate=1;
				}
			}
			yield;
		}
		if(typeEnd == END_FAILED)
		{
			descent(i in 0 .. 60)
			{
				if(length(GetEnemyBossObjectID())>0)
				{
					ex=ObjRender_GetX(GetEnemyBossObjectID()[0]);
					ey=ObjRender_GetY(GetEnemyBossObjectID()[0]);
				}
				ObjRender_SetPosition(obj, ex, ey, 0);
				let alpha = i/120;
				ObjRender_SetColor(obj, color[0]*alpha, color[1]*alpha, color[2]*alpha);
				ObjRender_SetAngleXYZ(obj,AngleX,AngleY,AngleZ);
				MCBlur(ex,ey,alpha,1,AngleX,AngleY,AngleZ);
				AngleX+=AngleXPlus;
				AngleY+=AngleYPlus;
				AngleZ+=AngleZPlus;
				yield;
			}

			Obj_Delete(obj);
			loop(60){yield;}
		//	CloseScript(GetOwnScriptID());
			return;
		}
		else if(typeEnd == END_SUCCESS)
		{
			descent(i in 0 .. 30)
			{
				if(length(GetEnemyBossObjectID())>0)
				{
					ex=ObjRender_GetX(GetEnemyBossObjectID()[0]);
					ey=ObjRender_GetY(GetEnemyBossObjectID()[0]);
				}
				ObjRender_SetPosition(obj, ex, ey, 0);
				let alpha = i/60;
				ObjRender_SetColor(obj, color[0]*alpha, color[1]*alpha, color[2]*alpha);
				ObjRender_SetScaleXYZ(obj, 4*(0.5-alpha), 4*(0.5-alpha), 4*(0.5-alpha));
				ObjRender_SetAngleXYZ(obj,AngleX,AngleY,AngleZ);
				MCBlur(ex,ey,alpha,4*(0.5-alpha),AngleX,AngleY,AngleZ);
				AngleX+=AngleXPlus;
				AngleY+=AngleYPlus;
				AngleZ+=AngleZPlus;
				yield;
			}
			ascent(i in 0 .. 30)
			{
				ex=GetPlayerX;
				ey=GetPlayerY;
				ObjRender_SetPosition(obj, ex, ey, 0);
				let alpha = i/60;
				ObjRender_SetColor(obj, color[0]*alpha, color[1]*alpha, color[2]*alpha);
				ObjRender_SetScaleXYZ(obj, 4*(0.5-alpha), 4*(0.5-alpha), 4*(0.5-alpha));
				ObjRender_SetAngleXYZ(obj,AngleX,AngleY,AngleZ);
				MCBlur(ex,ey,alpha,4*(0.5-alpha),AngleX,AngleY,AngleZ);
				AngleX+=AngleXPlus;
				AngleY+=AngleYPlus;
				AngleZ+=AngleZPlus;
				yield;
			}
			Obj_Delete(obj);
			loop(60){yield;}
			CloseScript(GetOwnScriptID());
			return;
		}
		Obj_Delete(obj);
	}

	task MCBlur(ex,ey,alpha,scale,AngleX,AngleY,AngleZ)
	{
		let alphaMax=alpha/8;
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"img/Default_MagicCircle.png");//オブジェクトとテスクチャを関連付け
		ObjRender_SetPosition(obj, 0, 0, 0);
		Obj_SetRenderPriority(obj, 0.31);
		ObjSprite2D_SetSourceRect(obj, 0, 0,256, 256);
		ObjSprite2D_SetDestRect(obj, -128, -128, 128, 128);
//		ObjRender_SetColor(obj, 150, 150, 150);
		ObjRender_SetAlpha(obj, 255);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		descent(i in 0 .. 15)
		{
			ObjRender_SetPosition(obj, ex, ey, 0);
			let alpha = alphaMax*i/15;
			ObjRender_SetColor(obj, color[0]*alpha, color[1]*alpha, color[2]*alpha);
			ObjRender_SetAngleXYZ(obj,AngleX,AngleY,AngleZ);
			yield;
		}
		Obj_Delete(obj);
	}
}

function HueDifine(HueCount)
{
let ColorRed=0;
let ColorGreen=0;
let ColorBlue=0;
let MinColor=0;
while(HueCount>360){HueCount-=360;}
while(HueCount<=0){HueCount+=360;}
	if(0<HueCount && HueCount<=60)
	{
		ColorRed=255;
		ColorGreen=255*(HueCount)/60;
		ColorBlue=0;
	}
	else if(HueCount<=120)
	{
		ColorRed=255*(120-HueCount)/60;
		ColorGreen=255;
		ColorBlue=0;
	}
	else if(HueCount<=180)
	{
		ColorRed=0;
		ColorGreen=255;
		ColorBlue=255*(HueCount-120)/60;
	}
	else if(HueCount<=240)
	{
		ColorRed=0;
		ColorGreen=255*(240-HueCount)/60;
		ColorBlue=255;
	}
	else if(HueCount<=300)
	{
		ColorRed=255*(HueCount-240)/60;
		ColorGreen=0;
		ColorBlue=255;
	}
	else if(HueCount<=360)
	{
		ColorRed=255;
		ColorGreen=0;
		ColorBlue=255*(360-HueCount)/60;
	}
	return([ColorRed,ColorGreen,ColorBlue]);
}

task Play_SE(se)
{
	let objSE=ObjSound_Create;
	ObjSound_Load(objSE,se);
	let MaxVulume=GetAreaCommonData("TUNING","Setting",[])[1];
	ObjSound_SetVolumeRate(objSE,MaxVulume);
	ObjSound_Play(objSE);
}