#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS3"]
#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(45);
	}
	/*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);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	loop(1){
	let obj = Leaf(BossX, BossY, 2.5, 0, 1, objBoss, 0);
	ObjShot_SetDeleteFrame(obj, 60);
	Mamizous(obj, 0);
	let obj2 = Leaf(BossX, BossY, 2.5, 180, 1, objBoss, 0);
	ObjShot_SetDeleteFrame(obj2, 60);
	Mamizous(obj2, 1);
	}
	
}

task Mamizous(obj, side){
let X = 0;
let Y = 0;
while(!Obj_IsDeleted(obj)){
 X = GetX(obj);
 Y = GetY(obj);
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
let shot = CreateShotA1(X, Y, 0, 0, 0, 0);
MamiSmoke(X, Y, rand(0, 0), rand(0,360), 1, 0, 10, 0);
ObjShot_SetSpellResist(shot, true);
RenderCharacter(shot);
if(side == 0){AttackLeft(shot);}
if(side == 1){AttackRight(shot);}
}

task AttackLeft(shot){
wait(60);
Shot2(shot, 1);
wait(90);
ObjMove_SetDestAtWeight(shot, GetX(shot), GetStgFrameHeight/2+200, 5, 4);
wait(120);
loop{
Shot2(shot, -1);
Shot3(objBoss, -1);
wait(200);
Shot2(shot, 1);
Shot3(objBoss, 1);
wait(200);
ObjMove_SetDestAtWeight(shot, GetX(shot), GetStgFrameHeight/2+rand(-200, 200), 5, 8);
wait(60);
}
}
task AttackRight(shot){
wait(60);
Shot2(shot, -1);
wait(90);
ObjMove_SetDestAtWeight(shot, GetX(shot), GetStgFrameHeight/2+200, 5, 4);
wait(120);
loop{
Shot2(shot, -1);
wait(200);
Shot2(shot, 1);
wait(200);
ObjMove_SetDestAtWeight(shot, GetX(shot), GetStgFrameHeight/2+rand(-200, 200), 5, 8);
wait(60);
}
}

task Shot(shot, mult){
let chn = 55;
let time = 30;
	ascent(j in 0..time){
		ascent(i in 0..3){
		FireShotA2(GetX(shot)+(time-j)*cos((j*chn*mult)+i*360/3), GetY(shot)+(time-j)*sin((j*chn*mult)+i*360/3), 1, (j*chn*mult)+i*360/3, 0.02, 3, ORB_M_YELLOW_ADD, 10);
		}
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
	wait(2);
	}
}
task Shot2(shot, mult){
let chn = 360/(7*2)+0.35;
let time = 40;
	ascent(j in 0..time){
		ascent(i in 0..7){
		FireShotA2(GetX(shot)+(time-j)*cos((j*chn*mult)+i*360/7), GetY(shot)+(time-j)*sin((j*chn*mult)+i*360/7), 0, (j*chn*mult)+i*360/7, 0.03, 3, ORB_M_BLUE_ADD, 15);
		}
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	wait(2);
	}
}
task Shot3(shot, mult){
let chn = 26;
let time = 11;
	ascent(j in 0..time){
		ascent(i in 0..3){
		FireShotA2(GetX(shot)+(time-j)*cos((j*chn*mult)+i*360/3), GetY(shot)+(time-j)*sin((j*chn*mult)+i*360/3), 0, (j*chn*mult)+i*360/3, 0.02, 2, ORB_M_YELLOW_ADD, 15);
		}
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
	wait(5);
	}
}

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());
	
} 


