
#ScriptVersion[3]
#Title["導命樹　stg1　Event02"]
#Text["Normal"]
#System["script/Th_mpp/ThMpp_System.dnh"]
#Image[""]
#Background[""]

	#include"../../../Control.dnh"
	#include"../../../lib_kshot.dnh"
	#include"./01_Obj_Texture.dnh"
	#include"./01_Obj_Shot.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 ctr			= 0;
	let flg			= 0;
	let EnmInfo		= 0;
	
	/*----会話専用変数を定義----*/
	//　配列がちょっとでも曖昧になっていると途中でエラー吐いてくるんだよ
	//　お空を先に表示した方がレイヤーの都合がいいと今日何度も言っておきます
	let enm_tex		= [chara_tex[4],"","","",""];
	let pla_tex1	= [player_tex[24],player_tex[25],player_tex[26],player_tex[27],
						player_tex[28],player_tex[29],player_tex[30],player_tex[31],player_tex[32]];
	let pla_tex2	= [player_tex[15],player_tex[16],player_tex[17],player_tex[18],
						player_tex[19],player_tex[20],player_tex[21],player_tex[22],player_tex[23]];
	let ehc			= 256-48;
	let phc			= [256-32,64];
	let phcy		= [0,16];
	let sca_e		= [0.55,0.55];
	let sca_p		= [0.65,0.65,0.65,0.65];//添え字2,3は2キャラ目XY
	
	@Initialize{
		enm	= ObjEnemy_Create(OBJ_ENEMY_BOSS);
		ObjEnemy_SetDamageRate(enm,0,0);
		ObjEnemy_Regist(enm);
		
		spl	= GetEnemyBossSceneObjectID();
		EnmInfo	= ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_REMAIN_STEP_COUNT);
		
		EnemyDisplay01(enm,true);
		Aura(8,32,128,128);
		RedMagicCircle(1,0);
		RemainStepCount(MinX+12,MinY+23,1,EnmInfo,enm);
		EndEnemy;
		
		CreateCommonDataArea("anime");
		SetAreaCommonData("anime","spa",false);
		
		CreateCommonDataArea("talk");
		SetAreaCommonData("talk","counter",0);
		
		TWaveCircle();
	}

	@Loading{
	}

	@MainLoop{
		yield;
		SetAreaCommonData("ST_System","GetSkillItem",60);
		
		/*制限時間処理*/
		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>180 ){//ボム中
			ObjEnemy_SetDamageRate(enm,0,0);
			Damage=0;
		}
		if(IsPlayerSpellActive==false){Damage++;}
		if(Damage>=180){ObjEnemy_SetDamageRate(enm,0,0);}//ダメージが通る
		
		/*敵の当たり判定を登録 ローカル*/
		let enx		= ObjMove_GetX(enm);
		let eny		= ObjMove_GetY(enm);
		ObjEnemy_SetIntersectionCircleToShot(enm, enx, eny, 32);//当たり判定(自弾)登録
		
		if(flg==0){
			if(count > 200){
				flg++;
				count=0;
			}else{
				count++;
			}
			if(count==1){
				ObjMove_SetDestAtWeight(enm,CenX+rand(-64,64),CenY-128,8,4);
				PlaySEs(csd~"../../se/BossEnd.wav");
			}
			if(count%2==0){
				ReleaseCherry01(enx,eny,255,0,0,200);
				ReleaseCherry01(enx,eny,255,0,0,400);
			}
			if(count==80){
				PlaySEs(csd~"../../se/BossEnd.wav");
				EnemyBreakDown_th14(enm);
				WorldShake(80,8);
				loop(64){
					ReleaseCherry01(enx,eny,255,0,0,200);
					ReleaseCherry01(enx,eny,255,0,0,400);
				}
				ObjMove_SetPosition(enm,CenX,MinY-512);
			}
		}
		else if(flg==1){
			SetForbidPlayerShot(true);
			SetForbidPlayerSpell(true);
			
			ctr++;
			if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH && ctr>10){
				frame++;
				count=0;
				ctr=0;
				SetAreaCommonData("talk","counter",frame);
			}
			if(GetVirtualKeyState(VK_SHOT)==KEY_HOLD){
				timer++;
			}else{
				timer=0;
			}
			if(timer>40 && ctr>4){
				frame++;
				count=0;
				ctr=0;
				SetAreaCommonData("talk","counter",frame);
			}
			
			count++;
			if(count==1){
				alternative(frame)
				case(0){
					DrawCharactorEnm(MaxX+ehc,CenY+128+32,[sca_e[0],sca_e[1]],frame,enm_tex[0],1024,1024,"FRONT","OFF");
					DrawCharactor(MinX+32+phc[0],CenY+128+phcy[0],[sca_p[0],sca_p[1]],frame,pla_tex1[0],1024,1024,"BACK","OFF");
					DrawCharactor(MinX+32+phc[1],CenY+128+phcy[1],[sca_p[2],sca_p[3]],frame,pla_tex2[0],1024,1024,"BACK","OFF");
/*to be changed*/					Balloon(CenX,CenY+98,128+64,0,"好好好,别把我眼镜弄坏了,我说就是了",frame,16,1.7,0.2,180);
				}
				case(1){
					DrawCharactorEnm(MaxX+ehc,CenY+128+32,[sca_e[0],sca_e[1]],frame,enm_tex[0],1024,1024,"BACK","ON");
					DrawCharactor(MinX+32+phc[0],CenY+128+phcy[0],[sca_p[0],sca_p[1]],frame,pla_tex1[0],1024,1024,"BACK","OFF");
					DrawCharactor(MinX+32+phc[1],CenY+128+phcy[1],[sca_p[2],sca_p[3]],frame,pla_tex2[7],1024,1024,"FRONT","ON");
/*to be changed*/					Balloon(CenX-32,CenY+128-32,128+96-4,0,"不过，这样用武力来收集信仰真的没问题吗？",frame,16,1.9,0.2,0);
				}
				case(2){
					DrawCharactorEnm(MaxX+ehc,CenY+128+32,[sca_e[0],sca_e[1]],frame,enm_tex[0],1024,1024,"BACK","OFF");
					DrawCharactor(MinX+32+phc[0],CenY+128+phcy[0],[sca_p[0],sca_p[1]],frame,pla_tex1[4],1024,1024,"FRONT","ON");
					DrawCharactor(MinX+32+phc[1],CenY+128+phcy[1],[sca_p[2],sca_p[3]],frame,pla_tex2[7],1024,1024,"BACK","ON");
/*to be changed*/					Balloon(CenX-128,CenY+128-32,128,0,"以前这么做的效果也不太好。[r]还是不要这么做了吧。",frame,16,1.2,0.4,180);
				}
				case(3){
					DrawCharactorEnm(MaxX+ehc,CenY+128+32,[sca_e[0],sca_e[1]],frame,enm_tex[0],1024,1024,"FRONT","ON");
					DrawCharactor(MinX+32+phc[0],CenY+128+phcy[0],[sca_p[0],sca_p[1]],frame,pla_tex1[4],1024,1024,"BACK","ON");
					DrawCharactor(MinX+32+phc[1],CenY+128+phcy[1],[sca_p[2],sca_p[3]],frame,pla_tex2[7],1024,1024,"BACK","OFF");
/*to be changed*/					Balloon(CenX+64,CenY+128-32,128+16,0,"嗯……[r]结果你们还是要砸我的眼镜吗？",frame,16,1.3,0.4,180);
				}
				case(4){
					DrawCharactorEnm(MaxX+ehc,CenY+128+32,[sca_e[0],sca_e[1]],frame,enm_tex[0],1024,1024,"BACK","ON");
					DrawCharactor(MinX+32+phc[0],CenY+128+phcy[0],[sca_p[2],sca_p[3]],frame,pla_tex1[1],1024,1024,"FRONT","ON");
					DrawCharactor(MinX+32+phc[1],CenY+128+phcy[1],[sca_p[0],sca_p[1]],frame,pla_tex2[7],1024,1024,"BACK","OFF");
/*to be changed*/					Balloon(CenX-128,CenY+128-32,96+8,0,"能量饮料我就拿走了。[r]记得每天送三瓶到神社来。",frame,16,1.0,0.4,180);
				}
				case(5){
					DrawCharactorEnm(MaxX+ehc,CenY+128+32,[sca_e[0],sca_e[1]],frame,enm_tex[0],1024,1024,"BACK","OFF");
					DrawCharactor(MinX+32+phc[0],CenY+128+phcy[0],[sca_p[0],sca_p[1]],frame,pla_tex1[1],1024,1024,"BACK","ON");
					DrawCharactor(MinX+32+phc[1],CenY+128+phcy[1],[sca_p[2],sca_p[3]],frame,pla_tex2[1],1024,1024,"FRONT","ON");
/*to be changed*/					Balloon(CenX-32,CenY+128-32,32+4,0,"好耶--",frame,16,0.4,0.2,0);
				}
				case(6){
					DrawCharactorEnm(MaxX+ehc,CenY+128+32,[sca_e[0],sca_e[1]],frame,enm_tex[0],1024,1024,"BACK","OFF");
					DrawCharactor(MinX+32+phc[0],CenY+128+phcy[0],[sca_p[2],sca_p[3]],frame,pla_tex1[1],1024,1024,"BACK","OFF");
					DrawCharactor(MinX+32+phc[1],CenY+128+phcy[1],[sca_p[0],sca_p[1]],frame,pla_tex2[0],1024,1024,"FRONT","OFF");
/*to be changed*/					Balloon(CenX-32,CenY+128-32,128+48+4,0,"...不对，我们不能再这样浪费时间了。[r]还是快点去导命树吧。",frame,16,1.6,0.4,0);
				}
				others{
					flg=2;
					SetForbidPlayerShot(false);
					SetForbidPlayerSpell(false);
				}
			}
		}
	}

	@Event{
		alternative(GetEventType())
		case(EV_REQUEST_LIFE){
			SetScriptResult(5000);//ライフを1500に設定
		}
	}

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

	task EndEnemy{
		while(flg!=2){
			SetAreaCommonData( "Multiplier", "Stop", true );
			yield;
		}
		
		SetAreaCommonData( "Multiplier", "Stop", false );
		
		let enx = ObjMove_GetX(enm);
		let eny = ObjMove_GetY(enm);
		
		ObjEnemy_AddLife(enm,-ObjEnemy_GetInfo(enm,INFO_LIFE));
		Obj_Delete(enm);
		
		loop(180){yield;}
		
		SaveCommonDataAreaA1("Trance");
		CloseScript(GetOwnScriptID);
	}

	task LWait(long){
		loop(long){yield;}
	}
	
	task WorldShake(long,shake){
		loop(long){
			Set2DCameraFocusX(CenX+rand(-shake,shake));
			Set2DCameraFocusY(CenY+rand(-shake,shake));
			yield;
		}
		Set2DCameraFocusX(CenX);
		Set2DCameraFocusY(CenY);
	}
