#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Luminescence \"Great Lantern Explosion\""]

#include"./Cutin.txt"
#include"./../../Functions/Effects/Effects.txt"
#include"./../../System/Miyako_Effect.txt"
#include"./LoadGraphics.txt"
#include"./LoadSounds.txt"

let bossObj;
let bossX;
let bossY;
let damage = 0;
#include"./MiyakoDrawBoss.txt"

@Initialize{	
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetCommonData("Safe",1);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
		
	LoadShotData;
	animateBossM;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(500);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_START_BOSS_SPELL){
		let path = GetCurrentScriptDirectory ~ "./../../System/Miyako_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);yield;}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 10, 0);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-120,5,3);
	TEtama;loop(90){yield;}SE(se_spell);
	if(GetCommonData("Replay",0) == 2){
	ObjCutin_SetSpellcardS4("Luminescence \"Great Lantern Explosion\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(MOKOU, cutin, "Practice");}
	else{
	ObjCutin_SetSpellcardS4("Luminescence \"Great Lantern Explosion\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cutin, "Extra");}
	TSpellBG;SetCommonData("BG",1);
	wait(150);damage=1;
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
		attack=1;TWave;wait(240);attack=0;
		ObjMove_SetDestAtWeight(bossObj,rand(100,382-100),rand(60,120),5,1);
		wait(120);}}

task TWave(){
	let ang = 0;SE(se_ch2);
	MakeConcentrationB1(bossObj,"SAKURA",255,255,64,75);wait(70);
	 ascent(a in 0..20){
		let red = CreateShotA1(bossX,bossY,0.2,a*18,276,0);
		let orange = CreateShotA1(bossX,bossY,0.5,a*18+6,282,0);
		let yellow = CreateShotA1(bossX,bossY,0.8,a*18+12,281,0);
		let green = CreateShotA1(bossX,bossY,1.1,a*18+18,280,0);
		let aqua = CreateShotA1(bossX,bossY,1.4,a*18+24,279,0);
		let blue = CreateShotA1(bossX,bossY,1.7,a*18+30,278,0);
		let purple = CreateShotA1(bossX,bossY,2,a*18+36,277,0);
		tExplosion(red,120,519);
		tExplosion(orange,125,531);
		tExplosion(yellow,130,530);
		tExplosion(green,135,527);
		tExplosion(aqua,140,524);
		tExplosion(blue,145,523);
		tExplosion(purple,150,520);}
	SE(se_enep3);
	ascent(a in 0..60){
		CreateShotA1(bossX,bossY,2.3,a*6,275,0);}
		TExplosionC(bossX,bossY);
	wait(120);wait(1000);
	
	task tExplosion(obj,time,gr){
		wait(time);SE(se_kira2);
		if(!Obj_IsDeleted(obj)){
		ascent(i in 0..4){
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0.8,ObjMove_GetAngle(obj)+i*90+45,gr,30);}}
		Obj_Delete(obj);
	}}

task TExplosionC(x,y){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, expl2);
	Obj_SetRenderPriority(obj,0.65);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj,0,80,64,144);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,x,y,0);

	let scale1 = 0;
	let alpha = 255;
	while(alpha > 0){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetScaleXYZ(obj,scale1,scale1,1);
		scale1+=0.1;
		alpha-=1;
		yield;}
	Obj_Delete(obj);}