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


let objBoss;

let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	rendernue(objBoss);
	BossShotSound(objBoss, 100, 600);
	BottomEnemyMarker(objBoss, objBoss);
	FlameAura(objBoss,[255,255,255],3);
	ObjMove_SetDestAtWeight(objBoss,384/2,150,2,6);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	yield;
} 

@Finalize {

} 

task mainTask { 
	wait(60);
	let count = 0;
	let reverse = 1;
	loop{
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 70);
	wait(40);
	attack=true;
	wait(20);
	let ang = 0;
	let angle = 0;
	loop{
		loop(50){
		let obj = CreateShotA2(BossX, BossY, (0.1+1.5*cos(angle*2))+2, angle+(ang*2), 0.01, 50, AMULET_PURPLE, 0);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		angle+=360/50;
		}
	angle-=1;
	ang-=4;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 70);
	wait(45);
	count++;
	if(count==7){secondaryfire;}
	}
	}
}

task secondaryfire{
let angle = 0;
let ang = 0;
	while(!Obj_IsDeleted(objBoss)){
	ascent(i in 0..1){
			loop(6){
			let obj = CreateShotA2(BossX+50*sin(angle), BossY+50*cos(angle), 2, ang+(i*3), 0.02, 5, AMULET_BLUE, 15);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			let obj2 = CreateShotA2(BossX+50*sin(angle+180), BossY+50*cos(angle+180), 2, ang+(i*3), 0.02, 5, AMULET_BLUE, 15);
			ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
			ang+=360/6;
			}
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		angle+=360/18;
		ang+=3;
		wait(7);
	}
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Cutin.png";
	ObjCutin_SetSpellcardS3(name, 25, 25, 25);
	ObjCutin_LaunchS3("KANAKO", Cutin, "Normal");
	TCallBg;
	bspell = true;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(210);
}

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