#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP3"]
#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-80, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(75);
	}
	/*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(120);

let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam1.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam2.png";
SpellCard(160, "Transformation &quot;Futatsuiwa Clan of Nine Mamizous&quot;", [255, 60, 60], path, path2, 5, 150, 0.4, "Mamizou");

	
	ascent(i in 0..8){
	let obj = Leaf(BossX, BossY, 1.50, i*360/8, 1, objBoss, 0);
	ObjShot_SetDeleteFrame(obj, 60);
	Mamizous(obj, i*360/8);
	}
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
	
	wait(180);
	
	loop{
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-100, 100), GetStgFrameHeight/2-80, 5, 2);
	wait(210);
	}
	
}

task Mamizous(obj, off){
let X = 0;
let Y = 0;
while(!Obj_IsDeleted(obj)){
 X = GetX(obj);
 Y = GetY(obj);
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage.wav", 65, 0);
let shot = CreateShotA1(X, Y, 0, 0, 0, 0);
MamiSmoke(X, Y, rand(0, 0), rand(0,360), 2, 0, 10, 0);
ObjShot_SetSpellResist(shot, true);
RenderCharacter(shot);
Move(shot, off);
Shoot(shot);
}

task Shoot(obj){
wait(60+rand(0,120));
loop{
ascent(i in 0..5){
	let obj2 = Leaf(GetX(obj), GetY(obj), 1.50, GetAngleToPlayer(obj)-22.5+11.25*i, 0.5, objBoss, 0);
	ObjShot_SetDeleteFrame(obj2, 60);
	Birb(obj2, i*360/8);
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
MamiSmoke(GetX(obj), GetY(obj), rand(0, 1), rand(0,360), 0.35, 0, 10, 0);
let Frog = CreateShotA2(GetX(obj), GetY(obj), 0, 0, 0, 1, 2004, 1);
Explode(Frog);
wait(180);
}
}

task Explode(obj){
wait(60*5);
let random = rand(0,360);
if(!Obj_IsDeleted(obj)){
ascent(i in 0..8){
FireShotA1(GetX(obj), GetY(obj), 1.5, random+i*360/8, RICE_S_YELLOW, 10);
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
Obj_Delete(obj);
}
}

task Move(obj, off){
let a = 0;
let radx = 100;
let rady = 100;
loop{
ObjMove_SetPosition(obj, BossX+radx*cos(off), BossY+rady*sin(off));
ObjEnemy_SetIntersectionCircleToShot(obj, GetX(obj), GetY(obj),21);
radx = 150*cos(a);
rady = 150*sin(a);
off+=2.1212;
a++;
yield;
}
}

task Birb(obj, a){
let X = 0;
let Y = 0;
let angle = 0;
while(!Obj_IsDeleted(obj)){
 angle = ObjMove_GetAngle(obj);
 X = GetX(obj);
 Y = GetY(obj);
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
let shot = CreateShotA2(X, Y, 0, angle, 0.04, 3, 2003, 1);
ObjRender_SetAngleZ(shot, -90);
ObjMove_SetAngle(shot, GetAngleToPlayer(shot));
MamiSmoke(X, Y, rand(0, 1), rand(0,360), 0.35, 0, 10, 0);
ObjShot_SetSpellResist(shot, true);

}

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


