#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main{
	#include_function ".\lib\lib_anime_Daiyousei.txt"
	let imgBoss=GetCurrentScriptDirectory~"img\Boss\dot_daiyousei.png";
        #include_function ".\lib\lib_Bosscommon.txt"
        #include_function ".\lib\lib_SpellBouns.txt"
	let bounus=3000000;		//スペル基本得点

    	@Initialize
        {
	  SetLife(500);
	  SetDamageRate(0,0);
	  SetAction(ACT_MOVE,60);
	  SetCountDown;
          Tmain;
	}
	
	@MainLoop
	{  
                yield;
                SetCollisionA(GetX(),GetY(),32);
		SetCollisionB(GetX(),GetY(),16);
		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;

        } 
	
	@Finalize
	{       
		let Power=int(GetCommonData("Power")/100);	//パワー取得
		loop(20){
			CreateShotFromScript("I_Item",GetX+rand(-70,70),GetY+rand(-70,70),0,0,0,1);
		}		
		if(Power>=5){
			loop(10){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}
		else{
			CreateShotFromScript("P_Item" ,GetX,GetY,0,0,0,1);
			loop(6){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}

		SetCommonData("SpellCade",false);


		if(GetMissCountInThisSpell == 0 && GetBombCountInThisSpell == 0 && IsTimeOut == false){//スペル取得した時
			PlaySE("seGetSpellCardBonus.wav");			//効果音
			SetCommonData("GetSpell",true);				//スペルを取得したかどうか
		}
	}

	@DrawLoop
	{//描画
                SetColor(255,255,255);
		SetRenderState(ALPHA);
		DrawBoss( imgBoss );
	}

        task Tmain
        {
		yield;
		//前のスペルを収得したかどうか--------------------------------------------------------------
		if(GetCommonData("GetSpell")==true){GetSpellEffect( GetCommonData("GetSpellBounus_B") );}

		loop(90){yield;}
		SpellCutName(0,32,bounus);		//カード名
	 	SetDamageRate(20,10);
		MagicCircle(false);
		SetMovePosition03(cx,cy-10,10,4);
		SetAction(ACT_MOVE,60);
		SetTimer(41);
		loop(120){yield;}
		Shot01;
		loop(150){yield;}
		loop{
			Concentration01(60);//溜めモーション
			SetAction(ACT_SHOT_B,60);
        		loop(50){yield;}
			SetAction(ACT_SHOT_A,60);
        		loop(20){yield;}
			Shot02;
			PlaySE(shoot13);
			loop(80){yield;}
		}
	}


	task Shot01{	
		let loops=110;
		alternative(Level)
		case(1){//hard
		    loops=135;
		}
		let angle=0;
		let L=290;
		loop(loops){
			PlaySE(arrow01);
			loop(30){
				CreateShot01(cx+L*cos(angle),cy+L*sin(angle),3,angle+90,84,5);
				CreateShot01(cx+L*cos(angle),cy+L*sin(angle),3,angle-90,86,5);
				angle+=12;
			}
			L--;
			angle+=2;
			loop(10){yield;}
		}
		loop{
			PlaySE(arrow01);
			loop(30){
				CreateShot01(cx+L*cos(angle),cy+L*sin(angle),3,angle+90,84,5);
				CreateShot01(cx+L*cos(angle),cy+L*sin(angle),3,angle-90,86,5);
				angle+=12;
			}
			angle+=2;
			loop(10){yield;}
		}
	}

	task Shot02{	
		let Pangle=18;
		let wait=4;
		let speed=5;
		alternative(Level)
		case(1){//hard
			Pangle=4.5;
			wait=1;
			speed=6;
		}
                let obj = Obj_Create(OBJ_SHOT);
		Obj_SetX(obj,GetX);
		Obj_SetY(obj,GetY);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,GetAngleToPlayer);
		ObjShot_SetGraphic(obj,52);
		ObjShot_SetDelay(obj,20);
		ObjShot_SetBombResist(obj,true);
		let Sangle=GetAngleToPlayer;
		loop(20){yield;}
		let angle=0;
		let Base=GetAngleToPlayer;
		while( !Obj_BeDeleted(obj) ){
			effectshot(Obj_GetX(obj),Obj_GetY(obj),Sangle);
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.4,Base+angle,27,8);
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.4,Base-angle,27,8);
			angle+=Pangle;
			loop(wait){yield;}
		}

	}
        task effectshot(X,Y,angle){
		let speed=5;
		alternative(Level)
		case(1){//hard
			speed=6;
		}
                let obj = Obj_Create(OBJ_SHOT);
		Obj_SetX(obj,X);
		Obj_SetY(obj,Y);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,52);
		ObjShot_SetBombResist(obj,true);
		Obj_SetCollisionToPlayer(obj,false);
		Obj_SetAlpha(obj,0);
		loop(5){
			ObjShot_SetDelay(obj,28);
			yield;
		}
		loop(30){yield;}
		Obj_Delete(obj);
        }


}
#include_script".\Item01.txt"
#include_script".\Item02.txt"
#include_script".\Item04.txt"