#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Practice: Spell Card 2-8"]
#Player["./resource/player/Reimu by plasmaflame22/Reimu_A.txt","./resource/player/Reimu by plasmaflame22/Reimu_B.txt","./resource/player/Reimu by plasmaflame22/Reimu_C.txt"]
#Background["./resource/bg/stg02.txt"]
#System["./system/system.txt"]

#include"./resource/cutin/cutin.txt"
#include"./system/effects.txt"
#include"./resource/[library] effects.txt"
#include"./resource/[library] boss.txt"
#include"./resource/[library] se.txt"
let bossObj = 0;
let bossX = 0;
let bossY = 0;
let attack = 0;
let csd = GetCurrentScriptDirectory;
let cutin = csd ~ "./resource/img/cutinstg03.png";
	
@Initialize{
	SetCommonData("BOSS","Aunn");
	SetCommonData("ForceLifebar", 1);
	InstallFont(csd ~ "./resource/blogger sans.ttf");

	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);

	animateBossAunn(bossObj);
	TEtama;
	LoadShot;
	MainTask;
	TEndScript;
	AddGraze(-GetGraze);
	
	SetPlayerLife(1);
	SetAutoDeleteObject(true);
	SetForbidPlayerSpell(true);
}

@Loading{
	LoadTexture(cutin);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(100);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(62);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(11000000);
	}
	case(EV_GAIN_SPELL){
		SetScriptResult(110000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true);
	}
}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	ObjEnemy_SetDamageRate(bossObj, 0, 0);
	ObjEnemy_SetIntersectionCircleToShot(bossObj, bossX, bossY, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj, bossX, bossY, 24);
	yield;
}

@Finalize{
}

task MainTask{
	ObjMove_SetDestAtWeight(bossObj,192,120,6,3);
	loop(60){yield;}
	if(!Obj_IsDeleted(bossObj)){ SE(se_spell);}
	CutIn_Left(cutin,"\"Komainu of the Hakurei Shrine\"");
	loop(120){yield;}
	TPath;
	loop(120){yield;}
	if(!Obj_IsDeleted(bossObj)){ SE(se_ch);
	MakeConcentrationA1(bossObj,"SAKURA",255,128,200,45); }
	loop(120){yield;}
	if(!Obj_IsDeleted(bossObj)){ SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",255,128,200); }
	
	ObjMove_SetDestAtWeight(bossObj,40,80,1,3);
	let enemy = CreateFamilar(bossX,bossY);
	ObjMove_SetDestAtWeight(enemy,384-40,80,1,3);
	loop(120){yield;}
	attack = 1;
	let count = 0;
	loop(150){
		if(Obj_IsDeleted(bossObj)){
			Obj_Delete(enemy); break;}
		ascent(i in -2..3){ if(!Obj_IsDeleted(bossObj)){ SE(se_tan);
			let shotA = CreateShotA1(bossX+60*cos(count*23+i*2),bossY+60*sin(count*23+i*2),1.5,count*23+i*2,371,15);
			TReflectAum1(shotA);}
			yield;
		} if(!Obj_IsDeleted(bossObj)){
		let shotB = CreateShotA1(ObjMove_GetX(enemy)+60*cos(-count*23),ObjMove_GetY(enemy)+60*sin(-count*23),1.5,-count*23,276,15);
		TReflection(shotB);
		count++;
		yield; SE(se_kira);}
	}
	ObjMove_SetDestAtWeight(bossObj,40,224,1,3);
	ObjMove_SetDestAtWeight(enemy,384-40,224,1,3);
	loop(120){
		if(Obj_IsDeleted(bossObj)){
			Obj_Delete(enemy); break;}
			yield;}
	count = 0;
	loop(150){
		if(Obj_IsDeleted(bossObj)){
			Obj_Delete(enemy); break;}
		ascent(i in -2..3){ if(!Obj_IsDeleted(bossObj)){ SE(se_tan);
			let shotA = CreateShotA1(bossX+60*cos(count*23+i*2),bossY+60*sin(count*23+i*2),1.5,count*23+i*2,371,15);
			TReflectAum1(shotA);}
			yield;
		} if(!Obj_IsDeleted(bossObj)){
		let shotB = CreateShotA1(ObjMove_GetX(enemy)+60*cos(-count*23),ObjMove_GetY(enemy)+60*sin(-count*23),1.5,-count*23,276,15);
		TReflection(shotB);
		count++;
		yield; SE(se_kira);}
	}
	ObjMove_SetDestAtWeight(bossObj,40,448-80,1,3);
	ObjMove_SetDestAtWeight(enemy,384-40,448-80,1,3);
	loop(120){
		if(Obj_IsDeleted(bossObj)){
			Obj_Delete(enemy); break;}
			yield;}
	count = 0;
	loop(150){
		if(Obj_IsDeleted(bossObj)){
			Obj_Delete(enemy); break;}
		ascent(i in -2..3){ if(!Obj_IsDeleted(bossObj)){ SE(se_tan);
			let shotA = CreateShotA1(bossX+60*cos(count*23+i*2),bossY+60*sin(count*23+i*2),1.5,count*23+i*2,371,15);
			TReflectAum1(shotA);}
			yield;
		} if(!Obj_IsDeleted(bossObj)){
		let shotB = CreateShotA1(ObjMove_GetX(enemy)+60*cos(-count*23),ObjMove_GetY(enemy)+60*sin(-count*23),1.5,-count*23,276,15);
		TReflection(shotB);
		count++;
		yield; SE(se_kira);}
	}
	loop(240){
		if(Obj_IsDeleted(bossObj)){
			Obj_Delete(enemy); break;}
			yield;}
	Obj_Delete(enemy);
}

task TReflection(obj){
	while(ObjMove_GetX(obj) <= 384){yield;}
	ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
	ObjShot_SetDelay(obj,15);
	ObjShot_SetGraphic(obj,281);
}

task TReflectAum1(obj){
	while(ObjMove_GetX(obj) >= 0){yield;}
	ObjShot_SetGraphic(obj,373);
	ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
	while(ObjMove_GetX(obj) <= -20+25*5){yield;}
	let objH = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),25,ObjMove_GetAngle(obj),1,0);
	ObjMove_SetSpeed(obj,0);
	Obj_SetVisible(objH,false);
	ObjShot_SetAutoDelete(objH, false);
	ObjShot_SetIntersectionEnable(objH,false);
	while(ObjMove_GetX(objH) <= 384+20-25*5){yield;}
	ObjMove_SetSpeed(objH,0);
	CreateStraightLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetAngle(obj),GetObjectDistance(obj,objH),6,30,1014,60);
	loop(60){yield;} 
	if(!Obj_IsDeleted(bossObj)){SE(se_lazer2);}
}

task TPath{
	ascent(i in 0..25){
		if(Obj_IsDeleted(bossObj)){break;}
		CreateShotA1(-10+i*5,-10,2,90,98,30);
		CreateShotA1(-20+i*5,-20,2,90,98,30);
		CreateShotA1(-30+i*5,-30,2,90,98,30);
		
		CreateShotA1(384+10-i*5,-10,2,90,98,30);
		CreateShotA1(384+20-i*5,-20,2,90,98,30);
		CreateShotA1(384+30-i*5,-30,2,90,98,30);
		loop(3){yield;}
	}
	while(!Obj_IsDeleted(bossObj)){
		if(Obj_IsDeleted(bossObj)){break;}
		CreateShotA1(-10+25*5,-10,2,90,98,30);
		CreateShotA1(-20+25*5,-20,2,90,98,30);
		CreateShotA1(-30+25*5,-30,2,90,98,30);
		
		CreateShotA1(384+10-25*5,-10,2,90,98,30);
		CreateShotA1(384+20-25*5,-20,2,90,98,30);
		CreateShotA1(384+30-25*5,-30,2,90,98,30);
		ascent(i in 0..19){
			let shot = CreateShotA1(121+i*8,-30,2,90,97,30);
			ObjShot_SetIntersectionEnable(shot,false);
			Obj_SetRenderPriorityI(shot,30);
			ObjRender_SetAlpha(shot,100);
		}
		
		loop(5){yield;}
	}
}