//e[Single]
#ScriptVersion[3]
#ID["DT_31_RAIKO_S02"]
//System["script/default_system/Default_System.txt"]
#Title["RAIKO_S02"]
#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_Raiko.txt"
#include "./../../cmn/shotConst_Laser2.txt"

let objEnemy;	//GIuWFNg
let pathDot = GetCurrentScriptDirectory() ~ "./../../img/raiko_dot.png";
let pathCutin = GetCurrentScriptDirectory() ~ "./../../img/raiko_cutin.png";
let pathTimer = GetCurrentScriptDirectory() ~ "./../../se/timer.wav";
let pathShot = GetCurrentScriptDirectory() ~ "./../../se/do.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,700,600);
	SetAction(ACT_SPELL,120);
	Wait(180);
	
	Fire();
	End(-1);
	
	Wait(30);
	SetDamageRateType();
}

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

task Bullet(let x,let y,let ang){
	let shot;
	let dmy;
	
	dmy = CreateShotA1(x,y,0,0,S_BIG+S_YELLOW,10);
	Shot_Modify(dmy);
	shot = CreateShotA1(x,y,4,ang,S_NOTE+S_ORANGE,10);
	Shot_Modify(shot);
	Eff(dmy,shot);
	
	yield;
	let tAng;
	loop(60){
		if(Obj_IsDeleted(shot)){	break;	}
		if(ObjMove_GetX(shot) < GetScreenWidth()/2){	break;	}
		
		tAng = GetAngleToPlayer(shot);
		tAng = (ang - tAng) % 360;
		if(tAng < 5 && tAng > -5){	ang = GetAngleToPlayer(shot);	}
		else if(tAng < 180){	ang -= 5;	}
		else{	ang += 5;	}
		ObjMove_SetAngle(shot,ang);
		yield;
	}
	
	while(!Obj_IsDeleted(shot)){
		if(ObjMove_GetX(shot) < 0 || ObjMove_GetX(shot) > GetStgFrameWidth() || ObjMove_GetY(shot) < 0 || ObjMove_GetY(shot) > GetStgFrameHeight()){
			let way = 8;
			tAng = 180;
			loop(way){
				dmy = CreateLooseLaserA1(ObjMove_GetX(shot),ObjMove_GetY(shot),4,tAng,128,20,S_LASER_2,0);
				Shot_Modify(dmy);
				tAng += (360/way);
			}
			Obj_Delete(shot);
		}
		yield;
	}
}

task Eff(let id,let main){
	while(Obj_IsDeleted(main)){
		ObjMove_SetPosition(id,ObjMove_GetX(main),ObjMove_GetY(main));
		yield;
	}
	Obj_Delete(id);
}
