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

let CLICK = 0;
let Value = 0.7;
let GRAPHIC = DS_BALL_BS_RED;
let M = -1;
let A2 = 1.5;
let TURNER = 61;
let angle3 = 45;
@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){ 
		SetScriptResult(5200*2.2)
	}
	
	case(EV_REQUEST_TIMER) { SetScriptResult(100); }
}

@MainLoop{
	
	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;
		ObjEnemy_SetDamageRate(objBoss, 100, 50);
		}
	animation++;
	
	
	if(animation==10){
		///BossCut(objBoss, "Traditionalism \"Drawing Reality By Hand\"", "./Okina_Stand.png");
		
		let Oki_Stand = GetCurrentScriptDirectory~"SatoriDeclare.png";
		ObjCutin_SetSpellcardS4("Breaker \"Mind of the Intellectual Rapist\"", 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(4, 100, 1);
			angle = 90;
			}

		if(frame==60){
			let angle = GetAngleToPlayer(objBoss)-90;
			MineDrop(ObjMove_GetX(objBoss)+130*cos(angle), ObjMove_GetY(objBoss)+130*sin(angle), 180);
			
			}
			
		if(frame==95){
			let angle = GetAngleToPlayer(objBoss)+90;
			MineDrop(ObjMove_GetX(objBoss)+130*cos(angle), ObjMove_GetY(objBoss)+130*sin(angle), 0);
			}
			
		if(frame==95+65+245){
			PlaySoundA1(4, 100, 1);
			CLICK = 1;
			ObjEnemy_SetDamageRate(objBoss, 0, 0);
			}
			
		if(frame==95+65+245+85){
			MoveBoss(objBoss, 60, 120);
			frame=60-120;
			}
					
		}
	yield;
	}
	
task Die1(tobj){
	loop(1){
		DeleteShotAll(TYPE_ALL, TYPE_FADE);
		}
	Obj_Delete(tobj);
	
	loop(100){
		yield;
		}
	
	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 MineDrop(X, Y, Angle){
	loop(15){
		PlaySoundA1(22, 80, 1);	
		Hermit(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), X, Y, rand(0, 360), rand(0, 360), rand(30, 50), DS_STAR_M_RED, "WHITE");
		Hermit(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), X, Y, rand(0, 360), rand(0, 360), rand(30, 50), DS_STAR_M_BLUE, "WHITE");
		yield;
		}
		
	loop(65){
		yield;
		}
		
	let angle = Angle+180;
	let num = 4;
	let mod = -20;
	PlaySoundA1(24, 80, 1);
	loop(num){
		MindLaser(X, Y, 4, angle+mod, 1);
		MindLaser(X, Y, 4, angle-mod, -1);
		
		///cap: 30*6
		mod+=(30*6)/num;
		}
		
	}
	
task MindLaser(X, Y, Speed, Angle, Type){
	let graphic = DS_BALL_BS_RED;
	let graphic1 = DS_BILL_RED;
	if(Type == -1){
		graphic = DS_BALL_BS_BLUE;
		graphic1 = DS_BILL_BLUE;
		}
	let obj = CreateShotA1(X, Y, Speed, Angle, graphic, 0);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	
	ObjMove_SetAngularVelocity(obj, 2*Type); 
	ObjShot_SetDeleteFrame(obj, 240);
	ObjShot_SetSpellResist(obj, true);
	ObjShot_SetAutoDelete(obj, false);
	///ObjMove_AddPatternA2(obj, 160/2, 
	ObjRender_SetScaleXYZ(obj, 1.2, 1.2, NULL);
	let frame = 0;
	let count = 0;
	let C = 0;
	let s = -1;
	let allow = 0;
	while(!Obj_IsDeleted(obj)){
		frame++;
		count++;
		C++;
		
		if(C==240/2){
			ObjMove_SetAngularVelocity(obj, -0.8*Type);
			ObjMove_SetSpeed(obj, Speed+1.5);
			PlaySoundA1(23, 70, 1);
			}
			
		if(count==5){
			let obj1 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, 0, graphic, 0);
			ObjShot_FadeDelete(obj1);
			ObjRender_SetBlendType(obj1, BLEND_ADD_ARGB);
			count-=1;
			ObjRender_SetScaleXYZ(obj1, 1.2, 1.2, NULL);
			}
			
		if(frame==1){
			let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, ObjMove_GetAngle(obj)+90*s, graphic1, 10);
			Vision(obj2, 0.8, Type, 80);
			ObjMove_SetAcceleration(obj2, 0.8/60);
			ObjMove_SetMaxSpeed(obj2, 0.8);
			frame-=2;
			allow++;
			if(allow==4){
				allow=0;
				s*=-1;
				}
			}
		yield;
		}
		
	task Vision(tobj, Speed, Type, Time){
		
		let obj = tobj;
		let Angle = ObjMove_GetAngle(obj);
		let dist = (((ObjMove_GetX(obj)-ObjMove_GetX(objBoss))^2)+((ObjMove_GetY(obj)-ObjMove_GetX(objBoss))^2))^0.5;
		let PosX = ObjMove_GetX(obj);
		let PosY = ObjMove_GetY(obj);
		let angle = atan2(ObjMove_GetY(objBoss) - PosY, ObjMove_GetX(objBoss) - PosX);
		let mod = 0;
		let s = 1;
		while(!Obj_IsDeleted(obj)){
		
			if(CLICK==0){
				///ObjMove_SetSpeed(obj, Speed);
				//ObjShot_SetGraphic(obj, Graphic1);
				ObjRender_SetAlpha(obj, 255);
				ObjRender_SetBlendType(obj, BLEND_ALPHA);
				dist = (((ObjMove_GetX(obj)-ObjMove_GetX(objBoss))^2)+((ObjMove_GetY(obj)-ObjMove_GetY(objBoss))^2))^0.5;
				PosX = ObjMove_GetX(obj);
				PosY = ObjMove_GetY(obj);
				angle = atan2(PosY - ObjMove_GetY(objBoss), PosX - ObjMove_GetX(objBoss));
				ObjShot_SetSpellResist(obj, false);
				ObjShot_SetIntersectionEnable(obj, true);
				mod=0;
				s=1;
				}
				
			if(CLICK==1){
				loop(Time){
				ObjMove_SetAcceleration(obj, 0);
				ObjRender_SetBlendType(obj, BLEND_ALPHA);
				ObjRender_SetAlpha(obj, 100);
				ObjMove_SetSpeed(obj, 0);
				ObjMove_SetPosition(obj, ObjMove_GetX(objBoss)+dist*cos(angle), ObjMove_GetY(objBoss)+dist*sin(angle));
				angle+=mod*Type;
				Angle+=mod*Type;
				ObjMove_SetAngle(obj, Angle);
				ObjShot_SetSpellResist(obj, true);
				ObjShot_SetIntersectionEnable(obj, false);
				mod+=(1/(Time/2))*s;
				
				if(mod>=1){
					s=-1;
					}
				yield;
					}
					
				loop(5){
					yield;
					}
				CLICK = 0;
				ObjMove_SetSpeed(obj, Speed);
				ObjEnemy_SetDamageRate(objBoss, 100, 50);
				}
			
			yield;
			}
		}
		
	}