#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Training: Spell Card 1-4"]
#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 csd = GetCurrentScriptDirectory;
let cutin = csd ~ "./resource/img/cutinstg02.png";

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

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

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

	animateBossSakata;
	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);
	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(30){yield;} if(!Obj_IsDeleted(bossObj)){SE(se_spell);}
	CutIn_Right(cutin,"Yamanba's Blade \"Ability to Kill People\"");
	loop(150){yield;}
	TMovement;
	while(!Obj_IsDeleted(bossObj)){
		TSmall;
		loop(240){yield;}
		TSmall;
		loop(240){yield;}
		TSmall;
		loop(270){yield;}
			if(!Obj_IsDeleted(bossObj)){ SE(se_ch);
			MakeConcentrationA1(bossObj,"SAKURA",255,150,64,45); }
		loop(90){yield;}
		attack = 1;
		loop(5){
			TBig(0,rand(60,388),rand(-30,30));
			loop(5){ yield; }
			TBig(384,rand(60,388),rand(150,210));
			loop(5){ yield; }}
		attack = 0;
		loop(640){yield;}
	}
}

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

task TSmall(){
	let bub = CreateShotOA1(bossObj,4,GetAngleToPlayer(bossObj),1,0);
	Obj_SetVisible(bub,false);attack = 1;
	while(!Obj_IsDeleted(bub)){
		TSharp;
		loop(8){
			if(Obj_IsDeleted(bossObj)){break;}
			yield;}
	}
	attack = 0;

	task TSharp{
		let r = 80;
		let ang = rand(0,359);
		let angle = 0;
		let x = ObjMove_GetX(bub);
		let y = ObjMove_GetY(bub);
		SE(se_slash);
		loop(20){
			if(Obj_IsDeleted(bossObj)){break;} 
			let s = CreateShotA1(0,0,0,0,530,15);
			ObjMove_SetPosition(s,x+r*cos(ang+atan2(ObjMove_GetY(s)-y,ObjMove_GetX(s)-x)),y+r*sin(ang+atan2(ObjMove_GetY(s)-y,ObjMove_GetX(s)-x)));
			ObjMove_SetAngle(s,ang+atan2(ObjMove_GetY(s)-y,ObjMove_GetX(s)-x));
			ObjMove_AddPatternA3(s,90,4,ang+angle,-0.1,0,1,873);
			r-=(80*2)/20;
			angle+=25;
			yield;
		}
		loop(90){yield;}
		if(!Obj_IsDeleted(bossObj)){
		SE(se_tan2);}
	}
}

task TBig(x,y,angle){
	let r = 0;
	let ang = rand(0,360);
	let angle2 = 0;
	if(!Obj_IsDeleted(bossObj)){
	SE(se_slash);
	let laser = CreateLooseLaserA1(x,y,45,angle,360,20,19,0);
	ObjShot_SetIntersectionEnable(laser,false);}
	loop(45){yield;}
	if(!Obj_IsDeleted(bossObj)){
	loop(60){
		let s = CreateShotA1(x+r*cos(angle),y+r*sin(angle),0,angle,519,30);
		ObjMove_AddPatternA3(s,120,0.5,ang+angle2,0,0,0,871);
		r+=160/20;
		angle2+=18;
	}}
	loop(150){
		if(Obj_IsDeleted(bossObj)){break;}
		yield;}
	if(!Obj_IsDeleted(bossObj)){
	SE(se_kira);}
}