//e[Single]
#ScriptVersion[3]
#ID["DT_31_SAKUYA_S00"]
//System["script/default_system/Default_System.txt"]
#Title["SAKUYA_S00"]
#Text[""]
//Image[""]
//Background["script/default_system/Default_Background_IceMountain.txt"]
//Player[]

#include "./../../cmn/common.txt"
#include "./../../cmn/shotConst.txt"
#include "./../../cmn/Effect.txt"
#include "./../../cmn/boss/commonBossFunc.txt"
#include "./../../cmn/commonFunc.txt"
#include "./../../cmn/lib/lib_anime_Suwako.txt"

let objEnemy;	//GIuWFNg
let pathDot = GetCurrentScriptDirectory() ~ "./../../img/suwako_dot.png";
let pathCutin = GetCurrentScriptDirectory() ~ "./../../img/suwako_cutin.png";
let pathTimer = GetCurrentScriptDirectory() ~ "./../../se/timer.wav";
let pathShot = GetCurrentScriptDirectory() ~ "./../../se/shot0.wav";

@Loading{
	if(!IsCommonDataAreaExists(nsStage)){
		LoadTexture(pathDot);
		LoadTexture(pathCutin);
		LoadSound(pathTimer);
		LoadSound(pathShot);
	}
}

@Initialize{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	SetShotAutoDeleteClip(64,64,64,64);
	
	InitializeAction(objEnemy, pathDot);
	Render();
//	BackGround(pathCutin, 450, 600);
	Schedule();
}

@MainLoop{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//蔻(e)o^
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 24);//蔻(̓)o^
	
	yield;
}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2500);	//Ctݒ
	}
	case(EV_REQUEST_TIMER){
		let timerBoss = 60;
		SetScriptResult(timerBoss);	//Ԑݒ
		TimerSE(timerBoss);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(10);	//XyJ[h{[iXݒ
		T_SpellCardBonus(50000);
	}
//	case(EV_REQUEST_IS_DURABLE_SPELL){
//		SetScriptResult(true);	//ϋvXyJݒ
//	}
	others{}
}

@Finalize{}

task Schedule(){
//	ObjMove_SetX(objEnemy, GetStgFrameWidth()+64);
//	ObjMove_SetY(objEnemy, GetStgFrameHeight()/2);
	ObjMove_SetDestAtFrame(objEnemy, GetStgFrameWidth()-100, GetStgFrameHeight()/2, 60);
	SetAction(ACT_MOVE, 60);
	Wait(60);
	
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());
	CutIn(pathCutin,180,191,550,600);
	SetAction(ACT_SPELL,120);
	Wait(180);
	
	Fire();
	End(-1);
	
	Wait(30);
	SetDamageRateType();
}

//U
task Fire(){
	let ang = 0;
	let way = 6;
	let clr = 0;
	
	loop{
		SetAction(ACT_SHOT_A,36);
		Wait(12);
		if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){	return;	}
		ang = GetAngleToPlayer(objEnemy);
		PlaySE(pathShot);
		loop(way){
			Bullet(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),ang,clr);
			ang += (360/way);
		}
		Wait(24);
		SetAction(ACT_MOVE,60);
		SetMoveBoss(60);
		Wait(60);
		clr++;
		clr %= 2;
	}
}

task Bullet(let x,let y,let ang,let clr){
	let spd = 3;
	let color = [S_GREEN,S_YELLOW][clr];
	let shot = CreateShotA1(x,y,spd,ang,S_NORMAL+color,0);
	Shot_Modify(shot);
	
	let way = 10;
	let len = 32;
	let aAng = rand(0,360);
	
	loop(way){
		BulletA(shot,aAng,len,color);
		aAng += (360/way);
	}
	
	let cnt = 0;
	while(!Obj_IsDeleted(shot)){
		if(ObjMove_GetX(shot) < 0 || ObjMove_GetX(shot) > GetStgFrameWidth()){
			ObjMove_SetAngle(shot,180-ObjMove_GetAngle(shot));
		}else if(ObjMove_GetY(shot) < 0 || ObjMove_GetY(shot) > GetStgFrameHeight()){
			ObjMove_SetAngle(shot,-1*ObjMove_GetAngle(shot));
		}
		cnt++;
		if(cnt > 300){
			ObjShot_FadeDelete(shot);
		}
		else if(cnt > 180){
			spd -= 0.05;
			if(spd < 0){
				spd = 0;
			}
			ObjMove_SetSpeed(shot,spd);
		}
		yield;
	}
}

task BulletA(let id,let ang,let len,let clr){
	let shot = CreateShotA1(ObjMove_GetX(id)+len*cos(ang),ObjMove_GetY(id)+len*sin(ang),0,ang,S_TINY+clr,0);
	Shot_Modify(shot);
	
	while(!Obj_IsDeleted(id)){
		ObjMove_SetX(shot,ObjMove_GetX(id)+len*cos(ang));
		ObjMove_SetY(shot,ObjMove_GetY(id)+len*sin(ang));
		yield;
	}
	
	ObjMove_SetSpeed(shot,1);
}
