//e[Single]
#ScriptVersion[3]
#ID["DT_31_SAKUYA_S01"]
//System["script/default_system/Default_System.txt"]
#Title["SAKUYA_S01"]
#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 = rand(0,360);
	let clr = 0;
	
	Move();
	
	loop{
		if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){	return;	}
		Bullet(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),ang,clr);
		ang += 7;
		clr++;
		clr %= 2;
		ang %= 360;
		Wait(1);
	}
}

task Move(){
	loop{
		PlaySE(pathShot);
		Wait(60);
		SetAction(ACT_MOVE,60);
		SetMoveBoss(60);
		Wait(60);
	}
}

task Bullet(let x,let y,let ang,let clr){
	let color = [S_BGREEN,S_YGREEN][clr];
	let len = 32;
	ReverseEraseEffect(x+len*cos(ang),y+len*sin(ang),[32,255][clr],255,[255,32][clr],16,2);
	Wait(16);
	let shot = CreateShotA1(x+len*cos(ang),y+len*sin(ang),3,ang,S_ZORI_S+color,0);
	Shot_Modify(shot);
	len = 0;
	
	if(clr == 1){
		while(!Obj_IsDeleted(shot)){
			len = GetLengthToObj(ObjMove_GetX(shot),ObjMove_GetY(shot),GetPlayerX(),GetPlayerY());
			if(len < 64){
				ObjMove_SetSpeed(shot,0);
				let dmy = CreateShotA1(ObjMove_GetX(shot),ObjMove_GetY(shot),0,0,S_TINY+color,30);
				Shot_Modify(dmy);
				ObjShot_SetSpellResist(dmy,true);
				loop(60){
					ObjShot_SetDelay(dmy,30);
					yield;
				}
				let way = 9;
				let tAng = rand(0,360);
				loop(way){
					BulletA(ObjMove_GetX(shot),ObjMove_GetY(shot),tAng,color);
					tAng += (360/way);
				}
				yield;
				Obj_Delete(dmy);
				Obj_Delete(shot);
			}
			yield;
		}
	}
}

task BulletA(let x,let y,let ang,let clr){
	let shot = CreateShotA1(x,y,1,ang,S_NORMAL+clr,0);
	Shot_Modify(shot);
	Wait(105);
	ObjShot_FadeDelete(shot);
}
