#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spellcard 2"]
#Text[" Mononobe Clan - [r]\"Eighty Sacred Sake Dishes\" "]
#System["./System.txt"]
#Background["./Background.dnh"]
#Player["./player/YukaMarisa/YukaMarisa.dnh"]

let bossObj;
let attack = false;
let BossX = 0;
let BossY = 0;

let shot = GetCurrentScriptDirectory ~ "se/Shot1.wav";
let shot3 = GetCurrentScriptDirectory ~ "se/Shot3.wav";
let wave = GetCurrentScriptDirectory ~ "se/BulletWave.wav";
let barrage = GetCurrentScriptDirectory ~ "se/barrage.wav";
let eff = GetCurrentScriptDirectory ~ "se/Eff1.wav";
let Eff2 = GetCurrentScriptDirectory ~ "se/Eff2.wav";
let Eff4 = GetCurrentScriptDirectory ~ "se/Eff4.wav";
let weirdsound = GetCurrentScriptDirectory ~ "se/um2.wav";
let laser = GetCurrentScriptDirectory ~ "se/Laser3.wav";
let Anim_Attack = 0;

#include "./Render.dnh"
#include "./shot/AllStarShot_Const.dnh"

@Initialize{
	// Initialize: Works when starting up Danmakufu PH3

	//  Defines a Boss and Registers it.
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	
	NameFuto;
	AnimateBossFuto(bossObj);
	ObjMove_SetDestAtWeight(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2-64,15,5);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	
	mainTask; //Runs Maintask
	
}

@Event{
	// Event: Sets the Boss's Specs
	
		// Sets Boss's Life and Timer
		alternative(GetEventType() )
		case(EV_REQUEST_LIFE) {
			SetScriptResult(5250);
		}
		case(EV_REQUEST_TIMER) {
			SetScriptResult(80);
		}

}

@MainLoop{
	// MainLoop: Runs throughout the script.
	
	// Sets the Boss's Collision Circle(Hitbox) For the Shots and Player.
	ObjEnemy_SetIntersectionCircleToShot(bossObj,BossX,BossY,20);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,BossX,BossY,20);
		
	// Indicates that BossX = GetEnemyX and BossY = GetEnemyY
	BossX = ObjMove_GetX(bossObj);
	BossY = ObjMove_GetY(bossObj);
	
	yield;

}

@Finalize{


}

// Your best friend. FOREVER!!! The Wait Function
function wait(w) { loop(w){ yield;} }

task mainTask{
	end;
	wait(10);
	ObjMove_SetDestAtWeight(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2-32,15,5);
	wait(80);
	CutIn("Mononobe Clan - \"Eighty Sacred Sake Dishes\"");
	let sceneObj = GetEnemyBossSceneObjectID;
	ObjEnemyBossScene_StartSpell(sceneObj);
	wait(160);
	ConcentrationQ;
	wait(80);
	loop{
	dish;
	wait(2320);
	dishbarrage;
	wait(600);
	}
}

task dish{
	let spin = 0;
	let dir = 0;
	let a = 8;
	let s = 0;
	let x = 0;
	let i = 0;
	
	
		while(x<a){
		
			Play(barrage);
			wave1;
			
			dir+=360/a;
			x++;
			spin+=2/a;
		}
		x = 0;
		dir = 0;
		wait(15);
		Anim_Attack = 0;
		wait(1120);
		while(x<a){
		
			Play(barrage);
			wave2;
			
			dir+=360/a;
			x++;
			spin+=2/a;
		}
		x = 0;
		dir = 0;
		wait(15);
		Anim_Attack = 0;
		
			task wave1{
				Anim_Attack = 1;
				let obj1 = CreateShotA1(BossX+0*cos(dir+spin),BossY+13+0*sin(dir+spin),0,dir,3110,10);
				let obj = CreateShotA1(BossX+0*cos(dir+spin),BossY+0*sin(dir+spin),0,dir,3110,10);
				let r2 = ObjMove_GetAngle(obj);
				let r21 = ObjMove_GetAngle(obj1);
				ObjRender_SetAngleXYZ(obj,30,0,90);
				ObjRender_SetAngleXYZ(obj1,30,0,90);
				ObjRender_SetScaleXYZ(obj,2.5,3,2);
				ObjShot_SetSpellResist(obj,true);
				ObjShot_SetSpellResist(obj1,true);
				ObjMove_SetAcceleration(obj,0.033);
				ObjMove_SetAcceleration(obj1,0.033);
				ObjMove_SetMaxSpeed(obj,6);
				ObjMove_SetMaxSpeed(obj1,6);
				ObjMove_SetAngularVelocity(obj,2);
				ObjMove_SetAngularVelocity(obj1,2);
				wait(150);
				ascent(i in 0..40){
				Play(wave);
				let zobj = CreateShotA1(ObjMove_GetX(obj)+0*cos(dir+spin),ObjMove_GetY(obj)+0*sin(dir+spin),0,dir+spin+i*6,135,10);
				let zobj1 = CreateShotA1(ObjMove_GetX(obj)+0*cos(dir+spin),ObjMove_GetY(obj)+0*sin(dir+spin),0,dir-spin-i*6,135,10);
				ObjMove_SetAcceleration(zobj,0.025);
				ObjMove_SetAcceleration(zobj1,0.025);
				ObjMove_SetMaxSpeed(zobj,2.5);
				ObjMove_SetMaxSpeed(zobj1,2.5);
				ObjMove_SetAngularVelocity(zobj,-0.1);
				ObjMove_SetAngularVelocity(zobj1,0.1);
				spin+=4/a;
				dir+=360/a;
				wait(15);
				}
				loop(5){
					ascent(i in 0..2){
						ObjRender_SetColor(obj,255*i,255*i,255*i);
						ObjRender_SetColor(obj1,255*i,255*i,255*i);
						wait(5);
					}
					wait(5);
				}
				spin = 0;
				Play(weirdsound);
				loop(127){
					ObjRender_SetColor(obj,255,255-spin,255-spin);
					ObjRender_SetColor(obj1,255,255-spin,255-spin);
					ObjMove_SetAcceleration(obj,-s/a/5);
					ObjMove_SetAcceleration(obj1,-s/a/5);
					ObjMove_SetMaxSpeed(obj,0);
					ObjMove_SetMaxSpeed(obj1,0);
						spin+=2;
						s+=2/127;
					yield;
				}
				wait(30);
				ObjMove_SetAngle(obj,r2+135);
				ObjMove_SetAngle(obj1,r21+135);
				ObjMove_SetAcceleration(obj,0.3);
				ObjMove_SetAcceleration(obj1,0.3);
				ObjMove_SetAngularVelocity(obj,0);
				ObjMove_SetAngularVelocity(obj1,0);
				ObjMove_SetMaxSpeed(obj,4);
				ObjMove_SetMaxSpeed(obj1,4);
				explodetimebaby;
				
				task explodetimebaby{
					while(!Obj_IsDeleted(obj)){
						if(trunc(ObjMove_GetX(obj))<0){
							Play(wave);
							loop(24){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(1,3),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetX(obj))>GetStgFrameWidth){
							Play(wave);
							loop(24){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-3,-1),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))<0){
							Play(wave);
							loop(24){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-4,4),rand(0.1,2),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))>GetStgFrameHeight){
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						yield;
					}
				}
			}
			
			task wave2{
				Anim_Attack = 1;
				let obj1 = CreateShotA1(BossX+0*cos(dir+spin),BossY+13+0*sin(dir+spin),0,dir,3110,10);
				let obj = CreateShotA1(BossX+0*cos(dir+spin),BossY+0*sin(dir+spin),0,dir,3110,10);
				let r2 = ObjMove_GetAngle(obj);
				let r21 = ObjMove_GetAngle(obj1);
				ObjRender_SetAngleXYZ(obj,30,0,90);
				ObjRender_SetAngleXYZ(obj1,30,0,90);
				ObjRender_SetScaleXYZ(obj,2.5,3,2);
				ObjShot_SetSpellResist(obj,true);
				ObjShot_SetSpellResist(obj1,true);
				ObjMove_SetAcceleration(obj,0.033);
				ObjMove_SetAcceleration(obj1,0.033);
				ObjMove_SetMaxSpeed(obj,6);
				ObjMove_SetMaxSpeed(obj1,6);
				ObjMove_SetAngularVelocity(obj,-2);
				ObjMove_SetAngularVelocity(obj1,-2);
				wait(150);
				ascent(i in 0..40){
				Play(wave);
				let zobj = CreateShotA1(ObjMove_GetX(obj)+0*cos(dir+spin),ObjMove_GetY(obj)+0*sin(dir+spin),0,dir+spin-i*6,135,10);
				let zobj1 = CreateShotA1(ObjMove_GetX(obj)+0*cos(dir+spin),ObjMove_GetY(obj)+0*sin(dir+spin),0,dir-spin+i*6,135,10);
				ObjMove_SetAcceleration(zobj,0.025);
				ObjMove_SetAcceleration(zobj1,0.025);
				ObjMove_SetMaxSpeed(zobj,2.5);
				ObjMove_SetMaxSpeed(zobj1,2.5);
				ObjMove_SetAngularVelocity(zobj,0.1);
				ObjMove_SetAngularVelocity(zobj1,-0.1);
				spin+=4/a;
				dir+=360/a;
				wait(15);
				}
				loop(5){
					ascent(i in 0..2){
						ObjRender_SetColor(obj,255*i,255*i,255*i);
						ObjRender_SetColor(obj1,255*i,255*i,255*i);
						wait(5);
					}
					wait(5);
				}
				spin = 0;
				Play(weirdsound);
				loop(127){
					ObjRender_SetColor(obj,255,255-spin,255-spin);
					ObjRender_SetColor(obj1,255,255-spin,255-spin);
					ObjMove_SetAcceleration(obj,-s/a/5);
					ObjMove_SetAcceleration(obj1,-s/a/5);
					ObjMove_SetMaxSpeed(obj,0);
					ObjMove_SetMaxSpeed(obj1,0);
						spin+=2;
						s+=2/127;
					yield;
				}
				wait(30);
				ObjMove_SetAngle(obj,r2-135);
				ObjMove_SetAngle(obj1,r21-135);
				ObjMove_SetAcceleration(obj,0.3);
				ObjMove_SetAcceleration(obj1,0.3);
				ObjMove_SetAngularVelocity(obj,0);
				ObjMove_SetAngularVelocity(obj1,0);
				ObjMove_SetMaxSpeed(obj,4);
				ObjMove_SetMaxSpeed(obj1,4);
				explodetimebaby;
				
				task explodetimebaby{
					while(!Obj_IsDeleted(obj)){
						if(trunc(ObjMove_GetX(obj))<0){
							Play(wave);
							loop(24){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(1,3),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetX(obj))>GetStgFrameWidth){
							Play(wave);
							loop(24){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-3,-1),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))<0){
							Play(wave);
							loop(24){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-4,4),rand(0.1,2),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))>GetStgFrameHeight){
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						yield;
					}
				}
			}
}

task dishbarrage{
	let spin = 0;
		let dir = 0;
		let a = 8;
		let s = 0;
		let x = 0;
		let i = 0;
		
		ascent(i in 0..3){
			while(x<a){
			
				Play(barrage);
				wave3;
				
				dir+=360/a;
				x++;
				spin+=2/a;
			}
			x = 0;
			dir = 0;
			wait(15);
			Anim_Attack = 0;
			wait(30);
			while(x<a){
			
				Play(barrage);
				wave4;
				
				dir+=360/a;
				x++;
				spin+=2/a;
			}
			x = 0;
			dir = 0;
			wait(15);
			Anim_Attack = 0;
			wait(30);
		}
				task wave3{
				Anim_Attack = 1;
				let obj1 = CreateShotA1(BossX+0*cos(dir+spin),BossY+13+0*sin(dir+spin),0,dir,3110,10);
				let obj = CreateShotA1(BossX+0*cos(dir+spin),BossY+0*sin(dir+spin),0,dir,3110,10);
				let r2 = ObjMove_GetAngle(obj);
				let r21 = ObjMove_GetAngle(obj1);
				ObjRender_SetAngleXYZ(obj,30,0,90);
				ObjRender_SetAngleXYZ(obj1,30,0,90);
				ObjRender_SetScaleXYZ(obj,2.5,3,2);
				ObjShot_SetSpellResist(obj,true);
				ObjShot_SetSpellResist(obj1,true);
				ObjMove_SetAcceleration(obj,0.033);
				ObjMove_SetAcceleration(obj1,0.033);
				ObjMove_SetMaxSpeed(obj,6);
				ObjMove_SetMaxSpeed(obj1,6);
				ObjMove_SetAngularVelocity(obj,-1);
				ObjMove_SetAngularVelocity(obj1,-1);
				explodetimebaby;
				
				task explodetimebaby{
					while(!Obj_IsDeleted(obj)){
						if(trunc(ObjMove_GetX(obj))<0){
							Play(wave);
							loop(4){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(1,3),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetX(obj))>GetStgFrameWidth){
							Play(wave);
							loop(4){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-3,-1),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))<0){
							Play(wave);
							loop(4){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-4,4),rand(0.1,2),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))>GetStgFrameHeight){
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						yield;
					}
				}
			}
			
			task wave4{
				Anim_Attack = 1;
				let obj1 = CreateShotA1(BossX+0*cos(dir+spin),BossY+13+0*sin(dir+spin),0,dir,3110,10);
				let obj = CreateShotA1(BossX+0*cos(dir+spin),BossY+0*sin(dir+spin),0,dir,3110,10);
				let r2 = ObjMove_GetAngle(obj);
				let r21 = ObjMove_GetAngle(obj1);
				ObjRender_SetAngleXYZ(obj,30,0,90);
				ObjRender_SetAngleXYZ(obj1,30,0,90);
				ObjRender_SetScaleXYZ(obj,2.5,3,2);
				ObjShot_SetSpellResist(obj,true);
				ObjShot_SetSpellResist(obj1,true);
				ObjMove_SetAcceleration(obj,0.033);
				ObjMove_SetAcceleration(obj1,0.033);
				ObjMove_SetMaxSpeed(obj,6);
				ObjMove_SetMaxSpeed(obj1,6);
				ObjMove_SetAngularVelocity(obj,1);
				ObjMove_SetAngularVelocity(obj1,1);
				explodetimebaby;
				
				task explodetimebaby{
					while(!Obj_IsDeleted(obj)){
						if(trunc(ObjMove_GetX(obj))<0){
							Play(wave);
							loop(4){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(1,3),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetX(obj))>GetStgFrameWidth){
							Play(wave);
							loop(4){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-3,-1),rand(-1,-2.5),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))<0){
							Play(wave);
							loop(4){
								CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(-4,4),rand(0.1,2),0,0.033,0,2.5,87,0);
							}
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						if(trunc(ObjMove_GetY(obj))>GetStgFrameHeight){
						wait(5);
						Obj_Delete(obj);
						Obj_Delete(obj1);
						}
						yield;
					}
				}
			}
}
			
task end{
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){ yield;}
	
	Obj_Delete(bossObj);
	Anim_Attack = 0;
	
	loop(2){
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	yield;
	}
	

	CloseScript(GetOwnScriptID());
}