#include"./FreuSkeleton.txt"
let Declare = false;
let Type = "PURE";

let CLICK = 0;
let Value = 8;
let GRAPHIC = DS_BALL_BS_RED;
let M = -1;
let A2 = 0;
let angle3 = rand(0, 360);
@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5200)
	}
	
	case(EV_REQUEST_TIMER) { SetScriptResult(50); }
}

@MainLoop{
	if(animation==0){
		
		//ObjMove_SetDestAtFrame(objBoss, -100, GetStgFrameHeight/8, 0);
		ObjMove_SetPosition(objBoss, -100, GetStgFrameHeight/8);
		
		Entrance;
		}
		
	animation++;
	
	
	if(animation==10){
		///BossCut(objBoss, "Traditionalism \"Drawing Reality By Hand\"", "./Okina_Stand.png");
		
		let Oki_Stand = GetCurrentScriptDirectory~"Okina_Stand.png";
		ObjCutin_SetSpellcardS4("Android Familiar \"Plasma Neurodiversion Field\"", Oki_Stand, AYA, 255, 100, 100);
		//ObjCutin_LaunchS3(KANAKO, 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==1){
			Concentration_True(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(0, 360), 3, 60, 1, 5, -4, 30, objBoss);
			PlaySoundA1(4, 100, 1);
			}
			
		
		if(frame==80){
			let num = 15;
			PlaySoundA1(21, 100, 10);
			loop(num){
				//CreateShotA1(ObjMove_GetX(objBoss)+40*cos(angle1), ObjMove_GetY(objBoss)+40*sin(angle1), 2+sin(angle), angle+180, DS_SCALE_YELLOW, 10);
				FrostShot(ObjMove_GetX(objBoss)+40*cos(angle1), ObjMove_GetY(objBoss)+40*sin(angle1), 4+sin(angle)*3, 1, angle, DS_BALL_S_A_BLUE, DS_RICE_M_SKY, 10);
				angle+=360/num;
				}
				
			angle-=angle1;
			angle1+=21*s;
			
			allow++;
			
			if(allow<=12){
				frame-=12;
				}
				
			else{
				angle1 = 90+90*s;
				s*= -1;
				allow=0;
				
				A2++;
				}
			}
			
		if(frame==90){
			
			if(A2<2){
				MoveFreu(rand(130, GetStgFrameWidth-130), rand(100, 120), 100);			
				frame-=130;
				}
				
			else{
				MoveFreu(GetPlayerX()+rand(-10, 10), rand(100, 120), 100);
				A2=0;
				}
			}
			
		if(frame==210){
			let num = 10;
			let num1 = 4;
			
			PlaySoundA1(22, 100, 20);
			
			loop(num){
				let mod = 0;
				let mod1 = 0;
				
				loop(num1){
					let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), Value, angle3-mod, DS_KUNAI_BLUE, 20);
					ObjMove_SetAcceleration(obj, -(Value-0.4+mod1)/60);
					ObjMove_SetMaxSpeed(obj, 0.4+mod1);
					
					mod+=5;
					mod1+=0.1*M;
					}
					
				angle3+=360/num;
				}
				
			allow++;
			
			angle3+=21*s;
			
			if(allow<5){
				frame-=20;
				Value-=1.1;
				M*=-1;
				}
				
			else{
				MoveFreu(GetStgFrameWidth/2, 120, 100);
				frame=80-120;
				Value = 8;
				allow=0;
				angle3= rand(0, 360);
				}
				
			}
			
		}
	yield;
	}
	
task Die1(tobj){
	loop(1){
		DeleteShotAll(TYPE_ALL, TYPE_FADE);
		}
	Obj_Delete(tobj);
	
	loop(100){
		yield;
		}
	
	CloseScript(GetOwnScriptID());
	}	
	
task MoveFreu(X, Y, Time){
	ObjMove_SetDestAtFrame(objBoss, X, Y, Time);
	ObjRender_SetScaleXYZ(objBoss, 0, 0, NULL);
	
	loop(Time){
		FreuMove = true;
		FreuTrail;
		yield;
		}
		
	let scale = 0;
	
	FreuMove = false;
	
	loop(6){
		ObjRender_SetScaleXYZ(objBoss,scale, 1, NULL);
		scale+=1/5;
		}
		
	}
	
	
task MoveBoss(tobj, mod, time){
	let posX = ObjMove_GetX(tobj)+rand(-mod, mod);
	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 Entrance{
	ObjRender_SetScaleXYZ(objBoss, 0, 0, NULL);
	let angle = 180;
	let distx = 200;
	let disty= 80;
	
	loop(120){
		FreuTrail;
		ObjMove_SetPosition(objBoss, GetStgFrameWidth/2+distx*cos(angle), 110+disty*sin(angle));
		
		angle+=270/120;
		distx-=200/120;
		disty-=80/120;
		yield;
		}
		
	let scale = 0;
	
	loop(6){
		ObjRender_SetScaleXYZ(objBoss, scale, 1, NULL);
		
		scale+=1/5;
		}
	}
	
task FreuTrail{
	let obj = CreateShotA1(ObjMove_GetX(objBoss)+rand(-15, 15), ObjMove_GetY(objBoss)+rand(-15, 15), 0, 0, DS_BILL_WHITE, 40);
	ObjShot_SetDeleteFrame(obj, 0);
	}
	
task FrostShot(X, Y, Speed, Speed1, Angle, Graphic1, Graphic2, Delay){
	let obj = CreateShotA1(X, Y, Speed, Angle, Graphic1, Delay);
	
	ObjMove_SetAcceleration(obj, -(Speed/60));
	ObjMove_SetMaxSpeed(obj, 0);
	
	let count = 0;
	while(!Obj_IsDeleted(obj)){
		
		if(ObjMove_GetSpeed(obj)<=0&&count==0){
			count = 1;
			
			let obj1 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, Angle, Graphic2-1, Delay);
			let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, Angle+140*s, Graphic2, Delay);
			
			ObjMove_SetAcceleration(obj1, Speed1/30);
			ObjMove_SetAcceleration(obj2, (Speed1+1)/30);
			ObjMove_SetMaxSpeed(obj1, Speed1);
			ObjMove_SetMaxSpeed(obj2, Speed1+1);
			HAGraphic(obj1);
			Obj_Delete(obj);
			}
		yield;
		}
	
	task HAGraphic(tobj){
		let graphic = GetCurrentScriptDirectory~ "Halo.png";
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, graphic);
		Obj_SetRenderPriorityI(obj,28);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj, ObjMove_GetX(tobj), ObjMove_GetY(tobj), 0);
		ObjRender_SetColor(obj, 200, 200, 200);
		ObjRender_SetScaleXYZ(obj, 0.5, 0.5, NULL);
		
		let scale = 0;
		let alpha =150;
		while(!Obj_IsDeleted(tobj)){
			ObjRender_SetScaleXYZ(obj, scale, scale, NULL);
			ObjRender_SetAlpha(obj, alpha);
			
			if(scale<=0.2){
				scale+=0.2/20;
				alpha-=150/20;
				}
				
			else{
				Obj_Delete(obj);
				}
				
			yield;
			}
			
		Obj_Delete(obj);
		}	
	}