#include"./lib/lib_shot/shot_const.txt"
#include"./function.txt"

let BossObj;
let BossObjX = 0;
let BossObjY = 0;

let BossAlpha = 0;
let hitbox = [48,96];
let imgBossObj 	= bossSprite;

let objScene = GetEnemyBossSceneObjectID();

let stopall=false;

@Initialize 
{
	SetAutoDeleteObject	(true);
	BossObj = ObjEnemy_Create	(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist				(BossObj);
	ObjEnemy_SetDamageRate		(BossObj,0,0);
	ObjRender_SetPosition		(BossObj,320,-120,0);
	mainTask;
} 

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(0);
	}
}

@MainLoop 
{
	ObjRender_SetAlpha		(BossObj,BossAlpha);
	BossObjX = ObjMove_GetX	(BossObj);
	BossObjY = ObjMove_GetY	(BossObj);
	yield;
} 

@Finalize 
{ 
} 

task mainTask
{
	SetForbidPlayerShot(true);
	loop(120){yield;}
	spriteIdle(BossObj,300,imgBossObj,1);
	ObjRender_SetPosition(BossObj,320,120,0);
	playSE(seCharge0,80);
	mistCharge;
	loop(180){yield;}
	visible;
	loop(120){yield;}
	let plSpeed = GetPlayerSpeed();
	SetPlayerSpeed(0,0);
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(435,450,"Hiya there",120,true,8);
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(430,450,"Oh, it's you",120,true,7);
	
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(245,450,"Well, um",120,true,15);
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(245,450,"What are you doing here?",120,true,11);
	
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(435,450,"Oh, I'm adjusting the taste of my drink",180,true,1);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(435,450,"By using the power of four seasons",180,true,8);
	
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(245,450,"Please don't use such power for trivial stuff",180,true,14);
	spriteIdle(BossObj,180,imgBossObj,1);
	chatBox(245,450,"Unless it's a notable amount",150,true,13);
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(245,450,"Such as for a feast",120,true,10);
	
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(430,450,"Ah, you're right, it's a feast",180,true,1);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(430,450,"Everyone has been so busy lately",180,true,2);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(430,450,"So I made enough drink for everyone",180,true,1);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(435,450,"Just so everyone can try to loosen things up",180,true,8);
	
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(245,450,"Don't you think you're making too much?",180,true,13);
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(245,450,"No one drinks that much-",120,true,10);
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(245,450,"Wait...",120,true,15);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(245,450,"Are you inviting your own kind to the surface?",180,true,11);
	
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(430,450,"Everyone just gathers naturally by my call",180,true,1);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(435,450,"Who knows how many or what will come~",180,true,8);
	
	spriteIdle(BossObj,150,imgBossObj,1);
	chatBox(245,450,"That's decided",120,true,10);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(250,450,"It's time to put a stop to it",180,true,12);
	
	SetCommonData("bgmPreBattle",false);
	spriteIdle(BossObj,180,imgBossObj,1);
	chatBox(430,450,"Well, ain't you a downer?",150,true,4);
	spriteIdle(BossObj,210,imgBossObj,1);
	chatBox(430,450,"But can you actually defeat me?",180,true,1);
	stageAccelerate;
	SetCommonData("bgmBoss",true);
	spriteIdle(BossObj,330,imgBossObj,1);
	chatBox(420,450,"Witness the strength of oni who bear the power of the four seasons!",300,false,3);
	SetForbidPlayerShot(false);
	SetPlayerSpeed(plSpeed[0],plSpeed[1]);
	TEnd;
}

task stageAccelerate
{
	let speed = 0.5;
	loop(120)
	{
		speed += 2.5/120;
		SetCommonData("bgSpeed",speed);
		yield;
	}
}

task mistCharge
{
	let pos = [320,120];
	let xyz = 15;
	let time = 0;
	let alpha = 0;
	let range = 480;
	let lp = 24;
	let m = 1;
	let lpp = 12;
	let ang = rand(0,360);
	loop(lp)
	{
		time 	+= 180/lp;
		alpha 	+= 150/lp;
		xyz 	+= 105/lp;
		range 	-= 450/lp;
		lpp		-= 6/lp;
		loop(lpp)
		{
			let post = [pos[0]+range*sin(ang),pos[1]+range*cos(ang)];
			charge(sfxCloud,BLEND_ADD_ARGB,255,255,255,xyz,post[0],post[1],time,alpha,m,ang);
			ang += 360 / lpp;
			ang = ang%360;
		}
		ang += 360 / lp;
		loop(120/lp){yield;}
		m *= -1;
	}
}

task visible
{
	loop(120)
	{
		BossAlpha += 256 / 120;
		yield;
	}
}

task TEnd
{
	Obj_Delete(BossObj);
	CloseScript(GetOwnScriptID());
}