#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell3"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;

let invisible2 = false;

#include "./Functions/Index.txt"
#include "./Functions/Dialogue.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderkanako(objBoss);
	BossShotSound(objBoss, 100, 600);
	KanakoAura(objBoss, false);
	Sticks(objBoss, false);
	BottomEnemyMarker(objBoss, objBoss);
	DrawName("Kanako Yasaka", [20, 20, 200], 11);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 5);
	Maintask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(50);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	if(invisible==false){
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	}
	
	if(GetPlayerInvincibilityFrame<=0){invisible=false;}
	if(GetPlayerInvincibilityFrame>0){invisible = true;}
	if(invisible2 == true){invisible = true;}
	
	yield;
} 

@Finalize {

} 


task Maintask{
wait(80);
ObjEnemy_SetDamageRate(objBoss, 300, 200);
	loop{
	Pattern1;
	wait(120);
	Pattern2;
	wait(120);
	Pattern3;
	wait(120);
	}
}

function Pattern1{
invisible2 = true;
attack = true;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 60);
wait(60);
revolve = true;
	ascent(j in 0..32){
		ascent(i in 0..7){
		let obj = CreateShotA2(BossX, BossY, 5-(j/8), j*7+(i*360/7), 0.01, 5, KNIFE_RED, 5);
		ObjMove_SetAngularVelocity(obj, 0.2);
		}
		ascent(i in 0..7){
		let obj = CreateShotA2(BossX, BossY, 2+(j/3), j*7-(i*360/7), 0.01, 5, KNIFE_GREEN, 5);
		ObjMove_SetAngularVelocity(obj, -0.2);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(5);
	}
revolve = false;
invisible2 = false;
attack = false;
}

function Pattern2{
invisible2 = true;
attack = true;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 60);
wait(60);
revolve = true;
	ascent(k in 0..7){
		ascent(i in 0..6){
			ascent(j in 0..24){
			CreateShotA2(BossX, BossY, 0.1*i, k*7+(j*360/24), 0.06, 10, LARGE_GREEN, 5);
			}
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
		wait(40-(k*7));
	}

revolve = false;
invisible2 = false;
attack = false;
}

function Pattern3{
invisible2 = true;
attack = true;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 60);
wait(60);
revolve = true;

	ascent(i in 0..6){
		ascent(j in 0..8){
		let obj = CreateShotA2(BossX+60, BossY-20, 4, -70+(j*10), -0.08, 0, ICE_GREEN, 10);
		let obj2 = CreateShotA2(BossX-60, BossY-20, 4, 180+70-(j*10), -0.08, 0, ICE_GREEN, 10);
		Redirect(obj);
		Redirect(obj2);
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		wait(4);
	}
	wait(10);
	ascent(i in 0..12){
	let random = rand(0,360);
		ascent(j in 0..18){
		CreateShotA1(BossX+30, BossY, 4, random+(j*360/18), PELLET_RED, 5);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(5);
		ascent(j in 0..18){
		CreateShotA1(BossX-30, BossY, 4, random+(j*360/18), PELLET_MAGENTA, 5);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(5);
	}
	task Redirect(obj){
	wait(60);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
	ObjMove_AddPatternA3(obj, 0, 2, GetAngleToPlayer(obj), 0.07, 0, 8, NO_CHANGE);
	}

revolve = false;
invisible2 = false;
attack = false;
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	wait(1);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
