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


let objBoss;
let bossring;

let BossX;
let BossY;

let BossX2;
let BossY2;

let Death1 = false;
let Death2 = false;


#include "./Functions/Index.txt"

let ufoboss = UFO(-200,150, "white");

@Initialize {
	bossring = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossring);
	
	objBoss = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objBoss);
	rendernue(objBoss);
	
	ObjEnemy_SetLife(objBoss, 3000);
	ObjEnemy_SetLife(ufoboss, 3000);
	DeathCheckNue;
	DeathCheckUfo;
	
	BossShotSound(objBoss, 100, 600);
	BossShotSound(ufoboss, 100, 600);
	BottomEnemyMarker(objBoss, objBoss);
	BottomEnemyMarker(ufoboss, ufoboss);
	FlameAura(objBoss,[255,255,255],3);
	
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjEnemy_SetDamageRate(ufoboss, 0, 0);
	ObjEnemy_SetDamageRate(bossring, 0, 0);
	
	ObjMove_SetPosition(objBoss, GetCommonData("BossX", 1),GetCommonData("BossY", 1));
	
	ObjMove_SetDestAtWeight(objBoss,384/2+75,150,2,6);
	ObjMove_SetDestAtWeight(ufoboss,384/2-75,150,2,2);
	mainTask;
	end;
} 

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

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	BossX2 = ObjMove_GetX(ufoboss);
	BossY2 = ObjMove_GetY(ufoboss);
	
	if(Death1 == false){
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	ObjEnemy_SetIntersectionCircleToShot(bossring,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(bossring,BossX,BossY,16);
	}
	
	if(Death2 == false){
	ObjEnemy_SetIntersectionCircleToShot(ufoboss,BossX2,BossY2,21);
	ObjEnemy_SetIntersectionCircleToPlayer(ufoboss,BossX2,BossY2,16);
	ObjEnemy_SetIntersectionCircleToShot(bossring,BossX2,BossY2,21);
	ObjEnemy_SetIntersectionCircleToPlayer(bossring,BossX2,BossY2,16);
	}
	
	ObjMove_SetPosition(bossring, BossX, BossY);
	yield;
} 

@Finalize {

} 

task mainTask { 
	wait(160);
	SpellCard("Contrast &quot;Duality of Pure and Unpure&quot;");
	MoveBoth;
	AttackUfo;
	AttackNue;
	ObjEnemy_SetDamageRate(objBoss, 100, 100);
	ObjEnemy_SetDamageRate(ufoboss, 100, 100);
	ObjEnemy_SetDamageRate(bossring, 100, 100);
	}

task AttackNue{
	loop{
		ascent(j in 0..24){
		let obj = CreateShotA1(BossX, BossY, 2, GetAngleToPlayer(objBoss)-(24*7/2)+(j*7), ARROW_BLUE, 5);
		}
	if(Death1==true||Death2==true){break;}
	wait(90);
	}
}	

task AttackUfo{
	loop{
		ascent(i in 0..17){
			ascent(j in 0..9){
			let obj = CreateShotA2(BossX2, BossY2, 0.5, 0+(j*360/9)+(i*(4+i/4)), 0.02, 50, FIRE_GRAY, 5);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
			if(Death1==true||Death2==true){break;}
			wait(4);
		}
		wait(60);
		if(Death1==true||Death2==true){break;}
		ascent(i in 0..17){
			ascent(j in 0..9){
			let obj = CreateShotA2(BossX2, BossY2, 0.5, 0+(j*360/9)-(i*(4+i/4)), 0.02, 50, FIRE_GRAY, 5);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
			if(Death1==true||Death2==true){break;}
			wait(4);
		}
		if(Death1==true||Death2==true){break;}
		wait(60);
	}
}

task AttackNueEnraged{
wait(120);
attack = true;
let angle = 0;
let count = 0;
let counter = 6;
let sinner = 0;
	loop{
		ascent(j in 0..12){
		let obj = CreateShotA1(BossX, BossY, 2, GetAngleToPlayer(objBoss)-(12*7/2)+(j*7)+angle, AMULET_BLUE, 5);
		let obj2 = CreateShotA1(BossX, BossY, 1+2*sin(sinner), (12*7/2)+(j*7)+angle+180, AMULET_PURPLE, 5);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
	angle+=15;
	sinner+=2;
		if(count==counter){
		let random = rand(0,360);
			ascent(i in 0..12){
			let obj = DarknessCloud(BossX,BossY);
			ObjMove_SetAngle(obj, random+(i*360/12));
			ObjMove_SetSpeed(obj, 0.8);
			}
		count=0;
		}
	count++;
	wait(10);
	}
}	

task AttackUfoEnraged{
	wait(120);
	loop{
		ascent(i in 0..14){
			ascent(j in 0..9){
			let obj = CreateShotA2(BossX2, BossY2, 0.9, 0+(j*360/9)+(i*(4+i/4)), 0.03, 50, FIRE_GRAY, 5);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
			wait(4);
		}
		ascent(i in 0..14){
			ascent(j in 0..9){
			let obj = CreateShotA2(BossX2, BossY2, 0.9, 0+(j*360/9)-(i*(4+i/4)), 0.03, 50, FIRE_GRAY, 5);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
			wait(4);
		}
	}
}
	
	
task MoveBoth{
let elps = 0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) != 0 && ObjEnemy_GetInfo(ufoboss, INFO_LIFE) != 0){
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+125*cos(elps), 100+25*sin(elps), 5, 1);
	ObjMove_SetDestAtWeight(ufoboss, GetStgFrameWidth/2+125*cos(elps+180), 100+25*sin(elps+180), 5, 1);
	elps+=0.5;
	yield;
	}
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjEnemy_SetDamageRate(ufoboss, 0, 0);
	ObjEnemy_SetDamageRate(bossring, 0, 0);
	wait(120);
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) != 0){
	ObjMove_SetDestAtWeight(objBoss,384/2,150,2,2);
	ObjEnemy_SetDamageRate(objBoss, 60, 60);
	ObjEnemy_SetDamageRate(bossring, 60, 60);
	AttackNueEnraged;
	}
	if(ObjEnemy_GetInfo(ufoboss, INFO_LIFE) != 0){
	ObjMove_SetDestAtWeight(ufoboss,384/2,150,2,2);
	ObjEnemy_SetDamageRate(ufoboss, 60, 60);
	ObjEnemy_SetDamageRate(bossring, 60, 60);
	AttackUfoEnraged;
	}
}

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 DeathCheckNue{
	while(!Obj_IsDeleted(objBoss)){
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) == 0){
	ObjRender_SetAlpha(objBoss, 122);
	Death1 = true;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death.wav", 100);
	SpellBurstA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),"Cherry",[255, 255, 255]);
	break;}
	yield;
	}
}

task DeathCheckUfo{
	while(!Obj_IsDeleted(ufoboss)){
	if(ObjEnemy_GetInfo(ufoboss, INFO_LIFE) == 0){
	ObjRender_SetAlpha(ufoboss, 122);
	Death2 = true; 
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death.wav", 100);
	SpellBurstA1(ObjMove_GetX(ufoboss),ObjMove_GetY(ufoboss),"Cherry",[255, 255, 255]);
	break;}
	yield;
	}
	wait(60);
	ObjMove_SetDestAtWeight(ufoboss,GetStgFrameWidth+200,150,5,4);
}

task end{
	loop{
	if(Death1&&Death2 == true){break;}
	yield;
	}
    Obj_Delete(objBoss);
	Obj_Delete(ufoboss);
	Obj_Delete(bossring);
	wait(1);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
