#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP3"]
#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("Aura Sign &quot;Clarification of the Lower Beings&quot;", [198, 132, 39], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Shou.png", 0);
	
	ObjEnemy_SetDamageRate(objBoss, 60, 70);
	
	loop{
	ascent(j in 0..4){
	let obj = PagodaLaser(GetStgFrameWidth/2+320*cos(90+j*360/4), GetStgFrameHeight/2+320*sin(90+j*360/4),0,0,2,270+j*360/4,0,0,30,[154, 127, 14],60,180);
	LaserSoundTimer(60);
	Dual(obj);
	}
	wait(60);
	ascent(j in 0..4){
	let obj = PagodaLaser(GetStgFrameWidth/2+400*cos(45+j*360/4), GetStgFrameHeight/2+400*sin(45+j*360/4),0,0,2,270-45+j*360/4,0,0,30,[154, 127, 14],60,180);
	LaserSoundTimer(60);
	Dual(obj);
	}
	wait(60);
	}
	
	task Dual(obj){
	let obj2 = CreateStraightLaserA1(ObjMove_GetX(obj)+5*cos(ObjStLaser_GetAngle(obj)+90), ObjMove_GetY(obj)+5*sin(ObjStLaser_GetAngle(obj)+90), ObjStLaser_GetAngle(obj), 600, 10, 180, LASER_RED, 60);
	Obj_SetVisible(obj2, 0);
	Trail(obj2);
	}
	
	task Trail(obj){
	wait(170);
	let random = rand(0,360);
	ascent(i in 0..64){
	let obj2 = CreateShotA1(ObjMove_GetX(obj)+(i*12)*cos(ObjStLaser_GetAngle(obj)),ObjMove_GetY(obj)+(i*12)*sin(ObjStLaser_GetAngle(obj)), 0, ObjStLaser_GetAngle(obj)+90, RICE_S_YELLOW, 25);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 50);
	Obj_SetRenderPriorityI(obj2, 25);
	let random = rand(0,60);
	let random2 = rand(-0.1, 0.1);
	ObjMove_AddPatternA2(obj2, 120-i+random, NO_CHANGE, NO_CHANGE, 0.01, 0 , 10);
	ObjMove_AddPatternA2(obj2, 120-i+random+180, NO_CHANGE, NO_CHANGE, -0.01, 0, -10);
	Render(obj2);
	yield;
	}
	
	task Render(obj2){
	wait(120);
	Obj_SetRenderPriorityI(obj2, 50);
	}
	}
}

task LaserSoundTimer(time){
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/barrage.wav", 90);
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());
} 