#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Doremy Bonus!"]
#Text["Doremy Bonus! [r] by:SKN SMR [r] Comment:So...this is old last  spell and easier than new one [r] and I make it to bonus ENJOY~"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"

let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let action = false;
let objScene=GetEnemyBossSceneObjectID();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetPlayerLife(999);
SetBoss("Doremy",true);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),18);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(7500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(150);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(50,25,300);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("\"Nine Eternal YUME[A-E]\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "never.mp3");
	wait(105);
	TShot1;
	wait(1200);
	DamageRateAtFrame(75,40,0);
	}
//----------------------------------------------------

task TShot1
{
        attack(99990,1);
	let s = 1;
	PlaySound("Charge3",100,0);
	wait(10);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
	RayCharge("RED",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"RED");
        RWave(-1);
	wait(60);
	RayCharge("ORANGE",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"ORANGE");
        OShot;
        OShot;
	wait(60);
	RayCharge("YELLOW",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"YELLOW");
        Star(-1);
	wait(60);
	RayCharge("GREEN",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"GREEN");
	ALaserSet;
	ALaserSet;
	wait(60);
	RayCharge("AQUA",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"AQUA");
        AShot;
	wait(60);
	RayCharge("BLUE",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"BLUE");
        BSet;
	wait(60);
	RayCharge("PURPLE",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"PURPLE");
        PShot;
	wait(60);
	RayCharge("PINK",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"PINK");
        PiWave;
	wait(60);
	RayCharge("WHITE",2,60);
	wait(40);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"WHITE");
        WSpread;
	wait(60);
	}
}

function RWave(way) // red
{
	let r = 25;
	let num = 5;
	ascent(n in 0..40)
	{
		PlaySound("BulletWave",95,0);
		ascent(i in 0..num)
		{
			ascent(j in 0..6)
			{
				let angle = i*360/num*way+j*(0.2+n/12)*way+n*2*way;
				TShotA2(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),5,angle,5,5,300,8);
			}
		}
		wait(2);
	}
}

task OShot //Orange
{
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;

		dir = 0;
		ascent(n in 0..40)
		{
			r = 80;
			PlaySound("Shot1",100,0);
			ascent(i in 0..2)
			{
				ShotA1(GetEnemyX+r*cos(angle+i*180),GetEnemyY+r*sin(angle+i*180),1.75+n/60,dir+i*180,47,0,12);
			}
			r = 60;
			PlaySound("Shot1",100,0);
			ascent(i in 0..2)
			{
				ShotA1(GetEnemyX+r*cos(angle+i*180),GetEnemyY+r*sin(angle+i*180),1.75+n/60,dir+i*180,47,0,12);
			}

			angle += 10;
			dir+= (90);
			wait(2);
		}
	
}

task Star(way) // yellow
{
	let angle = GetAngleToPlayer(objBoss);
	let r = 150;
	let px = GetPlayerX;
	let py = GetPlayerY;
	let p = 90+90*way+rand(0,90)-45;
	ascent(n in 0..60)
	{
		r = 0;
		let x = rand(0,400);
		let y = 0;
		let dir = GetPointAngle(px,py,x,y);
		let obj = TShotA1(x,y,2,90,773,12);
		ObjMove_SetAngle(0,dir);
		PlaySound("BulletWave",95,120);
			if(n%2==0)
			{
				ascent(i in 0..2)
				{
					r = 0;
					let x = rand(0,360);
					let y = rand(0,360);

					ObjMove_SetAngle(obj,90);
					ObjMove_AddPatternA2(obj,120,90,90,270,0,1.5);
				}
			}

		if(n%3!=0){wait(1);}
	}
}

task ALaserSet // Green
{
	ascent(i in 0..4)
	{
		PlaySound("Shot6",100,0);
		CShot(GetEnemyX,GetEnemyY,5.3-i/2.5,rand(0,360)+i*8,796,8);
		CShot(GetEnemyX,GetEnemyY,5.3-i/2.5,rand(0,360)-i*8,796,8);
		wait(5);
	}
	task CShot(x,y,v,angle,color,delay)
	{
		let core = TShotA1(x,y,v,angle,color,delay);
		wait(50);
		
		if(!Obj_IsDeleted(core))
		{
			PlaySound("Shot6",100,0);
			ALaser(ObjMove_GetX(core),ObjMove_GetY(core));
			Obj_Delete(core);
		}
		task ALaser(ax,ay)
		{
			let laser = CreateStraightLaserA1(ax,ay,90,99,9,99,1011,0);
			DummyDelay(ax,ay,120);
			ObjShot_SetIntersectionEnable(laser,false);
			ascent(i in 0..90) // 60
			{
				ObjLaser_SetLength(laser,i*9);
				wait(i%2);
			}
			PlaySound("Laser3",100,0);
			ascent(i in 0..20) // 50
			{
				if(i==10){ObjShot_SetIntersectionEnable(laser,true);}
				ObjLaser_SetRenderWidth(laser,i);
				ObjLaser_SetIntersectionWidth(laser,i);
				yield;
			}
			wait(40); // 90
			descent(i in 0..10)
			{
				ObjLaser_SetRenderWidth(laser,i);
				ObjLaser_SetIntersectionWidth(laser,i-5);
				yield;
			}			
		}
			task DummyDelay(ax,ay,time)
			{	
				ascent(i in 0..time)
				{
					let stick = TShotA1(ax,ay,0,0,1011,2+(i)%3);
					ObjShot_SetDeleteFrame(stick,0);
					yield;
				}
			}
	}
}

task AShot // Aqua
{
	let r = 0;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
		ascent(n in 0..100)
		{
			PlaySound("Shot1",100,0);
			ascent(i in 0..1)
			{
				ShotA1(GetEnemyX+rand(-360,360),GetEnemyY+330,3,270,185,0,12);
			}
			angle += 80;
                        wait(1);
			dir+= (3);
			r+= 1/3;
		}
	
}

task BSet // Blue
{
	let r = 30;
	let num = 2;
	let curve = 1;
	let acc = 0.01;
	let multi = 1;
	let c = 0;
	let c2 = 0;
	let count = 0;
	ascent(n in 0..60)
	{
		PlaySound("BulletWave",95,0);
		ascent(i in 0..num)
		{
			ascent(j in 0..6)
			{
			let angle = i*360/num+180/num+c+count;
			TrickyBullet(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),1,angle,834,acc,curve*sin(count*10),12);
			}
		count++;
		c+=num;

                }

	}
}
             		task TrickyBullet(x,y,v,angle,color,acc,ang,delay)
		{
			let obj = TShotA2(x,y,v,angle,0,0,color,delay);
			wait(60);
			
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,acc,ang,10);
			wait(90);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,acc,0,10);
		}

task PShot // Purple
{
	let r = 0;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	
		dir = 0;
		r = 0;
		ascent(n in 0..50)
		{
			PlaySound("Shot1",100,0);

			ascent(i in 0..2)
			{
				ShotA1(GetEnemyX+r*cos(angle+i*10),GetEnemyY+r*sin(angle+i*10),1.25+n/60,180-dir+i*180,841,277,12);
			}
			ascent(i in 0..2)
			{
				ShotA1(GetEnemyX+r*cos(angle+i*0),GetEnemyY+r*sin(angle+i*0),1.25+n/90,0-dir+i*10,841,277,12);
			}
			angle += rand(0,360);
			dir+= (5)*s;
			wait(0);
			r+= 1;
		}
	
}

task PiWave // Pink
{
	let r = 120;
	let angle = 90;
	let dir = 0;
	let s = 1;
	let degree = 0;
	descent(n in -18..15)
	{
		ascent(j in 0..6)
		{
			r = 0;
			PlaySound("Shot1",100,0);
			ascent(i in 0..1)
			{
				ShotA1(GetEnemyX+0,GetEnemyY+0,5,dir+i*180,857,0,12);
			}
			angle += 90;
			dir+= (8);
			wait(0);
		}
		yield;
	}
}

task WSpread // White
{
	let angle = [10,10,10];
		let result = GetAngleToPlayer(objBoss)+rand(-5,5);
		ascent(i in 0..50)
		{
			PlaySound("Shot1",85,0);
			TShotA1(GetEnemyX+30*cos(i*rand(0,360)+result),GetEnemyY+30*sin(i*angle+result),15,i*angle+result,613,12);
			wait(2);
		}
}

task CheckNearPlayer(obj)
{
	wait(11);
	if(GetDistance(ObjMove_GetX(obj),ObjMove_GetY(obj),GetPlayerX,GetPlayerY)<20)
	{
		Obj_Delete(obj);
	}
}



//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		let color = GetColor("PURPLE");
		ClearBullet(120,10);
ExCircle(GetEnemyX,GetEnemyY,0.05,5);
ExCircle(GetEnemyX-30,GetEnemyY,0.05,100);
ExCircle(GetEnemyX+30,GetEnemyY,0.05,100);
ExCircle(GetEnemyX,GetEnemyY-30,0.05,100);
ExCircle(GetEnemyX,GetEnemyY+30,0.05,100);
loop(10){yield;}
		ObjMove_SetPosition(objBoss,stgx,-1000);
		PlaySound("enemoff",100,0);
		MapleExplode(stgx,150,1.5,"PINK");
		MapleExplode(stgx,150,2,"AQUA");
		descent(i in 0..30){
		Maple(stgx,150,1+i/30,rand(0,360),color[0],color[1],color[2]);
		yield;}

			wait(60);
		EndBoss(0);
		yield;
		CloseScript(GetOwnScriptID());
}

task ExCircle(x,y,sc,dtime){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
let timer = 0;
let s = 0;


let Target = GetCurrentScriptDirectory~"./Effect03.png";
let mx = ObjRender_GetX(obj);
let my = ObjRender_GetY(obj);


	Obj_SetRenderPriorityI(obj, 79);
	ObjPrim_SetTexture(obj, Target);

	ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);

	ObjSprite2D_SetSourceRect(obj, 0, 0, 512, 512);

        ObjSprite2D_SetDestCenter(obj);
        ObjRender_SetScaleXYZ(obj, s, s, s);
ObjRender_SetPosition(obj,x,y,0);
loop{
timer++;
        s+=sc;
        ObjRender_SetScaleXYZ(obj, s, s, s);

        if(timer == dtime){
        Obj_Delete(obj);
        break;
        }
        yield;
        }
        }