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


let objBoss;

let BossX;
let BossY;

let stage = 0;

#include "./Functions/Index.txt"

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

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

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(10000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(99);
	}
	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);
	SpellCard("&quot;Purified UFO of the Chimera&quot;");
	Go(ufofamilair);
	movement;
	Staging;
}

task Staging{
let HPTreshold = 8000;
wait(90);
ObjEnemy_SetDamageRate(objBoss, 80, 40);
	loop{
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < HPTreshold){
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death2.wav", 100);
		HPTreshold-=2000;
		stage++;
		}
	yield;
	}
}

task Go(obj){
let sine = 0;
let sine2 = 0;
let counter = 0;
let counter2 = 0;
let counterswitch = 0;
let phase = 1;
let shoot = 0;
let radius = 50;
ObjMove_SetDestAtFrame(obj, BossX, BossY, 90);
wait(90);
	while(!Obj_IsDeleted(obj)){
	ObjMove_SetPosition(obj, BossX+radius*sin(sine), BossY+radius*sin(sine2));
	sine+=2;
	sine2+=1;
	
	if(counter >= 8 && phase==1 && stage==0){
		ascent(i in 0..8){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, shoot+(i*360/8), 0.02, 100, AMULET_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	counter=0;
	shoot+=12;
	}
	
	if(counter >= 6 && phase==1 && stage==1){
		ascent(i in 0..8){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, shoot+(i*360/8), 0.02, 100, AMULET_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	counter=0;
	shoot+=5;
	}
	
	if(counter2 >= 18 && phase==1 && stage==2){
		ascent(i in 0..12){
		let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 2, shoot+(i*360/12), LARGE_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
	counter2=0;
	shoot+=10;
	}
	if(counter >= 2 && phase==1 && stage==2){
		ascent(i in 0..4){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, shoot+(i*360/4), 0.02, 100, AMULET_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	counter=0;
	shoot+=10;
	}

	if(counter2 >= 24 && phase==1 && stage==3){
		ascent(i in 0..12){
		let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 2.5, shoot+(i*360/12), LARGE_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
	counter2=0;
	shoot+=10;
	}
	if(counter >= 3 && phase==1 && stage==3){
		ascent(i in 0..7){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, shoot+(i*360/7), 0.03, 100, AMULET_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	counter=0;
	shoot+=6;
	}

	if(counter2 >= 24 && phase==1 && stage==4){
		ascent(i in 0..18){
		let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 3, shoot+(i*360/18), LARGE_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
	counter2=0;
	shoot+=14;
	}
	if(counter >= 2 && phase==1 && stage==4){
		ascent(i in 0..8){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, shoot+(i*360/8), 0.05, 100, AMULET_GRAY, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB)
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	counter=0;
	shoot+=1;
	}
	
	if(counter >=15 && phase==2 && stage==0){
		ascent(i in 0..8){
		CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 1+(i*360/8), 700, 15, 20, ST_LASER_GRAY, 60);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 60);
	counter=0;
	}
	
	if(counter >=15 && phase==2 && stage==1){
		ascent(i in 0..8){
		CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), shoot+(i*360/8), 700, 15, 20, ST_LASER_GRAY, 60);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 60);
	counter=0;
	shoot+=2;
	}
	
	if(counter >=12 && phase==2 && stage==2){
		ascent(i in 0..12){
		CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), shoot+(i*360/12), 700, 15, 20, ST_LASER_GRAY, 50);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 60);
	counter=0;
	shoot+=4;
	}
	
	if(counter >=12 && phase==2 && stage==3){
		ascent(i in 0..12){
		CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), shoot+(i*360/12), 700, 15, 10, ST_LASER_GRAY, 40);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 60);
	counter=0;
	shoot+=4;
	}
	
	if(counter >=8 && phase==2 && stage==4){
		ascent(i in 0..12){
		CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), shoot+(i*360/12), 700, 15, 10, ST_LASER_GRAY, 40);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 60);
	counter=0;
	shoot+=4;
	}

	if(phase==2 && radius<=100){
	radius++;
	}
	
	if(phase==1 && radius>=50){
	radius--;
	}
	
	if(counterswitch==240 && phase==1){
	counterswitch=0;
	phase=2;}
	if(counterswitch==240 && phase==2){
	counterswitch=0;
	phase=1;}
	
	counterswitch++;
	counter++;
	counter2++;
	yield;
	}
}

task movement{
	loop{
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX,150,5,3);
	wait(180);
	}
}

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;}
		StartSlow(TARGET_ALL, 30);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death.wav", 100);
	loop(11){
	SpellBurstA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),"Cherry",[255, 255, 255]);
	wait(7);
	}
	StopSlow(TARGET_ALL);
	wait(1);
	SetCommonData("BossX", ObjMove_GetX(objBoss));
	SetCommonData("BossY", ObjMove_GetY(objBoss));
    Obj_Delete(objBoss);
	SetCommonData("Died",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
