#include".\shot\AllStarShot_Const.txt"
#include".\Resources.txt"
#include".\selibrary.txt"
#include".\lib\AnimLib.h"
#include".\lib\DialogueLibrary.h"
#include".\OzzieEffects.txt"

let Koishi = ID_INVALID;
let KoishiX = 0;
let KoishiY = 0;

let imgKoishi = CSD~"./img/dot_Koishi.png";

@Event{
    SetTimer(999);
    SetLife(1200);
    SetScore(1000000);
}
 
@Initialize{
	SetAutoDeleteObject(true);
	Koishi = ObjEnemy_Create(OBJ_ENEMY_BOSS);	
    ObjEnemy_Regist(Koishi);	
	
	ObjMove_SetY(Koishi, GetCenterY-120);
	ObjMove_SetX(Koishi, GetCenterX);
	
	RenderKoishi;
	BossManage;
	MainTask;     
}

task RenderKoishi{
	ObjPrim_SetTexture(Koishi,imgKoishi);
	ObjSprite2D_SetDestCenter(Koishi);	
	ObjRender_SetScaleXYZ(Koishi,1,1,0);
	
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 32, 32, 96, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 32, 160, 96, 224);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 32, 288, 96, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 160, 32, 224, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 160, 160, 224, 224);
	
	ObjAnim_AddFrameA1(Koishi, ANIM_MOVE, 288, 288, 352, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_MOVE, 288, 416, 352, 480);
	ObjAnim_AddFrameA1(Koishi, ANIM_MOVEEND, 288, 288, 352, 352);
		
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 544, 32, 608, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 544, 160, 608, 224);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 544, 288, 608, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 672, 32, 736, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 672, 160, 736, 224);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 672, 288, 736, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACKEND, 544, 160, 608, 224);
	
	ObjAnim_SetLoopPointA1(Koishi, ANIM_MOVE, 1);
	ObjAnim_SetLoopPointA1(Koishi, ANIM_ATTACK, 5);
	ObjAnim_SetSpeedA1(Koishi, ANIM_IDLE, 7);
	ObjAnim_SetSpeedA1(Koishi, ANIM_MOVE, 4);
	ObjAnim_SetSpeedA1(Koishi, ANIM_ATTACK, 3);
	ObjAnim_SetSpeedA1(Koishi, ANIM_ATTACKEND, 3);
	ObjAnim_StartAnimationA1(Koishi, 10, 3);
}


@MainLoop{
	yield;
}

task MainTask{	
	ObjEnemy_SetDamageRate(Koishi,0,0);
	wait(130);
	SE_Play(charge1,100);
	ConcentrationA2(Koishi,"HEART",60,7,150,[255,100,255]);
	NotifyEventAll(EV_USER +1,0);
	ObjEnemyBossScene_SetSpellTimer(GetEnemyBossSceneObjectID,5940);
	FireTask;	
}

task Movement{
	loop{
		if(GetPlayerX>GetStgFrameWidth/2-100 && GetPlayerX<GetStgFrameWidth/2+100){
			ObjMove_SetDestAtWeight(Koishi,GetPlayerX,GetStgFrameHeight/2-rand(100,150),20,2);}
		else if(GetPlayerX<GetStgFrameWidth/2-100){
			ObjMove_SetDestAtWeight(Koishi,GetStgFrameWidth/2-100,GetStgFrameHeight/2-rand(100,150),20,2);}
		else if(GetPlayerX>GetStgFrameWidth/2+100){
			ObjMove_SetDestAtWeight(Koishi,GetStgFrameWidth/2+100,GetStgFrameHeight/2-rand(100,150),20,2);}
	wait(180);}
}

task FireTask{
wait(130);
ObjEnemy_SetDamageRate(Koishi,30,4);
Movement;
loop{
	fire;
	wait(120);}
}

let angleT = 0;

task fire{
	loop(10.2515) {
	SE_Play(shot,30);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),4,angleT+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),4.15,angleT+557+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),4.3,angleT+80+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),4.45,angleT+120+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),4.60,angleT+160+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),4.75,angleT+200+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),5,angleT+2557+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),5.15,angleT+280+20-90,557,0);
	CreateShotA1(KoishiX+120*cos(angleT-90),KoishiY+120*sin(angleT-90),5.3,angleT+320+20-90,557,0);
	
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),5.3,-angleT+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),5.15,-angleT+557+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),5,-angleT+80+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),4.75,-angleT+120+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),4.60,-angleT+160+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),4.45,-angleT+200+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),4.3,-angleT+2557+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),4.15,-angleT+280+20-90,559,0);
	CreateShotA1(KoishiX+120*cos(-angleT-90),KoishiY+120*sin(-angleT-90),4,-angleT+320+20-90,559,0);
	angleT+=360/10.2515;
	wait(5);
	}
}

task BossManage{

	while(ObjEnemy_GetInfo(Koishi,INFO_LIFE)>0){
        KoishiX = ObjMove_GetX(Koishi);
        KoishiY = ObjMove_GetY(Koishi);
		

        ObjEnemy_SetIntersectionCircleToShot(Koishi, KoishiX, KoishiY, 20);
		yield;
	}
	
	Obj_Delete(Koishi);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    CloseScript(GetOwnScriptID()); 
}