#include"./SatoriSkeleton.txt"
let Declare = true;
let Type = "PURE";

let CLICK = 2;
let Value = 30;
let GRAPHIC = DS_BALL_BS_RED;
let M = -1;
let A2 = 0;
let TURNER = 61;
let angle3 = 45;
@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){ 
		SetScriptResult(5200*1.8)
	}
	
	case(EV_REQUEST_TIMER) { SetScriptResult(40); }
}

@MainLoop{

	if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)==(5)&&CLICK==2){
		PlaySoundA1(28, 100, 1);
		CLICK=3;
		}
		
	if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)==(4)&&CLICK==3){
		PlaySoundA1(28, 100, 1);
		CLICK=4;
		}
		
	if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)==(3)&&CLICK==4){
		PlaySoundA1(28, 100, 1);
		CLICK=5;
		}
		
	if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)==(2)&&CLICK==5){
		PlaySoundA1(28, 100, 1);
		CLICK=6;
		}
		
	if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)==(1)&&CLICK==6){
		PlaySoundA1(28, 100, 1);
		CLICK=7;
		}
		
	if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)==(0)&&CLICK==7){
		PlaySoundA1(28, 100, 1);
		CLICK=8;
		}
	
	if(ObjMove_GetSpeed(objBoss)<=0){
		ObjSprite2D_SetSourceRect(objBoss, 0, 0, 128, 128);
		}
	
	if(animation==0){
		//ObjMove_SetPosition(objBoss, GetStgFrameWidth/2-90, GetStgFrameHeight/2);
		ObjMove_SetDestAtFrame(objBoss, GetStgFrameWidth/2, 110, 100);
		ObjSprite2D_SetSourceRect(objBoss, 128*2, 128*3, 128*3, 128*4);
		///ObjRender_SetAlpha(objBoss, 0);
		///Entrance;
		}
	animation++;
	
	
	if(animation==10){
		///BossCut(objBoss, "Traditionalism \"Drawing Reality By Hand\"", "./Okina_Stand.png");
		
		let Oki_Stand = GetCurrentScriptDirectory~"SatoriDeclare.png";
		ObjCutin_SetSpellcardS4("Recollection \"National Anthem of Yamatai\"", Oki_Stand, AYA, 255, 100, 100);
		ObjCutin_LaunchS3(YABUSAME, Oki_Stand, "Normal");
		//ObjMove_SetDestAtFrame(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 70);
		}
	
	if(animation>=120){
		frame++;
		shot++;
		
		if(FreuMove==false){
			//ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32);
			}
		
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){
			Die(objBoss);
			}
			
		if(shot==15){
			//Concentration_True(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(0, 360), 5, 60, 5, 1, -4, 40, objBoss);
			Concentration_True(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(0, 360), 5, 60, 3, 5, -4, 30, objBoss);
			//Concentration_True(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(0, 360), 5, 120, 2, 5, 4, 40, objBoss);
			Concentration_True(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(0, 360), 5, 120, 5, 6, 4, 30, objBoss);
			PlaySoundA1(31, 100, 1);
			//shot=-100;
			BossTitleCard;
			SetForbidPlayerShot(true);
			Pyon;
			}
			
		if(frame==60){
			let num = 6;
			PlaySoundA1(23, 50, 1);
			loop(num){
				let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 4, -angle, DS_BALL_S_RED, 10);
				let obj1 = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 4, angle, DS_BALL_S_BLUE, 10);
				
				angle+=360/num;
				}
				
			A2++;
			
			if(A2==3*20){
				MoveBoss(objBoss, 60, 80);
				A2=0;
				}
				
			frame-=3;
			angle+=1.2;
			}
			
		if(shot==160){
			let num = 4;
			
			if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)>(10)){
				num = 4;
				}
			
			PlaySoundA1(21, 70, 10);
			loop(num){
				let obj = CreateShotA1(ObjMove_GetX(objBoss)+20*cos(angle1), ObjMove_GetY(objBoss)+20*sin(angle1), 4.5, angle1, DS_BALL_M_PURPLE, 10);
				
				angle1+=360/num;
				}
				
			allow++;
			
			if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)>(10)){
				if(allow<7){
					shot-=1;
					angle1+=2.7;
					}
				
				else{
					allow=0;
					shot-=9;
					angle1+=2.7*10;
					}
				}
				
			else{
				angle1+=2.7;
				shot-=1;
				}
			}
				
		
		
		
		}
	yield;
	}
	
task Die1(tobj){
	loop(1){
		DeleteShotAll(TYPE_ALL, TYPE_FADE);
		}
	Obj_Delete(tobj);
	
	loop(100){
		yield;
		}
	SetForbidPlayerShot(false);
	CloseScript(GetOwnScriptID());
	}	
	
	
task MoveBoss(tobj, mod, time){
	let posX = GetPlayerX+rand(-20, 20);
	let posY = rand(80, 120);
			
	if(posX<=GetStgFrameWidth/6){
		posX=(GetStgFrameWidth/6)+20;
		}
			
	if(posX>=GetStgFrameWidth/6*5){
		posX=(GetStgFrameWidth/6*5)-20;
		}
				
	if(posY>=110){
		posY-=mod*2.1;
		}
				
	if(posY<=80){
		posY+=mod*2.1;
		}
		
	if(posX>ObjMove_GetX(objBoss)){
		ObjSprite2D_SetSourceRect(objBoss, 128*2, 128*3, 128*3, 128*4);
		//AuraMoveRight=true;
		}
		
	if(posX<ObjMove_GetX(objBoss)){
		ObjSprite2D_SetSourceRect(objBoss, 128*2, 128, 128*3, 128*2);
		//AuraMoveLeft=true;
		}
			
	ObjMove_SetDestAtFrame(tobj, posX, posY, time);
	
	}
	
	
task Hermit(x, y, x2, y2, angle, angle2, time, graphic, color){
	let vx=(x2-x)/time;
	let vy=(y2-y)/time;
	let r=0;
	let a=0;
	loop(time){
	angle+=2; angle2+=2;
	x+=vx; y+=vy;
	a+=360/time; r=120-120*cos(a);
	ShrinkShot(x+r*cos(angle), y+r*sin(angle2),graphic, color);
	yield;
	}
	
	}
task ShrinkShot(x, y, graphic,color){
	let obj=ObjShot_Create(OBJ_SHOT);
	ObjShot_Regist(obj);
	let sca=1;
	ObjShot_SetIntersectionEnable(obj, false);
	ObjShot_SetSpellResist(obj,true);
	ObjShot_SetGraphic(obj, graphic);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	if(color=="BLUE"){ObjRender_SetColor(obj,155,155,255);}
	if(color=="GREEN"){ObjRender_SetColor(obj, 155, 255, 155);}
	if(color=="RED"){ObjRender_SetColor(obj, 255, 155, 155);}
	if(color=="PURPLE"){ObjRender_SetColor(obj, 255, 155, 255);}
	if(color=="WHITE"){ObjRender_SetColor(obj, 255, 255, 255);}
	ObjRender_SetAlpha(obj, 60);
	ObjMove_SetPosition(obj, x, y);
	loop(10){
	sca-=1/15;
	///ObjRender_SetScaleXYZ(obj, sca, sca, 1);
	yield;
	}
	Obj_Delete(obj);
	}
	
task BossTitleCard{
	//496, 52
	let graphic = GetCurrentScriptDirectory~ "Explanation.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, graphic);
	Obj_SetRenderPriorityI(obj,36);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 384, 128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, 0, GetStgFrameHeight/2, 0);
	///ObjRender_SetColor(obj, 200, 200, 200);
	//ObjRender_SetScaleXYZ(obj, 0.8, 0.8, NULL);
	ObjRender_SetAlpha(obj, 0);
	ObjRender_SetScaleXYZ(obj, 1, 0, NULL);
	let Y = 0;
	
	let X = 0;
	let alpha = 0;
	let time = 30;
	loop(time){
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, X, GetStgFrameHeight/2, 0);
		ObjRender_SetScaleXYZ(obj, 0.8, Y, NULL);
		X+=GetStgFrameWidth/2/time;
		alpha+=255/time;
		Y+=0.8/time;
		yield;
		}
		
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetPosition(obj, GetStgFrameWidth/2, GetStgFrameHeight/2, 0);
	ObjRender_SetScaleXYZ(obj, 0.8, 0.8, NULL);
	loop(40){
		yield;
		}
		
	loop(time/2){
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj, X, GetStgFrameHeight/2, 0);
		ObjRender_SetScaleXYZ(obj, 0.8, Y, NULL);
		X+=GetStgFrameWidth/2/(time/2);
		alpha-=255/(time/2);
		Y-=0.8/(time/2);
		yield;
		}
		
	Obj_Delete(obj);
	}
	
task Pyon{
	let count = 0;
	while(!Obj_IsDeleted(objBoss)){
		if(GetVirtualKeyState(VK_SHOT) != KEY_FREE && count==0){
			count=1;
			let scale = 1;
			PlaySoundA1(22, 100, 10);
			SetPlayerInvincibilityFrame(20);
			
			loop(8){
				ObjRender_SetScaleXYZ(GetPlayerObjectID, scale, scale, NULL);
				scale+=1/8;
				yield;
				}
			ObjRender_SetScaleXYZ(GetPlayerObjectID, 2, 2, NULL);
			loop(3){
				yield;
				}
				
			loop(8){
				ObjRender_SetScaleXYZ(GetPlayerObjectID, scale, scale, NULL);
				scale-=1/8;
				yield;
				}
				
			ObjRender_SetScaleXYZ(GetPlayerObjectID, 1, 1, NULL);
			
			loop(10){
				yield;
				}
			count=0;
			}
			
		yield;
		}
	
	ObjRender_SetScaleXYZ(GetPlayerObjectID, 1, 1, NULL);	
	SetForbidPlayerShot(false);
	}