#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell2L"]

#include"./functions1.txt"

timer = 60;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());
	
	TEnemyWork;
	ObjEnemy_Render;
	ObjEffect_Shadow(true);
	TLife(objEnemy,360,20,20,2.5,2.5,25,25/4);
	TEnd;
}

@MainLoop
{
	timer-=1/60;
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(500);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(timer);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
	case(EV_START_BOSS_SPELL)
		{
		SetScriptResult(true);
		}
}

task TEnemyWork
{
	TSpellName("Shrine Service \"Seven Colored Omikuji\"");
	TXY;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-100,15,5);
	loop(90){yield;}
	EnemySpell = true;
	loop(30){yield;}
	EnemySpell2 = true;
	loop(30){yield;}

	let spread = 7;
	let time = 4;
	let turn = 2*time/6;	

	let angleA = -90;
	let numb1 = 1;
	let numb2 = 1;
	ascent(numb in 0..320/(time))
		{
		ascent(i in 0..spread)	
			{
			let angle = i*360/spread+angleA;
			TShot(angle,[numb1,numb2],i*3%7);
			numb1 *=-1;
			if(numb1 == 1)
				{
				numb2*=-1;
				if(numb2 == 1)
					{
					TShot(angle,[0,0],i*3%7);	
					}
				}
			}
		PlaySound(se_CuteShotLong,77.5);
		loop(time){yield;}
		if(numb == round(0.8*320/time))
			{
			PlaySound(se_ChargeLong,95);
			}
		}
	PlaySound(se_DeepShotHigh,80);
	let dir = 1;
	ascent(numb in 0..180/(time))
		{
		ascent(i in 0..spread)	
			{
			let angle = i*360/spread+angleA;
			TShot(angle,[numb1,numb2],i*3%7);
			numb1 *=-1;
			if(numb1 == 1)
				{
				numb2*=-1;
				if(numb2 == 1)
					{
					TShot(angle,[0,0],i*3%7);	
					}
				}
			}
		PlaySound(se_CuteShotLong,77.5);
		loop(time){yield;}
		angleA+=dir*turn;
		if(numb == round(0.4*180/time))
			{
			PlaySound(se_ChargeLong,95);
			}
		}
	PlaySound(se_DeepShotHigh,80);
	loop
		{
		dir = dir*-1;
		ascent(numb in 0..360/(time))
			{
			ascent(i in 0..spread)	
				{
				let angle = i*360/spread+angleA;
				TShot(angle,[numb1,numb2],i*(3.5-dir*0.5)%7);
				numb1 *=-1;
				if(numb1 == 1)
					{
					numb2*=-1;
					if(numb2 == 1)
						{
						TShot(angle,[0,0],i*(3.5-dir*0.5)%7);	
						}
					}
				}
			PlaySound(se_CuteShotLong,77.5);
			loop(time){yield;}
			angleA+=dir*turn;
			if(numb == round(0.8*360/time))
				{
				PlaySound(se_ChargeLong,95);
				}
			}
		PlaySound(se_DeepShotHigh,80);
		}
	task TShot(angle,array,graph)
		{
		let dist = 0;
		let time = 0;		
		let accel = -0.1;
		let speed = 8;
		let speedM = speed;
		let max = 1;
		while(dist < 384-48)
			{
			speedM+=accel;
			if(max-speedM >= 0)
				{
				speedM = max;
				}
			dist+=speedM;
			time+=1;
			}
		let obj = CreateShotA2(enmx+384*cos(angle),enmy+384*sin(angle),speed,angle+180,accel,max,DS_BALL_L_D_RED+graph,5);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetScaleXYZ(obj,0.75,0.75,0);
		ObjShot_SetAutoDelete(obj,false);
		loop(time){yield;}	
		let velo = array[1]*9/spread;
		let accel2 = 0.0075+array[0]*0.005;
		ObjMove_SetAcceleration(obj,accel2);
		ObjMove_SetMaxSpeed(obj,10);
		ObjShot_SetAutoDelete(obj,true);
		ObjMove_SetAngularVelocity(obj,velo);
		let alph = 255;
		loop(30)
			{
			alph-=255/30;
			ObjRender_SetAlpha(obj,alph);
			yield;
			}
		loop(45){yield;}
		if(Obj_IsDeleted(obj)){return;}
		graph *= 2;
		if(graph == (DS_BALL_L_YELLOW-DS_BALL_L_RED)*2)
			{
			graph+=1;	
			}
		let obj2 = CreateShotC2(ObjMove_GetX(obj),ObjMove_GetY(obj),ObjMove_GetSpeed(obj),ObjMove_GetAngle(obj),0.01,10,DS_BILL_RED+graph,15);
		ObjMove_SetAngularVelocity(obj2,velo);
		Obj_Delete(obj);
		loop(45){yield;}
		ObjMove_SetAngularVelocity(obj2,0);
		}	
}		

task TMovement
{
	let distM = 33;
	let distm = 33/2;
	let numb = absolute(cos(GetAngleToPlayer(objEnemy)))/cos(GetAngleToPlayer(objEnemy));
		if(ObjMove_GetX(objEnemy) < 175)
			{
			numb =1;	
			}
		else if (ObjMove_GetX(objEnemy) > GetStgFrameWidth-175)
			{	
			numb = -1;
			}
	ObjMove_SetDestAtWeight(objEnemy,ObjMove_GetX(objEnemy)+numb*rand(distm,distM),rand(110,150),30,5);
		
}

