#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP2"]
#Text["Baaaaaaaaaap"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"


let BossX;
let BossY;
let objBoss;



@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	HitSound(objBoss, 75, 450);
	RenderCharacter(objBoss);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	
	if(GetCommonData("IsStage", false)==true){
	MagicRing(objBoss,false);
	}
	else{
	MagicRing(objBoss,true);
	SetCommonData("BossAlpha", 255);
	StageBackground;
	}
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 4);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(105);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
}

let appear = false; 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);

	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	yield;
} 

@Finalize {
} 

task mainTask { 
	SpellCard("Jeweled Pagoda &quot;Vajra of Purifying Light&quot;", [198, 132, 39], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Shou.png", 0);
	
	ObjEnemy_SetDamageRate(objBoss, 100, 100);
	Laser;	
	
	task Laser{
	let angle = 0;
	let angle2 = 0;
	let rotatecount = 0.5825;
	let count = 0;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/barrage.wav", 90);
		loop{
			ascent(i in 0..4){
			let obj = PagodaLaser(GetStgFrameWidth/2-200,150,0,0,1,i*360/4+45+angle,rotatecount,rotatecount,40,[0, 12, 134],70,30);
			}
			ascent(i in 0..4){
			let obj = PagodaLaser(GetStgFrameWidth/2+200,150,0,0,1,i*360/4+angle2,-rotatecount,-rotatecount,40,[0, 12, 134],70,30);
			}
			if(count>3){
			Spread(GetStgFrameWidth/2-200,150, rotatecount);
			Spread(GetStgFrameWidth/2+200,150, -rotatecount);
			}
			LaserSoundTimer(70);
			ascent(i in 0..110){
			angle+=rotatecount;
			angle2-=rotatecount;
			yield;
			}
			count++;
		}
		
		task Spread(x, y, rot){
		let ang = 0;
		let random = rand(0,360);
			ascent(i in 0..6){
				ascent(j in 0..6){
				CreateShotA2(x, y, 0.5, random+j*360/6+ang, 0.01, 4, RICE_M_BLUE, 25);
				}
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 50);
			ang+=rot*10;
			wait(5);
			}
		}
	}
}

task LaserSoundTimer(time){

wait(time);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser1.wav", 50);
}
task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	SetCommonData("deathsound",1);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 