//e[Single]
#ScriptVersion[3]
#ID["DT_31_ALICE_S03"]
//System["script/default_system/Default_System.txt"]
#Title["ALICE_S03"]
#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_Alice.txt"

let objEnemy;	//GIuWFNg
let pathDot = GetCurrentScriptDirectory() ~ "./../../img/alice_dot.png";
let pathCutin = GetCurrentScriptDirectory() ~ "./../../img/alice_cutin.png";
let pathTimer = GetCurrentScriptDirectory() ~ "./../../se/timer.wav";
let pathShot = GetCurrentScriptDirectory() ~ "./../../se/do.wav";
let pathShot2 = GetCurrentScriptDirectory() ~ "./../../se/re.wav";
let pathShot3 = GetCurrentScriptDirectory() ~ "./../../se/mi.wav";

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

@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ݒ
		SetScriptResult(5000);	//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,450,600);
	SetAction(ACT_SPELL,120);
	Wait(180);
	
	Fire();
	End(-1);
	
	Wait(30);
	SetDamageRateType();
}

//U
task Fire(){
	Circle(GetClipMinX(),GetClipMinY(),7);
	Circle(GetClipMinX(),GetClipMaxY(),7);
	Circle(GetClipMaxX(),GetClipMinY(),-7);
	Circle(GetClipMaxX(),GetClipMaxY(),-7);
	
	let shot;
	let ang;
	
	Wait(135);
	
	loop{
		PlaySE(pathShot3);
		ang = GetAngleToPlayer(objEnemy);
		loop(5){
			shot = CreateLooseLaserA1(ObjMove_GetX(objEnemy)+rand(-16,16),ObjMove_GetY(objEnemy)+rand(-16,16),3,ang,127,8,S_ZORI_N+S_PINK,0);
			Shot_Modify(shot);
			Wait(6);
		}
		Wait(30);
	}
}

task Circle(let x,let y,let dAng){
	let shot = CreateShotA1(x,y,0,0,S_MAGIC,20);
	Shot_Modify(shot);
	ObjShot_SetSpellResist(shot,true);
	CircleEffect(shot,dAng);
	Wait(60);
	
	let way = 10;
	let ang = rand(0,360);
	loop{
		if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){	return;	}
		PlaySE(pathShot);
		loop(way){
			Bullet(x,y,ang,dAng/70,S_RED);
			ang += (360/way);
		}
		ang += dAng;
		ang %= 360;
		Wait(30);
		if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){	return;	}
		else if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 4000){
			PlaySE(pathShot2);
			loop(way){
				Bullet(x,y,ang,dAng/70,S_BLUE);
				ang += (360/way);
			}
		}
		ang += (dAng/2);
		ang %= 360;
		Wait(15);
		if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0){	return;	}
		else if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 2500){
			PlaySE(pathShot2);
			loop(way){
				Bullet(x,y,ang,dAng/70,S_GREEN);
				ang += (360/way);
			}
		}
		ang += (dAng/2);
		ang %= 360;
		Wait(15);
	}
}

task Bullet(let x,let y,let ang,let dAng,let clr){
	let shot = CreateShotA1(x,y,3,ang,S_DOLL+clr,0);
	Shot_Modify(shot);
	yield;
	while(!Obj_IsDeleted(shot)){
		ang += dAng;
		ObjMove_SetAngle(shot,ang);
		yield;
	}
}

task CircleEffect(let id,let dAng){
	let ang = 0;
	dAng /= 10;
	while(!Obj_IsDeleted(id)){
		ang += dAng;
		ang %= 360;
		ObjRender_SetAngleZ(id,ang);
		yield;
	}
}
