
#ScriptVersion[3]
#Title["導命樹　stg3 spell1 N An"]
#Text["菊符「一輪斬り」N"]
#System["script/Th_mpp/ThMpp_System.dnh"]
#Image[""]
#Background[""]

	#include"../../../Control.dnh"
	#include"../../../lib_kshot.dnh"
	#include"./03_Obj_Texture.dnh"
	#include"./03_Obj_Shot.dnh"
	#include"../../SpellCounter.dnh"

	let csd			= GetCurrentScriptDirectory;
	let se01		= csd~"../../se/boon.wav";
	let enm;
	let ens;
	let spl;
	let MinX		= 0;
	let MinY		= 0;
	let MaxX		= GetStgFrameWidth;
	let MaxY		= GetStgFrameHeight;
	let CenX		= GetStgFrameWidth/2;
	let CenY		= GetStgFrameHeight/2;
	let frame		= 0;
	let count		= 0;
	let timer		= 0;
	let angle1		= 0;
	let angle2		= 0;
	let angle3		= 0;
	let S_count		= 0;
	let T_count		= 0;
	let Damage		= 0;
	let GetTimer	= ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(),INFO_TIMER);
	let EnmInfo		= 0;
	
	@Initialize{
		enm	= ObjEnemy_Create(OBJ_ENEMY_BOSS);
		ObjEnemy_Regist(enm);
		ObjEnemy_SetDamageRate(enm,0,0);//披ダメージを10%に設定
		
		spl	= GetEnemyBossSceneObjectID();
		EnmInfo	= ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_REMAIN_STEP_COUNT);
		
		VSname(0,"Kodama");
		EnemyDisplay03b(enm,true);
		Timer(1,60);
		Hpb("Spell",true,100,0);
		Aura(8,128,128,64);
		RedMagicCircle(1,0);
		RemainStepCount(MinX+12,MinY+23,1,EnmInfo,enm);
		EndEnemy;
		
		ObjMove_SetDestAtWeight(enm,CenX,CenY-100,8,8);

		CreateCommonDataArea("anime");
		SetAreaCommonData("anime","spa",false);
		
		SpellCounter(3,1);
		
		TWaveCircle();
	}

	@Loading{
		
	}

	@MainLoop{
		yield;
		let get_spell	= GetAreaCommonData("spell_counter","get_stage3",0);
		let play_spell	= GetAreaCommonData("spell_counter","play_stage3",0);
		
		/*制限時間処理*/
		GetTimer	= ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(),INFO_TIMER);
		if(GetTimer<=10&&GetTimer>=0&&ObjEnemy_GetInfo(enm,INFO_LIFE)>0){T_count++;}
		alternative(T_count)
		case(1,60,120,180,240){PlaySEs(csd~"../../se/timer2.wav");}
		case(300,360,420,480,540){PlaySEs(csd~"../../se/timer1.wav");}
	
		/*ボム中、使用後一定時間ダメージ無効処理*/
		if( IsPlayerSpellActive && S_count > 120 ){//ボム中
			ObjEnemy_SetDamageRate(enm,200,100);
			Damage=0;
		}
		if(IsPlayerSpellActive==false){Damage++;}
		if(Damage>=180){ObjEnemy_SetDamageRate(enm,200,100);}//ダメージが通る
		
		/*敵の当たり判定を登録 ローカル*/
		let enx		= ObjMove_GetX(enm);
		let eny		= ObjMove_GetY(enm);
		ObjEnemy_SetIntersectionCircleToShot(enm, enx, eny, 32);//当たり判定(自弾)登録
		ObjEnemy_SetIntersectionCircleToPlayer(enm, enx, eny, 24);//当たり判定(体当たり)登録

		if(ObjEnemy_GetInfo(enm,INFO_LIFE)<=0){
			S_count=0;
			count=0;
			frame=0;
			timer=0;
		}
		
		if(S_count==60){
			spl	= GetEnemyBossSceneObjectID();
			ObjEnemyBossScene_StartSpell(spl);
			Cutin("TIREI",128,240,[0.5,0.5],chara_tex[17],1024,1024,255,0,128);
			CutinSP2("ｾﾕｷ蠇ｸｽ｣ﾂﾖﾕｶ｡ｹ",get_spell[1],play_spell[1]);
			BackGroundEffect05();
		}
		
		S_count++;
		count++;
		frame++;
		timer++;
		if(timer==180){
			CherryConcentration(50,csd~"../../se/power_logo.wav",enm);
			frame=timer;
		}
		if(timer==230){
			SetAreaCommonData("anime","spa",true);
		}
		if(frame==280){
			let shote	= [kYELLOW64,kORANGE64];
			loop(5){
				KikuShot1(enx,eny,angle1,1.2,0,10,kWHITE01,shote[angle2],8,0.2);
				angle1+=72;
			}angle1+=rand(0,360);
			angle2++;
			if(angle2==2){angle2=0;}
			PlaySEs(csd~"../../se/shot2.wav");
			frame=260;
		}
	}

	@Event{
		alternative(GetEventType())
		case(EV_REQUEST_LIFE){
			SetScriptResult(5000);//ライフを1500に設定
		}
		case(EV_REQUEST_TIMER){
			SetScriptResult(60);
		}
		case(EV_REQUEST_SPELL_SCORE){
			SetScriptResult(9000000);
		}
		case(EV_GAIN_SPELL){
			SpellCounter_Get(3,1);
		}
	}

	@Finalize{//最後に実行。
	}

	task EndEnemy{
		while(ObjEnemy_GetInfo(enm,INFO_LIFE)>0){
			yield;
		}
		
		let enx = ObjMove_GetX(enm);
		let eny = ObjMove_GetY(enm);
		//爆破の処理を追加
		DeleteShotAll(TYPE_ALL, TYPE_ITEM);//敵弾を全て削除
		
		loop(64){
			ReleaseCherry01(enx,eny,255,0,0,400);
			ReleaseCherry02(rand(MinX,MaxX),rand(MinY,MaxY),255,0,0,200);
			ReleaseCherry02(rand(MinX,MaxX),rand(MinY,MaxY),0,255,0,200);
			ReleaseCherry02(rand(MinX,MaxX),rand(MinY,MaxY),0,0,255,200);
		}PlaySEs(csd~"../../se/enemy_vanish[エフェクトＢ].wav");
		
		if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(),INFO_PLAYER_SHOOTDOWN_COUNT)==0){
				LifeFragment(enx-16,eny);				loop(2){SkillUp(enx+rand(-16,16),eny+rand(-16,16));}
		}
		if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(),INFO_PLAYER_SPELL_COUNT)==0){
				SpellFragment(enx+16,eny);				loop(1){SkillUp(enx+rand(-16,16),eny+rand(-16,16));}
		}
		
		if(GetPlayerPower<400){
			loop(6){
				SmallPower(enx+rand(-32,32),eny+rand(-32,32));
			}
			loop(2){
				BigPower(enx+rand(-32,32),eny+rand(-32,32));
			}
		}else{
			loop(8){
				AddPoints(enx+rand(-32,32),eny+rand(-32,32));
			}
		}
		ExtendLife(enx,eny);
		
		Obj_Delete(enm);

		loop(300){
			yield;
		}
		
		CloseScript(GetOwnScriptID);
	}
