#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Training: Spell Card 1-3"]
#Player["./resource/player/Marisa by plasmaflame22/Marisa_A.txt","./resource/player/Marisa by plasmaflame22/Marisa_B.txt","./resource/player/Marisa by plasmaflame22/Marisa_C.txt"]
#Background["./resource/bg/stg01.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 damage = 0;
let csd = GetCurrentScriptDirectory;
let cutin = csd ~ "./resource/img/cutinstg01.png";

@Initialize{
	SetCommonData("BOSS","Eternity");
	InstallFont(csd ~ "./resource/blogger sans.ttf");

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

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

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

@Loading{
	LoadTexture(cutin);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(500);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(120);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(11000000);
	}
}

@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, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj, bossX, bossY, 24);
	yield;
}

@Finalize{
}

task MainTask{
	ObjMove_SetDestAtWeight(bossObj,192,120,6,4);
	loop(80){yield;} if(!Obj_IsDeleted(bossObj)){SE(se_spell);}
	CutIn_Left(cutin,"\"Schumann's Butterfly Masquerade\"");
	loop(120){yield;}
	damage = 1;
	TMovement;
	while(!Obj_IsDeleted(bossObj)){
		loop(10){
			if(!Obj_IsDeleted(bossObj)){
			TLine(rand(60,324),0);
			CreateShotA2(rand(0,384),0,6,rand(80,100),-0.2,1,824,30);}
			loop(45){yield;}
			if(!Obj_IsDeleted(bossObj)){
			CreateShotA2(rand(0,384),0,6,rand(80,100),-0.2,1,827,30);}
			loop(45){yield;}
		}
		let angle = 0;
		let color = 0;
		loop(30){yield;}
			if(!Obj_IsDeleted(bossObj)){ SE(se_ch);
			MakeConcentrationA1(bossObj,"FLOWER",255,150,64,45); }
		loop(30){yield;}
		let gr = 0;
		if(!Obj_IsDeleted(bossObj)){
		ascent(i in 0..11){
			let type = truncate(rand(0,4));
			if(type == 1){gr = 823;}
			if(type == 2){gr = 826;}
			if(type == 3){gr = 829;}
			CreateShotA2(0+i*384/10,0,6,90,-0.2,rand(0.2,2),gr,30);
			loop(2){yield;}
		}}
		loop(30){yield;}
		attack = 1;
		loop(120){	if(Obj_IsDeleted(bossObj)){break;}
			SE(se_tan); SE(se_kira2);
			CreateShotOA1(bossObj,3,90+80-angle,386,0);
			CreateShotOA1(bossObj,3,90-80+angle,386,0);
			ascent(i in 0..10){
				CreateShotOA1(bossObj,3-i/4,90+80-angle,531,8);
				CreateShotOA1(bossObj,3-i/4,90+80-angle,871,12);

				CreateShotOA1(bossObj,3-i/4,90-80+angle,531,8);
				CreateShotOA1(bossObj,3-i/4,90-80+angle,871,12);}
			angle+=11.5;
			color+=3;
			loop(5){
				if(Obj_IsDeleted(bossObj)){break;}
				yield;}
		}
		attack = 0;
	}
}

task TLine(x,y){
	let angle = 0;
	loop(11){ 
		if(!Obj_IsDeleted(bossObj)){
		SE(se_tan);
		let pap = CreateShotA2(x,y,6,90,-0.1,0,385,15);
		Obj_SetRenderPriorityI(pap,51);
		TManage(pap,angle);
	angle+=15;}
	loop(4){
		if(Obj_IsDeleted(bossObj)){break;}
		yield;}
	}
	if(!Obj_IsDeleted(bossObj)){
		SE(se_kira2);}
	
	task TManage(obj,angle){
		loop(60){yield;}
		if(!Obj_IsDeleted(bossObj)){
			if(ObjMove_GetX(obj) < ObjMove_GetX(bossObj)){
				ObjMove_AddPatternA1(obj,0,3,90+75-angle);
				ascent(i in 0..10){
					let a = CreateShotOA1(obj,3-i/4,90+75-angle,521,8);
					CreateShotOA1(obj,3-i/4,90+75-angle,871,12);}
			}
			if(ObjMove_GetX(obj) > ObjMove_GetX(bossObj)){
				ObjMove_AddPatternA1(obj,0,3,90-75+angle);
				ascent(i in 0..10){
					let a = CreateShotOA1(obj,3-i/4,90-75+angle,521,8);
					CreateShotOA1(obj,3-i/4,90-75+angle,871,12);}
			}
		}
	}
}

task TMovement{
	while(!Obj_IsDeleted(bossObj)){
		ObjMove_SetDestAtWeight(bossObj,192+rand(-90,90),100+rand(-30,30),15,3);
	loop(240){yield;}}
}