
#ScriptVersion[3]
#Title["導命樹　stg2 spell2"]
#Text["実弾「ウォールナットフォール」N"]
#System["script/Th_mpp/ThMpp_System.dnh"]
#Image[""]
#Background[""]

	#include"../../../Control.dnh"
	#include"../../../lib_kshot.dnh"
	#include"./02_Obj_Texture.dnh"
	#include"./02_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,"Tobikura Momo");
		EnemyDisplay02(enm,true);
		Timer(1,60);
		Hpb("Spell",true,100,0);
		Aura(8,128,64,32);
		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(2,9);
		
		TWaveCircle();
	}

	@Loading{
		
	}

	@MainLoop{
		yield;
		let get_spell	= GetAreaCommonData("spell_counter","get_stage2",0);
		let play_spell	= GetAreaCommonData("spell_counter","play_stage2",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",200,240,[0.5,0.5],chara_tex[18],1024,1024,255,128,0);
			CutinSP2("ﾊｵｵｯ｡ｸWalnut Fall｡ｹ",get_spell[9],play_spell[9]);
			BackGroundEffect02();
		}
		
		S_count++;
		count++;
		frame++;
		timer++;
		if(frame==280){
			loop(7){
				let sht	= CreateShotA2(MinX+angle1-1,MinY-32,1.6,90,0,5,kRED03,0);
				ObjShot_SetAutoDelete(sht,true);
				ObjRender_SetScaleXYZ(sht,1.2,1.2,0);
				angle1+=64;
			}angle1=0;
			PlaySEs(csd~"../../se/shot1.wav");
		}
		if(timer==280){
			loop(12){
				CreateShotA2(enx,eny,1.4,angle2,0,5,kORANGE01,0);
				CreateShotA2(enx,eny,2.4,-angle2,0,5,kYELLOW01,0);
				angle2+=30;
			}angle2+=6;
			PlaySEs(csd~"../../se/shot2.wav");
			timer=276;
		}
		//アニメーション、移動
		if(count==180){
			CherryConcentration(50,csd~"../../se/power_logo.wav",enm);
		}
		alternative(count)
		case(300){
			if(count==0){ObjMove_SetDestAtWeight(enm,CenX,CenY-100,8,3);}
			else if(eny<=CenY-100){ObjMove_SetDestAtWeight(enm,GetPlayerX,eny+50,8,3);}
			else if(eny>=CenY-50){ObjMove_SetDestAtWeight(enm,GetPlayerX,eny-50,8,3);}
			else if(enx>=GetPlayerX){ObjMove_SetDestAtWeight(enm,enx-rand(50,90),eny+rand(30,-30),8,3);}
			else if(enx<=GetPlayerX){ObjMove_SetDestAtWeight(enm,enx+rand(50,90),eny+rand(30,-30),8,3);}
		}
		if(count==300){
			count=120;
			timer=120;
			frame=120;
			angle1=0;
		}
	}

	@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(2,9);
		}
	}

	@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));
			}
		}
		
		Obj_Delete(enm);

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