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

let CLICK = 0;
let Value = 18;
let GRAPHIC = DS_ICE_BLUE;
let M = -3;
let A2 = 0;
let angle3 = rand(0, 360);
let SpeedM = 2;
@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6200*1.6)
	}
	
	case(EV_REQUEST_TIMER) { SetScriptResult(80); }
}

@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("Freudenstachel \"A Frozen Cottonflower Adrift\"", 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==60){
			let angle = rand(0, 360);
			let num = 10;
			
			loop(num){
				Stachel(ObjMove_GetX(objBoss)+40*cos(angle), ObjMove_GetY(objBoss)+40*sin(angle), SpeedM, angle+SpeedM, DS_ICE_SKY);
				
				angle+=360/num;
				}
				
			SpeedM+=sin(A2)/4;
			A2+=10;
			
			frame-=15;
			}
			
		if(shot==180){
			MoveFreu(GetPlayerX, rand(80, 140), 80);
			shot=10;
			}
			
		}
	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 Stachel(X, Y, Speed, Angle, Graphic){
	let obj = CreateShotA1(X, Y, Speed, Angle, Graphic, 0);
	let count = 0;
	let angle = 0;
	ObjRender_SetAlpha(obj, 60);
	ObjShot_SetIntersectionEnable(obj, false);
	while(!Obj_IsDeleted(obj)){
		
		if(ObjMove_GetX(obj)>=GetStgFrameWidth&&count==0){
			count=1;
			ObjMove_SetX(obj, GetStgFrameWidth-2);
			angle = 180-ObjMove_GetAngle(obj);
			}
			
		if(ObjMove_GetX(obj)<=0&&count==0){
			count=1;
			ObjMove_SetX(obj, 2);
			angle = 180-ObjMove_GetAngle(obj);
			}
			
		if(ObjMove_GetY(obj)<=0&&count==0){
			count=1;
			ObjMove_SetY(obj, 2);
			angle = 360-ObjMove_GetAngle(obj);
			}
			
		if(count==1){
			count=2;
			Drifter(ObjMove_GetX(obj), ObjMove_GetY(obj), rand(0.5, 5), angle);
			Obj_Delete(obj);
			}
			
		
		yield;
		}
		
	task Drifter(X, Y, Speed, Angle){
		let obj = CreateShotA1(X, Y, Speed, Angle, DS_BALL_S_WHITE, 5);
		ObjRender_SetAlpha(obj, 60);
		ObjShot_SetIntersectionEnable(obj, false);
		let DECEL = truncate(rand(80, 140));
		ObjMove_SetAcceleration(obj, -Speed/DECEL);
		ObjMove_SetMaxSpeed(obj, 0);
		let c = 0;
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetSpeed(obj)<=0&&c==0){
				c=1;
				let Speeder = rand(0.8, 2);
				let obj1 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, 90+rand(-4, 4), DS_BALL_SS_WHITE, 15);
				ObjMove_SetAcceleration(obj1, Speeder/100);
				ObjMove_SetMaxSpeed(obj1, Speeder);
				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);
	}