#include"./FreuSkeleton.txt"
let Declare = true;
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(5600)
	}
	
	case(EV_REQUEST_TIMER) { SetScriptResult(60); }
}

@MainLoop{
	if(animation==0){
		MoveFreu(GetStgFrameWidth/2, 110, 100);
		}
		
	animation++;
	
	
	if(animation==10){
		///BossCut(objBoss, "Traditionalism \"Drawing Reality By Hand\"", "./Okina_Stand.png");
		
		let Oki_Stand = GetCurrentScriptDirectory~"Ch-Freudiaf.png";
		ObjCutin_SetSpellcardS4("Frostfackel \"Pyre of Saint Germain\"", 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==-100){
			let angle = GetAngleToPlayer(objBoss);
			let num = 13;
			PlaySoundA1(11, 100, 10);
			loop(num){
				let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 0.8, angle, DS_BALL_L_ORANGE, 10);
				let obj1 = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 0.4, angle+180, DS_BALL_L_ORANGE, 10);
				angle+=360/num;
				}
				
			}
			
		
		if(frame==80){
			let mod = GetAngleToPlayer(objBoss)+180;
			
			PlaySoundA1(22, 100, 2);
			
			Torch(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, angle+mod, DS_BALL_M_SKY, US_BRIGHT_SKY, DS_BEAM_BLUE);
			
			angle+=360/9*s;
			
			allow++;
			
			if(allow<9){
				frame-=7;
				}
				
			else{
				s*=-1;
				allow=0;
				}
			}
			
		if(frame==140){
			MoveFreu(GetPlayerX, rand(90, 120), 80);
			frame=-200;
			}
			
		}
	yield;
	}
	
task Die1(tobj){
	loop(10){
		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 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);
	ObjShot_SetSpellResist(obj, true);
	
	}
	
task Torch(X, Y, Speed, Angle, Graphic1, Graphic2, Graphic3){
	let obj = CreateShotA1(X, Y, Speed, Angle, Graphic1, 0);
	
	ObjShot_SetSpellResist(obj, true);
	ObjShot_SetIntersectionEnable(obj, false);
	ObjRender_SetAlpha(obj, 0);
	
	let count = 0;
	while(!Obj_IsDeleted(obj)){
		Fader(ObjMove_GetX(obj)+rand(-5, 5), ObjMove_GetY(obj)+rand(-5, 5), Graphic1, rand(1, 2));
		
		if(ObjMove_GetX(obj)>=GetStgFrameWidth&&count==0){
			count = 1;
			ObjMove_SetX(obj, GetStgFrameWidth-2);
			ObjMove_SetSpeed(obj, 0);
			loop(3){
				Hermit(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), ObjMove_GetX(obj), ObjMove_GetY(obj), rand(0, 360), rand(0, 360), 80, Graphic1, "BLUE");
				yield;
				}
				
			loop(85){
				yield;
				}
				
			let obj2 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 180, 640, 30, 20, Graphic3, 40);
			PlaySoundA1(24, 100, 40);
			loop(5){
				yield;
				}
			PlaySoundA1(24, 100, 40);
			let obj3 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)+10, 180, 640, 30, 20, Graphic3, 40);
			let obj4 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)-10, 180, 640, 30, 20, Graphic3, 20);
			
			loop(5){
				yield;
				}
			PlaySoundA1(24, 100, 40);
			let obj5 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)+20, 180, 640, 30, 20, Graphic3, 40);
			let obj6 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)-20, 180, 640, 30, 20, Graphic3, 40);
			
			loop(40){
				yield;
				}	
			
			let angle = rand(0, 360);
			let num = 13;
			let num1 = 1;
			
			loop(num){
				let mod = 0;
				
				loop(num1){
					let obj1 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod, Graphic2, 20);
					ObjMove_SetAcceleration(obj1, -(3-0.7)/50);
					ObjMove_SetMaxSpeed(obj1, 0.7);
					let obj2 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod+180, Graphic2, 20);
					ObjMove_SetAcceleration(obj2, -(3-0.5)/50);
					ObjMove_SetMaxSpeed(obj2, 0.5);
					mod+=3;
					}
						
				angle+=360/num;
				}
			
			Obj_Delete(obj);
			}
			
		if(ObjMove_GetX(obj)<=0&&count==0){
			count=1;
			ObjMove_SetX(obj, 2);
			ObjMove_SetSpeed(obj, 0);
			loop(3){
				Hermit(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), ObjMove_GetX(obj), ObjMove_GetY(obj), rand(0, 360), rand(0, 360), 80, Graphic1, "BLUE");
				yield;
				}
				
			loop(85){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj2 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, 640, 30, 20, Graphic3, 40);
			loop(5){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj3 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)+10, 0, 640, 30, 20, Graphic3, 40);
			let obj4 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)-10, 0, 640, 30, 20, Graphic3, 40);
			
			loop(5){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj5 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)+20, 0, 640, 30, 20, Graphic3, 40);
			let obj6 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj)-20, 0, 640, 30, 20, Graphic3, 40);
			
			loop(40){
				yield;
				}
			let angle = rand(0, 360);
			let num = 13;
			let num1 = 1;
			
			loop(num){
				let mod = 0;
			
				loop(num1){
					let obj1 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod, Graphic2, 20);
					ObjMove_SetAcceleration(obj1, -(3-0.7)/50);
					ObjMove_SetMaxSpeed(obj1, 0.7);
					let obj2 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod+180, Graphic2, 20);
					ObjMove_SetAcceleration(obj2, -(3-0.5)/50);
					ObjMove_SetMaxSpeed(obj2, 0.5);
					mod+=3;
					}
						
				angle+=360/num;
				}
				
			Obj_Delete(obj);
			}
			
		if(ObjMove_GetY(obj)<=0&&count==0){
			count=1;
			ObjMove_SetY(obj, 2);
			ObjMove_SetSpeed(obj, 0);
			loop(3){
				Hermit(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), ObjMove_GetX(obj), ObjMove_GetY(obj), rand(0, 360), rand(0, 360), 80, Graphic1, "BLUE");
				
				yield;
				}
				
			loop(85){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj2 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 90, 640, 30, 20, Graphic3, 40);
			loop(5){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj3 = CreateStraightLaserA1(ObjMove_GetX(obj)+10, ObjMove_GetY(obj), 90, 640, 30, 20, Graphic3, 40);
			let obj4 = CreateStraightLaserA1(ObjMove_GetX(obj)-10, ObjMove_GetY(obj), 90, 640, 30, 20, Graphic3, 40);
			
			loop(5){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj5 = CreateStraightLaserA1(ObjMove_GetX(obj)+20, ObjMove_GetY(obj), 90, 640, 30, 20, Graphic3, 40);
			let obj6 = CreateStraightLaserA1(ObjMove_GetX(obj)-20, ObjMove_GetY(obj), 90, 640, 30, 20, Graphic3, 40);
			
			loop(40){
				yield;
				}
				
			let angle = rand(0, 360);
			let num = 13;
			let num1 = 1;
			
			loop(num){
				let mod = 0;
				
				loop(num1){
					let obj1 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod, Graphic2, 20);
					ObjMove_SetAcceleration(obj1, -(3-0.7)/50);
					ObjMove_SetMaxSpeed(obj1, 0.7);
					let obj2 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod+180, Graphic2, 20);
					ObjMove_SetAcceleration(obj2, -(3-0.5)/50);
					ObjMove_SetMaxSpeed(obj2, 0.5);
					mod+=3;
					}
						
				angle+=360/num;
				}
				
			Obj_Delete(obj);
			}
			
		if(ObjMove_GetY(obj)>=GetStgFrameHeight&&count==0){
			count=1;
			ObjMove_SetY(obj, GetStgFrameHeight-2);
			ObjMove_SetSpeed(obj, 0);
			loop(3){
				Hermit(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), ObjMove_GetX(obj), ObjMove_GetY(obj), rand(0, 360), rand(0, 360), 80, Graphic1, "BLUE");
				yield;
				}
				
			loop(85){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj2 = CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 270, 640, 30, 20, Graphic3, 40);
			loop(5){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj3 = CreateStraightLaserA1(ObjMove_GetX(obj)+10, ObjMove_GetY(obj),270, 640, 30, 20, Graphic3, 40);
			let obj4 = CreateStraightLaserA1(ObjMove_GetX(obj)-10, ObjMove_GetY(obj), 270, 640, 30, 20, Graphic3, 40);
			
			loop(5){
				yield;
				}
				PlaySoundA1(24, 100, 40);
			let obj5 = CreateStraightLaserA1(ObjMove_GetX(obj)+20, ObjMove_GetY(obj), 270, 640, 30, 20, Graphic3, 40);
			let obj6 = CreateStraightLaserA1(ObjMove_GetX(obj)-20, ObjMove_GetY(obj), 270, 640, 30, 20, Graphic3, 40);
			
			loop(40){
				yield;
				}
				
			let angle = rand(0, 360);
			let num = 13;
			let num1 = 1;
			
			loop(num){
				let mod = 0;
				
				loop(num1){
					let obj1 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod, Graphic2, 20);
					ObjMove_SetAcceleration(obj1, -(3-0.7)/50);
					ObjMove_SetMaxSpeed(obj1, 0.7);
					
					let obj2 =  CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, angle+mod+180, Graphic2, 20);
					ObjMove_SetAcceleration(obj2, -(3-0.5)/50);
					ObjMove_SetMaxSpeed(obj2, 0.5);
					mod+=3;
					}
						
				angle+=360/num;
				}
				
			Obj_Delete(obj);
			}
			
		yield;
		}
		
	task Fader(X, Y, Graphic, Scale){
		let obj = CreateShotA1(X, Y, 0, 0, Graphic, 0);
		ObjShot_SetIntersectionEnable(obj, false);
		let scale = Scale;
		let alpha = 20;
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		while(!Obj_IsDeleted(obj)){
			ObjRender_SetScaleXYZ(obj, Scale, Scale, NULL);
			ObjRender_SetAlpha(obj, alpha);
			if(Scale>=0){
				Scale-=scale/30;
				alpha-=20/30;
				}
				
			else{
				Obj_Delete(obj);
				}
				
			yield;
			}
		}
		
	}
	
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, 100);
	ObjMove_SetPosition(obj, x, y);
	loop(10){
	sca-=1/15;
	ObjRender_SetScaleXYZ(obj, sca, sca, 1);
	yield;
	}
	Obj_Delete(obj);
	}