#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SP1"]
#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("Slug Sign &quot;Towards Justice and Virtue&quot;", [198, 132, 39], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Shou.png", 0);
	
	attack = true;
	ObjEnemy_SetDamageRate(objBoss, 100, 100);
	loop{
	ascent(i in 0..8){
	let obj = PagodaLaser(BossX, BossY,0,0,2,270+i*360/8,0,0,40,[255, 199, 17],60,120);
	Trail(obj);
//Laser(obj);
	LaserSoundTimer(60);
	wait(15);
	}
	descent(i in 0..8){
	let obj = PagodaLaser(BossX, BossY,0,0,2,270+i*360/8-22.5,0,0,40,[255, 199, 17],60,120);
	Trail(obj);
//Laser(obj);
	LaserSoundTimer(60);
	wait(15);
	}
	}
	
	task Trail(obj){
	wait(170);
	let random = rand(0,360);
	ascent(i in 0..48){
	CreateShotA2(ObjMove_GetX(obj)+(i*12)*cos(ObjStLaser_GetAngle(obj)),ObjMove_GetY(obj)+(i*12)*sin(ObjStLaser_GetAngle(obj)), 0, ObjStLaser_GetAngle(obj)+random+i*42, 0.005, 1, FIREBALL_YELLOW, 25);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90);
	yield;
	}
	}

	task Laser(obj){
	wait(170);
	ascent(i in 0..12){
	let las =CreateCurveLaserA1(ObjMove_GetX(obj)+(i*52)*cos(ObjStLaser_GetAngle(obj)),ObjMove_GetY(obj)+(i*52)*sin(ObjStLaser_GetAngle(obj)), 2, ObjStLaser_GetAngle(obj)+90, 20, 10, LASER_YELLOW, 25);
	let las2 = CreateCurveLaserA1(ObjMove_GetX(obj)+(i*52)*cos(ObjStLaser_GetAngle(obj)),ObjMove_GetY(obj)+(i*52)*sin(ObjStLaser_GetAngle(obj)), 2, ObjStLaser_GetAngle(obj)-90, 20, 10, LASER_YELLOW, 25);
	ObjMove_SetAcceleration(las, -0.02);
	ObjMove_SetMaxSpeed(las, rand(-1,-2));
	ObjMove_SetAcceleration(las2, -0.02);
	ObjMove_SetMaxSpeed(las2, rand(-1,-2));
	ObjCrLaser_SetTipDecrement(las, 0);
	ObjCrLaser_SetTipDecrement(las2, 0);
	yield;
	}
	}
}

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());
} 