#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS4"]
#Text["Blep"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;
let BossX;
let BossY;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	HitSound(objBoss, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 120);
	EnemyMarker(objBoss);
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	/*case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}*/
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
	yield;
} 

@Finalize {
} 

task Main { 
wait(90);
Attack(60);
SetCommonData("BossAlpha", 0);
let player = GetCommonData("Chara", "reimu");
if(player == "reimu"){
		ascent(i in 0..45){
		let random = rand(0,360);
		let randomrad = rand(0, 25);
		MamiSmoke(BossX+randomrad*cos(random), BossY+randomrad*sin(random), rand(1, 2), rand(0,360), 0.5, 0, 5, 60);
		}
	RenderReimu(objBoss);
	ShootReimu;
	WarpCheck;
}
if(player == "marisa"){
		ascent(i in 0..45){
		let random = rand(0,360);
		let randomrad = rand(0, 25);
		MamiSmoke(BossX+randomrad*cos(random), BossY+randomrad*sin(random), rand(1, 2), rand(0,360), 0.5, 0, 5, 60);
		}
	RenderMarisa(objBoss);
	ShootMarisa;
}
if(player == "sanae"){
		ascent(i in 0..45){
		let random = rand(0,360);
		let randomrad = rand(0, 25);
		MamiSmoke(BossX+randomrad*cos(random), BossY+randomrad*sin(random), rand(1, 2), rand(0,360), 0.5, 0, 5, 60);
		}
	RenderSanae(objBoss);
	ShootSanae;
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 60, 0);
}

let rot = 1;

task ShootMarisa{
wait(120);
	ascent(i in 0..7){
	let obj = CreateShotA1(BossX, BossY, 0, 0, STAR_M_RED+i*2, 0);
	Rotate(obj, i*360/7, STAR_M_RED+i*2, 1, 0.005);
	Shoot(obj, STAR_M_RED+i*2);
	}
	
wait(60*6);

	ascent(i in 0..7){
	let obj = CreateShotA1(BossX, BossY, 0, 0, STAR_M_RED+i*2, 0);
	Rotate(obj, i*360/7, STAR_M_RED+i*2, -1, 0.01);
	Shoot(obj, STAR_M_RED+i*2);
	}
	
	
	task Shoot(obj, graph){
	wait(180);
	Shoot1;
	wait(180+6*7);
	Shoot2;
	task Shoot1{
		loop{
		rot = 2;
		ObjShot_SetGraphic(obj, ORB_L2_ORANGE_ADD);
			ascent(i in 0..6){
			FireShotA1(GetX(obj), GetY(obj), 3, GetAngleToObject(obj, objBoss), ORB_M_ORANGE_ADD, 10);
			PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
			wait(7);
			}
		wait(180-6*7);
		}
	}
	task Shoot2{
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
		loop{
		rot = 0.5;
		ObjShot_SetGraphic(obj, graph);
		let random = rand(-25, 25);
			ascent(j in 0..3){
				ascent(i in 0..9){
				let obj2 = FireShotA2(GetX(obj), GetY(obj), 6, GetAngleToObject(obj, objBoss)+random+i*360/9, -0.1, 1, graph-14, 10);
				ObjMove_AddPatternA2(obj2, 60*2, NO_CHANGE, NO_CHANGE, 0.02, 0, 3);
				}
				wait(5);
			}
		wait(180-3*5);
		}
	}
	}
	

	task Rotate(obj, off, graph, mult, dif){
	let rad = 0;
	let radmult = 1;
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj, BossX+rad*cos(off), BossY+rad*sin(off));
		rad+=1*radmult;
		if(radmult>0){radmult-=dif;}
		off+=rot*mult;
		yield;
		}
	}
}

task ShootSanae{
wait(120);
let rad = 100;
let ang = 270;
MoveStar(rad, ang, 1, DOT_WHITE, 6, 2, 15);
MoveStar(rad, ang+360/6, 1, DOT_WHITE, 6, 2,15);
MoveStar(rad, ang, 2, RICE_S_BLUE, 6, 2,15);
MoveStar(rad, ang+360/6, 2, RICE_S_GREEN, 6, 2,15);
wait(60*6);
ascent(i in 0..4){
MoveStar(rad*(0.50*i), ang+180, 1, RICE_S_RED, 5, 1, 10);
}
wait(60*8);
let a = 0;
loop{
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-75, 75), GetStgFrameHeight/2-150, 5, 1);
loop(32){
ascent(i in 0..4){
	ascent(j in 0..4){
	FireShotA1(BossX, BossY, 2+j/4, a*12+i*360/4+j*2, RICE_S_BLUE, 10);
	}
}
a++;
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
wait(4);
}
wait(30);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-75, 75), GetStgFrameHeight/2-150, 5, 1);
loop(32){
ascent(i in 0..4){
	ascent(j in 0..4){
	FireShotA1(BossX, BossY, 2+j/4, a*12+i*360/4-j*2, RICE_S_BLUE, 10);
	}
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
a--;
wait(4);
}
wait(90);
}
}

task MoveStar(rad, ang, spd, graph, point, div, time){
let obj = Enemee(BossX, BossY);
ObjMove_SetPosition(obj, BossX+rad*cos(ang), BossY+rad*sin(ang));
Shoot(obj, spd, graph, time, point/div);
let points = point;
let pointangle = 360/points+360/points;
	ascent(i in 1..points/div+1){
	ObjMove_SetDestAtFrame(obj, BossX+rad*cos(ang+(pointangle)*i), BossY+rad*sin(ang+(pointangle)*i), time);
	wait(time);
	}
}

task Shoot(obj, spd, graph, time, puntos){
	ascent(j in 0..time*puntos){
	ascent(i in 0..5){
	let obj2 = FireShotA1(GetX(obj), GetY(obj), 0, 270+i*360/5, graph, 10);
	ObjMove_AddPatternA2(obj2, time*puntos+30-j, 2, NO_CHANGE, -0.02, 0, 0);
	ObjMove_AddPatternA2(obj2, time*puntos+120-j, 0, ObjMove_GetAngle(obj2)+j*24, 0.02, 0, spd);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, time*puntos+30-j);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, time*puntos+120-j);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	}
	yield;
	}
}

task ShootReimu{
	loop{
		loop(2){
		wait(180);
		Shot(1);
		ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-75, 75), GetStgFrameHeight/2-150, 5, 1);
		ShotReim;
		wait(180);
		Shot(-1);
		ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-75, 75), GetStgFrameHeight/2-150, 5, 1);
		ShotReim;
		}
		wait(60*6);
		ObjMove_AddPatternA2(objBoss, 0, 10, 180, -0.06, 0, 0);
		ShotReim2;
		wait(210);
		ObjMove_AddPatternA2(objBoss, 0, 10, 0, -0.06, 0, 0);
		ShotReim2;
		wait(210);
	}
}

task WarpCheck{
loop{
if(BossX < GetStageLeft){ObjMove_SetPosition(objBoss, GetStageRight, BossY);}
if(BossX > GetStageRight){ObjMove_SetPosition(objBoss, GetStageLeft, BossY);}
yield;
}
}

task Shot(mult){
let chn = 79;
let time = 60;
	ascent(j in 0..time){
		ascent(i in 0..8){
		FireShotA2(BossX+(time-j)*cos((j*chn*mult)+i*360/8), BossY+(time-j)*sin((j*chn*mult)+i*360/8), 1, (j*chn*mult)+i*360/8, 0.02, 2, ORB_M_WHITE_ADD, 25);
		}
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	wait(2);
	}
}

task ShotReim{
let random = rand(0,360);
ascent(i in 0..9){
	ascent(j in 0..32){
	FireShotA1(BossX, BossY, 1+i/3, random+j*360/32, AMULET_RED, 10);
	}
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
}

task ShotReim2{
let random = rand(0,360);
ascent(j in 0..12){
	ascent(i in 0..3){
		ascent(j in 0..5){
		FireShotA1(BossX, BossY, 4+j/6, GetAngleToPlayer(objBoss)-10+5*i, ORB_M_RED_ADD, 10);
		}
	}
	ascent(j in 0..16){
	FireShotA1(BossX, BossY, 3, random+j*360/16, AMULET_RED, 10);
	}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
wait(10);
}
}


task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("bossx", BossX);
	SetCommonData("bossy", BossY);
	SetCommonData("RipNon", 1);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
	
} 


