#TouhouDanmakufu
#Title[SatoriNonSpell H]
#Text[Nonspell]
#BackGround[User(.\img\stage.png,0,-0.5)]
#PlayLevel[Extra]
#Player[FREE]
#BGM[.\HeartfeltFancy.mp3]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\Library.dnh"

let SatoriSprite = csd~"img/Satori/SatoriSprite.png";
let SatoriCutin = csd~"img/Satori/SatoriCutin.png";

@Initialize
	{
	LoadUserShotData(csd~"Shot.txt");
	LoadGraphic(SatoriSprite);
	SetLife(3000);
	SetEnemyMarker(true);
	SetDamageRate(5,5);
	SetTimer(71);
	//let a=0;
	CutIn(YOUMU,"Vague Recollection -- Omoikane's Device",SatoriCutin,0,0,256,512);
	SetEffectForZeroLife(60,0,0);	
	SetDurableSpellCard;
	

MainTask;
Vulnerable;
Timer;
IdleSatori;
//MoveAbout;
SetMovePosition03(GetCenterX, GetCenterY - 130, 30,10);
}

task Vulnerable
{
Wait(600);
SetDamageRate(50,50);
}

task Icicle(s,a,k){
let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	Obj_SetSpeed(obj,s);
	Obj_SetAngle(obj,a);
	ObjShot_SetGraphic(obj,94);
	ObjShot_SetDelay(obj,0);
	let ti=30;
	let u=-1;
	let X=GetPlayerX;
	let Y=GetPlayerY;
	while(!Obj_BeDeleted(obj)){
		
		yield;
		ti--;
		u--;
		if(ti==0){Obj_SetSpeed(obj,0);
				Obj_SetAngle(obj,a+90*k);}
		if(ti==-120){Obj_SetSpeed(obj,s)};
	}
}

task Icicle2(s,a,k){
let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	Obj_SetSpeed(obj,s);
	Obj_SetAngle(obj,a);
	ObjShot_SetGraphic(obj,94);
	ObjShot_SetDelay(obj,0);
	let ti=30;
	let u=-1;
	let X=GetPlayerX;
	let Y=GetPlayerY;
	while(!Obj_BeDeleted(obj)){
		
		yield;
		ti--;
		u--;
		if(ti==0){Obj_SetSpeed(obj,0);
				Obj_SetAngle(obj,a+90*k);}
		if(ti==-120){Obj_SetSpeed(obj,s/2)};
		if(ti==floor(-150+30*sin(a))){Obj_SetAngle(obj,a+180*k)};
	}
}


task IcicleFall(s){
let a=-40;
loop{
	loop(24){
		loop(15){yield};
		ascent(i in 6..12){Icicle(s*i/2,a,1);Icicle(s*i/2,180-a,-1);}
		a+=5;}
	a=-40;
	loop(120){yield;}
	
	loop(30){
		loop(15){yield};
		ascent(i in 6..12){Icicle2(s*i/2,a,1);Icicle2(s*i/2,180-a,-1);}
		a+=5;}
	a=-40;
	loop(120){yield;}
	}
}

task MoonBlade(speed,f,ra,va,l,stype,s2,dl,z,y,angle){
		let objShot= Obj_Create(OBJ_SHOT);
		let FireCount=0;
		let Span=3;
		let speedcap=0;
		let bounce=false;
		let timer=0;
		let ang=0;
		let alp=0;
		let ndir=0;
		let ag=0;
		let t=0;
		let e=0;
		let a=ra+va/2;
		let R=1/(1+e*cos(va/2));
		Obj_SetX(objShot, GetX+2*l*cos(ra));
		Obj_SetY(objShot, GetY+2*l*sin(ra));
		Obj_SetAlpha(objShot, 250); 
        	ObjShot_SetGraphic(objShot, stype);

		Obj_SetAngle(objShot, 0);
		Obj_SetSpeed(objShot,0);

		while( !Obj_BeDeleted(objShot)){
			
			if(timer<z/speed){
				t=timer*speed/z-0.5;
					Obj_SetX(objShot, GetX+(sin(t*va)*1/(1+e*cos(t*va))*sin(a)-(cos(t*va)*1/(1+e*cos(t*va)))*cos(a))*l/R);
					Obj_SetY(objShot, GetY+(sin(t*va)*1/(1+e*cos(t*va))*cos(a)+(cos(t*va)*1/(1+e*cos(t*va)))*sin(a))*l/R);
					if(timer%f==y%f){Dlbullet(Obj_GetX(objShot),Obj_GetY(objShot),2,angle-a-va*t+rand(-0,0),s2,30,dl)}
				t=(timer+1/2)*speed/z-0.5;
					Obj_SetX(objShot, GetX+(sin(t*va)*1/(1+e*cos(t*va))*sin(a)-(cos(t*va)*1/(1+e*cos(t*va)))*cos(a))*l/R);
					Obj_SetY(objShot, GetY+(sin(t*va)*1/(1+e*cos(t*va))*cos(a)+(cos(t*va)*1/(1+e*cos(t*va)))*sin(a))*l/R);
					if(timer%(f)==y%f){Dlbullet(Obj_GetX(objShot),Obj_GetY(objShot),2,angle-a-va*t+rand(-0,0),s2,30,dl)}
			}else{Obj_SetX(objShot, GetX+(sin(t*va)*1/(1+e*cos(t*va))*sin(a)-(cos(t*va)*1/(1+e*cos(t*va)))*cos(a))*l/R);
					Obj_SetY(objShot, GetY+(sin(t*va)*1/(1+e*cos(t*va))*cos(a)+(cos(t*va)*1/(1+e*cos(t*va)))*sin(a))*l/R);}
					if(timer%(f)==y%f){Dlbullet(Obj_GetX(objShot),Obj_GetY(objShot),2,angle-a-va*t+rand(-0,0),s2,30,dl)}
			if(timer==z){Obj_Delete(objShot)}
			yield;
			timer++;;
			}

}
	task Dlbullet(x,y,s,a,ty,d,dl){
		let objShot= Obj_Create(OBJ_SHOT);
		let FireCount=0;
		let Span=3;
		let speedcap=0;
		let bounce=false;
		let timer=0;
		let ang=0;
		let alp=0;
		let ndir=0;
		let ag=0;
		let t=dl;
		Obj_SetX(objShot, x);
		Obj_SetY(objShot, y);
		Obj_SetAlpha(objShot, 250); 
        		ObjShot_SetGraphic(objShot, ty);
		ObjShot_SetDelay(objShot,d);
		Obj_SetAngle(objShot, a);
		Obj_SetSpeed(objShot,s/3);

		while( !Obj_BeDeleted(objShot)){
			t--;
			if(t==0){Obj_SetSpeed(objShot,s);}
			yield;
			}
}

task Dlbullet2(x,y,s,a,ty,d,dl){
		let objShot= Obj_Create(OBJ_SHOT);
		let FireCount=0;
		let Span=3;
		let speedcap=0;
		let bounce=false;
		let timer=0;
		let ang=0;
		let alp=0;
		let ndir=0;
		let ag=0;
		let t=dl;
		Obj_SetX(objShot, x);
		Obj_SetY(objShot, y);
		Obj_SetAlpha(objShot, 250); 
        		ObjShot_SetGraphic(objShot, ty);
		ObjShot_SetDelay(objShot,d);
		Obj_SetAngle(objShot, a);
		Obj_SetSpeed(objShot,s/3);

		while( !Obj_BeDeleted(objShot)){
			t--;
			if(t==0){Obj_SetSpeed(objShot,s);Obj_SetAngle(objShot, a+90*(-1)^rand_int(1,2));}
			yield;
			}
}

task Sinua(x,y,a,s,ty,k){
	let obj= Obj_Create(OBJ_SHOT);
		let timer=0;
		let ang=0;
		let alp=0;
		let ndir=0;
		let ag=rand(0,90);
		let t=-ag;
		Obj_SetX(obj, x);
		Obj_SetY(obj, y);
		Obj_SetAlpha(obj, 250); 
        ObjShot_SetGraphic(obj, ty);
		ObjShot_SetDelay(obj,ag);
		Obj_SetAngle(obj, a);
		Obj_SetSpeed(obj,s);

		while( !Obj_BeDeleted(obj)){
			t++;
			if(t<105){Obj_SetAngle(obj,a+k*60*sin(6*t));}
			yield;
			}

}

task Bfly(k){

loop(330){yield;ascent(i in 0..5){CreateShot01(GetX,GetY,7,-115+10*i,242,0);
CreateShot01(GetX,GetY,3,-115+10*i,242,0)}}
ascent(j in 0..120){yield;ascent(i in 0..5){CreateShot01(GetX,GetY,7,-110+10*i+k*180*sin(j*90/120)^2,242,0);
CreateShot01(GetX,GetY,3,-115+10*i+k*180*sin(j*90/120)^2,242,0)}}
loop(60){yield;ascent(i in 0..5){CreateShot01(GetX,GetY,7,-115+10*i+180*k,242,0);
CreateShot01(GetX,GetY,3,-115+10*i+180*k,242,0)}}
}

task Omoikane(let a,k,o){
let x=224;
let y=280;

loop(20){
	loop(5){yield;}
	ascent(i in o..60-o){
						CreateShot01(x,y,4,a+6*i,133,20);
						}
	}
loop(90){
	loop(5){yield;}
	ascent(i in o..60-o){
						CreateShot01(x,y,4,a+6*i,133,20);
						}
	y=y+2;
	a=a+k;
	}	
	
}

task MainTask
{
Wait(120);
let a=0;

loop
	{Omoikane(90,3,5);
	loop(60){yield;}
	loop(20){
	ascent(i in 0..20){ascent(j in 0..5){CreateShot01(GetX,GetY,2,360/20*i+2*j,87,5)}}
	loop(30){yield;}
	
	}
	loop(180){yield;}
	Omoikane(-90,3,10);
	loop(60){yield;}
	loop(20){
	ascent(i in 0..20){ascent(j in 0..5){CreateShot01(GetX,GetY,2,360/20*i+2*j,87,5)}}
	loop(30){yield;}
	
	}
	loop(180){yield;}
	
	Omoikane(-90,-3,10);
	loop(60){yield;}
	loop(20){
	ascent(i in 0..20){ascent(j in 0..5){CreateShot01(GetX,GetY,2,360/20*i+2*j,87,5)}}
	loop(30){yield;}
	
	}
	loop(180){yield;}
	}
}

task MoveAbout
{
SetMovePosition02(GetCenterX,GetCenterY-120,60);
MoveSatori;
loop
	{
	Wait(250);
	SetMovePositionRandom01(64,64,1,GetClipMinX+64,GetClipMinY+64,GetClipMaxX-64,GetClipMinY+128);
	MoveSatori;
	Wait(150);
	}
}

@MainLoop
	{
	SetCollisionA(GetX,GetY,32);
	SetCollisionB(GetX,GetY,32);
	yield;
	}



@DrawLoop
	{
	SetAlpha(255);
	if (bossflip==0){SetGraphicScale(1,1);}
	if (bossflip==1){SetGraphicScale(-1,1);}
	SetColor(255,255,255);
	SetGraphicAngle(0,0,0);
	SetTexture(SatoriSprite);
	SetGraphicRect(BR[0],BR[1],BR[2],BR[3]);
	DrawGraphic(GetX,GetY);
	}

@Finalize
	{
	DeleteGraphic(SatoriSprite);
	}

}