#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP5"]
#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", 1);
	SetCommonData("BossAlpha", 255);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(1);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(80);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(1);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	yield;
} 

@Finalize {
} 

task Main { 
wait(180);

ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-1000, 5, 4);
Leaves;
let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam1.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam2.png";
SpellCard(160, "&quot;Animals Running Wild&quot;", [255, 60, 60], path, path2, 5, 150, 0.4, "Mamizou");


}

let Mamizou = [ID_INVALID, ID_INVALID, ID_INVALID, ID_INVALID];
let Mamizou2 = [ID_INVALID, ID_INVALID, ID_INVALID, ID_INVALID];

task Leaves{
let a = 0;
	loop(4){
	let obj = Leaf(BossX, BossY, 3, 45, 1, objBoss, 0);
	ObjShot_SetDeleteFrame(obj, 60);
	Mamizous(obj, 0, a);
	let obj2 = Leaf(BossX, BossY, 3, 180-45, 1, objBoss, 0);
	ObjShot_SetDeleteFrame(obj2, 60);
	Mamizous2(obj2, 1, a);
	a++;
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
	wait(20);
	}
wait(60*2);

ObjMove_SetDestAtWeight(Mamizou2[0], 20, 40, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[1], 20, 160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[2], 20, GetStageDown-160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[3], 20, GetStageDown-40, 5, 4);

ObjMove_SetDestAtWeight(Mamizou[0], GetStageRight-20, 40, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[1], GetStageRight-20, 160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[2], GetStageRight-20, GetStageDown-160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[3], GetStageRight-20, GetStageDown-40, 5, 4);

wait(60*4);

loop(5){
let random = truncate(rand(0, 4));
let X1 = GetX(Mamizou[random]);
let X2 = GetX(Mamizou2[random]);
let Y = GetY(Mamizou[random]);
ObjMove_SetDestAtWeight(Mamizou[random], X2, Y, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[random], X1, Y, 5, 4);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
wait(120);
}

wait(120);

ObjMove_SetDestAtWeight(Mamizou2[0], 40, 40, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[1], 40, 160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[2], 40, GetStageDown-160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[3], 40, GetStageDown-40, 5, 4);

ObjMove_SetDestAtWeight(Mamizou[0], GetStageRight-40, 40, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[1], GetStageRight-40, 160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[2], GetStageRight-40, GetStageDown-160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[3], GetStageRight-40, GetStageDown-40, 5, 4);
	
wait(60*2);

Birbs(Mamizou2[0]);Birbs(Mamizou[0]);Birbs(Mamizou2[3]);Birbs(Mamizou[3]);
wait(60*8);

loop(4){
let random = truncate(0);
let X1 = GetX(Mamizou[random]);
let X2 = GetX(Mamizou2[random]);
let Y = GetY(Mamizou[random]);
ObjMove_SetDestAtWeight(Mamizou[random], X2, Y, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[random], X1, Y, 5, 4);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
wait(120);
 random = truncate(3);
 X1 = GetX(Mamizou[random]);
 X2 = GetX(Mamizou2[random]);
 Y = GetY(Mamizou[random]);
ObjMove_SetDestAtWeight(Mamizou[random], X2, Y, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[random], X1, Y, 5, 4);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
wait(120);
}
wait(180);

ObjMove_SetDestAtWeight(Mamizou2[0], 80, 40, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[1], 80, 160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[2], 80, GetStageDown-160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou2[3], 80, GetStageDown-40, 5, 4);

ObjMove_SetDestAtWeight(Mamizou[0], GetStageRight-80, 40, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[1], GetStageRight-80, 160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[2], GetStageRight-80, GetStageDown-160, 5, 4);
ObjMove_SetDestAtWeight(Mamizou[3], GetStageRight-80, GetStageDown-40, 5, 4);

ascent(i in 0..4){
Frogs(Mamizou2[i]);Frogs(Mamizou[i]);
}

wait(180);
	loop(7){
	let random = truncate(rand(0, 4));
	let X1 = GetX(Mamizou[random]);
	let X2 = GetX(Mamizou2[random]);
	let Y = GetY(Mamizou[random]);
	ObjMove_SetDestAtWeight(Mamizou[random], X2, Y, 5, 2);
	ObjMove_SetDestAtWeight(Mamizou2[random], X1, Y, 5, 2);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
	wait(180);
	}
ascent(i in 0..4){
DedMamis(Mamizou2[i]);DedMamis(Mamizou[i]);
}
}

task DedMamis(off){
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage.wav", 65, 0);
	ascent(i in 0..24){
	MamiSmoke(GetX(off), GetY(off), rand(1, 2), rand(0,360), 0.5, 0, 15, 30);
	}
	ObjMove_SetPosition(off, -1000, -1000);
	Obj_SetValue(off, "Stop", 1);
}

task Mamizous(obj, side, a){
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);
Mamizou[a] = CreateShotA1(X, Y, 0, 0, 0, 0);
MamiSmoke(X, Y, rand(0, 0), rand(0,360), 1, 0, 10, 0);
ObjShot_SetSpellResist(Mamizou[a], true);
ObjShot_SetAutoDelete(Mamizou[a], false);
RenderCharacter(Mamizou[a]);
Hitbox(Mamizou[a]);
Shot(Mamizou[a]);
}

task Mamizous2(obj, side, a){
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);
Mamizou2[a] = CreateShotA1(X, Y, 0, 0, 0, 0);
MamiSmoke(X, Y, rand(0, 0), rand(0,360), 1, 0, 10, 0);
ObjShot_SetSpellResist(Mamizou2[a], true);
ObjShot_SetAutoDelete(Mamizou2[a], false);
RenderCharacter(Mamizou2[a]);
Hitbox(Mamizou2[a]);
Shot(Mamizou2[a]);
}

task Hitbox(obj){
loop{
ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),24);
yield;
}
}

task Birbs(shot){
loop(10){
let rad = 22.5;
ascent(i in 0..5){
let obj = FireShotA2(GetX(shot), GetY(shot), 0, GetAngleToPlayer(shot)-rad+rad/2*i, 0.01, 1.2, 2003, 0);
ObjRender_SetAngleZ(obj, -90);
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
wait(rand(120, 180));
}
}

task Frogs(shot){
	while(Obj_GetValueD(shot, "Stop", 0) == 0){
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
	let obj2 = FireShotA1(GetX(shot), GetY(shot), 0, 0, 2004, 0);
	Explode(obj2);
	wait(rand(30, 35));
	}
}
task Explode(obj){
wait(rand(60, 120));
let random = rand(0,360);
if(!Obj_IsDeleted(obj)){
	ascent(i in 0..12){
	let obj2 = FireShotA2(GetX(obj), GetY(obj), 2, random+i*360/12, -0.03, 0, RICE_S_BLUE_ADD, 10);
	del(obj2);
	}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
}
Obj_Delete(obj);
}

task del(obj){
wait(120);
ObjShot_FadeDelete(obj);
}
task Shot(shot){
wait(60*4);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage.wav", 65, 0);
while(Obj_GetValueD(shot, "Stop", 0) == 0){
ascent(i in 0..2){
FireShotA2(GetX(shot), GetY(shot), 0, 270+180*i+rand(-3, 3), 0.01, 3, 2000, 0);
}
wait(rand(10, 15));
}
}


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


