#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP1"]
#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(120);

let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam1.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam2.png";
SpellCard(160, "New Duel &quot;Extraterrestial Danmaku Transformation&quot;", [255, 60, 60], path, path2, 5, 150, 0.4, "Mamizou");

	ascent(i in 0..32){
		let obj = Leaf(-10, 42, 0+i, 0, 0.5, objBoss, 0);
		ObjShot_SetDeleteFrame(obj, 60);
		UFO(obj);
	}
	UfoLeft;
	ascent(i in 0..32){
		let obj = Leaf(GetStageRight+10, 64, 0+i, 180, 0.5, objBoss, 0);
		ObjShot_SetDeleteFrame(obj, 60);
		UFO(obj);
	}
	UfoRight;
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage.wav", 65, 0);
	
	wait(180);
	UFOController;
	loop{
	ascent(i in 0..32){
	let random = 1.5+rand(-0.5, 0.5);
		ascent(j in 0..4){
		let obj = Leaf(BossX, BossY, random, i*360/32, 0.5, objBoss, 10+12.5*j);
		ObjShot_SetDeleteFrame(obj, 60);
		UFOA(obj);
		}
	}
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage.wav", 65, 0);
		ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-84, 84), GetStgFrameHeight/2-100, 5, 4);
	wait(180);
	}
	
}

task UFOController{
	loop{
	ShootTop;
	wait(120);
	ShootBot;
	wait(120);
	}
}

task ShootTop{
SetCommonData("ShootTop", 1);
wait(60);
SetCommonData("ShootTop", 0);
}

task ShootBot{
SetCommonData("ShootBot", 1);
wait(60);
SetCommonData("ShootBot", 0);
}

task UfoLeft{
wait(160);
	loop{
	let shot = CreateShotA1(-10, 42, 1, 0, 2008, 1);
	Obj_SetValue(shot, "UFOTop", 1);
	ObjShot_SetSpellResist(shot, true);
	Shoot(shot);
	wait(60);
	}
}
	
task UfoRight{
wait(160);
	loop{
	let shot = CreateShotA1(GetStageRight+10, 64, 1, 180, 2008, 1);
	Obj_SetValue(shot, "UFOBot", 1);
	ObjShot_SetSpellResist(shot, true);
	Shoot(shot);
	wait(60);
	}
}

task UFO(obj){
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.01, 1, 2008, 1);
MamiSmoke(X, Y, rand(0, 1), rand(0,360), 0.35, 0, 10, 0);
ObjShot_SetSpellResist(shot, true);
Shoot(shot);

}

task UFOA(obj){
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.01, 1, 2008, 1);
MamiSmoke(X, Y, rand(0, 1), rand(0,360), 0.35, 0, 10, 0);
ObjShot_SetSpellResist(shot, true);
//Shoot2(shot);

}

task Shoot(shot){
	while(!Obj_IsDeleted(shot)){
		if(Obj_GetValueD(shot, "UFOTop", 0) == 1 && GetCommonData("ShootTop", 0) == 1){
		FireShotA1(GetX(shot), GetY(shot), 3, 90, RICE_S_BLUE_ADD, 10);
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
		wait(8);
		}
		if(Obj_GetValueD(shot, "UFOBot", 0) == 1 && GetCommonData("ShootBot", 0) == 1){
		FireShotA1(GetX(shot), GetY(shot), 3, 90, RICE_S_BLUE_ADD, 10);
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
		wait(8);
		}
	yield;
	}
}

task Shoot2(shot){
wait(120);
FireShotA2(GetX(shot), GetY(shot), 0.5, 90, 0.01, 10, RICE_S_BLUE, 10);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
}


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


